DMARC-Filter: OpenDMARC Filter v1.4.2 delorie.com 53AI53Y63387652
Authentication-Results: delorie.com; dmarc=pass (p=none dis=none) header.from=cygwin.com
Authentication-Results: delorie.com; spf=pass smtp.mailfrom=cygwin.com
DKIM-Filter: OpenDKIM Filter v2.11.0 delorie.com 53AI53Y63387652
Authentication-Results: delorie.com;
	dkim=pass (1024-bit key, unprotected) header.d=cygwin.com header.i=@cygwin.com header.a=rsa-sha256 header.s=default header.b=Nx1eNQMV
X-Recipient: archive-cygwin@delorie.com
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A819B384389D
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com;
	s=default; t=1744308302;
	bh=o3FLI+jScDJ4G+NnV2bb+kxZ8CsTEmS2zkkA9b6QWe0=;
	h=Date:To:Subject:In-Reply-To:References:List-Id:List-Unsubscribe:
	 List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:
	 From;
	b=Nx1eNQMVEfh80pmk6VlLr9rc0LRRerzj9MFLXMayFDZcn9cLw5fEiDZADcgWDf9JS
	 Xh3p+KzZF/30YIAUakfwp6I1AeDrgYjnLYQoDEGA8Bv+5pat8mpMO9pPxN1ZAbZ4be
	 lDieuaO8qA9eWGw5GaWUPszLCp8ZEsLZdnOFObvk=
X-Original-To: cygwin@cygwin.com
Delivered-To: cygwin@cygwin.com
DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 00AB23857712
ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 00AB23857712
ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1744308240; cv=none;
 b=RaVzTxRhPcpxQtgi39wWRczouvZPhuiomKMjYgV868h3MfnB6/0wgmyDqzEXGI/Yngp9bpna/Qgb8mbtrwV0WgRoTzHiVk+bzNkUMMcxqnB33ZhCuMvMKVXa47ZpR90fdUPwWPuQTL9MnpWNzpJFC6hN/bnMegqil1b7I/Gmkq8=
ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key;
 t=1744308240; c=relaxed/simple;
 bh=4tKQl2rPD3HsBFvXUvCd+yDNNsbc0SsrA3oHFvFRdz8=;
 h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version;
 b=ezT1eaWUNasM0vkvx4ZlyAOFdRV/OFlD/GCNZZCNoE8sjLXO4GbSAGhjGuExolGpiWvZo7kpJH4cmjdyxhUtp+WJG0J1bIZY+scjJuGmBT106PNq6yI50WMTLSOCLbZMXGnWOW4purPQL1DsKG2l6p6YyJQec4NX/W+V3bn6ogU=
ARC-Authentication-Results: i=1; server2.sourceware.org
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 00AB23857712
Date: Thu, 10 Apr 2025 11:03:59 -0700 (PDT)
X-X-Sender: jeremyd@resin.csoft.net
To: Corinna Vinschen via Cygwin <cygwin@cygwin.com>
Subject: Re: pthread_atfork vs dlopen/dlclose
In-Reply-To: <Z_eJqDJw-xbhktwC@calimero.vinschen.de>
Message-ID: <fe7d04eb-584d-ca1c-4408-be2bcd58e4af@jdrake.com>
References: <07665688-8199-2e80-cdfe-abeaa6f56ba7@jdrake.com>
 <2021152719.99592.1744265074916@mail.yahoo.com>
 <b150c1e4-b3cd-4f90-8548-0c5f287948d4@jdrake.com>
 <94af5480-167a-fcc6-5f4c-89afa5ce8637@jdrake.com>
 <Z_eJqDJw-xbhktwC@calimero.vinschen.de>
MIME-Version: 1.0
X-BeenThere: cygwin@cygwin.com
X-Mailman-Version: 2.1.30
Precedence: list
List-Id: General Cygwin discussions and problem reports <cygwin.cygwin.com>
List-Unsubscribe: <https://cygwin.com/mailman/options/cygwin>,
 <mailto:cygwin-request@cygwin.com?subject=unsubscribe>
List-Archive: <https://cygwin.com/pipermail/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-request@cygwin.com?subject=help>
List-Subscribe: <https://cygwin.com/mailman/listinfo/cygwin>,
 <mailto:cygwin-request@cygwin.com?subject=subscribe>
From: Jeremy Drake via Cygwin <cygwin@cygwin.com>
Reply-To: Jeremy Drake <cygwin@jdrake.com>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: cygwin-bounces~archive-cygwin=delorie.com@cygwin.com
Sender: "Cygwin" <cygwin-bounces~archive-cygwin=delorie.com@cygwin.com>

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.  What about at_quick_exit though?
That's entirely within newlib, isn't it?

-- 
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
