Skip to content

Commit

Permalink
wasm_cluster_destroy_spawned_exec_env: Avoid "invalid exec env" trap (#…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
yamt authored Jan 23, 2024
1 parent b44aa65 commit ab97d54
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion core/iwasm/libraries/thread-mgr/thread_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -604,11 +604,24 @@ wasm_cluster_destroy_spawned_exec_env(WASMExecEnv *exec_env)
WASMCluster *cluster = wasm_exec_env_get_cluster(exec_env);
wasm_module_inst_t module_inst = wasm_runtime_get_module_inst(exec_env);
bh_assert(cluster != NULL);
WASMExecEnv *exec_env_tls = NULL;

#ifdef OS_ENABLE_HW_BOUND_CHECK
/* Note: free_aux_stack can execute the module's "free" function
* using the specified exec_env. In case of OS_ENABLE_HW_BOUND_CHECK,
* it needs to match the TLS exec_env if available. (Consider a native
* function which calls wasm_cluster_destroy_spawned_exec_env.)
*/
exec_env_tls = wasm_runtime_get_exec_env_tls();
#endif
if (exec_env_tls == NULL) {
exec_env_tls = exec_env;
}

os_mutex_lock(&cluster->lock);

/* Free aux stack space */
free_aux_stack(exec_env, exec_env->aux_stack_bottom.bottom);
free_aux_stack(exec_env_tls, exec_env->aux_stack_bottom.bottom);
/* Remove exec_env */
wasm_cluster_del_exec_env_internal(cluster, exec_env, false);
/* Destroy exec_env */
Expand Down

0 comments on commit ab97d54

Please sign in to comment.