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 const MAX_VM_ARGS: usize = 32usize
pub const MAX_VM_ARGS: usize = 32usize
The maximum number of arguments that can be passed to a VM function.
pub fn get_all_host_functions() -> Vec<(&'static str, &'static str, u32)>
pub fn get_all_host_functions_with_supported_protocol_range() -> Vec<(&'static str, &'static str, u32, Option<u32>, Option<u32>)>
pub fn from_parsed_module( host: &Host, contract_id: Hash, parsed_module: Rc<ParsedModule>, ) -> Result<Rc<Self>, HostError>
Sourcepub fn new(
host: &Host,
contract_id: Hash,
wasm: &[u8],
) -> Result<Rc<Self>, HostError>
pub fn new( host: &Host, contract_id: Hash, wasm: &[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.
With the introduction of the granular cost inputs this method should only be used for the one-off full parses of the new Wasms during the initial upload verification.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Vm
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>
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§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
.Source§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
.Source§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.Source§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.