From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mout.kundenserver.de (mout.kundenserver.de [212.227.17.24]) by sourceware.org (Postfix) with ESMTPS id 2FF453858400 for ; Tue, 26 Oct 2021 09:24:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2FF453858400 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 1N7AAk-1mkdpq43TA-017TNF for ; Tue, 26 Oct 2021 11:24:55 +0200 Received: by calimero.vinschen.de (Postfix, from userid 500) id 74229A80DAB; Tue, 26 Oct 2021 11:24:49 +0200 (CEST) Date: Tue, 26 Oct 2021 11:24:49 +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> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <4b322eb0-4941-6b8f-6f46-aa76caf5a66f@cornell.edu> X-Provags-ID: V03:K1:PQ7AFBxJTroqFtsozMZpA9d1X0fTzGOg9hugS2BqXMJh9jzJWIY jS7drlIQo9Fo35UhgBdZVTlNw3JB8HsAttWS3ilPR0Z0Fg4LoUMnGKKeNnVhl1HNb4Fp0YM Hj8DZbfhJitPqnwy39aOdGB/tiJvub0iIlKvpuqVODqMDaPbhWPBDQ41rVf5vgp/MOlG1/9 bu6LQSwaoSoHL8TPAuDOg== X-UI-Out-Filterresults: notjunk:1;V03:K0:k84v3TsiFck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hs3jgqEIv7H6ZALlNBUFTPkD6N94N4Flz7X0OUe8b11r+3eCDpPStOZe4qX8ZH VgWzPRM1nhNri8= 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_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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:24:58 -0000 On Oct 25 18:02, 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. Right, but malloc_init is only called from dll_crt0_1, so only the main thread can actually call malloc_init, other threads never get there. > 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. That sounds more likely. In theory this shouldn't have much influence, though. First of all, all fixup calls are running in a single thread, so there's no serialization required(*), and the malloc_init call doesn't set up the malloc arena, it just initializes the muto and checks for user space provided malloc calls, which is not a problem in this scenario. (*) unless multiple threads are started during fixup and some of these threads mallocate memory again... Ken, is there a chance to tweak the fifo code to stop creating threads from inside fixup, and to defer the thread start to the first call in the process actually relying on the thread being started? Corinna