-
Notifications
You must be signed in to change notification settings - Fork 636
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Main thread spread exception when thread-mgr enabled #1889
Merged
wenyongh
merged 20 commits into
bytecodealliance:main
from
xujuntwt95329:main_thread_spread
Jan 20, 2023
Merged
Changes from 19 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
3d416ab
main thread spread exception
xujuntwt95329 9067254
terminate threads when spread exception
xujuntwt95329 c72dfc9
add file header
xujuntwt95329 4174215
auto format
xujuntwt95329 2d3da36
spread exception during throwing
xujuntwt95329 ff1bd10
restore unused modification
xujuntwt95329 a4a2bb6
minor fix
xujuntwt95329 0016228
refactor wasi proc exception processing
xujuntwt95329 2426fd8
minor fix
xujuntwt95329 fc5c945
fix build error
xujuntwt95329 c770575
fix typo
xujuntwt95329 12cf0af
address some PR comments
xujuntwt95329 8f0a046
add lock when traversing list in thread-mgr
xujuntwt95329 1ace00f
avoid creating new thread while spreading exception
xujuntwt95329 d0f5d94
fix dead lock issue
xujuntwt95329 d7d78c0
update comments
xujuntwt95329 f30f900
check return value
xujuntwt95329 1d6553e
fix spec test issue
xujuntwt95329 315985b
fix sgx spec test issue
xujuntwt95329 d939080
address PR comments
xujuntwt95329 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1743,6 +1743,30 @@ wasm_runtime_finalize_call_function(WASMExecEnv *exec_env, | |
} | ||
#endif | ||
|
||
bool | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can set to static if the above is ok |
||
clear_wasi_proc_exit_exception(WASMModuleInstanceCommon *module_inst_comm) | ||
{ | ||
#if WASM_ENABLE_LIBC_WASI != 0 | ||
const char *exception; | ||
WASMModuleInstance *module_inst = (WASMModuleInstance *)module_inst_comm; | ||
|
||
bh_assert(module_inst_comm->module_type == Wasm_Module_Bytecode | ||
|| module_inst_comm->module_type == Wasm_Module_AoT); | ||
|
||
exception = wasm_get_exception(module_inst); | ||
if (exception && !strcmp(exception, "Exception: wasi proc exit")) { | ||
/* The "wasi proc exit" exception is thrown by native lib to | ||
let wasm app exit, which is a normal behavior, we clear | ||
the exception here. */ | ||
wasm_set_exception(module_inst, NULL); | ||
return true; | ||
} | ||
return false; | ||
#else | ||
return false; | ||
#endif | ||
} | ||
|
||
bool | ||
wasm_runtime_call_wasm(WASMExecEnv *exec_env, | ||
WASMFunctionInstanceCommon *function, uint32 argc, | ||
|
@@ -1783,10 +1807,15 @@ wasm_runtime_call_wasm(WASMExecEnv *exec_env, | |
param_argc, new_argv); | ||
#endif | ||
if (!ret) { | ||
if (new_argv != argv) { | ||
wasm_runtime_free(new_argv); | ||
if (clear_wasi_proc_exit_exception(exec_env->module_inst)) { | ||
ret = true; | ||
} | ||
else { | ||
if (new_argv != argv) { | ||
wasm_runtime_free(new_argv); | ||
} | ||
return false; | ||
} | ||
return false; | ||
} | ||
|
||
#if WASM_ENABLE_REF_TYPES != 0 | ||
|
@@ -2150,11 +2179,25 @@ wasm_runtime_get_exec_env_singleton(WASMModuleInstanceCommon *module_inst_comm) | |
void | ||
wasm_set_exception(WASMModuleInstance *module_inst, const char *exception) | ||
{ | ||
if (exception) | ||
WASMExecEnv *exec_env = NULL; | ||
|
||
if (exception) { | ||
snprintf(module_inst->cur_exception, sizeof(module_inst->cur_exception), | ||
"Exception: %s", exception); | ||
else | ||
} | ||
else { | ||
module_inst->cur_exception[0] = '\0'; | ||
} | ||
|
||
#if WASM_ENABLE_THREAD_MGR != 0 | ||
exec_env = | ||
wasm_clusters_search_exec_env((WASMModuleInstanceCommon *)module_inst); | ||
if (exec_env) { | ||
wasm_cluster_spread_exception(exec_env, exception ? false : true); | ||
} | ||
#else | ||
(void)exec_env; | ||
#endif | ||
} | ||
|
||
/* clang-format off */ | ||
|
@@ -4179,6 +4222,8 @@ bool | |
wasm_runtime_call_indirect(WASMExecEnv *exec_env, uint32 element_indices, | ||
uint32 argc, uint32 argv[]) | ||
{ | ||
bool ret = false; | ||
|
||
if (!wasm_runtime_exec_env_check(exec_env)) { | ||
LOG_ERROR("Invalid exec env stack info."); | ||
return false; | ||
|
@@ -4190,13 +4235,18 @@ wasm_runtime_call_indirect(WASMExecEnv *exec_env, uint32 element_indices, | |
|
||
#if WASM_ENABLE_INTERP != 0 | ||
if (exec_env->module_inst->module_type == Wasm_Module_Bytecode) | ||
return wasm_call_indirect(exec_env, 0, element_indices, argc, argv); | ||
ret = wasm_call_indirect(exec_env, 0, element_indices, argc, argv); | ||
#endif | ||
#if WASM_ENABLE_AOT != 0 | ||
if (exec_env->module_inst->module_type == Wasm_Module_AoT) | ||
return aot_call_indirect(exec_env, 0, element_indices, argc, argv); | ||
ret = aot_call_indirect(exec_env, 0, element_indices, argc, argv); | ||
#endif | ||
return false; | ||
|
||
if (!ret && clear_wasi_proc_exit_exception(exec_env->module_inst)) { | ||
ret = true; | ||
} | ||
|
||
return ret; | ||
} | ||
|
||
static void | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems no need to clear wasi proc exit exception here. WASI module doesn't set internal start func index,instead it exports a function named "_start". If here it really call wasi proc exit,we can also let instantiation process failed. @lum1n0us what is your opinion?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree with that, and updated