From 3849ece49675dc5120a57bff587dcdc84f5ddc4c Mon Sep 17 00:00:00 2001 From: Wenyong Huang Date: Tue, 9 Feb 2021 20:11:32 -0600 Subject: [PATCH] Fix auxiliary stack size not 16-byte aligned issue (#524) --- core/config.h | 2 ++ core/iwasm/libraries/thread-mgr/thread_manager.c | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/core/config.h b/core/config.h index 74ada171..e8ab5bb2 100644 --- a/core/config.h +++ b/core/config.h @@ -241,6 +241,8 @@ #else #define DEFAULT_WASM_STACK_SIZE (12 * 1024) #endif +/* 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 */ #if !defined(BH_PLATFORM_ZEPHYR) && !defined(BH_PLATFORM_ALIOS_THINGS) \ diff --git a/core/iwasm/libraries/thread-mgr/thread_manager.c b/core/iwasm/libraries/thread-mgr/thread_manager.c index dfed25be..6f2dcbae 100644 --- a/core/iwasm/libraries/thread-mgr/thread_manager.c +++ b/core/iwasm/libraries/thread-mgr/thread_manager.c @@ -151,9 +151,11 @@ wasm_cluster_create(WASMExecEnv *exec_env) } cluster->stack_size = aux_stack_size / (cluster_max_thread_num + 1); - if (cluster->stack_size == 0) { + if (cluster->stack_size < WASM_THREAD_AUX_STACK_SIZE_MIN) { goto fail; } + /* Make stack size 16-byte aligned */ + cluster->stack_size = cluster->stack_size & (~15); /* Set initial aux stack top to the instance and aux stack boundary to the main exec_env */