* cygtls.cc (_cygtls::call): Invoke new exception protection here.
(_cygtls::init_thread): Remove conditionalized exception handler setup.
(exception_list): Delete declaration.
(_cygtls::init_exception_handler): Delete obsolete function.
* cygtls.h: Remove (now) unneeded include.
(_cygtls): Make this a real C++ class.
(_cygtls::handle_exceptions): Remove.
(_cygtls::init_exception_handler): Remove.
(_cygtls::call2): Make private.
(myfault::faulted): Remove unneeded parentheses.
* dcrt0.cc (dll_crt0_1): Remove exception handler setup.
* dlfcn.cc (dlopen): Ditto.
(dlclose): Ditto.
* dll_init.cc (dll_dllcrt0_1): Ditto.
(dll_list::detach): Use new exception handler protection.
* exceptions.cc (dump_exception): Rename to prevent confusion with new class.
(exception::handle): Rename from _cygtls::handle_exceptions. Accommodate new
exception class. Accommodate rename to dump_exception.
* tlsoffsets.h: Regenerate.
+2010-02-27 Christopher Faylor <me+cygwin@cgf.cx>
+
+ Update some copyrights.
+ * cygtls.cc (_cygtls::call): Invoke new exception protection here.
+ (_cygtls::init_thread): Remove conditionalized exception handler setup.
+ (exception_list): Delete declaration.
+ (_cygtls::init_exception_handler): Delete obsolete function.
+ * cygtls.h: Remove (now) unneeded include.
+ (_cygtls): Make this a real C++ class.
+ (_cygtls::handle_exceptions): Remove.
+ (_cygtls::init_exception_handler): Remove.
+ (_cygtls::call2): Make private.
+ (myfault::faulted): Remove unneeded parentheses.
+ * dcrt0.cc (dll_crt0_1): Remove exception handler setup.
+ * dlfcn.cc (dlopen): Ditto.
+ (dlclose): Ditto.
+ * dll_init.cc (dll_dllcrt0_1): Ditto.
+ (dll_list::detach): Use new exception handler protection.
+ * exceptions.cc (dump_exception): Rename to prevent confusion with new
+ class.
+ (exception::handle): Rename from _cygtls::handle_exceptions.
+ Accommodate new exception class. Accommodate rename to dump_exception.
+ * tlsoffsets.h: Regenerate.
+
2010-02-26 Christopher Faylor <me+cygwin@cgf.cx>
* cygtls.h (_cygtls::init_exception_handler): Eliminate argument.
/* cygtls.cc
- Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Red Hat, Inc.
+ Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Red Hat, Inc.
This software is a copyrighted work licensed under the terms of the
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
#include "dtable.h"
#include "cygheap.h"
#include "sigproc.h"
+#include "exception.h"
class sentry
{
_cygtls::call (DWORD (*func) (void *, void *), void *arg)
{
char buf[CYGTLS_PADSIZE];
+ /* Initialize this thread's ability to respond to things like
+ SIGSEGV or SIGFPE. */
+ exception protect;
_my_tls.call2 (func, arg, buf);
}
}
local_clib._current_locale = "C";
locals.process_logmask = LOG_UPTO (LOG_DEBUG);
- /* Initialize this thread's ability to respond to things like
- SIGSEGV or SIGFPE. */
- init_exception_handler ();
}
thread_id = GetCurrentThreadId ();
{
infodata = pack->si;
}
-
-/* Set up the exception handler for the current thread. The x86 uses segment
- register fs, offset 0 to point to the current exception handler. */
-
-extern exception_list *_except_list asm ("%fs:0");
-
-void
-_cygtls::init_exception_handler ()
-{
- /* Here in the distant past of 17-Jul-2009, we had an issue where Windows
- 2008 became YA perplexed because the cygwin exception handler was added
- at the start of the SEH while still being in the list further on. This
- was because we added a loop by setting el.prev to _except_list here.
- Since el is reused in this thread, and this function can be called
- more than once when a dll is loaded, this is not a good thing.
-
- So, for now, until the next required tweak, we will just avoid adding the
- cygwin exception handler if it is already on this list. This could present
- a problem if some previous exception handler tries to do things that are
- better left to Cygwin. I await the cygwin mailing list notification of
- this event with bated breath.
- (cgf 2009-07-17)
-
- A change in plans: In the not-so-distant past of 2010-02-23 it was
- discovered that something was moving in ahead of cygwin's exception
- handler so just detecting that the exception handler was loaded wasn't
- good enough. I sort of anticipated this. So, the next step is to remove
- the old exception handler from the list and add it to the beginning.
-
- The next step will probably be to call this function at various points
- in cygwin (like from _cygtls::setup_fault maybe) to absolutely ensure that
- we have control. For now, however, this seems good enough.
- (cgf 2010-02-23)
- */
- exception_list *e = _except_list;
- if (e == &el)
- return;
- while (e && e != (exception_list *) -1)
- if (e->prev != &el)
- e = e->prev;
- else
- {
- e->prev = el.prev;
- break;
- }
- /* Apparently Windows stores some information about an exception and tries
- to figure out if the SEH which returned 0 last time actually solved the
- problem, or if the problem still persists (e.g. same exception at same
- address). In this case Windows seems to decide that it can't trust
- that SEH and calls the next handler in the chain instead.
-
- At one point this was a loop (el.prev = ⪙). This outsmarted the
- above behaviour. Unfortunately this trick doesn't work anymore with
- Windows 2008, which irremediably gets into an endless loop, taking 100%
- CPU. That's why we reverted to a normal SEH chain and changed the way
- the exception handler returns to the application. */
- el.handler = handle_exceptions;
- el.prev = _except_list;
- _except_list = ⪙
-}
/* cygtls.h
- Copyright 2003, 2004, 2005, 2008, 2009 Red Hat, Inc.
+ Copyright 2003, 2004, 2005, 2008, 2009, 2010 Red Hat, Inc.
This software is a copyrighted work licensed under the terms of the
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
#include <mntent.h>
#undef _NOMNTENT_FUNCS
#include <setjmp.h>
-#include <exceptions.h>
#define CYGTLS_INITIALIZED 0xc763173f
/*gentls_offsets*/
typedef __uint32_t __stack_t;
-struct _cygtls
+
+class _cygtls
{
+public:
void (*func) /*gentls_offsets*/(int)/*gentls_offsets*/;
- exception_list el;
int saved_errno;
int sa_flags;
sigset_t oldmask;
static void init ();
void init_thread (void *, DWORD (*) (void *, void *));
static void call (DWORD (*) (void *, void *), void *);
- void call2 (DWORD (*) (void *, void *), void *, void *) __attribute__ ((regparm (3)));
static struct _cygtls *find_tls (int sig);
void remove (DWORD);
void push (__stack_t) __attribute__ ((regparm (2)));
struct sigaction& siga)
__attribute__((regparm(3)));
- /* exception handling */
- static int handle_exceptions (EXCEPTION_RECORD *, exception_list *, CONTEXT *, void *);
bool inside_kernel (CONTEXT *);
- void init_exception_handler () __attribute__ ((regparm(1)));
void signal_exit (int) __attribute__ ((noreturn, regparm(2)));
void copy_context (CONTEXT *) __attribute__ ((regparm(2)));
void signal_debugger (int) __attribute__ ((regparm(2)));
void lock () __attribute__ ((regparm (1)));
void unlock () __attribute__ ((regparm (1)));
bool locked () __attribute__ ((regparm (1)));
+private:
+ void call2 (DWORD (*) (void *, void *), void *, void *) __attribute__ ((regparm (3)));
/*gentls_offsets*/
};
#pragma pack(pop)
}
inline int faulted (void const *obj, int myerrno = 0) __attribute__ ((always_inline))
{
- return (!obj || !(*(const char **)obj)) || sebastian.setup (myerrno);
+ return !obj || !(*(const char **) obj) || sebastian.setup (myerrno);
}
inline int faulted (int myerrno) __attribute__ ((always_inline))
{
#include "dll_init.h"
#include "heap.h"
#include "tls_pbuf.h"
+#include "exception.h"
#define MAX_AT_FILE_LEVEL 10
{
_tlsbase = (char *) fork_info->stackbottom;
_tlstop = (char *) fork_info->stacktop;
- _my_tls.init_exception_handler ();
}
longjmp (fork_info->jmp, true);
/* dlfcn.cc
- Copyright 1998, 2000, 2001, 2002, 2003, 2004, 2008, 2009 Red Hat, Inc.
+ Copyright 1998, 2000, 2001, 2002, 2003, 2004, 2008, 2009, 2010 Red Hat, Inc.
This file is part of Cygwin.
ret = (void *) LoadLibraryW (path);
- /* In case it was removed by LoadLibrary. */
- _my_tls.init_exception_handler ();
-
/* Restore original cxx_malloc pointer. */
__cygwin_user_data.cxx_malloc = tmp_malloc;
int ret;
if (handle == GetModuleHandle (NULL))
ret = 0;
+ else if (FreeLibrary ((HMODULE) handle))
+ ret = 0;
else
- {
- if (FreeLibrary ((HMODULE) handle))
- ret = 0;
- else
- ret = -1;
- /* In case it was removed by FreeLibrary */
- _my_tls.init_exception_handler ();
- }
+ ret = -1;
if (ret)
set_dl_error ("dlclose");
return ret;
/* dll_init.cc
Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
- 2007, 2008, 2009 Red Hat, Inc.
+ 2007, 2008, 2009, 2010 Red Hat, Inc.
This software is a copyrighted work licensed under the terms of the
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
#include "cygheap.h"
#include "pinfo.h"
#include "cygtls.h"
+#include "exception.h"
#include <wchar.h>
#include <sys/reent.h>
system_printf ("WARNING: trying to detach an already detached dll ...");
if (--d->count == 0)
{
- /* Make sure our exception handler is enabled for destructors */
- _my_tls.init_exception_handler ();
+ /* Ensure our exception handler is enabled for destructors */
+ exception protect;
__cxa_finalize (d);
d->run_dtors ();
d->prev->next = d->next;
per_process*& p = ((dllcrt0_info *)x)->p;
int& res = ((dllcrt0_info *)x)->res;
- /* Make sure that our exception handler is installed.
- That should always be the case but this just makes sure.
-
- At some point, we may want to just remove this code since
- the exception handler should be guaranteed to be installed.
- I'm leaving it in until potentially after the release of
- 1.7.1 */
- _my_tls.init_exception_handler ();
-
if (p == NULL)
p = &__cygwin_user_data;
else
--- /dev/null
+/* exception.h
+
+ Copyright 2003, 2004, 2005, 2008, 2009 Red Hat, Inc.
+
+This software is a copyrighted work licensed under the terms of the
+Cygwin license. Please consult the file "CYGWIN_LICENSE" for
+details. */
+
+#ifndef _EXCEPTION_H
+#define _EXCEPTION_H
+
+#include <exceptions.h>
+
+extern exception_list *_except_list asm ("%fs:0");
+
+class exception
+{
+ exception_list el;
+ exception_list *save;
+ static int handle (EXCEPTION_RECORD *, exception_list *, CONTEXT *, void *);
+public:
+#ifdef DEBUG_EXCEPTION
+ exception ();
+ ~exception ();
+#else
+ exception () __attribute__ ((always_inline))
+ {
+ save = _except_list;
+ el.handler = handle;
+ el.prev = _except_list;
+ _except_list = ⪙
+ };
+ ~exception () __attribute__ ((always_inline)) { _except_list = save; }
+#endif
+};
+
+#endif /*_CYGTLS_H*/ /*gentls_offsets*/
+
/* exceptions.cc
Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
- 2005, 2006, 2007, 2008, 2009 Red Hat, Inc.
+ 2005, 2006, 2007, 2008, 2009, 2010 Red Hat, Inc.
This file is part of Cygwin.
#include "cygheap.h"
#include "child_info.h"
#include "ntdll.h"
+#include "exception.h"
#define CALL_HANDLER_RETRY 20
/* Utilities for dumping the stack, etc. */
static void
-exception (EXCEPTION_RECORD *e, CONTEXT *in)
+dump_exception (EXCEPTION_RECORD *e, CONTEXT *in)
{
const char *exception_name = NULL;
extern exception_list *_except_list asm ("%fs:0");
int
-_cygtls::handle_exceptions (EXCEPTION_RECORD *e, exception_list *frame, CONTEXT *in, void *)
+exception::handle (EXCEPTION_RECORD *e, exception_list *frame, CONTEXT *in, void *)
{
static bool NO_COPY debugging;
static int NO_COPY recursed;
/* Temporarily replace windows top level SEH with our own handler.
We don't want any Windows magic kicking in. This top level frame
will be removed automatically after our exception handler returns. */
- _except_list->handler = _cygtls::handle_exceptions;
+ _except_list->handler = handle;
if (masked
|| &me == _sig_tls
rtl_unwind (frame, e);
open_stackdumpfile ();
- exception (e, in);
+ dump_exception (e, in);
stackdump ((DWORD) ebp, 0, 1);
}
//;# autogenerated: Do not edit.
-//; $tls::sizeof__cygtls = 4312;
+//; $tls::sizeof__cygtls = 4304;
//; $tls::func = -12700;
//; $tls::pfunc = 0;
-//; $tls::el = -12696;
-//; $tls::pel = 4;
-//; $tls::saved_errno = -12688;
-//; $tls::psaved_errno = 12;
-//; $tls::sa_flags = -12684;
-//; $tls::psa_flags = 16;
-//; $tls::oldmask = -12680;
-//; $tls::poldmask = 20;
-//; $tls::deltamask = -12676;
-//; $tls::pdeltamask = 24;
-//; $tls::event = -12672;
-//; $tls::pevent = 28;
-//; $tls::errno_addr = -12668;
-//; $tls::perrno_addr = 32;
-//; $tls::sigmask = -12664;
-//; $tls::psigmask = 36;
-//; $tls::sigwait_mask = -12660;
-//; $tls::psigwait_mask = 40;
-//; $tls::sigwait_info = -12656;
-//; $tls::psigwait_info = 44;
-//; $tls::thread_context = -12652;
-//; $tls::pthread_context = 48;
-//; $tls::thread_id = -12440;
-//; $tls::pthread_id = 260;
-//; $tls::threadkill = -12436;
-//; $tls::pthreadkill = 264;
-//; $tls::infodata = -12432;
-//; $tls::pinfodata = 268;
-//; $tls::tid = -12284;
-//; $tls::ptid = 416;
-//; $tls::local_clib = -12280;
-//; $tls::plocal_clib = 420;
-//; $tls::__dontuse = -12280;
-//; $tls::p__dontuse = 420;
-//; $tls::locals = -11192;
-//; $tls::plocals = 1508;
-//; $tls::_ctinfo = -9472;
-//; $tls::p_ctinfo = 3228;
-//; $tls::andreas = -9468;
-//; $tls::pandreas = 3232;
-//; $tls::wq = -9464;
-//; $tls::pwq = 3236;
-//; $tls::sig = -9436;
-//; $tls::psig = 3264;
-//; $tls::incyg = -9432;
-//; $tls::pincyg = 3268;
-//; $tls::spinning = -9428;
-//; $tls::pspinning = 3272;
-//; $tls::stacklock = -9424;
-//; $tls::pstacklock = 3276;
-//; $tls::stackptr = -9420;
-//; $tls::pstackptr = 3280;
-//; $tls::stack = -9416;
-//; $tls::pstack = 3284;
-//; $tls::initialized = -8392;
-//; $tls::pinitialized = 4308;
+//; $tls::saved_errno = -12696;
+//; $tls::psaved_errno = 4;
+//; $tls::sa_flags = -12692;
+//; $tls::psa_flags = 8;
+//; $tls::oldmask = -12688;
+//; $tls::poldmask = 12;
+//; $tls::deltamask = -12684;
+//; $tls::pdeltamask = 16;
+//; $tls::event = -12680;
+//; $tls::pevent = 20;
+//; $tls::errno_addr = -12676;
+//; $tls::perrno_addr = 24;
+//; $tls::sigmask = -12672;
+//; $tls::psigmask = 28;
+//; $tls::sigwait_mask = -12668;
+//; $tls::psigwait_mask = 32;
+//; $tls::sigwait_info = -12664;
+//; $tls::psigwait_info = 36;
+//; $tls::thread_context = -12660;
+//; $tls::pthread_context = 40;
+//; $tls::thread_id = -12448;
+//; $tls::pthread_id = 252;
+//; $tls::threadkill = -12444;
+//; $tls::pthreadkill = 256;
+//; $tls::infodata = -12440;
+//; $tls::pinfodata = 260;
+//; $tls::tid = -12292;
+//; $tls::ptid = 408;
+//; $tls::local_clib = -12288;
+//; $tls::plocal_clib = 412;
+//; $tls::__dontuse = -12288;
+//; $tls::p__dontuse = 412;
+//; $tls::locals = -11200;
+//; $tls::plocals = 1500;
+//; $tls::_ctinfo = -9480;
+//; $tls::p_ctinfo = 3220;
+//; $tls::andreas = -9476;
+//; $tls::pandreas = 3224;
+//; $tls::wq = -9472;
+//; $tls::pwq = 3228;
+//; $tls::sig = -9444;
+//; $tls::psig = 3256;
+//; $tls::incyg = -9440;
+//; $tls::pincyg = 3260;
+//; $tls::spinning = -9436;
+//; $tls::pspinning = 3264;
+//; $tls::stacklock = -9432;
+//; $tls::pstacklock = 3268;
+//; $tls::stackptr = -9428;
+//; $tls::pstackptr = 3272;
+//; $tls::stack = -9424;
+//; $tls::pstack = 3276;
+//; $tls::initialized = -8400;
+//; $tls::pinitialized = 4300;
//; __DATA__
#define tls_func (-12700)
#define tls_pfunc (0)
-#define tls_el (-12696)
-#define tls_pel (4)
-#define tls_saved_errno (-12688)
-#define tls_psaved_errno (12)
-#define tls_sa_flags (-12684)
-#define tls_psa_flags (16)
-#define tls_oldmask (-12680)
-#define tls_poldmask (20)
-#define tls_deltamask (-12676)
-#define tls_pdeltamask (24)
-#define tls_event (-12672)
-#define tls_pevent (28)
-#define tls_errno_addr (-12668)
-#define tls_perrno_addr (32)
-#define tls_sigmask (-12664)
-#define tls_psigmask (36)
-#define tls_sigwait_mask (-12660)
-#define tls_psigwait_mask (40)
-#define tls_sigwait_info (-12656)
-#define tls_psigwait_info (44)
-#define tls_thread_context (-12652)
-#define tls_pthread_context (48)
-#define tls_thread_id (-12440)
-#define tls_pthread_id (260)
-#define tls_threadkill (-12436)
-#define tls_pthreadkill (264)
-#define tls_infodata (-12432)
-#define tls_pinfodata (268)
-#define tls_tid (-12284)
-#define tls_ptid (416)
-#define tls_local_clib (-12280)
-#define tls_plocal_clib (420)
-#define tls___dontuse (-12280)
-#define tls_p__dontuse (420)
-#define tls_locals (-11192)
-#define tls_plocals (1508)
-#define tls__ctinfo (-9472)
-#define tls_p_ctinfo (3228)
-#define tls_andreas (-9468)
-#define tls_pandreas (3232)
-#define tls_wq (-9464)
-#define tls_pwq (3236)
-#define tls_sig (-9436)
-#define tls_psig (3264)
-#define tls_incyg (-9432)
-#define tls_pincyg (3268)
-#define tls_spinning (-9428)
-#define tls_pspinning (3272)
-#define tls_stacklock (-9424)
-#define tls_pstacklock (3276)
-#define tls_stackptr (-9420)
-#define tls_pstackptr (3280)
-#define tls_stack (-9416)
-#define tls_pstack (3284)
-#define tls_initialized (-8392)
-#define tls_pinitialized (4308)
+#define tls_saved_errno (-12696)
+#define tls_psaved_errno (4)
+#define tls_sa_flags (-12692)
+#define tls_psa_flags (8)
+#define tls_oldmask (-12688)
+#define tls_poldmask (12)
+#define tls_deltamask (-12684)
+#define tls_pdeltamask (16)
+#define tls_event (-12680)
+#define tls_pevent (20)
+#define tls_errno_addr (-12676)
+#define tls_perrno_addr (24)
+#define tls_sigmask (-12672)
+#define tls_psigmask (28)
+#define tls_sigwait_mask (-12668)
+#define tls_psigwait_mask (32)
+#define tls_sigwait_info (-12664)
+#define tls_psigwait_info (36)
+#define tls_thread_context (-12660)
+#define tls_pthread_context (40)
+#define tls_thread_id (-12448)
+#define tls_pthread_id (252)
+#define tls_threadkill (-12444)
+#define tls_pthreadkill (256)
+#define tls_infodata (-12440)
+#define tls_pinfodata (260)
+#define tls_tid (-12292)
+#define tls_ptid (408)
+#define tls_local_clib (-12288)
+#define tls_plocal_clib (412)
+#define tls___dontuse (-12288)
+#define tls_p__dontuse (412)
+#define tls_locals (-11200)
+#define tls_plocals (1500)
+#define tls__ctinfo (-9480)
+#define tls_p_ctinfo (3220)
+#define tls_andreas (-9476)
+#define tls_pandreas (3224)
+#define tls_wq (-9472)
+#define tls_pwq (3228)
+#define tls_sig (-9444)
+#define tls_psig (3256)
+#define tls_incyg (-9440)
+#define tls_pincyg (3260)
+#define tls_spinning (-9436)
+#define tls_pspinning (3264)
+#define tls_stacklock (-9432)
+#define tls_pstacklock (3268)
+#define tls_stackptr (-9428)
+#define tls_pstackptr (3272)
+#define tls_stack (-9424)
+#define tls_pstack (3276)
+#define tls_initialized (-8400)
+#define tls_pinitialized (4300)