Instance

Struct Instance 

Source
#[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, Option<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.

§tags: BoxedSlice<TagIndex, InternalStoreHandle<VMTag>>

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, Option<Arc<[u8]>>>>

Per-instance view of the module’s passive data segments.

A None entry (dropped) or a missing entry is treated as an empty slice.

The bytes are shared with the module via Arc (no per-instance copy). data.drop replaces an entry’s value with None to mark the segment unusable for subsequent memory.init on this instance, without affecting the shared module bytes or any other instance.

§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: 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

Source

unsafe fn vmctx_plus_offset<T>(&self, offset: u32) -> *mut T

Helper function to access various locations offset from our *mut VMContext object.

Source

fn module(&self) -> &Arc<ModuleInfo>

Source

pub(crate) fn module_ref(&self) -> &ModuleInfo

Source

pub(crate) fn context(&self) -> &StoreObjects

Source

pub(crate) fn context_mut(&mut self) -> &mut StoreObjects

Source

fn offsets(&self) -> &VMOffsets

Offsets in the vmctx region.

Source

fn imported_function(&self, index: FunctionIndex) -> &VMFunctionImport

Return the indexed VMFunctionImport.

Source

fn imported_functions_ptr(&self) -> *mut VMFunctionImport

Return a pointer to the VMFunctionImports.

Source

fn imported_table(&self, index: TableIndex) -> &VMTableImport

Return the index VMTableImport.

Source

fn imported_tables_ptr(&self) -> *mut VMTableImport

Return a pointer to the VMTableImportss.

Source

fn imported_memory(&self, index: MemoryIndex) -> &VMMemoryImport

Return the indexed VMMemoryImport.

Source

fn imported_memories_ptr(&self) -> *mut VMMemoryImport

Return a pointer to the VMMemoryImports.

Source

fn imported_global(&self, index: GlobalIndex) -> &VMGlobalImport

Return the indexed VMGlobalImport.

Source

fn imported_globals_ptr(&self) -> *mut VMGlobalImport

Return a pointer to the VMGlobalImports.

Source

pub(crate) fn shared_tag_ptr(&self, index: TagIndex) -> &VMSharedTagIndex

Return the indexed VMSharedTagIndex.

Source

pub(crate) fn shared_tags_ptr(&self) -> *mut VMSharedTagIndex

Return a pointer to the VMSharedTagIndexs.

Source

fn table(&self, index: LocalTableIndex) -> VMTableDefinition

Return the indexed VMTableDefinition.

Source

fn set_table(&self, index: LocalTableIndex, table: &VMTableDefinition)

Updates the value for a defined table to VMTableDefinition.

Source

fn table_ptr(&self, index: LocalTableIndex) -> NonNull<VMTableDefinition>

Return the indexed VMTableDefinition.

Source

fn tables_ptr(&self) -> *mut VMTableDefinition

Return a pointer to the VMTableDefinitions.

Source

fn fixed_funcref_table_ptr( &self, index: LocalTableIndex, ) -> Option<NonNull<VMCallerCheckedAnyfunc>>

Source

fn sync_fixed_funcref_table_element( &self, table_index: LocalTableIndex, index: u32, funcref: Option<VMFuncRef>, )

Source

fn sync_fixed_funcref_table(&self, table_index: LocalTableIndex)

Source

fn sync_fixed_funcref_table_by_index(&self, table_index: TableIndex)

Source

fn get_memory(&self, index: MemoryIndex) -> VMMemoryDefinition

Get a locally defined or imported memory.

Source

fn memory(&self, index: LocalMemoryIndex) -> VMMemoryDefinition

Return the indexed VMMemoryDefinition.

Source

fn set_memory(&self, index: LocalMemoryIndex, mem: &VMMemoryDefinition)

Set the indexed memory to VMMemoryDefinition.

Source

fn memory_ptr(&self, index: LocalMemoryIndex) -> NonNull<VMMemoryDefinition>

Return the indexed VMMemoryDefinition.

Source

fn memories_ptr(&self) -> *mut VMMemoryDefinition

Return a pointer to the VMMemoryDefinitions.

Source

fn get_vmmemory(&self, index: MemoryIndex) -> &VMMemory

Get a locally defined or imported memory.

Source

fn get_vmmemory_mut(&mut self, index: MemoryIndex) -> &mut VMMemory

Get a locally defined or imported memory.

Source

fn get_local_vmmemory_mut( &mut self, local_index: LocalMemoryIndex, ) -> &mut VMMemory

Get a locally defined memory as mutable.

Source

fn global(&self, index: LocalGlobalIndex) -> VMGlobalDefinition

Return the indexed VMGlobalDefinition.

Source

fn set_global(&self, index: LocalGlobalIndex, global: &VMGlobalDefinition)

Set the indexed global to VMGlobalDefinition.

Source

fn global_ptr(&self, index: LocalGlobalIndex) -> NonNull<VMGlobalDefinition>

Return the indexed VMGlobalDefinition.

Source

fn globals_ptr(&self) -> *mut VMGlobalDefinition

Return a pointer to the VMGlobalDefinitions.

Source

fn builtin_functions_ptr(&self) -> *mut VMBuiltinFunctionsArray

Return a pointer to the VMBuiltinFunctionsArray.

Source

fn vmctx(&self) -> &VMContext

Return a reference to the vmctx used by compiled wasm code.

Source

fn vmctx_ptr(&self) -> *mut VMContext

Return a raw pointer to the vmctx used by compiled wasm code.

Source

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.

Source

pub(crate) fn vmctx_offset() -> isize

Return the offset from the vmctx pointer to its containing Instance.

Source

pub(crate) fn table_index(&self, table: &VMTableDefinition) -> LocalTableIndex

Return the table index for the given VMTableDefinition.

Source

pub(crate) fn memory_index( &self, memory: &VMMemoryDefinition, ) -> LocalMemoryIndex

Return the memory index for the given VMMemoryDefinition.

Source

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.

Source

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.

Source

pub(crate) fn memory_size(&self, memory_index: LocalMemoryIndex) -> Pages

Returns the number of allocated wasm pages.

Source

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.

Source

pub(crate) fn table_size(&self, table_index: LocalTableIndex) -> u32

Returns the number of elements in a given table.

Source

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.

Source

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.

Source

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.

Source

pub(crate) fn table_get( &self, table_index: LocalTableIndex, index: u32, ) -> Option<TableElement>

Get table element by index.

Source

pub(crate) unsafe fn imported_table_get( &self, table_index: TableIndex, index: u32, ) -> Option<TableElement>

Returns the element at the given index.

§Safety

table_index must be a valid, imported table index.

Source

pub(crate) fn table_set( &mut self, table_index: LocalTableIndex, index: u32, val: TableElement, ) -> Result<(), Trap>

Set table element by index.

Source

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.

Source

pub(crate) fn func_ref( &self, function_index: FunctionIndex, ) -> Option<VMFuncRef>

Get a VMFuncRef for the given FunctionIndex.

Source

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.

Source

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

Source

pub(crate) fn table_copy( &mut self, dst_table_index: TableIndex, src_table_index: TableIndex, dst: u32, src: u32, len: u32, ) -> Result<(), Trap>

The table.copy operation.

Source

pub(crate) fn elem_drop(&self, elem_index: ElemIndex)

Drop an element.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub(crate) fn data_drop(&self, data_index: DataIndex)

Drop the given data segment, truncating its length to zero.

Source

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.

Source

pub(crate) fn get_local_table(&mut self, index: LocalTableIndex) -> &mut VMTable

Get a locally-defined table.

Source

pub(crate) fn get_foreign_table(&mut self, index: TableIndex) -> &mut VMTable

Get an imported, foreign table.

Source

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.

Source

unsafe fn memory_wait( memory: &mut VMMemory, dst: u32, expected: ExpectedValue, timeout: i64, ) -> Result<u32, Trap>

Source

pub(crate) fn local_memory_wait32( &mut self, memory_index: LocalMemoryIndex, dst: u32, val: u32, timeout: i64, ) -> Result<u32, Trap>

Perform an Atomic.Wait32

Source

pub(crate) fn imported_memory_wait32( &mut self, memory_index: MemoryIndex, dst: u32, val: u32, timeout: i64, ) -> Result<u32, Trap>

Perform an Atomic.Wait32

Source

pub(crate) fn local_memory_wait64( &mut self, memory_index: LocalMemoryIndex, dst: u32, val: u64, timeout: i64, ) -> Result<u32, Trap>

Perform an Atomic.Wait64

Source

pub(crate) fn imported_memory_wait64( &mut self, memory_index: MemoryIndex, dst: u32, val: u64, timeout: i64, ) -> Result<u32, Trap>

Perform an Atomic.Wait64

Source

pub(crate) fn local_memory_notify( &mut self, memory_index: LocalMemoryIndex, dst: u32, count: u32, ) -> Result<u32, Trap>

Perform an Atomic.Notify

Source

pub(crate) fn imported_memory_notify( &mut self, memory_index: MemoryIndex, dst: u32, count: u32, ) -> Result<u32, Trap>

Perform an Atomic.Notify

Trait Implementations§

Source§

impl Debug for Instance

Source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> ArchivePointee for T

§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> LayoutRaw for T

§

fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>

Returns the layout of the type.
§

impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
where T: SharedNiching<N1, N2>, N1: Niching<T>, N2: Niching<T>,

§

unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool

Returns whether the given value has been niched. Read more
§

fn resolve_niched(out: Place<NichedOption<T, N1>>)

Writes data to out indicating that a T is niched.
§

impl<T> Pointee for T

§

type Metadata = ()

The metadata type for pointers and references to this type.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.