pub struct Store<'b, T: Config> {
pub(crate) functions: AddrVec<FuncAddr, FuncInst<T>>,
pub(crate) tables: AddrVec<TableAddr, TableInst>,
pub(crate) memories: AddrVec<MemAddr, MemInst>,
pub(crate) globals: AddrVec<GlobalAddr, GlobalInst>,
pub(crate) elements: AddrVec<ElemAddr, ElemInst>,
pub(crate) data: AddrVec<DataAddr, DataInst>,
pub(crate) modules: AddrVec<ModuleAddr, ModuleInst<'b>>,
pub registry: Registry,
pub user_data: T,
pub(crate) dormitory: Dormitory,
}Expand description
The store represents all global state that can be manipulated by WebAssembly programs. It consists of the runtime representation of all instances of functions, tables, memories, and globals, element segments, and data segments that have been allocated during the life time of the abstract machine. https://webassembly.github.io/spec/core/exec/runtime.html#store
Fields§
§functions: AddrVec<FuncAddr, FuncInst<T>>§tables: AddrVec<TableAddr, TableInst>§memories: AddrVec<MemAddr, MemInst>§globals: AddrVec<GlobalAddr, GlobalInst>§elements: AddrVec<ElemAddr, ElemInst>§data: AddrVec<DataAddr, DataInst>§modules: AddrVec<ModuleAddr, ModuleInst<'b>>An address space of modules instantiated within the context of this Store.
Although the WebAssembly Specification 2.0 does not specify module instances
to be part of the Store, in reality they can be managed very similar to
other instance types. Therefore, we extend the Store by a module address
space along with a ModuleAddr index type.
registry: Registry§user_data: T§dormitory: DormitoryImplementations§
Source§impl<'b, T: Config> Store<'b, T>
impl<'b, T: Config> Store<'b, T>
Sourcepub fn new(user_data: T) -> Self
pub fn new(user_data: T) -> Self
Creates a new empty store with some user data
See: WebAssembly Specification 2.0 - 7.1.4 - store_init
Sourcepub fn add_module(
&mut self,
name: &str,
validation_info: &ValidationInfo<'b>,
maybe_fuel: Option<u32>,
) -> Result<ModuleAddr, RuntimeError>
pub fn add_module( &mut self, name: &str, validation_info: &ValidationInfo<'b>, maybe_fuel: Option<u32>, ) -> Result<ModuleAddr, RuntimeError>
instantiates a validated module with validation_info as validation evidence with name name
with the steps in https://webassembly.github.io/spec/core/exec/modules.html#instantiation
this method roughly matches the suggested embedder functionmodule_instantiate
https://webassembly.github.io/spec/core/appendix/embedding.html#modules
except external values for module instantiation are retrieved from self.
Returns the module addr of the new module instance
Sourcepub fn instance_export(
&self,
module_addr: ModuleAddr,
name: &str,
) -> Result<ExternVal, RuntimeError>
pub fn instance_export( &self, module_addr: ModuleAddr, name: &str, ) -> Result<ExternVal, RuntimeError>
Gets an export of a specific module instance by its name
See: WebAssembly Specification 2.0 - 7.1.6 - instance_export
Sourcepub fn func_alloc(
&mut self,
func_type: FuncType,
host_func: fn(&mut T, Vec<Value>) -> Result<Vec<Value>, HaltExecutionError>,
) -> FuncAddr
pub fn func_alloc( &mut self, func_type: FuncType, host_func: fn(&mut T, Vec<Value>) -> Result<Vec<Value>, HaltExecutionError>, ) -> FuncAddr
Allocates a new function with some host code.
This type of function is also called a host function.
§Panics & Unexpected Behavior
The specification states that:
This operation must make sure that the provided host function satisfies the pre- and post-conditions required for a function instance with type
functype.
Therefore, all “invalid” host functions (e.g. those which return incorrect return values) can cause the interpreter to panic or behave unexpectedly.
See: https://webassembly.github.io/spec/core/exec/modules.html#host-functions See: WebAssembly Specification 2.0 - 7.1.7 - func_alloc
Sourcepub fn func_type(&self, func_addr: FuncAddr) -> FuncType
pub fn func_type(&self, func_addr: FuncAddr) -> FuncType
Gets the type of a function by its addr.
See: WebAssembly Specification 2.0 - 7.1.7 - func_type
Sourcepub fn invoke(
&mut self,
func_addr: FuncAddr,
params: Vec<Value>,
maybe_fuel: Option<u32>,
) -> Result<RunState, RuntimeError>
pub fn invoke( &mut self, func_addr: FuncAddr, params: Vec<Value>, maybe_fuel: Option<u32>, ) -> Result<RunState, RuntimeError>
See: WebAssembly Specification 2.0 - 7.1.7 - func_invoke
Sourcepub fn table_alloc(
&mut self,
table_type: TableType,
ref: Ref,
) -> Result<TableAddr, RuntimeError>
pub fn table_alloc( &mut self, table_type: TableType, ref: Ref, ) -> Result<TableAddr, RuntimeError>
Allocates a new table with some table type and an initialization value ref and returns its table address.
See: WebAssembly Specification 2.0 - 7.1.8 - table_alloc
Sourcepub fn table_type(&self, table_addr: TableAddr) -> TableType
pub fn table_type(&self, table_addr: TableAddr) -> TableType
Gets the type of some table by its addr.
See: WebAssembly Specification 2.0 - 7.1.8 - table_type
Sourcepub fn table_read(
&self,
table_addr: TableAddr,
i: u32,
) -> Result<Ref, RuntimeError>
pub fn table_read( &self, table_addr: TableAddr, i: u32, ) -> Result<Ref, RuntimeError>
Reads a single reference from a table by its table address and an index into the table.
See: WebAssembly Specification 2.0 - 7.1.8 - table_read
Sourcepub fn table_write(
&mut self,
table_addr: TableAddr,
i: u32,
ref: Ref,
) -> Result<(), RuntimeError>
pub fn table_write( &mut self, table_addr: TableAddr, i: u32, ref: Ref, ) -> Result<(), RuntimeError>
Writes a single reference into a table by its table address and an index into the table.
See: WebAssembly Specification 2.0 - 7.1.8 - table_write
Sourcepub fn table_size(&self, table_addr: TableAddr) -> u32
pub fn table_size(&self, table_addr: TableAddr) -> u32
Gets the current size of a table by its table address.
See: WebAssembly Specification 2.0 - 7.1.8 - table_size
Sourcepub fn table_grow(
&mut self,
table_addr: TableAddr,
n: u32,
ref: Ref,
) -> Result<(), RuntimeError>
pub fn table_grow( &mut self, table_addr: TableAddr, n: u32, ref: Ref, ) -> Result<(), RuntimeError>
Grows a table referenced by its table address by n elements.
See: WebAssembly Specification 2.0 - 7.1.8 - table_grow
Sourcepub fn mem_alloc(&mut self, mem_type: MemType) -> MemAddr
pub fn mem_alloc(&mut self, mem_type: MemType) -> MemAddr
Allocates a new linear memory and returns its memory address.
See: WebAssembly Specification 2.0 - 7.1.9 - mem_alloc
Sourcepub fn mem_type(&self, mem_addr: MemAddr) -> MemType
pub fn mem_type(&self, mem_addr: MemAddr) -> MemType
Gets the memory type of some memory by its memory address
See: WebAssemblySpecification 2.0 - 7.1.9 - mem_type
Sourcepub fn mem_read(&self, mem_addr: MemAddr, i: u32) -> Result<u8, RuntimeError>
pub fn mem_read(&self, mem_addr: MemAddr, i: u32) -> Result<u8, RuntimeError>
Reads a byte from some memory by its memory address and an index into the memory
See: WebAssemblySpecification 2.0 - 7.1.9 - mem_read
Sourcepub fn mem_write(
&self,
mem_addr: MemAddr,
i: u32,
byte: u8,
) -> Result<(), RuntimeError>
pub fn mem_write( &self, mem_addr: MemAddr, i: u32, byte: u8, ) -> Result<(), RuntimeError>
Writes a byte into some memory by its memory address and an index into the memory
See: WebAssemblySpecification 2.0 - 7.1.9 - mem_write
Sourcepub fn mem_size(&self, mem_addr: MemAddr) -> u32
pub fn mem_size(&self, mem_addr: MemAddr) -> u32
Gets the size of some memory by its memory address in pages.
See: WebAssemblySpecification 2.0 - 7.1.9 - mem_size
Sourcepub fn mem_grow(
&mut self,
mem_addr: MemAddr,
n: u32,
) -> Result<(), RuntimeError>
pub fn mem_grow( &mut self, mem_addr: MemAddr, n: u32, ) -> Result<(), RuntimeError>
Grows some memory by its memory address by n pages.
See: WebAssemblySpecification 2.0 - 7.1.9 - mem_grow
Sourcepub fn global_alloc(
&mut self,
global_type: GlobalType,
val: Value,
) -> Result<GlobalAddr, RuntimeError>
pub fn global_alloc( &mut self, global_type: GlobalType, val: Value, ) -> Result<GlobalAddr, RuntimeError>
Allocates a new global and returns its global address.
See: WebAssemblySpecification 2.0 - 7.1.10 - global_alloc
Sourcepub fn global_type(&self, global_addr: GlobalAddr) -> GlobalType
pub fn global_type(&self, global_addr: GlobalAddr) -> GlobalType
Returns the global type of some global instance by its addr.
See: WebAssembly Specification 2.0 - 7.1.10 - global_type
Sourcepub fn global_read(&self, global_addr: GlobalAddr) -> Value
pub fn global_read(&self, global_addr: GlobalAddr) -> Value
Returns the current value of some global instance by its addr.
See: WebAssembly Specification 2.0 - 7.1.10 - global_read
Sourcepub fn global_write(
&mut self,
global_addr: GlobalAddr,
val: Value,
) -> Result<(), RuntimeError>
pub fn global_write( &mut self, global_addr: GlobalAddr, val: Value, ) -> Result<(), RuntimeError>
Sets a new value of some global instance by its addr.
§Errors
See: WebAssembly Specification 2.0 - 7.1.10 - global_write
Sourcefn alloc_func(
&mut self,
func: (usize, (Span, usize)),
module_addr: ModuleAddr,
) -> FuncAddr
fn alloc_func( &mut self, func: (usize, (Span, usize)), module_addr: ModuleAddr, ) -> FuncAddr
roughly matches https://webassembly.github.io/spec/core/exec/modules.html#functions with the addition of sidetable pointer to the input signature
Sourcefn alloc_table(&mut self, table_type: TableType, reff: Ref) -> TableAddr
fn alloc_table(&mut self, table_type: TableType, reff: Ref) -> TableAddr
Sourcefn alloc_global(&mut self, global_type: GlobalType, val: Value) -> GlobalAddr
fn alloc_global(&mut self, global_type: GlobalType, val: Value) -> GlobalAddr
Sourcefn alloc_data(&mut self, bytes: &[u8]) -> DataAddr
fn alloc_data(&mut self, bytes: &[u8]) -> DataAddr
Sourcepub fn reregister_module(
&mut self,
module_addr: ModuleAddr,
name: &str,
) -> Result<(), RuntimeError>
pub fn reregister_module( &mut self, module_addr: ModuleAddr, name: &str, ) -> Result<(), RuntimeError>
This function allows an already instantiated module to be reregistered under a different name. All previous registers of this module are not affected.
Note: This method exists as a temporary solution because our suboptimal registry
design. Because Store::add_module automatically registers all
modules directly after instantiation, we still need to provide some way
for only registering a module.