From cd5ff133f84854f0b269f5cb06193ad8205f05d3 Mon Sep 17 00:00:00 2001 From: Ben Smith Date: Tue, 21 Jul 2020 13:39:04 -0700 Subject: [PATCH] Completely disable signal handler on 32-bit (#1488) The previous change prevented `WASM_RT_MEMCHECK_SIGNAL_HANDLER_POSIX` from being defined, but `WASM_RT_MEMCHECK_SIGNAL_HANDLER` was still defined, which would prevent the memory bounds check. --- wasm2c/wasm-rt.h | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/wasm2c/wasm-rt.h b/wasm2c/wasm-rt.h index a2f70fc5b..2797e8f71 100644 --- a/wasm2c/wasm-rt.h +++ b/wasm2c/wasm-rt.h @@ -35,28 +35,37 @@ extern "C" { #define WASM_RT_MAX_CALL_STACK_DEPTH 500 #endif -/** Whether to enable memory checking via a signal handler. +/** Enable memory checking via a signal handler via the following definition: + * + * #define WASM_RT_MEMCHECK_SIGNAL_HANDLER 1 * * This is usually 10%-25% faster, but requires OS-specific support. * */ + +/** Check whether the signal handler is supported at all. */ +#if (defined(__linux__) || defined(__unix__) || defined(__APPLE__)) && \ + defined(__WORDSIZE) && __WORDSIZE == 64 + +/* If the signal handler is supported, then use it by default. */ #ifndef WASM_RT_MEMCHECK_SIGNAL_HANDLER #define WASM_RT_MEMCHECK_SIGNAL_HANDLER 1 #endif #if WASM_RT_MEMCHECK_SIGNAL_HANDLER -#if defined(__linux__) || defined(__unix__) || defined(__APPLE__) -#if defined(__WORDSIZE) && __WORDSIZE != 64 -#warning "Signal handler is only supported on 64-bit architectures" -#else #define WASM_RT_MEMCHECK_SIGNAL_HANDLER_POSIX 1 #endif + #else -#error "No signal handler implementation for OS!" -#endif + +/* The signal handler is not supported, error out if the user was trying to + * enable it. */ +#if WASM_RT_MEMCHECK_SIGNAL_HANDLER +#error "Signal handler is not supported for this OS/Architecture!" #endif -#ifndef WASM_RT_MEMCHECK_SIGNAL_HANDLER_POSIX +#define WASM_RT_MEMCHECK_SIGNAL_HANDLER 0 #define WASM_RT_MEMCHECK_SIGNAL_HANDLER_POSIX 0 + #endif /** Reason a trap occurred. Provide this to `wasm_rt_trap`. */