Skip to content

Commit 2c4eeea

Browse files
committed
Cygwin: signal: Revive toggling incyg flag in call_signal_handler()
The commit 68991cd dropped toggling incyg flag in the function call_signal_handler(). However this seems to cause another problem that the command "stress-ng --kill 0 -t 5" sometimes leaves child processes hanging. With this patch additional mechanism to determin whether the target thread is inside cygwin1.dll has been introduced instead. This mechanism utilizes _cygtls::inside_kernel() function with additional argument to return true if the code is in the cygwin DLL even if incyg flag is not set. Fixes: 68991cd ("Cygwin: signal: Do not handle signals while waiting for wakeup evt") Signed-off-by: Takashi Yano <[email protected]> (cherry picked from commit b7097ab)
1 parent 20aded9 commit 2c4eeea

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

winsup/cygwin/exceptions.cc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ cygwin_exception::dumpstack ()
440440
}
441441

442442
bool
443-
_cygtls::inside_kernel (CONTEXT *cx)
443+
_cygtls::inside_kernel (CONTEXT *cx, bool inside_cygwin)
444444
{
445445
int res;
446446
MEMORY_BASIC_INFORMATION m;
@@ -462,6 +462,8 @@ _cygtls::inside_kernel (CONTEXT *cx)
462462
else if (h == hntdll)
463463
res = true; /* Calling GetModuleFilename on ntdll.dll
464464
can hang */
465+
else if (h == cygwin_hmodule && inside_cygwin)
466+
res = true;
465467
else if (h == user_data->hmodule)
466468
res = false;
467469
else if (!GetModuleFileNameW (h, checkdir,
@@ -921,7 +923,7 @@ _cygtls::interrupt_now (CONTEXT *cx, siginfo_t& si, void *handler,
921923
/* Delay the interrupt if we are
922924
1) somehow inside the DLL
923925
2) in a Windows DLL. */
924-
if (incyg || inside_kernel (cx))
926+
if (incyg || inside_kernel (cx, true))
925927
interrupted = false;
926928
else
927929
{
@@ -1756,6 +1758,7 @@ _cygtls::call_signal_handler ()
17561758

17571759
int this_errno = saved_errno;
17581760
reset_signal_arrived ();
1761+
incyg = false;
17591762
current_sig = 0; /* Flag that we can accept another signal */
17601763

17611764
/* We have to fetch the original return address from the signal stack
@@ -1868,6 +1871,8 @@ _cygtls::call_signal_handler ()
18681871
}
18691872
unlock ();
18701873

1874+
incyg = true;
1875+
18711876
set_signal_mask (_my_tls.sigmask, (this_sa_flags & SA_SIGINFO)
18721877
? context1.uc_sigmask : this_oldmask);
18731878
if (this_errno >= 0)

winsup/cygwin/local_includes/cygtls.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ class _cygtls
229229
bool interrupt_now (CONTEXT *, siginfo_t&, void *, struct sigaction&);
230230
void interrupt_setup (siginfo_t&, void *, struct sigaction&);
231231

232-
bool inside_kernel (CONTEXT *);
232+
bool inside_kernel (CONTEXT *, bool inside_cygwin = false);
233233
void signal_debugger (siginfo_t&);
234234

235235
#ifdef CYGTLS_HANDLE

0 commit comments

Comments
 (0)