@@ -1743,6 +1743,30 @@ wasm_runtime_finalize_call_function(WASMExecEnv *exec_env,
17431743}
17441744#endif
17451745
1746+ static bool
1747+ clear_wasi_proc_exit_exception (WASMModuleInstanceCommon * module_inst_comm )
1748+ {
1749+ #if WASM_ENABLE_LIBC_WASI != 0
1750+ const char * exception ;
1751+ WASMModuleInstance * module_inst = (WASMModuleInstance * )module_inst_comm ;
1752+
1753+ bh_assert (module_inst_comm -> module_type == Wasm_Module_Bytecode
1754+ || module_inst_comm -> module_type == Wasm_Module_AoT );
1755+
1756+ exception = wasm_get_exception (module_inst );
1757+ if (exception && !strcmp (exception , "Exception: wasi proc exit" )) {
1758+ /* The "wasi proc exit" exception is thrown by native lib to
1759+ let wasm app exit, which is a normal behavior, we clear
1760+ the exception here. */
1761+ wasm_set_exception (module_inst , NULL );
1762+ return true;
1763+ }
1764+ return false;
1765+ #else
1766+ return false;
1767+ #endif
1768+ }
1769+
17461770bool
17471771wasm_runtime_call_wasm (WASMExecEnv * exec_env ,
17481772 WASMFunctionInstanceCommon * function , uint32 argc ,
@@ -1783,10 +1807,15 @@ wasm_runtime_call_wasm(WASMExecEnv *exec_env,
17831807 param_argc , new_argv );
17841808#endif
17851809 if (!ret ) {
1786- if (new_argv != argv ) {
1787- wasm_runtime_free (new_argv );
1810+ if (clear_wasi_proc_exit_exception (exec_env -> module_inst )) {
1811+ ret = true;
1812+ }
1813+ else {
1814+ if (new_argv != argv ) {
1815+ wasm_runtime_free (new_argv );
1816+ }
1817+ return false;
17881818 }
1789- return false;
17901819 }
17911820
17921821#if WASM_ENABLE_REF_TYPES != 0
@@ -2150,11 +2179,25 @@ wasm_runtime_get_exec_env_singleton(WASMModuleInstanceCommon *module_inst_comm)
21502179void
21512180wasm_set_exception (WASMModuleInstance * module_inst , const char * exception )
21522181{
2153- if (exception )
2182+ WASMExecEnv * exec_env = NULL ;
2183+
2184+ if (exception ) {
21542185 snprintf (module_inst -> cur_exception , sizeof (module_inst -> cur_exception ),
21552186 "Exception: %s" , exception );
2156- else
2187+ }
2188+ else {
21572189 module_inst -> cur_exception [0 ] = '\0' ;
2190+ }
2191+
2192+ #if WASM_ENABLE_THREAD_MGR != 0
2193+ exec_env =
2194+ wasm_clusters_search_exec_env ((WASMModuleInstanceCommon * )module_inst );
2195+ if (exec_env ) {
2196+ wasm_cluster_spread_exception (exec_env , exception ? false : true);
2197+ }
2198+ #else
2199+ (void )exec_env ;
2200+ #endif
21582201}
21592202
21602203/* clang-format off */
@@ -4179,6 +4222,8 @@ bool
41794222wasm_runtime_call_indirect (WASMExecEnv * exec_env , uint32 element_indices ,
41804223 uint32 argc , uint32 argv [])
41814224{
4225+ bool ret = false;
4226+
41824227 if (!wasm_runtime_exec_env_check (exec_env )) {
41834228 LOG_ERROR ("Invalid exec env stack info." );
41844229 return false;
@@ -4190,13 +4235,18 @@ wasm_runtime_call_indirect(WASMExecEnv *exec_env, uint32 element_indices,
41904235
41914236#if WASM_ENABLE_INTERP != 0
41924237 if (exec_env -> module_inst -> module_type == Wasm_Module_Bytecode )
4193- return wasm_call_indirect (exec_env , 0 , element_indices , argc , argv );
4238+ ret = wasm_call_indirect (exec_env , 0 , element_indices , argc , argv );
41944239#endif
41954240#if WASM_ENABLE_AOT != 0
41964241 if (exec_env -> module_inst -> module_type == Wasm_Module_AoT )
4197- return aot_call_indirect (exec_env , 0 , element_indices , argc , argv );
4242+ ret = aot_call_indirect (exec_env , 0 , element_indices , argc , argv );
41984243#endif
4199- return false;
4244+
4245+ if (!ret && clear_wasi_proc_exit_exception (exec_env -> module_inst )) {
4246+ ret = true;
4247+ }
4248+
4249+ return ret ;
42004250}
42014251
42024252static void
0 commit comments