Enum wasmtime_runtime::Table
source · pub enum Table {
Static(StaticTable),
Dynamic(DynamicTable),
}
Expand description
Represents an instance’s table.
Variants§
Static(StaticTable)
A “static” table where storage space is managed externally, currently used with the pooling allocator.
Dynamic(DynamicTable)
A “dynamic” table where table storage space is dynamically allocated via
malloc
(aka Rust’s Vec
).
Implementations§
source§impl Table
impl Table
sourcepub fn new_dynamic(plan: &TablePlan, store: &mut dyn Store) -> Result<Self>
pub fn new_dynamic(plan: &TablePlan, store: &mut dyn Store) -> Result<Self>
Create a new dynamic (movable) table instance for the specified table plan.
sourcepub unsafe fn new_static(
plan: &TablePlan,
data: SendSyncPtr<[u8]>,
store: &mut dyn Store
) -> Result<Self>
pub unsafe fn new_static( plan: &TablePlan, data: SendSyncPtr<[u8]>, store: &mut dyn Store ) -> Result<Self>
Create a new static (immovable) table instance for the specified table plan.
sourcepub fn element_type(&self) -> TableElementType
pub fn element_type(&self) -> TableElementType
Returns the type of the elements in this table.
sourcepub fn maximum(&self) -> Option<u32>
pub fn maximum(&self) -> Option<u32>
Returns the maximum number of elements at runtime.
Returns None
if the table is unbounded.
The runtime maximum may not be equal to the maximum from the table’s Wasm type when it is being constrained by an instance allocator.
sourcepub fn init_func(
&mut self,
dst: u32,
items: impl ExactSizeIterator<Item = *mut VMFuncRef>
) -> Result<(), Trap>
pub fn init_func( &mut self, dst: u32, items: impl ExactSizeIterator<Item = *mut VMFuncRef> ) -> Result<(), Trap>
Initializes the contents of this table to the specified function
§Panics
Panics if the table is not a function table.
sourcepub fn init_gc_refs(
&mut self,
dst: u32,
items: impl ExactSizeIterator<Item = Option<VMGcRef>>
) -> Result<(), Trap>
pub fn init_gc_refs( &mut self, dst: u32, items: impl ExactSizeIterator<Item = Option<VMGcRef>> ) -> Result<(), Trap>
Fill table[dst..]
with values from items
Returns a trap error on out-of-bounds accesses.
sourcepub fn fill(
&mut self,
gc_store: &mut GcStore,
dst: u32,
val: TableElement,
len: u32
) -> Result<(), Trap>
pub fn fill( &mut self, gc_store: &mut GcStore, dst: u32, val: TableElement, len: u32 ) -> Result<(), Trap>
Fill table[dst..dst + len]
with val
.
Returns a trap error on out-of-bounds accesses.
§Panics
Panics if val
does not have a type that matches this table.
sourcepub unsafe fn grow(
&mut self,
delta: u32,
init_value: TableElement,
store: &mut dyn Store
) -> Result<Option<u32>, Error>
pub unsafe fn grow( &mut self, delta: u32, init_value: TableElement, store: &mut dyn Store ) -> Result<Option<u32>, Error>
Grow table by the specified amount of elements.
Returns the previous size of the table if growth is successful.
Returns None
if table can’t be grown by the specified amount of
elements, or if the init_value
is the wrong kind of table element.
§Panics
Panics if init_value
does not have a type that matches this table.
§Unsafety
Resizing the table can reallocate its internal elements buffer. This
table’s instance’s VMContext
has raw pointers to the elements buffer
that are used by Wasm, and they need to be fixed up before we call into
Wasm again. Failure to do so will result in use-after-free inside Wasm.
Generally, prefer using InstanceHandle::table_grow
, which encapsulates
this unsafety.
sourcepub fn get(&self, gc_store: &mut GcStore, index: u32) -> Option<TableElement>
pub fn get(&self, gc_store: &mut GcStore, index: u32) -> Option<TableElement>
Get reference to the specified element.
Returns None
if the index is out of bounds.
sourcepub unsafe fn copy(
gc_store: &mut GcStore,
dst_table: *mut Self,
src_table: *mut Self,
dst_index: u32,
src_index: u32,
len: u32
) -> Result<(), Trap>
pub unsafe fn copy( gc_store: &mut GcStore, dst_table: *mut Self, src_table: *mut Self, dst_index: u32, src_index: u32, len: u32 ) -> Result<(), Trap>
Copy len
elements from src_table[src_index..]
into dst_table[dst_index..]
.
§Errors
Returns an error if the range is out of bounds of either the source or destination tables.
sourcepub fn vmtable(&mut self) -> VMTableDefinition
pub fn vmtable(&mut self) -> VMTableDefinition
Return a VMTableDefinition
for exposing the table to compiled wasm code.
sourcepub fn gc_refs_mut(&mut self) -> &mut [Option<VMGcRef>]
pub fn gc_refs_mut(&mut self) -> &mut [Option<VMGcRef>]
Get this table’s GC references as a slice.
Panics if this is not a table of GC references.