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: dlopen() bug (new testcase)


--- Bernhard Loos <bernloos@web.de> wrote:

> I was able to track the problem down, inserting a
> call to
> _my_tls.init_exception_handler
> (_cygtls::handle_exceptions);
> in the function dll::init() solves it. But I'm
> unsure, whether it introduce
> other bugs. If somebody has checked this, I could
> submit a patch, if necessary.
> 
>                      Bernhard Loos
> 

Bernard,

I did some further checking this weekend and have
confirmed that MS LoadLibrary() installs a new
exception handler (in NTDLL.DLL) which gets called
when the access error caused by the call into
verifyable_object_isvalid() called from
pthread_key_create() called from pthread::once() ...
when a dll is dlopen()ed. Evidently, this exception
handler does not pass control back to the Cygwin
exception handler, leaving Cygwin's state unstable.

All of this can be checked in gdb by examining fs:0
inside of dlopen () before the call to LoadLibrary ()
and again in dll_dllcrt0 ()

I see three possible places to apply a patch:
  1) in dll::init() [dll_init.cc]:
     [NOTE: this will get called whether any dll is
dlopen()ed or linked in at compile time]
     int
     dll::init ()
     {
       int ret = 1;
      
_my_tls.init_exception_handler(_cygtls::handle_exceptions);
       ...

  2) in pthread::once()  [thread.cc]:
     [NOTE: exception handler only gets installed here
for the first dlopen()ed dll]
     if (!once_control->state)
       {
        
_my_tls.init_exception_handler(_cygtls::handle_exceptions);
         init_routine ();
         once_control->state = 1;
       }
      ...

  3) or remove the test that leads directly to the
problem in pthread_key_create() [thread.cc]:
     [NOTE: the comment indicates that this check may
not be necessary, anyway]
    extern "C" int
     pthread_key_create (pthread_key_t *key, void
(*destructor) (void *))
     {
       /* The opengroup docs don't define if we should
check this or not,
          but creation is relatively rare.  */
       /* REMOVE THE FOLLOWING TWO LINES: */
     if (pthread_key::is_good_object (key))
         return EBUSY;


If you need any more information or support for
getting this patched, let me know.

Thank you,
Gary Zablackis

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


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