From: Jeffrey Altman Date: Tue, 27 Dec 2005 16:18:53 +0000 (+0000) Subject: STABLE14-windows-process-detach-20051227 X-Git-Tag: openafs-stable-1_4_1-rc3~5 X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=005f708a83639978a735629a3a0fd4aef26e664b;p=packages%2Fo%2Fopenafs.git STABLE14-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. (cherry picked from commit 3875eec844609443710d3b98a2ac795d7f2d9121) --- diff --git a/src/procmgmt/pmgtprivate.h b/src/procmgmt/pmgtprivate.h index bbbabe63a..04b0dd236 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 f62134ae4..2fa0e81a0 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 2eabcc162..c27551e3e 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; + } +} +