#ifdef SIGRTMIN
int __pthread_sig_restart;
int __pthread_sig_cancel;
+int __pthread_sig_debug;
#else
int __pthread_sig_restart = DEFAULT_SIG_RESTART;
int __pthread_sig_cancel = DEFAULT_SIG_CANCEL;
+int __pthread_sig_debug = 0; /* disabled */
#endif
/* These variables are used by the setup code. */
static void pthread_handle_sigcancel(int sig, struct sigcontext ctx);
static void pthread_handle_sigrestart(int sig, struct sigcontext ctx);
#endif
+static void pthread_handle_sigdebug(int sig);
/* Initialize the pthread library.
Initialization is split in two functions:
/* Allocate the signals used. */
__pthread_sig_restart = __libc_allocate_rtsig (1);
__pthread_sig_cancel = __libc_allocate_rtsig (1);
- if (__pthread_sig_restart < 0 || __pthread_sig_cancel < 0)
+ __pthread_sig_debug = __libc_allocate_rtsig (2);
+ if (__pthread_sig_restart < 0 ||
+ __pthread_sig_cancel < 0 ||
+ __pthread_sig_debug < 0)
{
/* The kernel does not support real-time signals. Use as before
- the available signals in the fixed set. */
+ the available signals in the fixed set.
+ Debugging is not supported in this case. */
__pthread_sig_restart = DEFAULT_SIG_RESTART;
__pthread_sig_cancel = DEFAULT_SIG_CANCEL;
+ __pthread_sig_debug = 0;
}
#endif
/* Setup signal handlers for the initial thread.
sa.sa_handler = (__sighandler_t) pthread_handle_sigrestart;
#endif
sigemptyset(&sa.sa_mask);
- sa.sa_flags = SA_RESTART; /* does not matter for regular threads, but
- better for the thread manager */
+ sa.sa_flags = 0;
__sigaction(__pthread_sig_restart, &sa, NULL);
#ifndef __i386__
sa.sa_handler = pthread_handle_sigcancel;
#endif
sa.sa_flags = 0;
__sigaction(__pthread_sig_cancel, &sa, NULL);
-
+ if (__pthread_sig_debug > 0) {
+ sa.sa_handler = pthread_handle_sigdebug;
+ sigemptyset(&sa.sa_mask);
+ sa.sa_flags = 0;
+ __sigaction(__pthread_sig_debug, &sa, NULL);
+ }
/* Initially, block __pthread_sig_restart. Will be unblocked on demand. */
sigemptyset(&mask);
sigaddset(&mask, __pthread_sig_restart);
/* The handler for the CANCEL signal checks for cancellation
(in asynchronous mode), for process-wide exit and exec requests.
- For the thread manager thread, redirect the signal to
- __pthread_manager_sighandler.
- The debugging strategy is as follows:
- On reception of a REQ_DEBUG request (sent by new threads created to
- the thread manager under debugging mode), the thread manager throws
- __pthread_sig_cancel to itself. The debugger (if active) intercepts
- this signal, takes into account new threads and continue execution
- of the thread manager by propagating the signal because it doesn't
- know what it is specifically done for. In the current implementation,
- the thread manager simply discards it. */
+ For the thread manager thread, redirect the signal to
+ __pthread_manager_sighandler. */
#ifndef __i386__
static void pthread_handle_sigcancel(int sig)
}
}
+/* Handler for the DEBUG signal.
+ The debugging strategy is as follows:
+ On reception of a REQ_DEBUG request (sent by new threads created to
+ the thread manager under debugging mode), the thread manager throws
+ __pthread_sig_cancel to itself. The debugger (if active) intercepts
+ this signal, takes into account new threads and continue execution
+ of the thread manager by propagating the signal because it doesn't
+ know what it is specifically done for. In the current implementation,
+ the thread manager simply discards it. */
+
+static void pthread_handle_sigdebug(int sig)
+{
+ /* Nothing */
+}
+
/* Reset the state of the thread machinery after a fork().
Close the pipe used for requests and set the main thread to the forked
thread.
THREAD_SETMEM(self, p_in_sighandler, NULL);
}
+/* The wrapper around sigaction. Install our own signal handler
+ around the signal. */
int sigaction(int sig, const struct sigaction * act,
struct sigaction * oact)
{
struct sigaction newact;
struct sigaction *newactp;
- if (sig == __pthread_sig_restart || sig == __pthread_sig_cancel)
+ if (sig == __pthread_sig_restart ||
+ sig == __pthread_sig_cancel ||
+ (sig == __pthread_sig_debug && __pthread_sig_debug > 0))
return EINVAL;
if (act)
{
newact = *act;
if (act->sa_handler != SIG_IGN && act->sa_handler != SIG_DFL
- && sig < NSIG)
+ && sig > 0 && sig < NSIG)
newact.sa_handler = pthread_sighandler;
newactp = &newact;
}
newactp = NULL;
if (__sigaction(sig, newactp, oact) == -1)
return -1;
- if (sig < NSIG)
+ if (sig > 0 && sig < NSIG)
{
if (oact != NULL)
oact->sa_handler = sighandler[sig];
return 0;
}
+/* A signal handler that does nothing */
+static void pthread_null_sighandler(int sig) { }
+
+/* sigwait -- synchronously wait for a signal */
int sigwait(const sigset_t * set, int * sig)
{
volatile pthread_descr self = thread_self();
sigset_t mask;
int s;
sigjmp_buf jmpbuf;
+ struct sigaction sa;
/* Get ready to block all signals except those in set
- and the cancellation signal */
+ and the cancellation signal.
+ Also check that handlers are installed on all signals in set,
+ and if not, install our dummy handler. This is conformant to
+ POSIX: "The effect of sigwait() on the signal actions for the
+ signals in set is unspecified." */
sigfillset(&mask);
sigdelset(&mask, __pthread_sig_cancel);
for (s = 1; s <= NSIG; s++) {
- if (sigismember(set, s) && s != __pthread_sig_cancel)
+ if (sigismember(set, s) &&
+ s != __pthread_sig_restart &&
+ s != __pthread_sig_cancel &&
+ s != __pthread_sig_debug) {
sigdelset(&mask, s);
+ if (sighandler[s] == NULL ||
+ sighandler[s] == SIG_DFL ||
+ sighandler[s] == SIG_IGN) {
+ sa.sa_handler = pthread_null_sighandler;
+ sigemptyset(&sa.sa_mask);
+ sa.sa_flags = 0;
+ sigaction(s, &sa, NULL);
+ }
+ }
}
/* Test for cancellation */
if (sigsetjmp(jmpbuf, 1) == 0) {
return 0;
}
+/* Redefine raise() to send signal to calling thread only,
+ as per POSIX 1003.1c */
int raise (int sig)
{
int retcode = pthread_kill(pthread_self(), sig);