Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 5.6k
Enable mono runtime to handle SIGTERM like CoreCLR #82806#82813
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
c07259e9ac0c3b98eeadf38b5e873adb5d6bd9326bFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -118,6 +118,7 @@ const char *mono_build_date; | ||
| gboolean mono_do_signal_chaining; | ||
| gboolean mono_do_crash_chaining; | ||
| int mini_verbose = 0; | ||
| gboolean mono_term_signaled = FALSE; | ||
| /* | ||
| * This flag controls whenever the runtime uses LLVM for JIT compilation, and whenever | ||
| @@ -3628,6 +3629,17 @@ MONO_SIG_HANDLER_FUNC (, mono_crashing_signal_handler) | ||
| } | ||
| } | ||
| MONO_SIG_HANDLER_FUNC (, mono_sigterm_signal_handler) | ||
| { | ||
| mono_environment_exitcode_set(128+SIGTERM); /* Set default exit code */ | ||
nealef marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| mono_term_signaled = TRUE; | ||
| mono_gc_finalize_notify (); | ||
| mono_chain_signal (MONO_SIG_HANDLER_PARAMS); | ||
| } | ||
| #if defined(MONO_ARCH_USE_SIGACTION) || defined(HOST_WIN32) | ||
| #define HAVE_SIG_INFO | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -189,6 +189,7 @@ mono_runtime_install_handlers (void) | ||||||
| win32_seh_set_handler(SIGFPE, mono_sigfpe_signal_handler); | ||||||
| win32_seh_set_handler(SIGILL, mono_crashing_signal_handler); | ||||||
| win32_seh_set_handler(SIGSEGV, mono_sigsegv_signal_handler); | ||||||
| win32_seh_set_handler(SIGTERM, mono_sigterm_signal_handler); | ||||||
| ||||||
| privatestaticInterop.BOOLHandlerRoutine(intdwCtrlType) |
This is how its handled by CoreCLR:
runtime/src/coreclr/vm/ceemain.cpp
Line 605 in ffffc4b
| ::SetConsoleCtrlHandler(DbgCtrlCHandler, TRUE/*add*/); |
So for Mono Windows handling of "SIGTERM" it probably need to setup a console ctrl handler and then react on the event as part of that handler and can't be handled through existing vectorized exception handling logic.
Uh oh!
There was an error while loading. Please reload this page.
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.
Since this is updated from a different thread without any locking, maybe we would need a read memory barrier to make sure we see updated value, especially when wait == FALSE,. There might be one hidden in the mono_coop_sem_timedwait, looks like at least sem_trywait seems to issue memory barriers, and other implementations probably do as well (like WaitForSingleObjectEx), so maybe not needed in the end, but we depend on implementation details. I guess we can leave it as is for now, just wanted to make a comment/note around potential but adding a read barrier in that code path shouldn't be too dramatic.
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.
I think that at one point, this PR had
mono_term_signaledasvolatile.Maybe that (or something else) is needed to ensure these lines don't reorder, causing the wrong exit code to be picked up.
This is how the exit code is set:
Uh oh!
There was an error while loading. Please reload this page.
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.
We can always do acquire/release semantics on
mono_term_signaledand we would make sure this is not reordered by compiler or CPU. Just usingvolatileonmono_term_signaledwill only prevent compiler to reorder load/store but CPU is still free to do load/store reorder.