#[repr(C)]pub(crate) struct Instance {Show 13 fields
module: Arc<ModuleInfo>,
context: *mut StoreObjects,
offsets: VMOffsets,
memories: BoxedSlice<LocalMemoryIndex, InternalStoreHandle<VMMemory>>,
tables: BoxedSlice<LocalTableIndex, InternalStoreHandle<VMTable>>,
globals: BoxedSlice<LocalGlobalIndex, InternalStoreHandle<VMGlobal>>,
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 StoreObjects
Pointer to the object store of the context owning this instance.
offsets: VMOffsets
Offsets 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.
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.drop
s happen, these
entries get removed.
passive_data: RefCell<HashMap<DataIndex, Arc<[u8]>>>
Passive data segments from our module. As data.drop
s 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. VMFuncRef
s
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. VMFuncRef
s
will point to elements here for functions imported by this instance.
vmctx: VMContext
Additional 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
fn context(&self) -> &StoreObjects
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 VMSharedSignatureIndex
s.
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 VMFunctionImport
s.
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 VMTableImports
s.
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 VMMemoryImport
s.
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 VMGlobalImport
s.
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 VMTableDefinition
s.
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 VMMemoryDefinition
s.
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 VMGlobalDefinition
s.
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.
fn memory_wait( memory: &mut VMMemory, dst: u32, timeout: i64, ) -> Result<u32, Trap>
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