Skip to content

Commit 7dc96b8

Browse files
authored
Merge pull request #226 from git-for-windows/msys2-runtime-529a0f09a93fa9316c8a3acd9802a5c8cf0c055a
msys2-runtime: update to 3.6.0-2
2 parents baa6286 + 3b9f564 commit 7dc96b8

5 files changed

+173
-6
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
From 5c97a05fe79a97f5b3afed0a1ca39fb010c04cec Mon Sep 17 00:00:00 2001
2+
From: Johannes Schindelin <[email protected]>
3+
Date: Thu, 27 Mar 2025 12:18:45 +0100
4+
Subject: [PATCH 50/N] Cygwin: pipe: Fix hang due to inadvertent 0-length
5+
raw_write()
6+
7+
It is possible for `NtQueryInformationFile()` to report a 0-length
8+
`InboundQuota` when obtaining `FilePipeLocalInformation`. This seems to
9+
be the case e.g. when a pipe was created on the other side and its quota
10+
information is not available on the client side.
11+
12+
This can lead to a situation where the `avail` variable is set to 0, and
13+
since that is used to cap the number of bytes to send, a 0-length write.
14+
Which hangs forever.
15+
16+
This was observed in the MSYS2 project when building GIMP, and reduced
17+
to a simple test case where a MINGW `ninja.exe` tries to call an MSYS
18+
`bison.exe` and the error message (saying that `bison` wants to have
19+
some input) is not even shown.
20+
21+
Since the minimal pipe buffer size is 4k, let's ensure that it is at
22+
least that, even when `InboundQuota` reports 0.
23+
24+
This fixes https://github.com/msys2/msys2-runtime/issues/270
25+
26+
Fixes: cbfaeba4f7 (Cygwin: pipe: Fix incorrect write length in raw_write())
27+
Helped-by: Corinna Vinschen <[email protected]>
28+
Signed-off-by: Johannes Schindelin <[email protected]>
29+
---
30+
winsup/cygwin/fhandler/pipe.cc | 2 +-
31+
1 file changed, 1 insertion(+), 1 deletion(-)
32+
33+
diff --git a/winsup/cygwin/fhandler/pipe.cc b/winsup/cygwin/fhandler/pipe.cc
34+
index 3537180..92fc09d 100644
35+
--- a/winsup/cygwin/fhandler/pipe.cc
36+
+++ b/winsup/cygwin/fhandler/pipe.cc
37+
@@ -1158,7 +1158,7 @@ fhandler_pipe::set_pipe_buf_size ()
38+
status = NtQueryInformationFile (get_handle (), &io, &fpli, sizeof fpli,
39+
FilePipeLocalInformation);
40+
if (NT_SUCCESS (status))
41+
- pipe_buf_size = fpli.InboundQuota;
42+
+ pipe_buf_size = fpli.InboundQuota < PIPE_BUF ? PIPE_BUF : fpli.InboundQuota;
43+
}
44+
45+
int
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
From 4fbceca1e3750f02b1e47ccec8499fcd0f45d179 Mon Sep 17 00:00:00 2001
2+
From: Johannes Schindelin <[email protected]>
3+
Date: Mon, 31 Mar 2025 08:30:15 +0200
4+
Subject: [PATCH 51/N] Cygwin: signal: Clear direction flag in sigdeleyed
5+
6+
x86_64 ABI requires the direction flag in CPU flags register cleared.
7+
https://learn.microsoft.com/en-us/cpp/build/x64-software-conventions
8+
However, currently that flag is not maintained in signal handler.
9+
Therefore, if the signal handler is called when that flag is set, it
10+
destroys the data and may crash if rep instruction is used in the
11+
signal handler. With this patch, the direction flag is cleared in
12+
sigdelayed() by adding cld instruction.
13+
14+
Backported-from: d71aeccff4 (Cygwin: signal: Clear direction flag in sigdeleyed, 2025-03-24)
15+
Addresses: https://cygwin.com/pipermail/cygwin/2025-March/257704.html
16+
Fixes: 1fd5e000ace5 ("import winsup-2000-02-17 snapshot")
17+
Reported-by: Christian Franke <[email protected]>
18+
Reviewed-by: Corinna Vischen <[email protected]>
19+
Signed-off-by: Takashi Yano <[email protected]>
20+
(cherry picked from commit 9f4cec47df66a913256912c358afe5e597dec25c)
21+
Signed-off-by: Johannes Schindelin <[email protected]>
22+
---
23+
winsup/cygwin/release/3.6.1 | 3 +++
24+
winsup/cygwin/scripts/gendef | 1 +
25+
2 files changed, 4 insertions(+)
26+
27+
diff --git a/winsup/cygwin/release/3.6.1 b/winsup/cygwin/release/3.6.1
28+
index 0b54b5f..0b05f45 100644
29+
--- a/winsup/cygwin/release/3.6.1
30+
+++ b/winsup/cygwin/release/3.6.1
31+
@@ -3,3 +3,6 @@ Fixes:
32+
33+
- Console mode is really restored to the previous mode.
34+
Addresses: https://github.com/msys2/msys2-runtime/issues/268
35+
+
36+
+- Clear direction flag in sigdeleyed before calling signal handler.
37+
+ Addresses: https://cygwin.com/pipermail/cygwin/2025-March/257704.html
38+
diff --git a/winsup/cygwin/scripts/gendef b/winsup/cygwin/scripts/gendef
39+
index a2f0392..861a240 100755
40+
--- a/winsup/cygwin/scripts/gendef
41+
+++ b/winsup/cygwin/scripts/gendef
42+
@@ -179,6 +179,7 @@ sigdelayed:
43+
movq %rsp,%rbp
44+
pushf
45+
.seh_pushreg %rax # fake, there's no .seh_pushreg for the flags
46+
+ cld # x86_64 ABI requires direction flag cleared
47+
# stack is aligned or unaligned on entry!
48+
# make sure it is aligned from here on
49+
# We could be called from an interrupted thread which doesn't know
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
From 529a0f09a93fa9316c8a3acd9802a5c8cf0c055a Mon Sep 17 00:00:00 2001
2+
From: Johannes Schindelin <[email protected]>
3+
Date: Mon, 31 Mar 2025 08:31:53 +0200
4+
Subject: [PATCH 52/N] Cygwin: signal: Copy context to alternate stack in the
5+
SA_ONSTACK case
6+
7+
After the commit 0210c77311ae, the context passed to signal handler
8+
cannot be accessed from the signal handler that uses alternate stack.
9+
This is because the context locally copied is on the stack that is
10+
different area from the signal handler uses. With this patch, copy
11+
the context to alternate signal stack area to avoid this situation.
12+
13+
Backported-from: 7f67575711 (Cygwin: signal: Copy context to alternate stack in the SA_ONSTACK case, 2025-03-25)
14+
Addresses: https://cygwin.com/pipermail/cygwin/2025-March/257714.html
15+
Fixes: 0210c77311ae ("Cygwin: signal: Use context locally copied in call_signal_handler()")
16+
Reported-by: Bruno Haible <[email protected]>
17+
Reviewed-by: Corinna Vischen <[email protected]>
18+
Signed-off-by: Takashi Yano <[email protected]>
19+
(cherry picked from commit 0d0e76b99025704d8ee44a44b19a23af9aafe297)
20+
Signed-off-by: Johannes Schindelin <[email protected]>
21+
---
22+
winsup/cygwin/exceptions.cc | 8 ++++++++
23+
winsup/cygwin/release/3.6.1 | 5 +++++
24+
2 files changed, 13 insertions(+)
25+
26+
diff --git a/winsup/cygwin/exceptions.cc b/winsup/cygwin/exceptions.cc
27+
index 493b32c..e9bc6d9 100644
28+
--- a/winsup/cygwin/exceptions.cc
29+
+++ b/winsup/cygwin/exceptions.cc
30+
@@ -1807,6 +1807,13 @@ _cygtls::call_signal_handler ()
31+
to 16 byte. */
32+
uintptr_t new_sp = ((uintptr_t) _my_tls.altstack.ss_sp
33+
+ _my_tls.altstack.ss_size) & ~0xf;
34+
+ /* Copy context1 to the alternate signal stack area, because the
35+
+ context1 allocated in the normal stack area is not accessible
36+
+ from the signal handler that uses alternate signal stack. */
37+
+ thiscontext = (ucontext_t *) ((new_sp - sizeof (ucontext_t)) & ~0xf);
38+
+ memcpy (thiscontext, &context1, sizeof (ucontext_t));
39+
+ new_sp = (uintptr_t) thiscontext;
40+
+
41+
/* In assembler: Save regs on new stack, move to alternate stack,
42+
call thisfunc, revert stack regs. */
43+
#ifdef __x86_64__
44+
@@ -1850,6 +1857,7 @@ _cygtls::call_signal_handler ()
45+
#else
46+
#error unimplemented for this target
47+
#endif
48+
+ memcpy (&context1, thiscontext, sizeof (ucontext_t));
49+
}
50+
else
51+
/* No alternate signal stack requested or available, just call
52+
diff --git a/winsup/cygwin/release/3.6.1 b/winsup/cygwin/release/3.6.1
53+
index 0b05f45..50db0b8 100644
54+
--- a/winsup/cygwin/release/3.6.1
55+
+++ b/winsup/cygwin/release/3.6.1
56+
@@ -6,3 +6,8 @@ Fixes:
57+
58+
- Clear direction flag in sigdeleyed before calling signal handler.
59+
Addresses: https://cygwin.com/pipermail/cygwin/2025-March/257704.html
60+
+
61+
+- Copy context to alternate signal stack area in call_signal_handler()
62+
+ in the SA_ONSTACK case, because locally-copied context on the normal
63+
+ stack area is not accessible from the signal handler.
64+
+ Addresses: https://cygwin.com/pipermail/cygwin/2025-March/257714.html

msys2-runtime/PKGBUILD

Lines changed: 14 additions & 5 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.6.0
7-
pkgrel=1
7+
pkgrel=2
88
pkgdesc="Cygwin POSIX emulation engine"
99
arch=('x86_64')
1010
url="https://www.cygwin.com/"
@@ -75,9 +75,12 @@ source=('msys2-runtime'::git+https://github.com/cygwin/cygwin#tag=cygwin-${pkgve
7575
0046-Make-paths-WCS-MBS-conversion-explicit.patch
7676
0047-Use-MB_CUR_MAX-6-by-default.patch
7777
0048-Change-the-default-base-address-for-x86_64.patch
78-
0049-msys2-runtime-restore-fast-path-for-current-user-pri.patch)
78+
0049-msys2-runtime-restore-fast-path-for-current-user-pri.patch
79+
0050-Cygwin-pipe-Fix-hang-due-to-inadvertent-0-length-raw.patch
80+
0051-Cygwin-signal-Clear-direction-flag-in-sigdeleyed.patch
81+
0052-Cygwin-signal-Copy-context-to-alternate-stack-in-the.patch)
7982
sha256sums=('a57fc7fe47e2d766c98dbd603655ccefb871630e36165472bf1e60dd9e1996d9'
80-
'ecc5a901e9de3ac5dcb8cc5cfbb14ac467ed9379369af9956c885d5c6c7edf32'
83+
'615640a6a527ff282e64f2d2214f7c36ca4d2213c88d6646948822eed212ded1'
8184
'5945b95c6b3caf18cc8356802e9af1770746a76c27d0931b897d48d072603fcf'
8285
'8f2def0add5397487e2470fd7219bd80233e4d43e9f78d92d042907fede0570a'
8386
'0cebee2ed462579029512e46e4bd3c7bddd4d92823ef69803a938007c66d2843'
@@ -126,7 +129,10 @@ sha256sums=('a57fc7fe47e2d766c98dbd603655ccefb871630e36165472bf1e60dd9e1996d9'
126129
'00e16c80725435e0c1949b2a9208e766d0c0ddf754078570d113068557c96547'
127130
'9bcb1865d0716595a86e4589549d527c821314174ba1664e3f729d74daa27210'
128131
'a15a9b5a968f6e1397acf43d29b41310011841251c895b76496d76a90302f895'
129-
'6fe858194859e857ea20bf6501ab95427296f9e34aed7ac10681dee0bf2a1d06')
132+
'6fe858194859e857ea20bf6501ab95427296f9e34aed7ac10681dee0bf2a1d06'
133+
'b38be4d385beb0c8f6815b2f285ecfcf60641c627eeb7810141ba1127fb908ea'
134+
'8b891cc7ddb75e43d45c3d610cd3809ba3eed00eb68344cc79c55ef1b530bd16'
135+
'753860b3fa45044d40b6cde36e4a22d2422ad254618fa2e51c554a54ae11c364')
130136

131137
# Helper macros to help make tasks easier #
132138
apply_patch_with_msg() {
@@ -229,7 +235,10 @@ prepare() {
229235
0046-Make-paths-WCS-MBS-conversion-explicit.patch \
230236
0047-Use-MB_CUR_MAX-6-by-default.patch \
231237
0048-Change-the-default-base-address-for-x86_64.patch \
232-
0049-msys2-runtime-restore-fast-path-for-current-user-pri.patch
238+
0049-msys2-runtime-restore-fast-path-for-current-user-pri.patch \
239+
0050-Cygwin-pipe-Fix-hang-due-to-inadvertent-0-length-raw.patch \
240+
0051-Cygwin-signal-Clear-direction-flag-in-sigdeleyed.patch \
241+
0052-Cygwin-signal-Copy-context-to-alternate-stack-in-the.patch
233242
}
234243

235244
build() {

msys2-runtime/msys2-runtime.commit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
9300298449c13cbc6511482de7ed54e368800cbd
1+
529a0f09a93fa9316c8a3acd9802a5c8cf0c055a

0 commit comments

Comments
 (0)