EH: Fix broken stack usage calculation (#3121)

Fixes: https://github.com/bytecodealliance/wasm-micro-runtime/issues/3108
This commit is contained in:
YAMAMOTO Takashi 2024-02-03 13:21:15 +09:00 committed by GitHub
parent a32b082d2a
commit 529fa9dd17
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -4412,19 +4412,20 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
else { else {
WASMFunction *cur_wasm_func = cur_func->u.func; WASMFunction *cur_wasm_func = cur_func->u.func;
WASMType *func_type; WASMType *func_type;
uint32 max_stack_cell_num = cur_wasm_func->max_stack_cell_num;
#if WASM_ENABLE_EXCE_HANDLING != 0 #if WASM_ENABLE_EXCE_HANDLING != 0
/* account for exception handlers */ /* account for exception handlers */
/* bundle them here */ /* bundle them here */
uint32 eh_size = uint32 eh_size =
cur_wasm_func->exception_handler_count * sizeof(uint8 *); cur_wasm_func->exception_handler_count * sizeof(uint8 *);
cur_wasm_func->max_stack_cell_num += eh_size; max_stack_cell_num += eh_size;
#endif #endif
func_type = cur_wasm_func->func_type; func_type = cur_wasm_func->func_type;
all_cell_num = cur_func->param_cell_num + cur_func->local_cell_num all_cell_num = cur_func->param_cell_num + cur_func->local_cell_num
+ cur_wasm_func->max_stack_cell_num + max_stack_cell_num
+ cur_wasm_func->max_block_num + cur_wasm_func->max_block_num
* (uint32)sizeof(WASMBranchBlock) / 4; * (uint32)sizeof(WASMBranchBlock) / 4;
@ -4447,8 +4448,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
frame_sp = frame->sp_bottom = frame_sp = frame->sp_bottom =
frame_lp + cur_func->param_cell_num + cur_func->local_cell_num; frame_lp + cur_func->param_cell_num + cur_func->local_cell_num;
frame->sp_boundary = frame->sp_boundary = frame->sp_bottom + max_stack_cell_num;
frame->sp_bottom + cur_wasm_func->max_stack_cell_num;
frame_csp = frame->csp_bottom = frame_csp = frame->csp_bottom =
(WASMBranchBlock *)frame->sp_boundary; (WASMBranchBlock *)frame->sp_boundary;