Skip to content

Commit 21630fd

Browse files
authored
Merge pull request #91 from dscho/fix-ninja-hang
Cygwin: pipe: Fix hang due to inadvertent 0-length raw_write() and some signal fixes
2 parents bcbfa28 + 529a0f0 commit 21630fd

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed

winsup/cygwin/exceptions.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1807,6 +1807,13 @@ _cygtls::call_signal_handler ()
18071807
to 16 byte. */
18081808
uintptr_t new_sp = ((uintptr_t) _my_tls.altstack.ss_sp
18091809
+ _my_tls.altstack.ss_size) & ~0xf;
1810+
/* Copy context1 to the alternate signal stack area, because the
1811+
context1 allocated in the normal stack area is not accessible
1812+
from the signal handler that uses alternate signal stack. */
1813+
thiscontext = (ucontext_t *) ((new_sp - sizeof (ucontext_t)) & ~0xf);
1814+
memcpy (thiscontext, &context1, sizeof (ucontext_t));
1815+
new_sp = (uintptr_t) thiscontext;
1816+
18101817
/* In assembler: Save regs on new stack, move to alternate stack,
18111818
call thisfunc, revert stack regs. */
18121819
#ifdef __x86_64__
@@ -1850,6 +1857,7 @@ _cygtls::call_signal_handler ()
18501857
#else
18511858
#error unimplemented for this target
18521859
#endif
1860+
memcpy (&context1, thiscontext, sizeof (ucontext_t));
18531861
}
18541862
else
18551863
/* No alternate signal stack requested or available, just call

winsup/cygwin/fhandler/pipe.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1158,7 +1158,7 @@ fhandler_pipe::set_pipe_buf_size ()
11581158
status = NtQueryInformationFile (get_handle (), &io, &fpli, sizeof fpli,
11591159
FilePipeLocalInformation);
11601160
if (NT_SUCCESS (status))
1161-
pipe_buf_size = fpli.InboundQuota;
1161+
pipe_buf_size = fpli.InboundQuota < PIPE_BUF ? PIPE_BUF : fpli.InboundQuota;
11621162
}
11631163

11641164
int

winsup/cygwin/release/3.6.1

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,11 @@ Fixes:
33

44
- Console mode is really restored to the previous mode.
55
Addresses: https://github.com/msys2/msys2-runtime/issues/268
6+
7+
- Clear direction flag in sigdeleyed before calling signal handler.
8+
Addresses: https://cygwin.com/pipermail/cygwin/2025-March/257704.html
9+
10+
- Copy context to alternate signal stack area in call_signal_handler()
11+
in the SA_ONSTACK case, because locally-copied context on the normal
12+
stack area is not accessible from the signal handler.
13+
Addresses: https://cygwin.com/pipermail/cygwin/2025-March/257714.html

winsup/cygwin/scripts/gendef

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ sigdelayed:
179179
movq %rsp,%rbp
180180
pushf
181181
.seh_pushreg %rax # fake, there's no .seh_pushreg for the flags
182+
cld # x86_64 ABI requires direction flag cleared
182183
# stack is aligned or unaligned on entry!
183184
# make sure it is aligned from here on
184185
# We could be called from an interrupted thread which doesn't know

0 commit comments

Comments
 (0)