diff --git a/externals/wamr/CMakeLists.txt b/externals/wamr/CMakeLists.txt index 9e82f1fc..fed1888e 100644 --- a/externals/wamr/CMakeLists.txt +++ b/externals/wamr/CMakeLists.txt @@ -39,7 +39,6 @@ set(WAMR_DISABLE_HW_BOUND_CHECK 0) set(WAMR_DISABLE_STACK_HW_BOUND_CHECK 0) set(WAMR_DISABLE_WAKEUP_BLOCKING_OP 0) add_compile_definitions(BUILTIN_LIBC_BUFFERED_PRINTF=1 BUILTIN_LIBC_BUFFERED_PRINT_SIZE=512) - add_compile_definitions("$<$:BH_DEBUG=1>") include("${CMAKE_CURRENT_LIST_DIR}/wamr/build-scripts/runtime_lib.cmake") @@ -47,7 +46,6 @@ include("${CMAKE_CURRENT_LIST_DIR}/wamr/build-scripts/runtime_lib.cmake") file(GLOB_RECURSE iwasm_headers "${CMAKE_CURRENT_LIST_DIR}/wamr/core/*.h") add_library(iwasm_static STATIC ${WAMR_RUNTIME_LIB_SOURCE} ${iwasm_headers}) target_include_directories(iwasm_static INTERFACE "wamr/core/iwasm/include") -target_link_libraries(iwasm_static INTERFACE ${LLVM_AVAILABLE_LIBS} ${UV_A_LIBS}) target_compile_definitions(iwasm_static PUBLIC WASM_RUNTIME_API_EXTERN= WASM_API_EXTERN= COMPILING_WASM_RUNTIME_API=1) if(MSVC) diff --git a/sources/libcore/wasm.cpp b/sources/libcore/wasm.cpp index 6824780f..43471a38 100644 --- a/sources/libcore/wasm.cpp +++ b/sources/libcore/wasm.cpp @@ -70,6 +70,13 @@ namespace cage return 0; }(); (void)dummy; + thread_local int dummy2 = []() -> int + { + if (!wasm_runtime_init_thread_env()) + CAGE_THROW_ERROR(Exception, "failed to initialize wasm thread env"); + return 0; + }(); + (void)dummy2; } WasmTypeEnum convert(wasm_valkind_t k) @@ -188,6 +195,8 @@ namespace cage WasmInstanceImpl(Holder &&module_) : module(std::move(module_).cast()) { + initialize(); + CAGE_ASSERT(module); String err; instance = wasm_runtime_instantiate(module->module, 1'000'000, 1'000'000, err.rawData(), err.MaxLength - 100); @@ -227,6 +236,8 @@ namespace cage WasmFunctionImpl(WasmInstanceImpl *instance, const String &name) : name(name), instance(instance) { + CAGE_ASSERT(wasm_runtime_thread_env_inited()); + func = wasm_runtime_lookup_function(instance->instance, name.c_str()); if (!func) {