diff --git a/core/iwasm/aot/aot_runtime.c b/core/iwasm/aot/aot_runtime.c index bf7f51964..55b680502 100644 --- a/core/iwasm/aot/aot_runtime.c +++ b/core/iwasm/aot/aot_runtime.c @@ -2315,13 +2315,6 @@ invoke_native_with_hw_bound_check(WASMExecEnv *exec_env, void *func_ptr, #endif bool ret; - /* Check native stack overflow firstly to ensure we have enough - native stack to run the following codes before actually calling - the aot function in invokeNative function. */ - if (!wasm_runtime_detect_native_stack_overflow(exec_env)) { - return false; - } - if (!exec_env_tls) { if (!os_thread_signal_inited()) { aot_set_exception(module_inst, "thread signal env not inited"); @@ -2340,6 +2333,13 @@ invoke_native_with_hw_bound_check(WASMExecEnv *exec_env, void *func_ptr, } } + /* Check native stack overflow firstly to ensure we have enough + native stack to run the following codes before actually calling + the aot function in invokeNative function. */ + if (!wasm_runtime_detect_native_stack_overflow(exec_env)) { + return false; + } + wasm_exec_env_push_jmpbuf(exec_env, &jmpbuf_node); if (os_setjmp(jmpbuf_node.jmpbuf) == 0) { diff --git a/core/iwasm/interpreter/wasm_runtime.c b/core/iwasm/interpreter/wasm_runtime.c index 64719f7f5..3cc2afe04 100644 --- a/core/iwasm/interpreter/wasm_runtime.c +++ b/core/iwasm/interpreter/wasm_runtime.c @@ -3523,13 +3523,6 @@ call_wasm_with_hw_bound_check(WASMModuleInstance *module_inst, #endif bool ret = true; - /* Check native stack overflow firstly to ensure we have enough - native stack to run the following codes before actually calling - the aot function in invokeNative function. */ - if (!wasm_runtime_detect_native_stack_overflow(exec_env)) { - return; - } - if (!exec_env_tls) { if (!os_thread_signal_inited()) { wasm_set_exception(module_inst, "thread signal env not inited"); @@ -3548,6 +3541,13 @@ call_wasm_with_hw_bound_check(WASMModuleInstance *module_inst, } } + /* Check native stack overflow firstly to ensure we have enough + native stack to run the following codes before actually calling + the aot function in invokeNative function. */ + if (!wasm_runtime_detect_native_stack_overflow(exec_env)) { + return; + } + wasm_exec_env_push_jmpbuf(exec_env, &jmpbuf_node); if (os_setjmp(jmpbuf_node.jmpbuf) == 0) {