Trait wasmtime_runtime::InstanceAllocator
source · [−]pub unsafe trait InstanceAllocator: Send + Sync {
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);
fn allocate_fiber_stack(&self) -> Result<FiberStack, FiberStackError>;
unsafe fn deallocate_fiber_stack(&self, stack: &FiberStack);
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
unsafe fn allocate(
&self,
req: InstanceAllocationRequest<'_>
) -> Result<InstanceHandle, InstantiationError>
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.
unsafe fn initialize(
&self,
handle: &mut InstanceHandle,
module: &Module,
is_bulk_memory: bool
) -> Result<(), InstantiationError>
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.
unsafe fn deallocate(&self, handle: &InstanceHandle)
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.
fn allocate_fiber_stack(&self) -> Result<FiberStack, FiberStackError>
fn allocate_fiber_stack(&self) -> Result<FiberStack, FiberStackError>
Allocates a fiber stack for calling async functions on.
unsafe fn deallocate_fiber_stack(&self, stack: &FiberStack)
unsafe fn deallocate_fiber_stack(&self, stack: &FiberStack)
Deallocates a fiber stack that was previously allocated with allocate_fiber_stack
.
Safety
The provided stack is required to have been allocated with allocate_fiber_stack
.
Provided methods
Validates that a module is supported by the allocator.
fn adjust_tunables(&self, tunables: &mut Tunables)
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
.