Skip to content

Commit ab97d54

Browse files
authored
wasm_cluster_destroy_spawned_exec_env: Avoid "invalid exec env" trap (#3068)
Possible alternatives: * Make wasm_cluster_destroy_spawned_exec_env take two exec_env. One for wasm execution and another to specify the target to destroy. * Make execute functions to switch exec_env as briefly discussed in #2047
1 parent b44aa65 commit ab97d54

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

core/iwasm/libraries/thread-mgr/thread_manager.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,11 +604,24 @@ wasm_cluster_destroy_spawned_exec_env(WASMExecEnv *exec_env)
604604
WASMCluster *cluster = wasm_exec_env_get_cluster(exec_env);
605605
wasm_module_inst_t module_inst = wasm_runtime_get_module_inst(exec_env);
606606
bh_assert(cluster != NULL);
607+
WASMExecEnv *exec_env_tls = NULL;
608+
609+
#ifdef OS_ENABLE_HW_BOUND_CHECK
610+
/* Note: free_aux_stack can execute the module's "free" function
611+
* using the specified exec_env. In case of OS_ENABLE_HW_BOUND_CHECK,
612+
* it needs to match the TLS exec_env if available. (Consider a native
613+
* function which calls wasm_cluster_destroy_spawned_exec_env.)
614+
*/
615+
exec_env_tls = wasm_runtime_get_exec_env_tls();
616+
#endif
617+
if (exec_env_tls == NULL) {
618+
exec_env_tls = exec_env;
619+
}
607620

608621
os_mutex_lock(&cluster->lock);
609622

610623
/* Free aux stack space */
611-
free_aux_stack(exec_env, exec_env->aux_stack_bottom.bottom);
624+
free_aux_stack(exec_env_tls, exec_env->aux_stack_bottom.bottom);
612625
/* Remove exec_env */
613626
wasm_cluster_del_exec_env_internal(cluster, exec_env, false);
614627
/* Destroy exec_env */

0 commit comments

Comments
 (0)