Skip to content

Commit 46ec863

Browse files
authored
fix false native stack overflow detections with HW_BOUND_CHECK (#4196)
In call_wasm_with_hw_bound_check/call_native_with_hw_bound_check, ensure to set up the stack boundary (wasm_exec_env_set_thread_info) before checking the overflow. It seems that the problem was introduced by: #2940
1 parent 3bdec3c commit 46ec863

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

core/iwasm/aot/aot_runtime.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2315,13 +2315,6 @@ invoke_native_with_hw_bound_check(WASMExecEnv *exec_env, void *func_ptr,
23152315
#endif
23162316
bool ret;
23172317

2318-
/* Check native stack overflow firstly to ensure we have enough
2319-
native stack to run the following codes before actually calling
2320-
the aot function in invokeNative function. */
2321-
if (!wasm_runtime_detect_native_stack_overflow(exec_env)) {
2322-
return false;
2323-
}
2324-
23252318
if (!exec_env_tls) {
23262319
if (!os_thread_signal_inited()) {
23272320
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,
23402333
}
23412334
}
23422335

2336+
/* Check native stack overflow firstly to ensure we have enough
2337+
native stack to run the following codes before actually calling
2338+
the aot function in invokeNative function. */
2339+
if (!wasm_runtime_detect_native_stack_overflow(exec_env)) {
2340+
return false;
2341+
}
2342+
23432343
wasm_exec_env_push_jmpbuf(exec_env, &jmpbuf_node);
23442344

23452345
if (os_setjmp(jmpbuf_node.jmpbuf) == 0) {

core/iwasm/interpreter/wasm_runtime.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3523,13 +3523,6 @@ call_wasm_with_hw_bound_check(WASMModuleInstance *module_inst,
35233523
#endif
35243524
bool ret = true;
35253525

3526-
/* Check native stack overflow firstly to ensure we have enough
3527-
native stack to run the following codes before actually calling
3528-
the aot function in invokeNative function. */
3529-
if (!wasm_runtime_detect_native_stack_overflow(exec_env)) {
3530-
return;
3531-
}
3532-
35333526
if (!exec_env_tls) {
35343527
if (!os_thread_signal_inited()) {
35353528
wasm_set_exception(module_inst, "thread signal env not inited");
@@ -3548,6 +3541,13 @@ call_wasm_with_hw_bound_check(WASMModuleInstance *module_inst,
35483541
}
35493542
}
35503543

3544+
/* Check native stack overflow firstly to ensure we have enough
3545+
native stack to run the following codes before actually calling
3546+
the aot function in invokeNative function. */
3547+
if (!wasm_runtime_detect_native_stack_overflow(exec_env)) {
3548+
return;
3549+
}
3550+
35513551
wasm_exec_env_push_jmpbuf(exec_env, &jmpbuf_node);
35523552

35533553
if (os_setjmp(jmpbuf_node.jmpbuf) == 0) {

0 commit comments

Comments
 (0)