From c48dd5ccd7eeddeae7622e835f6d15af9b62159d Mon Sep 17 00:00:00 2001 From: James Ring Date: Fri, 9 May 2025 02:14:33 -0700 Subject: [PATCH] Don't call os_thread_get_stack_boundary unless we actually use it (#4264) Previously, if the user sets their own stack boundary, we still compute the thread stack boundary (which is expensive), then immediately discard the result. This change makes the expensive call only if we need it for sure. --- core/iwasm/common/wasm_exec_env.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/iwasm/common/wasm_exec_env.c b/core/iwasm/common/wasm_exec_env.c index e33fd9f3..27484dfc 100644 --- a/core/iwasm/common/wasm_exec_env.c +++ b/core/iwasm/common/wasm_exec_env.c @@ -276,8 +276,6 @@ wasm_exec_env_restore_module_inst( void wasm_exec_env_set_thread_info(WASMExecEnv *exec_env) { - uint8 *stack_boundary = os_thread_get_stack_boundary(); - #if WASM_ENABLE_THREAD_MGR != 0 os_mutex_lock(&exec_env->wait_lock); #endif @@ -286,9 +284,11 @@ wasm_exec_env_set_thread_info(WASMExecEnv *exec_env) /* WASM_STACK_GUARD_SIZE isn't added for flexibility to developer, he must ensure that enough guard bytes are kept. */ exec_env->native_stack_boundary = exec_env->user_native_stack_boundary; - else + else { + uint8 *stack_boundary = os_thread_get_stack_boundary(); exec_env->native_stack_boundary = stack_boundary ? stack_boundary + WASM_STACK_GUARD_SIZE : NULL; + } exec_env->native_stack_top_min = (void *)UINTPTR_MAX; #if WASM_ENABLE_THREAD_MGR != 0 os_mutex_unlock(&exec_env->wait_lock);