Trait wasmtime_runtime::InstanceAllocator

source ·
pub unsafe trait InstanceAllocator {
    // Required methods
    fn allocate_index(
        &self,
        req: &InstanceAllocationRequest<'_>,
    ) -> Result<usize>;
    fn deallocate_index(&self, index: usize);
    fn allocate_memories(
        &self,
        index: usize,
        req: &mut InstanceAllocationRequest<'_>,
        mems: &mut PrimaryMap<DefinedMemoryIndex, Memory>,
    ) -> Result<()>;
    fn deallocate_memories(
        &self,
        index: usize,
        mems: &mut PrimaryMap<DefinedMemoryIndex, Memory>,
    );
    fn allocate_tables(
        &self,
        index: usize,
        req: &mut InstanceAllocationRequest<'_>,
        tables: &mut PrimaryMap<DefinedTableIndex, Table>,
    ) -> Result<()>;
    fn deallocate_tables(
        &self,
        index: usize,
        tables: &mut PrimaryMap<DefinedTableIndex, Table>,
    );
    fn purge_module(&self, module: CompiledModuleId);

    // Provided methods
    fn validate(
        &self,
        module: &Module,
        offsets: &VMOffsets<HostPtr>,
    ) -> Result<()> { ... }
    fn allocate(
        &self,
        req: InstanceAllocationRequest<'_>,
    ) -> Result<InstanceHandle> { ... }
    fn deallocate(&self, handle: &mut InstanceHandle) { ... }
}
Expand description

Represents a runtime instance allocator.

§Safety

This trait is unsafe as it requires knowledge of Wasmtime’s runtime internals to implement correctly.

Required Methods§

source

fn allocate_index(&self, req: &InstanceAllocationRequest<'_>) -> Result<usize>

Optionally allocates an allocator-defined index for the req provided.

The return value here, if successful, is passed to the various methods below for memory/table allocation/deallocation.

source

fn deallocate_index(&self, index: usize)

Deallocates indices allocated by allocate_index.

source

fn allocate_memories( &self, index: usize, req: &mut InstanceAllocationRequest<'_>, mems: &mut PrimaryMap<DefinedMemoryIndex, Memory>, ) -> Result<()>

Attempts to allocate all defined linear memories for a module.

Pushes all memories for req onto the mems storage provided which is already appropriately allocated to contain all memories.

Note that this is allowed to fail. Failure can additionally happen after some memories have already been successfully allocated. All memories pushed onto mem are guaranteed to one day make their way to deallocate_memories.

source

fn deallocate_memories( &self, index: usize, mems: &mut PrimaryMap<DefinedMemoryIndex, Memory>, )

Deallocates all memories provided, optionally reclaiming resources for the pooling allocator for example.

source

fn allocate_tables( &self, index: usize, req: &mut InstanceAllocationRequest<'_>, tables: &mut PrimaryMap<DefinedTableIndex, Table>, ) -> Result<()>

Same as allocate_memories, but for tables.

source

fn deallocate_tables( &self, index: usize, tables: &mut PrimaryMap<DefinedTableIndex, Table>, )

Same as deallocate_memories, but for tables.

source

fn purge_module(&self, module: CompiledModuleId)

Purges all lingering resources related to module from within this allocator.

Primarily present for the pooling allocator to remove mappings of this module from slots in linear memory.

Provided Methods§

source

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

Validates that a module is supported by the allocator.

source

fn allocate(&self, req: 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.

source

fn deallocate(&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.

Implementors§