pub struct IsolatedMemory<const MAX_PAGES: usize> { /* private fields */ }Expand description
Isolated linear memory for a single Wasm module.
MAX_PAGES is the compile-time maximum (from the Wasm module’s declared
maximum or a CLI override). The backing array is fully pre-allocated.
Implementations§
Source§impl<const MAX_PAGES: usize> IsolatedMemory<MAX_PAGES>
impl<const MAX_PAGES: usize> IsolatedMemory<MAX_PAGES>
Sourcepub fn try_new(initial_pages: usize) -> Result<Self, ConstructionError>
pub fn try_new(initial_pages: usize) -> Result<Self, ConstructionError>
Create a new IsolatedMemory with initial_pages active.
§Errors
Returns ConstructionError::MemoryInitialPagesExceedsMax if initial_pages > MAX_PAGES.
Sourcepub fn try_init(
slot: &mut MaybeUninit<Self>,
initial_pages: usize,
) -> Result<(), ConstructionError>
pub fn try_init( slot: &mut MaybeUninit<Self>, initial_pages: usize, ) -> Result<(), ConstructionError>
Initialize an IsolatedMemory in-place within a caller-provided slot.
Unlike try_new, this writes directly into slot without ever creating
a large Result<Self, E> on the call stack. Use this when MAX_PAGES
is large, to avoid stack overflow in debug builds.
§Errors
Returns ConstructionError::MemoryInitialPagesExceedsMax if initial_pages > MAX_PAGES.
Sourcepub fn page_count(&self) -> usize
pub fn page_count(&self) -> usize
Current number of active pages.
Sourcepub fn active_size(&self) -> usize
pub fn active_size(&self) -> usize
Current active size in bytes.
Sourcepub fn grow(&mut self, delta: u32) -> i32
pub fn grow(&mut self, delta: u32) -> i32
Wasm memory.grow — returns previous page count, or -1 on failure.
No allocation occurs: the backing array is already sized to MAX_PAGES.
Sourcepub fn memory_copy(&mut self, dst: u32, src: u32, len: u32) -> WasmResult<()>
pub fn memory_copy(&mut self, dst: u32, src: u32, len: u32) -> WasmResult<()>
Wasm memory.copy — copy len bytes from src to dst.
Semantics match memmove: overlapping source and destination regions
are handled correctly. Traps (OutOfBounds) if either region extends
beyond the current active memory.
Sourcepub fn load_i32(&self, offset: usize) -> WasmResult<i32>
pub fn load_i32(&self, offset: usize) -> WasmResult<i32>
Load an i32 from linear memory with bounds checking.
Sourcepub fn load_i64(&self, offset: usize) -> WasmResult<i64>
pub fn load_i64(&self, offset: usize) -> WasmResult<i64>
Load an i64 from linear memory with bounds checking.
Sourcepub fn load_u8(&self, offset: usize) -> WasmResult<u8>
pub fn load_u8(&self, offset: usize) -> WasmResult<u8>
Load a u8 (i32.load8_u) from linear memory with bounds checking.
Sourcepub fn load_u16(&self, offset: usize) -> WasmResult<u16>
pub fn load_u16(&self, offset: usize) -> WasmResult<u16>
Load a u16 (i32.load16_u) from linear memory with bounds checking.
Sourcepub fn load_f32(&self, offset: usize) -> WasmResult<f32>
pub fn load_f32(&self, offset: usize) -> WasmResult<f32>
Load an f32 from linear memory with bounds checking.
Sourcepub fn load_f64(&self, offset: usize) -> WasmResult<f64>
pub fn load_f64(&self, offset: usize) -> WasmResult<f64>
Load an f64 from linear memory with bounds checking.
Sourcepub fn store_i32(&mut self, offset: usize, value: i32) -> WasmResult<()>
pub fn store_i32(&mut self, offset: usize, value: i32) -> WasmResult<()>
Store an i32 into linear memory with bounds checking.
Sourcepub fn store_i64(&mut self, offset: usize, value: i64) -> WasmResult<()>
pub fn store_i64(&mut self, offset: usize, value: i64) -> WasmResult<()>
Store an i64 into linear memory with bounds checking.
Sourcepub fn store_u8(&mut self, offset: usize, value: u8) -> WasmResult<()>
pub fn store_u8(&mut self, offset: usize, value: u8) -> WasmResult<()>
Store a u8 (i32.store8) into linear memory with bounds checking.
Sourcepub fn store_u16(&mut self, offset: usize, value: u16) -> WasmResult<()>
pub fn store_u16(&mut self, offset: usize, value: u16) -> WasmResult<()>
Store a u16 (i32.store16) into linear memory with bounds checking.
Sourcepub fn store_f32(&mut self, offset: usize, value: f32) -> WasmResult<()>
pub fn store_f32(&mut self, offset: usize, value: f32) -> WasmResult<()>
Store an f32 into linear memory with bounds checking.
Sourcepub fn store_f64(&mut self, offset: usize, value: f64) -> WasmResult<()>
pub fn store_f64(&mut self, offset: usize, value: f64) -> WasmResult<()>
Store an f64 into linear memory with bounds checking.
Sourcepub fn init_data(&mut self, offset: usize, data: &[u8]) -> WasmResult<()>
pub fn init_data(&mut self, offset: usize, data: &[u8]) -> WasmResult<()>
Initialize a region of memory from a byte slice (Wasm data segment).
Copies data into linear memory starting at offset. Equivalent to
calling store_u8 for each byte, but avoids emitting N separate
function calls in generated code.
§Errors
Returns Err(WasmTrap::OutOfBounds) if offset + data.len() exceeds
active_pages * PAGE_SIZE.
Sourcepub unsafe fn load_i32_unchecked(&self, offset: usize) -> i32
pub unsafe fn load_i32_unchecked(&self, offset: usize) -> i32
Sourcepub unsafe fn load_i64_unchecked(&self, offset: usize) -> i64
pub unsafe fn load_i64_unchecked(&self, offset: usize) -> i64
Sourcepub unsafe fn store_i32_unchecked(&mut self, offset: usize, value: i32)
pub unsafe fn store_i32_unchecked(&mut self, offset: usize, value: i32)
Sourcepub unsafe fn store_i64_unchecked(&mut self, offset: usize, value: i64)
pub unsafe fn store_i64_unchecked(&mut self, offset: usize, value: i64)
Sourcepub fn as_mut_slice(&mut self) -> &mut [u8]
pub fn as_mut_slice(&mut self) -> &mut [u8]
Mutable access to the active memory region.