public inbox for cygwin-patches@cygwin.com
 help / color / mirror / Atom feed
From: Johannes Schindelin <Johannes.Schindelin@gmx.de>
To: Takashi Yano <takashi.yano@nifty.ne.jp>
Cc: cygwin-patches@cygwin.com,
	Takashi Yano <takashi.yano@nifty.ne.jp>,
	 Johannes Schindelin <Johannes.Schindelin@gmx.de>
Subject: Re: [PATCH] Cygwin: pipe: Give up to use query_hdl for non-cygwin apps.
Date: Sun, 3 Mar 2024 10:34:44 +0100 (CET)	[thread overview]
Message-ID: <b0bd6b96-5bd8-7f4e-71ff-4552e5ac1cb5@gmx.de> (raw)
In-Reply-To: <20240303050915.2024-1-takashi.yano@nifty.ne.jp>

Hi Takashi,

thank you for the fix! I can confirm that it addresses the problem
demonstrated by the reproducer in that MSYS2-runtime ticket.

After noticing that we enumerate all the processes (which is an expensive
operation) just to skip all of the non-Cygwin ones anyway, I wonder if it
wouldn't be smarter to go through the internal list of cygpids and take it
from there, skipping the `SystemProcessInformation` calls altogether.

Ciao,
Johannes

On Sun, 3 Mar 2024, Takashi Yano wrote:

> Non-cygwin app may call ReadFile() which makes NtQueryObject() for
> ObjectNameInformation block in fhandler_pipe::get_query_hdl_per_process.
> Therefore, stop to try to get query_hdl for non-cygwin apps.
>
> Addresses: https://github.com/msys2/msys2-runtime/issues/202
>
> Fixes: b531d6b06eeb ("Cygwin: pipe: Introduce temporary query_hdl.")
> Reported-by: Alisa Sireneva, Johannes Schindelin <Johannes.Schindelin@gmx.de>
> Reviewed-by:
> Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
> ---
>  winsup/cygwin/fhandler/pipe.cc | 10 ++++++++++
>  winsup/cygwin/release/3.5.2    |  4 ++++
>  2 files changed, 14 insertions(+)
>
> diff --git a/winsup/cygwin/fhandler/pipe.cc b/winsup/cygwin/fhandler/pipe.cc
> index 1a97108b5..95c2f843a 100644
> --- a/winsup/cygwin/fhandler/pipe.cc
> +++ b/winsup/cygwin/fhandler/pipe.cc
> @@ -1241,6 +1241,16 @@ fhandler_pipe::get_query_hdl_per_process (WCHAR *name,
>
>    for (LONG i = (LONG) n_process - 1; i >= 0; i--)
>      {
> +      /* Non-cygwin app may call ReadFile() which makes NtQueryObject()
> +	for ObjectNameInformation block. Therefore, stop to try to get
> +	query_hdl for non-cygwin apps. */
> +      pid_t cygpid;
> +      if (!(cygpid = cygwin_pid (proc_pids[i])))
> +	continue;
> +      pinfo p (cygpid);
> +      if (p && ISSTATE (p, PID_NOTCYGWIN))
> +	continue;
> +
>        HANDLE proc = OpenProcess (PROCESS_DUP_HANDLE
>  				 | PROCESS_QUERY_INFORMATION,
>  				 0, proc_pids[i]);
> diff --git a/winsup/cygwin/release/3.5.2 b/winsup/cygwin/release/3.5.2
> index 7d8df9489..efd30b64a 100644
> --- a/winsup/cygwin/release/3.5.2
> +++ b/winsup/cygwin/release/3.5.2
> @@ -5,3 +5,7 @@ Fixes:
>    is already unmapped due to race condition. To avoid this issue,
>    shared console memory will be kept mapped if it belongs to CTTY.
>    Addresses:  https://cygwin.com/pipermail/cygwin/2024-February/255561.html
> +
> +- Fix a problem that select() call for write-side of a pipe possibly
> +  hangs with non-cygwin reader.
> +  Addresses: https://github.com/msys2/msys2-runtime/issues/202
> --
> 2.43.0
>
>

  reply	other threads:[~2024-03-03  9:34 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-03  5:09 Takashi Yano
2024-03-03  9:34 ` Johannes Schindelin [this message]
2024-03-03 10:21   ` Takashi Yano
2024-03-03 10:39     ` ASSI
2024-03-03 11:36       ` Takashi Yano
2024-03-04 10:34         ` Corinna Vinschen
2024-03-04 15:45           ` ASSI
2024-03-04 17:38             ` Corinna Vinschen
2024-03-05  0:06               ` Takashi Yano
2024-03-05 10:14                 ` Corinna Vinschen
2024-03-05 14:47                   ` Takashi Yano
2024-03-05 16:54                     ` Corinna Vinschen
2024-03-05 18:42                       ` Takashi Yano
2024-03-05 18:46                         ` Takashi Yano
2024-03-06 12:54                         ` 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=b0bd6b96-5bd8-7f4e-71ff-4552e5ac1cb5@gmx.de \
    --to=johannes.schindelin@gmx.de \
    --cc=cygwin-patches@cygwin.com \
    --cc=takashi.yano@nifty.ne.jp \
    /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).