Struct soroban_env_host::vm::Vm
source · pub struct Vm { /* private fields */ }Expand description
A Vm is a thin wrapper around an instance of wasmi::Module. 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
sourceimpl Vm
impl Vm
sourcepub fn new(
host: &Host,
contract_id: Hash,
module_wasm_code: &[u8]
) -> Result<Rc<Self>, HostError>
pub fn new(
host: &Host,
contract_id: Hash,
module_wasm_code: &[u8]
) -> Result<Rc<Self>, HostError>
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
startfunction, or post-MVP wasm extensions. - Instantiates the module, leaving it ready to accept function invocations.
- Looks up and caches its linear memory export named
memoryif it exists.
This method is called automatically as part of Host::invoke_function and does not usually need to be called from outside the crate.
sourcepub fn invoke_function(
self: &Rc<Self>,
host: &Host,
func: &str,
args: &ScVec
) -> Result<ScVal, HostError>
pub fn invoke_function(
self: &Rc<Self>,
host: &Host,
func: &str,
args: &ScVec
) -> Result<ScVal, HostError>
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.
Auto Trait Implementations
impl !RefUnwindSafe for Vm
impl !Send for Vm
impl !Sync for Vm
impl Unpin for Vm
impl !UnwindSafe for Vm
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
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 morefn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait. Read morefn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s. Read morefn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s. Read more