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§
source§impl 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
start
function, or post-MVP wasm extensions. - Instantiates the module, leaving it ready to accept function invocations.
- Looks up and caches its linear memory export named
memory
if 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.
Trait Implementations§
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§
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<T, U, V, W, E, C> Compare<(T, U, V, W)> for C
impl<T, U, V, W, E, C> Compare<(T, U, V, W)> for C
type Error = E
fn compare( &self, a: &(T, U, V, W), b: &(T, U, V, W) ) -> Result<Ordering, <C as Compare<(T, U, V, W)>>::Error>
source§impl<T, U, V, W, X, E, C> Compare<(T, U, V, W, X)> for C
impl<T, U, V, W, X, E, C> Compare<(T, U, V, W, X)> for C
type Error = E
fn compare( &self, a: &(T, U, V, W, X), b: &(T, U, V, W, X) ) -> Result<Ordering, <C as Compare<(T, U, V, W, X)>>::Error>
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn 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.§fn 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.