pub unsafe trait InstanceAllocator: Send + Sync {
    // Required methods
    unsafe fn allocate(
        &self,
        req: InstanceAllocationRequest<'_>
    ) -> Result<InstanceHandle>;
    unsafe fn initialize(
        &self,
        handle: &mut InstanceHandle,
        module: &Module,
        is_bulk_memory: bool
    ) -> Result<()>;
    unsafe fn deallocate(&self, handle: &InstanceHandle);
    fn purge_module(&self, module: CompiledModuleId);

    // Provided method
    fn validate(
        &self,
        module: &Module,
        offsets: &VMOffsets<HostPtr>
    ) -> Result<()> { ... }
}
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

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

Allocates an instance for the given allocation request.

Safety

This method is not inherently unsafe, but care must be made to ensure pointers passed in the allocation request outlive the returned instance.

source

unsafe fn initialize( &self, handle: &mut InstanceHandle, module: &Module, is_bulk_memory: bool ) -> Result<()>

Finishes the instantiation process started by an instance allocator.

Safety

This method is only safe to call immediately after an instance has been allocated.

source

unsafe fn deallocate(&self, handle: &InstanceHandle)

Deallocates a previously allocated instance.

Safety

This function is unsafe because there are no guarantees that the given handle is the only owner of the underlying instance to deallocate.

Use extreme care when deallocating an instance so that there are no dangling instance pointers.

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.

Implementors§