On Apr 10 11:03, Jeremy Drake via Cygwin wrote:
> On Thu, 10 Apr 2025, Corinna Vinschen via Cygwin wrote:
> 
> > > It seems glibc takes care of this implicit deregistration in
> > > __cxa_finalize, after calling __cxa_atexit functions, it unregisters any
> > > at_quick_exit or pthread_atfork callbacks from the DSO being unloaded.
> > >
> > > https://sourceware.org/git/?p=glibc.git;a=blob;f=stdlib/cxa_finalize.c;h=2bb35602edc6bf842e5d2c93ad03454d7b57ee65;hb=HEAD
> > >
> > > It doesn't look like newlib deals with either at_quick_exit or
> > > pthread_atfork handlers in its __cxa_finalize implementation.
> >
> > Cygwin is doing this stuff mostly in its own code, see thread.cc.
> > It keeps lists of the callbacks in a global structure which is
> > called MT_INTERFACE throughout thread.cc.
> >
> > The functions pthread::atforkprepare(), pthread::atforkparent() and
> > pthread::atforkchild () are called from different spots during fork().
> >
> > Here's what we're missing:
> >
> > - Either keep track of the DLL a callback function is coming from by
> >   calling dlls.find (handle, true) and store the struct dll pointer.
> >   In dlclose(), if the DLL is of type DLL_LOAD or DLL_NATIVE, and
> >   the refcounter indicates that this is the last FreeLibrary, check the
> >   three callback lists in MT_INTERFACE and remove all functions
> >   with the same struct dll pointer.
> 
> I'm inclined to take this approach.

You can do the cleanup in dll_list::detach, btw.

> What about at_quick_exit though?
> That's entirely within newlib, isn't it?

Yes, and it's neither DSO aware, nor is it called during a normal exit.
I'd ignore it for now, or we need a new implementation along the lines
of the GLibc implementation which always stores the DSO handle together
with the handler function.  But that's something for 3.7, not a bugfix
for 3.6.


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

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

Reply via email to