This patch partially reverts the commit b7097ab39ed0 because it
seems to cause issues when longjmp is used within a signal handler.
The problem that the commit addressed no longer occurs even if this
chage is reverted. Instead, handling incyg in call_signal_handler()
has been revised. Previously, incyg was set to false before calling
the signal handler and set to true after the handler returns. However
if incyg was originally 0, it would be unintentionally changed to 1.
This patch ensures that incyg is properly restored to its original
value.
Fixes: b7097ab39ed0 ("Cygwin: signal: Revive toggling incyg flag in
call_signal_handler()")
Reviewed-by:
Signed-off-by: Takashi Yano <[email protected]>
---
winsup/cygwin/exceptions.cc | 11 +++++------
winsup/cygwin/local_includes/cygtls.h | 4 ++--
2 files changed, 7 insertions(+), 8 deletions(-)
diff --git a/winsup/cygwin/exceptions.cc b/winsup/cygwin/exceptions.cc
index 892b6c68f..7791a5096 100644
--- a/winsup/cygwin/exceptions.cc
+++ b/winsup/cygwin/exceptions.cc
@@ -932,7 +930,7 @@ _cygtls::interrupt_now (CONTEXT *cx, siginfo_t& si, void
*handler,
/* Delay the interrupt if we are
1) somehow inside the DLL
2) in a Windows DLL. */
- if (incyg || inside_kernel (cx, true))
+ if (incyg || inside_kernel (cx))
interrupted = false;
else
{
@@ -1794,7 +1792,8 @@ _cygtls::call_signal_handler ()
int this_errno = saved_errno;
reset_signal_arrived ();
- incyg = false;
+ unsigned incyg_orig = incyg;
+ incyg = 0;
current_sig = 0; /* Flag that we can accept another signal */
/* We have to fetch the original return address from the signal stack
@@ -1907,7 +1906,7 @@ _cygtls::call_signal_handler ()
}
unlock ();
- incyg = true;
+ incyg = incyg_orig;
set_signal_mask (_my_tls.sigmask, (this_sa_flags & SA_SIGINFO)
? context1.uc_sigmask : this_oldmask);
diff --git a/winsup/cygwin/local_includes/cygtls.h
b/winsup/cygwin/local_includes/cygtls.h
index 1b3bf65f1..669812663 100644
--- a/winsup/cygwin/local_includes/cygtls.h
+++ b/winsup/cygwin/local_includes/cygtls.h
@@ -198,7 +198,7 @@ public: /* Do NOT remove this public: line, it's a marker
for gentls_offsets. */
class san *andreas;
waitq wq;
volatile int current_sig;
- unsigned incyg;
+ volatile unsigned incyg;
volatile unsigned stacklock;
__tlsstack_t *stackptr;
__tlsstack_t stack[TLS_STACK_SIZE];
--
2.45.1