diff options
Diffstat (limited to 'wasm2c')
-rw-r--r-- | wasm2c/wasm-rt-impl.c | 25 | ||||
-rw-r--r-- | wasm2c/wasm-rt.h | 10 |
2 files changed, 20 insertions, 15 deletions
diff --git a/wasm2c/wasm-rt-impl.c b/wasm2c/wasm-rt-impl.c index 72e4d66e..5f22d3bf 100644 --- a/wasm2c/wasm-rt-impl.c +++ b/wasm2c/wasm-rt-impl.c @@ -25,7 +25,8 @@ #include <stdlib.h> #include <string.h> -#if WASM_RT_INSTALL_SIGNAL_HANDLER && !defined(_WIN32) +#if (WASM_RT_INSTALL_SIGNAL_HANDLER || !WASM_RT_USE_STACK_DEPTH_COUNT) && \ + !defined(_WIN32) #include <signal.h> #include <unistd.h> #endif @@ -163,17 +164,7 @@ static void os_print_last_error(const char* msg) { perror(msg); } -#if WASM_RT_INSTALL_SIGNAL_HANDLER -static void os_signal_handler(int sig, siginfo_t* si, void* unused) { - if (si->si_code == SEGV_ACCERR) { - wasm_rt_trap(WASM_RT_TRAP_OOB); - } else { - wasm_rt_trap(WASM_RT_TRAP_EXHAUSTION); - } -} - #if !WASM_RT_USE_STACK_DEPTH_COUNT -/* These routines set up an altstack to handle SIGSEGV from stack overflow. */ static bool os_has_altstack_installed() { /* check for altstack already in place */ stack_t ss; @@ -184,7 +175,19 @@ static bool os_has_altstack_installed() { return !(ss.ss_flags & SS_DISABLE); } +#endif + +#if WASM_RT_INSTALL_SIGNAL_HANDLER +static void os_signal_handler(int sig, siginfo_t* si, void* unused) { + if (si->si_code == SEGV_ACCERR) { + wasm_rt_trap(WASM_RT_TRAP_OOB); + } else { + wasm_rt_trap(WASM_RT_TRAP_EXHAUSTION); + } +} +#if !WASM_RT_USE_STACK_DEPTH_COUNT +/* These routines set up an altstack to handle SIGSEGV from stack overflow. */ static void os_allocate_and_install_altstack(void) { /* verify altstack not already allocated */ assert(!g_alt_stack && diff --git a/wasm2c/wasm-rt.h b/wasm2c/wasm-rt.h index a79271e3..fe68aa1d 100644 --- a/wasm2c/wasm-rt.h +++ b/wasm2c/wasm-rt.h @@ -202,7 +202,7 @@ extern WASM_RT_THREAD_LOCAL uint32_t wasm_rt_call_stack_depth; #define WASM_RT_NO_RETURN __attribute__((noreturn)) #endif -#if defined(__APPLE__) && WASM_RT_INSTALL_SIGNAL_HANDLER +#if defined(__APPLE__) && !WASM_RT_USE_STACK_DEPTH_COUNT #define WASM_RT_MERGED_OOB_AND_EXHAUSTION_TRAPS 1 #else #define WASM_RT_MERGED_OOB_AND_EXHAUSTION_TRAPS 0 @@ -218,7 +218,7 @@ typedef enum { WASM_RT_TRAP_UNREACHABLE, /** Unreachable instruction executed. */ WASM_RT_TRAP_CALL_INDIRECT, /** Invalid call_indirect, for any reason. */ WASM_RT_TRAP_UNCAUGHT_EXCEPTION, /* Exception thrown and not caught. */ - WASM_RT_TRAP_UNALIGNED, /** Unaligned atomic instruction executed. */ + WASM_RT_TRAP_UNALIGNED, /** Unaligned atomic instruction executed. */ #if WASM_RT_MERGED_OOB_AND_EXHAUSTION_TRAPS WASM_RT_TRAP_EXHAUSTION = WASM_RT_TRAP_OOB, #else @@ -354,7 +354,8 @@ typedef struct { jmp_buf buffer; } wasm_rt_jmp_buf; -#if WASM_RT_INSTALL_SIGNAL_HANDLER && !defined(_WIN32) +#if (WASM_RT_INSTALL_SIGNAL_HANDLER || (!WASM_RT_USE_STACK_DEPTH_COUNT)) && \ + !defined(_WIN32) #define WASM_RT_SETJMP_SETBUF(buf) sigsetjmp(buf, 1) #else #define WASM_RT_SETJMP_SETBUF(buf) setjmp(buf) @@ -363,7 +364,8 @@ typedef struct { #define WASM_RT_SETJMP(buf) \ ((buf).initialized = true, WASM_RT_SETJMP_SETBUF((buf).buffer)) -#if WASM_RT_INSTALL_SIGNAL_HANDLER && !defined(_WIN32) +#if (WASM_RT_INSTALL_SIGNAL_HANDLER || (!WASM_RT_USE_STACK_DEPTH_COUNT)) && \ + !defined(_WIN32) #define WASM_RT_LONGJMP_UNCHECKED(buf, val) siglongjmp(buf, val) #else #define WASM_RT_LONGJMP_UNCHECKED(buf, val) longjmp(buf, val) |