aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakashi Yano <takashi.yano@nifty.ne.jp>2025-03-25 18:59:53 +0900
committerTakashi Yano <takashi.yano@nifty.ne.jp>2025-03-25 21:58:03 +0900
commit0d0e76b99025704d8ee44a44b19a23af9aafe297 (patch)
treef1970ce05069622c88797185265c87112e373bf3
parent2ef1a37e7823b21eda524972c006e0e8c26f97b3 (diff)
downloadnewlib-0d0e76b99025704d8ee44a44b19a23af9aafe297.zip
newlib-0d0e76b99025704d8ee44a44b19a23af9aafe297.tar.gz
newlib-0d0e76b99025704d8ee44a44b19a23af9aafe297.tar.bz2
Cygwin: signal: Copy context to alternate stack in the SA_ONSTACK case
After the commit 0210c77311ae, 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. Addresses: https://cygwin.com/pipermail/cygwin/2025-March/257714.html Fixes: 0210c77311ae ("Cygwin: signal: Use context locally copied in call_signal_handler()") Reported-by: Bruno Haible <bruno@clisp.org> Reviewed-by: Corinna Vischen <corinna@vinschen.de> Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
-rw-r--r--winsup/cygwin/exceptions.cc8
-rw-r--r--winsup/cygwin/release/3.6.15
2 files changed, 13 insertions, 0 deletions
diff --git a/winsup/cygwin/exceptions.cc b/winsup/cygwin/exceptions.cc
index 2e25aa2..a3aae2c 100644
--- a/winsup/cygwin/exceptions.cc
+++ b/winsup/cygwin/exceptions.cc
@@ -1791,6 +1791,13 @@ _cygtls::call_signal_handler ()
to 16 byte. */
uintptr_t new_sp = ((uintptr_t) _my_tls.altstack.ss_sp
+ _my_tls.altstack.ss_size) & ~0xf;
+ /* Copy context1 to the alternate signal stack area, because the
+ context1 allocated in the normal stack area is not accessible
+ from the signal handler that uses alternate signal stack. */
+ thiscontext = (ucontext_t *) ((new_sp - sizeof (ucontext_t)) & ~0xf);
+ memcpy (thiscontext, &context1, sizeof (ucontext_t));
+ new_sp = (uintptr_t) thiscontext;
+
/* In assembler: Save regs on new stack, move to alternate stack,
call thisfunc, revert stack regs. */
#ifdef __x86_64__
@@ -1834,6 +1841,7 @@ _cygtls::call_signal_handler ()
#else
#error unimplemented for this target
#endif
+ memcpy (&context1, thiscontext, sizeof (ucontext_t));
}
else
/* No alternate signal stack requested or available, just call
diff --git a/winsup/cygwin/release/3.6.1 b/winsup/cygwin/release/3.6.1
index 40ef297..95c2c05 100644
--- a/winsup/cygwin/release/3.6.1
+++ b/winsup/cygwin/release/3.6.1
@@ -10,3 +10,8 @@ Fixes:
- getlocalename_l: Fix a crash and handle LC_ALL according to final
POSIX-1.2024 docs.
Addresses: https://cygwin.com/pipermail/cygwin/2025-March/257715.html
+
+- Copy context to alternate signal stack area in call_signal_handler()
+ in the SA_ONSTACK case, because locally-copied context on the normal
+ stack area is not accessible from the signal handler.
+ Addresses: https://cygwin.com/pipermail/cygwin/2025-March/257714.html