[PATCH] Cygwin: pipe: Give up to use query_hdl for non-cygwin apps.

Johannes Schindelin Johannes.Schindelin@gmx.de
Sun Mar 3 09:34:44 GMT 2024


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
>
>


More information about the Cygwin-patches mailing list