Skip to content

Commit c101fa5

Browse files
authored
Merge pull request #180 from git-for-windows/msys2-runtime-4eb0db98443ea3a75714d1046d775fa054b15045
msys2-runtime: update to 4eb0db98443ea3a75714d1046d775fa054b15045
2 parents 7c6ae21 + 93bd915 commit c101fa5

7 files changed

+410
-6
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
From 7793231f24aa7060214862852c09c7eb9c3cbdd2 Mon Sep 17 00:00:00 2001
2+
From: Christoph Reiter <[email protected]>
3+
Date: Sat, 10 Feb 2024 08:31:55 +0100
4+
Subject: [PATCH 75/N] pathconv: don't skip arguments with double quote
5+
6+
It is used to pass strings/paths to the preprocessor and breaks
7+
for example the CPython build. For example -DPREFIX='"/ucrt64"'.
8+
9+
Fixes msys2/msys2-runtime/#190
10+
11+
Signed-off-by: Johannes Schindelin <[email protected]>
12+
---
13+
winsup/cygwin/msys2_path_conv.cc | 1 -
14+
1 file changed, 1 deletion(-)
15+
16+
diff --git a/winsup/cygwin/msys2_path_conv.cc b/winsup/cygwin/msys2_path_conv.cc
17+
index 133939a..1c60bf3 100644
18+
--- a/winsup/cygwin/msys2_path_conv.cc
19+
+++ b/winsup/cygwin/msys2_path_conv.cc
20+
@@ -366,7 +366,6 @@ skip_p2w:
21+
switch (*it) {
22+
case '`':
23+
case '\'':
24+
- case '"':
25+
case '*':
26+
case '?':
27+
case '[':
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
From fdc7c9a039aab6001d74e9463decd45710d6798f Mon Sep 17 00:00:00 2001
2+
From: Takashi Yano <[email protected]>
3+
Date: Fri, 2 Feb 2024 13:59:19 +0900
4+
Subject: [PATCH 76/N] Cygwin: console: Fix exit code for non-cygwin process.
5+
6+
If non-cygwin process is executed in console, the exit code is not
7+
set correctly. This is because the stub process for non-cygwin app
8+
crashes in fhandler_console::set_disable_master_thread() due to NULL
9+
pointer dereference. This bug was introduced by the commit:
10+
3721a756b0d8 ("Cygwin: console: Make the console accessible from
11+
other terminals."), that the pointer cons is accessed before fixing
12+
when it is NULL. This patch fixes the issue.
13+
14+
Backported-from: aa73e11524 (Cygwin: console: Fix exit code for non-cygwin process., 2024-02-02)
15+
Fixes: 3721a756b0d8 ("Cygwin: console: Make the console accessible from other terminals.")
16+
Reported-by: Johannes Schindelin <[email protected]>
17+
Signed-off-by: Takashi Yano <[email protected]>
18+
Signed-off-by: Johannes Schindelin <[email protected]>
19+
---
20+
winsup/cygwin/fhandler/console.cc | 4 ++--
21+
1 file changed, 2 insertions(+), 2 deletions(-)
22+
23+
diff --git a/winsup/cygwin/fhandler/console.cc b/winsup/cygwin/fhandler/console.cc
24+
index 1fe72fc..edcc484 100644
25+
--- a/winsup/cygwin/fhandler/console.cc
26+
+++ b/winsup/cygwin/fhandler/console.cc
27+
@@ -4344,8 +4344,6 @@ fhandler_console::need_console_handler ()
28+
void
29+
fhandler_console::set_disable_master_thread (bool x, fhandler_console *cons)
30+
{
31+
- if (con.disable_master_thread == x)
32+
- return;
33+
if (cons == NULL)
34+
{
35+
if (cygheap->ctty && cygheap->ctty->get_major () == DEV_CONS_MAJOR)
36+
@@ -4353,6 +4351,8 @@ fhandler_console::set_disable_master_thread (bool x, fhandler_console *cons)
37+
else
38+
return;
39+
}
40+
+ if (con.disable_master_thread == x)
41+
+ return;
42+
cons->acquire_input_mutex (mutex_timeout);
43+
con.disable_master_thread = x;
44+
cons->release_input_mutex ();
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
From d52d8f79398e5605f1224de14ea4bef0841a7f8e Mon Sep 17 00:00:00 2001
2+
From: Takashi Yano <[email protected]>
3+
Date: Sat, 3 Feb 2024 00:54:23 +0900
4+
Subject: [PATCH 77/N] Cygwin: console: Avoid slipping past
5+
disable_master_thread check.
6+
7+
If disable_master_thread flag is set between the code checking that
8+
flag not be set and the code acquiring input_mutex, input record is
9+
processed once after setting disable_master_thread flag. This patch
10+
prevents that.
11+
12+
Backported-from: 9bcfd06045 (Cygwin: console: Avoid slipping past disable_master_thread check., 2024-02-03)
13+
Fixes: d4aacd50e6cf ("Cygwin: console: Add missing input_mutex guard.")
14+
Signed-off-by: Takashi Yano <[email protected]>
15+
Signed-off-by: Johannes Schindelin <[email protected]>
16+
---
17+
winsup/cygwin/fhandler/console.cc | 2 --
18+
1 file changed, 2 deletions(-)
19+
20+
diff --git a/winsup/cygwin/fhandler/console.cc b/winsup/cygwin/fhandler/console.cc
21+
index edcc484..f9a6946 100644
22+
--- a/winsup/cygwin/fhandler/console.cc
23+
+++ b/winsup/cygwin/fhandler/console.cc
24+
@@ -4351,8 +4351,6 @@ fhandler_console::set_disable_master_thread (bool x, fhandler_console *cons)
25+
else
26+
return;
27+
}
28+
- if (con.disable_master_thread == x)
29+
- return;
30+
cons->acquire_input_mutex (mutex_timeout);
31+
con.disable_master_thread = x;
32+
cons->release_input_mutex ();
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
From a4bd6e9733cf85914843ad7ea7e9f54417dce9fb Mon Sep 17 00:00:00 2001
2+
From: Takashi Yano <[email protected]>
3+
Date: Sun, 3 Mar 2024 13:44:17 +0900
4+
Subject: [PATCH 78/N] Cygwin: pipe: Give up to use query_hdl for non-cygwin
5+
apps.
6+
7+
Non-cygwin app may call ReadFile() for empty pipe, which makes
8+
NtQueryObject() for ObjectNameInformation block in fhandler_pipe::
9+
get_query_hdl_per_process. Therefore, do not to try to get query_hdl
10+
for non-cygwin apps.
11+
12+
Addresses: https://github.com/msys2/msys2-runtime/issues/202
13+
14+
Backported-from: f6be372ace (Cygwin: pipe: Give up to use query_hdl for non-cygwin apps., 2024-03-03)
15+
Fixes: b531d6b06eeb ("Cygwin: pipe: Introduce temporary query_hdl.")
16+
Reported-by: Alisa Sireneva, Johannes Schindelin <[email protected]>
17+
Reviewed-by: Corinna Vinschen <[email protected]>
18+
Signed-off-by: Takashi Yano <[email protected]>
19+
Signed-off-by: Johannes Schindelin <[email protected]>
20+
---
21+
winsup/cygwin/fhandler/pipe.cc | 57 ++++++++--------------------------
22+
1 file changed, 13 insertions(+), 44 deletions(-)
23+
24+
diff --git a/winsup/cygwin/fhandler/pipe.cc b/winsup/cygwin/fhandler/pipe.cc
25+
index 283319c..05b1625 100644
26+
--- a/winsup/cygwin/fhandler/pipe.cc
27+
+++ b/winsup/cygwin/fhandler/pipe.cc
28+
@@ -1207,53 +1207,24 @@ HANDLE
29+
fhandler_pipe::get_query_hdl_per_process (WCHAR *name,
30+
OBJECT_NAME_INFORMATION *ntfn)
31+
{
32+
- NTSTATUS status;
33+
- ULONG len;
34+
- DWORD n_process = 256;
35+
- PSYSTEM_PROCESS_INFORMATION spi;
36+
- do
37+
- { /* Enumerate processes */
38+
- DWORD nbytes = n_process * sizeof (SYSTEM_PROCESS_INFORMATION);
39+
- spi = (PSYSTEM_PROCESS_INFORMATION) HeapAlloc (GetProcessHeap (),
40+
- 0, nbytes);
41+
- if (!spi)
42+
- return NULL;
43+
- status = NtQuerySystemInformation (SystemProcessInformation,
44+
- spi, nbytes, &len);
45+
- if (NT_SUCCESS (status))
46+
- break;
47+
- HeapFree (GetProcessHeap (), 0, spi);
48+
- n_process *= 2;
49+
- }
50+
- while (n_process < (1L<<20) && status == STATUS_INFO_LENGTH_MISMATCH);
51+
- if (!NT_SUCCESS (status))
52+
- return NULL;
53+
+ winpids pids ((DWORD) 0);
54+
55+
- /* In most cases, it is faster to check the processes in reverse order.
56+
- To do this, store PIDs into an array. */
57+
- DWORD *proc_pids = (DWORD *) HeapAlloc (GetProcessHeap (), 0,
58+
- n_process * sizeof (DWORD));
59+
- if (!proc_pids)
60+
+ /* In most cases, it is faster to check the processes in reverse order. */
61+
+ for (LONG i = (LONG) pids.npids - 1; i >= 0; i--)
62+
{
63+
- HeapFree (GetProcessHeap (), 0, spi);
64+
- return NULL;
65+
- }
66+
- PSYSTEM_PROCESS_INFORMATION p = spi;
67+
- n_process = 0;
68+
- while (true)
69+
- {
70+
- proc_pids[n_process++] = (DWORD)(intptr_t) p->UniqueProcessId;
71+
- if (!p->NextEntryOffset)
72+
- break;
73+
- p = (PSYSTEM_PROCESS_INFORMATION) ((char *) p + p->NextEntryOffset);
74+
- }
75+
- HeapFree (GetProcessHeap (), 0, spi);
76+
+ NTSTATUS status;
77+
+ ULONG len;
78+
+
79+
+ /* Non-cygwin app may call ReadFile() for empty pipe, which makes
80+
+ NtQueryObject() for ObjectNameInformation block. Therefore, do
81+
+ not try to get query_hdl for non-cygwin apps. */
82+
+ _pinfo *p = pids[i];
83+
+ if (!p || ISSTATE (p, PID_NOTCYGWIN))
84+
+ continue;
85+
86+
- for (LONG i = (LONG) n_process - 1; i >= 0; i--)
87+
- {
88+
HANDLE proc = OpenProcess (PROCESS_DUP_HANDLE
89+
| PROCESS_QUERY_INFORMATION,
90+
- 0, proc_pids[i]);
91+
+ 0, p->dwProcessId);
92+
if (!proc)
93+
continue;
94+
95+
@@ -1317,7 +1288,6 @@ fhandler_pipe::get_query_hdl_per_process (WCHAR *name,
96+
query_hdl_proc = proc;
97+
query_hdl_value = (HANDLE)(intptr_t) phi->Handles[j].HandleValue;
98+
HeapFree (GetProcessHeap (), 0, phi);
99+
- HeapFree (GetProcessHeap (), 0, proc_pids);
100+
return h;
101+
}
102+
close_handle:
103+
@@ -1327,7 +1297,6 @@ close_handle:
104+
close_proc:
105+
CloseHandle (proc);
106+
}
107+
- HeapFree (GetProcessHeap (), 0, proc_pids);
108+
return NULL;
109+
}
110+
Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
From a4d92d60dc618a2c1207dab20dcd04b4fb7cb541 Mon Sep 17 00:00:00 2001
2+
From: Takashi Yano <[email protected]>
3+
Date: Mon, 11 Mar 2024 22:08:00 +0900
4+
Subject: [PATCH 79/N] Cygwin: pipe: Make sure to set read pipe non-blocking
5+
for cygwin apps.
6+
7+
If pipe reader is a non-cygwin app first, and cygwin process reads
8+
the same pipe after that, the pipe has been set to bclocking mode
9+
for the cygwin app. However, the commit 9e4d308cd592 assumes the
10+
pipe for cygwin process always is non-blocking mode. With this patch,
11+
the pipe mode is reset to non-blocking when cygwin app is started.
12+
13+
Backported-from: 55431b408e (Cygwin: pipe: Make sure to set read pipe non-blocking for cygwin apps., 2024-03-11)
14+
Addresses: https://cygwin.com/pipermail/cygwin/2024-March/255644.html
15+
Fixes: 9e4d308cd592 ("Cygwin: pipe: Adopt FILE_SYNCHRONOUS_IO_NONALERT flag for read pipe.")
16+
Reported-by: wh <[email protected]>
17+
Reviewed-by: Corinna Vinschen <[email protected]>
18+
Signed-off-by: Takashi Yano <[email protected]>
19+
Signed-off-by: Johannes Schindelin <[email protected]>
20+
---
21+
winsup/cygwin/fhandler/pipe.cc | 63 +++++++++++++++++++++++++
22+
winsup/cygwin/local_includes/fhandler.h | 3 ++
23+
winsup/cygwin/spawn.cc | 34 +------------
24+
3 files changed, 68 insertions(+), 32 deletions(-)
25+
26+
diff --git a/winsup/cygwin/fhandler/pipe.cc b/winsup/cygwin/fhandler/pipe.cc
27+
index 05b1625..8daae8d 100644
28+
--- a/winsup/cygwin/fhandler/pipe.cc
29+
+++ b/winsup/cygwin/fhandler/pipe.cc
30+
@@ -18,6 +18,7 @@ details. */
31+
#include "pinfo.h"
32+
#include "shared_info.h"
33+
#include "tls_pbuf.h"
34+
+#include "sigproc.h"
35+
#include <assert.h>
36+
37+
/* This is only to be used for writing. When reading,
38+
@@ -587,6 +588,17 @@ fhandler_pipe::fixup_after_fork (HANDLE parent)
39+
ReleaseMutex (hdl_cnt_mtx);
40+
}
41+
42+
+void
43+
+fhandler_pipe::fixup_after_exec ()
44+
+{
45+
+ /* Set read pipe itself always non-blocking for cygwin process.
46+
+ Blocking/non-blocking is simulated in raw_read(). For write
47+
+ pipe, follow is_nonblocking(). */
48+
+ bool mode = get_device () == FH_PIPEW ? is_nonblocking () : true;
49+
+ set_pipe_non_blocking (mode);
50+
+ fhandler_base::fixup_after_exec ();
51+
+}
52+
+
53+
int
54+
fhandler_pipe::dup (fhandler_base *child, int flags)
55+
{
56+
@@ -1370,3 +1382,54 @@ close_proc:
57+
HeapFree (GetProcessHeap (), 0, shi);
58+
return NULL;
59+
}
60+
+
61+
+void
62+
+fhandler_pipe::spawn_worker (int fileno_stdin, int fileno_stdout,
63+
+ int fileno_stderr)
64+
+{
65+
+ bool need_send_noncygchld_sig = false;
66+
+
67+
+ /* spawn_worker() is called from spawn.cc only when non-cygwin app
68+
+ is started. Set pipe mode blocking for the non-cygwin process. */
69+
+ int fd;
70+
+ cygheap_fdenum cfd (false);
71+
+ while ((fd = cfd.next ()) >= 0)
72+
+ if (cfd->get_dev () == FH_PIPEW
73+
+ && (fd == fileno_stdout || fd == fileno_stderr))
74+
+ {
75+
+ fhandler_pipe *pipe = (fhandler_pipe *)(fhandler_base *) cfd;
76+
+ pipe->set_pipe_non_blocking (false);
77+
+
78+
+ /* Setup for query_ndl stuff. Read the comment below. */
79+
+ if (pipe->request_close_query_hdl ())
80+
+ need_send_noncygchld_sig = true;
81+
+ }
82+
+ else if (cfd->get_dev () == FH_PIPER && fd == fileno_stdin)
83+
+ {
84+
+ fhandler_pipe *pipe = (fhandler_pipe *)(fhandler_base *) cfd;
85+
+ pipe->set_pipe_non_blocking (false);
86+
+ }
87+
+
88+
+ /* If multiple writers including non-cygwin app exist, the non-cygwin
89+
+ app cannot detect pipe closure on the read side when the pipe is
90+
+ created by system account or the pipe creator is running as service.
91+
+ This is because query_hdl which is held in write side also is a read
92+
+ end of the pipe, so the pipe is still alive for the non-cygwin app
93+
+ even after the reader is closed.
94+
+
95+
+ To avoid this problem, let all processes in the same process
96+
+ group close query_hdl using internal signal __SIGNONCYGCHLD when
97+
+ non-cygwin app is started. */
98+
+ if (need_send_noncygchld_sig)
99+
+ {
100+
+ tty_min dummy_tty;
101+
+ dummy_tty.ntty = (fh_devices) myself->ctty;
102+
+ dummy_tty.pgid = myself->pgid;
103+
+ tty_min *t = cygwin_shared->tty.get_cttyp ();
104+
+ if (!t) /* If tty is not allocated, use dummy_tty instead. */
105+
+ t = &dummy_tty;
106+
+ /* Emit __SIGNONCYGCHLD to let all processes in the
107+
+ process group close query_hdl. */
108+
+ t->kill_pgrp (__SIGNONCYGCHLD);
109+
+ }
110+
+}
111+
diff --git a/winsup/cygwin/local_includes/fhandler.h b/winsup/cygwin/local_includes/fhandler.h
112+
index 649a431..15b19f7 100644
113+
--- a/winsup/cygwin/local_includes/fhandler.h
114+
+++ b/winsup/cygwin/local_includes/fhandler.h
115+
@@ -1212,6 +1212,7 @@ public:
116+
int open (int flags, mode_t mode = 0);
117+
bool open_setup (int flags);
118+
void fixup_after_fork (HANDLE);
119+
+ void fixup_after_exec ();
120+
int dup (fhandler_base *child, int);
121+
void set_close_on_exec (bool val);
122+
int close ();
123+
@@ -1273,6 +1274,8 @@ public:
124+
}
125+
return false;
126+
}
127+
+ static void spawn_worker (int fileno_stdin, int fileno_stdout,
128+
+ int fileno_stderr);
129+
};
130+
131+
#define CYGWIN_FIFO_PIPE_NAME_LEN 47
132+
diff --git a/winsup/cygwin/spawn.cc b/winsup/cygwin/spawn.cc
133+
index 383f5e5..acdef49 100644
134+
--- a/winsup/cygwin/spawn.cc
135+
+++ b/winsup/cygwin/spawn.cc
136+
@@ -607,38 +607,8 @@ child_info_spawn::worker (const char *prog_arg, const char *const *argv,
137+
int fileno_stderr = 2;
138+
139+
if (!iscygwin ())
140+
- {
141+
- bool need_send_sig = false;
142+
- int fd;
143+
- cygheap_fdenum cfd (false);
144+
- while ((fd = cfd.next ()) >= 0)
145+
- if (cfd->get_dev () == FH_PIPEW
146+
- && (fd == fileno_stdout || fd == fileno_stderr))
147+
- {
148+
- fhandler_pipe *pipe = (fhandler_pipe *)(fhandler_base *) cfd;
149+
- pipe->set_pipe_non_blocking (false);
150+
- if (pipe->request_close_query_hdl ())
151+
- need_send_sig = true;
152+
- }
153+
- else if (cfd->get_dev () == FH_PIPER && fd == fileno_stdin)
154+
- {
155+
- fhandler_pipe *pipe = (fhandler_pipe *)(fhandler_base *) cfd;
156+
- pipe->set_pipe_non_blocking (false);
157+
- }
158+
-
159+
- if (need_send_sig)
160+
- {
161+
- tty_min dummy_tty;
162+
- dummy_tty.ntty = (fh_devices) myself->ctty;
163+
- dummy_tty.pgid = myself->pgid;
164+
- tty_min *t = cygwin_shared->tty.get_cttyp ();
165+
- if (!t) /* If tty is not allocated, use dummy_tty instead. */
166+
- t = &dummy_tty;
167+
- /* Emit __SIGNONCYGCHLD to let all processes in the
168+
- process group close query_hdl. */
169+
- t->kill_pgrp (__SIGNONCYGCHLD);
170+
- }
171+
- }
172+
+ fhandler_pipe::spawn_worker (fileno_stdin, fileno_stdout,
173+
+ fileno_stderr);
174+
175+
bool no_pcon = mode != _P_OVERLAY && mode != _P_WAIT;
176+
term_spawn_worker.setup (iscygwin (), handle (fileno_stdin, false),

0 commit comments

Comments
 (0)