Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e7aa03d

Browse files
committedMar 17, 2025·
fix: improve instruction limit checks and enhance readability of HANDLE_OP macros
1 parent cb63a92 commit e7aa03d

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed
 

‎core/iwasm/interpreter/wasm_interp_classic.c

+15-7
Original file line numberDiff line numberDiff line change
@@ -1569,11 +1569,13 @@ get_global_addr(uint8 *global_data, WASMGlobalInstance *global)
15691569
}
15701570

15711571
#if WASM_INSTRUCTION_METERING != 0
1572-
#define CHECK_INSTRUCTION_LIMIT() \
1573-
if (instructions_left == 0) { \
1574-
goto return_func; \
1575-
} \
1576-
instructions_left--;
1572+
#define CHECK_INSTRUCTION_LIMIT() \
1573+
if (instructions_left == 0) { \
1574+
wasm_set_exception(module, "instruction limit exceeded"); \
1575+
goto got_exception; \
1576+
} \
1577+
else if (instructions_left > 0) \
1578+
instructions_left--; \
15771579
#else
15781580
#define CHECK_INSTRUCTION_LIMIT() (void)0
15791581
#endif
@@ -1721,7 +1723,10 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
17211723
goto got_exception;
17221724
}
17231725

1724-
HANDLE_OP(WASM_OP_NOP) { HANDLE_OP_END(); }
1726+
HANDLE_OP(WASM_OP_NOP)
1727+
{
1728+
HANDLE_OP_END();
1729+
}
17251730

17261731
#if WASM_ENABLE_EXCE_HANDLING != 0
17271732
HANDLE_OP(WASM_OP_RETHROW)
@@ -5658,7 +5663,10 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
56585663
HANDLE_OP(WASM_OP_I32_REINTERPRET_F32)
56595664
HANDLE_OP(WASM_OP_I64_REINTERPRET_F64)
56605665
HANDLE_OP(WASM_OP_F32_REINTERPRET_I32)
5661-
HANDLE_OP(WASM_OP_F64_REINTERPRET_I64) { HANDLE_OP_END(); }
5666+
HANDLE_OP(WASM_OP_F64_REINTERPRET_I64)
5667+
{
5668+
HANDLE_OP_END();
5669+
}
56625670

56635671
HANDLE_OP(WASM_OP_I32_EXTEND8_S)
56645672
{

‎core/iwasm/interpreter/wasm_interp_fast.c

+8-5
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,14 @@ typedef float64 CellType_F64;
102102
} while (0)
103103

104104
#if WASM_INSTRUCTION_METERING != 0
105-
#define CHECK_INSTRUCTION_LIMIT() \
106-
if (instructions_left == 0) { \
107-
goto return_func; \
108-
} \
109-
instructions_left--;
105+
#define CHECK_INSTRUCTION_LIMIT() \
106+
if (instructions_left == 0) { \
107+
wasm_set_exception(module_inst, "instruction limit exceeded"); \
108+
goto got_exception; \
109+
} \
110+
else if (instructions_left > 0) { \
111+
instructions_left--; \
112+
} \
110113
#else
111114
#define CHECK_INSTRUCTION_LIMIT() (void)0
112115
#endif

0 commit comments

Comments
 (0)
Please sign in to comment.