summaryrefslogtreecommitdiffstats
path: root/winsup/cygwin/dll_init.cc
diff options
context:
space:
mode:
authorChristopher Faylor <me@cgf.cx>2011-04-21 00:53:55 +0000
committerChristopher Faylor <me@cgf.cx>2011-04-21 00:53:55 +0000
commit71c17c540231c3b824474431f2be0bd5ce63005f (patch)
tree29ddf6d9c57e712238eaca5629fb5524ab24c17b /winsup/cygwin/dll_init.cc
parent2f9c27131fc48d8364e0ef16332cf6e6402c4fdd (diff)
downloadcygnal-71c17c540231c3b824474431f2be0bd5ce63005f.tar.gz
cygnal-71c17c540231c3b824474431f2be0bd5ce63005f.tar.bz2
cygnal-71c17c540231c3b824474431f2be0bd5ce63005f.zip
* cygheap.cc (init_cygheap::close_ctty): Avoid closing console-cttys since they
don't use archetypes and this will just result in double frees. * dll_init.cc (dll_list::protect): Define. (dll_list::alloc): Guard list access. (dll_list::detach): Ditto. * dll_init.h (dll_list::protect): Declare new muto. (dll_list::guard): Define/declare function to guard list access. * fhandler_termios.cc (fhandler_termios::sigflush): Avoid SEGV in pathological condition of get_ttyp() == NULL.
Diffstat (limited to 'winsup/cygwin/dll_init.cc')
-rw-r--r--winsup/cygwin/dll_init.cc46
1 files changed, 28 insertions, 18 deletions
diff --git a/winsup/cygwin/dll_init.cc b/winsup/cygwin/dll_init.cc
index 5ee2f0036..f457b2766 100644
--- a/winsup/cygwin/dll_init.cc
+++ b/winsup/cygwin/dll_init.cc
@@ -10,6 +10,7 @@ details. */
#include "winsup.h"
#include "cygerrno.h"
#include "perprocess.h"
+#include "sync.h"
#include "dll_init.h"
#include "environ.h"
#include "security.h"
@@ -28,6 +29,8 @@ extern void __stdcall check_sanity_and_sync (per_process *);
dll_list dlls;
+muto dll_list::protect;
+
static bool dll_global_dtors_recorded;
/* Run destructors for all DLLs on exit. */
@@ -116,6 +119,7 @@ dll_list::alloc (HINSTANCE h, per_process *p, dll_type type)
WCHAR name[NT_MAX_PATH];
DWORD namelen = GetModuleFileNameW (h, name, sizeof (name));
+ guard (true);
/* Already loaded? */
dll *d = dlls[name];
if (d)
@@ -146,6 +150,7 @@ dll_list::alloc (HINSTANCE h, per_process *p, dll_type type)
if (type == DLL_LOAD)
loaded_dlls++;
}
+ guard (false);
assert (p->envptr != NULL);
return d;
}
@@ -170,27 +175,32 @@ void
dll_list::detach (void *retaddr)
{
dll *d;
- if (!myself || !(d = find (retaddr)))
+ if (!myself)
return;
- if (d->count <= 0)
- system_printf ("WARNING: trying to detach an already detached dll ...");
- if (--d->count == 0)
+ guard (true);
+ if ((d = find (retaddr)))
{
- /* Ensure our exception handler is enabled for destructors */
- exception protect;
- /* Call finalize function if we are not already exiting */
- if (!exit_state)
- __cxa_finalize (d);
- d->run_dtors ();
- d->prev->next = d->next;
- if (d->next)
- d->next->prev = d->prev;
- if (d->type == DLL_LOAD)
- loaded_dlls--;
- if (end == d)
- end = d->prev;
- cfree (d);
+ if (d->count <= 0)
+ system_printf ("WARNING: trying to detach an already detached dll ...");
+ if (--d->count == 0)
+ {
+ /* Ensure our exception handler is enabled for destructors */
+ exception protect;
+ /* Call finalize function if we are not already exiting */
+ if (!exit_state)
+ __cxa_finalize (d);
+ d->run_dtors ();
+ d->prev->next = d->next;
+ if (d->next)
+ d->next->prev = d->prev;
+ if (d->type == DLL_LOAD)
+ loaded_dlls--;
+ if (end == d)
+ end = d->prev;
+ cfree (d);
+ }
}
+ guard (false);
}
/* Initialization for all linked DLLs, called by dll_crt0_1. */