WASI
WASI copied to clipboard
Separate initialization and finalization
Right now, _start initializes global state, calls main(), and then tears down global state.
This is fine for executable modules, but not for modules designed to be used as libraries.
For a library, I would like to initialize global state right after the library is loaded, and then tear down global state right before shutting the library down.
I am proposing separating the initialization part into a separate exported function (call it _init) and, similarly, splitting the finalization into a separate exported function (call it _fini).
Then _start becomes (pseudocode):
void _start() {
_init();
// set up arguments for main(), call main()
_fini();
}
but people who intend to use the module as a library have the option to call _init() and _fini() directly.
we already have this (to some degree), it is called a wasi reactor and it uses _initialize: https://github.com/WebAssembly/WASI/blob/main/design/application-abi.md#current-unstable-abi
Nice, thank you. There should probably also be a finalization API (that would call, e.g. destructors of global C++ objects)