Trait wasmtime_runtime::InstanceAllocatorImpl

source ·
pub unsafe trait InstanceAllocatorImpl {
Show 13 methods // Required methods fn validate_module_impl( &self, module: &Module, offsets: &VMOffsets<HostPtr> ) -> Result<()>; fn increment_component_instance_count(&self) -> Result<()>; fn decrement_component_instance_count(&self); fn increment_core_instance_count(&self) -> Result<()>; fn decrement_core_instance_count(&self); unsafe fn allocate_memory( &self, request: &mut InstanceAllocationRequest<'_>, memory_plan: &MemoryPlan, memory_index: DefinedMemoryIndex ) -> Result<(MemoryAllocationIndex, Memory)>; unsafe fn deallocate_memory( &self, memory_index: DefinedMemoryIndex, allocation_index: MemoryAllocationIndex, memory: Memory ); unsafe fn allocate_table( &self, req: &mut InstanceAllocationRequest<'_>, table_plan: &TablePlan, table_index: DefinedTableIndex ) -> Result<(TableAllocationIndex, Table)>; unsafe fn deallocate_table( &self, table_index: DefinedTableIndex, allocation_index: TableAllocationIndex, table: Table ); fn purge_module(&self, module: CompiledModuleId); fn next_available_pkey(&self) -> Option<ProtectionKey>; fn restrict_to_pkey(&self, pkey: ProtectionKey); fn allow_all_pkeys(&self);
}
Expand description

Trait that represents the hooks needed to implement an instance allocator.

Implement this trait when implementing new instance allocators, but don’t use this trait when you need an instance allocator. Instead use the InstanceAllocator trait for that, which has additional helper methods and a blanket implementation for all types that implement this trait.

§Safety

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

Required Methods§

source

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

Validate whether a module is allocatable by this instance allocator.

source

fn increment_component_instance_count(&self) -> Result<()>

Increment the count of concurrent component instances that are currently allocated, if applicable.

Not all instance allocators will have limits for the maximum number of concurrent component instances that can be live at the same time, and these allocators may implement this method with a no-op.

source

fn decrement_component_instance_count(&self)

The dual of increment_component_instance_count.

source

fn increment_core_instance_count(&self) -> Result<()>

Increment the count of concurrent core module instances that are currently allocated, if applicable.

Not all instance allocators will have limits for the maximum number of concurrent core module instances that can be live at the same time, and these allocators may implement this method with a no-op.

source

fn decrement_core_instance_count(&self)

The dual of increment_core_instance_count.

source

unsafe fn allocate_memory( &self, request: &mut InstanceAllocationRequest<'_>, memory_plan: &MemoryPlan, memory_index: DefinedMemoryIndex ) -> Result<(MemoryAllocationIndex, Memory)>

Allocate a memory for an instance.

§Unsafety

The memory and its associated module must have already been validated by Self::validate_module and passed that validation.

source

unsafe fn deallocate_memory( &self, memory_index: DefinedMemoryIndex, allocation_index: MemoryAllocationIndex, memory: Memory )

Deallocate an instance’s previously allocated memory.

§Unsafety

The memory must have previously been allocated by Self::allocate_memory, be at the given index, and must currently be allocated. It must never be used again.

source

unsafe fn allocate_table( &self, req: &mut InstanceAllocationRequest<'_>, table_plan: &TablePlan, table_index: DefinedTableIndex ) -> Result<(TableAllocationIndex, Table)>

Allocate a table for an instance.

§Unsafety

The table and its associated module must have already been validated by Self::validate_module and passed that validation.

source

unsafe fn deallocate_table( &self, table_index: DefinedTableIndex, allocation_index: TableAllocationIndex, table: Table )

Deallocate an instance’s previously allocated table.

§Unsafety

The table must have previously been allocated by Self::allocate_table, be at the given index, and must currently be allocated. It must never be used again.

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.

source

fn next_available_pkey(&self) -> Option<ProtectionKey>

Use the next available protection key.

The pooling allocator can use memory protection keys (MPK) for compressing the guard regions protecting against OOB. Each pool-allocated store needs its own key.

source

fn restrict_to_pkey(&self, pkey: ProtectionKey)

Restrict access to memory regions protected by pkey.

This is useful for the pooling allocator, which can use memory protection keys (MPK). Note: this may still allow access to other protection keys, such as the default kernel key; see implementations of this.

source

fn allow_all_pkeys(&self)

Allow access to memory regions protected by any protection key.

Implementors§