From 46695b992ce4501bd9de847f835dc09a6095bc5c Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Fri, 12 Jul 2024 12:00:55 +0900 Subject: [PATCH] EH: Use the consistent type for EH handlers (#3619) The "handlers" on the interpreter stack is sometimes treated as host pointers and sometimes treated as i64 values. It's quite broken for targets where pointers are not 64-bit. This commit makes them host pointers consistently. (at least for 32-bit and 64-bit pointers. We don't support other pointer sizes anyway.) Fixes https://github.com/bytecodealliance/wasm-micro-runtime/issues/3110 --- core/iwasm/interpreter/wasm_interp_classic.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/core/iwasm/interpreter/wasm_interp_classic.c b/core/iwasm/interpreter/wasm_interp_classic.c index b4128392..6a5e9ae1 100644 --- a/core/iwasm/interpreter/wasm_interp_classic.c +++ b/core/iwasm/interpreter/wasm_interp_classic.c @@ -495,6 +495,12 @@ wasm_interp_get_frame_ref(WASMInterpFrame *frame) } while (0) #endif +#if UINTPTR_MAX == UINT64_MAX +#define PUSH_PTR(value) PUSH_I64(value) +#else +#define PUSH_PTR(value) PUSH_I32(value) +#endif + /* in exception handling, label_type needs to be stored to lookup exception * handlers */ @@ -1892,19 +1898,19 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, switch (handler_opcode) { case WASM_OP_CATCH: skip_leb(lookup_cursor); /* skip tag_index */ - PUSH_I64(end_addr); + PUSH_PTR(end_addr); break; case WASM_OP_CATCH_ALL: - PUSH_I64(end_addr); + PUSH_PTR(end_addr); break; case WASM_OP_DELEGATE: skip_leb(lookup_cursor); /* skip depth */ - PUSH_I64(end_addr); + PUSH_PTR(end_addr); /* patch target_addr */ (frame_csp - 1)->target_addr = lookup_cursor; break; case WASM_OP_END: - PUSH_I64(0); + PUSH_PTR(0); /* patch target_addr */ (frame_csp - 1)->target_addr = end_addr; break;