#[repr(C)]
pub struct Instance { /* private fields */ }
Expand description

A type that roughly corresponds to a WebAssembly instance, but is also used for host-defined objects.

This structure is is never allocated directly but is instead managed through an InstanceHandle. This structure ends with a VMContext which has a dynamic size corresponding to the module configured within. Memory management of this structure is always externalized.

Instances here can correspond to actual instantiated modules, but it’s also used ubiquitously for host-defined objects. For example creating a host-defined memory will have a module that looks like it exports a single memory (and similar for other constructs).

This Instance type is used as a ubiquitous representation for WebAssembly values, whether or not they were created on the host or through a module.

Implementations§

source§

impl Instance

source

pub unsafe fn from_vmctx<R>( vmctx: *mut VMContext, f: impl FnOnce(&mut Instance) -> R ) -> R

Converts the provided *mut VMContext to an Instance pointer and runs the provided closure with the instance.

This method will move the vmctx pointer backwards to point to the original Instance that precedes it. The closure is provided a temporary version of the Instance pointer with a constrained lifetime to the closure to ensure it doesn’t accidentally escape.

Unsafety

Callers must validate that the vmctx pointer is a valid allocation and that it’s valid to acquire &mut Instance at this time. For example this can’t be called twice on the same VMContext to get two active pointers to the same Instance.

source

pub fn defined_memories<'a>( &'a self ) -> impl ExactSizeIterator<Item = (DefinedMemoryIndex, &'a Memory)> + 'a

Return the memories defined within this instance (not imported).

source

pub fn all_globals<'a>( &'a mut self ) -> impl ExactSizeIterator<Item = (GlobalIndex, ExportGlobal)> + 'a

Get all globals within this instance.

Returns both import and defined globals.

Returns both exported and non-exported globals.

Gives access to the full globals space.

source

pub fn defined_globals<'a>( &'a mut self ) -> impl ExactSizeIterator<Item = (DefinedGlobalIndex, ExportGlobal)> + 'a

Get the globals defined in this instance (not imported).

source

pub fn runtime_limits(&mut self) -> *mut *const VMRuntimeLimits

Return a pointer to the interrupts structure

source

pub fn epoch_ptr(&mut self) -> *mut *const AtomicU64

Return a pointer to the global epoch counter used by this instance.

source

pub fn externref_activations_table( &mut self ) -> *mut *mut VMExternRefActivationsTable

Return a pointer to the VMExternRefActivationsTable.

source

pub fn store(&self) -> *mut dyn Store

Gets a pointer to this instance’s Store which was originally configured on creation.

Panics

This will panic if the originally configured store was None. That can happen for host functions so host functions can’t be queried what their original Store was since it’s just retained as null (since host functions are shared amongst threads and don’t all share the same store).

source

pub fn vmctx(&self) -> *mut VMContext

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

source

pub fn exports(&self) -> Iter<'_, String, EntityIndex>

Return an iterator over the exports of this instance.

Specifically, it provides access to the key-value pairs, where the keys are export names, and the values are export declarations which can be resolved lookup_by_declaration.

source

pub fn host_state(&self) -> &dyn Any

Return a reference to the custom state attached to this instance.

source

pub unsafe fn table_index( &mut self, table: &VMTableDefinition ) -> DefinedTableIndex

Return the table index for the given VMTableDefinition.

source

pub fn get_defined_memory(&mut self, index: DefinedMemoryIndex) -> *mut Memory

Get a locally-defined memory.

source

pub fn get_defined_table_with_lazy_init( &mut self, idx: DefinedTableIndex, range: impl Iterator<Item = u32> ) -> *mut Table

Gets the raw runtime table data structure owned by this instance given the provided idx.

The range specified is eagerly initialized for funcref tables.

Trait Implementations§

source§

impl Drop for Instance

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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, U> TryFrom<U> for Twhere 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 Twhere 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.