Skip to content

Commit deacb7a

Browse files
authored
Fix exec_env_tls assertion in module instantiation (#3844)
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.
1 parent 30539bf commit deacb7a

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

core/iwasm/aot/aot_runtime.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1560,8 +1560,12 @@ execute_post_instantiate_functions(AOTModuleInstance *module_inst,
15601560
if (is_sub_inst) {
15611561
bh_assert(exec_env_main);
15621562
#ifdef OS_ENABLE_HW_BOUND_CHECK
1563-
bh_assert(exec_env_tls == exec_env_main);
1564-
(void)exec_env_tls;
1563+
/* May come from pthread_create_wrapper, thread_spawn_wrapper and
1564+
wasm_cluster_spawn_exec_env. If it comes from the former two,
1565+
the exec_env_tls must be not NULL and equal to exec_env_main,
1566+
else if it comes from the last one, it may be NULL. */
1567+
if (exec_env_tls)
1568+
bh_assert(exec_env_tls == exec_env_main);
15651569
#endif
15661570
exec_env = exec_env_main;
15671571

core/iwasm/interpreter/wasm_runtime.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1594,8 +1594,12 @@ execute_post_instantiate_functions(WASMModuleInstance *module_inst,
15941594
if (is_sub_inst) {
15951595
bh_assert(exec_env_main);
15961596
#ifdef OS_ENABLE_HW_BOUND_CHECK
1597-
bh_assert(exec_env_tls == exec_env_main);
1598-
(void)exec_env_tls;
1597+
/* May come from pthread_create_wrapper, thread_spawn_wrapper and
1598+
wasm_cluster_spawn_exec_env. If it comes from the former two,
1599+
the exec_env_tls must be not NULL and equal to exec_env_main,
1600+
else if it comes from the last one, it may be NULL. */
1601+
if (exec_env_tls)
1602+
bh_assert(exec_env_tls == exec_env_main);
15991603
#endif
16001604
exec_env = exec_env_main;
16011605

0 commit comments

Comments
 (0)