diff --git a/core/iwasm/aot/aot_runtime.c b/core/iwasm/aot/aot_runtime.c index 3b152581d1..19120b457c 100644 --- a/core/iwasm/aot/aot_runtime.c +++ b/core/iwasm/aot/aot_runtime.c @@ -2819,8 +2819,8 @@ aot_table_copy(AOTModuleInstance *module_inst, uint32 src_tbl_idx, dst_tbl_inst = aot_get_table_inst(module_inst, dst_tbl_idx); bh_assert(dst_tbl_inst); - if ((uint64)src_offset + length > dst_tbl_inst->cur_size - || (uint64)dst_offset + length > src_tbl_inst->cur_size) { + if ((uint64)dst_offset + length > dst_tbl_inst->cur_size + || (uint64)src_offset + length > src_tbl_inst->cur_size) { aot_set_exception_with_id(module_inst, EXCE_OUT_OF_BOUNDS_TABLE_ACCESS); return; } diff --git a/core/iwasm/compilation/aot_compiler.c b/core/iwasm/compilation/aot_compiler.c index c4dac553a4..e1516eebe9 100644 --- a/core/iwasm/compilation/aot_compiler.c +++ b/core/iwasm/compilation/aot_compiler.c @@ -489,6 +489,7 @@ aot_compile_func(AOTCompContext *comp_ctx, uint32 func_index) break; case WASM_OP_GET_GLOBAL: + case WASM_OP_GET_GLOBAL_64: read_leb_uint32(frame_ip, frame_ip_end, global_idx); if (!aot_compile_op_get_global(comp_ctx, func_ctx, global_idx)) return false; diff --git a/core/iwasm/interpreter/wasm_interp.h b/core/iwasm/interpreter/wasm_interp.h index 4ac36edae6..9fa2488286 100644 --- a/core/iwasm/interpreter/wasm_interp.h +++ b/core/iwasm/interpreter/wasm_interp.h @@ -68,8 +68,14 @@ typedef struct WASMInterpFrame { static inline unsigned wasm_interp_interp_frame_size(unsigned all_cell_num) { - return align_uint((uint32)offsetof(WASMInterpFrame, lp) + all_cell_num * 5, - 4); + unsigned frame_size; + +#if WASM_ENABLE_FAST_INTERP == 0 + frame_size = (uint32)offsetof(WASMInterpFrame, lp) + all_cell_num * 4; +#else + frame_size = (uint32)offsetof(WASMInterpFrame, operand) + all_cell_num * 4; +#endif + return align_uint(frame_size, 4); } void diff --git a/core/iwasm/interpreter/wasm_interp_classic.c b/core/iwasm/interpreter/wasm_interp_classic.c index 37536777c2..05a7350bfb 100644 --- a/core/iwasm/interpreter/wasm_interp_classic.c +++ b/core/iwasm/interpreter/wasm_interp_classic.c @@ -3067,8 +3067,8 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, s = (uint32)POP_I32(); d = (uint32)POP_I32(); - if (s + n > dst_tbl_inst->cur_size - || d + n > src_tbl_inst->cur_size) { + if (d + n > dst_tbl_inst->cur_size + || s + n > src_tbl_inst->cur_size) { wasm_set_exception(module, "out of bounds table access"); goto got_exception; diff --git a/core/iwasm/interpreter/wasm_interp_fast.c b/core/iwasm/interpreter/wasm_interp_fast.c index 0b567137fc..6638e4543b 100644 --- a/core/iwasm/interpreter/wasm_interp_fast.c +++ b/core/iwasm/interpreter/wasm_interp_fast.c @@ -2984,8 +2984,8 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, s = (uint32)POP_I32(); d = (uint32)POP_I32(); - if (s + n > dst_tbl_inst->cur_size - || d + n > src_tbl_inst->cur_size) { + if (d + n > dst_tbl_inst->cur_size + || s + n > src_tbl_inst->cur_size) { wasm_set_exception(module, "out of bounds table access"); goto got_exception; diff --git a/core/iwasm/interpreter/wasm_loader.c b/core/iwasm/interpreter/wasm_loader.c index 6c5df59394..fb411abfbf 100644 --- a/core/iwasm/interpreter/wasm_loader.c +++ b/core/iwasm/interpreter/wasm_loader.c @@ -6414,6 +6414,7 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func, uint8 value_type; BlockType block_type; + p_org = p - 1; value_type = read_uint8(p); if (is_byte_a_type(value_type)) { /* If the first byte is one of these special values: @@ -6441,9 +6442,9 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func, * the block quickly. */ #if WASM_ENABLE_DEBUG_INTERP != 0 - record_fast_op(module, p - 2, *(p - 2)); + record_fast_op(module, p_org, *p_org); #endif - *(p - 2) = EXT_OP_BLOCK + (opcode - WASM_OP_BLOCK); + *p_org = EXT_OP_BLOCK + (opcode - WASM_OP_BLOCK); #endif } @@ -7309,33 +7310,22 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func, operand_offset = local_offset; PUSH_OFFSET_TYPE(local_type); #else -#if (WASM_ENABLE_WAMR_COMPILER == 0) && (WASM_ENABLE_JIT == 0) +#if (WASM_ENABLE_WAMR_COMPILER == 0) && (WASM_ENABLE_JIT == 0) \ + && (WASM_ENABLE_DEBUG_INTERP == 0) if (local_offset < 0x80) { -#if WASM_ENABLE_DEBUG_INTERP != 0 - record_fast_op(module, p_org, *p_org); -#endif *p_org++ = EXT_OP_GET_LOCAL_FAST; if (is_32bit_type(local_type)) { -#if WASM_ENABLE_DEBUG_INTERP != 0 - record_fast_op(module, p_org, *p_org); -#endif *p_org++ = (uint8)local_offset; } else { -#if WASM_ENABLE_DEBUG_INTERP != 0 - record_fast_op(module, p_org, *p_org); -#endif *p_org++ = (uint8)(local_offset | 0x80); } while (p_org < p) { -#if WASM_ENABLE_DEBUG_INTERP != 0 - record_fast_op(module, p_org, *p_org); -#endif *p_org++ = WASM_OP_NOP; } } #endif -#endif +#endif /* end of WASM_ENABLE_FAST_INTERP != 0 */ break; } @@ -7384,33 +7374,22 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func, POP_OFFSET_TYPE(local_type); } #else -#if (WASM_ENABLE_WAMR_COMPILER == 0) && (WASM_ENABLE_JIT == 0) +#if (WASM_ENABLE_WAMR_COMPILER == 0) && (WASM_ENABLE_JIT == 0) \ + && (WASM_ENABLE_DEBUG_INTERP == 0) if (local_offset < 0x80) { -#if WASM_ENABLE_DEBUG_INTERP != 0 - record_fast_op(module, p_org, *p_org); -#endif *p_org++ = EXT_OP_SET_LOCAL_FAST; if (is_32bit_type(local_type)) { -#if WASM_ENABLE_DEBUG_INTERP != 0 - record_fast_op(module, p_org, *p_org); -#endif *p_org++ = (uint8)local_offset; } else { -#if WASM_ENABLE_DEBUG_INTERP != 0 - record_fast_op(module, p_org, *p_org); -#endif *p_org++ = (uint8)(local_offset | 0x80); } while (p_org < p) { -#if WASM_ENABLE_DEBUG_INTERP != 0 - record_fast_op(module, p_org, *p_org); -#endif *p_org++ = WASM_OP_NOP; } } #endif -#endif +#endif /* end of WASM_ENABLE_FAST_INTERP != 0 */ break; } @@ -7455,33 +7434,22 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func, *(loader_ctx->frame_offset - wasm_value_type_cell_num(local_type))); #else -#if (WASM_ENABLE_WAMR_COMPILER == 0) && (WASM_ENABLE_JIT == 0) +#if (WASM_ENABLE_WAMR_COMPILER == 0) && (WASM_ENABLE_JIT == 0) \ + && (WASM_ENABLE_DEBUG_INTERP == 0) if (local_offset < 0x80) { -#if WASM_ENABLE_DEBUG_INTERP != 0 - record_fast_op(module, p_org, *p_org); -#endif *p_org++ = EXT_OP_TEE_LOCAL_FAST; if (is_32bit_type(local_type)) { -#if WASM_ENABLE_DEBUG_INTERP != 0 - record_fast_op(module, p_org, *p_org); -#endif *p_org++ = (uint8)local_offset; } else { -#if WASM_ENABLE_DEBUG_INTERP != 0 - record_fast_op(module, p_org, *p_org); -#endif *p_org++ = (uint8)(local_offset | 0x80); } while (p_org < p) { -#if WASM_ENABLE_DEBUG_INTERP != 0 - record_fast_op(module, p_org, *p_org); -#endif *p_org++ = WASM_OP_NOP; } } #endif -#endif +#endif /* end of WASM_ENABLE_FAST_INTERP != 0 */ break; } @@ -7505,7 +7473,6 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func, PUSH_TYPE(global_type); #if WASM_ENABLE_FAST_INTERP == 0 -#if (WASM_ENABLE_WAMR_COMPILER == 0) && (WASM_ENABLE_JIT == 0) if (global_type == VALUE_TYPE_I64 || global_type == VALUE_TYPE_F64) { #if WASM_ENABLE_DEBUG_INTERP != 0 @@ -7513,7 +7480,6 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func, #endif *p_org = WASM_OP_GET_GLOBAL_64; } -#endif #else /* else of WASM_ENABLE_FAST_INTERP */ if (global_type == VALUE_TYPE_I64 || global_type == VALUE_TYPE_F64) { diff --git a/core/iwasm/interpreter/wasm_mini_loader.c b/core/iwasm/interpreter/wasm_mini_loader.c index 48b816fc76..f2b8728c06 100644 --- a/core/iwasm/interpreter/wasm_mini_loader.c +++ b/core/iwasm/interpreter/wasm_mini_loader.c @@ -4813,6 +4813,7 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func, uint8 value_type; BlockType block_type; + p_org = p - 1; value_type = read_uint8(p); if (is_byte_a_type(value_type)) { /* If the first byte is one of these special values: @@ -4835,7 +4836,7 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func, * to new extended opcode so that interpreter can resolve * the block quickly. */ - *(p - 2) = EXT_OP_BLOCK + (opcode - WASM_OP_BLOCK); + *p_org = EXT_OP_BLOCK + (opcode - WASM_OP_BLOCK); #endif } @@ -5744,12 +5745,10 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func, PUSH_TYPE(global_type); #if WASM_ENABLE_FAST_INTERP == 0 -#if (WASM_ENABLE_WAMR_COMPILER == 0) && (WASM_ENABLE_JIT == 0) if (global_type == VALUE_TYPE_I64 || global_type == VALUE_TYPE_F64) { *p_org = WASM_OP_GET_GLOBAL_64; } -#endif #else /* else of WASM_ENABLE_FAST_INTERP */ if (is_64bit_type(global_type)) { skip_label(); @@ -5789,7 +5788,6 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func, POP_TYPE(global_type); #if WASM_ENABLE_FAST_INTERP == 0 -#if (WASM_ENABLE_WAMR_COMPILER == 0) && (WASM_ENABLE_JIT == 0) if (is_64bit_type(global_type)) { *p_org = WASM_OP_SET_GLOBAL_64; } @@ -5797,7 +5795,6 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func, && global_idx == module->aux_stack_top_global_index) { *p_org = WASM_OP_SET_GLOBAL_AUX_STACK; } -#endif #else /* else of WASM_ENABLE_FAST_INTERP */ if (is_64bit_type(global_type)) { skip_label();