Skip to content

Commit

Permalink
Use get_memory helpers in more places (#1224)
Browse files Browse the repository at this point in the history
* use get_memory utility method

* add new inline annotations to load/store handlers
  • Loading branch information
Robbepop authored Oct 5, 2024
1 parent 5777d9e commit e6fe69b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
7 changes: 1 addition & 6 deletions crates/wasmi/src/engine/executor/instrs/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,7 @@ impl Executor<'_> {
'exec: 'bytes,
'store: 'bytes,
{
// Safety: the underlying instance of `self.cache` is always kept up-to-date conservatively.
let memory = unsafe {
self.cache
.get_memory(memory)
.unwrap_or_else(|| panic!("missing linear memory for {memory:?}"))
};
let memory = self.get_memory(memory);
store.resolve_memory(&memory).data()
}

Expand Down
10 changes: 4 additions & 6 deletions crates/wasmi/src/engine/executor/instrs/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,15 @@ impl Executor<'_> {
}

/// Fetches the bytes of the default memory at index 0.
#[inline]
fn fetch_default_memory_bytes_mut(&mut self) -> &mut [u8] {
// Safety: the `self.cache.memory` pointer is always synchronized
// conservatively whenever it could have been invalidated.
unsafe { self.cache.memory.data_mut() }
}

/// Fetches the bytes of the given `memory`.
#[inline]
fn fetch_memory_bytes_mut<'exec, 'store, 'bytes>(
&'exec mut self,
memory: Memory,
Expand All @@ -81,6 +83,7 @@ impl Executor<'_> {

/// Fetches the bytes of the given non-default `memory`.
#[cold]
#[inline]
fn fetch_non_default_memory_bytes_mut<'exec, 'store, 'bytes>(
&'exec mut self,
memory: Memory,
Expand All @@ -90,12 +93,7 @@ impl Executor<'_> {
'exec: 'bytes,
'store: 'bytes,
{
// Safety: the underlying instance of `self.cache` is always kept up-to-date conservatively.
let memory = unsafe {
self.cache
.get_memory(memory)
.unwrap_or_else(|| panic!("missing linear memory for {memory:?}"))
};
let memory = self.get_memory(memory);
store.resolve_memory_mut(&memory).data_mut()
}

Expand Down

0 comments on commit e6fe69b

Please sign in to comment.