Skip to content

Commit

Permalink
Fix exec_env_tls assertion in module instantiation (#3844)
Browse files Browse the repository at this point in the history
The execute_post_instantiate_functions may be triggered by wasm_cluster_spawn_exec_env,
in which the exec_env_tls can be NULL and cause the assertion invalid.

p.s. #3839.
  • Loading branch information
wenyongh authored Oct 8, 2024
1 parent 30539bf commit deacb7a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
8 changes: 6 additions & 2 deletions core/iwasm/aot/aot_runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -1560,8 +1560,12 @@ execute_post_instantiate_functions(AOTModuleInstance *module_inst,
if (is_sub_inst) {
bh_assert(exec_env_main);
#ifdef OS_ENABLE_HW_BOUND_CHECK
bh_assert(exec_env_tls == exec_env_main);
(void)exec_env_tls;
/* May come from pthread_create_wrapper, thread_spawn_wrapper and
wasm_cluster_spawn_exec_env. If it comes from the former two,
the exec_env_tls must be not NULL and equal to exec_env_main,
else if it comes from the last one, it may be NULL. */
if (exec_env_tls)
bh_assert(exec_env_tls == exec_env_main);
#endif
exec_env = exec_env_main;

Expand Down
8 changes: 6 additions & 2 deletions core/iwasm/interpreter/wasm_runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -1594,8 +1594,12 @@ execute_post_instantiate_functions(WASMModuleInstance *module_inst,
if (is_sub_inst) {
bh_assert(exec_env_main);
#ifdef OS_ENABLE_HW_BOUND_CHECK
bh_assert(exec_env_tls == exec_env_main);
(void)exec_env_tls;
/* May come from pthread_create_wrapper, thread_spawn_wrapper and
wasm_cluster_spawn_exec_env. If it comes from the former two,
the exec_env_tls must be not NULL and equal to exec_env_main,
else if it comes from the last one, it may be NULL. */
if (exec_env_tls)
bh_assert(exec_env_tls == exec_env_main);
#endif
exec_env = exec_env_main;

Expand Down

0 comments on commit deacb7a

Please sign in to comment.