-
Notifications
You must be signed in to change notification settings - Fork 715
Allow interrupting blocking instructions #1930
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
Changes from all commits
3c2f060
185cd4d
f9c0bd1
6eecad7
9d6dc29
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -128,12 +128,14 @@ runtime_malloc(uint64 size, WASMModuleInstanceCommon *module_inst, | |
static JitCompOptions jit_options = { 0 }; | ||
#endif | ||
|
||
#ifdef OS_ENABLE_HW_BOUND_CHECK | ||
#if defined(OS_ENABLE_HW_BOUND_CHECK) || defined(OS_ENABLE_BLOCK_INSN_INTERRUPT) | ||
/* The exec_env of thread local storage, set before calling function | ||
and used in signal handler, as we cannot get it from the argument | ||
of signal handler */ | ||
static os_thread_local_attribute WASMExecEnv *exec_env_tls = NULL; | ||
#endif | ||
|
||
#ifdef OS_ENABLE_HW_BOUND_CHECK | ||
#ifndef BH_PLATFORM_WINDOWS | ||
static void | ||
runtime_signal_handler(void *sig_addr) | ||
|
@@ -303,7 +305,9 @@ runtime_signal_destroy() | |
#endif | ||
os_thread_signal_destroy(); | ||
} | ||
#endif /* end of OS_ENABLE_HW_BOUND_CHECK */ | ||
|
||
#if defined(OS_ENABLE_HW_BOUND_CHECK) || defined(OS_ENABLE_BLOCK_INSN_INTERRUPT) | ||
void | ||
wasm_runtime_set_exec_env_tls(WASMExecEnv *exec_env) | ||
{ | ||
|
@@ -315,7 +319,20 @@ wasm_runtime_get_exec_env_tls() | |
{ | ||
return exec_env_tls; | ||
} | ||
#endif /* end of OS_ENABLE_HW_BOUND_CHECK */ | ||
#endif | ||
|
||
#ifdef OS_ENABLE_BLOCK_INSN_INTERRUPT | ||
static void | ||
interrupt_block_insn_sig_handler() | ||
{ | ||
WASMJmpBuf *jmpbuf_node = exec_env_tls->jmpbuf_stack_top; | ||
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. jmpbuf_stack_top here can be for another handler. 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. Yes, if HW bound check is enabled, it will get a "HW bound" 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. you can even get a signal between wasm_exec_env_push_jmpbuf and os_setjmp. 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.
In that case, the I wonder if we have to mask/un-mask signals to avoid the signal handler being called in the middle. We want to avoid signal handlers being called between 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. it isn't a problem for hw bound check because the signal for it is basically synchronous to the thread execution. ie. the thread itself can control where it can happen. 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 we maybe invert the order of But there are probably other cases that are not covered, like an exception before 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.
I tried that in the latest commit, but maybe it's safer to use something like
Apart from this, do you think there are other cases that are not covered? If we get the signal before |
||
if (!jmpbuf_node) { | ||
return; | ||
} | ||
|
||
os_longjmp(jmpbuf_node->jmpbuf, 1); | ||
} | ||
#endif /* OS_ENABLE_BLOCK_INSN_INTERRUPT */ | ||
|
||
static bool | ||
wasm_runtime_env_init() | ||
|
@@ -348,7 +365,11 @@ wasm_runtime_env_init() | |
goto fail5; | ||
} | ||
#endif | ||
|
||
#ifdef OS_ENABLE_BLOCK_INSN_INTERRUPT | ||
if (!os_interrupt_block_insn_init(interrupt_block_insn_sig_handler)) { | ||
goto fail6; | ||
eloparco marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
#endif | ||
#ifdef OS_ENABLE_HW_BOUND_CHECK | ||
if (!runtime_signal_init()) { | ||
goto fail6; | ||
|
@@ -404,8 +425,10 @@ wasm_runtime_env_init() | |
fail7: | ||
#endif | ||
#endif | ||
#if defined(OS_ENABLE_HW_BOUND_CHECK) || defined(OS_ENABLE_BLOCK_INSN_INTERRUPT) | ||
#ifdef OS_ENABLE_HW_BOUND_CHECK | ||
runtime_signal_destroy(); | ||
#endif | ||
fail6: | ||
#endif | ||
#if (WASM_ENABLE_WAMR_COMPILER == 0) && (WASM_ENABLE_THREAD_MGR != 0) | ||
|
Uh oh!
There was an error while loading. Please reload this page.