X-Recipient: archive-cygwin@delorie.com
DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id
	:list-unsubscribe:list-subscribe:list-archive:list-post
	:list-help:sender:mime-version:reply-to:in-reply-to:references
	:from:date:message-id:subject:to:content-type; q=dns; s=default; b=
	iwuW4ru40rLqBrTJQlEGMnRh2rjm7Rda51jOulzd9LMBcat4sEebKIm0XV6OXZx/
	0hIf3lfPWNcsyRmW/0zXyMY3XCIITRvqbRhI6PUnGAn8kAOZVUEwCY3IdhwGsRPb
	HH0zF6LkzlBecgDeWQvdhQMbxdPtk2hychhmU9z1qCs=
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id
	:list-unsubscribe:list-subscribe:list-archive:list-post
	:list-help:sender:mime-version:reply-to:in-reply-to:references
	:from:date:message-id:subject:to:content-type; s=default; bh=jw5
	hhWlL7men7rKai8eL/fXNB4M=; b=rXL/XDRZSho5Hw8yRQBlqf0MGzg03dmKGKw
	C7r8vttdDHfwi3pxEMm18E02sJhZ3nJeIQVm/k54ZK+49m1d1ioOu66CbkeqeEDn
	5xggrJ9EJjwgu7ic9hLGCHia/K4jV8DuYasLi0T+rTXc1ftKbaUtGfgCqk/udLak
	HChNZSp0=
Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe@cygwin.com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-help@cygwin.com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner@cygwin.com
Mail-Followup-To: cygwin@cygwin.com
Delivered-To: mailing list cygwin@cygwin.com
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
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
Reply-To: fracting@gmail.com
In-Reply-To: <20150907122836.GB20288@calimero.vinschen.de>
References: <CALd+sZS6eHn8tUxCzB-JhGkfn2FUzg5dNKHwcY+ryBT-o=2DFw@mail.gmail.com> <20150903105549.GT23669@calimero.vinschen.de> <CALd+sZRO9LbvQcQZ4PVf9Ge1e5Gu0kKTQkucm=YC68ENdkNNAA@mail.gmail.com> <20150907122836.GB20288@calimero.vinschen.de>
From: Qian Hong <fracting@gmail.com>
Date: Tue, 8 Sep 2015 01:13:57 +0800
Message-ID: <CALd+sZRDYi59XmupJJdr_oK=qUcnKwnG+kPJC8hJVWu_cC2vig@mail.gmail.com>
Subject: Re: [OT] Wine + Cygwin: `script -e` exit status forwarding randomly return zero for non zero child process
To: cygwin <cygwin@cygwin.com>
Content-Type: text/plain; charset=UTF-8
X-IsSubscribed: yes

Hi Corinna,

Thanks again for the quick reply.

On Mon, Sep 7, 2015 at 8:28 PM, Corinna Vinschen
<corinna-cygwin@cygwin.com> 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

