Add WASI ABI compatibility check for multi-module (#913)
Refer to https://github.com/WebAssembly/WASI/blob/main/design/application-abi.md to check the WASI ABI compatibility: - Command (main module) may export _start function with signature "()" - Reactor (sub module) may export _initialize function with signature "()" - _start and _initialize can not be exported at the same time - Reactor cannot export _start function - Command and Reactor must export memory And - Rename module->is_wasi_module to module->import_wasi_api - Refactor wasm_loader_find_export() - Remove MULTI_MODULE related codes from mini_loader - Update multi-module samples - Fix a "use-after-free" issue. Since we reuse the memory instance of sub module, just to protect it from freeing an imported memory instance
This commit is contained in:
74
samples/multi-module/wasm-apps/mD.cpp
Normal file
74
samples/multi-module/wasm-apps/mD.cpp
Normal file
@ -0,0 +1,74 @@
|
||||
#include <cstdlib>
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
|
||||
static void
|
||||
bye_main()
|
||||
{
|
||||
std::cout << "mD " << __FUNCTION__ << std::endl;
|
||||
}
|
||||
|
||||
static void
|
||||
bye_setup()
|
||||
{
|
||||
std::cout << "mD " << __FUNCTION__ << std::endl;
|
||||
}
|
||||
|
||||
static void
|
||||
bye_func()
|
||||
{
|
||||
std::cout << "mD " << __FUNCTION__ << std::endl;
|
||||
}
|
||||
|
||||
void
|
||||
func3() __attribute__((__import_module__("mE"), __import_name__("func1")));
|
||||
|
||||
void
|
||||
func4() __attribute__((__import_module__("mE"), __import_name__("func2")));
|
||||
|
||||
void
|
||||
func1()
|
||||
{
|
||||
std::printf("mD %s\n", __FUNCTION__);
|
||||
if (std::atexit(bye_func) != 0) {
|
||||
std::perror("register an atexit handler failed");
|
||||
}
|
||||
func3();
|
||||
}
|
||||
|
||||
void
|
||||
func2()
|
||||
{
|
||||
std::printf("mD %s\n", __FUNCTION__);
|
||||
func4();
|
||||
}
|
||||
|
||||
__attribute__((constructor)) void
|
||||
setup()
|
||||
{
|
||||
std::cout << "mD " << __FUNCTION__ << std::endl;
|
||||
if (std::atexit(bye_setup) != 0) {
|
||||
std::perror("register an atexit handler failed");
|
||||
}
|
||||
}
|
||||
|
||||
__attribute__((destructor)) void
|
||||
teardown()
|
||||
{
|
||||
std::cout << "mD " << __FUNCTION__ << std::endl;
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
std::printf("mD %s\n", __FUNCTION__);
|
||||
|
||||
if (std::atexit(bye_main) != 0) {
|
||||
std::perror("register an atexit handler failed");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
func1();
|
||||
func2();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
Reference in New Issue
Block a user