From 3875eec844609443710d3b98a2ac795d7f2d9121 Mon Sep 17 00:00:00 2001 From: Jeffrey Altman Date: Tue, 27 Dec 2005 16:17:11 +0000 Subject: [PATCH] windows-process-detach-20051227 The procmgmt library replaces the C RunTime Library's signal handlers but does not restore them on process detachment. This leaves the process with signal handlers pointing to invalid code that generates an invalid access error during process termination if the library was previously unloaded. --- src/procmgmt/pmgtprivate.h | 1 + src/procmgmt/procmgmt_nt.c | 11 ++++++++--- src/procmgmt/redirect_nt.c | 20 ++++++++++++++++++++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/procmgmt/pmgtprivate.h b/src/procmgmt/pmgtprivate.h index bbbabe6..04b0dd2 100644 --- a/src/procmgmt/pmgtprivate.h +++ b/src/procmgmt/pmgtprivate.h @@ -30,6 +30,7 @@ extern int pmgt_SignalRaiseLocalByName(const char *signo, int *libSigno); extern int pmgt_RedirectNativeSignals(void); +extern int pmgt_RestoreNativeSignals(void); #else /* Private process management definitions and declarations for Unix */ diff --git a/src/procmgmt/procmgmt_nt.c b/src/procmgmt/procmgmt_nt.c index 0f99ea9..8cfa2b5 100644 --- a/src/procmgmt/procmgmt_nt.c +++ b/src/procmgmt/procmgmt_nt.c @@ -1363,7 +1363,8 @@ DllMain(HINSTANCE dllInstHandle, /* instance handle for this DLL module */ DWORD reason, /* reason function is being called */ LPVOID reserved) { /* reserved for future use */ - if (reason == DLL_PROCESS_ATTACH) { + switch (reason) { + case DLL_PROCESS_ATTACH: /* library is being attached to a process */ if (PmgtLibraryInitialize()) { /* failed to initialize library */ @@ -1372,7 +1373,11 @@ DllMain(HINSTANCE dllInstHandle, /* instance handle for this DLL module */ /* disable thread attach/detach notifications */ (void)DisableThreadLibraryCalls(dllInstHandle); + return TRUE; + case DLL_PROCESS_DETACH: + pmgt_RestoreNativeSignals(); + return TRUE; + default: + return FALSE; } - - return TRUE; } diff --git a/src/procmgmt/redirect_nt.c b/src/procmgmt/redirect_nt.c index 2eabcc1..c27551e 100644 --- a/src/procmgmt/redirect_nt.c +++ b/src/procmgmt/redirect_nt.c @@ -110,3 +110,23 @@ pmgt_RedirectNativeSignals(void) return 0; } } + +/* + * pmgt_RedirectNativeSignals() -- initialize native signal redirection. + */ +int +pmgt_RestoreNativeSignals(void) +{ + if (signal(SIGINT, SIG_DFL) == SIG_ERR + || signal(SIGILL, SIG_DFL) == SIG_ERR + || signal(SIGFPE, SIG_DFL) == SIG_ERR + || signal(SIGSEGV, SIG_DFL) == SIG_ERR + || signal(SIGTERM, SIG_DFL) == SIG_ERR + || signal(SIGABRT, SIG_DFL) == SIG_ERR) { + errno = EINVAL; + return -1; + } else { + return 0; + } +} + -- 1.9.4