public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Qian Hong <fracting@gmail.com>
To: cygwin <cygwin@cygwin.com>
Subject: Re: [OT] Wine + Cygwin: `script -e` exit status forwarding randomly return zero for non zero child process
Date: Mon, 07 Sep 2015 17:14:00 -0000	[thread overview]
Message-ID: <CALd+sZRDYi59XmupJJdr_oK=qUcnKwnG+kPJC8hJVWu_cC2vig@mail.gmail.com> (raw)
In-Reply-To: <20150907122836.GB20288@calimero.vinschen.de>

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

  reply	other threads:[~2015-09-07 17:14 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-02 14:28 Qian Hong
2015-09-02 17:04 ` Qian Hong
2015-09-03 10:55 ` Corinna Vinschen
2015-09-07 11:03   ` Qian Hong
2015-09-07 12:28     ` Corinna Vinschen
2015-09-07 17:14       ` Qian Hong [this message]
2015-09-08  8:30         ` Corinna Vinschen
2015-10-21  4:50           ` Qian Hong
2015-10-21  8:18             ` Corinna Vinschen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CALd+sZRDYi59XmupJJdr_oK=qUcnKwnG+kPJC8hJVWu_cC2vig@mail.gmail.com' \
    --to=fracting@gmail.com \
    --cc=cygwin@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).