Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow use of guard pages without requiring a signal handler #2029

Merged
merged 1 commit into from
Nov 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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