Add wasm_runtime_detect_native_stack_overflow_size (#3355)
- Add a few API (https://github.com/bytecodealliance/wasm-micro-runtime/issues/3325) ```c wasm_runtime_detect_native_stack_overflow_size wasm_runtime_detect_native_stack_overflow ``` - Adapt the runtime to use them - Adapt samples/native-stack-overflow to use them - Add a few missing overflow checks in the interpreters - Build and run the sample on the CI
This commit is contained in:
@ -1159,6 +1159,10 @@ wasm_interp_call_func_native(WASMModuleInstance *module_inst,
|
||||
uint8 *frame_ref;
|
||||
#endif
|
||||
|
||||
if (!wasm_runtime_detect_native_stack_overflow(exec_env)) {
|
||||
return;
|
||||
}
|
||||
|
||||
all_cell_num = local_cell_num;
|
||||
#if WASM_ENABLE_GC != 0
|
||||
all_cell_num += (local_cell_num + 3) / 4;
|
||||
@ -1290,6 +1294,14 @@ wasm_interp_call_func_import(WASMModuleInstance *module_inst,
|
||||
uintptr_t aux_stack_origin_boundary = 0;
|
||||
uintptr_t aux_stack_origin_bottom = 0;
|
||||
|
||||
/*
|
||||
* perform stack overflow check before calling
|
||||
* wasm_interp_call_func_bytecode recursively.
|
||||
*/
|
||||
if (!wasm_runtime_detect_native_stack_overflow(exec_env)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!sub_func_inst) {
|
||||
snprintf(buf, sizeof(buf),
|
||||
"failed to call unlinked import function (%s, %s)",
|
||||
@ -7108,12 +7120,13 @@ wasm_interp_call_wasm(WASMModuleInstance *module_inst, WASMExecEnv *exec_env,
|
||||
}
|
||||
argc = function->param_cell_num;
|
||||
|
||||
RECORD_STACK_USAGE(exec_env, (uint8 *)&prev_frame);
|
||||
#if !(defined(OS_ENABLE_HW_BOUND_CHECK) \
|
||||
&& WASM_DISABLE_STACK_HW_BOUND_CHECK == 0)
|
||||
if ((uint8 *)&prev_frame < exec_env->native_stack_boundary) {
|
||||
wasm_set_exception((WASMModuleInstance *)exec_env->module_inst,
|
||||
"native stack overflow");
|
||||
#if defined(OS_ENABLE_HW_BOUND_CHECK) && WASM_DISABLE_STACK_HW_BOUND_CHECK == 0
|
||||
/*
|
||||
* wasm_runtime_detect_native_stack_overflow is done by
|
||||
* call_wasm_with_hw_bound_check.
|
||||
*/
|
||||
#else
|
||||
if (!wasm_runtime_detect_native_stack_overflow(exec_env)) {
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user