Expand description
Runtime library calls.
Note that Wasm compilers may sometimes perform these inline rather than calling them, particularly when CPUs have special instructions which compute them directly.
These functions are called by compiled Wasm code, and therefore must take certain care about some things:
-
They must always be
pub extern "C"
and should only contain basic, raw i32/i64/f32/f64/pointer parameters that are safe to pass across the system ABI! -
If any nested function propagates an
Err(trap)
out to the library function frame, we need to raise it. This involves some nasty and quite unsafe code under the covers! Notable, after raising the trap, drops will not be run for local variables! This can lead to things like leakingInstanceHandle
s which leads to never deallocating JIT code, instances, and modules! Therefore, always use nested blocks to ensure drops run before raising a trap:ⓘpub extern "C" fn my_lib_function(...) { let result = { // Do everything in here so drops run at the end of the block. ... }; if let Err(trap) = result { // Now we can safely raise the trap without leaking! raise_lib_trap(trap); } }
Enums
Statics
Functions
data.drop
.elem.drop
.func.ref
.memory.copy
for imported memories.memory.fill
for imported memories.table.get
for imported tables.table.grow
for imported tables.table.set
for imported tables.table.size
for imported tables.memory.copy
for locally defined memories.memory.fill
for locally defined memories.memory.init
.table.copy
.table.fill
.table.get
.table.grow
for locally-defined tables.table.init
.table.set
.table.size
.