This is the mail archive of the cygwin mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Statically initialising pthread attributes in dynamic dlls.

On 24/02/2010 04:52, Dave Korn wrote:

>   I think the answer lies here, in this comment in dll_dllcrt0_1:
>>   /* 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 (_cygtls::handle_exceptions);
>   Well, it may or may not already be installed, depending whether we got here
> via dlopen or whether this is a statically-linked DLL being initialised at
> process startup, and if it is already installed, it's not at the front of the
> list.  So I figure the best bet would be to replace this call with a local
> stack-frame-based exception registration record, which we'll unlink if we
> return.  IOW, just the same thing as those OS-registered SEH frames are doing
> when they unwind.  I'll report back later if it works.

  Yeh, that works nicely.  Here's what I tested, along with a couple of extra
test cases I used to check whether exception handling was still working before
and after the dlopen call.  With the current state of HEAD, the first one
works (by which I mean "prints 'sig 11' forever" and the second one fails (by
which I means reaches some sort of exit without hitting the signal handler at
all).  With the attached diff, they both work (as does the original unmodified

  This is just a brain dump because I'm off to bed now, hence no change log,
and there's still commented-out stuff and inadequate commenting, but I figured
 I may as well let everyone know what I found out.  'night all!


Index: winsup/cygwin/
RCS file: /cvs/src/src/winsup/cygwin/,v
retrieving revision 1.70
diff -p -u -r1.70
--- winsup/cygwin/	5 Feb 2010 15:05:22 -0000	1.70
+++ winsup/cygwin/	24 Feb 2010 05:05:45 -0000
@@ -329,7 +329,14 @@ dll_dllcrt0_1 (VOID *x)
      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 (_cygtls::handle_exceptions);
+  /* _my_tls.init_exception_handler (_cygtls::handle_exceptions); */
+  /* Correction: install a temporary registration with our handler
+     at the head of the list, and unlink it before returning.  */
+  extern exception_list *_except_list asm ("%fs:0");
+  exception_list seh;
+  seh.handler = _cygtls::handle_exceptions;
+  seh.prev = _except_list;
+  _except_list = &seh;
   if (p == NULL)
     p = &__cygwin_user_data;
@@ -390,6 +397,8 @@ dll_dllcrt0_1 (VOID *x)
     res = -1;
     res = (DWORD) d;
+  _except_list = seh.prev;
 /* OBSOLETE: This function is obsolete and will go away in the

Attachment: test3.cpp
Description: Text document

Attachment: test4.cpp
Description: Text document

Problem reports:
Unsubscribe info:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]