public inbox for cygwin-patches@cygwin.com
 help / color / mirror / Atom feed
From: Corinna Vinschen <corinna-cygwin@cygwin.com>
To: cygwin-patches@cygwin.com
Subject: Re: [PATCH 0/2] Testsuite adjustment and relevant fix
Date: Thu, 20 Jul 2023 17:17:51 +0200	[thread overview]
Message-ID: <ZLlQH47+AXD+YcMU@calimero.vinschen.de> (raw)
In-Reply-To: <ZLlPVSe3UyZ1tjXT@calimero.vinschen.de>

On Jul 20 17:14, Corinna Vinschen wrote:
> On Jul 20 13:55, Jon Turney wrote:
> > On 19/07/2023 16:33, Corinna Vinschen wrote:
> > > On Jul 19 13:41, Jon Turney wrote:
> > > > [1/2] has the side effect of flipping test stat06 from working to failing.
> > > > [2/2] fixes that
> > > > 
> > > > When run with TDIRECTORY set, libltp just uses that directory and assumes
> > > > something else will clean it up.
> > > > 
> > > > When TDIRECTORY is not set, libltp creates a subdirectory under /tmp, and when
> > > > the test is completed, removes the expected files and verifies that the
> > > > directory is empty.
> > > > 
> > > > stat06 fails that check, because it creates the a file named "file" there, and
> > > > tries stat("file", -1), testing that it returns the expected value EFAULT.
> > > > 
> > > > "file" is removed, but lingers in the STATUS_DELETE_PENDING state until the
> > > > Windows handle which stat_worker() leaks when an exception occurs is closed
> > > > (when the processes exits).
> > > 
> > > Great find. Please push.
> > 
> > So, it seems this doesn't work in an optimized build, as fh is always NULL
> > when we get around to deleting it after a fault.
> > 
> > I'm thinking that I've written this wrong somehow (horses), rather than it
> > being some complex problem with how the optimizer interacts with all the
> > memory and register barriers the exception handling uses (zebras)
> 
> What if you turn around the order instead?
> 
> diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc
> index 73343ecc1f07..32ace4d38943 100644
> --- a/winsup/cygwin/syscalls.cc
> +++ b/winsup/cygwin/syscalls.cc
> @@ -1967,12 +1967,13 @@ stat_worker (path_conv &pc, struct stat *buf)
>  	{
>  	  fhandler_base *fh;
>  
> -	  if (!(fh = build_fh_pc (pc)))
> -	    __leave;
> -
>  	  debug_printf ("(%S, %p, %p), file_attributes %d",
>  			pc.get_nt_native_path (), buf, fh, (DWORD) *fh);
>  	  memset (buf, 0, sizeof (*buf));

Maybe adding a MemoryBarrier() call here if all else fails...

> +
> +	  if (!(fh = build_fh_pc (pc)))
> +	    __leave;
> +
>  	  res = fh->fstat (buf);
>  	  if (!res)
>  	    fh->stat_fixup (buf);

  reply	other threads:[~2023-07-20 15:17 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-19 12:41 Jon Turney
2023-07-19 12:41 ` [PATCH 1/2] Cygwin: testsuite: Drop setting TDIRECTORY Jon Turney
2023-07-19 12:41 ` [PATCH 2/2] Cygwin: Fix Windows file handle leak in stat("file", -1) Jon Turney
2023-07-19 15:33 ` [PATCH 0/2] Testsuite adjustment and relevant fix Corinna Vinschen
2023-07-20 12:55   ` Jon Turney
2023-07-20 15:14     ` Corinna Vinschen
2023-07-20 15:17       ` Corinna Vinschen [this message]
2023-07-21 12:26       ` Jon Turney

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=ZLlQH47+AXD+YcMU@calimero.vinschen.de \
    --to=corinna-cygwin@cygwin.com \
    --cc=cygwin-patches@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).