pub struct InstanceHandle { /* private fields */ }
Expand description
A handle holding an Instance
of a WebAssembly module.
Implementations§
Source§impl InstanceHandle
impl InstanceHandle
Sourcepub 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>
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.
Sourcepub unsafe fn initialize(
&self,
is_bulk_memory: bool,
data_initializers: &[DataInitializer<'_>],
) -> Result<(), InstantiationError>
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.
Sourcepub unsafe fn from_vmctx(vmctx: *mut VMContext) -> Self
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
.
Sourcepub fn vmctx_ptr(&self) -> *mut VMContext
pub fn vmctx_ptr(&self) -> *mut VMContext
Return a raw pointer to the vmctx used by compiled wasm code.
Sourcepub fn module_ref(&self) -> &Module
pub fn module_ref(&self) -> &Module
Return a reference to a module.
Sourcepub fn lookup_by_declaration(&self, export: &EntityIndex) -> Export
pub fn lookup_by_declaration(&self, export: &EntityIndex) -> Export
Lookup an export with the given export declaration.
Sourcepub fn exports(&self) -> Iter<'_, String, EntityIndex>
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
.
Sourcepub fn host_state(&self) -> &dyn Any
pub fn host_state(&self) -> &dyn Any
Return a reference to the custom state attached to this instance.
Sourcepub fn memory_index(&self, memory: &VMMemoryDefinition) -> DefinedMemoryIndex
pub fn memory_index(&self, memory: &VMMemoryDefinition) -> DefinedMemoryIndex
Return the memory index for the given VMMemoryDefinition
in this instance.
Sourcepub fn memory_grow(
&self,
memory_index: DefinedMemoryIndex,
delta: u32,
) -> Option<u32>
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.
Sourcepub fn table_index(&self, table: &VMTableDefinition) -> DefinedTableIndex
pub fn table_index(&self, table: &VMTableDefinition) -> DefinedTableIndex
Return the table index for the given VMTableDefinition
in this instance.
Sourcepub fn table_grow(
&self,
table_index: DefinedTableIndex,
delta: u32,
) -> Option<u32>
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.
Sourcepub fn table_get(
&self,
table_index: DefinedTableIndex,
index: u32,
) -> Option<VMCallerCheckedAnyfunc>
pub fn table_get( &self, table_index: DefinedTableIndex, index: u32, ) -> Option<VMCallerCheckedAnyfunc>
Get table element reference.
Returns None
if index is out of bounds.
Sourcepub fn table_set(
&self,
table_index: DefinedTableIndex,
index: u32,
val: VMCallerCheckedAnyfunc,
) -> Result<(), ()>
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
Sourcepub fn get_defined_table(&self, index: DefinedTableIndex) -> &Table
pub fn get_defined_table(&self, index: DefinedTableIndex) -> &Table
Get a table defined locally within this module.
Sourcepub fn trampoline(&self, sig: VMSharedSignatureIndex) -> Option<VMTrampoline>
pub fn trampoline(&self, sig: VMSharedSignatureIndex) -> Option<VMTrampoline>
Gets the trampoline pre-registered for a particular signature
Sourcepub unsafe fn clone(&self) -> InstanceHandle
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.
Trait Implementations§
Source§impl Hash for InstanceHandle
impl Hash for InstanceHandle
Source§impl PartialEq for InstanceHandle
impl PartialEq for InstanceHandle
impl Eq for InstanceHandle
impl Send for InstanceHandle
impl StructuralPartialEq for InstanceHandle
Auto Trait Implementations§
impl Freeze for InstanceHandle
impl !RefUnwindSafe for InstanceHandle
impl !Sync for InstanceHandle
impl Unpin for InstanceHandle
impl !UnwindSafe for InstanceHandle
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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