Skip to content

Commit

Permalink
Fix incorrect memory overflow values + SIMD ifdefs
Browse files Browse the repository at this point in the history
  • Loading branch information
James Marsh authored and Zzzabiyaka committed Jan 27, 2025
1 parent a374d6c commit 2bc58d6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
4 changes: 2 additions & 2 deletions core/iwasm/interpreter/wasm_interp_fast.c
Original file line number Diff line number Diff line change
Expand Up @@ -5911,7 +5911,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
addr = GET_OPERAND(uint32, I32, 0); \
frame_ip += 2; \
addr_ret = GET_OFFSET(); \
CHECK_MEMORY_OVERFLOW(16); \
CHECK_MEMORY_OVERFLOW(4); \
\
simde_v128_t simde_result = simde_func(maddr); \
\
Expand Down Expand Up @@ -5954,7 +5954,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
offset += base;
addr = GET_OPERAND(uint32, I32, 0);

CHECK_MEMORY_OVERFLOW(32);
CHECK_MEMORY_OVERFLOW(4);
STORE_V128(maddr, data);
break;
}
Expand Down
15 changes: 12 additions & 3 deletions core/iwasm/interpreter/wasm_loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -7300,8 +7300,10 @@ wasm_loader_find_block_addr(WASMExecEnv *exec_env, BlockAddr *block_addr_cache,
case WASM_OP_SET_GLOBAL:
case WASM_OP_GET_GLOBAL_64:
case WASM_OP_SET_GLOBAL_64:
#if WASM_ENABLE_SIMDE != 0
case WASM_OP_GET_GLOBAL_128:
case WASM_OP_SET_GLOBAL_128:
#endif
case WASM_OP_SET_GLOBAL_AUX_STACK:
skip_leb_uint32(p, p_end); /* local index */
break;
Expand Down Expand Up @@ -9090,6 +9092,7 @@ preserve_referenced_local(WASMLoaderContext *loader_ctx, uint8 opcode,
bool *preserved, char *error_buf,
uint32 error_buf_size)
{

uint32 i = 0;
int16 preserved_offset = (int16)local_index;

Expand All @@ -9113,11 +9116,13 @@ preserve_referenced_local(WASMLoaderContext *loader_ctx, uint8 opcode,
loader_ctx->preserved_local_offset++;
emit_label(EXT_OP_COPY_STACK_TOP);
}
#if WASM_ENABLE_SIMDE != 0
else if (local_type == VALUE_TYPE_V128) {
if (loader_ctx->p_code_compiled)
loader_ctx->preserved_local_offset += 4;
emit_label(EXT_OP_COPY_STACK_TOP_V128);
}
#endif
else {
if (loader_ctx->p_code_compiled)
loader_ctx->preserved_local_offset += 2;
Expand Down Expand Up @@ -9790,11 +9795,12 @@ reserve_block_ret(WASMLoaderContext *loader_ctx, uint8 opcode,
/* insert op_copy before else opcode */
if (opcode == WASM_OP_ELSE)
skip_label();

#if WASM_ENABLE_SIMDE != 0
if (cell == 4) {
emit_label(EXT_OP_COPY_STACK_TOP_V128);
}
else {
#endif
if (cell <= 2) {
emit_label(cell == 1 ? EXT_OP_COPY_STACK_TOP
: EXT_OP_COPY_STACK_TOP_I64);
}
Expand Down Expand Up @@ -13115,10 +13121,12 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
emit_label(EXT_OP_TEE_LOCAL_FAST);
emit_byte(loader_ctx, (uint8)local_offset);
}
#if WASM_ENABLE_SIMDE != 0
else if (local_type == VALUE_TYPE_V128) {
emit_label(EXT_OP_TEE_LOCAL_FAST_V128);
emit_byte(loader_ctx, (uint8)local_offset);
}
#endif
else {
emit_label(EXT_OP_TEE_LOCAL_FAST_I64);
emit_byte(loader_ctx, (uint8)local_offset);
Expand Down Expand Up @@ -13213,11 +13221,12 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
skip_label();
emit_label(WASM_OP_GET_GLOBAL_64);
}

#if WASM_ENABLE_SIMDE != 0
if (global_type == VALUE_TYPE_V128) {
skip_label();
emit_label(WASM_OP_GET_GLOBAL_128);
}
#endif
#endif /* end of WASM_ENABLE_SIMDE */
emit_uint32(loader_ctx, global_idx);
PUSH_OFFSET_TYPE(global_type);
Expand Down

0 comments on commit 2bc58d6

Please sign in to comment.