From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 32379 invoked by alias); 7 Sep 2015 12:28:41 -0000 Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner@cygwin.com Mail-Followup-To: cygwin@cygwin.com Received: (qmail 32365 invoked by uid 89); 7 Sep 2015 12:28:40 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.5 required=5.0 tests=AWL,BAYES_20,KAM_LAZY_DOMAIN_SECURITY autolearn=no version=3.3.2 X-HELO: calimero.vinschen.de Received: from aquarius.hirmke.de (HELO calimero.vinschen.de) (217.91.18.234) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 07 Sep 2015 12:28:39 +0000 Received: by calimero.vinschen.de (Postfix, from userid 500) id EE97FA8084B; Mon, 7 Sep 2015 14:28:36 +0200 (CEST) Date: Mon, 07 Sep 2015 12:28:00 -0000 From: Corinna Vinschen To: cygwin@cygwin.com Subject: Re: [OT] Wine + Cygwin: `script -e` exit status forwarding randomly return zero for non zero child process Message-ID: <20150907122836.GB20288@calimero.vinschen.de> Reply-To: cygwin@cygwin.com Mail-Followup-To: cygwin@cygwin.com References: <20150903105549.GT23669@calimero.vinschen.de> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="CdrF4e02JqNVZeln" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) X-SW-Source: 2015-09/txt/msg00107.txt.bz2 --CdrF4e02JqNVZeln Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-length: 3563 On Sep 7 19:02, Qian Hong wrote: > Hi Corinna, >=20 > Sorry for delay, our progress on this issue is slow. >=20 > Many thanks for your great information, it does help us became closer > to the reason. >=20 > On Thu, Sep 3, 2015 at 6:55 PM, Corinna Vinschen > wrote: > > Comparing the straces, two interesting facts are conspicuous: > > - After the forked script returned, what happens in the parent is absol= utly > > identical in both cases, up to a point during exit. This point is re= ached > > with line 1573 in the "bad" case and line 1580 in the "good" case. T= hen > > "something" happens: > > >=20 > Thanks for the analysis, this does help us realized it should be a > very low level issue, in a level I wasn't doubt about. > [...] > > To me this looks like the "bad" script has been exited forcefully > > for some reason. > > >=20 > Yeah, this is the hard part. Sebastian has some progress on it, I > quote his note here: >=20 > =3D=3D=3D quote =3D=3D=3D >=20 > Cygwin tries to forcibly kill a thread, the implementation for that is > available here: > https://github.com/Alexpux/Cygwin/blob/79511853f788111efd975651f87eabbd4a= 8cbf6d/winsup/cygwin/cygthread.cc#L296 Guys, no offense meant, but I'd really appreciate if you could peruse and refer to the original upstream Cygwin repo at https://sourceware.org/git/?p=3Dnewlib-cygwin.git This is what we're talking about in the first place so I'd like to stick to this, ok? > Excerpt from the log with annotations: >=20 > --- snip --- > 0027:Call KERNEL32.TerminateThread(00000168,00000000) ret=3D610055ca > 0027: terminate_thread( handle=3D0168, exit_code=3D0 ) > 0027: terminate_thread() =3D 0 { self=3D0, last=3D0 } > 0027:Ret KERNEL32.TerminateThread() retval=3D00000001 ret=3D610055ca > // handle 00000168 corresponds to thread 0x0029 >=20 > 0027:Call KERNEL32.WaitForSingleObject(00000168,ffffffff) ret=3D610055e0 > 0027: select( flags=3D2, cookie=3D0060ba6c, timeout=3Dinfinite, > prev_apc=3D0000, result=3D{}, data=3D{WAIT,handles=3D{0168}} ) > 0027: select() =3D 0 { timeout=3Dinfinite, call=3D{APC_NONE}, apc_handle= =3D0000 } > 0027:Ret KERNEL32.WaitForSingleObject() retval=3D00000000 ret=3D610055e0 > // WaitForSingleObject doesn't block, so cygwin assumes the thread is gone >=20 > [...] >=20 > 0027:Call KERNEL32.VirtualFree(00a10000,00000000,00008000) ret=3D61005767 > // Cygwin tries to release the thread stack Ah, ok. What OS does Wine emulate here? Have a look at https://sourceware.org/git/?p=3Dnewlib-cygwin.git;a=3Dblob;f=3Dwinsup/cygwi= n/cygthread.cc;h=3De48a73e545e7ca90884fc891f1b188e0ab3bf863;hb=3DHEAD#l316 The terminate_thread_frees_stack flag is set to false for XP/2003 and to true for any newer OS. I guess this is a double-free because Wine's TerminateThread already freed the stack and Cygwin got the info it's supposedly running under XP/2003, so it tries to workaround the fact that TerminateThread on these systems didn't free the stack by themselves. > As a workaround NtFreeVirtualMemory can be replaced with a no-op > implementation returning STATUS_SUCCESS. I don't think this is the right thing to do. It's a hack covering the problem that TerminateThread should not free the thread stack if we're running an XP/2003 emulation. If my assumption here is incorrect, we need to know what address ret=3D61005767 is refering to. addr2line would help. Corinna --=20 Corinna Vinschen Please, send mails regarding Cygwin to Cygwin Maintainer cygwin AT cygwin DOT com Red Hat --CdrF4e02JqNVZeln Content-Type: application/pgp-signature Content-length: 819 -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBCAAGBQJV7YL0AAoJEPU2Bp2uRE+gwEUQAIBR1UhBUtLQTuqeBEox0uVS NVnqJ7N5/dw08XqkUSuuDjlVl5R8TU2fqafagCgNyLPiEUw98hu/um68X9tzK+Jq 8qJgjutqqOFcqQGSvxgLFt0w2XyK3WnRzFG40sqiyEu2b397nYpAprTCeN7XbgdC b8SPWn0ux/0Ow8wbHGSqUDi2+iMeCiG94Tgtt2yK/piRaeAgKEYpPwzm+JWCfNmd I9LdYaWH7pzc2sSB3mxk9XTkiPjIH5dfqrKv2Z1ShhkRF4Sa/CRT1+d0DYUei44Q RJ636Bys/dUSBxnKk9ckFc/BmRquB3ypzhfuRuJGMlfYxRE2AfnQXMVt/9ebZdjo wxyOGD1LB+H8sWknnnq6a605cdEmaCr2De7SNfMLUNMhKj7pfiLP5aOfGOaWd/h4 y92m/oMt06/c0lTHSMZNX1wLpYb01FfOj674w3Kyzp10L3qUU2GiQXNDRHGIzWgJ 8IZ59hs9HAPIquVCEOcusONp4M7Yit/uCw6KOK0ckyOGYUz/4d72LuzRm2s7w1ve yQsKH6N6xCPe3ASRHU9l+B4fpJ2/Tw8r/rMmgPf+qh+3mf1eAB/Ta+IiQ05RI5ly //53BkI8JTA0Y0euIUwxC+/0+3ej1e+Hqof6ylCcKPgjawH5PUoWVTvpmDAtM++1 FyjaBHES+/GhW+fNZRnE =hAT3 -----END PGP SIGNATURE----- --CdrF4e02JqNVZeln--