From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mout.kundenserver.de (mout.kundenserver.de [217.72.192.73]) by sourceware.org (Postfix) with ESMTPS id 9B97C3858400 for ; Tue, 26 Oct 2021 09:27:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9B97C3858400 Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=cygwin.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=cygwin.com Received: from calimero.vinschen.de ([24.134.7.25]) by mrelayeu.kundenserver.de (mreue106 [212.227.15.183]) with ESMTPSA (Nemesis) id 1MCs9W-1mWXIR0XyK-008vqR for ; Tue, 26 Oct 2021 11:27:23 +0200 Received: by calimero.vinschen.de (Postfix, from userid 500) id 42A53A80DAB; Tue, 26 Oct 2021 11:27:18 +0200 (CEST) Date: Tue, 26 Oct 2021 11:27:18 +0200 From: Corinna Vinschen To: cygwin-developers@cygwin.com Subject: Re: malloc crash Message-ID: Reply-To: cygwin-developers@cygwin.com Mail-Followup-To: cygwin-developers@cygwin.com References: <6a4d6675-7e4d-bcb3-9aff-acc0788d211d@cornell.edu> <97873b16-7ec3-02d7-1861-3ec62a79c37e@cornell.edu> <4b322eb0-4941-6b8f-6f46-aa76caf5a66f@cornell.edu> <2819d0db-3c5c-2d31-2b21-91efafb7f8f4@maxrnd.com> <20211026091855.7aaf2de97d10174121cbc8f9@nifty.ne.jp> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Provags-ID: V03:K1:aP0MX9Pw72//2Lfm1HtHTZ1UTikw46yPL5eqltqsndfCqxeu2Sc 6SFYbASsildF/rdk9nXX9L4p0Ck+Z/m4hrhREVgAUViaDN65g0+BhqTLoX4kMQ2Qf9eMr9u gqxKp1XDdIVXAOk34DKvQEJ/Z6G5O1Ek+Q/WKNEz8etDo4BilNXzfoL3oOUiLCH5FkekpMZ 0HmAniWimonTpGkdt9T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KRV7+qtpcKpTTV9800qeKvAaZpLk AU3/VUEFs3aOgKzeB7nhEv9ERE/LFDIuNWomhTocNEjZgPAcDiN+Uos/MOA5eDL2wv1cshBRx ofdXBkXDajU33M= X-Spam-Status: No, score=-99.6 required=5.0 tests=BAYES_00, GOOD_FROM_CORINNA_CYGWIN, KAM_DMARC_NONE, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NEUTRAL, TXREP, WEIRD_PORT autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: cygwin-developers@cygwin.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Cygwin core component developers mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 26 Oct 2021 09:27:27 -0000 On Oct 25 17:54, Mark Geisert wrote: > Takashi Yano wrote: > > On Mon, 25 Oct 2021 16:36:50 -0700 > > Mark Geisert wrote: > > > Ken Brown wrote: > > > > On 10/25/2021 5:29 PM, Mark Geisert wrote: > > > > > Corinna Vinschen wrote: > > > > > > On Oct 25 08:35, Ken Brown wrote: > > > > > > > On 10/25/2021 4:59 AM, Corinna Vinschen wrote: > > > > > > > > Has the thread already been started at this point? > > > > > > > > > > > > > > Yes, here's the backtrace of that thread: > > > > > > > > > > > > > > Thread 5 (Thread 9692.0x7c4c): > > > > > > > #0  0x00000001801934f9 in sys_alloc (m=0x18036f860 <_gm_>, nb=1040) at > > > > > > > ../../../../temp/winsup/cygwin/malloc.cc:4232 > > > > > > > #1  0x0000000180196b96 in dlmalloc (bytes=1024) at > > > > > > > ../../../../temp/winsup/cygwin/malloc.cc:4669 > > > > > > > #2  0x00000001801993e1 in dlrealloc (oldmem=0x0, bytes=1024) at > > > > > > > ../../../../temp/winsup/cygwin/malloc.cc:5187 > > > > > > > #3  0x00000001800e8eed in realloc (p=0x0, size=1024) at > > > > > > > ../../../../temp/winsup/cygwin/malloc_wrapper.cc:73 > > > > > > > > > > > > Er... huh?  So both threads are in a malloc function?  This shouldn't > > > > > > have happened, given the clunky muto guarding malloc calls.  This is > > > > > > really strange.  Why's the muto not working here? > > > > > > > > > > Is it possible both threads have executed malloc_init()? > > > > > If so, the second one would reinit the muto. > > > > > > > > Or does the fifo_reader thread call a malloc function before the main thread has > > > > called malloc_init()?  This would presumably cause __malloc_lock() to fail, but > > > > there's no error check. > > > > > > If there's a global constructor involved, that is known to happen. Constructors > > > are run from dll_crt0_0(), before malloc_init() is called from dll_crt0_1(). See > > > dcrt0.cc for the details. > > > > So how about moving malloc_init() call from dll_crt0_1() to dll_crl0_0() > > so that malloc() can be called in fixup_after_fork/exec()? > > It appears simple, but this is a touchy area of code. The _0 and _1 are two > separate phases of process startup. I'd want to hear Corinna's thoughts on > this. This would have to be split into two calls then. The muto initialization can be moved to dll_crt0_0, but the check for user space provided malloc can only occur after the processes' CRT code has run, so this can only be done from dll_crt0_1. > I'd also like to verify somehow that this is the scenario Ken is hitting. Yeah, that's not a safe bet yet. Corinna