diff options
author | Mike McLaughlin <mikem@microsoft.com> | 2015-12-14 17:24:43 -0800 |
---|---|---|
committer | Mike McLaughlin <mikem@microsoft.com> | 2015-12-15 11:51:27 -0800 |
commit | c47b9a0866affb60175dcad16b818798d0296573 (patch) | |
tree | bae6db527bd123dc2df093d811a03a898a065745 /src/pal | |
parent | 7fba91ac9eb310e9c256e19873f361608bf6b7bb (diff) | |
download | coreclr-c47b9a0866affb60175dcad16b818798d0296573.tar.gz coreclr-c47b9a0866affb60175dcad16b818798d0296573.tar.bz2 coreclr-c47b9a0866affb60175dcad16b818798d0296573.zip |
Debugger transport pipe file cleanup - Part 2
Clean up the pipe files in /tmp for unhandled managed exception termination.
Added a simple PAL shutdown API to set (one) shutdown callback handler which is used
by the debugger code to cleanup the transport thus removing the pipe files from /tmp.
This callback is executed PAL_Shutdown, ExitProcess and TerminateProcess, the later used
to terminate the process for an unhandled managed exception.
Add the __attribute__((destructor)) to the ShutdownTransport function to cover the case if
the if a third party host, the managed runtime or third party pinvoked code calls exit().
Diffstat (limited to 'src/pal')
-rw-r--r-- | src/pal/inc/pal.h | 18 | ||||
-rw-r--r-- | src/pal/src/thread/process.cpp | 36 |
2 files changed, 47 insertions, 7 deletions
diff --git a/src/pal/inc/pal.h b/src/pal/inc/pal.h index 660b4086c0..cec19c290e 100644 --- a/src/pal/inc/pal.h +++ b/src/pal/inc/pal.h @@ -569,6 +569,24 @@ PALAPI PAL_TerminateEx( int exitCode); +/*++ +Function: + PAL_SetShutdownCallback + +Abstract: + Sets a callback that is executed when the PAL is shut down because of + ExitProcess, TerminateProcess or PAL_Shutdown but not PAL_Terminate/Ex. + + NOTE: Currently only one callback can be set at a time. +--*/ +typedef VOID (*PSHUTDOWN_CALLBACK)(void); + +PALIMPORT +VOID +PALAPI +PAL_SetShutdownCallback( + IN PSHUTDOWN_CALLBACK callback); + PALIMPORT void PALAPI diff --git a/src/pal/src/thread/process.cpp b/src/pal/src/thread/process.cpp index 0953bf0172..4e2a9c5571 100644 --- a/src/pal/src/thread/process.cpp +++ b/src/pal/src/thread/process.cpp @@ -105,46 +105,43 @@ CAllowedObjectTypes aotProcess(otiProcess); // // The representative IPalObject for this process // - IPalObject* CorUnix::g_pobjProcess; // // Critical section that protects process data (e.g., the // list of active threads)/ // - CRITICAL_SECTION g_csProcess; // // List and count of active threads // - CPalThread* CorUnix::pGThreadList; DWORD g_dwThreadCount; // // The command line and app name for the process // - LPWSTR g_lpwstrCmdLine = NULL; LPWSTR g_lpwstrAppDir = NULL; -/* Thread ID of thread that has started the ExitProcess process */ +// Thread ID of thread that has started the ExitProcess process Volatile<LONG> terminator = 0; // Process ID of this process. DWORD gPID = (DWORD) -1; +// Function to call during PAL/process shutdown +PSHUTDOWN_CALLBACK g_shutdownCallback = nullptr; + // // Key used for associating CPalThread's with the underlying pthread // (through pthread_setspecific) // - pthread_key_t CorUnix::thObjKey; #define PROCESS_PELOADER_FILENAME "clix" - static WCHAR W16_WHITESPACE[]= {0x0020, 0x0009, 0x000D, 0}; static WCHAR W16_WHITESPACE_DQUOTE[]= {0x0020, 0x0009, 0x000D, '"', 0}; @@ -1398,6 +1395,26 @@ static BOOL PROCEndProcess(HANDLE hProcess, UINT uExitCode, BOOL bTerminateUncon /*++ Function: + PAL_SetShutdownCallback + +Abstract: + Sets a callback that is executed when the PAL is shut down because of + ExitProcess, TerminateProcess or PAL_Shutdown but not PAL_Terminate/Ex. + + NOTE: Currently only one callback can be set at a time. +--*/ +PALIMPORT +VOID +PALAPI +PAL_SetShutdownCallback( + IN PSHUTDOWN_CALLBACK callback) +{ + _ASSERTE(g_shutdownCallback == nullptr); + g_shutdownCallback = callback; +} + +/*++ +Function: PROCCleanupProcess Do all cleanup work for TerminateProcess, but don't terminate the process. @@ -1407,6 +1424,11 @@ Function: --*/ void PROCCleanupProcess(BOOL bTerminateUnconditionally) { + if (g_shutdownCallback != nullptr) + { + g_shutdownCallback(); + } + /* Declare the beginning of shutdown */ PALSetShutdownIntent(); |