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

A Vm is a thin wrapper around an instance of wasmi::ModuleRef. Multiple Vms may be held in a single Host, and each contains a single WASM module instantiation.

Vm rejects modules with either floating point or start functions.

Vm is configured to use its Host as a source of WASM imports. Specifically Host implements wasmi::ImportResolver by resolving all and only the functions declared in Env as imports, if requested by the WASM module. Any other lookups on any tables other than import functions will fail.

Implementations

Constructs a new instance of a Vm within the provided Host, establishing a new execution context for a contract identified by contract_id with WASM bytecode provided in module_wasm_code.

This function performs several steps:

  • Parses and performs WASM validation on the module.
  • Checks that the module contains an meta::INTERFACE_VERSION that matches the host.
  • Checks that the module has no floating point code or start function.
  • Instantiates the module, leaving it ready to accept function invocations.

This method is called automatically as part of Host::invoke_function and does not usually need to be called from outside the crate.

Invokes a function in the VM’s module, converting externally stable XDR ScVal arguments into Host-specific RawVals and converting the RawVal returned from the invocation back to an ScVal.

This function, like Vm::new, is called as part of Host::invoke_function, and does not usually need to be called manually from outside the crate.

Returns a list of functions in the WASM module loaded into the Vm.

Returns the raw binary content of a named custom section from the WASM module loaded into the Vm, or None if no such custom section exists.

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

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait. Read more

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait. Read more

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s. Read more

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s. Read more

Returns the argument unchanged.

Calls U::from(self).

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

Should always be Self

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.