From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 59081 invoked by alias); 7 Sep 2015 17:14:44 -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 59059 invoked by uid 89); 7 Sep 2015 17:14:41 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=0.4 required=5.0 tests=AWL,BAYES_50,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-wi0-f174.google.com Received: from mail-wi0-f174.google.com (HELO mail-wi0-f174.google.com) (209.85.212.174) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Mon, 07 Sep 2015 17:14:40 +0000 Received: by wicfx3 with SMTP id fx3so90042161wic.0 for ; Mon, 07 Sep 2015 10:14:37 -0700 (PDT) X-Received: by 10.194.87.69 with SMTP id v5mr36561235wjz.140.1441646077115; Mon, 07 Sep 2015 10:14:37 -0700 (PDT) MIME-Version: 1.0 Received: by 10.28.144.196 with HTTP; Mon, 7 Sep 2015 10:13:57 -0700 (PDT) Reply-To: fracting@gmail.com In-Reply-To: <20150907122836.GB20288@calimero.vinschen.de> References: <20150903105549.GT23669@calimero.vinschen.de> <20150907122836.GB20288@calimero.vinschen.de> From: Qian Hong Date: Mon, 07 Sep 2015 17:14:00 -0000 Message-ID: Subject: Re: [OT] Wine + Cygwin: `script -e` exit status forwarding randomly return zero for non zero child process To: cygwin Content-Type: text/plain; charset=UTF-8 X-IsSubscribed: yes X-SW-Source: 2015-09/txt/msg00114.txt.bz2 Hi Corinna, Thanks again for the quick reply. On Mon, Sep 7, 2015 at 8:28 PM, Corinna Vinschen wrote: > 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=newlib-cygwin.git > > This is what we're talking about in the first place so I'd like to stick > to this, ok? Oops, I'm so sorry, it's my mistake, it was just a lazy copy&paste from bugzilla, not on purpose, won't happen again. Thanks for reminder. > Ah, ok. What OS does Wine emulate here? Have a look at > https://sourceware.org/git/?p=newlib-cygwin.git;a=blob;f=winsup/cygwin/cygthread.cc;h=e48a73e545e7ca90884fc891f1b188e0ab3bf863;hb=HEAD#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. > Wine emulates Windows XP here, I double checked Wine source code and I can confirm Wine doesn't free the stack: NtTerminateThread() -> abort_thread() -> terminate_thread() https://github.com/wine-compholio/wine-patched/blob/8b3a785e97a7e28ff58731b58d19237a59239acc/dlls/ntdll/thread.c#L369 Cygwin reports wincap as wincap_xpsp2 which is also correct here. > we need to know what address ret=61005767 is refering to. addr2line would help. As you point out, ret=61005767 is the call to VirtualFree() inside cygthread::terminate_thread () https://sourceware.org/git/?p=newlib-cygwin.git;a=blob;f=winsup/cygwin/cygthread.cc;h=e48a73e545e7ca90884fc891f1b188e0ab3bf863;hb=HEAD#l324 After combine the information we have so far, I think the problem is clear now. It's not Cygwin's fault, it's Wine's fault. Wine's WaitForSingleObject() needs to wait long enough after the TerminateThread() call, so the target thread has enough time to finish the system cleanup and return correct exit_code before Cygwin call VirtualFree to free the stack. But in our current implementation Wine's WaitForSingleObject returns too early, it shouldn't return before the system thread cleanup done, as a result there is a race here. We are thinking of a solution in Wine. Thanks again for the great help! -- Regards, Qian Hong - http://www.winehq.org -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple