public inbox for cygwin-patches@cygwin.com
 help / color / mirror / Atom feed
* [PATCH] Cygwin: pipe: Give up to use query_hdl for non-cygwin apps.
@ 2024-03-03  5:09 Takashi Yano
  2024-03-03  9:34 ` Johannes Schindelin
  0 siblings, 1 reply; 15+ messages in thread
From: Takashi Yano @ 2024-03-03  5:09 UTC (permalink / raw)
  To: cygwin-patches; +Cc: Takashi Yano, Alisa, Sireneva, Johannes Schindelin

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


^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2024-03-06 12:54 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-03  5:09 [PATCH] Cygwin: pipe: Give up to use query_hdl for non-cygwin apps Takashi Yano
2024-03-03  9:34 ` Johannes Schindelin
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

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