summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShravan Narayan <shravanrn@gmail.com>2022-10-27 16:24:49 -0400
committerShravan Narayan <shravanrn@gmail.com>2022-11-02 12:38:19 -0400
commit64941b6a140c78514500ace9910172fa4c9e1ef6 (patch)
tree7cc4c5d618216fdaf1ac0529e431869fa5455506
parent8c8e8fdfb0911199ded02771629f84229d2e8197 (diff)
downloadwabt-64941b6a140c78514500ace9910172fa4c9e1ef6.tar.gz
wabt-64941b6a140c78514500ace9910172fa4c9e1ef6.tar.bz2
wabt-64941b6a140c78514500ace9910172fa4c9e1ef6.zip
Allow use of guard pages without requiring a signal handler
-rw-r--r--wasm2c/wasm-rt-impl.c12
-rw-r--r--wasm2c/wasm-rt.h4
2 files changed, 10 insertions, 6 deletions
diff --git a/wasm2c/wasm-rt-impl.c b/wasm2c/wasm-rt-impl.c
index 0ef58a7c..3fcf0391 100644
--- a/wasm2c/wasm-rt-impl.c
+++ b/wasm2c/wasm-rt-impl.c
@@ -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
@@ -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
@@ -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);
@@ -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;
@@ -266,7 +266,7 @@ 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;
@@ -274,7 +274,7 @@ bool wasm_rt_is_initialized(void) {
}
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
}
diff --git a/wasm2c/wasm-rt.h b/wasm2c/wasm-rt.h
index f78a8b42..d7be800f 100644
--- a/wasm2c/wasm-rt.h
+++ b/wasm2c/wasm-rt.h
@@ -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:
*