From 8b1e63470484da9a011b251500e2bb55ddf6e570 Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Mon, 12 May 2025 13:10:43 -0700 Subject: [PATCH 1/6] Delete runtime build-in handling for SIGTERM The runtime build-in handling for SIGTERM signals is not correct for all appmodels. It is better to leave it to each model appmodel to handle it in appmodel specific way if necessary. The popular console appmodel based on HostingHostBuilderExtensions.UseConsoleLifetime does that already. Fixes #115206 --- src/coreclr/debug/ee/debugger.cpp | 19 ++--- src/coreclr/pal/inc/pal.h | 6 -- src/coreclr/pal/src/exception/signal.cpp | 10 +-- src/coreclr/pal/src/include/pal/corunix.hpp | 4 - src/coreclr/pal/src/synchmgr/synchmanager.cpp | 80 +------------------ src/coreclr/pal/src/synchmgr/synchmanager.hpp | 3 - src/coreclr/vm/ceemain.cpp | 7 -- src/coreclr/vm/exceptionhandling.cpp | 21 ----- src/coreclr/vm/listlock.h | 2 +- src/coreclr/vm/vars.cpp | 6 -- src/coreclr/vm/vars.hpp | 6 -- 11 files changed, 13 insertions(+), 151 deletions(-) diff --git a/src/coreclr/debug/ee/debugger.cpp b/src/coreclr/debug/ee/debugger.cpp index 69c06d3309701c..1da42283144c4f 100644 --- a/src/coreclr/debug/ee/debugger.cpp +++ b/src/coreclr/debug/ee/debugger.cpp @@ -5903,8 +5903,7 @@ void Debugger::SendDataBreakpoint(Thread *thread, CONTEXT *context, LOG((LF_CORDB, LL_INFO10000, "D::SDB: breakpoint BP:0x%x\n", breakpoint)); _ASSERTE((g_pEEInterface->GetThread() && - !g_pEEInterface->GetThread()->m_fPreemptiveGCDisabled) || - g_fInControlC); + !g_pEEInterface->GetThread()->m_fPreemptiveGCDisabled)); _ASSERTE(ThreadHoldsLock()); @@ -5951,8 +5950,7 @@ void Debugger::SendBreakpoint(Thread *thread, CONTEXT *context, LOG((LF_CORDB, LL_INFO10000, "D::SB: breakpoint BP:0x%x\n", breakpoint)); _ASSERTE((g_pEEInterface->GetThread() && - !g_pEEInterface->GetThread()->m_fPreemptiveGCDisabled) || - g_fInControlC); + !g_pEEInterface->GetThread()->m_fPreemptiveGCDisabled)); _ASSERTE(ThreadHoldsLock()); @@ -6095,8 +6093,7 @@ void Debugger::SendStep(Thread *thread, CONTEXT *context, stepper, reason)); _ASSERTE((g_pEEInterface->GetThread() && - !g_pEEInterface->GetThread()->m_fPreemptiveGCDisabled) || - g_fInControlC); + !g_pEEInterface->GetThread()->m_fPreemptiveGCDisabled)); _ASSERTE(ThreadHoldsLock()); @@ -6423,8 +6420,7 @@ void Debugger::SyncAllThreads(DebuggerLockHolder *dbgLockHolder) Thread *pThread = g_pEEInterface->GetThread(); (void)pThread; //prevent "unused variable" error from GCC _ASSERTE((pThread && - !pThread->m_fPreemptiveGCDisabled) || - g_fInControlC); + !pThread->m_fPreemptiveGCDisabled)); _ASSERTE(ThreadHoldsLock()); @@ -9007,8 +9003,7 @@ void Debugger::ThreadStarted(Thread* pRuntimeThread) // _ASSERTE((g_pEEInterface->GetThread() && - !g_pEEInterface->GetThread()->m_fPreemptiveGCDisabled) || - g_fInControlC); + !g_pEEInterface->GetThread()->m_fPreemptiveGCDisabled)); _ASSERTE(ThreadHoldsLock()); DebuggerIPCEvent* ipce = m_pRCThread->GetIPCEventSendBuffer(); @@ -9145,7 +9140,7 @@ BOOL Debugger::SuspendComplete(bool isEESuspendedForGC) // We can't throw here (we're in the middle of the runtime suspension logic). // But things below us throw. So we catch the exception, but then what state are we in? - if (!isEESuspendedForGC) {_ASSERTE((!g_pEEInterface->GetThread() || !g_pEEInterface->GetThread()->m_fPreemptiveGCDisabled) || g_fInControlC); } + if (!isEESuspendedForGC) {_ASSERTE((!g_pEEInterface->GetThread() || !g_pEEInterface->GetThread()->m_fPreemptiveGCDisabled)); } if (!isEESuspendedForGC) { _ASSERTE(ThisIsHelperThreadWorker()); } STRESS_LOG0(LF_CORDB, LL_INFO10000, "D::SC: suspension complete\n"); @@ -9982,7 +9977,7 @@ void Debugger::FuncEvalComplete(Thread* pThread, DebuggerEval *pDE) _ASSERTE(pDE->m_completed); - _ASSERTE((g_pEEInterface->GetThread() && !g_pEEInterface->GetThread()->m_fPreemptiveGCDisabled) || g_fInControlC); + _ASSERTE((g_pEEInterface->GetThread() && !g_pEEInterface->GetThread()->m_fPreemptiveGCDisabled)); _ASSERTE(ThreadHoldsLock()); // diff --git a/src/coreclr/pal/inc/pal.h b/src/coreclr/pal/inc/pal.h index 293d9ab41b156c..4f75b948f2af33 100644 --- a/src/coreclr/pal/inc/pal.h +++ b/src/coreclr/pal/inc/pal.h @@ -4116,12 +4116,6 @@ PAL_ThrowExceptionFromContext( IN CONTEXT* context, IN PAL_SEHException* ex); -PALIMPORT -VOID -PALAPI -PAL_SetTerminationRequestHandler( - IN PTERMINATION_REQUEST_HANDLER terminationRequestHandler); - PALIMPORT VOID PALAPI diff --git a/src/coreclr/pal/src/exception/signal.cpp b/src/coreclr/pal/src/exception/signal.cpp index cb183bd6a6c8a3..689408201fcee8 100644 --- a/src/coreclr/pal/src/exception/signal.cpp +++ b/src/coreclr/pal/src/exception/signal.cpp @@ -846,15 +846,9 @@ static void sigterm_handler(int code, siginfo_t *siginfo, void *context) { PROCCreateCrashDumpIfEnabled(code, siginfo, false); } - // g_pSynchronizationManager shouldn't be null if PAL is initialized. - _ASSERTE(g_pSynchronizationManager != nullptr); - - g_pSynchronizationManager->SendTerminationRequestToWorkerThread(); - } - else - { - restore_signal_and_resend(SIGTERM, &g_previous_sigterm); } + + restore_signal_and_resend(SIGTERM, &g_previous_sigterm); } #ifdef INJECT_ACTIVATION_SIGNAL diff --git a/src/coreclr/pal/src/include/pal/corunix.hpp b/src/coreclr/pal/src/include/pal/corunix.hpp index 4ebed32d57659e..7e606980dd3434 100644 --- a/src/coreclr/pal/src/include/pal/corunix.hpp +++ b/src/coreclr/pal/src/include/pal/corunix.hpp @@ -976,10 +976,6 @@ namespace CorUnix CPalThread *pThread ) = 0; - virtual - PAL_ERROR - SendTerminationRequestToWorkerThread() = 0; - // // This routine is primarily meant for use by WaitForMultipleObjects[Ex]. // The caller must individually release each of the returned controller diff --git a/src/coreclr/pal/src/synchmgr/synchmanager.cpp b/src/coreclr/pal/src/synchmgr/synchmanager.cpp index 0d1b0bc32ed1b7..50446fdf1e775b 100644 --- a/src/coreclr/pal/src/synchmgr/synchmanager.cpp +++ b/src/coreclr/pal/src/synchmgr/synchmanager.cpp @@ -44,18 +44,6 @@ SET_DEFAULT_DEBUG_CHANNEL(SYNC); // some headers have code with asserts, so do t const int CorUnix::CThreadSynchronizationInfo::PendingSignalingsArraySize; -// We use the synchronization manager's worker thread to handle -// process termination requests. It does so by calling the -// registered handler function. -PTERMINATION_REQUEST_HANDLER g_terminationRequestHandler = NULL; - -// Set the handler for process termination requests. -VOID PALAPI PAL_SetTerminationRequestHandler( - IN PTERMINATION_REQUEST_HANDLER terminationHandler) -{ - g_terminationRequestHandler = terminationHandler; -} - namespace CorUnix { ///////////////////////////////// @@ -1160,25 +1148,6 @@ namespace CorUnix return palErr; } - /*++ - Method: - CPalSynchronizationManager::SendTerminationRequestToWorkerThread - - Send a request to the worker thread to initiate process termination. - --*/ - PAL_ERROR CPalSynchronizationManager::SendTerminationRequestToWorkerThread() - { - PAL_ERROR palErr = GetInstance()->WakeUpLocalWorkerThread(SynchWorkerCmdTerminationRequest); - if (palErr != NO_ERROR) - { - ERROR("Failed to wake up worker thread [errno=%d {%s%}]\n", - errno, strerror(errno)); - palErr = ERROR_INTERNAL_ERROR; - } - - return palErr; - } - /*++ Method: CPalSynchronizationManager::AreAPCsPending @@ -1558,22 +1527,6 @@ namespace CorUnix return palErr; } - // Entry point routine for the thread that initiates process termination. - DWORD PALAPI TerminationRequestHandlingRoutine(LPVOID pArg) - { - // Call the termination request handler if one is registered. - if (g_terminationRequestHandler != NULL) - { - // The process will terminate normally by calling exit. - // We use an exit code of '128 + signo'. This is a convention used in popular - // shells to calculate an exit code when the process was terminated by a signal. - // This is also used by the Process.ExitCode implementation. - g_terminationRequestHandler(128 + SIGTERM); - } - - return 0; - } - /*++ Method: CPalSynchronizationManager::WorkerThread @@ -1612,31 +1565,6 @@ namespace CorUnix } switch (swcCmd) { - case SynchWorkerCmdTerminationRequest: - // This worker thread is being asked to initiate process termination - - HANDLE hTerminationRequestHandlingThread; - palErr = InternalCreateThread(pthrWorker, - NULL, - 0, - &TerminationRequestHandlingRoutine, - NULL, - 0, - PalWorkerThread, - NULL, - &hTerminationRequestHandlingThread); - - if (NO_ERROR != palErr) - { - ERROR("Unable to create worker thread\n"); - } - - if (hTerminationRequestHandlingThread != NULL) - { - CloseHandle(hTerminationRequestHandlingThread); - } - - break; case SynchWorkerCmdNop: TRACE("Synch Worker: received SynchWorkerCmdNop\n"); if (fShuttingDown) @@ -1776,8 +1704,7 @@ namespace CorUnix } _ASSERT_MSG(SynchWorkerCmdNop == swcWorkerCmd || - SynchWorkerCmdShutdown == swcWorkerCmd || - SynchWorkerCmdTerminationRequest == swcWorkerCmd, + SynchWorkerCmdShutdown == swcWorkerCmd, "Unknown worker command code %u\n", swcWorkerCmd); TRACE("Got cmd %u from process pipe\n", swcWorkerCmd); @@ -2216,9 +2143,8 @@ namespace CorUnix "Value too big for swcWorkerCmd\n"); _ASSERT_MSG((SynchWorkerCmdNop == swcWorkerCmd) || - (SynchWorkerCmdShutdown == swcWorkerCmd) || - (SynchWorkerCmdTerminationRequest == swcWorkerCmd), - "WakeUpLocalWorkerThread supports only SynchWorkerCmdNop, SynchWorkerCmdShutdown, and SynchWorkerCmdTerminationRequest." + (SynchWorkerCmdShutdown == swcWorkerCmd), + "WakeUpLocalWorkerThread supports only SynchWorkerCmdNop and SynchWorkerCmdShutdown." "[received cmd=%d]\n", swcWorkerCmd); BYTE byCmd = (BYTE)(swcWorkerCmd & 0xFF); diff --git a/src/coreclr/pal/src/synchmgr/synchmanager.hpp b/src/coreclr/pal/src/synchmgr/synchmanager.hpp index 2dd0600d4d9c9f..83a3ee6ca30431 100644 --- a/src/coreclr/pal/src/synchmgr/synchmanager.hpp +++ b/src/coreclr/pal/src/synchmgr/synchmanager.hpp @@ -488,7 +488,6 @@ namespace CorUnix { SynchWorkerCmdNop, SynchWorkerCmdShutdown, - SynchWorkerCmdTerminationRequest, SynchWorkerCmdLast }; @@ -783,8 +782,6 @@ namespace CorUnix PAPCFUNC pfnAPC, ULONG_PTR uptrData); - virtual PAL_ERROR SendTerminationRequestToWorkerThread(); - virtual bool AreAPCsPending(CPalThread * pthrTarget); virtual PAL_ERROR DispatchPendingAPCs(CPalThread * pthrCurrent); diff --git a/src/coreclr/vm/ceemain.cpp b/src/coreclr/vm/ceemain.cpp index bbf904a0f15f23..042c14d3761891 100644 --- a/src/coreclr/vm/ceemain.cpp +++ b/src/coreclr/vm/ceemain.cpp @@ -372,13 +372,6 @@ static BOOL WINAPI DbgCtrlCHandler(DWORD dwCtrlType) else #endif // DEBUGGING_SUPPORTED { - if (dwCtrlType == CTRL_CLOSE_EVENT || dwCtrlType == CTRL_SHUTDOWN_EVENT) - { - // Initiate shutdown so the ProcessExit handlers run - ForceEEShutdown(SCA_ReturnWhenShutdownComplete); - } - - g_fInControlC = true; // only for weakening assertions in checked build. return FALSE; // keep looking for a real handler. } } diff --git a/src/coreclr/vm/exceptionhandling.cpp b/src/coreclr/vm/exceptionhandling.cpp index b939ddc968cc3b..fc206e357043f5 100644 --- a/src/coreclr/vm/exceptionhandling.cpp +++ b/src/coreclr/vm/exceptionhandling.cpp @@ -162,24 +162,6 @@ static inline void UpdatePerformanceMetrics(CrawlFrame *pcfThisFrame, BOOL bIsRe ETW::ExceptionLog::ExceptionThrown(pcfThisFrame, bIsRethrownException, bIsNewException); } -#ifdef TARGET_UNIX -static LONG volatile g_termination_triggered = 0; - -void HandleTerminationRequest(int terminationExitCode) -{ - // We set a non-zero exit code to indicate the process didn't terminate cleanly. - // This value can be changed by the user by setting Environment.ExitCode in the - // ProcessExit event. We only start termination on the first SIGTERM signal - // to ensure we don't overwrite an exit code already set in ProcessExit. - if (InterlockedCompareExchange(&g_termination_triggered, 1, 0) == 0) - { - SetLatchedExitCode(terminationExitCode); - - ForceEEShutdown(SCA_ExitProcessWhenShutdownComplete); - } -} -#endif - void InitializeExceptionHandling() { EH_LOG((LL_INFO100, "InitializeExceptionHandling(): ExInfo size: 0x%x bytes\n", sizeof(ExInfo))); @@ -192,9 +174,6 @@ void InitializeExceptionHandling() // Register handler for determining whether the specified IP has code that is a GC marker for GCCover PAL_SetGetGcMarkerExceptionCode(GetGcMarkerExceptionCode); - - // Register handler for termination requests (e.g. SIGTERM) - PAL_SetTerminationRequestHandler(HandleTerminationRequest); #endif // TARGET_UNIX } diff --git a/src/coreclr/vm/listlock.h b/src/coreclr/vm/listlock.h index c062c68fc087b0..7a23a52ad0adc0 100644 --- a/src/coreclr/vm/listlock.h +++ b/src/coreclr/vm/listlock.h @@ -278,7 +278,7 @@ class ListLockBase { WRAPPER_NO_CONTRACT; // There should not be any of these around - _ASSERTE(m_pHead == NULL || dbg_fDrasticShutdown || g_fInControlC); + _ASSERTE(m_pHead == NULL); if (m_fInited) { diff --git a/src/coreclr/vm/vars.cpp b/src/coreclr/vm/vars.cpp index 68a0d9299a62bd..303e1fec50448a 100644 --- a/src/coreclr/vm/vars.cpp +++ b/src/coreclr/vm/vars.cpp @@ -199,12 +199,6 @@ bool g_fManagedAttach = false; // bool g_fWeControlLifetime = false; -#ifdef _DEBUG -// The following should only be used for assertions. (Famous last words). -bool dbg_fDrasticShutdown = false; -#endif -bool g_fInControlC = false; - #endif // #ifndef DACCESS_COMPILE #ifdef DACCESS_COMPILE diff --git a/src/coreclr/vm/vars.hpp b/src/coreclr/vm/vars.hpp index c03d1883222a61..7913658fd271d9 100644 --- a/src/coreclr/vm/vars.hpp +++ b/src/coreclr/vm/vars.hpp @@ -500,12 +500,6 @@ EXTERN const char g_psBaseLibrarySatelliteAssemblyName[]; // EXTERN bool g_fWeControlLifetime; -#ifdef _DEBUG -// The following should only be used for assertions. (Famous last words). -EXTERN bool dbg_fDrasticShutdown; -#endif -EXTERN bool g_fInControlC; - // There is a global table of prime numbers that's available for e.g. hashing extern const DWORD g_rgPrimes[71]; From e2c8207f3864ce9c28ed2fbe42e4ead10f52f9dc Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Mon, 12 May 2025 14:46:44 -0700 Subject: [PATCH 2/6] Update Mono --- src/mono/mono/metadata/gc.c | 10 -------- src/mono/mono/mini/exceptions-amd64.c | 34 --------------------------- src/mono/mono/mini/exceptions-x86.c | 31 ------------------------ src/mono/mono/mini/mini-posix.c | 2 -- src/mono/mono/mini/mini-runtime.c | 12 ---------- src/mono/mono/mini/mini-runtime.h | 1 - src/mono/mono/mini/mini-windows.c | 1 - 7 files changed, 91 deletions(-) diff --git a/src/mono/mono/metadata/gc.c b/src/mono/mono/metadata/gc.c index 5ef0faa9f80516..9c49d2803cd95a 100644 --- a/src/mono/mono/metadata/gc.c +++ b/src/mono/mono/metadata/gc.c @@ -24,7 +24,6 @@ #include #include #include -#include #include #include #include @@ -64,8 +63,6 @@ static gboolean gc_disabled; static gboolean finalizing_root_domain; -extern gboolean mono_term_signaled; - gboolean mono_log_finalizers; gboolean mono_do_not_finalize; static volatile gboolean suspend_finalizers; @@ -855,7 +852,6 @@ finalizer_thread (gpointer unused) mono_hazard_pointer_install_free_queue_size_callback (hazard_free_queue_is_too_big); while (!finished) { - /* Wait to be notified that there's at least one * finaliser to run */ @@ -869,12 +865,6 @@ finalizer_thread (gpointer unused) } wait = TRUE; - /* Just in case we've received a SIGTERM */ - if (mono_term_signaled) { - mono_runtime_try_shutdown(); - exit(mono_environment_exitcode_get()); - } - mono_thread_info_set_flags (MONO_THREAD_INFO_FLAGS_NONE); /* The Finalizer thread doesn't initialize during creation because base managed diff --git a/src/mono/mono/mini/exceptions-amd64.c b/src/mono/mono/mini/exceptions-amd64.c index 617a551dc80875..5049bc799700ff 100644 --- a/src/mono/mono/mini/exceptions-amd64.c +++ b/src/mono/mono/mini/exceptions-amd64.c @@ -45,14 +45,10 @@ #include "mono/utils/mono-tls-inline.h" #ifdef TARGET_WIN32 -#include static void (*restore_stack) (void); static MonoW32ExceptionHandler fpe_handler; static MonoW32ExceptionHandler ill_handler; static MonoW32ExceptionHandler segv_handler; -static MonoW32ExceptionHandler term_handler = NULL; - -extern gboolean mono_term_signaled; LPTOP_LEVEL_EXCEPTION_FILTER mono_old_win_toplevel_exception_filter; void *mono_win_vectored_exception_handle; @@ -218,31 +214,6 @@ void win32_seh_cleanup(void) g_assert (ret); } -BOOL WINAPI mono_win_ctrl_handler(DWORD fdwCtrlType) -{ - switch (fdwCtrlType) { - case CTRL_C_EVENT: - if (term_handler != NULL) - term_handler(0, NULL, NULL); - return TRUE; - break; - case CTRL_CLOSE_EVENT: - return TRUE; - break; - case CTRL_BREAK_EVENT: - return FALSE; - break; - case CTRL_LOGOFF_EVENT: - return FALSE; - break; - case CTRL_SHUTDOWN_EVENT: - return FALSE; - break; - default: - return FALSE; - } -} - void win32_seh_set_handler(int type, MonoW32ExceptionHandler handler) { switch (type) { @@ -255,11 +226,6 @@ void win32_seh_set_handler(int type, MonoW32ExceptionHandler handler) case SIGSEGV: segv_handler = handler; break; - case SIGTERM: - term_handler = handler; - if (!SetConsoleCtrlHandler(mono_win_ctrl_handler, TRUE)) - fprintf(stderr,"Cannot set control handler\n"); - break; default: break; } diff --git a/src/mono/mono/mini/exceptions-x86.c b/src/mono/mono/mini/exceptions-x86.c index 366228f75c1b52..47ba88dcf92923 100644 --- a/src/mono/mono/mini/exceptions-x86.c +++ b/src/mono/mono/mini/exceptions-x86.c @@ -47,7 +47,6 @@ static void (*restore_stack) (void *); static MonoW32ExceptionHandler fpe_handler; static MonoW32ExceptionHandler ill_handler; static MonoW32ExceptionHandler segv_handler; -static MonoW32ExceptionHandler term_handler = NULL; LPTOP_LEVEL_EXCEPTION_FILTER mono_old_win_toplevel_exception_filter; gpointer mono_win_vectored_exception_handle; @@ -261,31 +260,6 @@ void win32_seh_cleanup(void) RemoveVectoredExceptionHandler (mono_win_vectored_exception_handle); } -BOOL WINAPI mono_win_ctrl_handler(DWORD fdwCtrlType) -{ - switch (fdwCtrlType) { - case CTRL_C_EVENT: - if (term_handler != NULL) - term_handler(0, NULL, NULL); - return TRUE; - break; - case CTRL_CLOSE_EVENT: - return TRUE; - break; - case CTRL_BREAK_EVENT: - return FALSE; - break; - case CTRL_LOGOFF_EVENT: - return FALSE; - break; - case CTRL_SHUTDOWN_EVENT: - return FALSE; - break; - default: - return FALSE; - } -} - void win32_seh_set_handler(int type, MonoW32ExceptionHandler handler) { switch (type) { @@ -298,11 +272,6 @@ void win32_seh_set_handler(int type, MonoW32ExceptionHandler handler) case SIGSEGV: segv_handler = handler; break; - case SIGTERM: - term_handler = handler; - if (!SetConsoleCtrlHandler(mono_win_ctrl_handler, TRUE)) - fprintf(stderr,"Cannot set control handler\n"); - break; default: break; } diff --git a/src/mono/mono/mini/mini-posix.c b/src/mono/mono/mini/mini-posix.c index 15b2b441eafb4f..4c36fd6b3ffeea 100644 --- a/src/mono/mono/mini/mini-posix.c +++ b/src/mono/mono/mini/mini-posix.c @@ -423,8 +423,6 @@ mono_runtime_posix_install_handlers (void) sigaddset (&signal_set, SIGFPE); add_signal_handler (SIGQUIT, sigquit_signal_handler, SA_RESTART); sigaddset (&signal_set, SIGQUIT); - add_signal_handler (SIGTERM, mono_sigterm_signal_handler, SA_RESTART); - sigaddset (&signal_set, SIGTERM); add_signal_handler (SIGILL, mono_crashing_signal_handler, 0); sigaddset (&signal_set, SIGILL); add_signal_handler (SIGBUS, mono_sigsegv_signal_handler, 0); diff --git a/src/mono/mono/mini/mini-runtime.c b/src/mono/mono/mini/mini-runtime.c index eb2ff7d4df81ae..e82d55c2645163 100644 --- a/src/mono/mono/mini/mini-runtime.c +++ b/src/mono/mono/mini/mini-runtime.c @@ -119,7 +119,6 @@ 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 @@ -3764,17 +3763,6 @@ 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 */ - - 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 diff --git a/src/mono/mono/mini/mini-runtime.h b/src/mono/mono/mini/mini-runtime.h index 7779909bd944e2..45fbe080cefc1b 100644 --- a/src/mono/mono/mini/mini-runtime.h +++ b/src/mono/mono/mini/mini-runtime.h @@ -676,7 +676,6 @@ void MONO_SIG_HANDLER_SIGNATURE (mono_sigfpe_signal_handler) ; void MONO_SIG_HANDLER_SIGNATURE (mono_crashing_signal_handler) ; void MONO_SIG_HANDLER_SIGNATURE (mono_sigsegv_signal_handler); void MONO_SIG_HANDLER_SIGNATURE (mono_sigint_signal_handler) ; -void MONO_SIG_HANDLER_SIGNATURE (mono_sigterm_signal_handler) ; gboolean MONO_SIG_HANDLER_SIGNATURE (mono_chain_signal); void mono_chain_signal_to_default_sigsegv_handler (void); diff --git a/src/mono/mono/mini/mini-windows.c b/src/mono/mono/mini/mini-windows.c index cb79586c98a5ee..d57c9d1a86c462 100644 --- a/src/mono/mono/mini/mini-windows.c +++ b/src/mono/mono/mini/mini-windows.c @@ -188,7 +188,6 @@ 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); if (mini_debug_options.handle_sigint) win32_seh_set_handler(SIGINT, mono_sigint_signal_handler); #endif From 73c8f4617f13e3743d8ad2bf1f1846316de2b50d Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Mon, 12 May 2025 15:27:00 -0700 Subject: [PATCH 3/6] More cleanup --- src/coreclr/pal/inc/pal.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/coreclr/pal/inc/pal.h b/src/coreclr/pal/inc/pal.h index 4f75b948f2af33..a918690114ea86 100644 --- a/src/coreclr/pal/inc/pal.h +++ b/src/coreclr/pal/inc/pal.h @@ -4093,7 +4093,6 @@ struct PAL_SEHException typedef BOOL (*PHARDWARE_EXCEPTION_HANDLER)(PAL_SEHException* ex); typedef BOOL (*PHARDWARE_EXCEPTION_SAFETY_CHECK_FUNCTION)(PCONTEXT contextRecord, PEXCEPTION_RECORD exceptionRecord); -typedef VOID (*PTERMINATION_REQUEST_HANDLER)(int terminationExitCode); typedef DWORD (*PGET_GCMARKER_EXCEPTION_CODE)(LPVOID ip); PALIMPORT From 17071f75077f680df4f1c2dfd382d0d37c1fb61d Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Tue, 13 May 2025 14:04:01 -0700 Subject: [PATCH 4/6] Fix tests --- .../tests/System.Runtime.Tests/System/ExitCodeTests.Unix.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/ExitCodeTests.Unix.cs b/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/ExitCodeTests.Unix.cs index bd7cf68e87c366..cdf121051850a9 100644 --- a/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/ExitCodeTests.Unix.cs +++ b/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/ExitCodeTests.Unix.cs @@ -58,8 +58,8 @@ public void SigTermExitCode(int? exitCodeOnSigterm) bool exited = process.WaitForExit(RemoteExecutor.FailWaitTimeoutMilliseconds); Assert.True(exited); - // Check exit code - Assert.Equal(exitCodeOnSigterm ?? 128 + SIGTERM, process.ExitCode); + // Check that the exit code is 143 (128 + SIGTERM). + Assert.Equal(143, process.ExitCode); } } } From 6bbd9a1d0f08401c280b9813e4eee4a1957c35d4 Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Tue, 13 May 2025 14:57:02 -0700 Subject: [PATCH 5/6] FB --- .../System/ExitCodeTests.Unix.cs | 21 +++++++------------ 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/ExitCodeTests.Unix.cs b/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/ExitCodeTests.Unix.cs index cdf121051850a9..4bbc7445693c25 100644 --- a/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/ExitCodeTests.Unix.cs +++ b/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/ExitCodeTests.Unix.cs @@ -15,23 +15,16 @@ public class ExitCodeTests [DllImport("libc", SetLastError = true)] private static extern int kill(int pid, int sig); - [ConditionalTheory(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] - [InlineData(null)] - [InlineData(0)] - [InlineData(42)] + [ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] [PlatformSpecific(TestPlatforms.AnyUnix)] // SIGTERM signal. - public void SigTermExitCode(int? exitCodeOnSigterm) + public void SigTermExitCode() { - Action action = (string sigTermExitCode) => + Action action = () => { - if (!string.IsNullOrEmpty(sigTermExitCode)) + AppDomain.CurrentDomain.ProcessExit += (sender, args) => { - AppDomain.CurrentDomain.ProcessExit += (sender, args) => - { - Assert.Same(AppDomain.CurrentDomain, sender); - Environment.ExitCode = int.Parse(sigTermExitCode); - }; - } + Assert.Fail("AppDomain.ProcessExit is not expected to be called when the process is killed by SIGTERM"); + }; Console.WriteLine("Application started"); @@ -42,7 +35,7 @@ public void SigTermExitCode(int? exitCodeOnSigterm) RemoteInvokeOptions options = new RemoteInvokeOptions(); options.StartInfo.RedirectStandardOutput = true; options.CheckExitCode = false; - using (RemoteInvokeHandle remoteExecution = RemoteExecutor.Invoke(action, exitCodeOnSigterm?.ToString() ?? string.Empty, options)) + using (RemoteInvokeHandle remoteExecution = RemoteExecutor.Invoke(action, options)) { Process process = remoteExecution.Process; From 22d986cba246737b04887d95b826fd7a6daaafb1 Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Wed, 14 May 2025 14:14:55 -0700 Subject: [PATCH 6/6] Update src/libraries/System.Runtime/tests/System.Runtime.Tests/System/ExitCodeTests.Unix.cs --- .../tests/System.Runtime.Tests/System/ExitCodeTests.Unix.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/ExitCodeTests.Unix.cs b/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/ExitCodeTests.Unix.cs index 4bbc7445693c25..4fa16a04453ba3 100644 --- a/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/ExitCodeTests.Unix.cs +++ b/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/ExitCodeTests.Unix.cs @@ -19,7 +19,7 @@ public class ExitCodeTests [PlatformSpecific(TestPlatforms.AnyUnix)] // SIGTERM signal. public void SigTermExitCode() { - Action action = () => + Action action = () => { AppDomain.CurrentDomain.ProcessExit += (sender, args) => {