wasm-micro-runtime/core/iwasm/aot
Steven 5664589daa
fix: clear exec_env_tls when destroying exec_env (#4774)
* fix: clear exec_env_tls when destroying exec_env

When an exec_env is destroyed, check if it matches the current thread's
exec_env_tls and clear it to avoid dangling pointer issues.

Without this fix, in daemon-style execution where the same thread runs
multiple WASM modules sequentially (like Cloudflare Workers), the
exec_env_tls can point to freed memory after an exec_env is destroyed,
causing crashes on subsequent executions when the signal handler tries
to access it.

This is critical for AOT mode with hardware bounds checking enabled,
where signal handlers rely on exec_env_tls to handle SIGSEGV properly.

* test(exec_env): add reproducer for exec_env_tls dangling pointer bug

Add test case that reproduces the bug where exec_env_tls is not cleared
on early return paths in invoke_native_with_hw_bound_check.

The test triggers native stack overflow check failure, which causes
wasm_runtime_call_wasm to return early after setting exec_env_tls but
without clearing it. This leaves exec_env_tls pointing to a destroyed
exec_env, causing subsequent calls to fail with "invalid exec env".

Test confirms the fix in wasm_exec_env_destroy correctly clears
exec_env_tls when destroying the exec_env it points to.

* fix(runtime): clear exec_env_tls on early return from stack overflow check

Move the fix to clear exec_env_tls at the source - in the early return
path of invoke_native_with_hw_bound_check when native stack overflow
check fails.
2026-01-20 07:09:26 +08:00
..
arch Add missing functions from thumb arch (#4718) 2025-11-28 17:08:24 +08:00
debug Appease GCC strict prototypes warning (#3775) 2024-09-10 09:42:23 +08:00
aot_intrinsic.c Enable -Wdouble-promotion by default and fix related warnings (#4603) 2025-09-12 08:44:42 +08:00
aot_intrinsic.h fix return types of our 64-bit clz/ctz/popcount intrinsics (#4238) 2025-05-06 10:15:00 +08:00
aot_loader.c aot: avoid forcing mmap low addresses on NuttX (#4776) 2026-01-05 10:57:18 +08:00
aot_perf_map.c Add missing casts and improve error handling in performance map functions (#4202) 2025-04-17 15:22:23 +08:00
aot_perf_map.h Enhance wasm loading with LoadArgs and support module names (#3265) 2024-04-07 15:04:35 +08:00
aot_reloc.h Shared heap enhancements for Interpreter and AOT (#4400) 2025-07-04 10:44:51 +08:00
aot_runtime.c fix: clear exec_env_tls when destroying exec_env (#4774) 2026-01-20 07:09:26 +08:00
aot_runtime.h Pass InstantiationArgs2 down to aot_instantiate/wasm_instantiate (#4594) 2025-10-23 15:57:50 +08:00
aot_validator.c add a validator for aot module (#3995) 2025-02-05 15:21:49 +08:00
aot_validator.h add a validator for aot module (#3995) 2025-02-05 15:21:49 +08:00
iwasm_aot.cmake Keep fix the CMake compatibility issue (#4180) 2025-04-15 12:51:19 +08:00
SConscript Add ia32 support and fix compiling issue for RT-Thread (#730) 2021-09-07 10:20:14 +08:00