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.
This commit is contained in:
Wenyong Huang 2022-02-11 11:43:03 +08:00 committed by GitHub
parent a22a5da40d
commit 59282f7ddb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 2 deletions

View File

@ -198,6 +198,10 @@ endif ()
if (WAMR_DISABLE_HW_BOUND_CHECK EQUAL 1)
add_definitions (-DWASM_DISABLE_HW_BOUND_CHECK=1)
message (" Hardware boundary check disabled")
elseif (NOT WAMR_BUILD_AOT EQUAL 1)
# Enable memory access boundary check with hardware trap
# only when AOT/JIT is enabled
add_definitions (-DWASM_DISABLE_HW_BOUND_CHECK=1)
else ()
add_definitions (-DWASM_DISABLE_HW_BOUND_CHECK=0)
endif ()

View File

@ -285,7 +285,9 @@
/* Min auxilliary stack size of each wasm thread */
#define WASM_THREAD_AUX_STACK_SIZE_MIN (256)
/* Default/min/max stack size of each app thread */
/* Default/min native stack size of each app thread */
#if !(defined(APP_THREAD_STACK_SIZE_DEFAULT) \
&& defined(APP_THREAD_STACK_SIZE_MIN))
#if defined(BH_PLATFORM_ZEPHYR) || defined(BH_PLATFORM_ALIOS_THINGS) \
|| defined(BH_PLATFORM_ESP_IDF) || defined(BH_PLATFORM_OPENRTOS)
#define APP_THREAD_STACK_SIZE_DEFAULT (6 * 1024)
@ -293,20 +295,37 @@
#elif defined(PTHREAD_STACK_DEFAULT) && defined(PTHREAD_STACK_MIN)
#define APP_THREAD_STACK_SIZE_DEFAULT PTHREAD_STACK_DEFAULT
#define APP_THREAD_STACK_SIZE_MIN PTHREAD_STACK_MIN
#elif WASM_ENABLE_UVWASI != 0
/* UVWASI requires larger native stack */
#define APP_THREAD_STACK_SIZE_DEFAULT (64 * 1024)
#define APP_THREAD_STACK_SIZE_MIN (48 * 1024)
#else
#define APP_THREAD_STACK_SIZE_DEFAULT (32 * 1024)
#define APP_THREAD_STACK_SIZE_MIN (24 * 1024)
#endif
#endif /* end of !(defined(APP_THREAD_STACK_SIZE_DEFAULT) \
&& defined(APP_THREAD_STACK_SIZE_MIN)) */
/* Max native stack size of each app thread */
#if !defined(APP_THREAD_STACK_SIZE_MAX)
#define APP_THREAD_STACK_SIZE_MAX (8 * 1024 * 1024)
#endif
/* Reserved bytes to the native thread stack boundary, throw native
stack overflow exception if the guard boudary is reached */
#define RESERVED_BYTES_TO_NATIVE_STACK_BOUNDARY (512)
#ifndef RESERVED_BYTES_TO_NATIVE_STACK_BOUNDARY
#if WASM_ENABLE_UVWASI != 0
/* UVWASI requires larger native stack */
#define RESERVED_BYTES_TO_NATIVE_STACK_BOUNDARY (4096 * 6)
#else
#define RESERVED_BYTES_TO_NATIVE_STACK_BOUNDARY (1024)
#endif
#endif
/* Guard page count for stack overflow check with hardware trap */
#ifndef STACK_OVERFLOW_CHECK_GUARD_PAGE_COUNT
#define STACK_OVERFLOW_CHECK_GUARD_PAGE_COUNT 3
#endif
/* Default wasm block address cache size and conflict list size */
#ifndef BLOCK_ADDR_CACHE_SIZE