Skip to content

Commit 11efa75

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

4 files changed

+268
-3
lines changed
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
From 1c45d1d6b02cf18ad05c692e982309b0aa19999d 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 1001/1003] 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 is placed
10+
placed outside the TLS lock to avoid frequent TLS lock/unlock.
11+
12+
Fixes: 9ae51bcc51a7 ("Cygwin: signal: Fix another deadlock between main and sig thread")
13+
Reviewed-by:
14+
Signed-off-by: Takashi Yano <[email protected]>
15+
---
16+
winsup/cygwin/exceptions.cc | 36 ++++++++++-----------------
17+
winsup/cygwin/local_includes/cygtls.h | 2 +-
18+
2 files changed, 14 insertions(+), 24 deletions(-)
19+
20+
diff --git a/winsup/cygwin/exceptions.cc b/winsup/cygwin/exceptions.cc
21+
index 469052a98a..18ea2ffb29 100644
22+
--- a/winsup/cygwin/exceptions.cc
23+
+++ b/winsup/cygwin/exceptions.cc
24+
@@ -1420,7 +1420,7 @@ api_fatal_debug ()
25+
26+
/* Attempt to carefully handle SIGCONT when we are stopped. */
27+
void
28+
-_cygtls::handle_SIGCONT (threadlist_t * &tl_entry)
29+
+_cygtls::handle_SIGCONT ()
30+
{
31+
if (NOTSTATE (myself, PID_STOPPED))
32+
return;
33+
@@ -1431,23 +1431,17 @@ _cygtls::handle_SIGCONT (threadlist_t * &tl_entry)
34+
Make sure that any pending signal is handled before trying to
35+
send a new one. Then make sure that SIGCONT has been recognized
36+
before exiting the loop. */
37+
- bool sigsent = false;
38+
- while (1)
39+
- if (sig) /* Assume that it's ok to just test sig outside of a
40+
- lock since setup_handler does it this way. */
41+
- {
42+
- cygheap->unlock_tls (tl_entry);
43+
- yield (); /* Attempt to schedule another thread. */
44+
- tl_entry = cygheap->find_tls (_main_tls);
45+
- }
46+
- else if (sigsent)
47+
- break; /* SIGCONT has been recognized by other thread */
48+
- else
49+
- {
50+
- sig = SIGCONT;
51+
- set_signal_arrived (); /* alert sig_handle_tty_stop */
52+
- sigsent = true;
53+
- }
54+
+ while (sig)
55+
+ yield ();
56+
+
57+
+ threadlist_t *tl_entry = cygheap->find_tls (this);
58+
+ sig = SIGCONT;
59+
+ set_signal_arrived (); /* alert sig_handle_tty_stop */
60+
+ cygheap->unlock_tls (tl_entry);
61+
+
62+
+ while (sig == SIGCONT)
63+
+ yield ();
64+
+
65+
/* Clear pending stop signals */
66+
sig_clear (SIGSTOP, false);
67+
sig_clear (SIGTSTP, false);
68+
@@ -1479,11 +1473,7 @@ sigpacket::process ()
69+
myself->rusage_self.ru_nsignals++;
70+
71+
if (si.si_signo == SIGCONT)
72+
- {
73+
- tl_entry = cygheap->find_tls (_main_tls);
74+
- _main_tls->handle_SIGCONT (tl_entry);
75+
- cygheap->unlock_tls (tl_entry);
76+
- }
77+
+ _main_tls->handle_SIGCONT ();
78+
79+
/* SIGKILL is special. It always goes through. */
80+
if (si.si_signo == SIGKILL)
81+
diff --git a/winsup/cygwin/local_includes/cygtls.h b/winsup/cygwin/local_includes/cygtls.h
82+
index e4e3889aff..7dea6de8a7 100644
83+
--- a/winsup/cygwin/local_includes/cygtls.h
84+
+++ b/winsup/cygwin/local_includes/cygtls.h
85+
@@ -275,7 +275,7 @@ public: /* Do NOT remove this public: line, it's a marker for gentls_offsets. */
86+
{
87+
will_wait_for_signal = false;
88+
}
89+
- void handle_SIGCONT (threadlist_t * &);
90+
+ void handle_SIGCONT ();
91+
static void cleanup_early(struct _reent *);
92+
private:
93+
void call2 (DWORD (*) (void *, void *), void *, void *);
94+
--
95+
2.47.1.windows.2
96+
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
From 57ea7814c175163485fd376fb5a208723385f6e9 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 1002/1003] Revert "Cygwin: signal: Do not handle signal when
5+
__SIGFLUSHFAST is sent"
6+
7+
This reverts commit 33799c250f0a7d353cfc34961c7bba26d3a4219a.
8+
9+
Signed-off-by: Jeremy Drake <[email protected]>
10+
---
11+
winsup/cygwin/release/3.5.6 | 5 -----
12+
winsup/cygwin/sigproc.cc | 20 +++++---------------
13+
2 files changed, 5 insertions(+), 20 deletions(-)
14+
delete mode 100644 winsup/cygwin/release/3.5.6
15+
16+
diff --git a/winsup/cygwin/release/3.5.6 b/winsup/cygwin/release/3.5.6
17+
deleted file mode 100644
18+
index 643d58e585..0000000000
19+
--- a/winsup/cygwin/release/3.5.6
20+
+++ /dev/null
21+
@@ -1,5 +0,0 @@
22+
-Fixes:
23+
-------
24+
-
25+
-- Fix zsh hang at startup.
26+
- Addresses: https://cygwin.com/pipermail/cygwin/2024-December/256954.html
27+
diff --git a/winsup/cygwin/sigproc.cc b/winsup/cygwin/sigproc.cc
28+
index c2985277fc..cf43aa9335 100644
29+
--- a/winsup/cygwin/sigproc.cc
30+
+++ b/winsup/cygwin/sigproc.cc
31+
@@ -751,14 +751,10 @@ sig_send (_pinfo *p, siginfo_t& si, _cygtls *tls)
32+
res = WriteFile (sendsig, leader, packsize, &nb, NULL);
33+
if (!res || packsize == nb)
34+
break;
35+
- if (cygwait (NULL, 10, cw_sig_eintr) == WAIT_SIGNALED
36+
- && pack.si.si_signo != __SIGFLUSHFAST)
37+
+ if (cygwait (NULL, 10, cw_sig_eintr) == WAIT_SIGNALED)
38+
_my_tls.call_signal_handler ();
39+
res = 0;
40+
}
41+
- /* Re-assert signal_arrived which has been cleared in cygwait(). */
42+
- if (_my_tls.sig)
43+
- _my_tls.set_signal_arrived ();
44+
45+
if (!res)
46+
{
47+
@@ -789,16 +785,7 @@ sig_send (_pinfo *p, siginfo_t& si, _cygtls *tls)
48+
if (wait_for_completion)
49+
{
50+
sigproc_printf ("Waiting for pack.wakeup %p", pack.wakeup);
51+
- do
52+
- {
53+
- rc = cygwait (pack.wakeup, WSSC, cw_sig_eintr);
54+
- if (rc == WAIT_SIGNALED && pack.si.si_signo != __SIGFLUSHFAST)
55+
- _my_tls.call_signal_handler ();
56+
- }
57+
- while (rc != WAIT_OBJECT_0 && rc != WAIT_TIMEOUT);
58+
- /* Re-assert signal_arrived which has been cleared in cygwait(). */
59+
- if (_my_tls.sig)
60+
- _my_tls.set_signal_arrived ();
61+
+ rc = cygwait (pack.wakeup, WSSC);
62+
ForceCloseHandle (pack.wakeup);
63+
}
64+
else
65+
@@ -819,6 +806,9 @@ sig_send (_pinfo *p, siginfo_t& si, _cygtls *tls)
66+
rc = -1;
67+
}
68+
69+
+ if (wait_for_completion && si.si_signo != __SIGFLUSHFAST)
70+
+ _my_tls.call_signal_handler ();
71+
+
72+
out:
73+
if (communing && rc)
74+
{
75+
--
76+
2.47.1.windows.2
77+
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
From aa2ce2a8a1db49dfe2ca880b372c9948da6bb1a6 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 1003/1003] Cygwin: signal: Do not handle signal when
5+
__SIGFLUSHFAST 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-Cygwin-signal-Avoid-frequent-tls-lock-unlock-for-SIG.patch
78+
1002-Revert-Cygwin-signal-Do-not-handle-signal-when-__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+
'729aa4ed9a68c425aef84fc452fff90a0e0d94751ff47219d5566443b953808e'
127+
'3ef111ca96b39c593fc46570b2bfc7341a8812b8533de410a1d38c3035953241'
128+
'53c3d49b046712918091fc0aa73398dc1335fd6f7757a3ffe11a726c2fcb1fa3')
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-Cygwin-signal-Avoid-frequent-tls-lock-unlock-for-SIG.patch \
215+
1002-Revert-Cygwin-signal-Do-not-handle-signal-when-__SIG.patch \
216+
1003-Cygwin-signal-Do-not-handle-signal-when-__SIGFLUSHFA.patch
205217
}
206218

207219
build() {

0 commit comments

Comments
 (0)