Struct wasmer_vm::instance::Instance

source ·
#[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.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: 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

fn context(&self) -> &StoreObjects

source

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

source

fn offsets(&self) -> &VMOffsets

Offsets in the vmctx region.

source

fn signature_ids_ptr(&self) -> *mut VMSharedSignatureIndex

Return a pointer to the VMSharedSignatureIndexs.

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

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 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 *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 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

fn memory_wait( memory: &mut VMMemory, dst: u32, 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.

§

impl<T> LayoutRaw for T

§

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

Returns the layout of the type.
§

impl<T> Pointee for T

§

type Metadata = ()

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

impl<T> Same for T

§

type Output = T

Should always be Self
source§

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

§

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>,

§

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.