Skip to content

Commit 59282f7

Browse files
authored
Fix native stack overflow check failed in interpreter (#992)
Increase default/min native stack size when UVWASI is enabled as UVWASI requires larger native stack size. Increase the reserved bytes to the native thread stack boundary to better detect the native stack overflow. Set WASM_DISABLE_HW_BOUND_CHECK to 0 when interpreter is enabled and AOT is disabled, as memory access boundary check with hardware trap is only enabled in AOT/JIT mode.
1 parent a22a5da commit 59282f7

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

build-scripts/config_common.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,10 @@ endif ()
198198
if (WAMR_DISABLE_HW_BOUND_CHECK EQUAL 1)
199199
add_definitions (-DWASM_DISABLE_HW_BOUND_CHECK=1)
200200
message (" Hardware boundary check disabled")
201+
elseif (NOT WAMR_BUILD_AOT EQUAL 1)
202+
# Enable memory access boundary check with hardware trap
203+
# only when AOT/JIT is enabled
204+
add_definitions (-DWASM_DISABLE_HW_BOUND_CHECK=1)
201205
else ()
202206
add_definitions (-DWASM_DISABLE_HW_BOUND_CHECK=0)
203207
endif ()

core/config.h

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,28 +285,47 @@
285285
/* Min auxilliary stack size of each wasm thread */
286286
#define WASM_THREAD_AUX_STACK_SIZE_MIN (256)
287287

288-
/* Default/min/max stack size of each app thread */
288+
/* Default/min native stack size of each app thread */
289+
#if !(defined(APP_THREAD_STACK_SIZE_DEFAULT) \
290+
&& defined(APP_THREAD_STACK_SIZE_MIN))
289291
#if defined(BH_PLATFORM_ZEPHYR) || defined(BH_PLATFORM_ALIOS_THINGS) \
290292
|| defined(BH_PLATFORM_ESP_IDF) || defined(BH_PLATFORM_OPENRTOS)
291293
#define APP_THREAD_STACK_SIZE_DEFAULT (6 * 1024)
292294
#define APP_THREAD_STACK_SIZE_MIN (4 * 1024)
293295
#elif defined(PTHREAD_STACK_DEFAULT) && defined(PTHREAD_STACK_MIN)
294296
#define APP_THREAD_STACK_SIZE_DEFAULT PTHREAD_STACK_DEFAULT
295297
#define APP_THREAD_STACK_SIZE_MIN PTHREAD_STACK_MIN
298+
#elif WASM_ENABLE_UVWASI != 0
299+
/* UVWASI requires larger native stack */
300+
#define APP_THREAD_STACK_SIZE_DEFAULT (64 * 1024)
301+
#define APP_THREAD_STACK_SIZE_MIN (48 * 1024)
296302
#else
297303
#define APP_THREAD_STACK_SIZE_DEFAULT (32 * 1024)
298304
#define APP_THREAD_STACK_SIZE_MIN (24 * 1024)
299305
#endif
306+
#endif /* end of !(defined(APP_THREAD_STACK_SIZE_DEFAULT) \
307+
&& defined(APP_THREAD_STACK_SIZE_MIN)) */
308+
309+
/* Max native stack size of each app thread */
300310
#if !defined(APP_THREAD_STACK_SIZE_MAX)
301311
#define APP_THREAD_STACK_SIZE_MAX (8 * 1024 * 1024)
302312
#endif
303313

304314
/* Reserved bytes to the native thread stack boundary, throw native
305315
stack overflow exception if the guard boudary is reached */
306-
#define RESERVED_BYTES_TO_NATIVE_STACK_BOUNDARY (512)
316+
#ifndef RESERVED_BYTES_TO_NATIVE_STACK_BOUNDARY
317+
#if WASM_ENABLE_UVWASI != 0
318+
/* UVWASI requires larger native stack */
319+
#define RESERVED_BYTES_TO_NATIVE_STACK_BOUNDARY (4096 * 6)
320+
#else
321+
#define RESERVED_BYTES_TO_NATIVE_STACK_BOUNDARY (1024)
322+
#endif
323+
#endif
307324

308325
/* Guard page count for stack overflow check with hardware trap */
326+
#ifndef STACK_OVERFLOW_CHECK_GUARD_PAGE_COUNT
309327
#define STACK_OVERFLOW_CHECK_GUARD_PAGE_COUNT 3
328+
#endif
310329

311330
/* Default wasm block address cache size and conflict list size */
312331
#ifndef BLOCK_ADDR_CACHE_SIZE

0 commit comments

Comments
 (0)