diff --git a/rs/embedders/src/lib.rs b/rs/embedders/src/lib.rs index 4478fb38f9c..5ed31f05b43 100644 --- a/rs/embedders/src/lib.rs +++ b/rs/embedders/src/lib.rs @@ -36,10 +36,6 @@ pub struct InstanceRunResult { pub exported_globals: Vec, } -pub trait LinearMemory { - fn as_ptr(&self) -> *mut libc::c_void; -} - /// The results of compiling a Canister which need to be passed back to the main /// replica process. #[derive(Debug, Serialize, Deserialize, Clone)] diff --git a/rs/embedders/src/wasmtime_embedder/host_memory.rs b/rs/embedders/src/wasmtime_embedder/host_memory.rs index be6c19a4fc1..a2280a84174 100644 --- a/rs/embedders/src/wasmtime_embedder/host_memory.rs +++ b/rs/embedders/src/wasmtime_embedder/host_memory.rs @@ -1,10 +1,8 @@ use anyhow::bail; use ic_types::MAX_STABLE_MEMORY_IN_BYTES; -use wasmtime::MemoryType; +use wasmtime::{LinearMemory, MemoryType}; use wasmtime_environ::{WASM32_MAX_PAGES, WASM_PAGE_SIZE}; -use crate::LinearMemory; - use ic_sys::PAGE_SIZE; use libc::c_void; @@ -60,7 +58,7 @@ unsafe impl wasmtime::MemoryCreator for WasmtimeMemoryCreator { _maximum: Option, reserved_size_in_bytes: Option, guard_size: usize, - ) -> Result, String> { + ) -> Result, String> { // We don't use the `reserved_size_in_bytes` because the size of the // memory allocation is determined based on the memory type: 64-bit // memories have size at most the maximum stable memory size and 32-bit @@ -102,7 +100,7 @@ unsafe impl wasmtime::MemoryCreator for WasmtimeMemoryCreator { epilogue_guard_size_in_bytes, ); created_memories.insert( - MemoryStart(wasmtime::LinearMemory::as_ptr(&new_memory) as usize), + MemoryStart(LinearMemory::as_ptr(&new_memory) as usize), MemoryPageSize(Arc::clone(&new_memory.used)), ); Ok(Box::new(new_memory)) @@ -185,9 +183,7 @@ impl MmapMemory { epilogue_guard_size_in_bytes, } } -} -impl LinearMemory for MmapMemory { fn as_ptr(&self) -> *mut c_void { self.wasm_memory } @@ -200,17 +196,17 @@ impl Drop for MmapMemory { } } -pub struct WasmtimeMemory { - mem: M, +pub struct WasmtimeMemory { + mem: MmapMemory, max_size_in_pages: usize, used: MemoryPageSize, prologue_guard_size_in_bytes: usize, epilogue_guard_size_in_bytes: usize, } -impl WasmtimeMemory { +impl WasmtimeMemory { fn new( - mem: M, + mem: MmapMemory, min_size_in_pages: usize, max_size_in_pages: usize, prologue_guard_size_in_bytes: usize, @@ -234,7 +230,7 @@ fn convert_pages_to_bytes(pages: usize) -> usize { result } -unsafe impl wasmtime::LinearMemory for WasmtimeMemory { +unsafe impl LinearMemory for WasmtimeMemory { /// Returns the number of allocated wasm pages. fn byte_size(&self) -> usize { convert_pages_to_bytes(self.used.load(Ordering::SeqCst))