Skip to content

Commit 25604e5

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

4 files changed

+275
-3
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
From 5c7cfd00d3588b3b5bf2befbc707bdb10b3b7eb3 Mon Sep 17 00:00:00 2001
2+
From: Jeremy Drake <[email protected]>
3+
Date: Sat, 18 Jan 2025 12:23:54 -0800
4+
Subject: [PATCH 1/3] Revert "Cygwin: signal: Do not handle signal when
5+
__SIGFLUSHFAST is sent"
6+
7+
This reverts commit 33799c250f0a7d353cfc34961c7bba26d3a4219a.
8+
---
9+
winsup/cygwin/release/3.5.6 | 5 -----
10+
winsup/cygwin/sigproc.cc | 20 +++++---------------
11+
2 files changed, 5 insertions(+), 20 deletions(-)
12+
delete mode 100644 winsup/cygwin/release/3.5.6
13+
14+
diff --git a/winsup/cygwin/release/3.5.6 b/winsup/cygwin/release/3.5.6
15+
deleted file mode 100644
16+
index 643d58e585..0000000000
17+
--- a/winsup/cygwin/release/3.5.6
18+
+++ /dev/null
19+
@@ -1,5 +0,0 @@
20+
-Fixes:
21+
-------
22+
-
23+
-- Fix zsh hang at startup.
24+
- Addresses: https://cygwin.com/pipermail/cygwin/2024-December/256954.html
25+
diff --git a/winsup/cygwin/sigproc.cc b/winsup/cygwin/sigproc.cc
26+
index c2985277fc..cf43aa9335 100644
27+
--- a/winsup/cygwin/sigproc.cc
28+
+++ b/winsup/cygwin/sigproc.cc
29+
@@ -751,14 +751,10 @@ sig_send (_pinfo *p, siginfo_t& si, _cygtls *tls)
30+
res = WriteFile (sendsig, leader, packsize, &nb, NULL);
31+
if (!res || packsize == nb)
32+
break;
33+
- if (cygwait (NULL, 10, cw_sig_eintr) == WAIT_SIGNALED
34+
- && pack.si.si_signo != __SIGFLUSHFAST)
35+
+ if (cygwait (NULL, 10, cw_sig_eintr) == WAIT_SIGNALED)
36+
_my_tls.call_signal_handler ();
37+
res = 0;
38+
}
39+
- /* Re-assert signal_arrived which has been cleared in cygwait(). */
40+
- if (_my_tls.sig)
41+
- _my_tls.set_signal_arrived ();
42+
43+
if (!res)
44+
{
45+
@@ -789,16 +785,7 @@ sig_send (_pinfo *p, siginfo_t& si, _cygtls *tls)
46+
if (wait_for_completion)
47+
{
48+
sigproc_printf ("Waiting for pack.wakeup %p", pack.wakeup);
49+
- do
50+
- {
51+
- rc = cygwait (pack.wakeup, WSSC, cw_sig_eintr);
52+
- if (rc == WAIT_SIGNALED && pack.si.si_signo != __SIGFLUSHFAST)
53+
- _my_tls.call_signal_handler ();
54+
- }
55+
- while (rc != WAIT_OBJECT_0 && rc != WAIT_TIMEOUT);
56+
- /* Re-assert signal_arrived which has been cleared in cygwait(). */
57+
- if (_my_tls.sig)
58+
- _my_tls.set_signal_arrived ();
59+
+ rc = cygwait (pack.wakeup, WSSC);
60+
ForceCloseHandle (pack.wakeup);
61+
}
62+
else
63+
@@ -819,6 +806,9 @@ sig_send (_pinfo *p, siginfo_t& si, _cygtls *tls)
64+
rc = -1;
65+
}
66+
67+
+ if (wait_for_completion && si.si_signo != __SIGFLUSHFAST)
68+
+ _my_tls.call_signal_handler ();
69+
+
70+
out:
71+
if (communing && rc)
72+
{
73+
--
74+
2.47.1.windows.2
75+
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
From 3506dbadcf91161ec1e4eaa686debeab5fe617bb Mon Sep 17 00:00:00 2001
2+
From: Takashi Yano <[email protected]>
3+
Date: Sat, 18 Jan 2025 19:03:23 +0900
4+
Subject: [PATCH 2/3] Cygwin: signal: Avoid frequent tls lock/unlock for
5+
SIGCONT processing
6+
7+
It seems that current _cygtls::handle_SIGCONT() code sometimes falls
8+
into a deadlock due to frequent TLS lock/unlock operation in the
9+
yield() loop. With this patch, the yield() in the wait loop for an
10+
existing signal is placed outside the TLS lock. Conversely, the
11+
yield() in the wait loop for a self-issued SIGCONT is placed inside
12+
the TLS lock and do not unlock every time yield() is called.
13+
14+
Fixes: 9ae51bcc51a7 ("Cygwin: signal: Fix another deadlock between main and sig thread")
15+
Reviewed-by:
16+
Signed-off-by: Takashi Yano <[email protected]>
17+
---
18+
winsup/cygwin/exceptions.cc | 38 +++++++++++----------------
19+
winsup/cygwin/local_includes/cygtls.h | 2 +-
20+
2 files changed, 16 insertions(+), 24 deletions(-)
21+
22+
diff --git a/winsup/cygwin/exceptions.cc b/winsup/cygwin/exceptions.cc
23+
index 469052a98a..460d4ac89d 100644
24+
--- a/winsup/cygwin/exceptions.cc
25+
+++ b/winsup/cygwin/exceptions.cc
26+
@@ -1420,7 +1420,7 @@ api_fatal_debug ()
27+
28+
/* Attempt to carefully handle SIGCONT when we are stopped. */
29+
void
30+
-_cygtls::handle_SIGCONT (threadlist_t * &tl_entry)
31+
+_cygtls::handle_SIGCONT ()
32+
{
33+
if (NOTSTATE (myself, PID_STOPPED))
34+
return;
35+
@@ -1431,28 +1431,24 @@ _cygtls::handle_SIGCONT (threadlist_t * &tl_entry)
36+
Make sure that any pending signal is handled before trying to
37+
send a new one. Then make sure that SIGCONT has been recognized
38+
before exiting the loop. */
39+
- bool sigsent = false;
40+
- while (1)
41+
- if (sig) /* Assume that it's ok to just test sig outside of a
42+
- lock since setup_handler does it this way. */
43+
- {
44+
- cygheap->unlock_tls (tl_entry);
45+
- yield (); /* Attempt to schedule another thread. */
46+
- tl_entry = cygheap->find_tls (_main_tls);
47+
- }
48+
- else if (sigsent)
49+
- break; /* SIGCONT has been recognized by other thread */
50+
- else
51+
- {
52+
- sig = SIGCONT;
53+
- set_signal_arrived (); /* alert sig_handle_tty_stop */
54+
- sigsent = true;
55+
- }
56+
+ while (sig)
57+
+ yield ();
58+
+
59+
+ threadlist_t *tl_entry = cygheap->find_tls (this);
60+
+
61+
+ sig = SIGCONT;
62+
+ set_signal_arrived (); /* alert sig_handle_tty_stop */
63+
+
64+
+ while (sig == SIGCONT)
65+
+ yield ();
66+
+
67+
/* Clear pending stop signals */
68+
sig_clear (SIGSTOP, false);
69+
sig_clear (SIGTSTP, false);
70+
sig_clear (SIGTTIN, false);
71+
sig_clear (SIGTTOU, false);
72+
+
73+
+ cygheap->unlock_tls (tl_entry);
74+
}
75+
76+
int
77+
@@ -1479,11 +1475,7 @@ sigpacket::process ()
78+
myself->rusage_self.ru_nsignals++;
79+
80+
if (si.si_signo == SIGCONT)
81+
- {
82+
- tl_entry = cygheap->find_tls (_main_tls);
83+
- _main_tls->handle_SIGCONT (tl_entry);
84+
- cygheap->unlock_tls (tl_entry);
85+
- }
86+
+ _main_tls->handle_SIGCONT ();
87+
88+
/* SIGKILL is special. It always goes through. */
89+
if (si.si_signo == SIGKILL)
90+
diff --git a/winsup/cygwin/local_includes/cygtls.h b/winsup/cygwin/local_includes/cygtls.h
91+
index e4e3889aff..7dea6de8a7 100644
92+
--- a/winsup/cygwin/local_includes/cygtls.h
93+
+++ b/winsup/cygwin/local_includes/cygtls.h
94+
@@ -275,7 +275,7 @@ public: /* Do NOT remove this public: line, it's a marker for gentls_offsets. */
95+
{
96+
will_wait_for_signal = false;
97+
}
98+
- void handle_SIGCONT (threadlist_t * &);
99+
+ void handle_SIGCONT ();
100+
static void cleanup_early(struct _reent *);
101+
private:
102+
void call2 (DWORD (*) (void *, void *), void *, void *);
103+
--
104+
2.47.1.windows.2
105+
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
From 0f82cd14af4fd4191ce07f68aa6248a828492769 Mon Sep 17 00:00:00 2001
2+
From: Takashi Yano <[email protected]>
3+
Date: Sat, 18 Jan 2025 19:21:51 +0900
4+
Subject: [PATCH 3/3] Cygwin: signal: Do not handle signal when __SIGFLUSHFAST
5+
is sent
6+
7+
The commit a22a0ad7c4f0 was not exactly the correct thing. Even with
8+
the patch, some hangs still happen. This patch overrides the previous
9+
commit to fix these hangs.
10+
11+
Addresses: https://cygwin.com/pipermail/cygwin/2024-December/256987.html
12+
Fixes: a22a0ad7c4f0 ("Cygwin: signal: Do not handle signal when __SIGFLUSHFAST is sent")
13+
Reported-by: Jeremy Drake <[email protected]>
14+
Reviewed-by:
15+
Signed-off-by: Takashi Yano <[email protected]>
16+
---
17+
winsup/cygwin/sigproc.cc | 33 +++++++++++++++++++++++++++------
18+
1 file changed, 27 insertions(+), 6 deletions(-)
19+
20+
diff --git a/winsup/cygwin/sigproc.cc b/winsup/cygwin/sigproc.cc
21+
index cf43aa9335..20046eb738 100644
22+
--- a/winsup/cygwin/sigproc.cc
23+
+++ b/winsup/cygwin/sigproc.cc
24+
@@ -751,8 +751,19 @@ sig_send (_pinfo *p, siginfo_t& si, _cygtls *tls)
25+
res = WriteFile (sendsig, leader, packsize, &nb, NULL);
26+
if (!res || packsize == nb)
27+
break;
28+
- if (cygwait (NULL, 10, cw_sig_eintr) == WAIT_SIGNALED)
29+
- _my_tls.call_signal_handler ();
30+
+ if (pack.si.si_signo == __SIGFLUSHFAST)
31+
+ Sleep (10);
32+
+ else /* Handle signals */
33+
+ do
34+
+ {
35+
+ DWORD rc = WaitForSingleObject (_my_tls.get_signal_arrived (), 10);
36+
+ if (rc == WAIT_OBJECT_0)
37+
+ {
38+
+ _my_tls.call_signal_handler ();
39+
+ continue;
40+
+ }
41+
+ }
42+
+ while (false);
43+
res = 0;
44+
}
45+
46+
@@ -785,7 +796,20 @@ sig_send (_pinfo *p, siginfo_t& si, _cygtls *tls)
47+
if (wait_for_completion)
48+
{
49+
sigproc_printf ("Waiting for pack.wakeup %p", pack.wakeup);
50+
- rc = cygwait (pack.wakeup, WSSC);
51+
+ if (pack.si.si_signo == __SIGFLUSHFAST)
52+
+ rc = WaitForSingleObject (pack.wakeup, WSSC);
53+
+ else /* Handle signals */
54+
+ do
55+
+ {
56+
+ HANDLE w[2] = {pack.wakeup, _my_tls.get_signal_arrived ()};
57+
+ rc = WaitForMultipleObjects (2, w, FALSE, WSSC);
58+
+ if (rc == WAIT_OBJECT_0 + 1) /* signal arrived */
59+
+ {
60+
+ _my_tls.call_signal_handler ();
61+
+ continue;
62+
+ }
63+
+ }
64+
+ while (false);
65+
ForceCloseHandle (pack.wakeup);
66+
}
67+
else
68+
@@ -806,9 +830,6 @@ sig_send (_pinfo *p, siginfo_t& si, _cygtls *tls)
69+
rc = -1;
70+
}
71+
72+
- if (wait_for_completion && si.si_signo != __SIGFLUSHFAST)
73+
- _my_tls.call_signal_handler ();
74+
-
75+
out:
76+
if (communing && rc)
77+
{
78+
--
79+
2.47.1.windows.2
80+

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-signal-Avoid-frequent-tls-lock-unlock-for-SIG.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+
'ae271cc5d7d27b8909eb08202bef39eadc28a0f9f6ad8a80af40ab8da951869a'
127+
'1c4f40315156db30a4f32e8c007b94da8fe7397ca9dced9a3bde11ef45a272c4'
128+
'9a08c1dcfcdae4d8b2a4ee8762c03f6ec060c6fd0c990e1acdd5fe40fbebd651')
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-signal-Avoid-frequent-tls-lock-unlock-for-SIG.patch \
216+
1003-Cygwin-signal-Do-not-handle-signal-when-__SIGFLUSHFA.patch
205217
}
206218

207219
build() {

0 commit comments

Comments
 (0)