* 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.
This commit is contained in:
parent
2f9c27131f
commit
71c17c5402
|
@ -1,3 +1,16 @@
|
||||||
|
2011-04-20 Christopher Faylor <me.cygwin2011@cgf.cx>
|
||||||
|
|
||||||
|
* 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.
|
||||||
|
|
||||||
2011-04-20 Christopher Faylor <me.cygwin2011@cgf.cx>
|
2011-04-20 Christopher Faylor <me.cygwin2011@cgf.cx>
|
||||||
|
|
||||||
* select.cc (serial_cleanup): Make sure that device_specific_pipe is
|
* select.cc (serial_cleanup): Make sure that device_specific_pipe is
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
#include "cygerrno.h"
|
#include "cygerrno.h"
|
||||||
#include "security.h"
|
#include "security.h"
|
||||||
#include "path.h"
|
#include "path.h"
|
||||||
|
#include "tty.h"
|
||||||
#include "fhandler.h"
|
#include "fhandler.h"
|
||||||
#include "dtable.h"
|
#include "dtable.h"
|
||||||
#include "cygheap.h"
|
#include "cygheap.h"
|
||||||
|
@ -106,7 +107,11 @@ void
|
||||||
init_cygheap::close_ctty ()
|
init_cygheap::close_ctty ()
|
||||||
{
|
{
|
||||||
debug_printf ("closing cygheap->ctty %p", cygheap->ctty);
|
debug_printf ("closing cygheap->ctty %p", cygheap->ctty);
|
||||||
cygheap->ctty->close ();
|
/* FIXME: Support for console-as-ctty is limited due to the fact that
|
||||||
|
the console doesn't use archetypes - even though they could and should */
|
||||||
|
if (cygheap->ctty->get_ttyp ()
|
||||||
|
&& cygheap->ctty->get_ttyp ()->ntty != TTY_CONSOLE)
|
||||||
|
cygheap->ctty->close ();
|
||||||
cygheap->ctty = NULL;
|
cygheap->ctty = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@ details. */
|
||||||
#include "winsup.h"
|
#include "winsup.h"
|
||||||
#include "cygerrno.h"
|
#include "cygerrno.h"
|
||||||
#include "perprocess.h"
|
#include "perprocess.h"
|
||||||
|
#include "sync.h"
|
||||||
#include "dll_init.h"
|
#include "dll_init.h"
|
||||||
#include "environ.h"
|
#include "environ.h"
|
||||||
#include "security.h"
|
#include "security.h"
|
||||||
|
@ -28,6 +29,8 @@ extern void __stdcall check_sanity_and_sync (per_process *);
|
||||||
|
|
||||||
dll_list dlls;
|
dll_list dlls;
|
||||||
|
|
||||||
|
muto dll_list::protect;
|
||||||
|
|
||||||
static bool dll_global_dtors_recorded;
|
static bool dll_global_dtors_recorded;
|
||||||
|
|
||||||
/* Run destructors for all DLLs on exit. */
|
/* 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];
|
WCHAR name[NT_MAX_PATH];
|
||||||
DWORD namelen = GetModuleFileNameW (h, name, sizeof (name));
|
DWORD namelen = GetModuleFileNameW (h, name, sizeof (name));
|
||||||
|
|
||||||
|
guard (true);
|
||||||
/* Already loaded? */
|
/* Already loaded? */
|
||||||
dll *d = dlls[name];
|
dll *d = dlls[name];
|
||||||
if (d)
|
if (d)
|
||||||
|
@ -146,6 +150,7 @@ dll_list::alloc (HINSTANCE h, per_process *p, dll_type type)
|
||||||
if (type == DLL_LOAD)
|
if (type == DLL_LOAD)
|
||||||
loaded_dlls++;
|
loaded_dlls++;
|
||||||
}
|
}
|
||||||
|
guard (false);
|
||||||
assert (p->envptr != NULL);
|
assert (p->envptr != NULL);
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
@ -170,27 +175,32 @@ void
|
||||||
dll_list::detach (void *retaddr)
|
dll_list::detach (void *retaddr)
|
||||||
{
|
{
|
||||||
dll *d;
|
dll *d;
|
||||||
if (!myself || !(d = find (retaddr)))
|
if (!myself)
|
||||||
return;
|
return;
|
||||||
if (d->count <= 0)
|
guard (true);
|
||||||
system_printf ("WARNING: trying to detach an already detached dll ...");
|
if ((d = find (retaddr)))
|
||||||
if (--d->count == 0)
|
|
||||||
{
|
{
|
||||||
/* Ensure our exception handler is enabled for destructors */
|
if (d->count <= 0)
|
||||||
exception protect;
|
system_printf ("WARNING: trying to detach an already detached dll ...");
|
||||||
/* Call finalize function if we are not already exiting */
|
if (--d->count == 0)
|
||||||
if (!exit_state)
|
{
|
||||||
__cxa_finalize (d);
|
/* Ensure our exception handler is enabled for destructors */
|
||||||
d->run_dtors ();
|
exception protect;
|
||||||
d->prev->next = d->next;
|
/* Call finalize function if we are not already exiting */
|
||||||
if (d->next)
|
if (!exit_state)
|
||||||
d->next->prev = d->prev;
|
__cxa_finalize (d);
|
||||||
if (d->type == DLL_LOAD)
|
d->run_dtors ();
|
||||||
loaded_dlls--;
|
d->prev->next = d->next;
|
||||||
if (end == d)
|
if (d->next)
|
||||||
end = d->prev;
|
d->next->prev = d->prev;
|
||||||
cfree (d);
|
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. */
|
/* Initialization for all linked DLLs, called by dll_crt0_1. */
|
||||||
|
|
|
@ -72,6 +72,7 @@ class dll_list
|
||||||
dll *end;
|
dll *end;
|
||||||
dll *hold;
|
dll *hold;
|
||||||
dll_type hold_type;
|
dll_type hold_type;
|
||||||
|
static muto protect;
|
||||||
public:
|
public:
|
||||||
dll start;
|
dll start;
|
||||||
int tot;
|
int tot;
|
||||||
|
@ -90,13 +91,22 @@ public:
|
||||||
break;
|
break;
|
||||||
return hold;
|
return hold;
|
||||||
}
|
}
|
||||||
|
|
||||||
dll *istart (dll_type t)
|
dll *istart (dll_type t)
|
||||||
{
|
{
|
||||||
hold_type = t;
|
hold_type = t;
|
||||||
hold = &start;
|
hold = &start;
|
||||||
return inext ();
|
return inext ();
|
||||||
}
|
}
|
||||||
|
void guard(bool lockit)
|
||||||
|
{
|
||||||
|
if (lockit)
|
||||||
|
protect.acquire ();
|
||||||
|
else
|
||||||
|
protect.release ();
|
||||||
|
}
|
||||||
friend void dll_global_dtors ();
|
friend void dll_global_dtors ();
|
||||||
|
dll_list () { protect.init ("dll_list"); }
|
||||||
};
|
};
|
||||||
|
|
||||||
extern dll_list dlls;
|
extern dll_list dlls;
|
||||||
|
|
|
@ -371,6 +371,9 @@ fhandler_termios::lseek (_off64_t, int)
|
||||||
void
|
void
|
||||||
fhandler_termios::sigflush ()
|
fhandler_termios::sigflush ()
|
||||||
{
|
{
|
||||||
if (!(get_ttyp ()->ti.c_lflag & NOFLSH))
|
/* FIXME: Checking get_ttyp() for NULL is not right since it should not
|
||||||
|
be NULL while this is alive. However, we can conceivably close a
|
||||||
|
ctty while exiting and that will zero this. */
|
||||||
|
if (get_ttyp () && !(get_ttyp ()->ti.c_lflag & NOFLSH))
|
||||||
tcflush (TCIFLUSH);
|
tcflush (TCIFLUSH);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
which is intended to operate similarly to a mutex but attempts to
|
which is intended to operate similarly to a mutex but attempts to
|
||||||
avoid making expensive calls to the kernel.
|
avoid making expensive calls to the kernel.
|
||||||
|
|
||||||
Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2009 Red Hat, Inc.
|
Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2009, 2010 Red Hat, Inc.
|
||||||
|
|
||||||
This file is part of Cygwin.
|
This file is part of Cygwin.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue