Trait wasmtime_runtime::InstanceAllocator

source ·
pub trait InstanceAllocator: InstanceAllocatorImpl {
    // Provided methods
    fn validate_module(
        &self,
        module: &Module,
        offsets: &VMOffsets<HostPtr>
    ) -> Result<()> { ... }
    unsafe fn allocate_module(
        &self,
        request: InstanceAllocationRequest<'_>
    ) -> Result<InstanceHandle> { ... }
    unsafe fn deallocate_module(&self, handle: &mut InstanceHandle) { ... }
    unsafe fn allocate_memories(
        &self,
        request: &mut InstanceAllocationRequest<'_>,
        memories: &mut PrimaryMap<DefinedMemoryIndex, (MemoryAllocationIndex, Memory)>
    ) -> Result<()> { ... }
    unsafe fn deallocate_memories(
        &self,
        memories: &mut PrimaryMap<DefinedMemoryIndex, (MemoryAllocationIndex, Memory)>
    ) { ... }
    unsafe fn allocate_tables(
        &self,
        request: &mut InstanceAllocationRequest<'_>,
        tables: &mut PrimaryMap<DefinedTableIndex, (TableAllocationIndex, Table)>
    ) -> Result<()> { ... }
    unsafe fn deallocate_tables(
        &self,
        tables: &mut PrimaryMap<DefinedTableIndex, (TableAllocationIndex, Table)>
    ) { ... }
}
Expand description

A thing that can allocate instances.

Don’t implement this trait directly, instead implement InstanceAllocatorImpl and you’ll get this trait for free via a blanket impl.

Provided Methods§

source

fn validate_module( &self, module: &Module, offsets: &VMOffsets<HostPtr> ) -> Result<()>

Validate whether a core module is allocatable with this instance allocator.

source

unsafe fn allocate_module( &self, request: InstanceAllocationRequest<'_> ) -> Result<InstanceHandle>

Allocates a fresh InstanceHandle for the req given.

This will allocate memories and tables internally from this allocator and weave that altogether into a final and complete InstanceHandle ready to be registered with a store.

Note that the returned instance must still have .initialize(..) called on it to complete the instantiation process.

§Unsafety

The request’s associated module, memories, tables, and vmctx must have already have been validated by Self::validate_module.

source

unsafe fn deallocate_module(&self, handle: &mut InstanceHandle)

Deallocates the provided instance.

This will null-out the pointer within handle and otherwise reclaim resources such as tables, memories, and the instance memory itself.

§Unsafety

The instance must have previously been allocated by Self::allocate.

source

unsafe fn allocate_memories( &self, request: &mut InstanceAllocationRequest<'_>, memories: &mut PrimaryMap<DefinedMemoryIndex, (MemoryAllocationIndex, Memory)> ) -> Result<()>

Allocate the memories for the given instance allocation request, pushing them into memories.

§Unsafety

The request’s associated module and memories must have previously been validated by Self::validate_module.

source

unsafe fn deallocate_memories( &self, memories: &mut PrimaryMap<DefinedMemoryIndex, (MemoryAllocationIndex, Memory)> )

Deallocate all the memories in the given primary map.

§Unsafety

The memories must have previously been allocated by Self::allocate_memories.

source

unsafe fn allocate_tables( &self, request: &mut InstanceAllocationRequest<'_>, tables: &mut PrimaryMap<DefinedTableIndex, (TableAllocationIndex, Table)> ) -> Result<()>

Allocate tables for the given instance allocation request, pushing them into tables.

§Unsafety

The request’s associated module and tables must have previously been validated by Self::validate_module.

source

unsafe fn deallocate_tables( &self, tables: &mut PrimaryMap<DefinedTableIndex, (TableAllocationIndex, Table)> )

Deallocate all the tables in the given primary map.

§Unsafety

The tables must have previously been allocated by Self::allocate_tables.

Implementors§