Skip to content

Commit 529a0f0

Browse files
committed
Cygwin: signal: Copy context to alternate stack in the SA_ONSTACK case
After the commit 0210c77, the context passed to signal handler cannot be accessed from the signal handler that uses alternate stack. This is because the context locally copied is on the stack that is different area from the signal handler uses. With this patch, copy the context to alternate signal stack area to avoid this situation. Backported-from: 7f67575 (Cygwin: signal: Copy context to alternate stack in the SA_ONSTACK case, 2025-03-25) Addresses: https://cygwin.com/pipermail/cygwin/2025-March/257714.html Fixes: 0210c77 ("Cygwin: signal: Use context locally copied in call_signal_handler()") Reported-by: Bruno Haible <[email protected]> Reviewed-by: Corinna Vischen <[email protected]> Signed-off-by: Takashi Yano <[email protected]> (cherry picked from commit 0d0e76b) Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 4fbceca commit 529a0f0

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
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/release/3.6.1

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,8 @@ Fixes:
66

77
- Clear direction flag in sigdeleyed before calling signal handler.
88
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

0 commit comments

Comments
 (0)