pub trait RuntimeLinearMemory: Send + Sync {
    // Required methods
    fn byte_size(&self) -> usize;
    fn maximum_byte_size(&self) -> Option<usize>;
    fn grow_to(&mut self, size: usize) -> Result<()>;
    fn vmmemory(&mut self) -> VMMemoryDefinition;
    fn needs_init(&self) -> bool;
    fn as_any_mut(&mut self) -> &mut dyn Any;
    fn wasm_accessible(&self) -> Range<usize>;

    // Provided method
    fn grow(
        &mut self,
        delta_pages: u64,
        store: Option<&mut dyn Store>
    ) -> Result<Option<(usize, usize)>, Error> { ... }
}
Expand description

A linear memory

Required Methods§

source

fn byte_size(&self) -> usize

Returns the number of allocated bytes.

source

fn maximum_byte_size(&self) -> Option<usize>

Returns the maximum number of bytes the memory can grow to. Returns None if the memory is unbounded.

source

fn grow_to(&mut self, size: usize) -> Result<()>

Grow memory to the specified amount of bytes.

Returns an error if memory can’t be grown by the specified amount of bytes.

source

fn vmmemory(&mut self) -> VMMemoryDefinition

Return a VMMemoryDefinition for exposing the memory to compiled wasm code.

source

fn needs_init(&self) -> bool

Does this memory need initialization? It may not if it already has initial contents courtesy of the MemoryImage passed to RuntimeMemoryCreator::new_memory().

source

fn as_any_mut(&mut self) -> &mut dyn Any

Used for optional dynamic downcasting.

source

fn wasm_accessible(&self) -> Range<usize>

Returns the range of addresses that may be reached by WebAssembly.

This starts at the base of linear memory and ends at the end of the guard pages, if any.

Provided Methods§

source

fn grow( &mut self, delta_pages: u64, store: Option<&mut dyn Store> ) -> Result<Option<(usize, usize)>, Error>

Grows a memory by delta_pages.

This performs the necessary checks on the growth before delegating to the underlying grow_to implementation. A default implementation of this memory is provided here since this is assumed to be the same for most kinds of memory; one exception is shared memory, which must perform all the steps of the default implementation plus the required locking.

The store is used only for error reporting.

Implementors§

source§

impl RuntimeLinearMemory for SharedMemory

Proxy all calls through the RwLock.