Type Alias wasmtime_runtime::VMTrampoline
source · pub type VMTrampoline = unsafe extern "C" fn(_: *mut VMOpaqueContext, _: *mut VMContext, _: *const VMFunctionBody, _: *mut ValRaw);
Expand description
Type definition of the trampoline used to enter WebAssembly from the host.
This function type is what’s generated for the entry trampolines that are
compiled into a WebAssembly module’s image. Note that trampolines are not
always used by Wasmtime since the TypedFunc
API allows bypassing the
trampoline and directly calling the underlying wasm function (at the time of
this writing).
The trampoline’s arguments here are:
-
*mut VMOpaqueContext
- this a contextual pointer defined within the context of the receiving function pointer. For now this is always*mut VMContext
but with the component model it may be the case that this is a different type of pointer. -
*mut VMContext
- this is the “caller” context, which at this time is always unconditionally core wasm (even in the component model). This contextual pointer cannot beNULL
and provides information necessary to resolve the caller’s context for theCaller
API in Wasmtime. -
*const VMFunctionBody
- this is the indirect function pointer which is the actual target function to invoke. This function uses the System-V ABI for its argumenst and a semi-custom ABI for the return values (one return value is returned directly, multiple return values have the first one returned directly and remaining ones returned indirectly through a stack pointer). This function pointer may be Cranelift-compiled code or it may also be a host-compiled trampoline (e.g. when a host function calls a host function through thewasmtime::Func
wrapper). The definition of the first argument of this function depends on what this receiving function pointer desires. -
*mut ValRaw
- this is storage space for both arguments and results of the function. The trampoline will read the arguments from this array to pass to the function pointer provided. The results are then written to the array afterwards (both reads and writes start at index 0). It’s the caller’s responsibility to make sure this array is appropriately sized.