Skip to content

Commit fa6ee40

Browse files
committed
msys2-runtime: test Takashi's patches
As these are for testing, apply them separately and leave the msys2-runtime PR as a draft for now (msys2/msys2-runtime#253).
1 parent f9fe3ae commit fa6ee40

File tree

4 files changed

+309
-3
lines changed

4 files changed

+309
-3
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
From 7d863074b54b58caa4696515473e986bbb8d1def Mon Sep 17 00:00:00 2001
2+
From: Takashi Yano <[email protected]>
3+
Date: Tue, 21 Jan 2025 12:15:33 +0900
4+
Subject: [PATCH 1001/1003] Revert "Cygwin: signal: Do not handle signal when
5+
__SIGFLUSHFAST is sent"
6+
7+
This reverts commit a22a0ad7c4f0 to apply a new patch for the same
8+
purpose.
9+
10+
Signed-off-by: Takashi Yano <[email protected]>
11+
---
12+
winsup/cygwin/release/3.5.6 | 5 -----
13+
winsup/cygwin/sigproc.cc | 20 +++++---------------
14+
2 files changed, 5 insertions(+), 20 deletions(-)
15+
delete mode 100644 winsup/cygwin/release/3.5.6
16+
17+
diff --git a/winsup/cygwin/release/3.5.6 b/winsup/cygwin/release/3.5.6
18+
deleted file mode 100644
19+
index 643d58e585..0000000000
20+
--- a/winsup/cygwin/release/3.5.6
21+
+++ /dev/null
22+
@@ -1,5 +0,0 @@
23+
-Fixes:
24+
-------
25+
-
26+
-- Fix zsh hang at startup.
27+
- Addresses: https://cygwin.com/pipermail/cygwin/2024-December/256954.html
28+
diff --git a/winsup/cygwin/sigproc.cc b/winsup/cygwin/sigproc.cc
29+
index c2985277fc..cf43aa9335 100644
30+
--- a/winsup/cygwin/sigproc.cc
31+
+++ b/winsup/cygwin/sigproc.cc
32+
@@ -751,14 +751,10 @@ sig_send (_pinfo *p, siginfo_t& si, _cygtls *tls)
33+
res = WriteFile (sendsig, leader, packsize, &nb, NULL);
34+
if (!res || packsize == nb)
35+
break;
36+
- if (cygwait (NULL, 10, cw_sig_eintr) == WAIT_SIGNALED
37+
- && pack.si.si_signo != __SIGFLUSHFAST)
38+
+ if (cygwait (NULL, 10, cw_sig_eintr) == WAIT_SIGNALED)
39+
_my_tls.call_signal_handler ();
40+
res = 0;
41+
}
42+
- /* Re-assert signal_arrived which has been cleared in cygwait(). */
43+
- if (_my_tls.sig)
44+
- _my_tls.set_signal_arrived ();
45+
46+
if (!res)
47+
{
48+
@@ -789,16 +785,7 @@ sig_send (_pinfo *p, siginfo_t& si, _cygtls *tls)
49+
if (wait_for_completion)
50+
{
51+
sigproc_printf ("Waiting for pack.wakeup %p", pack.wakeup);
52+
- do
53+
- {
54+
- rc = cygwait (pack.wakeup, WSSC, cw_sig_eintr);
55+
- if (rc == WAIT_SIGNALED && pack.si.si_signo != __SIGFLUSHFAST)
56+
- _my_tls.call_signal_handler ();
57+
- }
58+
- while (rc != WAIT_OBJECT_0 && rc != WAIT_TIMEOUT);
59+
- /* Re-assert signal_arrived which has been cleared in cygwait(). */
60+
- if (_my_tls.sig)
61+
- _my_tls.set_signal_arrived ();
62+
+ rc = cygwait (pack.wakeup, WSSC);
63+
ForceCloseHandle (pack.wakeup);
64+
}
65+
else
66+
@@ -819,6 +806,9 @@ sig_send (_pinfo *p, siginfo_t& si, _cygtls *tls)
67+
rc = -1;
68+
}
69+
70+
+ if (wait_for_completion && si.si_signo != __SIGFLUSHFAST)
71+
+ _my_tls.call_signal_handler ();
72+
+
73+
out:
74+
if (communing && rc)
75+
{
76+
--
77+
2.47.1.windows.2
78+
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
From 1ee031bc7531a4ab28609c70219304272d3f6aa5 Mon Sep 17 00:00:00 2001
2+
From: Takashi Yano <[email protected]>
3+
Date: Tue, 21 Jan 2025 12:15:34 +0900
4+
Subject: [PATCH 1002/1003] Cygwin: cygwait: Make cygwait() reentrant
5+
6+
To allow cygwait() to be called in the signal handler, a locally
7+
created timer is used instead of _cygtls::locals.cw_timer if it is
8+
in use.
9+
10+
Co-Authored-By: Corinna Vinschen <[email protected]>
11+
Signed-off-by: Takashi Yano <[email protected]>
12+
---
13+
winsup/cygwin/cygtls.cc | 2 ++
14+
winsup/cygwin/cygwait.cc | 22 +++++++++++++++-------
15+
winsup/cygwin/local_includes/cygtls.h | 3 ++-
16+
winsup/cygwin/select.cc | 10 +++++++++-
17+
4 files changed, 28 insertions(+), 9 deletions(-)
18+
19+
diff --git a/winsup/cygwin/cygtls.cc b/winsup/cygwin/cygtls.cc
20+
index afaee8e977..b8b5a01498 100644
21+
--- a/winsup/cygwin/cygtls.cc
22+
+++ b/winsup/cygwin/cygtls.cc
23+
@@ -64,6 +64,7 @@ _cygtls::init_thread (void *x, DWORD (*func) (void *, void *))
24+
initialized = CYGTLS_INITIALIZED;
25+
errno_addr = &(local_clib._errno);
26+
locals.cw_timer = NULL;
27+
+ locals.cw_timer_inuse = false;
28+
locals.pathbufs.clear ();
29+
30+
if ((void *) func == (void *) cygthread::stub
31+
@@ -85,6 +86,7 @@ _cygtls::fixup_after_fork ()
32+
signal_arrived = NULL;
33+
locals.select.sockevt = NULL;
34+
locals.cw_timer = NULL;
35+
+ locals.cw_timer_inuse = false;
36+
locals.pathbufs.clear ();
37+
wq.thread_ev = NULL;
38+
}
39+
diff --git a/winsup/cygwin/cygwait.cc b/winsup/cygwin/cygwait.cc
40+
index dbbe1db6e1..bb653f6b7c 100644
41+
--- a/winsup/cygwin/cygwait.cc
42+
+++ b/winsup/cygwin/cygwait.cc
43+
@@ -58,16 +58,20 @@ cygwait (HANDLE object, PLARGE_INTEGER timeout, unsigned mask)
44+
}
45+
46+
DWORD timeout_n;
47+
+ HANDLE local_timer = NULL;
48+
+ HANDLE &wait_timer =
49+
+ _my_tls.locals.cw_timer_inuse ? local_timer : _my_tls.locals.cw_timer;
50+
if (!timeout)
51+
timeout_n = WAIT_TIMEOUT + 1;
52+
else
53+
{
54+
+ if (!_my_tls.locals.cw_timer_inuse)
55+
+ _my_tls.locals.cw_timer_inuse = true;
56+
timeout_n = WAIT_OBJECT_0 + num++;
57+
- if (!_my_tls.locals.cw_timer)
58+
- NtCreateTimer (&_my_tls.locals.cw_timer, TIMER_ALL_ACCESS, NULL,
59+
- NotificationTimer);
60+
- NtSetTimer (_my_tls.locals.cw_timer, timeout, NULL, NULL, FALSE, 0, NULL);
61+
- wait_objects[timeout_n] = _my_tls.locals.cw_timer;
62+
+ if (!wait_timer)
63+
+ NtCreateTimer (&wait_timer, TIMER_ALL_ACCESS, NULL, NotificationTimer);
64+
+ NtSetTimer (wait_timer, timeout, NULL, NULL, FALSE, 0, NULL);
65+
+ wait_objects[timeout_n] = wait_timer;
66+
}
67+
68+
while (1)
69+
@@ -100,7 +104,7 @@ cygwait (HANDLE object, PLARGE_INTEGER timeout, unsigned mask)
70+
{
71+
TIMER_BASIC_INFORMATION tbi;
72+
73+
- NtQueryTimer (_my_tls.locals.cw_timer, TimerBasicInformation, &tbi,
74+
+ NtQueryTimer (wait_timer, TimerBasicInformation, &tbi,
75+
sizeof tbi, NULL);
76+
/* if timer expired, TimeRemaining is negative and represents the
77+
system uptime when signalled */
78+
@@ -108,7 +112,11 @@ cygwait (HANDLE object, PLARGE_INTEGER timeout, unsigned mask)
79+
timeout->QuadPart = tbi.SignalState || tbi.TimeRemaining.QuadPart < 0LL
80+
? 0LL : tbi.TimeRemaining.QuadPart;
81+
}
82+
- NtCancelTimer (_my_tls.locals.cw_timer, NULL);
83+
+ NtCancelTimer (wait_timer, NULL);
84+
+ if (local_timer)
85+
+ NtClose(local_timer);
86+
+ else
87+
+ _my_tls.locals.cw_timer_inuse = false;
88+
}
89+
90+
if (res == WAIT_CANCELED && is_cw_cancel_self)
91+
diff --git a/winsup/cygwin/local_includes/cygtls.h b/winsup/cygwin/local_includes/cygtls.h
92+
index e4e3889aff..4bd79c36d7 100644
93+
--- a/winsup/cygwin/local_includes/cygtls.h
94+
+++ b/winsup/cygwin/local_includes/cygtls.h
95+
@@ -135,6 +135,7 @@ struct _local_storage
96+
97+
/* thread.cc */
98+
HANDLE cw_timer;
99+
+ bool cw_timer_inuse;
100+
101+
tls_pathbuf pathbufs;
102+
char ttybuf[32];
103+
@@ -180,7 +181,7 @@ public: /* Do NOT remove this public: line, it's a marker for gentls_offsets. */
104+
siginfo_t *sigwait_info;
105+
HANDLE signal_arrived;
106+
bool will_wait_for_signal;
107+
-#if 0
108+
+#if 1
109+
long __align; /* Needed to align context to 16 byte. */
110+
#endif
111+
/* context MUST be aligned to 16 byte, otherwise RtlCaptureContext fails.
112+
diff --git a/winsup/cygwin/select.cc b/winsup/cygwin/select.cc
113+
index bc02c3f9d4..48e811e2a1 100644
114+
--- a/winsup/cygwin/select.cc
115+
+++ b/winsup/cygwin/select.cc
116+
@@ -385,10 +385,14 @@ next_while:;
117+
to create the timer once per thread. Since WFMO checks the handles
118+
in order, we append the timer as last object, otherwise it's preferred
119+
over actual events on the descriptors. */
120+
- HANDLE &wait_timer = _my_tls.locals.cw_timer;
121+
+ HANDLE local_timer = NULL;
122+
+ HANDLE &wait_timer =
123+
+ _my_tls.locals.cw_timer_inuse ? local_timer : _my_tls.locals.cw_timer;
124+
if (us > 0LL)
125+
{
126+
NTSTATUS status;
127+
+ if (!_my_tls.locals.cw_timer_inuse)
128+
+ _my_tls.locals.cw_timer_inuse = true;
129+
if (!wait_timer)
130+
{
131+
status = NtCreateTimer (&wait_timer, TIMER_ALL_ACCESS, NULL,
132+
@@ -431,6 +435,10 @@ next_while:;
133+
{
134+
BOOLEAN current_state;
135+
NtCancelTimer (wait_timer, &current_state);
136+
+ if (local_timer)
137+
+ NtClose (local_timer);
138+
+ else
139+
+ _my_tls.locals.cw_timer_inuse = false;
140+
}
141+
142+
wait_states res;
143+
--
144+
2.47.1.windows.2
145+
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
From 365766a3823577d32dd8b24932f6cc3c10d406bc Mon Sep 17 00:00:00 2001
2+
From: Takashi Yano <[email protected]>
3+
Date: Tue, 21 Jan 2025 12:15:35 +0900
4+
Subject: [PATCH 1003/1003] Cygwin: signal: Do not handle signal when
5+
__SIGFLUSHFAST is sent
6+
7+
The commit a22a0ad7c4f0 was not entirely correct. Even with the patch,
8+
some hangs still occur. This patch overrides the previous commit along
9+
with the patch that makes cygwait() reentrant, to fix these hangs.
10+
11+
Addresses: https://cygwin.com/pipermail/cygwin/2024-December/256954.html
12+
Addresses: https://cygwin.com/pipermail/cygwin/2024-December/256987.html
13+
Fixes: d243e51ef1d3 ("Cygwin: signal: Fix deadlock between main thread and sig thread")
14+
Fixes: a22a0ad7c4f0 ("Cygwin: signal: Do not handle signal when __SIGFLUSHFAST is sent")
15+
Reported-by: Daisuke Fujimura <[email protected]>
16+
Reported-by: Jeremy Drake <[email protected]>
17+
Reviewed-by:
18+
Signed-off-by: Takashi Yano <[email protected]>
19+
---
20+
winsup/cygwin/sigproc.cc | 14 ++++++++------
21+
1 file changed, 8 insertions(+), 6 deletions(-)
22+
23+
diff --git a/winsup/cygwin/sigproc.cc b/winsup/cygwin/sigproc.cc
24+
index cf43aa9335..474abe1495 100644
25+
--- a/winsup/cygwin/sigproc.cc
26+
+++ b/winsup/cygwin/sigproc.cc
27+
@@ -742,6 +742,12 @@ sig_send (_pinfo *p, siginfo_t& si, _cygtls *tls)
28+
memcpy (p, si._si_commune._si_str, n); p += n;
29+
}
30+
31+
+ unsigned cw_mask;
32+
+ if (pack.si.si_signo == __SIGFLUSHFAST)
33+
+ cw_mask = 0;
34+
+ else
35+
+ cw_mask = cw_sig_restart;
36+
+
37+
DWORD nb;
38+
BOOL res;
39+
/* Try multiple times to send if packsize != nb since that probably
40+
@@ -751,8 +757,7 @@ sig_send (_pinfo *p, siginfo_t& si, _cygtls *tls)
41+
res = WriteFile (sendsig, leader, packsize, &nb, NULL);
42+
if (!res || packsize == nb)
43+
break;
44+
- if (cygwait (NULL, 10, cw_sig_eintr) == WAIT_SIGNALED)
45+
- _my_tls.call_signal_handler ();
46+
+ cygwait (NULL, 10, cw_mask);
47+
res = 0;
48+
}
49+
50+
@@ -785,7 +790,7 @@ sig_send (_pinfo *p, siginfo_t& si, _cygtls *tls)
51+
if (wait_for_completion)
52+
{
53+
sigproc_printf ("Waiting for pack.wakeup %p", pack.wakeup);
54+
- rc = cygwait (pack.wakeup, WSSC);
55+
+ rc = cygwait (pack.wakeup, WSSC, cw_mask);
56+
ForceCloseHandle (pack.wakeup);
57+
}
58+
else
59+
@@ -806,9 +811,6 @@ sig_send (_pinfo *p, siginfo_t& si, _cygtls *tls)
60+
rc = -1;
61+
}
62+
63+
- if (wait_for_completion && si.si_signo != __SIGFLUSHFAST)
64+
- _my_tls.call_signal_handler ();
65+
-
66+
out:
67+
if (communing && rc)
68+
{
69+
--
70+
2.47.1.windows.2
71+

msys2-runtime/PKGBUILD

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
pkgbase=msys2-runtime
55
pkgname=('msys2-runtime' 'msys2-runtime-devel')
66
pkgver=3.5.5
7-
pkgrel=2
7+
pkgrel=3
88
pkgdesc="Cygwin POSIX emulation engine"
99
arch=('x86_64')
1010
url="https://www.cygwin.com/"
@@ -73,7 +73,10 @@ source=('msys2-runtime'::git://sourceware.org/git/newlib-cygwin.git#tag=cygwin-$
7373
0042-Cygwin-revert-use-of-CancelSyncronousIo-on-wait_thre.patch
7474
0043-Cygwin-cache-IsWow64Process2-host-arch-in-wincap.patch
7575
0044-Cygwin-uname-add-host-machine-tag-to-sysname.patch
76-
0045-Cygwin-signal-Do-not-handle-signal-when-__SIGFLUSHFA.patch)
76+
0045-Cygwin-signal-Do-not-handle-signal-when-__SIGFLUSHFA.patch
77+
1001-Revert-Cygwin-signal-Do-not-handle-signal-when-__SIG.patch
78+
1002-Cygwin-cygwait-Make-cygwait-reentrant.patch
79+
1003-Cygwin-signal-Do-not-handle-signal-when-__SIGFLUSHFA.patch)
7780
sha256sums=('0c6fcf91be78369e753deb1963b4a04e0db613194e70a7ec653774b028adf509'
7881
'76e37d572d2aba473aab8f5a1984af2084e6069f9195795c71bc45778edbd1eb'
7982
'5c79b09f9337cc8a5f993db6dd1f54df269f8390ab3348a94e5a139a5d060e39'
@@ -119,7 +122,10 @@ sha256sums=('0c6fcf91be78369e753deb1963b4a04e0db613194e70a7ec653774b028adf509'
119122
'29c3412a1c7b0e4e719b64337ba5508b141037884ba96e9bee5f8ea253811aa3'
120123
'7064362256cb558fe443469b5f9988ca927667b7cf13f1c1020aca98e616f900'
121124
'fb6c38381eb4f36338a5184f79c98e6046c9ff741da37f2f38f4757c8714ca92'
122-
'84bbe9320fe9fdc8bf6af88c9ae68eaff4bc8e162ba58ba7422bbd053e88a986')
125+
'84bbe9320fe9fdc8bf6af88c9ae68eaff4bc8e162ba58ba7422bbd053e88a986'
126+
'9675483b06cd2844b854add3b3b470e1b119076efc0960e6d6baa9ee60721e4a'
127+
'0e2e6c13b12f646c16b164677a4d284a52b4de9305709dbccbc022ffe5a8022c'
128+
'788dc3c5176924cef8d50295047e03d68037657ee3127b60cbdbef14441e9fef')
123129

124130
# Helper macros to help make tasks easier #
125131
apply_patch_with_msg() {
@@ -202,6 +208,12 @@ prepare() {
202208
0043-Cygwin-cache-IsWow64Process2-host-arch-in-wincap.patch \
203209
0044-Cygwin-uname-add-host-machine-tag-to-sysname.patch \
204210
0045-Cygwin-signal-Do-not-handle-signal-when-__SIGFLUSHFA.patch
211+
212+
# test patches for @tyan0
213+
apply_patch_with_msg \
214+
1001-Revert-Cygwin-signal-Do-not-handle-signal-when-__SIG.patch \
215+
1002-Cygwin-cygwait-Make-cygwait-reentrant.patch \
216+
1003-Cygwin-signal-Do-not-handle-signal-when-__SIGFLUSHFA.patch
205217
}
206218

207219
build() {

0 commit comments

Comments
 (0)