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)
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 */
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 */
/* disable thread attach/detach notifications */
(void)DisableThreadLibraryCalls(dllInstHandle);
+ return TRUE;
+ case DLL_PROCESS_DETACH:
+ pmgt_RestoreNativeSignals();
+ return TRUE;
+ default:
+ return FALSE;
}
-
- return TRUE;
}
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;
+ }
+}
+