delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2015/09/07/13:15:01

X-Recipient: archive-cygwin AT delorie DOT 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 AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT 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 AT gmail DOT com
In-Reply-To: <20150907122836.GB20288@calimero.vinschen.de>
References: <CALd+sZS6eHn8tUxCzB-JhGkfn2FUzg5dNKHwcY+ryBT-o=2DFw AT mail DOT gmail DOT com> <20150903105549 DOT GT23669 AT calimero DOT vinschen DOT de> <CALd+sZRO9LbvQcQZ4PVf9Ge1e5Gu0kKTQkucm=YC68ENdkNNAA AT mail DOT gmail DOT com> <20150907122836 DOT GB20288 AT calimero DOT vinschen DOT de>
From: Qian Hong <fracting AT gmail DOT 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 AT cygwin DOT com>
X-IsSubscribed: yes

Hi Corinna,

Thanks again for the quick reply.

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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019