thread mgr: Free aux stack only when it was allocated (#3282)

When thread manager is enabled, the aux stack of exec_env may be allocated
by wasm_cluster_allocate_aux_stack or disabled by setting aux_stack_bottom
as UINTPTR_MAX directly. For the latter, no need to free it.

And fix an issue when paring `--gc-heap-size=n` argument for iwasm, and
fix a variable shadowed warning in fast-jit.
This commit is contained in:
Wenyong Huang
2024-04-08 09:06:49 +08:00
committed by GitHub
parent 4ef724bbff
commit b11dbcba0a
4 changed files with 19 additions and 7 deletions

View File

@ -558,6 +558,7 @@ wasm_cluster_spawn_exec_env(WASMExecEnv *exec_env)
aux_stack_size)) {
goto fail3;
}
new_exec_env->is_aux_stack_allocated = true;
/* Inherit suspend_flags of parent thread */
new_exec_env->suspend_flags.flags =
@ -603,7 +604,9 @@ wasm_cluster_destroy_spawned_exec_env(WASMExecEnv *exec_env)
exec_env_tls = exec_env;
}
/* Free aux stack space */
/* Free aux stack space which was allocated in
wasm_cluster_spawn_exec_env */
bh_assert(exec_env_tls->is_aux_stack_allocated);
wasm_cluster_free_aux_stack(exec_env_tls,
(uint64)exec_env->aux_stack_bottom);
@ -655,7 +658,9 @@ thread_manager_start_routine(void *arg)
#endif
/* Free aux stack space */
wasm_cluster_free_aux_stack(exec_env, (uint64)exec_env->aux_stack_bottom);
if (exec_env->is_aux_stack_allocated)
wasm_cluster_free_aux_stack(exec_env,
(uint64)exec_env->aux_stack_bottom);
os_mutex_lock(&cluster_list_lock);
@ -723,11 +728,13 @@ wasm_cluster_create_thread(WASMExecEnv *exec_env,
aux_stack_size)) {
goto fail2;
}
new_exec_env->is_aux_stack_allocated = true;
}
else {
/* Disable aux stack */
new_exec_env->aux_stack_boundary = 0;
new_exec_env->aux_stack_bottom = UINTPTR_MAX;
new_exec_env->is_aux_stack_allocated = false;
}
/* Inherit suspend_flags of parent thread */
@ -1049,7 +1056,9 @@ wasm_cluster_exit_thread(WASMExecEnv *exec_env, void *retval)
#endif
/* Free aux stack space */
wasm_cluster_free_aux_stack(exec_env, (uint64)exec_env->aux_stack_bottom);
if (exec_env->is_aux_stack_allocated)
wasm_cluster_free_aux_stack(exec_env,
(uint64)exec_env->aux_stack_bottom);
/* App exit the thread, free the resources before exit native thread */