summaryrefslogtreecommitdiff
path: root/src/prebuilt
diff options
context:
space:
mode:
authorKeith Winstein <keithw@cs.stanford.edu>2022-04-04 21:07:34 -0700
committerGitHub <noreply@github.com>2022-04-04 21:07:34 -0700
commit26ce1caf0a9fb9104b71faac5b7478cd6b72cf8d (patch)
treeff350a4c99c985a80950e1d6c7dfb531538029bf /src/prebuilt
parentab2a5ae5f090048885f6d4f0dfa8baa03edd831c (diff)
downloadwabt-26ce1caf0a9fb9104b71faac5b7478cd6b72cf8d.tar.gz
wabt-26ce1caf0a9fb9104b71faac5b7478cd6b72cf8d.tar.bz2
wabt-26ce1caf0a9fb9104b71faac5b7478cd6b72cf8d.zip
wasm2c: use signal handler to detect stack exhaustion (#1875)
On MacOS, merge OOB and exhaustion traps. (Linux distinguishes these as SEGV_ACCERR vs. SEGV_MAPERR in the si_code, but MacOS seems to deliver a SEGV_ACCERR for both.) Add wasm_rt_init() and wasm_rt_free() functions to wasm-rt.h that the embedder must call to set up and clean up the runtime state. (If the embedder doesn't call these, OOB and exhaustion will result in an uncaught segfault.)
Diffstat (limited to 'src/prebuilt')
-rw-r--r--src/prebuilt/wasm2c.include.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/prebuilt/wasm2c.include.c b/src/prebuilt/wasm2c.include.c
index cf511212..96a25f23 100644
--- a/src/prebuilt/wasm2c.include.c
+++ b/src/prebuilt/wasm2c.include.c
@@ -9,11 +9,17 @@ const char SECTION_NAME(declarations)[] =
"\n"
"#define TRAP(x) (wasm_rt_trap(WASM_RT_TRAP_##x), 0)\n"
"\n"
+"#if WASM_RT_MEMCHECK_SIGNAL_HANDLER\n"
+"#define FUNC_PROLOGUE\n"
+"\n"
+"#define FUNC_EPILOGUE\n"
+"#else\n"
"#define FUNC_PROLOGUE \\\n"
" if (++wasm_rt_call_stack_depth > WASM_RT_MAX_CALL_STACK_DEPTH) \\\n"
" TRAP(EXHAUSTION)\n"
"\n"
"#define FUNC_EPILOGUE --wasm_rt_call_stack_depth\n"
+"#endif\n"
"\n"
"#define UNREACHABLE TRAP(UNREACHABLE)\n"
"\n"