How should I pass control to another Wasm module?
How should I pass control to another wasm module (like
jmp) while preserving the current state e.g. the stack?
As modules do not have "control," only functions do, and you want to maintain the stack's state, I presume that you would want to be using function calls?
@programmeruser Dynamic imports are not possible, but dynamic calls are.
call_indirect and function pointers into tables.
If you attempt to call a function with a mis-matched signature, then the code traps immediately.
You should pass around a
(table funcref), between the modules, use
table.get and call via function pointers to the table.
And if you need to replicate a register-like structure, you can store into globals, call the function, and then read from them in the callee.
@programmeruser Well... idk.
Interrupts have a payload, which the OS may or may not have a registered handler for, and is called if present upon the interrupt.
The payload could be represented as a usize, and used to access an array of functions... but that sounds wrong.
Why can't they just be imported functions?
Syscalls are OS functions, just forget about the interrupt overhead, and call the function.
Linux pipe is the following:
int pipe(int pipefd);
This could be imported as
(import "syscall" "pipe" (func $syscall::pipe (param i32) (result i32)))
As for how it would be exported to the module, that depends on the Wasm VM.