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

    // Provided methods
    fn validate(&self, module: &Module) -> Result<()> { ... }
    fn adjust_tunables(&self, tunables: &mut Tunables) { ... }
}
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, InstantiationError>

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<(), InstantiationError>

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.

Provided Methods§

source

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

Validates that a module is supported by the allocator.

source

fn adjust_tunables(&self, tunables: &mut Tunables)

Adjusts the tunables prior to creation of any JIT compiler.

This method allows the instance allocator control over tunables passed to a wasmtime_jit::Compiler.

Implementors§