Reputation: 23637
When compiling to WebAssembly, emscripten generates functions like invoke_vii
. What is their purpose?
Details:
WebAssembly modules compiled from C with emcc -s WASM=1 -g
expect various functions to be provided by the host environment.
...
(import "env" "abortOnCannotGrowMemory" (func $import$9 (result i32)))
(import "env" "invoke_vii" (func $import$10 (param i32 i32 i32)))
(import "env" "___syscall221" (func $import$11 (param i32 i32) (result i32)))
...
I am working on a WebAssembly interpreter written in C. So I have to deal with providing these functions, but I am dumbfounded by functions like invoke_vii
, invoke_iiii
, and the like.
The postfix is obviously related to the call signature. For example, vii
means return void
and take some int
s. The name invoke suggests the function is supposed to invoke something.
I could find no information about these functions other than their implementation in the Java Script code generated by emscripten:
function invoke_ii(index,a1) {
# removed error checking for brevity
return Module["dynCall_ii"](index,a1);
}
dynCall_ii
exists in the WebAssembly module.
It seems all the invoke_*
functions do is to instruct the interpreter to run the corresponding dynCall_*
function. What is the purpose of this indirection? Why doesn't the WebAssembly code call dynCall_
directly?
Upvotes: 3
Views: 1077
Reputation: 3022
These are used for handling of setjmp/longjmp and also C++ exceptions. In these mechanisms JavaScript requires the ability to call back into a WebAssembly and invoke functions in the WebAssembly indirect function table.
If you build without exceptions and with -s SUPPORT_LONGJMP=0
(not the default) you should not see any these functions at all.
Upvotes: 4