#[repr(C)]pub(crate) struct Instance {Show 14 fields
module: Arc<ModuleInfo>,
context: *mut StoreObjects,
offsets: VMOffsets,
memories: BoxedSlice<LocalMemoryIndex, InternalStoreHandle<VMMemory>>,
tables: BoxedSlice<LocalTableIndex, InternalStoreHandle<VMTable>>,
globals: BoxedSlice<LocalGlobalIndex, InternalStoreHandle<VMGlobal>>,
tags: BoxedSlice<TagIndex, InternalStoreHandle<VMTag>>,
functions: BoxedSlice<LocalFunctionIndex, FunctionBodyPtr>,
function_call_trampolines: BoxedSlice<SignatureIndex, VMTrampoline>,
passive_elements: RefCell<HashMap<ElemIndex, Box<[Option<VMFuncRef>]>>>,
passive_data: RefCell<HashMap<DataIndex, Arc<[u8]>>>,
funcrefs: BoxedSlice<LocalFunctionIndex, VMCallerCheckedAnyfunc>,
imported_funcrefs: BoxedSlice<FunctionIndex, NonNull<VMCallerCheckedAnyfunc>>,
vmctx: VMContext,
}Expand description
A WebAssembly instance.
The type is dynamically-sized. Indeed, the vmctx field can
contain various data. That’s why the type has a C representation
to ensure that the vmctx field is last. See the documentation of
the vmctx field to learn more.
Fields§
§module: Arc<ModuleInfo>The ModuleInfo this Instance was instantiated from.
context: *mut StoreObjectsPointer to the object store of the context owning this instance.
offsets: VMOffsetsOffsets in the vmctx region.
memories: BoxedSlice<LocalMemoryIndex, InternalStoreHandle<VMMemory>>WebAssembly linear memory data.
tables: BoxedSlice<LocalTableIndex, InternalStoreHandle<VMTable>>WebAssembly table data.
globals: BoxedSlice<LocalGlobalIndex, InternalStoreHandle<VMGlobal>>WebAssembly global data.
WebAssembly tag data. Notably, this stores all tags, not just local ones.
functions: BoxedSlice<LocalFunctionIndex, FunctionBodyPtr>Pointers to functions in executable memory.
function_call_trampolines: BoxedSlice<SignatureIndex, VMTrampoline>Pointers to function call trampolines in executable memory.
passive_elements: RefCell<HashMap<ElemIndex, Box<[Option<VMFuncRef>]>>>Passive elements in this instantiation. As elem.drops happen, these
entries get removed.
passive_data: RefCell<HashMap<DataIndex, Arc<[u8]>>>Passive data segments from our module. As data.drops happen, entries
get removed. A missing entry is considered equivalent to an empty slice.
funcrefs: BoxedSlice<LocalFunctionIndex, VMCallerCheckedAnyfunc>Mapping of function indices to their func ref backing data. VMFuncRefs
will point to elements here for functions defined by this instance.
imported_funcrefs: BoxedSlice<FunctionIndex, NonNull<VMCallerCheckedAnyfunc>>Mapping of function indices to their func ref backing data. VMFuncRefs
will point to elements here for functions imported by this instance.
vmctx: VMContextAdditional context used by compiled WebAssembly code. This field is last, and represents a dynamically-sized array that extends beyond the nominal end of the struct (similar to a flexible array member).
Implementations§
Source§impl Instance
impl Instance
Sourceunsafe fn vmctx_plus_offset<T>(&self, offset: u32) -> *mut T
unsafe fn vmctx_plus_offset<T>(&self, offset: u32) -> *mut T
Helper function to access various locations offset from our *mut VMContext object.
fn module(&self) -> &Arc<ModuleInfo>
pub(crate) fn module_ref(&self) -> &ModuleInfo
pub(crate) fn context(&self) -> &StoreObjects
pub(crate) fn context_mut(&mut self) -> &mut StoreObjects
Sourcefn signature_ids_ptr(&self) -> *mut VMSharedSignatureIndex
fn signature_ids_ptr(&self) -> *mut VMSharedSignatureIndex
Return a pointer to the VMSharedSignatureIndexs.
Sourcefn imported_function(&self, index: FunctionIndex) -> &VMFunctionImport
fn imported_function(&self, index: FunctionIndex) -> &VMFunctionImport
Return the indexed VMFunctionImport.
Sourcefn imported_functions_ptr(&self) -> *mut VMFunctionImport
fn imported_functions_ptr(&self) -> *mut VMFunctionImport
Return a pointer to the VMFunctionImports.
Sourcefn imported_table(&self, index: TableIndex) -> &VMTableImport
fn imported_table(&self, index: TableIndex) -> &VMTableImport
Return the index VMTableImport.
Sourcefn imported_tables_ptr(&self) -> *mut VMTableImport
fn imported_tables_ptr(&self) -> *mut VMTableImport
Return a pointer to the VMTableImportss.
Sourcefn imported_memory(&self, index: MemoryIndex) -> &VMMemoryImport
fn imported_memory(&self, index: MemoryIndex) -> &VMMemoryImport
Return the indexed VMMemoryImport.
Sourcefn imported_memories_ptr(&self) -> *mut VMMemoryImport
fn imported_memories_ptr(&self) -> *mut VMMemoryImport
Return a pointer to the VMMemoryImports.
Sourcefn imported_global(&self, index: GlobalIndex) -> &VMGlobalImport
fn imported_global(&self, index: GlobalIndex) -> &VMGlobalImport
Return the indexed VMGlobalImport.
Sourcefn imported_globals_ptr(&self) -> *mut VMGlobalImport
fn imported_globals_ptr(&self) -> *mut VMGlobalImport
Return a pointer to the VMGlobalImports.
Return the indexed VMSharedTagIndex.
Return a pointer to the VMSharedTagIndexs.
Sourcefn table(&self, index: LocalTableIndex) -> VMTableDefinition
fn table(&self, index: LocalTableIndex) -> VMTableDefinition
Return the indexed VMTableDefinition.
Sourcefn set_table(&self, index: LocalTableIndex, table: &VMTableDefinition)
fn set_table(&self, index: LocalTableIndex, table: &VMTableDefinition)
Updates the value for a defined table to VMTableDefinition.
Sourcefn table_ptr(&self, index: LocalTableIndex) -> NonNull<VMTableDefinition>
fn table_ptr(&self, index: LocalTableIndex) -> NonNull<VMTableDefinition>
Return the indexed VMTableDefinition.
Sourcefn tables_ptr(&self) -> *mut VMTableDefinition
fn tables_ptr(&self) -> *mut VMTableDefinition
Return a pointer to the VMTableDefinitions.
Sourcefn get_memory(&self, index: MemoryIndex) -> VMMemoryDefinition
fn get_memory(&self, index: MemoryIndex) -> VMMemoryDefinition
Get a locally defined or imported memory.
Sourcefn memory(&self, index: LocalMemoryIndex) -> VMMemoryDefinition
fn memory(&self, index: LocalMemoryIndex) -> VMMemoryDefinition
Return the indexed VMMemoryDefinition.
Sourcefn set_memory(&self, index: LocalMemoryIndex, mem: &VMMemoryDefinition)
fn set_memory(&self, index: LocalMemoryIndex, mem: &VMMemoryDefinition)
Set the indexed memory to VMMemoryDefinition.
Sourcefn memory_ptr(&self, index: LocalMemoryIndex) -> NonNull<VMMemoryDefinition>
fn memory_ptr(&self, index: LocalMemoryIndex) -> NonNull<VMMemoryDefinition>
Return the indexed VMMemoryDefinition.
Sourcefn memories_ptr(&self) -> *mut VMMemoryDefinition
fn memories_ptr(&self) -> *mut VMMemoryDefinition
Return a pointer to the VMMemoryDefinitions.
Sourcefn get_vmmemory(&self, index: MemoryIndex) -> &VMMemory
fn get_vmmemory(&self, index: MemoryIndex) -> &VMMemory
Get a locally defined or imported memory.
Sourcefn get_vmmemory_mut(&mut self, index: MemoryIndex) -> &mut VMMemory
fn get_vmmemory_mut(&mut self, index: MemoryIndex) -> &mut VMMemory
Get a locally defined or imported memory.
Sourcefn get_local_vmmemory_mut(
&mut self,
local_index: LocalMemoryIndex,
) -> &mut VMMemory
fn get_local_vmmemory_mut( &mut self, local_index: LocalMemoryIndex, ) -> &mut VMMemory
Get a locally defined memory as mutable.
Sourcefn global(&self, index: LocalGlobalIndex) -> VMGlobalDefinition
fn global(&self, index: LocalGlobalIndex) -> VMGlobalDefinition
Return the indexed VMGlobalDefinition.
Sourcefn set_global(&self, index: LocalGlobalIndex, global: &VMGlobalDefinition)
fn set_global(&self, index: LocalGlobalIndex, global: &VMGlobalDefinition)
Set the indexed global to VMGlobalDefinition.
Sourcefn global_ptr(&self, index: LocalGlobalIndex) -> NonNull<VMGlobalDefinition>
fn global_ptr(&self, index: LocalGlobalIndex) -> NonNull<VMGlobalDefinition>
Return the indexed VMGlobalDefinition.
Sourcefn globals_ptr(&self) -> *mut *mut VMGlobalDefinition
fn globals_ptr(&self) -> *mut *mut VMGlobalDefinition
Return a pointer to the VMGlobalDefinitions.
Sourcefn builtin_functions_ptr(&self) -> *mut VMBuiltinFunctionsArray
fn builtin_functions_ptr(&self) -> *mut VMBuiltinFunctionsArray
Return a pointer to the VMBuiltinFunctionsArray.
Sourcefn vmctx_ptr(&self) -> *mut VMContext
fn vmctx_ptr(&self) -> *mut VMContext
Return a raw pointer to the vmctx used by compiled wasm code.
Sourcefn invoke_start_function(
&self,
config: &VMConfig,
trap_handler: Option<*const TrapHandlerFn<'static>>,
) -> Result<(), Trap>
fn invoke_start_function( &self, config: &VMConfig, trap_handler: Option<*const TrapHandlerFn<'static>>, ) -> Result<(), Trap>
Invoke the WebAssembly start function of the instance, if one is present.
Sourcepub(crate) fn vmctx_offset() -> isize
pub(crate) fn vmctx_offset() -> isize
Return the offset from the vmctx pointer to its containing Instance.
Sourcepub(crate) fn table_index(&self, table: &VMTableDefinition) -> LocalTableIndex
pub(crate) fn table_index(&self, table: &VMTableDefinition) -> LocalTableIndex
Return the table index for the given VMTableDefinition.
Sourcepub(crate) fn memory_index(
&self,
memory: &VMMemoryDefinition,
) -> LocalMemoryIndex
pub(crate) fn memory_index( &self, memory: &VMMemoryDefinition, ) -> LocalMemoryIndex
Return the memory index for the given VMMemoryDefinition.
Sourcepub(crate) fn memory_grow<IntoPages>(
&mut self,
memory_index: LocalMemoryIndex,
delta: IntoPages,
) -> Result<Pages, MemoryError>where
IntoPages: Into<Pages>,
pub(crate) fn memory_grow<IntoPages>(
&mut self,
memory_index: LocalMemoryIndex,
delta: IntoPages,
) -> Result<Pages, MemoryError>where
IntoPages: Into<Pages>,
Grow memory by the specified amount of pages.
Returns None if memory can’t be grown by the specified amount
of pages.
Sourcepub(crate) unsafe fn imported_memory_grow<IntoPages>(
&mut self,
memory_index: MemoryIndex,
delta: IntoPages,
) -> Result<Pages, MemoryError>where
IntoPages: Into<Pages>,
pub(crate) unsafe fn imported_memory_grow<IntoPages>(
&mut self,
memory_index: MemoryIndex,
delta: IntoPages,
) -> Result<Pages, MemoryError>where
IntoPages: Into<Pages>,
Grow imported memory by the specified amount of pages.
Returns None if memory can’t be grown by the specified amount
of pages.
§Safety
This and imported_memory_size are currently unsafe because they
dereference the memory import’s pointers.
Sourcepub(crate) fn memory_size(&self, memory_index: LocalMemoryIndex) -> Pages
pub(crate) fn memory_size(&self, memory_index: LocalMemoryIndex) -> Pages
Returns the number of allocated wasm pages.
Sourcepub(crate) unsafe fn imported_memory_size(
&self,
memory_index: MemoryIndex,
) -> Pages
pub(crate) unsafe fn imported_memory_size( &self, memory_index: MemoryIndex, ) -> Pages
Returns the number of allocated wasm pages in an imported memory.
§Safety
This and imported_memory_grow are currently unsafe because they
dereference the memory import’s pointers.
Sourcepub(crate) fn table_size(&self, table_index: LocalTableIndex) -> u32
pub(crate) fn table_size(&self, table_index: LocalTableIndex) -> u32
Returns the number of elements in a given table.
Sourcepub(crate) unsafe fn imported_table_size(&self, table_index: TableIndex) -> u32
pub(crate) unsafe fn imported_table_size(&self, table_index: TableIndex) -> u32
Returns the number of elements in a given imported table.
§Safety
table_index must be a valid, imported table index.
Sourcepub(crate) fn table_grow(
&mut self,
table_index: LocalTableIndex,
delta: u32,
init_value: TableElement,
) -> Option<u32>
pub(crate) fn table_grow( &mut self, table_index: LocalTableIndex, delta: u32, init_value: TableElement, ) -> Option<u32>
Grow table by the specified amount of elements.
Returns None if table can’t be grown by the specified amount
of elements.
Sourcepub(crate) unsafe fn imported_table_grow(
&mut self,
table_index: TableIndex,
delta: u32,
init_value: TableElement,
) -> Option<u32>
pub(crate) unsafe fn imported_table_grow( &mut self, table_index: TableIndex, delta: u32, init_value: TableElement, ) -> Option<u32>
Grow table by the specified amount of elements.
§Safety
table_index must be a valid, imported table index.
Sourcepub(crate) fn table_get(
&self,
table_index: LocalTableIndex,
index: u32,
) -> Option<TableElement>
pub(crate) fn table_get( &self, table_index: LocalTableIndex, index: u32, ) -> Option<TableElement>
Get table element by index.
Sourcepub(crate) unsafe fn imported_table_get(
&self,
table_index: TableIndex,
index: u32,
) -> Option<TableElement>
pub(crate) unsafe fn imported_table_get( &self, table_index: TableIndex, index: u32, ) -> Option<TableElement>
Sourcepub(crate) fn table_set(
&mut self,
table_index: LocalTableIndex,
index: u32,
val: TableElement,
) -> Result<(), Trap>
pub(crate) fn table_set( &mut self, table_index: LocalTableIndex, index: u32, val: TableElement, ) -> Result<(), Trap>
Set table element by index.
Sourcepub(crate) unsafe fn imported_table_set(
&mut self,
table_index: TableIndex,
index: u32,
val: TableElement,
) -> Result<(), Trap>
pub(crate) unsafe fn imported_table_set( &mut self, table_index: TableIndex, index: u32, val: TableElement, ) -> Result<(), Trap>
Set table element by index for an imported table.
§Safety
table_index must be a valid, imported table index.
Sourcepub(crate) fn func_ref(
&self,
function_index: FunctionIndex,
) -> Option<VMFuncRef>
pub(crate) fn func_ref( &self, function_index: FunctionIndex, ) -> Option<VMFuncRef>
Get a VMFuncRef for the given FunctionIndex.
Sourcepub(crate) fn table_init(
&mut self,
table_index: TableIndex,
elem_index: ElemIndex,
dst: u32,
src: u32,
len: u32,
) -> Result<(), Trap>
pub(crate) fn table_init( &mut self, table_index: TableIndex, elem_index: ElemIndex, dst: u32, src: u32, len: u32, ) -> Result<(), Trap>
The table.init operation: initializes a portion of a table with a
passive element.
§Errors
Returns a Trap error when the range within the table is out of bounds
or the range within the passive element is out of bounds.
Sourcepub(crate) fn table_fill(
&mut self,
table_index: TableIndex,
start_index: u32,
item: TableElement,
len: u32,
) -> Result<(), Trap>
pub(crate) fn table_fill( &mut self, table_index: TableIndex, start_index: u32, item: TableElement, len: u32, ) -> Result<(), Trap>
The table.fill operation: fills a portion of a table with a given value.
§Errors
Returns a Trap error when the range within the table is out of bounds
Sourcepub(crate) fn local_memory_copy(
&self,
memory_index: LocalMemoryIndex,
dst: u32,
src: u32,
len: u32,
) -> Result<(), Trap>
pub(crate) fn local_memory_copy( &self, memory_index: LocalMemoryIndex, dst: u32, src: u32, len: u32, ) -> Result<(), Trap>
Do a memory.copy for a locally defined memory.
§Errors
Returns a Trap error when the source or destination ranges are out of
bounds.
Sourcepub(crate) fn imported_memory_copy(
&self,
memory_index: MemoryIndex,
dst: u32,
src: u32,
len: u32,
) -> Result<(), Trap>
pub(crate) fn imported_memory_copy( &self, memory_index: MemoryIndex, dst: u32, src: u32, len: u32, ) -> Result<(), Trap>
Perform a memory.copy on an imported memory.
Sourcepub(crate) fn local_memory_fill(
&self,
memory_index: LocalMemoryIndex,
dst: u32,
val: u32,
len: u32,
) -> Result<(), Trap>
pub(crate) fn local_memory_fill( &self, memory_index: LocalMemoryIndex, dst: u32, val: u32, len: u32, ) -> Result<(), Trap>
Perform the memory.fill operation on a locally defined memory.
§Errors
Returns a Trap error if the memory range is out of bounds.
Sourcepub(crate) fn imported_memory_fill(
&self,
memory_index: MemoryIndex,
dst: u32,
val: u32,
len: u32,
) -> Result<(), Trap>
pub(crate) fn imported_memory_fill( &self, memory_index: MemoryIndex, dst: u32, val: u32, len: u32, ) -> Result<(), Trap>
Perform the memory.fill operation on an imported memory.
§Errors
Returns a Trap error if the memory range is out of bounds.
Sourcepub(crate) fn memory_init(
&self,
memory_index: MemoryIndex,
data_index: DataIndex,
dst: u32,
src: u32,
len: u32,
) -> Result<(), Trap>
pub(crate) fn memory_init( &self, memory_index: MemoryIndex, data_index: DataIndex, dst: u32, src: u32, len: u32, ) -> Result<(), Trap>
Performs the memory.init operation.
§Errors
Returns a Trap error if the destination range is out of this module’s
memory’s bounds or if the source range is outside the data segment’s
bounds.
Sourcepub(crate) fn data_drop(&self, data_index: DataIndex)
pub(crate) fn data_drop(&self, data_index: DataIndex)
Drop the given data segment, truncating its length to zero.
Sourcepub(crate) fn get_table(&mut self, table_index: TableIndex) -> &mut VMTable
pub(crate) fn get_table(&mut self, table_index: TableIndex) -> &mut VMTable
Get a table by index regardless of whether it is locally-defined or an imported, foreign table.
Sourcepub(crate) fn get_local_table(&mut self, index: LocalTableIndex) -> &mut VMTable
pub(crate) fn get_local_table(&mut self, index: LocalTableIndex) -> &mut VMTable
Get a locally-defined table.
Sourcepub(crate) fn get_foreign_table(&mut self, index: TableIndex) -> &mut VMTable
pub(crate) fn get_foreign_table(&mut self, index: TableIndex) -> &mut VMTable
Get an imported, foreign table.
Sourcepub(crate) fn get_table_handle(
&mut self,
table_index: TableIndex,
) -> InternalStoreHandle<VMTable>
pub(crate) fn get_table_handle( &mut self, table_index: TableIndex, ) -> InternalStoreHandle<VMTable>
Get a table handle by index regardless of whether it is locally-defined or an imported, foreign table.
Sourceunsafe fn memory_wait(
memory: &mut VMMemory,
dst: u32,
expected: ExpectedValue,
timeout: i64,
) -> Result<u32, Trap>
unsafe fn memory_wait( memory: &mut VMMemory, dst: u32, expected: ExpectedValue, timeout: i64, ) -> Result<u32, Trap>
§Safety
Sourcepub(crate) fn local_memory_wait32(
&mut self,
memory_index: LocalMemoryIndex,
dst: u32,
val: u32,
timeout: i64,
) -> Result<u32, Trap>
pub(crate) fn local_memory_wait32( &mut self, memory_index: LocalMemoryIndex, dst: u32, val: u32, timeout: i64, ) -> Result<u32, Trap>
Perform an Atomic.Wait32
Sourcepub(crate) fn imported_memory_wait32(
&mut self,
memory_index: MemoryIndex,
dst: u32,
val: u32,
timeout: i64,
) -> Result<u32, Trap>
pub(crate) fn imported_memory_wait32( &mut self, memory_index: MemoryIndex, dst: u32, val: u32, timeout: i64, ) -> Result<u32, Trap>
Perform an Atomic.Wait32
Sourcepub(crate) fn local_memory_wait64(
&mut self,
memory_index: LocalMemoryIndex,
dst: u32,
val: u64,
timeout: i64,
) -> Result<u32, Trap>
pub(crate) fn local_memory_wait64( &mut self, memory_index: LocalMemoryIndex, dst: u32, val: u64, timeout: i64, ) -> Result<u32, Trap>
Perform an Atomic.Wait64
Sourcepub(crate) fn imported_memory_wait64(
&mut self,
memory_index: MemoryIndex,
dst: u32,
val: u64,
timeout: i64,
) -> Result<u32, Trap>
pub(crate) fn imported_memory_wait64( &mut self, memory_index: MemoryIndex, dst: u32, val: u64, timeout: i64, ) -> Result<u32, Trap>
Perform an Atomic.Wait64
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Instance
impl !RefUnwindSafe for Instance
impl !Send for Instance
impl !Sync for Instance
impl Unpin for Instance
impl !UnwindSafe for Instance
Blanket Implementations§
§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
§type ArchivedMetadata = ()
type ArchivedMetadata = ()
§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more