From 6bfc08849a8bc8c2031442aef625e12b863a5bf5 Mon Sep 17 00:00:00 2001 From: Georgii Rylov Date: Tue, 28 Jan 2025 11:09:32 +0000 Subject: [PATCH] Calculate func_index instead of adding an extra field to wasm frame --- core/iwasm/interpreter/wasm_interp.h | 2 -- core/iwasm/interpreter/wasm_interp_classic.c | 4 +--- core/iwasm/interpreter/wasm_interp_fast.c | 5 +---- core/iwasm/interpreter/wasm_runtime.c | 3 ++- 4 files changed, 4 insertions(+), 10 deletions(-) diff --git a/core/iwasm/interpreter/wasm_interp.h b/core/iwasm/interpreter/wasm_interp.h index a4e31766d..141640546 100644 --- a/core/iwasm/interpreter/wasm_interp.h +++ b/core/iwasm/interpreter/wasm_interp.h @@ -26,8 +26,6 @@ typedef struct WASMInterpFrame { /* Instruction pointer of the bytecode array. */ uint8 *ip; - uint32 func_index; - #if WASM_ENABLE_FAST_JIT != 0 uint8 *jitted_return_addr; #endif diff --git a/core/iwasm/interpreter/wasm_interp_classic.c b/core/iwasm/interpreter/wasm_interp_classic.c index 2d4eb82d9..834311f7e 100644 --- a/core/iwasm/interpreter/wasm_interp_classic.c +++ b/core/iwasm/interpreter/wasm_interp_classic.c @@ -1264,11 +1264,9 @@ wasm_interp_call_func_native(WASMModuleInstance *module_inst, init_frame_refs(frame_ref, local_cell_num, cur_func); #endif - cur_func_index = (uint32)(cur_func - module_inst->e->functions); - frame->func_index = cur_func_index; - wasm_exec_env_set_cur_frame(exec_env, frame); + cur_func_index = (uint32)(cur_func - module_inst->e->functions); bh_assert(cur_func_index < module_inst->module->import_function_count); if (!func_import->call_conv_wasm_c_api) { native_func_pointer = module_inst->import_func_ptrs[cur_func_index]; diff --git a/core/iwasm/interpreter/wasm_interp_fast.c b/core/iwasm/interpreter/wasm_interp_fast.c index f61b24f7c..f44644e45 100644 --- a/core/iwasm/interpreter/wasm_interp_fast.c +++ b/core/iwasm/interpreter/wasm_interp_fast.c @@ -1205,11 +1205,9 @@ wasm_interp_call_func_native(WASMModuleInstance *module_inst, init_frame_refs(frame->frame_ref, local_cell_num, cur_func); #endif - cur_func_index = (uint32)(cur_func - module_inst->e->functions); - frame->func_index = cur_func_index; - wasm_exec_env_set_cur_frame(exec_env, frame); + cur_func_index = (uint32)(cur_func - module_inst->e->functions); bh_assert(cur_func_index < module_inst->module->import_function_count); if (!func_import->call_conv_wasm_c_api) { native_func_pointer = module_inst->import_func_ptrs[cur_func_index]; @@ -6034,7 +6032,6 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, /* Initialize the interpreter context. */ frame->function = cur_func; - frame->func_index = (uint32)(cur_func - module->e->functions); frame_ip = wasm_get_func_code(cur_func); frame_ip_end = wasm_get_func_code_end(cur_func); diff --git a/core/iwasm/interpreter/wasm_runtime.c b/core/iwasm/interpreter/wasm_runtime.c index 90fed59ba..4ac882bff 100644 --- a/core/iwasm/interpreter/wasm_runtime.c +++ b/core/iwasm/interpreter/wasm_runtime.c @@ -4222,7 +4222,8 @@ wasm_interp_iterate_callstack(WASMExecEnv *exec_env, && (uint8_t *)cur_frame + sizeof(WASMInterpFrame) <= top_boundary) { record_frame.instance = module_inst; record_frame.module_offset = 0; - record_frame.func_index = cur_frame->func_index; + // It's safe to dereference module_inst->e because "e" is asigned only once in wasm_instantiate + record_frame.func_index = (uint32)(cur_frame->function - module_inst->e->functions); if (!frame_handler(user_data, &record_frame)) { break; }