From 0f043dcc4251ea3de350fdea1fe6f5b2a4d90397 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Mon, 22 Apr 2024 13:10:22 +0900 Subject: [PATCH] Remove extra +1 from native stack guard page calculations https://github.com/bytecodealliance/wasm-micro-runtime/issues/3297 --- core/iwasm/aot/aot_runtime.c | 4 ++-- core/iwasm/interpreter/wasm_runtime.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/core/iwasm/aot/aot_runtime.c b/core/iwasm/aot/aot_runtime.c index 2ec001713..09bf4b1e6 100644 --- a/core/iwasm/aot/aot_runtime.c +++ b/core/iwasm/aot/aot_runtime.c @@ -1980,8 +1980,8 @@ invoke_native_with_hw_bound_check(WASMExecEnv *exec_env, void *func_ptr, native stack to run the following codes before actually calling the aot function in invokeNative function. */ RECORD_STACK_USAGE(exec_env, (uint8 *)&module_inst); - if ((uint8 *)&module_inst < exec_env->native_stack_boundary - + page_size * (guard_page_count + 1)) { + if ((uint8 *)&module_inst + < exec_env->native_stack_boundary + page_size * guard_page_count) { aot_set_exception_with_id(module_inst, EXCE_NATIVE_STACK_OVERFLOW); return false; } diff --git a/core/iwasm/interpreter/wasm_runtime.c b/core/iwasm/interpreter/wasm_runtime.c index c08e09a8c..cf480fb21 100644 --- a/core/iwasm/interpreter/wasm_runtime.c +++ b/core/iwasm/interpreter/wasm_runtime.c @@ -3154,8 +3154,8 @@ call_wasm_with_hw_bound_check(WASMModuleInstance *module_inst, native stack to run the following codes before actually calling the aot function in invokeNative function. */ RECORD_STACK_USAGE(exec_env, (uint8 *)&exec_env_tls); - if ((uint8 *)&exec_env_tls < exec_env->native_stack_boundary - + page_size * (guard_page_count + 1)) { + if ((uint8 *)&exec_env_tls + < exec_env->native_stack_boundary + page_size * guard_page_count) { wasm_set_exception(module_inst, "native stack overflow"); return; }