fix: improve instruction limit checks and enhance readability of HANDLE_OP macros

This commit is contained in:
Alix ANNERAUD 2025-03-17 22:47:19 +01:00
parent e4ceb6b429
commit 70af781bde
2 changed files with 23 additions and 12 deletions

View File

@ -1569,11 +1569,13 @@ get_global_addr(uint8 *global_data, WASMGlobalInstance *global)
}
#if WASM_INSTRUCTION_METERING != 0
#define CHECK_INSTRUCTION_LIMIT() \
if (instructions_left == 0) { \
goto return_func; \
} \
instructions_left--;
#define CHECK_INSTRUCTION_LIMIT() \
if (instructions_left == 0) { \
wasm_set_exception(module, "instruction limit exceeded"); \
goto got_exception; \
} \
else if (instructions_left > 0) \
instructions_left--; \
#else
#define CHECK_INSTRUCTION_LIMIT() (void)0
#endif
@ -1721,7 +1723,10 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
goto got_exception;
}
HANDLE_OP(WASM_OP_NOP) { HANDLE_OP_END(); }
HANDLE_OP(WASM_OP_NOP)
{
HANDLE_OP_END();
}
#if WASM_ENABLE_EXCE_HANDLING != 0
HANDLE_OP(WASM_OP_RETHROW)
@ -5658,7 +5663,10 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
HANDLE_OP(WASM_OP_I32_REINTERPRET_F32)
HANDLE_OP(WASM_OP_I64_REINTERPRET_F64)
HANDLE_OP(WASM_OP_F32_REINTERPRET_I32)
HANDLE_OP(WASM_OP_F64_REINTERPRET_I64) { HANDLE_OP_END(); }
HANDLE_OP(WASM_OP_F64_REINTERPRET_I64)
{
HANDLE_OP_END();
}
HANDLE_OP(WASM_OP_I32_EXTEND8_S)
{

View File

@ -102,11 +102,14 @@ typedef float64 CellType_F64;
} while (0)
#if WASM_INSTRUCTION_METERING != 0
#define CHECK_INSTRUCTION_LIMIT() \
if (instructions_left == 0) { \
goto return_func; \
} \
instructions_left--;
#define CHECK_INSTRUCTION_LIMIT() \
if (instructions_left == 0) { \
wasm_set_exception(module_inst, "instruction limit exceeded"); \
goto got_exception; \
} \
else if (instructions_left > 0) { \
instructions_left--; \
} \
#else
#define CHECK_INSTRUCTION_LIMIT() (void)0
#endif