From 39d06d71ff60e2c65b678e41b004e00c262c938b Mon Sep 17 00:00:00 2001 From: Christopher Faylor Date: Thu, 22 Jan 2004 19:03:19 +0000 Subject: * cygtls.cc (_threadinfo::remove): Don't assume that we are removing _my_tls. * exceptions.cc (setup_handler): Improve debugging output. (call_signal_handler_now): Remove ill-advised debugger call. * sigproc.cc (sigcomplete_main): Delete. (sig_send): Honor FIXME and avoid using main thread's completion event for everything or suffer races. (pending_signals::add): Default stored mask to current process mask rather than mask at time of signal send. (wait_sig): Add debugging output. * sigproc.h (sigpacket::mask_storage): Delete. --- winsup/cygwin/ChangeLog | 14 ++++++++++++++ winsup/cygwin/cygtls.cc | 3 ++- winsup/cygwin/exceptions.cc | 10 +++++----- winsup/cygwin/sigproc.cc | 37 +++++++++++++++++-------------------- winsup/cygwin/sigproc.h | 1 - 5 files changed, 38 insertions(+), 27 deletions(-) (limited to 'winsup') diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 85a848941..07d199ffc 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,17 @@ +2004-01-22 Christopher Faylor + + * cygtls.cc (_threadinfo::remove): Don't assume that we are removing + _my_tls. + * exceptions.cc (setup_handler): Improve debugging output. + (call_signal_handler_now): Remove ill-advised debugger call. + * sigproc.cc (sigcomplete_main): Delete. + (sig_send): Honor FIXME and avoid using main thread's completion event + for everything or suffer races. + (pending_signals::add): Default stored mask to current process mask + rather than mask at time of signal send. + (wait_sig): Add debugging output. + * sigproc.h (sigpacket::mask_storage): Delete. + 2004-01-22 Christopher Faylor * fhandler.cc (fhandler_base::open): Revert isfs change. diff --git a/winsup/cygwin/cygtls.cc b/winsup/cygwin/cygtls.cc index 6e31d66e6..4833b58d2 100644 --- a/winsup/cygwin/cygtls.cc +++ b/winsup/cygwin/cygtls.cc @@ -140,10 +140,11 @@ _threadinfo::remove (DWORD wait) if (here.acquired ()) { for (size_t i = 0; i < nthreads; i++) - if (&_my_tls == cygheap->threadlist[i]) + if (this == cygheap->threadlist[i]) { if (i < --nthreads) cygheap->threadlist[i] = cygheap->threadlist[nthreads]; + debug_printf ("removed %p element %d", this, i); break; } } diff --git a/winsup/cygwin/exceptions.cc b/winsup/cygwin/exceptions.cc index 1e9745b22..e67405527 100644 --- a/winsup/cygwin/exceptions.cc +++ b/winsup/cygwin/exceptions.cc @@ -744,7 +744,11 @@ setup_handler (int sig, void *handler, struct sigaction& siga, _threadinfo *tls) bool interrupted = false; if (tls->sig) - goto out; + { + sigproc_printf ("trying to send sig %d but signal %d already armed", + sig, tls->sig); + goto out; + } for (int i = 0; i < CALL_HANDLER_RETRY; i++) { @@ -1141,10 +1145,6 @@ call_signal_handler_now () void (*sigfunc) (int) = _my_tls.func; (void) _my_tls.pop (); -#ifdef DEBUGGING - if (_my_tls.stackptr > (_my_tls.stack + 1)) - try_to_debug (); -#endif reset_signal_arrived (); sigset_t oldmask = _my_tls.oldmask; int this_errno = _my_tls.saved_errno; diff --git a/winsup/cygwin/sigproc.cc b/winsup/cygwin/sigproc.cc index 6471665bf..dff2c1bd4 100644 --- a/winsup/cygwin/sigproc.cc +++ b/winsup/cygwin/sigproc.cc @@ -114,9 +114,6 @@ HANDLE NO_COPY signal_arrived; // Event signaled when a signal has Static DWORD proc_loop_wait = 1000; // Wait for subprocesses to exit -Static HANDLE sigcomplete_main; // Event signaled when a signal has - // finished processing for the main - // thread HANDLE NO_COPY sigCONT; // Used to "STOP" a process Static cygthread *hwait_sig; // Handle of wait_sig thread Static cygthread *hwait_subproc; // Handle of sig_subproc thread @@ -646,7 +643,6 @@ sigproc_terminate (void) { sigproc_printf ("entering"); // finished with anything it is doing - ForceCloseHandle (sigcomplete_main); if (!hExeced) { HANDLE sendsig = myself->sendsig; @@ -681,8 +677,8 @@ sig_send (_pinfo *p, siginfo_t& si, _threadinfo *tls) HANDLE sendsig; sigpacket pack; + pack.wakeup = NULL; bool wait_for_completion; - // FIXMENOW: Avoid using main thread's completion event! if (!(its_me = (p == NULL || p == myself || p == myself_nowait))) wait_for_completion = false; else @@ -710,11 +706,7 @@ sig_send (_pinfo *p, siginfo_t& si, _threadinfo *tls) } if (its_me) - { - sendsig = myself->sendsig; - if (wait_for_completion) - pack.wakeup = sigcomplete_main; - } + sendsig = myself->sendsig; else { HANDLE hp = OpenProcess (PROCESS_DUP_HANDLE, false, p->dwProcessId); @@ -756,7 +748,13 @@ sig_send (_pinfo *p, siginfo_t& si, _threadinfo *tls) pack.si.si_uid = myself->uid; pack.pid = myself->pid; pack.tls = (_threadinfo *) tls; - pack.mask_storage = 0; + if (wait_for_completion) + { + pack.wakeup = CreateEvent (&sec_none_nih, FALSE, FALSE, NULL); + sigproc_printf ("wakeup %p", pack.wakeup); + ProtectHandle (pack.wakeup); + } + DWORD nb; if (!WriteFile (sendsig, &pack, sizeof (pack), &nb, NULL) || nb != sizeof (pack)) { @@ -815,6 +813,9 @@ sig_send (_pinfo *p, siginfo_t& si, _threadinfo *tls) call_signal_handler_now (); out: + if (pack.wakeup) + ForceCloseHandle (pack.wakeup); + if (si.si_signo != __SIGPENDING) /* nothing */; else if (!rc) @@ -1028,8 +1029,7 @@ pending_signals::add (sigpacket& pack) empty = 0; se = sigs + empty; *se = pack; - se->mask_storage = *(pack.mask); - se->mask = &se->mask_storage; + se->mask = &myself->getsigmask (); se->next = NULL; if (end) end->next = se; @@ -1077,12 +1077,8 @@ wait_sig (VOID *self) /* Initialization */ (void) SetThreadPriority (GetCurrentThread (), WAIT_SIG_PRIORITY); - /* sigcomplete_main - event used to signal main thread on signal - completion */ if (!CreatePipe (&readsig, &myself->sendsig, sec_user_nih (sa_buf), 0)) api_fatal ("couldn't create signal pipe, %E"); - sigcomplete_main = CreateEvent (&sec_none_nih, FALSE, FALSE, NULL); - sigproc_printf ("sigcomplete_main %p", sigcomplete_main); sigCONT = CreateEvent (&sec_none_nih, FALSE, FALSE, NULL); /* Setting dwProcessId flags that this process is now capable of receiving @@ -1093,8 +1089,6 @@ wait_sig (VOID *self) myself->process_state |= PID_ACTIVE; myself->process_state &= ~PID_INITIALIZING; - ProtectHandle (sigcomplete_main); - /* If we've been execed, then there is still a stub left in the previous windows process waiting to see if it's started a cygwin process or not. Signalling subproc_ready indicates that we are a cygwin process. */ @@ -1193,7 +1187,10 @@ wait_sig (VOID *self) break; } if (pack.wakeup) - SetEvent (pack.wakeup); + { + SetEvent (pack.wakeup); + sigproc_printf ("signalled %p", pack.wakeup); + } } sigproc_printf ("done"); diff --git a/winsup/cygwin/sigproc.h b/winsup/cygwin/sigproc.h index 9c9608901..b37b91ed9 100644 --- a/winsup/cygwin/sigproc.h +++ b/winsup/cygwin/sigproc.h @@ -55,7 +55,6 @@ struct sigpacket pid_t pid; class _threadinfo *tls; sigset_t *mask; - sigset_t mask_storage; union { HANDLE wakeup; -- cgit v1.2.3