Skip to content

Commit

Permalink
Fixups
Browse files Browse the repository at this point in the history
  • Loading branch information
keithw committed Dec 3, 2023
1 parent 60c2c7e commit 65eb03a
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions wasm2c/wasm-rt-impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,17 +163,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;
Expand All @@ -184,11 +174,23 @@ 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 &&
"wasm-rt error: tried to re-allocate thread-local alternate stack\n");
"wasm-rt error: tried to re-allocate thread-local alternate stack");

/* We could check and warn if an altstack is already installed, but some
* sanitizers install their own altstack, so this warning would fire
Expand All @@ -214,12 +216,8 @@ static void os_allocate_and_install_altstack(void) {

static void os_disable_and_deallocate_altstack(void) {
/* in debug build, verify altstack allocated */
#ifndef NDEBUG
if (!g_alt_stack) {
fprintf(stderr, "wasm-rt error: alternate stack is NULL\n");
abort();
}
#endif
assert(g_alt_stack &&
"wasm-rt error: thread-local alternate stack not allocated");

/* verify altstack was still in place */
stack_t ss;
Expand Down

0 comments on commit 65eb03a

Please sign in to comment.