Module ABI
This section describes some low-level details of ABI used for module linking and passing values in module-module and module-host schemes.
The best way to see ABI functions is to use the following command:
sh
marine info -i artifacts/greeting.wasm...;; Exports(@interface export "allocate" (func 0))(@interface export "release_objects" (func 1))(@interface export "get_result_size" (func 2))(@interface export "get_result_ptr" (func 3))(@interface export "set_result_size" (func 4))(@interface export "set_result_ptr" (func 5))...
sh
marine info -i artifacts/greeting.wasm...;; Exports(@interface export "allocate" (func 0))(@interface export "release_objects" (func 1))(@interface export "get_result_size" (func 2))(@interface export "get_result_ptr" (func 3))(@interface export "set_result_size" (func 4))(@interface export "set_result_ptr" (func 5))...
All these functions are generated by the SDK and normally a developer shouldn't care about them.
Let's consider all these functions:
allocate
rust
allocate(elem_count: usize, elem_ty: usize) -> usize
rust
allocate(elem_count: usize, elem_ty: usize) -> usize
Allocate memory enough to place elem_count
objects of type elem_ty
, returns a pointer to allocated memory region
release_objects
rust
release_objects()
rust
release_objects()
Removes objects that were saved by generated by the #[marine]
macro code to prevent their deletion before parameters passing ends. Usually called by the IT side at the end of passing a function result.
Next four functions are intended to pass results from called functions. They are temporary solution and intended to overcome missing multi-value feature in IT, will be removed in the future with the multi-value passing scheme.
get_result_size
rust
get_result_size() -> usize
rust
get_result_size() -> usize
Returns a size of a result to the IT operand stack.
get_result_ptr
rust
get_result_ptr() -> usize
rust
get_result_ptr() -> usize
Returns a pointer to a result to the IT operand stack.
set_result_size
rust
set_result_size(size: usize)
rust
set_result_size(size: usize)
Set a size of a result to the given value.
set_result_ptr
rust
set_result_ptr(ptr: usize)
rust
set_result_ptr(ptr: usize)
Set a pointer of a result to the given value.