diff options
author | Shravan Narayan <shravanrn@gmail.com> | 2023-12-15 00:29:01 -0600 |
---|---|---|
committer | Shravan Narayan <shravanrn@gmail.com> | 2024-01-02 08:35:49 -0600 |
commit | b85ecbec261ff7e84351505da3b2c45d9ea8d3c7 (patch) | |
tree | 8ff64733623679138d1548acd596a67ddcfe4fdf | |
parent | 9fdd024249b6b181d98a4164700ca6ee09f970d9 (diff) | |
download | wabt-b85ecbec261ff7e84351505da3b2c45d9ea8d3c7.tar.gz wabt-b85ecbec261ff7e84351505da3b2c45d9ea8d3c7.tar.bz2 wabt-b85ecbec261ff7e84351505da3b2c45d9ea8d3c7.zip |
wasm2c: Add macro and tests to allow disabling stack exhaustion checks
-rw-r--r-- | .github/workflows/build.yml | 6 | ||||
-rw-r--r-- | wasm2c/wasm-rt.h | 24 |
2 files changed, 25 insertions, 5 deletions
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 29af531f..2b086ccf 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -172,7 +172,7 @@ jobs: runs-on: ubuntu-latest env: USE_NINJA: "1" - WASM2C_CFLAGS: "-DWASM_RT_USE_MMAP=1 -DWASM_RT_SKIP_SIGNAL_RECOVERY=1 -DWASM2C_TEST_EMBEDDER_SIGNAL_HANDLING" + 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" steps: - uses: actions/setup-python@v1 with: @@ -182,5 +182,5 @@ jobs: submodules: true - run: sudo apt-get install ninja-build - run: make clang-debug - - name: tests (excluding memory64) - run: ./test/run-tests.py --exclude-dir memory64 + - name: tests (wasm2c tests excluding memory64) + run: ./test/run-tests.py wasm2c --exclude-dir memory64 diff --git a/wasm2c/wasm-rt.h b/wasm2c/wasm-rt.h index 55b3cce8..bd0cd61d 100644 --- a/wasm2c/wasm-rt.h +++ b/wasm2c/wasm-rt.h @@ -166,11 +166,20 @@ extern "C" { #define WASM_RT_INSTALL_SIGNAL_HANDLER 0 #endif +/* This macro, if defined, allows the embedder to disable all stack exhaustion + * checks. This a non conformant configuration, i.e., this does not respect + * Wasm's specification, and may compromise security. Use with caution. + */ +#ifndef WASM_RT_NONCONFORMING_UNCHECKED_STACK_EXHAUSTION +#define WASM_RT_NONCONFORMING_UNCHECKED_STACK_EXHAUSTION 0 +#endif + /* We need to detect and trap stack overflows. If we use a signal handler on * POSIX systems, this can detect call stack overflows. On windows, or platforms * without a signal handler, we use stack depth counting. */ -#if !defined(WASM_RT_STACK_DEPTH_COUNT) && \ - !defined(WASM_RT_STACK_EXHAUSTION_HANDLER) +#if !defined(WASM_RT_STACK_DEPTH_COUNT) && \ + !defined(WASM_RT_STACK_EXHAUSTION_HANDLER) && \ + !WASM_RT_NONCONFORMING_UNCHECKED_STACK_EXHAUSTION #if WASM_RT_INSTALL_SIGNAL_HANDLER && !defined(_WIN32) #define WASM_RT_STACK_EXHAUSTION_HANDLER 1 @@ -188,6 +197,15 @@ extern "C" { #define WASM_RT_STACK_EXHAUSTION_HANDLER 0 #endif +#if WASM_RT_NONCONFORMING_UNCHECKED_STACK_EXHAUSTION + +#if (WASM_RT_STACK_EXHAUSTION_HANDLER + WASM_RT_STACK_DEPTH_COUNT) != 0 +#error \ + "Cannot specify WASM_RT_NONCONFORMING_UNCHECKED_STACK_EXHAUSTION along with WASM_RT_STACK_EXHAUSTION_HANDLER or WASM_RT_STACK_DEPTH_COUNT" +#endif + +#else + #if (WASM_RT_STACK_EXHAUSTION_HANDLER + WASM_RT_STACK_DEPTH_COUNT) > 1 #error \ "Cannot specify multiple options from WASM_RT_STACK_EXHAUSTION_HANDLER , WASM_RT_STACK_DEPTH_COUNT" @@ -196,6 +214,8 @@ extern "C" { "Must specify one of WASM_RT_STACK_EXHAUSTION_HANDLER , WASM_RT_STACK_DEPTH_COUNT" #endif +#endif + #if WASM_RT_STACK_EXHAUSTION_HANDLER && !WASM_RT_INSTALL_SIGNAL_HANDLER #error \ "WASM_RT_STACK_EXHAUSTION_HANDLER can only be used if WASM_RT_INSTALL_SIGNAL_HANDLER is enabled" |