Skip to content

Commit

Permalink
Allow use of guard pages without requiring a signal handler
Browse files Browse the repository at this point in the history
  • Loading branch information
shravanrn committed Oct 27, 2022
1 parent 59b1b69 commit 5ef16fa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
12 changes: 6 additions & 6 deletions wasm2c/wasm-rt-impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include <stdlib.h>
#include <string.h>

#if WASM_RT_MEMCHECK_SIGNAL_HANDLER_POSIX
#if WASM_RT_MEMCHECK_SIGNAL_HANDLER_POSIX && !WASM_RT_SKIP_SIGNAL_RECOVERY
#include <signal.h>
#include <unistd.h>
#endif
Expand All @@ -46,7 +46,7 @@ typedef struct FuncType {
uint32_t result_count;
} FuncType;

#if WASM_RT_MEMCHECK_SIGNAL_HANDLER
#if WASM_RT_MEMCHECK_SIGNAL_HANDLER && !WASM_RT_SKIP_SIGNAL_RECOVERY
static bool g_signal_handler_installed = false;
static char* g_alt_stack;
#else
Expand Down Expand Up @@ -163,7 +163,7 @@ void* wasm_rt_exception(void) {
return g_active_exception;
}

#if WASM_RT_MEMCHECK_SIGNAL_HANDLER_POSIX
#if WASM_RT_MEMCHECK_SIGNAL_HANDLER_POSIX && !WASM_RT_SKIP_SIGNAL_RECOVERY
static void signal_handler(int sig, siginfo_t* si, void* unused) {
if (si->si_code == SEGV_ACCERR) {
wasm_rt_trap(WASM_RT_TRAP_OOB);
Expand Down Expand Up @@ -230,7 +230,7 @@ static void os_print_last_error(const char* msg) {
#endif

void wasm_rt_init(void) {
#if WASM_RT_MEMCHECK_SIGNAL_HANDLER_POSIX
#if WASM_RT_MEMCHECK_SIGNAL_HANDLER_POSIX && !WASM_RT_SKIP_SIGNAL_RECOVERY
if (!g_signal_handler_installed) {
g_signal_handler_installed = true;

Expand Down Expand Up @@ -266,15 +266,15 @@ void wasm_rt_init(void) {
}

bool wasm_rt_is_initialized(void) {
#if WASM_RT_MEMCHECK_SIGNAL_HANDLER_POSIX
#if WASM_RT_MEMCHECK_SIGNAL_HANDLER_POSIX && !WASM_RT_SKIP_SIGNAL_RECOVERY
return g_signal_handler_installed;
#else
return true;
#endif
}

void wasm_rt_free(void) {
#if WASM_RT_MEMCHECK_SIGNAL_HANDLER_POSIX
#if WASM_RT_MEMCHECK_SIGNAL_HANDLER_POSIX && !WASM_RT_SKIP_SIGNAL_RECOVERY
free(g_alt_stack);
#endif
}
Expand Down
4 changes: 4 additions & 0 deletions wasm2c/wasm-rt.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ extern "C" {
#define wasm_rt_memcpy memcpy
#endif

#ifndef WASM_RT_SKIP_SIGNAL_RECOVERY
#define WASM_RT_SKIP_SIGNAL_RECOVERY 0
#endif

/**
* Enable memory checking via a signal handler via the following definition:
*
Expand Down

0 comments on commit 5ef16fa

Please sign in to comment.