Fix incorrect memory overflow values + SIMD ifdefs

This commit is contained in:
James Marsh 2025-01-24 18:07:37 +00:00 committed by Marcin Kolny
parent 28d74d2e6c
commit 80e6c986f4
2 changed files with 14 additions and 5 deletions

View File

@ -5909,7 +5909,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
addr = GET_OPERAND(uint32, I32, 0); \ addr = GET_OPERAND(uint32, I32, 0); \
frame_ip += 2; \ frame_ip += 2; \
addr_ret = GET_OFFSET(); \ addr_ret = GET_OFFSET(); \
CHECK_MEMORY_OVERFLOW(16); \ CHECK_MEMORY_OVERFLOW(4); \
\ \
simde_v128_t simde_result = simde_func(maddr); \ simde_v128_t simde_result = simde_func(maddr); \
\ \
@ -5952,7 +5952,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
offset += base; offset += base;
addr = GET_OPERAND(uint32, I32, 0); addr = GET_OPERAND(uint32, I32, 0);
CHECK_MEMORY_OVERFLOW(32); CHECK_MEMORY_OVERFLOW(4);
STORE_V128(maddr, data); STORE_V128(maddr, data);
break; break;
} }

View File

@ -7300,8 +7300,10 @@ wasm_loader_find_block_addr(WASMExecEnv *exec_env, BlockAddr *block_addr_cache,
case WASM_OP_SET_GLOBAL: case WASM_OP_SET_GLOBAL:
case WASM_OP_GET_GLOBAL_64: case WASM_OP_GET_GLOBAL_64:
case WASM_OP_SET_GLOBAL_64: case WASM_OP_SET_GLOBAL_64:
#if WASM_ENABLE_SIMDE != 0
case WASM_OP_GET_GLOBAL_128: case WASM_OP_GET_GLOBAL_128:
case WASM_OP_SET_GLOBAL_128: case WASM_OP_SET_GLOBAL_128:
#endif
case WASM_OP_SET_GLOBAL_AUX_STACK: case WASM_OP_SET_GLOBAL_AUX_STACK:
skip_leb_uint32(p, p_end); /* local index */ skip_leb_uint32(p, p_end); /* local index */
break; break;
@ -9090,6 +9092,7 @@ preserve_referenced_local(WASMLoaderContext *loader_ctx, uint8 opcode,
bool *preserved, char *error_buf, bool *preserved, char *error_buf,
uint32 error_buf_size) uint32 error_buf_size)
{ {
uint32 i = 0; uint32 i = 0;
int16 preserved_offset = (int16)local_index; int16 preserved_offset = (int16)local_index;
@ -9113,11 +9116,13 @@ preserve_referenced_local(WASMLoaderContext *loader_ctx, uint8 opcode,
loader_ctx->preserved_local_offset++; loader_ctx->preserved_local_offset++;
emit_label(EXT_OP_COPY_STACK_TOP); emit_label(EXT_OP_COPY_STACK_TOP);
} }
#if WASM_ENABLE_SIMDE != 0
else if (local_type == VALUE_TYPE_V128) { else if (local_type == VALUE_TYPE_V128) {
if (loader_ctx->p_code_compiled) if (loader_ctx->p_code_compiled)
loader_ctx->preserved_local_offset += 4; loader_ctx->preserved_local_offset += 4;
emit_label(EXT_OP_COPY_STACK_TOP_V128); emit_label(EXT_OP_COPY_STACK_TOP_V128);
} }
#endif
else { else {
if (loader_ctx->p_code_compiled) if (loader_ctx->p_code_compiled)
loader_ctx->preserved_local_offset += 2; loader_ctx->preserved_local_offset += 2;
@ -9790,11 +9795,12 @@ reserve_block_ret(WASMLoaderContext *loader_ctx, uint8 opcode,
/* insert op_copy before else opcode */ /* insert op_copy before else opcode */
if (opcode == WASM_OP_ELSE) if (opcode == WASM_OP_ELSE)
skip_label(); skip_label();
#if WASM_ENABLE_SIMDE != 0
if (cell == 4) { if (cell == 4) {
emit_label(EXT_OP_COPY_STACK_TOP_V128); emit_label(EXT_OP_COPY_STACK_TOP_V128);
} }
else { #endif
if (cell <= 2) {
emit_label(cell == 1 ? EXT_OP_COPY_STACK_TOP emit_label(cell == 1 ? EXT_OP_COPY_STACK_TOP
: EXT_OP_COPY_STACK_TOP_I64); : EXT_OP_COPY_STACK_TOP_I64);
} }
@ -13115,10 +13121,12 @@ re_scan:
emit_label(EXT_OP_TEE_LOCAL_FAST); emit_label(EXT_OP_TEE_LOCAL_FAST);
emit_byte(loader_ctx, (uint8)local_offset); emit_byte(loader_ctx, (uint8)local_offset);
} }
#if WASM_ENABLE_SIMDE != 0
else if (local_type == VALUE_TYPE_V128) { else if (local_type == VALUE_TYPE_V128) {
emit_label(EXT_OP_TEE_LOCAL_FAST_V128); emit_label(EXT_OP_TEE_LOCAL_FAST_V128);
emit_byte(loader_ctx, (uint8)local_offset); emit_byte(loader_ctx, (uint8)local_offset);
} }
#endif
else { else {
emit_label(EXT_OP_TEE_LOCAL_FAST_I64); emit_label(EXT_OP_TEE_LOCAL_FAST_I64);
emit_byte(loader_ctx, (uint8)local_offset); emit_byte(loader_ctx, (uint8)local_offset);
@ -13213,11 +13221,12 @@ re_scan:
skip_label(); skip_label();
emit_label(WASM_OP_GET_GLOBAL_64); emit_label(WASM_OP_GET_GLOBAL_64);
} }
#if WASM_ENABLE_SIMDE != 0
if (global_type == VALUE_TYPE_V128) { if (global_type == VALUE_TYPE_V128) {
skip_label(); skip_label();
emit_label(WASM_OP_GET_GLOBAL_128); emit_label(WASM_OP_GET_GLOBAL_128);
} }
#endif
#endif /* end of WASM_ENABLE_SIMDE */ #endif /* end of WASM_ENABLE_SIMDE */
emit_uint32(loader_ctx, global_idx); emit_uint32(loader_ctx, global_idx);
PUSH_OFFSET_TYPE(global_type); PUSH_OFFSET_TYPE(global_type);