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

A handle holding an Instance of a WebAssembly module.

Implementations§

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.

Examples found in repository?
src/debug_builtins.rs (line 11)
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
pub unsafe extern "C" fn resolve_vmctx_memory(ptr: usize) -> *const u8 {
    let handle = InstanceHandle::from_vmctx(VMCTX_AND_MEMORY.0);
    assert!(
        VMCTX_AND_MEMORY.1 < handle.module().memory_plans.len(),
        "memory index for debugger is out of bounds"
    );
    let index = MemoryIndex::new(VMCTX_AND_MEMORY.1);
    let mem = handle.instance().get_memory(index);
    mem.base.add(ptr)
}

#[no_mangle]
pub unsafe extern "C" fn resolve_vmctx_memory_ptr(p: *const u32) -> *const u8 {
    let ptr = std::ptr::read(p);
    assert!(
        !VMCTX_AND_MEMORY.0.is_null(),
        "must call `__vmctx->set()` before resolving Wasm pointers"
    );
    let handle = InstanceHandle::from_vmctx(VMCTX_AND_MEMORY.0);
    assert!(
        VMCTX_AND_MEMORY.1 < handle.module().memory_plans.len(),
        "memory index for debugger is out of bounds"
    );
    let index = MemoryIndex::new(VMCTX_AND_MEMORY.1);
    let mem = handle.instance().get_memory(index);
    mem.base.add(ptr as usize)
}

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

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

Return a reference to a module.

Examples found in repository?
src/debug_builtins.rs (line 13)
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
pub unsafe extern "C" fn resolve_vmctx_memory(ptr: usize) -> *const u8 {
    let handle = InstanceHandle::from_vmctx(VMCTX_AND_MEMORY.0);
    assert!(
        VMCTX_AND_MEMORY.1 < handle.module().memory_plans.len(),
        "memory index for debugger is out of bounds"
    );
    let index = MemoryIndex::new(VMCTX_AND_MEMORY.1);
    let mem = handle.instance().get_memory(index);
    mem.base.add(ptr)
}

#[no_mangle]
pub unsafe extern "C" fn resolve_vmctx_memory_ptr(p: *const u32) -> *const u8 {
    let ptr = std::ptr::read(p);
    assert!(
        !VMCTX_AND_MEMORY.0.is_null(),
        "must call `__vmctx->set()` before resolving Wasm pointers"
    );
    let handle = InstanceHandle::from_vmctx(VMCTX_AND_MEMORY.0);
    assert!(
        VMCTX_AND_MEMORY.1 < handle.module().memory_plans.len(),
        "memory index for debugger is out of bounds"
    );
    let index = MemoryIndex::new(VMCTX_AND_MEMORY.1);
    let mem = handle.instance().get_memory(index);
    mem.base.add(ptr as usize)
}

Lookup a function by index.

Examples found in repository?
src/instance.rs (line 1127)
1125
1126
1127
1128
1129
1130
1131
1132
    pub fn get_export_by_index(&mut self, export: EntityIndex) -> Export {
        match export {
            EntityIndex::Function(i) => Export::Function(self.get_exported_func(i)),
            EntityIndex::Global(i) => Export::Global(self.get_exported_global(i)),
            EntityIndex::Table(i) => Export::Table(self.get_exported_table(i)),
            EntityIndex::Memory(i) => Export::Memory(self.get_exported_memory(i)),
        }
    }

Lookup a global by index.

Examples found in repository?
src/instance.rs (line 1128)
1125
1126
1127
1128
1129
1130
1131
1132
    pub fn get_export_by_index(&mut self, export: EntityIndex) -> Export {
        match export {
            EntityIndex::Function(i) => Export::Function(self.get_exported_func(i)),
            EntityIndex::Global(i) => Export::Global(self.get_exported_global(i)),
            EntityIndex::Table(i) => Export::Table(self.get_exported_table(i)),
            EntityIndex::Memory(i) => Export::Memory(self.get_exported_memory(i)),
        }
    }

Lookup a memory by index.

Examples found in repository?
src/instance.rs (line 1130)
1125
1126
1127
1128
1129
1130
1131
1132
    pub fn get_export_by_index(&mut self, export: EntityIndex) -> Export {
        match export {
            EntityIndex::Function(i) => Export::Function(self.get_exported_func(i)),
            EntityIndex::Global(i) => Export::Global(self.get_exported_global(i)),
            EntityIndex::Table(i) => Export::Table(self.get_exported_table(i)),
            EntityIndex::Memory(i) => Export::Memory(self.get_exported_memory(i)),
        }
    }

Lookup a table by index.

Examples found in repository?
src/instance.rs (line 1129)
1125
1126
1127
1128
1129
1130
1131
1132
    pub fn get_export_by_index(&mut self, export: EntityIndex) -> Export {
        match export {
            EntityIndex::Function(i) => Export::Function(self.get_exported_func(i)),
            EntityIndex::Global(i) => Export::Global(self.get_exported_global(i)),
            EntityIndex::Table(i) => Export::Table(self.get_exported_table(i)),
            EntityIndex::Memory(i) => Export::Memory(self.get_exported_memory(i)),
        }
    }

Lookup an item with the given index.

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.

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

Get a memory defined locally within this module.

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

Get a table defined locally within this module.

Get a table defined locally within this module, lazily initializing the given range first.

Returns the Store pointer that was stored on creation

Configure the *mut dyn Store internal pointer after-the-fact.

This is provided for the original Store itself to configure the first self-pointer after the original Box has been initialized.

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§

Feeds this value into the given Hasher. Read more
Feeds a slice of this type into the given Hasher. Read more
This method tests for self and other values to be equal, and is used by ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Compare self to key and return true if they are equal.

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.