Skip to content

Commit a50cf67

Browse files
committed
wasm2c: Add macro and tests to allow disabling stack exhaustion checks
1 parent 9fdd024 commit a50cf67

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

.github/workflows/build.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ jobs:
172172
runs-on: ubuntu-latest
173173
env:
174174
USE_NINJA: "1"
175-
WASM2C_CFLAGS: "-DWASM_RT_USE_MMAP=1 -DWASM_RT_SKIP_SIGNAL_RECOVERY=1 -DWASM2C_TEST_EMBEDDER_SIGNAL_HANDLING"
175+
WASM2C_CFLAGS: "-DWASM_RT_USE_MMAP=1 -DWASM_RT_SKIP_SIGNAL_RECOVERY=1 -DWASM_RT_NONCONFORMING_UNCHECKED_STACK_EXHAUSTION=1 -DWASM2C_TEST_EMBEDDER_SIGNAL_HANDLING"
176176
steps:
177177
- uses: actions/setup-python@v1
178178
with:
@@ -182,5 +182,5 @@ jobs:
182182
submodules: true
183183
- run: sudo apt-get install ninja-build
184184
- run: make clang-debug
185-
- name: tests (excluding memory64)
186-
run: ./test/run-tests.py --exclude-dir memory64
185+
- name: tests (wasm2c tests excluding memory64)
186+
run: ./test/run-tests.py wasm2c --exclude-dir memory64

wasm2c/wasm-rt.h

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,20 @@ extern "C" {
166166
#define WASM_RT_INSTALL_SIGNAL_HANDLER 0
167167
#endif
168168

169+
/* This macro, if defined, allows the embedder to disable all stack exhaustion
170+
* checks. This a non conformant configuration, i.e., this does not respect
171+
* Wasm's specification, and may compromise security. Use with caution.
172+
*/
173+
#ifndef WASM_RT_NONCONFORMING_UNCHECKED_STACK_EXHAUSTION
174+
#define WASM_RT_NONCONFORMING_UNCHECKED_STACK_EXHAUSTION 0
175+
#endif
176+
169177
/* We need to detect and trap stack overflows. If we use a signal handler on
170178
* POSIX systems, this can detect call stack overflows. On windows, or platforms
171179
* without a signal handler, we use stack depth counting. */
172-
#if !defined(WASM_RT_STACK_DEPTH_COUNT) && \
173-
!defined(WASM_RT_STACK_EXHAUSTION_HANDLER)
180+
#if !defined(WASM_RT_STACK_DEPTH_COUNT) && \
181+
!defined(WASM_RT_STACK_EXHAUSTION_HANDLER) && \
182+
!WASM_RT_NONCONFORMING_UNCHECKED_STACK_EXHAUSTION
174183

175184
#if WASM_RT_INSTALL_SIGNAL_HANDLER && !defined(_WIN32)
176185
#define WASM_RT_STACK_EXHAUSTION_HANDLER 1
@@ -188,6 +197,15 @@ extern "C" {
188197
#define WASM_RT_STACK_EXHAUSTION_HANDLER 0
189198
#endif
190199

200+
#if WASM_RT_NONCONFORMING_UNCHECKED_STACK_EXHAUSTION
201+
202+
#if (WASM_RT_STACK_EXHAUSTION_HANDLER + WASM_RT_STACK_DEPTH_COUNT) != 0
203+
#error \
204+
"Cannot specify WASM_RT_NONCONFORMING_UNCHECKED_STACK_EXHAUSTION along with WASM_RT_STACK_EXHAUSTION_HANDLER or WASM_RT_STACK_DEPTH_COUNT"
205+
#endif
206+
207+
#else
208+
191209
#if (WASM_RT_STACK_EXHAUSTION_HANDLER + WASM_RT_STACK_DEPTH_COUNT) > 1
192210
#error \
193211
"Cannot specify multiple options from WASM_RT_STACK_EXHAUSTION_HANDLER , WASM_RT_STACK_DEPTH_COUNT"
@@ -196,6 +214,8 @@ extern "C" {
196214
"Must specify one of WASM_RT_STACK_EXHAUSTION_HANDLER , WASM_RT_STACK_DEPTH_COUNT"
197215
#endif
198216

217+
#endif
218+
199219
#if WASM_RT_STACK_EXHAUSTION_HANDLER && !WASM_RT_INSTALL_SIGNAL_HANDLER
200220
#error \
201221
"WASM_RT_STACK_EXHAUSTION_HANDLER can only be used if WASM_RT_INSTALL_SIGNAL_HANDLER is enabled"

0 commit comments

Comments
 (0)