Struct InstanceHandle

Source
pub struct InstanceHandle { /* private fields */ }
Expand description

A handle holding an Instance of a WebAssembly module.

Implementations§

Source§

impl InstanceHandle

Source

pub unsafe fn new( module: Arc<Module>, finished_functions: BoxedSlice<DefinedFuncIndex, *mut [VMFunctionBody]>, trampolines: HashMap<VMSharedSignatureIndex, VMTrampoline>, imports: Imports, mem_creator: Option<&dyn RuntimeMemoryCreator>, vmshared_signatures: BoxedSlice<SignatureIndex, VMSharedSignatureIndex>, dbg_jit_registration: Option<Arc<GdbJitImageRegistration>>, host_state: Box<dyn Any>, interrupts: Arc<VMInterrupts>, ) -> Result<Self, InstantiationError>

Create a new InstanceHandle pointing at a new Instance.

§Unsafety

This method is not necessarily inherently unsafe to call, but in general the APIs of an Instance are quite unsafe and have not been really audited for safety that much. As a result the unsafety here on this method is a low-overhead way of saying “this is an extremely unsafe type to work with”.

Extreme care must be taken when working with InstanceHandle and it’s recommended to have relatively intimate knowledge of how it works internally if you’d like to do so. If possible it’s recommended to use the wasmtime crate API rather than this type since that is vetted for safety.

Source

pub unsafe fn initialize( &self, is_bulk_memory: bool, data_initializers: &[DataInitializer<'_>], ) -> Result<(), InstantiationError>

Finishes the instantiation process started by Instance::new.

Only safe to call immediately after instantiation.

Source

pub unsafe fn from_vmctx(vmctx: *mut VMContext) -> Self

Create a new InstanceHandle pointing at the instance pointed to by the given VMContext pointer.

§Safety

This is unsafe because it doesn’t work on just any VMContext, it must be a VMContext allocated as part of an Instance.

Source

pub fn vmctx(&self) -> &VMContext

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

Source

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

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

Source

pub fn module(&self) -> &Arc<Module>

Return a reference-counting pointer to a module.

Source

pub fn module_ref(&self) -> &Module

Return a reference to a module.

Source

pub fn lookup(&self, field: &str) -> Option<Export>

Lookup an export with the given name.

Source

pub fn lookup_by_declaration(&self, export: &EntityIndex) -> Export

Lookup an export with the given export declaration.

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 fn memory_index(&self, memory: &VMMemoryDefinition) -> DefinedMemoryIndex

Return the memory index for the given VMMemoryDefinition in this instance.

Source

pub fn memory_grow( &self, memory_index: DefinedMemoryIndex, delta: u32, ) -> Option<u32>

Grow memory in this instance by the specified amount of pages.

Returns None if memory can’t be grown by the specified amount of pages.

Source

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

Return the table index for the given VMTableDefinition in this instance.

Source

pub fn table_grow( &self, table_index: DefinedTableIndex, delta: u32, ) -> Option<u32>

Grow table in this instance by the specified amount of pages.

Returns None if memory can’t be grown by the specified amount of pages.

Source

pub fn table_get( &self, table_index: DefinedTableIndex, index: u32, ) -> Option<VMCallerCheckedAnyfunc>

Get table element reference.

Returns None if index is out of bounds.

Source

pub fn table_set( &self, table_index: DefinedTableIndex, index: u32, val: VMCallerCheckedAnyfunc, ) -> Result<(), ()>

Set table element reference.

Returns an error if the index is out of bounds

Source

pub fn get_defined_table(&self, index: DefinedTableIndex) -> &Table

Get a table defined locally within this module.

Source

pub fn trampoline(&self, sig: VMSharedSignatureIndex) -> Option<VMTrampoline>

Gets the trampoline pre-registered for a particular signature

Source

pub unsafe fn clone(&self) -> InstanceHandle

Returns a clone of this instance.

This is unsafe because the returned handle here is just a cheap clone of the internals, there’s no lifetime tracking around its validity. You’ll need to ensure that the returned handles all go out of scope at the same time.

Source

pub unsafe fn dealloc(&self)

Deallocates memory associated with this instance.

Note that this is unsafe because there might be other handles to this InstanceHandle elsewhere, and there’s nothing preventing usage of this handle after this function is called.

Trait Implementations§

Source§

impl Hash for InstanceHandle

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for InstanceHandle

Source§

fn eq(&self, other: &InstanceHandle) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for InstanceHandle

Source§

impl Send for InstanceHandle

Source§

impl StructuralPartialEq for InstanceHandle

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
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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.