diff --git a/crates/wasmi/src/engine/executor/instrs/load.rs b/crates/wasmi/src/engine/executor/instrs/load.rs index 877f62f334..bbc68ce86d 100644 --- a/crates/wasmi/src/engine/executor/instrs/load.rs +++ b/crates/wasmi/src/engine/executor/instrs/load.rs @@ -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() } diff --git a/crates/wasmi/src/engine/executor/instrs/store.rs b/crates/wasmi/src/engine/executor/instrs/store.rs index c83a719ce3..41de755bba 100644 --- a/crates/wasmi/src/engine/executor/instrs/store.rs +++ b/crates/wasmi/src/engine/executor/instrs/store.rs @@ -57,6 +57,7 @@ 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. @@ -64,6 +65,7 @@ impl Executor<'_> { } /// Fetches the bytes of the given `memory`. + #[inline] fn fetch_memory_bytes_mut<'exec, 'store, 'bytes>( &'exec mut self, memory: Memory, @@ -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, @@ -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() }