1996-01-22 00:23:58 +00:00
|
|
|
/*
|
1998-04-29 09:59:34 +00:00
|
|
|
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
|
1996-01-22 00:23:58 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by John Birrell.
|
|
|
|
* 4. Neither the name of the author nor the names of any co-contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
1999-08-05 12:15:30 +00:00
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
1996-01-22 00:23:58 +00:00
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
1999-08-28 00:22:10 +00:00
|
|
|
* $FreeBSD$
|
1996-01-22 00:23:58 +00:00
|
|
|
*/
|
1999-09-29 15:18:46 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/signalvar.h>
|
1996-01-22 00:23:58 +00:00
|
|
|
#include <signal.h>
|
2003-04-18 05:04:16 +00:00
|
|
|
#include <errno.h>
|
1996-08-20 08:22:01 +00:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
2003-04-18 05:04:16 +00:00
|
|
|
#include <string.h>
|
1996-01-22 00:23:58 +00:00
|
|
|
#include <pthread.h>
|
2002-09-16 08:45:36 +00:00
|
|
|
#include "thr_private.h"
|
1996-01-22 00:23:58 +00:00
|
|
|
|
Change signal handling to conform to POSIX specified semantics.
Before this change, a signal was delivered to each thread that
didn't have the signal masked. Signals also improperly woke up
threads waiting on I/O. With this change, signals are now
handled in the following way:
o If a thread is waiting in a sigwait for the signal,
then the thread is woken up.
o If no threads are sigwait'ing on the signal and a
thread is in a sigsuspend waiting for the signal,
then the thread is woken up.
o In the case that no threads are waiting or suspended
on the signal, then the signal is delivered to the
first thread we find that has the signal unmasked.
o If no threads are waiting or suspended on the signal,
and no threads have the signal unmasked, then the signal
is added to the process wide pending signal set. The
signal will be delivered to the first thread that unmasks
the signal.
If there is an installed signal handler, it is only invoked
if the chosen thread was not in a sigwait.
In the case that multiple threads are waiting or suspended
on a signal, or multiple threads have the signal unmasked,
we wake up/deliver the signal to the first thread we find.
The above rules still apply.
Reported by: Scott Hess <scott@avantgo.com>
Reviewed by: jb, jasone
1999-12-04 22:55:59 +00:00
|
|
|
/* Prototypes: */
|
2004-12-18 18:07:37 +00:00
|
|
|
static inline void build_siginfo(siginfo_t *info, int signo);
|
2003-07-17 23:02:30 +00:00
|
|
|
#ifndef SYSTEM_SCOPE_ONLY
|
2003-04-18 05:04:16 +00:00
|
|
|
static struct pthread *thr_sig_find(struct kse *curkse, int sig,
|
|
|
|
siginfo_t *info);
|
2003-07-17 23:02:30 +00:00
|
|
|
#endif
|
2004-12-18 18:07:37 +00:00
|
|
|
static inline void thr_sigframe_restore(struct pthread *thread,
|
|
|
|
struct pthread_sigframe *psf);
|
|
|
|
static inline void thr_sigframe_save(struct pthread *thread,
|
|
|
|
struct pthread_sigframe *psf);
|
2000-10-13 22:12:32 +00:00
|
|
|
|
2003-07-17 23:02:30 +00:00
|
|
|
#define SA_KILL 0x01 /* terminates process by default */
|
|
|
|
#define SA_STOP 0x02
|
|
|
|
#define SA_CONT 0x04
|
|
|
|
|
|
|
|
static int sigproptbl[NSIG] = {
|
|
|
|
SA_KILL, /* SIGHUP */
|
|
|
|
SA_KILL, /* SIGINT */
|
|
|
|
SA_KILL, /* SIGQUIT */
|
|
|
|
SA_KILL, /* SIGILL */
|
|
|
|
SA_KILL, /* SIGTRAP */
|
|
|
|
SA_KILL, /* SIGABRT */
|
|
|
|
SA_KILL, /* SIGEMT */
|
|
|
|
SA_KILL, /* SIGFPE */
|
|
|
|
SA_KILL, /* SIGKILL */
|
|
|
|
SA_KILL, /* SIGBUS */
|
|
|
|
SA_KILL, /* SIGSEGV */
|
|
|
|
SA_KILL, /* SIGSYS */
|
|
|
|
SA_KILL, /* SIGPIPE */
|
|
|
|
SA_KILL, /* SIGALRM */
|
|
|
|
SA_KILL, /* SIGTERM */
|
|
|
|
0, /* SIGURG */
|
|
|
|
SA_STOP, /* SIGSTOP */
|
|
|
|
SA_STOP, /* SIGTSTP */
|
|
|
|
SA_CONT, /* SIGCONT */
|
|
|
|
0, /* SIGCHLD */
|
|
|
|
SA_STOP, /* SIGTTIN */
|
|
|
|
SA_STOP, /* SIGTTOU */
|
|
|
|
0, /* SIGIO */
|
|
|
|
SA_KILL, /* SIGXCPU */
|
|
|
|
SA_KILL, /* SIGXFSZ */
|
|
|
|
SA_KILL, /* SIGVTALRM */
|
|
|
|
SA_KILL, /* SIGPROF */
|
|
|
|
0, /* SIGWINCH */
|
|
|
|
0, /* SIGINFO */
|
|
|
|
SA_KILL, /* SIGUSR1 */
|
|
|
|
SA_KILL /* SIGUSR2 */
|
|
|
|
};
|
|
|
|
|
2003-02-17 10:05:18 +00:00
|
|
|
/* #define DEBUG_SIGNAL */
|
2000-10-13 22:12:32 +00:00
|
|
|
#ifdef DEBUG_SIGNAL
|
|
|
|
#define DBG_MSG stdout_debug
|
|
|
|
#else
|
|
|
|
#define DBG_MSG(x...)
|
|
|
|
#endif
|
Change signal handling to conform to POSIX specified semantics.
Before this change, a signal was delivered to each thread that
didn't have the signal masked. Signals also improperly woke up
threads waiting on I/O. With this change, signals are now
handled in the following way:
o If a thread is waiting in a sigwait for the signal,
then the thread is woken up.
o If no threads are sigwait'ing on the signal and a
thread is in a sigsuspend waiting for the signal,
then the thread is woken up.
o In the case that no threads are waiting or suspended
on the signal, then the signal is delivered to the
first thread we find that has the signal unmasked.
o If no threads are waiting or suspended on the signal,
and no threads have the signal unmasked, then the signal
is added to the process wide pending signal set. The
signal will be delivered to the first thread that unmasks
the signal.
If there is an installed signal handler, it is only invoked
if the chosen thread was not in a sigwait.
In the case that multiple threads are waiting or suspended
on a signal, or multiple threads have the signal unmasked,
we wake up/deliver the signal to the first thread we find.
The above rules still apply.
Reported by: Scott Hess <scott@avantgo.com>
Reviewed by: jb, jasone
1999-12-04 22:55:59 +00:00
|
|
|
|
2003-02-17 10:05:18 +00:00
|
|
|
/*
|
2003-04-18 05:04:16 +00:00
|
|
|
* Signal setup and delivery.
|
|
|
|
*
|
|
|
|
* 1) Delivering signals to threads in the same KSE.
|
|
|
|
* These signals are sent by upcall events and are set in the
|
|
|
|
* km_sigscaught field of the KSE mailbox. Since these signals
|
|
|
|
* are received while operating on the KSE stack, they can be
|
|
|
|
* delivered either by using signalcontext() to add a stack frame
|
|
|
|
* to the target thread's stack, or by adding them in the thread's
|
|
|
|
* pending set and having the thread run them down after it
|
|
|
|
* 2) Delivering signals to threads in other KSEs/KSEGs.
|
|
|
|
* 3) Delivering signals to threads in critical regions.
|
|
|
|
* 4) Delivering signals to threads after they change their signal masks.
|
|
|
|
*
|
|
|
|
* Methods of delivering signals.
|
|
|
|
*
|
|
|
|
* 1) Add a signal frame to the thread's saved context.
|
|
|
|
* 2) Add the signal to the thread structure, mark the thread as
|
|
|
|
* having signals to handle, and let the thread run them down
|
|
|
|
* after it resumes from the KSE scheduler.
|
|
|
|
*
|
|
|
|
* Problem with 1). You can't do this to a running thread or a
|
|
|
|
* thread in a critical region.
|
|
|
|
*
|
|
|
|
* Problem with 2). You can't do this to a thread that doesn't
|
|
|
|
* yield in some way (explicitly enters the scheduler). A thread
|
|
|
|
* blocked in the kernel or a CPU hungry thread will not see the
|
|
|
|
* signal without entering the scheduler.
|
|
|
|
*
|
|
|
|
* The solution is to use both 1) and 2) to deliver signals:
|
|
|
|
*
|
|
|
|
* o Thread in critical region - use 2). When the thread
|
|
|
|
* leaves the critical region it will check to see if it
|
|
|
|
* has pending signals and run them down.
|
|
|
|
*
|
|
|
|
* o Thread enters scheduler explicitly - use 2). The thread
|
|
|
|
* can check for pending signals after it returns from the
|
|
|
|
* the scheduler.
|
|
|
|
*
|
|
|
|
* o Thread is running and not current thread - use 2). When the
|
|
|
|
* thread hits a condition specified by one of the other bullets,
|
|
|
|
* the signal will be delivered.
|
|
|
|
*
|
|
|
|
* o Thread is running and is current thread (e.g., the thread
|
|
|
|
* has just changed its signal mask and now sees that it has
|
|
|
|
* pending signals) - just run down the pending signals.
|
|
|
|
*
|
|
|
|
* o Thread is swapped out due to quantum expiration - use 1)
|
|
|
|
*
|
|
|
|
* o Thread is blocked in kernel - kse_thr_wakeup() and then
|
|
|
|
* use 1)
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Rules for selecting threads for signals received:
|
|
|
|
*
|
|
|
|
* 1) If the signal is a sychronous signal, it is delivered to
|
|
|
|
* the generating (current thread). If the thread has the
|
|
|
|
* signal masked, it is added to the threads pending signal
|
|
|
|
* set until the thread unmasks it.
|
|
|
|
*
|
|
|
|
* 2) A thread in sigwait() where the signal is in the thread's
|
|
|
|
* waitset.
|
|
|
|
*
|
|
|
|
* 3) A thread in sigsuspend() where the signal is not in the
|
|
|
|
* thread's suspended signal mask.
|
|
|
|
*
|
|
|
|
* 4) Any thread (first found/easiest to deliver) that has the
|
|
|
|
* signal unmasked.
|
|
|
|
*/
|
|
|
|
|
2003-07-17 23:02:30 +00:00
|
|
|
#ifndef SYSTEM_SCOPE_ONLY
|
|
|
|
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
static void *
|
|
|
|
sig_daemon(void *arg /* Unused */)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
kse_critical_t crit;
|
|
|
|
struct timespec ts;
|
|
|
|
sigset_t set;
|
|
|
|
struct kse *curkse;
|
|
|
|
struct pthread *curthread = _get_curthread();
|
|
|
|
|
2003-07-17 23:02:30 +00:00
|
|
|
DBG_MSG("signal daemon started(%p)\n", curthread);
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
|
|
|
|
curthread->name = strdup("signal thread");
|
|
|
|
crit = _kse_critical_enter();
|
|
|
|
curkse = _get_curkse();
|
2003-07-17 23:02:30 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Daemon thread is a bound thread and we must be created with
|
|
|
|
* all signals masked
|
|
|
|
*/
|
|
|
|
#if 0
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
SIGFILLSET(set);
|
|
|
|
__sys_sigprocmask(SIG_SETMASK, &set, NULL);
|
2003-07-17 23:02:30 +00:00
|
|
|
#endif
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
__sys_sigpending(&set);
|
|
|
|
ts.tv_sec = 0;
|
|
|
|
ts.tv_nsec = 0;
|
|
|
|
while (1) {
|
|
|
|
KSE_LOCK_ACQUIRE(curkse, &_thread_signal_lock);
|
|
|
|
_thr_proc_sigpending = set;
|
|
|
|
KSE_LOCK_RELEASE(curkse, &_thread_signal_lock);
|
|
|
|
for (i = 1; i <= _SIG_MAXSIG; i++) {
|
|
|
|
if (SIGISMEMBER(set, i) != 0)
|
|
|
|
_thr_sig_dispatch(curkse, i,
|
|
|
|
NULL /* no siginfo */);
|
|
|
|
}
|
|
|
|
ts.tv_sec = 30;
|
|
|
|
ts.tv_nsec = 0;
|
2003-08-05 22:46:00 +00:00
|
|
|
curkse->k_kcb->kcb_kmbx.km_flags =
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
KMF_NOUPCALL | KMF_NOCOMPLETED | KMF_WAITSIGEVENT;
|
|
|
|
kse_release(&ts);
|
2003-08-05 22:46:00 +00:00
|
|
|
curkse->k_kcb->kcb_kmbx.km_flags = 0;
|
|
|
|
set = curkse->k_kcb->kcb_kmbx.km_sigscaught;
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2003-07-17 23:02:30 +00:00
|
|
|
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
/* Utility function to create signal daemon thread */
|
|
|
|
int
|
|
|
|
_thr_start_sig_daemon(void)
|
|
|
|
{
|
|
|
|
pthread_attr_t attr;
|
|
|
|
sigset_t sigset, oldset;
|
2003-07-17 23:02:30 +00:00
|
|
|
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
SIGFILLSET(sigset);
|
|
|
|
pthread_sigmask(SIG_SETMASK, &sigset, &oldset);
|
|
|
|
pthread_attr_init(&attr);
|
|
|
|
pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);
|
2004-07-13 22:52:11 +00:00
|
|
|
attr->flags |= THR_SIGNAL_THREAD;
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
/* sigmask will be inherited */
|
|
|
|
if (pthread_create(&_thr_sig_daemon, &attr, sig_daemon, NULL))
|
|
|
|
PANIC("can not create signal daemon thread!\n");
|
|
|
|
pthread_attr_destroy(&attr);
|
|
|
|
pthread_sigmask(SIG_SETMASK, &oldset, NULL);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2003-04-18 05:04:16 +00:00
|
|
|
/*
|
|
|
|
* This signal handler only delivers asynchronous signals.
|
|
|
|
* This must be called with upcalls disabled and without
|
|
|
|
* holding any locks.
|
2003-02-17 10:05:18 +00:00
|
|
|
*/
|
1998-04-29 09:59:34 +00:00
|
|
|
void
|
2003-04-18 05:04:16 +00:00
|
|
|
_thr_sig_dispatch(struct kse *curkse, int sig, siginfo_t *info)
|
|
|
|
{
|
2003-07-23 02:11:07 +00:00
|
|
|
struct kse_mailbox *kmbx;
|
2003-04-18 05:04:16 +00:00
|
|
|
struct pthread *thread;
|
|
|
|
|
|
|
|
DBG_MSG(">>> _thr_sig_dispatch(%d)\n", sig);
|
|
|
|
|
2003-07-17 23:02:30 +00:00
|
|
|
/* Check if the signal requires a dump of thread information: */
|
|
|
|
if (sig == SIGINFO) {
|
|
|
|
/* Dump thread information to file: */
|
|
|
|
_thread_dump_info();
|
|
|
|
}
|
|
|
|
|
2003-05-24 02:29:25 +00:00
|
|
|
while ((thread = thr_sig_find(curkse, sig, info)) != NULL) {
|
2003-04-18 05:04:16 +00:00
|
|
|
/*
|
|
|
|
* Setup the target thread to receive the signal:
|
|
|
|
*/
|
|
|
|
DBG_MSG("Got signal %d, selecting thread %p\n", sig, thread);
|
|
|
|
KSE_SCHED_LOCK(curkse, thread->kseg);
|
2003-05-24 02:29:25 +00:00
|
|
|
if ((thread->state == PS_DEAD) ||
|
|
|
|
(thread->state == PS_DEADLOCK) ||
|
|
|
|
THR_IS_EXITING(thread) || THR_IS_SUSPENDED(thread)) {
|
|
|
|
KSE_SCHED_UNLOCK(curkse, thread->kseg);
|
|
|
|
_thr_ref_delete(NULL, thread);
|
2003-07-27 06:46:34 +00:00
|
|
|
} else if (SIGISMEMBER(thread->sigmask, sig)) {
|
2003-06-08 17:37:21 +00:00
|
|
|
KSE_SCHED_UNLOCK(curkse, thread->kseg);
|
|
|
|
_thr_ref_delete(NULL, thread);
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
} else {
|
2003-07-23 02:11:07 +00:00
|
|
|
kmbx = _thr_sig_add(thread, sig, info);
|
2003-05-24 02:29:25 +00:00
|
|
|
KSE_SCHED_UNLOCK(curkse, thread->kseg);
|
|
|
|
_thr_ref_delete(NULL, thread);
|
2003-07-23 02:11:07 +00:00
|
|
|
if (kmbx != NULL)
|
|
|
|
kse_wakeup(kmbx);
|
2003-05-24 02:29:25 +00:00
|
|
|
break;
|
|
|
|
}
|
2003-04-18 05:04:16 +00:00
|
|
|
}
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
DBG_MSG("<<< _thr_sig_dispatch\n");
|
2003-04-18 05:04:16 +00:00
|
|
|
}
|
|
|
|
|
2003-07-17 23:02:30 +00:00
|
|
|
#endif /* ! SYSTEM_SCOPE_ONLY */
|
|
|
|
|
|
|
|
static __inline int
|
|
|
|
sigprop(int sig)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (sig > 0 && sig < NSIG)
|
|
|
|
return (sigproptbl[_SIG_IDX(sig)]);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2003-09-14 22:42:39 +00:00
|
|
|
typedef void (*ohandler)(int sig, int code,
|
|
|
|
struct sigcontext *scp, char *addr, __sighandler_t *catcher);
|
|
|
|
|
2003-04-18 05:04:16 +00:00
|
|
|
void
|
|
|
|
_thr_sig_handler(int sig, siginfo_t *info, ucontext_t *ucp)
|
|
|
|
{
|
2004-12-18 18:07:37 +00:00
|
|
|
struct pthread_sigframe psf;
|
2003-05-29 17:10:45 +00:00
|
|
|
__siginfohandler_t *sigfunc;
|
2003-07-17 23:02:30 +00:00
|
|
|
struct pthread *curthread;
|
2003-04-18 05:04:16 +00:00
|
|
|
struct kse *curkse;
|
2003-07-17 23:02:30 +00:00
|
|
|
struct sigaction act;
|
2004-12-18 18:07:37 +00:00
|
|
|
int sa_flags, err_save;
|
|
|
|
|
|
|
|
err_save = errno;
|
2003-07-17 23:02:30 +00:00
|
|
|
|
|
|
|
DBG_MSG(">>> _thr_sig_handler(%d)\n", sig);
|
2003-04-18 05:04:16 +00:00
|
|
|
|
2003-07-17 23:02:30 +00:00
|
|
|
curthread = _get_curthread();
|
|
|
|
if (curthread == NULL)
|
|
|
|
PANIC("No current thread.\n");
|
|
|
|
if (!(curthread->attr.flags & PTHREAD_SCOPE_SYSTEM))
|
|
|
|
PANIC("Thread is not system scope.\n");
|
2004-12-18 18:07:37 +00:00
|
|
|
if (curthread->flags & THR_FLAGS_EXITING) {
|
|
|
|
errno = err_save;
|
2003-07-17 23:02:30 +00:00
|
|
|
return;
|
2004-12-18 18:07:37 +00:00
|
|
|
}
|
|
|
|
|
2003-07-17 23:02:30 +00:00
|
|
|
curkse = _get_curkse();
|
|
|
|
/*
|
|
|
|
* If thread is in critical region or if thread is on
|
|
|
|
* the way of state transition, then latch signal into buffer.
|
|
|
|
*/
|
|
|
|
if (_kse_in_critical() || THR_IN_CRITICAL(curthread) ||
|
2004-12-18 18:07:37 +00:00
|
|
|
curthread->state != PS_RUNNING) {
|
2003-07-17 23:02:30 +00:00
|
|
|
DBG_MSG(">>> _thr_sig_handler(%d) in critical\n", sig);
|
|
|
|
curthread->siginfo[sig-1] = *info;
|
|
|
|
curthread->check_pending = 1;
|
|
|
|
curkse->k_sigseqno++;
|
|
|
|
SIGADDSET(curthread->sigpend, sig);
|
|
|
|
/*
|
|
|
|
* If the kse is on the way to idle itself, but
|
|
|
|
* we have signal ready, we should prevent it
|
|
|
|
* to sleep, kernel will latch the wakeup request,
|
|
|
|
* so kse_release will return from kernel immediately.
|
|
|
|
*/
|
|
|
|
if (KSE_IS_IDLE(curkse))
|
2003-08-05 22:46:00 +00:00
|
|
|
kse_wakeup(&curkse->k_kcb->kcb_kmbx);
|
2004-12-18 18:07:37 +00:00
|
|
|
errno = err_save;
|
2003-07-17 23:02:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-07-13 22:52:11 +00:00
|
|
|
/* Check if the signal requires a dump of thread information: */
|
|
|
|
if (sig == SIGINFO) {
|
|
|
|
/* Dump thread information to file: */
|
|
|
|
_thread_dump_info();
|
|
|
|
}
|
2004-12-18 18:07:37 +00:00
|
|
|
|
|
|
|
/* Check the threads previous state: */
|
|
|
|
curthread->critical_count++;
|
|
|
|
if (curthread->sigbackout != NULL)
|
|
|
|
curthread->sigbackout((void *)curthread);
|
|
|
|
curthread->critical_count--;
|
|
|
|
thr_sigframe_save(curthread, &psf);
|
|
|
|
THR_ASSERT(!(curthread->sigbackout), "sigbackout was not cleared.");
|
|
|
|
|
2003-07-17 23:02:30 +00:00
|
|
|
_kse_critical_enter();
|
2003-09-15 00:08:48 +00:00
|
|
|
/* Get a fresh copy of signal mask */
|
2003-09-22 14:40:36 +00:00
|
|
|
__sys_sigprocmask(SIG_BLOCK, NULL, &curthread->sigmask);
|
2003-07-17 23:02:30 +00:00
|
|
|
KSE_LOCK_ACQUIRE(curkse, &_thread_signal_lock);
|
|
|
|
sigfunc = _thread_sigact[sig - 1].sa_sigaction;
|
2003-12-28 12:20:04 +00:00
|
|
|
sa_flags = _thread_sigact[sig - 1].sa_flags;
|
2003-07-17 23:02:30 +00:00
|
|
|
if (sa_flags & SA_RESETHAND) {
|
|
|
|
act.sa_handler = SIG_DFL;
|
|
|
|
act.sa_flags = SA_RESTART;
|
|
|
|
SIGEMPTYSET(act.sa_mask);
|
|
|
|
__sys_sigaction(sig, &act, NULL);
|
|
|
|
__sys_sigaction(sig, NULL, &_thread_sigact[sig - 1]);
|
|
|
|
}
|
|
|
|
KSE_LOCK_RELEASE(curkse, &_thread_signal_lock);
|
2003-08-05 22:46:00 +00:00
|
|
|
_kse_critical_leave(&curthread->tcb->tcb_tmbx);
|
2003-07-17 23:02:30 +00:00
|
|
|
|
|
|
|
/* Now invoke real handler */
|
|
|
|
if (((__sighandler_t *)sigfunc != SIG_DFL) &&
|
|
|
|
((__sighandler_t *)sigfunc != SIG_IGN) &&
|
|
|
|
(sigfunc != (__siginfohandler_t *)_thr_sig_handler)) {
|
|
|
|
if ((sa_flags & SA_SIGINFO) != 0 || info == NULL)
|
|
|
|
(*(sigfunc))(sig, info, ucp);
|
2003-09-14 22:42:39 +00:00
|
|
|
else {
|
|
|
|
((ohandler)(*sigfunc))(
|
|
|
|
sig, info->si_code, (struct sigcontext *)ucp,
|
|
|
|
info->si_addr, (__sighandler_t *)sigfunc);
|
|
|
|
}
|
2003-07-17 23:02:30 +00:00
|
|
|
} else {
|
|
|
|
if ((__sighandler_t *)sigfunc == SIG_DFL) {
|
2003-08-18 03:58:29 +00:00
|
|
|
if (sigprop(sig) & SA_KILL) {
|
|
|
|
if (_kse_isthreaded())
|
|
|
|
kse_thr_interrupt(NULL,
|
|
|
|
KSE_INTR_SIGEXIT, sig);
|
|
|
|
else
|
|
|
|
kill(getpid(), sig);
|
|
|
|
}
|
2003-07-17 23:02:30 +00:00
|
|
|
#ifdef NOTYET
|
|
|
|
else if (sigprop(sig) & SA_STOP)
|
|
|
|
kse_thr_interrupt(NULL, KSE_INTR_JOBSTOP, sig);
|
|
|
|
#endif
|
|
|
|
}
|
2003-04-18 05:04:16 +00:00
|
|
|
}
|
2003-07-17 23:02:30 +00:00
|
|
|
_kse_critical_enter();
|
|
|
|
curthread->sigmask = ucp->uc_sigmask;
|
2003-09-15 00:08:48 +00:00
|
|
|
SIG_CANTMASK(curthread->sigmask);
|
2003-08-05 22:46:00 +00:00
|
|
|
_kse_critical_leave(&curthread->tcb->tcb_tmbx);
|
2004-12-18 18:07:37 +00:00
|
|
|
|
|
|
|
thr_sigframe_restore(curthread, &psf);
|
|
|
|
|
2003-07-17 23:02:30 +00:00
|
|
|
DBG_MSG("<<< _thr_sig_handler(%d)\n", sig);
|
2004-12-18 18:07:37 +00:00
|
|
|
|
|
|
|
errno = err_save;
|
2003-04-18 05:04:16 +00:00
|
|
|
}
|
|
|
|
|
2003-12-29 23:21:09 +00:00
|
|
|
struct sighandle_info {
|
|
|
|
__siginfohandler_t *sigfunc;
|
|
|
|
int sa_flags;
|
|
|
|
int sig;
|
|
|
|
siginfo_t *info;
|
|
|
|
ucontext_t *ucp;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void handle_signal(struct pthread *curthread,
|
|
|
|
struct sighandle_info *shi);
|
|
|
|
static void handle_signal_altstack(struct pthread *curthread,
|
|
|
|
struct sighandle_info *shi);
|
|
|
|
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
/* Must be called with signal lock and schedule lock held in order */
|
2003-04-18 05:04:16 +00:00
|
|
|
static void
|
|
|
|
thr_sig_invoke_handler(struct pthread *curthread, int sig, siginfo_t *info,
|
|
|
|
ucontext_t *ucp)
|
1998-04-29 09:59:34 +00:00
|
|
|
{
|
2003-12-29 23:21:09 +00:00
|
|
|
__siginfohandler_t *sigfunc;
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
sigset_t sigmask;
|
|
|
|
int sa_flags;
|
2003-12-29 23:21:09 +00:00
|
|
|
int onstack;
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
struct sigaction act;
|
|
|
|
struct kse *curkse;
|
2003-12-29 23:21:09 +00:00
|
|
|
struct sighandle_info shi;
|
2000-01-19 07:04:50 +00:00
|
|
|
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
/*
|
|
|
|
* Invoke the signal handler without going through the scheduler:
|
2003-04-18 05:04:16 +00:00
|
|
|
*/
|
|
|
|
DBG_MSG("Got signal %d, calling handler for current thread %p\n",
|
|
|
|
sig, curthread);
|
In the words of the author:
o The polling mechanism for I/O readiness was changed from
select() to poll(). In additon, a wrapped version of poll()
is now provided.
o The wrapped select routine now converts each fd_set to a
poll array so that the thread scheduler doesn't have to
perform a bitwise search for selected fds each time file
descriptors are polled for I/O readiness.
o The thread scheduler was modified to use a new queue (_workq)
for threads that need work. Threads waiting for I/O readiness
and spinblocks are added to the work queue in addition to the
waiting queue. This reduces the time spent forming/searching
the array of file descriptors being polled.
o The waiting queue (_waitingq) is now maintained in order of
thread wakeup time. This allows the thread scheduler to
find the nearest wakeup time by looking at the first thread
in the queue instead of searching the entire queue.
o Removed file descriptor locking for select/poll routines. An
application should not rely on the threads library for providing
this locking; if necessary, the application should use mutexes
to protect selecting/polling of file descriptors.
o Retrieve and use the kernel clock rate/resolution at startup
instead of hardcoding the clock resolution to 10 msec (tested
with kernel running at 1000 HZ).
o All queues have been changed to use queue.h macros. These
include the queues of all threads, dead threads, and threads
waiting for file descriptor locks.
o Added reinitialization of the GC mutex and condition variable
after a fork. Also prevented reallocation of the ready queue
after a fork.
o Prevented the wrapped close routine from closing the thread
kernel pipes.
o Initialized file descriptor table for stdio entries at thread
init.
o Provided additional flags to indicate to what queues threads
belong.
o Moved TAILQ initialization for statically allocated mutex and
condition variables to after the spinlock.
o Added dispatching of signals to pthread_kill. Removing the
dispatching of signals from thread activation broke sigsuspend
when pthread_kill was used to send a signal to a thread.
o Temporarily set the state of a thread to PS_SUSPENDED when it
is first created and placed in the list of threads so that it
will not be accidentally scheduled before becoming a member
of one of the scheduling queues.
o Change the signal handler to queue signals to the thread kernel
pipe if the scheduling queues are protected. When scheduling
queues are unprotected, signals are then dequeued and handled.
o Ensured that all installed signal handlers block the scheduling
signal and that the scheduling signal handler blocks all
other signals. This ensures that the signal handler is only
interruptible for and by non-scheduling signals. An atomic
lock is used to decide which instance of the signal handler
will handle pending signals.
o Removed _lock_thread_list and _unlock_thread_list as they are
no longer used to protect the thread list.
o Added missing RCS IDs to modified files.
o Added checks for appropriate queue membership and activity when
adding, removing, and searching the scheduling queues. These
checks add very little overhead and are enabled when compiled
with _PTHREADS_INVARIANTS defined. Suggested and implemented
by Tor Egge with some modification by me.
o Close a race condition in uthread_close. (Tor Egge)
o Protect the scheduling queues while modifying them in
pthread_cond_signal and _thread_fd_unlock. (Tor Egge)
o Ensure that when a thread gets a mutex, the mutex is on that
threads list of owned mutexes. (Tor Egge)
o Set the kernel-in-scheduler flag in _thread_kern_sched_state
and _thread_kern_sched_state_unlock to prevent a scheduling
signal from calling the scheduler again. (Tor Egge)
o Don't use TAILQ_FOREACH macro while searching the waiting
queue for threads in a sigwait state, because a change of
state destroys the TAILQ link. It is actually safe to do
so, though, because once a sigwaiting thread is found, the
loop ends and the function returns. (Tor Egge)
o When dispatching signals to threads, make the thread inherit
the signal deferral flag of the currently running thread.
(Tor Egge)
Submitted by: Daniel Eischen <eischen@vigrid.com> and
Tor Egge <Tor.Egge@fast.no>
1999-06-20 08:28:48 +00:00
|
|
|
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
if (!_kse_in_critical())
|
|
|
|
PANIC("thr_sig_invoke_handler without in critical\n");
|
2004-12-18 18:07:37 +00:00
|
|
|
curkse = curthread->kse;
|
2002-02-09 19:58:41 +00:00
|
|
|
/*
|
2003-04-18 05:04:16 +00:00
|
|
|
* Check that a custom handler is installed and if
|
|
|
|
* the signal is not blocked:
|
2002-02-09 19:58:41 +00:00
|
|
|
*/
|
2003-04-18 05:04:16 +00:00
|
|
|
sigfunc = _thread_sigact[sig - 1].sa_sigaction;
|
2003-12-28 12:20:04 +00:00
|
|
|
sa_flags = _thread_sigact[sig - 1].sa_flags;
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
sigmask = curthread->sigmask;
|
|
|
|
SIGSETOR(curthread->sigmask, _thread_sigact[sig - 1].sa_mask);
|
|
|
|
if (!(sa_flags & (SA_NODEFER | SA_RESETHAND)))
|
|
|
|
SIGADDSET(curthread->sigmask, sig);
|
|
|
|
if ((sig != SIGILL) && (sa_flags & SA_RESETHAND)) {
|
2003-07-17 23:02:30 +00:00
|
|
|
act.sa_handler = SIG_DFL;
|
|
|
|
act.sa_flags = SA_RESTART;
|
|
|
|
SIGEMPTYSET(act.sa_mask);
|
|
|
|
__sys_sigaction(sig, &act, NULL);
|
|
|
|
__sys_sigaction(sig, NULL, &_thread_sigact[sig - 1]);
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
}
|
|
|
|
KSE_LOCK_RELEASE(curkse, &_thread_signal_lock);
|
|
|
|
KSE_SCHED_UNLOCK(curkse, curkse->k_kseg);
|
2003-07-17 23:02:30 +00:00
|
|
|
/*
|
|
|
|
* We are processing buffered signals, synchronize working
|
|
|
|
* signal mask into kernel.
|
|
|
|
*/
|
|
|
|
if (curthread->attr.flags & PTHREAD_SCOPE_SYSTEM)
|
|
|
|
__sys_sigprocmask(SIG_SETMASK, &curthread->sigmask, NULL);
|
2003-12-29 23:21:09 +00:00
|
|
|
onstack = _thr_sigonstack(&sigfunc);
|
|
|
|
ucp->uc_stack = curthread->sigstk;
|
|
|
|
ucp->uc_stack.ss_flags = (curthread->sigstk.ss_flags & SS_DISABLE)
|
|
|
|
? SS_DISABLE : ((onstack) ? SS_ONSTACK : 0);
|
Check pending signals, if there is signal will be unblocked by
sigsuspend, thread shouldn't wait, in old code, it may be
ignored.
When a signal handler is invoked in sigsuspend, thread gets
two different signal masks, one is in thread structure,
sigprocmask() can retrieve it, another is in ucontext
which is a third parameter of signal handler, the former is
the result of sigsuspend mask ORed with sigaction's sa_mask
and current signal, the later is the mask in thread structure
before sigsuspend is called. After signal handler is called,
the mask in ucontext should be copied into thread structure,
and becomes CURRENT signal mask, then sigsuspend returns to
user code.
Reviewed by: deischen
Tested by: Sean McNeil <sean@mcneil.com>
2004-06-12 07:40:01 +00:00
|
|
|
if (curthread->oldsigmask) {
|
|
|
|
ucp->uc_sigmask = *(curthread->oldsigmask);
|
|
|
|
curthread->oldsigmask = NULL;
|
|
|
|
} else
|
|
|
|
ucp->uc_sigmask = sigmask;
|
2003-12-29 23:21:09 +00:00
|
|
|
shi.sigfunc = sigfunc;
|
|
|
|
shi.sig = sig;
|
2004-01-02 00:27:30 +00:00
|
|
|
shi.sa_flags = sa_flags;
|
2003-12-29 23:21:09 +00:00
|
|
|
shi.info = info;
|
|
|
|
shi.ucp = ucp;
|
2004-01-03 02:40:27 +00:00
|
|
|
if ((curthread->sigstk.ss_flags & SS_DISABLE) == 0) {
|
2003-12-29 23:21:09 +00:00
|
|
|
/* Deliver signal on alternative stack */
|
|
|
|
if (sa_flags & SA_ONSTACK && !onstack)
|
|
|
|
handle_signal_altstack(curthread, &shi);
|
|
|
|
else
|
|
|
|
handle_signal(curthread, &shi);
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
} else {
|
2003-12-29 23:21:09 +00:00
|
|
|
handle_signal(curthread, &shi);
|
2002-02-09 19:58:41 +00:00
|
|
|
}
|
2003-07-17 23:02:30 +00:00
|
|
|
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
_kse_critical_enter();
|
|
|
|
/* Don't trust after critical leave/enter */
|
2004-12-18 18:07:37 +00:00
|
|
|
curkse = curthread->kse;
|
2003-07-17 23:02:30 +00:00
|
|
|
|
2003-04-18 05:04:16 +00:00
|
|
|
/*
|
|
|
|
* Restore the thread's signal mask.
|
|
|
|
*/
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
curthread->sigmask = ucp->uc_sigmask;
|
2003-09-15 00:08:48 +00:00
|
|
|
SIG_CANTMASK(curthread->sigmask);
|
2003-07-17 23:02:30 +00:00
|
|
|
if (curthread->attr.flags & PTHREAD_SCOPE_SYSTEM)
|
|
|
|
__sys_sigprocmask(SIG_SETMASK, &ucp->uc_sigmask, NULL);
|
|
|
|
KSE_SCHED_LOCK(curkse, curkse->k_kseg);
|
|
|
|
KSE_LOCK_ACQUIRE(curkse, &_thread_signal_lock);
|
|
|
|
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
DBG_MSG("Got signal %d, handler returned %p\n", sig, curthread);
|
|
|
|
}
|
|
|
|
|
2003-12-29 23:21:09 +00:00
|
|
|
static void
|
|
|
|
handle_signal(struct pthread *curthread, struct sighandle_info *shi)
|
|
|
|
{
|
|
|
|
_kse_critical_leave(&curthread->tcb->tcb_tmbx);
|
|
|
|
|
2004-07-13 22:52:11 +00:00
|
|
|
/* Check if the signal requires a dump of thread information: */
|
|
|
|
if (shi->sig == SIGINFO) {
|
|
|
|
/* Dump thread information to file: */
|
|
|
|
_thread_dump_info();
|
|
|
|
}
|
|
|
|
|
2003-12-29 23:21:09 +00:00
|
|
|
if (((__sighandler_t *)shi->sigfunc != SIG_DFL) &&
|
|
|
|
((__sighandler_t *)shi->sigfunc != SIG_IGN)) {
|
|
|
|
if ((shi->sa_flags & SA_SIGINFO) != 0 || shi->info == NULL)
|
|
|
|
(*(shi->sigfunc))(shi->sig, shi->info, shi->ucp);
|
|
|
|
else {
|
|
|
|
((ohandler)(*shi->sigfunc))(
|
|
|
|
shi->sig, shi->info->si_code,
|
|
|
|
(struct sigcontext *)shi->ucp,
|
|
|
|
shi->info->si_addr,
|
|
|
|
(__sighandler_t *)shi->sigfunc);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ((__sighandler_t *)shi->sigfunc == SIG_DFL) {
|
|
|
|
if (sigprop(shi->sig) & SA_KILL) {
|
|
|
|
if (_kse_isthreaded())
|
|
|
|
kse_thr_interrupt(NULL,
|
|
|
|
KSE_INTR_SIGEXIT, shi->sig);
|
|
|
|
else
|
|
|
|
kill(getpid(), shi->sig);
|
|
|
|
}
|
|
|
|
#ifdef NOTYET
|
|
|
|
else if (sigprop(shi->sig) & SA_STOP)
|
|
|
|
kse_thr_interrupt(NULL, KSE_INTR_JOBSTOP,
|
|
|
|
shi->sig);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
handle_signal_wrapper(struct pthread *curthread, ucontext_t *ret_uc,
|
|
|
|
struct sighandle_info *shi)
|
|
|
|
{
|
|
|
|
shi->ucp->uc_stack.ss_flags = SS_ONSTACK;
|
|
|
|
handle_signal(curthread, shi);
|
|
|
|
if (curthread->attr.flags & PTHREAD_SCOPE_SYSTEM)
|
|
|
|
setcontext(ret_uc);
|
|
|
|
else {
|
|
|
|
/* Work around for ia64, THR_SETCONTEXT does not work */
|
|
|
|
_kse_critical_enter();
|
|
|
|
curthread->tcb->tcb_tmbx.tm_context = *ret_uc;
|
|
|
|
_thread_switch(curthread->kse->k_kcb, curthread->tcb, 1);
|
|
|
|
/* THR_SETCONTEXT */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Jump to stack set by sigaltstack before invoking signal handler
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
handle_signal_altstack(struct pthread *curthread, struct sighandle_info *shi)
|
|
|
|
{
|
|
|
|
volatile int once;
|
|
|
|
ucontext_t uc1, *uc2;
|
|
|
|
|
|
|
|
THR_ASSERT(_kse_in_critical(), "Not in critical");
|
|
|
|
|
|
|
|
once = 0;
|
|
|
|
THR_GETCONTEXT(&uc1);
|
|
|
|
if (once == 0) {
|
|
|
|
once = 1;
|
|
|
|
/* XXX
|
|
|
|
* We are still in critical region, it is safe to operate thread
|
|
|
|
* context
|
|
|
|
*/
|
|
|
|
uc2 = &curthread->tcb->tcb_tmbx.tm_context;
|
|
|
|
uc2->uc_stack = curthread->sigstk;
|
|
|
|
makecontext(uc2, (void (*)(void))handle_signal_wrapper,
|
|
|
|
3, curthread, &uc1, shi);
|
|
|
|
if (curthread->attr.flags & PTHREAD_SCOPE_SYSTEM)
|
|
|
|
setcontext(uc2);
|
|
|
|
else {
|
|
|
|
_thread_switch(curthread->kse->k_kcb, curthread->tcb, 1);
|
|
|
|
/* THR_SETCONTEXT(uc2); */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
int
|
|
|
|
_thr_getprocsig(int sig, siginfo_t *siginfo)
|
|
|
|
{
|
|
|
|
kse_critical_t crit;
|
|
|
|
struct kse *curkse;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
DBG_MSG(">>> _thr_getprocsig\n");
|
|
|
|
|
|
|
|
crit = _kse_critical_enter();
|
|
|
|
curkse = _get_curkse();
|
|
|
|
KSE_LOCK_ACQUIRE(curkse, &_thread_signal_lock);
|
|
|
|
ret = _thr_getprocsig_unlocked(sig, siginfo);
|
|
|
|
KSE_LOCK_RELEASE(curkse, &_thread_signal_lock);
|
|
|
|
_kse_critical_leave(crit);
|
|
|
|
|
|
|
|
DBG_MSG("<<< _thr_getprocsig\n");
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
_thr_getprocsig_unlocked(int sig, siginfo_t *siginfo)
|
|
|
|
{
|
|
|
|
sigset_t sigset;
|
|
|
|
struct timespec ts;
|
|
|
|
|
|
|
|
/* try to retrieve signal from kernel */
|
|
|
|
SIGEMPTYSET(sigset);
|
|
|
|
SIGADDSET(sigset, sig);
|
|
|
|
ts.tv_sec = 0;
|
|
|
|
ts.tv_nsec = 0;
|
2003-07-17 23:02:30 +00:00
|
|
|
SIGDELSET(_thr_proc_sigpending, sig);
|
|
|
|
if (__sys_sigtimedwait(&sigset, siginfo, &ts) > 0)
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
return (sig);
|
|
|
|
return (0);
|
2000-10-13 22:12:32 +00:00
|
|
|
}
|
|
|
|
|
2003-07-17 23:02:30 +00:00
|
|
|
#ifndef SYSTEM_SCOPE_ONLY
|
2000-10-13 22:12:32 +00:00
|
|
|
/*
|
2003-04-18 05:04:16 +00:00
|
|
|
* Find a thread that can handle the signal. This must be called
|
|
|
|
* with upcalls disabled.
|
2000-10-13 22:12:32 +00:00
|
|
|
*/
|
2003-04-18 05:04:16 +00:00
|
|
|
struct pthread *
|
|
|
|
thr_sig_find(struct kse *curkse, int sig, siginfo_t *info)
|
In the words of the author:
o The polling mechanism for I/O readiness was changed from
select() to poll(). In additon, a wrapped version of poll()
is now provided.
o The wrapped select routine now converts each fd_set to a
poll array so that the thread scheduler doesn't have to
perform a bitwise search for selected fds each time file
descriptors are polled for I/O readiness.
o The thread scheduler was modified to use a new queue (_workq)
for threads that need work. Threads waiting for I/O readiness
and spinblocks are added to the work queue in addition to the
waiting queue. This reduces the time spent forming/searching
the array of file descriptors being polled.
o The waiting queue (_waitingq) is now maintained in order of
thread wakeup time. This allows the thread scheduler to
find the nearest wakeup time by looking at the first thread
in the queue instead of searching the entire queue.
o Removed file descriptor locking for select/poll routines. An
application should not rely on the threads library for providing
this locking; if necessary, the application should use mutexes
to protect selecting/polling of file descriptors.
o Retrieve and use the kernel clock rate/resolution at startup
instead of hardcoding the clock resolution to 10 msec (tested
with kernel running at 1000 HZ).
o All queues have been changed to use queue.h macros. These
include the queues of all threads, dead threads, and threads
waiting for file descriptor locks.
o Added reinitialization of the GC mutex and condition variable
after a fork. Also prevented reallocation of the ready queue
after a fork.
o Prevented the wrapped close routine from closing the thread
kernel pipes.
o Initialized file descriptor table for stdio entries at thread
init.
o Provided additional flags to indicate to what queues threads
belong.
o Moved TAILQ initialization for statically allocated mutex and
condition variables to after the spinlock.
o Added dispatching of signals to pthread_kill. Removing the
dispatching of signals from thread activation broke sigsuspend
when pthread_kill was used to send a signal to a thread.
o Temporarily set the state of a thread to PS_SUSPENDED when it
is first created and placed in the list of threads so that it
will not be accidentally scheduled before becoming a member
of one of the scheduling queues.
o Change the signal handler to queue signals to the thread kernel
pipe if the scheduling queues are protected. When scheduling
queues are unprotected, signals are then dequeued and handled.
o Ensured that all installed signal handlers block the scheduling
signal and that the scheduling signal handler blocks all
other signals. This ensures that the signal handler is only
interruptible for and by non-scheduling signals. An atomic
lock is used to decide which instance of the signal handler
will handle pending signals.
o Removed _lock_thread_list and _unlock_thread_list as they are
no longer used to protect the thread list.
o Added missing RCS IDs to modified files.
o Added checks for appropriate queue membership and activity when
adding, removing, and searching the scheduling queues. These
checks add very little overhead and are enabled when compiled
with _PTHREADS_INVARIANTS defined. Suggested and implemented
by Tor Egge with some modification by me.
o Close a race condition in uthread_close. (Tor Egge)
o Protect the scheduling queues while modifying them in
pthread_cond_signal and _thread_fd_unlock. (Tor Egge)
o Ensure that when a thread gets a mutex, the mutex is on that
threads list of owned mutexes. (Tor Egge)
o Set the kernel-in-scheduler flag in _thread_kern_sched_state
and _thread_kern_sched_state_unlock to prevent a scheduling
signal from calling the scheduler again. (Tor Egge)
o Don't use TAILQ_FOREACH macro while searching the waiting
queue for threads in a sigwait state, because a change of
state destroys the TAILQ link. It is actually safe to do
so, though, because once a sigwaiting thread is found, the
loop ends and the function returns. (Tor Egge)
o When dispatching signals to threads, make the thread inherit
the signal deferral flag of the currently running thread.
(Tor Egge)
Submitted by: Daniel Eischen <eischen@vigrid.com> and
Tor Egge <Tor.Egge@fast.no>
1999-06-20 08:28:48 +00:00
|
|
|
{
|
2003-07-23 02:11:07 +00:00
|
|
|
struct kse_mailbox *kmbx = NULL;
|
2003-04-28 21:35:06 +00:00
|
|
|
struct pthread *pthread;
|
2002-02-09 19:58:41 +00:00
|
|
|
struct pthread *suspended_thread, *signaled_thread;
|
2003-07-17 23:02:30 +00:00
|
|
|
__siginfohandler_t *sigfunc;
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
siginfo_t si;
|
In the words of the author:
o The polling mechanism for I/O readiness was changed from
select() to poll(). In additon, a wrapped version of poll()
is now provided.
o The wrapped select routine now converts each fd_set to a
poll array so that the thread scheduler doesn't have to
perform a bitwise search for selected fds each time file
descriptors are polled for I/O readiness.
o The thread scheduler was modified to use a new queue (_workq)
for threads that need work. Threads waiting for I/O readiness
and spinblocks are added to the work queue in addition to the
waiting queue. This reduces the time spent forming/searching
the array of file descriptors being polled.
o The waiting queue (_waitingq) is now maintained in order of
thread wakeup time. This allows the thread scheduler to
find the nearest wakeup time by looking at the first thread
in the queue instead of searching the entire queue.
o Removed file descriptor locking for select/poll routines. An
application should not rely on the threads library for providing
this locking; if necessary, the application should use mutexes
to protect selecting/polling of file descriptors.
o Retrieve and use the kernel clock rate/resolution at startup
instead of hardcoding the clock resolution to 10 msec (tested
with kernel running at 1000 HZ).
o All queues have been changed to use queue.h macros. These
include the queues of all threads, dead threads, and threads
waiting for file descriptor locks.
o Added reinitialization of the GC mutex and condition variable
after a fork. Also prevented reallocation of the ready queue
after a fork.
o Prevented the wrapped close routine from closing the thread
kernel pipes.
o Initialized file descriptor table for stdio entries at thread
init.
o Provided additional flags to indicate to what queues threads
belong.
o Moved TAILQ initialization for statically allocated mutex and
condition variables to after the spinlock.
o Added dispatching of signals to pthread_kill. Removing the
dispatching of signals from thread activation broke sigsuspend
when pthread_kill was used to send a signal to a thread.
o Temporarily set the state of a thread to PS_SUSPENDED when it
is first created and placed in the list of threads so that it
will not be accidentally scheduled before becoming a member
of one of the scheduling queues.
o Change the signal handler to queue signals to the thread kernel
pipe if the scheduling queues are protected. When scheduling
queues are unprotected, signals are then dequeued and handled.
o Ensured that all installed signal handlers block the scheduling
signal and that the scheduling signal handler blocks all
other signals. This ensures that the signal handler is only
interruptible for and by non-scheduling signals. An atomic
lock is used to decide which instance of the signal handler
will handle pending signals.
o Removed _lock_thread_list and _unlock_thread_list as they are
no longer used to protect the thread list.
o Added missing RCS IDs to modified files.
o Added checks for appropriate queue membership and activity when
adding, removing, and searching the scheduling queues. These
checks add very little overhead and are enabled when compiled
with _PTHREADS_INVARIANTS defined. Suggested and implemented
by Tor Egge with some modification by me.
o Close a race condition in uthread_close. (Tor Egge)
o Protect the scheduling queues while modifying them in
pthread_cond_signal and _thread_fd_unlock. (Tor Egge)
o Ensure that when a thread gets a mutex, the mutex is on that
threads list of owned mutexes. (Tor Egge)
o Set the kernel-in-scheduler flag in _thread_kern_sched_state
and _thread_kern_sched_state_unlock to prevent a scheduling
signal from calling the scheduler again. (Tor Egge)
o Don't use TAILQ_FOREACH macro while searching the waiting
queue for threads in a sigwait state, because a change of
state destroys the TAILQ link. It is actually safe to do
so, though, because once a sigwaiting thread is found, the
loop ends and the function returns. (Tor Egge)
o When dispatching signals to threads, make the thread inherit
the signal deferral flag of the currently running thread.
(Tor Egge)
Submitted by: Daniel Eischen <eischen@vigrid.com> and
Tor Egge <Tor.Egge@fast.no>
1999-06-20 08:28:48 +00:00
|
|
|
|
2000-10-13 22:12:32 +00:00
|
|
|
DBG_MSG("Looking for thread to handle signal %d\n", sig);
|
2003-04-18 05:04:16 +00:00
|
|
|
|
2003-02-17 10:05:18 +00:00
|
|
|
/*
|
|
|
|
* Enter a loop to look for threads that have the signal
|
|
|
|
* unmasked. POSIX specifies that a thread in a sigwait
|
|
|
|
* will get the signal over any other threads. Second
|
|
|
|
* preference will be threads in in a sigsuspend. Third
|
|
|
|
* preference will be the current thread. If none of the
|
|
|
|
* above, then the signal is delivered to the first thread
|
|
|
|
* that is found. Note that if a custom handler is not
|
|
|
|
* installed, the signal only affects threads in sigwait.
|
|
|
|
*/
|
|
|
|
suspended_thread = NULL;
|
2003-04-18 05:04:16 +00:00
|
|
|
signaled_thread = NULL;
|
2003-02-17 10:05:18 +00:00
|
|
|
|
2003-04-18 05:04:16 +00:00
|
|
|
KSE_LOCK_ACQUIRE(curkse, &_thread_list_lock);
|
2003-04-28 21:35:06 +00:00
|
|
|
TAILQ_FOREACH(pthread, &_thread_list, tle) {
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
if (pthread == _thr_sig_daemon)
|
|
|
|
continue;
|
|
|
|
/* Signal delivering to bound thread is done by kernel */
|
|
|
|
if (pthread->attr.flags & PTHREAD_SCOPE_SYSTEM)
|
|
|
|
continue;
|
2003-04-29 21:03:33 +00:00
|
|
|
/* Take the scheduling lock. */
|
|
|
|
KSE_SCHED_LOCK(curkse, pthread->kseg);
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
if ((pthread->state == PS_DEAD) ||
|
|
|
|
(pthread->state == PS_DEADLOCK) ||
|
|
|
|
THR_IS_EXITING(pthread) ||
|
2003-07-09 14:30:51 +00:00
|
|
|
THR_IS_SUSPENDED(pthread)) {
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
; /* Skip this thread. */
|
2003-07-09 14:30:51 +00:00
|
|
|
} else if (pthread->state == PS_SIGWAIT &&
|
2003-07-27 06:46:34 +00:00
|
|
|
SIGISMEMBER(*(pthread->data.sigwait->waitset), sig)) {
|
In the words of the author:
o The polling mechanism for I/O readiness was changed from
select() to poll(). In additon, a wrapped version of poll()
is now provided.
o The wrapped select routine now converts each fd_set to a
poll array so that the thread scheduler doesn't have to
perform a bitwise search for selected fds each time file
descriptors are polled for I/O readiness.
o The thread scheduler was modified to use a new queue (_workq)
for threads that need work. Threads waiting for I/O readiness
and spinblocks are added to the work queue in addition to the
waiting queue. This reduces the time spent forming/searching
the array of file descriptors being polled.
o The waiting queue (_waitingq) is now maintained in order of
thread wakeup time. This allows the thread scheduler to
find the nearest wakeup time by looking at the first thread
in the queue instead of searching the entire queue.
o Removed file descriptor locking for select/poll routines. An
application should not rely on the threads library for providing
this locking; if necessary, the application should use mutexes
to protect selecting/polling of file descriptors.
o Retrieve and use the kernel clock rate/resolution at startup
instead of hardcoding the clock resolution to 10 msec (tested
with kernel running at 1000 HZ).
o All queues have been changed to use queue.h macros. These
include the queues of all threads, dead threads, and threads
waiting for file descriptor locks.
o Added reinitialization of the GC mutex and condition variable
after a fork. Also prevented reallocation of the ready queue
after a fork.
o Prevented the wrapped close routine from closing the thread
kernel pipes.
o Initialized file descriptor table for stdio entries at thread
init.
o Provided additional flags to indicate to what queues threads
belong.
o Moved TAILQ initialization for statically allocated mutex and
condition variables to after the spinlock.
o Added dispatching of signals to pthread_kill. Removing the
dispatching of signals from thread activation broke sigsuspend
when pthread_kill was used to send a signal to a thread.
o Temporarily set the state of a thread to PS_SUSPENDED when it
is first created and placed in the list of threads so that it
will not be accidentally scheduled before becoming a member
of one of the scheduling queues.
o Change the signal handler to queue signals to the thread kernel
pipe if the scheduling queues are protected. When scheduling
queues are unprotected, signals are then dequeued and handled.
o Ensured that all installed signal handlers block the scheduling
signal and that the scheduling signal handler blocks all
other signals. This ensures that the signal handler is only
interruptible for and by non-scheduling signals. An atomic
lock is used to decide which instance of the signal handler
will handle pending signals.
o Removed _lock_thread_list and _unlock_thread_list as they are
no longer used to protect the thread list.
o Added missing RCS IDs to modified files.
o Added checks for appropriate queue membership and activity when
adding, removing, and searching the scheduling queues. These
checks add very little overhead and are enabled when compiled
with _PTHREADS_INVARIANTS defined. Suggested and implemented
by Tor Egge with some modification by me.
o Close a race condition in uthread_close. (Tor Egge)
o Protect the scheduling queues while modifying them in
pthread_cond_signal and _thread_fd_unlock. (Tor Egge)
o Ensure that when a thread gets a mutex, the mutex is on that
threads list of owned mutexes. (Tor Egge)
o Set the kernel-in-scheduler flag in _thread_kern_sched_state
and _thread_kern_sched_state_unlock to prevent a scheduling
signal from calling the scheduler again. (Tor Egge)
o Don't use TAILQ_FOREACH macro while searching the waiting
queue for threads in a sigwait state, because a change of
state destroys the TAILQ link. It is actually safe to do
so, though, because once a sigwaiting thread is found, the
loop ends and the function returns. (Tor Egge)
o When dispatching signals to threads, make the thread inherit
the signal deferral flag of the currently running thread.
(Tor Egge)
Submitted by: Daniel Eischen <eischen@vigrid.com> and
Tor Egge <Tor.Egge@fast.no>
1999-06-20 08:28:48 +00:00
|
|
|
/*
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
* retrieve signal from kernel, if it is job control
|
|
|
|
* signal, and sigaction is SIG_DFL, then we will
|
|
|
|
* be stopped in kernel, we hold lock here, but that
|
|
|
|
* does not matter, because that's job control, and
|
|
|
|
* whole process should be stopped.
|
In the words of the author:
o The polling mechanism for I/O readiness was changed from
select() to poll(). In additon, a wrapped version of poll()
is now provided.
o The wrapped select routine now converts each fd_set to a
poll array so that the thread scheduler doesn't have to
perform a bitwise search for selected fds each time file
descriptors are polled for I/O readiness.
o The thread scheduler was modified to use a new queue (_workq)
for threads that need work. Threads waiting for I/O readiness
and spinblocks are added to the work queue in addition to the
waiting queue. This reduces the time spent forming/searching
the array of file descriptors being polled.
o The waiting queue (_waitingq) is now maintained in order of
thread wakeup time. This allows the thread scheduler to
find the nearest wakeup time by looking at the first thread
in the queue instead of searching the entire queue.
o Removed file descriptor locking for select/poll routines. An
application should not rely on the threads library for providing
this locking; if necessary, the application should use mutexes
to protect selecting/polling of file descriptors.
o Retrieve and use the kernel clock rate/resolution at startup
instead of hardcoding the clock resolution to 10 msec (tested
with kernel running at 1000 HZ).
o All queues have been changed to use queue.h macros. These
include the queues of all threads, dead threads, and threads
waiting for file descriptor locks.
o Added reinitialization of the GC mutex and condition variable
after a fork. Also prevented reallocation of the ready queue
after a fork.
o Prevented the wrapped close routine from closing the thread
kernel pipes.
o Initialized file descriptor table for stdio entries at thread
init.
o Provided additional flags to indicate to what queues threads
belong.
o Moved TAILQ initialization for statically allocated mutex and
condition variables to after the spinlock.
o Added dispatching of signals to pthread_kill. Removing the
dispatching of signals from thread activation broke sigsuspend
when pthread_kill was used to send a signal to a thread.
o Temporarily set the state of a thread to PS_SUSPENDED when it
is first created and placed in the list of threads so that it
will not be accidentally scheduled before becoming a member
of one of the scheduling queues.
o Change the signal handler to queue signals to the thread kernel
pipe if the scheduling queues are protected. When scheduling
queues are unprotected, signals are then dequeued and handled.
o Ensured that all installed signal handlers block the scheduling
signal and that the scheduling signal handler blocks all
other signals. This ensures that the signal handler is only
interruptible for and by non-scheduling signals. An atomic
lock is used to decide which instance of the signal handler
will handle pending signals.
o Removed _lock_thread_list and _unlock_thread_list as they are
no longer used to protect the thread list.
o Added missing RCS IDs to modified files.
o Added checks for appropriate queue membership and activity when
adding, removing, and searching the scheduling queues. These
checks add very little overhead and are enabled when compiled
with _PTHREADS_INVARIANTS defined. Suggested and implemented
by Tor Egge with some modification by me.
o Close a race condition in uthread_close. (Tor Egge)
o Protect the scheduling queues while modifying them in
pthread_cond_signal and _thread_fd_unlock. (Tor Egge)
o Ensure that when a thread gets a mutex, the mutex is on that
threads list of owned mutexes. (Tor Egge)
o Set the kernel-in-scheduler flag in _thread_kern_sched_state
and _thread_kern_sched_state_unlock to prevent a scheduling
signal from calling the scheduler again. (Tor Egge)
o Don't use TAILQ_FOREACH macro while searching the waiting
queue for threads in a sigwait state, because a change of
state destroys the TAILQ link. It is actually safe to do
so, though, because once a sigwaiting thread is found, the
loop ends and the function returns. (Tor Egge)
o When dispatching signals to threads, make the thread inherit
the signal deferral flag of the currently running thread.
(Tor Egge)
Submitted by: Daniel Eischen <eischen@vigrid.com> and
Tor Egge <Tor.Egge@fast.no>
1999-06-20 08:28:48 +00:00
|
|
|
*/
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
if (_thr_getprocsig(sig, &si)) {
|
|
|
|
DBG_MSG("Waking thread %p in sigwait"
|
|
|
|
" with signal %d\n", pthread, sig);
|
|
|
|
/* where to put siginfo ? */
|
2003-07-27 06:46:34 +00:00
|
|
|
*(pthread->data.sigwait->siginfo) = si;
|
2003-07-23 02:11:07 +00:00
|
|
|
kmbx = _thr_setrunnable_unlocked(pthread);
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
}
|
2003-04-18 05:04:16 +00:00
|
|
|
KSE_SCHED_UNLOCK(curkse, pthread->kseg);
|
2003-02-17 10:05:18 +00:00
|
|
|
/*
|
|
|
|
* POSIX doesn't doesn't specify which thread
|
|
|
|
* will get the signal if there are multiple
|
|
|
|
* waiters, so we give it to the first thread
|
|
|
|
* we find.
|
|
|
|
*
|
|
|
|
* Do not attempt to deliver this signal
|
|
|
|
* to other threads and do not add the signal
|
|
|
|
* to the process pending set.
|
|
|
|
*/
|
2003-04-18 05:04:16 +00:00
|
|
|
KSE_LOCK_RELEASE(curkse, &_thread_list_lock);
|
2003-07-23 02:11:07 +00:00
|
|
|
if (kmbx != NULL)
|
|
|
|
kse_wakeup(kmbx);
|
2004-10-21 03:42:24 +00:00
|
|
|
if (suspended_thread != NULL)
|
|
|
|
_thr_ref_delete(NULL, suspended_thread);
|
|
|
|
if (signaled_thread != NULL)
|
|
|
|
_thr_ref_delete(NULL, signaled_thread);
|
2003-02-17 10:05:18 +00:00
|
|
|
return (NULL);
|
2003-07-27 06:46:34 +00:00
|
|
|
} else if (!SIGISMEMBER(pthread->sigmask, sig)) {
|
2004-07-13 22:52:11 +00:00
|
|
|
/*
|
|
|
|
* If debugger is running, we don't quick exit,
|
|
|
|
* and give it a chance to check the signal.
|
|
|
|
*/
|
|
|
|
if (_libkse_debug == 0) {
|
|
|
|
sigfunc = _thread_sigact[sig - 1].sa_sigaction;
|
|
|
|
if ((__sighandler_t *)sigfunc == SIG_DFL) {
|
|
|
|
if (sigprop(sig) & SA_KILL) {
|
|
|
|
kse_thr_interrupt(NULL,
|
|
|
|
KSE_INTR_SIGEXIT, sig);
|
|
|
|
/* Never reach */
|
|
|
|
}
|
2003-07-17 23:02:30 +00:00
|
|
|
}
|
|
|
|
}
|
2003-02-17 10:05:18 +00:00
|
|
|
if (pthread->state == PS_SIGSUSPEND) {
|
2003-05-24 02:29:25 +00:00
|
|
|
if (suspended_thread == NULL) {
|
2003-02-17 10:05:18 +00:00
|
|
|
suspended_thread = pthread;
|
2003-05-24 02:29:25 +00:00
|
|
|
suspended_thread->refcount++;
|
|
|
|
}
|
|
|
|
} else if (signaled_thread == NULL) {
|
2003-02-17 10:05:18 +00:00
|
|
|
signaled_thread = pthread;
|
2003-05-24 02:29:25 +00:00
|
|
|
signaled_thread->refcount++;
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
}
|
1998-09-30 06:27:31 +00:00
|
|
|
}
|
2003-04-29 21:03:33 +00:00
|
|
|
KSE_SCHED_UNLOCK(curkse, pthread->kseg);
|
2003-02-17 10:05:18 +00:00
|
|
|
}
|
2003-04-18 05:04:16 +00:00
|
|
|
KSE_LOCK_RELEASE(curkse, &_thread_list_lock);
|
1998-09-30 06:27:31 +00:00
|
|
|
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
if (suspended_thread != NULL) {
|
|
|
|
pthread = suspended_thread;
|
|
|
|
if (signaled_thread)
|
2003-05-24 02:29:25 +00:00
|
|
|
_thr_ref_delete(NULL, signaled_thread);
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
} else if (signaled_thread) {
|
|
|
|
pthread = signaled_thread;
|
|
|
|
} else {
|
|
|
|
pthread = NULL;
|
2003-02-17 10:05:18 +00:00
|
|
|
}
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
return (pthread);
|
1998-04-29 09:59:34 +00:00
|
|
|
}
|
2003-07-17 23:02:30 +00:00
|
|
|
#endif /* ! SYSTEM_SCOPE_ONLY */
|
1998-04-29 09:59:34 +00:00
|
|
|
|
2004-12-18 18:07:37 +00:00
|
|
|
static inline void
|
2003-04-18 05:04:16 +00:00
|
|
|
build_siginfo(siginfo_t *info, int signo)
|
|
|
|
{
|
|
|
|
bzero(info, sizeof(*info));
|
|
|
|
info->si_signo = signo;
|
|
|
|
info->si_pid = _thr_pid;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is called by a thread when it has pending signals to deliver.
|
|
|
|
* It should only be called from the context of the thread.
|
|
|
|
*/
|
2000-10-13 22:12:32 +00:00
|
|
|
void
|
2004-12-18 18:07:37 +00:00
|
|
|
_thr_sig_rundown(struct pthread *curthread, ucontext_t *ucp)
|
2000-01-19 07:04:50 +00:00
|
|
|
{
|
2004-12-18 18:07:37 +00:00
|
|
|
struct pthread_sigframe psf;
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
siginfo_t siginfo;
|
2004-12-18 18:07:37 +00:00
|
|
|
int i, err_save;
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
kse_critical_t crit;
|
|
|
|
struct kse *curkse;
|
2003-07-17 23:02:30 +00:00
|
|
|
sigset_t sigmask;
|
2003-04-18 05:04:16 +00:00
|
|
|
|
2004-12-18 18:07:37 +00:00
|
|
|
err_save = errno;
|
|
|
|
|
2003-07-17 23:02:30 +00:00
|
|
|
DBG_MSG(">>> thr_sig_rundown (%p)\n", curthread);
|
2004-12-18 18:07:37 +00:00
|
|
|
|
2003-04-18 05:04:16 +00:00
|
|
|
/* Check the threads previous state: */
|
2004-12-18 18:07:37 +00:00
|
|
|
curthread->critical_count++;
|
|
|
|
if (curthread->sigbackout != NULL)
|
|
|
|
curthread->sigbackout((void *)curthread);
|
|
|
|
curthread->critical_count--;
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
|
2004-12-18 18:07:37 +00:00
|
|
|
THR_ASSERT(!(curthread->sigbackout), "sigbackout was not cleared.");
|
|
|
|
THR_ASSERT((curthread->state == PS_RUNNING), "state is not PS_RUNNING");
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
|
2004-12-18 18:07:37 +00:00
|
|
|
thr_sigframe_save(curthread, &psf);
|
2000-01-19 07:04:50 +00:00
|
|
|
/*
|
2003-04-18 05:04:16 +00:00
|
|
|
* Lower the priority before calling the handler in case
|
|
|
|
* it never returns (longjmps back):
|
2000-01-19 07:04:50 +00:00
|
|
|
*/
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
crit = _kse_critical_enter();
|
2004-12-18 18:07:37 +00:00
|
|
|
curkse = curthread->kse;
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
KSE_SCHED_LOCK(curkse, curkse->k_kseg);
|
|
|
|
KSE_LOCK_ACQUIRE(curkse, &_thread_signal_lock);
|
2003-04-18 05:04:16 +00:00
|
|
|
curthread->active_priority &= ~THR_SIGNAL_PRIORITY;
|
2003-08-21 22:02:18 +00:00
|
|
|
SIGFILLSET(sigmask);
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
while (1) {
|
2003-07-17 23:02:30 +00:00
|
|
|
/*
|
|
|
|
* For bound thread, we mask all signals and get a fresh
|
|
|
|
* copy of signal mask from kernel
|
|
|
|
*/
|
|
|
|
if (curthread->attr.flags & PTHREAD_SCOPE_SYSTEM) {
|
|
|
|
__sys_sigprocmask(SIG_SETMASK, &sigmask,
|
|
|
|
&curthread->sigmask);
|
|
|
|
}
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
for (i = 1; i <= _SIG_MAXSIG; i++) {
|
|
|
|
if (SIGISMEMBER(curthread->sigmask, i))
|
|
|
|
continue;
|
|
|
|
if (SIGISMEMBER(curthread->sigpend, i)) {
|
|
|
|
SIGDELSET(curthread->sigpend, i);
|
2003-06-30 06:16:50 +00:00
|
|
|
siginfo = curthread->siginfo[i-1];
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
break;
|
|
|
|
}
|
2003-07-17 23:02:30 +00:00
|
|
|
if (!(curthread->attr.flags & PTHREAD_SCOPE_SYSTEM)
|
|
|
|
&& SIGISMEMBER(_thr_proc_sigpending, i)) {
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
if (_thr_getprocsig_unlocked(i, &siginfo))
|
|
|
|
break;
|
|
|
|
}
|
2000-10-13 22:12:32 +00:00
|
|
|
}
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
if (i <= _SIG_MAXSIG)
|
|
|
|
thr_sig_invoke_handler(curthread, i, &siginfo, ucp);
|
2003-08-21 22:02:18 +00:00
|
|
|
else {
|
|
|
|
if (curthread->attr.flags & PTHREAD_SCOPE_SYSTEM) {
|
|
|
|
__sys_sigprocmask(SIG_SETMASK,
|
|
|
|
&curthread->sigmask, NULL);
|
|
|
|
}
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
break;
|
2003-08-21 22:02:18 +00:00
|
|
|
}
|
2000-01-19 07:04:50 +00:00
|
|
|
}
|
2003-04-18 05:04:16 +00:00
|
|
|
|
2004-12-18 18:07:37 +00:00
|
|
|
/* Don't trust after signal handling */
|
|
|
|
curkse = curthread->kse;
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
KSE_LOCK_RELEASE(curkse, &_thread_signal_lock);
|
|
|
|
KSE_SCHED_UNLOCK(curkse, curkse->k_kseg);
|
2003-08-05 22:46:00 +00:00
|
|
|
_kse_critical_leave(&curthread->tcb->tcb_tmbx);
|
2003-08-21 22:02:18 +00:00
|
|
|
/* repost masked signal to kernel, it hardly happens in real world */
|
|
|
|
if ((curthread->attr.flags & PTHREAD_SCOPE_SYSTEM) &&
|
|
|
|
!SIGISEMPTY(curthread->sigpend)) { /* dirty read */
|
|
|
|
__sys_sigprocmask(SIG_SETMASK, &sigmask, &curthread->sigmask);
|
|
|
|
for (i = 1; i <= _SIG_MAXSIG; ++i) {
|
|
|
|
if (SIGISMEMBER(curthread->sigpend, i)) {
|
|
|
|
SIGDELSET(curthread->sigpend, i);
|
|
|
|
if (!_kse_isthreaded())
|
|
|
|
kill(getpid(), i);
|
|
|
|
else
|
|
|
|
kse_thr_interrupt(
|
|
|
|
&curthread->tcb->tcb_tmbx,
|
|
|
|
KSE_INTR_SENDSIG,
|
|
|
|
i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
__sys_sigprocmask(SIG_SETMASK, &curthread->sigmask, NULL);
|
|
|
|
}
|
2003-07-17 23:02:30 +00:00
|
|
|
DBG_MSG("<<< thr_sig_rundown (%p)\n", curthread);
|
2004-12-18 18:07:37 +00:00
|
|
|
|
|
|
|
thr_sigframe_restore(curthread, &psf);
|
|
|
|
errno = err_save;
|
2000-10-13 22:12:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2003-04-18 05:04:16 +00:00
|
|
|
* This checks pending signals for the current thread. It should be
|
|
|
|
* called whenever a thread changes its signal mask. Note that this
|
|
|
|
* is called from a thread (using its stack).
|
|
|
|
*
|
|
|
|
* XXX - We might want to just check to see if there are pending
|
|
|
|
* signals for the thread here, but enter the UTS scheduler
|
|
|
|
* to actually install the signal handler(s).
|
2000-10-13 22:12:32 +00:00
|
|
|
*/
|
|
|
|
void
|
2003-04-18 05:04:16 +00:00
|
|
|
_thr_sig_check_pending(struct pthread *curthread)
|
2000-10-13 22:12:32 +00:00
|
|
|
{
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
ucontext_t uc;
|
|
|
|
volatile int once;
|
2003-08-20 13:43:35 +00:00
|
|
|
int errsave;
|
2003-04-18 05:04:16 +00:00
|
|
|
|
2004-12-18 18:07:37 +00:00
|
|
|
/*
|
|
|
|
* If the thread is in critical region, delay processing signals.
|
|
|
|
* If the thread state is not PS_RUNNING, it might be switching
|
|
|
|
* into UTS and but a THR_LOCK_RELEASE saw check_pending, and it
|
|
|
|
* goes here, in the case we delay processing signals, lets UTS
|
|
|
|
* process complicated things, normally UTS will call _thr_sig_add
|
|
|
|
* to resume the thread, so we needn't repeat doing it here.
|
|
|
|
*/
|
|
|
|
if (THR_IN_CRITICAL(curthread) || curthread->state != PS_RUNNING)
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
return;
|
2003-04-18 05:04:16 +00:00
|
|
|
|
2003-08-20 13:43:35 +00:00
|
|
|
errsave = errno;
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
once = 0;
|
|
|
|
THR_GETCONTEXT(&uc);
|
|
|
|
if (once == 0) {
|
|
|
|
once = 1;
|
2003-04-18 05:04:16 +00:00
|
|
|
curthread->check_pending = 0;
|
2004-12-18 18:07:37 +00:00
|
|
|
_thr_sig_rundown(curthread, &uc);
|
2000-01-19 07:04:50 +00:00
|
|
|
}
|
2003-08-20 13:43:35 +00:00
|
|
|
errno = errsave;
|
2000-01-19 07:04:50 +00:00
|
|
|
}
|
|
|
|
|
2000-10-13 22:12:32 +00:00
|
|
|
/*
|
|
|
|
* Perform thread specific actions in response to a signal.
|
|
|
|
* This function is only called if there is a handler installed
|
|
|
|
* for the signal, and if the target thread has the signal
|
|
|
|
* unmasked.
|
2003-04-18 05:04:16 +00:00
|
|
|
*
|
|
|
|
* This must be called with the thread's scheduling lock held.
|
2000-10-13 22:12:32 +00:00
|
|
|
*/
|
2003-07-23 02:11:07 +00:00
|
|
|
struct kse_mailbox *
|
2003-05-16 19:58:30 +00:00
|
|
|
_thr_sig_add(struct pthread *pthread, int sig, siginfo_t *info)
|
1998-04-29 09:59:34 +00:00
|
|
|
{
|
2003-07-23 02:11:07 +00:00
|
|
|
siginfo_t siginfo;
|
|
|
|
struct kse *curkse;
|
|
|
|
struct kse_mailbox *kmbx = NULL;
|
|
|
|
struct pthread *curthread = _get_curthread();
|
2003-04-18 05:04:16 +00:00
|
|
|
int restart;
|
2000-10-13 22:12:32 +00:00
|
|
|
int suppress_handler = 0;
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
int fromproc = 0;
|
2003-08-10 22:35:46 +00:00
|
|
|
__sighandler_t *sigfunc;
|
2000-10-13 22:12:32 +00:00
|
|
|
|
2003-07-17 23:02:30 +00:00
|
|
|
DBG_MSG(">>> _thr_sig_add %p (%d)\n", pthread, sig);
|
2003-04-18 05:04:16 +00:00
|
|
|
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
curkse = _get_curkse();
|
|
|
|
restart = _thread_sigact[sig - 1].sa_flags & SA_RESTART;
|
2003-08-10 22:35:46 +00:00
|
|
|
sigfunc = _thread_sigact[sig - 1].sa_handler;
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
fromproc = (curthread == _thr_sig_daemon);
|
|
|
|
|
|
|
|
if (pthread->state == PS_DEAD || pthread->state == PS_DEADLOCK ||
|
|
|
|
pthread->state == PS_STATE_MAX)
|
2003-07-23 02:11:07 +00:00
|
|
|
return (NULL); /* return false */
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
|
2003-07-17 23:02:30 +00:00
|
|
|
if ((pthread->attr.flags & PTHREAD_SCOPE_SYSTEM) &&
|
|
|
|
(curthread != pthread)) {
|
|
|
|
PANIC("Please use _thr_send_sig for bound thread");
|
2003-07-23 02:11:07 +00:00
|
|
|
return (NULL);
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
}
|
2001-05-04 20:37:07 +00:00
|
|
|
|
2004-12-18 18:07:37 +00:00
|
|
|
if (pthread->state != PS_SIGWAIT &&
|
|
|
|
SIGISMEMBER(pthread->sigmask, sig)) {
|
|
|
|
/* signal is masked, just add signal to thread. */
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
if (!fromproc) {
|
|
|
|
SIGADDSET(pthread->sigpend, sig);
|
|
|
|
if (info == NULL)
|
2003-06-30 06:16:50 +00:00
|
|
|
build_siginfo(&pthread->siginfo[sig-1], sig);
|
|
|
|
else if (info != &pthread->siginfo[sig-1])
|
|
|
|
memcpy(&pthread->siginfo[sig-1], info,
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
sizeof(*info));
|
|
|
|
} else {
|
2003-06-30 06:16:50 +00:00
|
|
|
if (!_thr_getprocsig(sig, &pthread->siginfo[sig-1]))
|
2003-07-23 02:11:07 +00:00
|
|
|
return (NULL);
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
SIGADDSET(pthread->sigpend, sig);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* if process signal not exists, just return */
|
|
|
|
if (fromproc) {
|
|
|
|
if (!_thr_getprocsig(sig, &siginfo))
|
2003-07-23 02:11:07 +00:00
|
|
|
return (NULL);
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
info = &siginfo;
|
|
|
|
}
|
2003-08-10 22:35:46 +00:00
|
|
|
|
|
|
|
if (pthread->state != PS_SIGWAIT && sigfunc == SIG_DFL &&
|
|
|
|
(sigprop(sig) & SA_KILL)) {
|
|
|
|
kse_thr_interrupt(NULL, KSE_INTR_SIGEXIT, sig);
|
|
|
|
/* Never reach */
|
|
|
|
}
|
|
|
|
|
2000-10-13 22:12:32 +00:00
|
|
|
/*
|
2003-05-16 19:58:30 +00:00
|
|
|
* Process according to thread state:
|
2000-10-13 22:12:32 +00:00
|
|
|
*/
|
2003-05-16 19:58:30 +00:00
|
|
|
switch (pthread->state) {
|
|
|
|
case PS_DEAD:
|
|
|
|
case PS_DEADLOCK:
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
case PS_STATE_MAX:
|
2003-07-23 02:11:07 +00:00
|
|
|
return (NULL); /* XXX return false */
|
2003-05-16 19:58:30 +00:00
|
|
|
case PS_LOCKWAIT:
|
|
|
|
case PS_SUSPENDED:
|
2000-10-13 22:12:32 +00:00
|
|
|
/*
|
2003-05-16 19:58:30 +00:00
|
|
|
* You can't call a signal handler for threads in these
|
|
|
|
* states.
|
2000-10-13 22:12:32 +00:00
|
|
|
*/
|
2003-04-18 05:04:16 +00:00
|
|
|
suppress_handler = 1;
|
2003-05-16 19:58:30 +00:00
|
|
|
break;
|
|
|
|
case PS_RUNNING:
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
if ((pthread->flags & THR_FLAGS_IN_RUNQ)) {
|
2003-05-16 19:58:30 +00:00
|
|
|
THR_RUNQ_REMOVE(pthread);
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
pthread->active_priority |= THR_SIGNAL_PRIORITY;
|
|
|
|
THR_RUNQ_INSERT_TAIL(pthread);
|
|
|
|
} else {
|
|
|
|
/* Possible not in RUNQ and has curframe ? */
|
|
|
|
pthread->active_priority |= THR_SIGNAL_PRIORITY;
|
|
|
|
}
|
2003-05-16 19:58:30 +00:00
|
|
|
break;
|
1998-09-30 06:27:31 +00:00
|
|
|
/*
|
2003-05-16 19:58:30 +00:00
|
|
|
* States which cannot be interrupted but still require the
|
|
|
|
* signal handler to run:
|
1998-09-30 06:27:31 +00:00
|
|
|
*/
|
2003-05-16 19:58:30 +00:00
|
|
|
case PS_COND_WAIT:
|
|
|
|
case PS_MUTEX_WAIT:
|
|
|
|
break;
|
2000-10-13 22:12:32 +00:00
|
|
|
|
2003-05-16 19:58:30 +00:00
|
|
|
case PS_SLEEP_WAIT:
|
|
|
|
/*
|
|
|
|
* Unmasked signals always cause sleep to terminate
|
|
|
|
* early regardless of SA_RESTART:
|
|
|
|
*/
|
|
|
|
pthread->interrupted = 1;
|
|
|
|
break;
|
2003-04-18 05:04:16 +00:00
|
|
|
|
2003-05-16 19:58:30 +00:00
|
|
|
case PS_JOIN:
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
break;
|
|
|
|
|
2003-05-16 19:58:30 +00:00
|
|
|
case PS_SIGSUSPEND:
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
pthread->interrupted = 1;
|
2003-05-16 19:58:30 +00:00
|
|
|
break;
|
2003-02-17 10:05:18 +00:00
|
|
|
|
2003-05-16 19:58:30 +00:00
|
|
|
case PS_SIGWAIT:
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
if (info == NULL)
|
2003-06-30 06:16:50 +00:00
|
|
|
build_siginfo(&pthread->siginfo[sig-1], sig);
|
|
|
|
else if (info != &pthread->siginfo[sig-1])
|
|
|
|
memcpy(&pthread->siginfo[sig-1], info,
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
sizeof(*info));
|
2003-04-18 05:04:16 +00:00
|
|
|
/*
|
2003-05-16 19:58:30 +00:00
|
|
|
* The signal handler is not called for threads in
|
|
|
|
* SIGWAIT.
|
2003-04-18 05:04:16 +00:00
|
|
|
*/
|
2003-05-16 19:58:30 +00:00
|
|
|
suppress_handler = 1;
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
/* Wake up the thread if the signal is not blocked. */
|
2003-07-27 06:46:34 +00:00
|
|
|
if (SIGISMEMBER(*(pthread->data.sigwait->waitset), sig)) {
|
2003-05-16 19:58:30 +00:00
|
|
|
/* Return the signal number: */
|
2003-07-27 06:46:34 +00:00
|
|
|
*(pthread->data.sigwait->siginfo) = pthread->siginfo[sig-1];
|
2003-05-16 19:58:30 +00:00
|
|
|
/* Make the thread runnable: */
|
2003-07-23 02:11:07 +00:00
|
|
|
kmbx = _thr_setrunnable_unlocked(pthread);
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
} else {
|
2003-05-16 19:58:30 +00:00
|
|
|
/* Increment the pending signal count. */
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
SIGADDSET(pthread->sigpend, sig);
|
2003-07-27 06:46:34 +00:00
|
|
|
if (!SIGISMEMBER(pthread->sigmask, sig)) {
|
2003-08-10 22:35:46 +00:00
|
|
|
if (sigfunc == SIG_DFL &&
|
|
|
|
sigprop(sig) & SA_KILL) {
|
|
|
|
kse_thr_interrupt(NULL,
|
|
|
|
KSE_INTR_SIGEXIT,
|
|
|
|
sig);
|
|
|
|
/* Never reach */
|
|
|
|
}
|
2003-07-09 22:30:55 +00:00
|
|
|
pthread->check_pending = 1;
|
|
|
|
pthread->interrupted = 1;
|
2003-07-23 02:11:07 +00:00
|
|
|
kmbx = _thr_setrunnable_unlocked(pthread);
|
2003-07-09 22:30:55 +00:00
|
|
|
}
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
}
|
2003-07-23 02:11:07 +00:00
|
|
|
return (kmbx);
|
2003-05-16 19:58:30 +00:00
|
|
|
}
|
|
|
|
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
SIGADDSET(pthread->sigpend, sig);
|
|
|
|
if (info == NULL)
|
2003-06-30 06:16:50 +00:00
|
|
|
build_siginfo(&pthread->siginfo[sig-1], sig);
|
|
|
|
else if (info != &pthread->siginfo[sig-1])
|
|
|
|
memcpy(&pthread->siginfo[sig-1], info, sizeof(*info));
|
2004-12-18 18:07:37 +00:00
|
|
|
pthread->check_pending = 1;
|
|
|
|
if (!(pthread->attr.flags & PTHREAD_SCOPE_SYSTEM) &&
|
|
|
|
(pthread->blocked != 0) && !THR_IN_CRITICAL(pthread))
|
|
|
|
kse_thr_interrupt(&pthread->tcb->tcb_tmbx,
|
|
|
|
restart ? KSE_INTR_RESTART : KSE_INTR_INTERRUPT, 0);
|
2003-05-16 19:58:30 +00:00
|
|
|
if (suppress_handler == 0) {
|
2003-04-18 05:04:16 +00:00
|
|
|
/*
|
|
|
|
* Setup a signal frame and save the current threads
|
|
|
|
* state:
|
|
|
|
*/
|
2004-12-18 18:07:37 +00:00
|
|
|
if (pthread->state != PS_RUNNING) {
|
|
|
|
if (pthread->flags & THR_FLAGS_IN_RUNQ)
|
|
|
|
THR_RUNQ_REMOVE(pthread);
|
|
|
|
pthread->active_priority |= THR_SIGNAL_PRIORITY;
|
|
|
|
kmbx = _thr_setrunnable_unlocked(pthread);
|
|
|
|
}
|
2003-05-16 19:58:30 +00:00
|
|
|
}
|
2000-10-13 22:12:32 +00:00
|
|
|
}
|
2003-07-23 02:11:07 +00:00
|
|
|
return (kmbx);
|
2000-10-25 11:46:07 +00:00
|
|
|
}
|
|
|
|
|
2000-10-13 22:12:32 +00:00
|
|
|
/*
|
|
|
|
* Send a signal to a specific thread (ala pthread_kill):
|
|
|
|
*/
|
1999-12-17 00:56:36 +00:00
|
|
|
void
|
2003-04-18 05:04:16 +00:00
|
|
|
_thr_sig_send(struct pthread *pthread, int sig)
|
1999-12-17 00:56:36 +00:00
|
|
|
{
|
2003-04-18 05:04:16 +00:00
|
|
|
struct pthread *curthread = _get_curthread();
|
2003-07-23 02:11:07 +00:00
|
|
|
struct kse_mailbox *kmbx;
|
2003-04-18 05:04:16 +00:00
|
|
|
|
2003-07-17 23:02:30 +00:00
|
|
|
if (pthread->attr.flags & PTHREAD_SCOPE_SYSTEM) {
|
2003-08-05 22:46:00 +00:00
|
|
|
kse_thr_interrupt(&pthread->tcb->tcb_tmbx, KSE_INTR_SENDSIG, sig);
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
return;
|
|
|
|
}
|
2003-07-17 23:02:30 +00:00
|
|
|
|
2003-04-18 05:04:16 +00:00
|
|
|
/* Lock the scheduling queue of the target thread. */
|
|
|
|
THR_SCHED_LOCK(curthread, pthread);
|
2003-07-17 23:02:30 +00:00
|
|
|
if (_thread_sigact[sig - 1].sa_handler != SIG_IGN) {
|
2003-07-23 02:11:07 +00:00
|
|
|
kmbx = _thr_sig_add(pthread, sig, NULL);
|
2004-12-18 18:07:37 +00:00
|
|
|
/* Add a preemption point. */
|
|
|
|
if (kmbx == NULL && (curthread->kseg == pthread->kseg) &&
|
|
|
|
(pthread->active_priority > curthread->active_priority))
|
|
|
|
curthread->critical_yield = 1;
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
THR_SCHED_UNLOCK(curthread, pthread);
|
2003-07-23 02:11:07 +00:00
|
|
|
if (kmbx != NULL)
|
|
|
|
kse_wakeup(kmbx);
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
/* XXX
|
|
|
|
* If thread sent signal to itself, check signals now.
|
|
|
|
* It is not really needed, _kse_critical_leave should
|
|
|
|
* have already checked signals.
|
|
|
|
*/
|
|
|
|
if (pthread == curthread && curthread->check_pending)
|
|
|
|
_thr_sig_check_pending(curthread);
|
2004-12-18 18:07:37 +00:00
|
|
|
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
} else {
|
|
|
|
THR_SCHED_UNLOCK(curthread, pthread);
|
1999-12-17 00:56:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-12-18 18:07:37 +00:00
|
|
|
static inline void
|
|
|
|
thr_sigframe_restore(struct pthread *curthread, struct pthread_sigframe *psf)
|
1998-04-29 09:59:34 +00:00
|
|
|
{
|
2004-12-18 18:07:37 +00:00
|
|
|
kse_critical_t crit;
|
|
|
|
struct kse *curkse;
|
2001-06-29 17:09:07 +00:00
|
|
|
|
2004-12-18 18:07:37 +00:00
|
|
|
THR_THREAD_LOCK(curthread, curthread);
|
|
|
|
curthread->cancelflags = psf->psf_cancelflags;
|
|
|
|
crit = _kse_critical_enter();
|
|
|
|
curkse = curthread->kse;
|
|
|
|
KSE_SCHED_LOCK(curkse, curthread->kseg);
|
|
|
|
curthread->flags = psf->psf_flags;
|
|
|
|
curthread->interrupted = psf->psf_interrupted;
|
|
|
|
curthread->timeout = psf->psf_timeout;
|
|
|
|
curthread->data = psf->psf_wait_data;
|
|
|
|
curthread->wakeup_time = psf->psf_wakeup_time;
|
|
|
|
curthread->continuation = psf->psf_continuation;
|
|
|
|
KSE_SCHED_UNLOCK(curkse, curthread->kseg);
|
|
|
|
_kse_critical_leave(crit);
|
|
|
|
THR_THREAD_UNLOCK(curthread, curthread);
|
2000-10-13 22:12:32 +00:00
|
|
|
}
|
2000-11-09 05:08:26 +00:00
|
|
|
|
2004-12-18 18:07:37 +00:00
|
|
|
static inline void
|
|
|
|
thr_sigframe_save(struct pthread *curthread, struct pthread_sigframe *psf)
|
2000-10-13 22:12:32 +00:00
|
|
|
{
|
2004-12-18 18:07:37 +00:00
|
|
|
kse_critical_t crit;
|
|
|
|
struct kse *curkse;
|
2000-10-13 22:12:32 +00:00
|
|
|
|
2004-12-18 18:07:37 +00:00
|
|
|
THR_THREAD_LOCK(curthread, curthread);
|
|
|
|
psf->psf_cancelflags = curthread->cancelflags;
|
|
|
|
crit = _kse_critical_enter();
|
|
|
|
curkse = curthread->kse;
|
|
|
|
KSE_SCHED_LOCK(curkse, curthread->kseg);
|
2003-04-18 05:04:16 +00:00
|
|
|
/* This has to initialize all members of the sigframe. */
|
2004-12-18 18:07:37 +00:00
|
|
|
psf->psf_flags = (curthread->flags & (THR_FLAGS_PRIVATE | THR_FLAGS_EXITING));
|
|
|
|
psf->psf_interrupted = curthread->interrupted;
|
|
|
|
psf->psf_timeout = curthread->timeout;
|
|
|
|
psf->psf_wait_data = curthread->data;
|
|
|
|
psf->psf_wakeup_time = curthread->wakeup_time;
|
|
|
|
psf->psf_continuation = curthread->continuation;
|
|
|
|
KSE_SCHED_UNLOCK(curkse, curthread->kseg);
|
|
|
|
_kse_critical_leave(crit);
|
|
|
|
THR_THREAD_UNLOCK(curthread, curthread);
|
2003-02-17 10:05:18 +00:00
|
|
|
}
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
_thr_signal_init(void)
|
|
|
|
{
|
|
|
|
struct sigaction act;
|
2003-07-17 23:02:30 +00:00
|
|
|
__siginfohandler_t *sigfunc;
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
int i;
|
2003-08-18 03:58:29 +00:00
|
|
|
sigset_t sigset;
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
|
2003-08-18 03:58:29 +00:00
|
|
|
SIGFILLSET(sigset);
|
|
|
|
__sys_sigprocmask(SIG_SETMASK, &sigset, &_thr_initial->sigmask);
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
/* Enter a loop to get the existing signal status: */
|
|
|
|
for (i = 1; i <= _SIG_MAXSIG; i++) {
|
|
|
|
/* Get the signal handler details: */
|
2004-07-13 22:52:11 +00:00
|
|
|
if (__sys_sigaction(i, NULL, &_thread_sigact[i - 1]) != 0) {
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
/*
|
|
|
|
* Abort this process if signal
|
|
|
|
* initialisation fails:
|
|
|
|
*/
|
|
|
|
PANIC("Cannot read signal handler info");
|
|
|
|
}
|
2003-07-17 23:02:30 +00:00
|
|
|
/* Intall wrapper if handler was set */
|
|
|
|
sigfunc = _thread_sigact[i - 1].sa_sigaction;
|
|
|
|
if (((__sighandler_t *)sigfunc) != SIG_DFL &&
|
|
|
|
((__sighandler_t *)sigfunc) != SIG_IGN) {
|
|
|
|
act = _thread_sigact[i - 1];
|
|
|
|
act.sa_flags |= SA_SIGINFO;
|
2003-08-10 22:30:20 +00:00
|
|
|
act.sa_sigaction =
|
|
|
|
(__siginfohandler_t *)_thr_sig_handler;
|
2003-07-17 23:02:30 +00:00
|
|
|
__sys_sigaction(i, &act, NULL);
|
|
|
|
}
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Install the signal handler for SIGINFO. It isn't
|
|
|
|
* really needed, but it is nice to have for debugging
|
|
|
|
* purposes.
|
|
|
|
*/
|
|
|
|
_thread_sigact[SIGINFO - 1].sa_flags = SA_SIGINFO | SA_RESTART;
|
|
|
|
SIGEMPTYSET(act.sa_mask);
|
|
|
|
act.sa_flags = SA_SIGINFO | SA_RESTART;
|
|
|
|
act.sa_sigaction = (__siginfohandler_t *)&_thr_sig_handler;
|
|
|
|
if (__sys_sigaction(SIGINFO, &act, NULL) != 0) {
|
2003-08-18 03:58:29 +00:00
|
|
|
__sys_sigprocmask(SIG_SETMASK, &_thr_initial->sigmask, NULL);
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
/*
|
|
|
|
* Abort this process if signal initialisation fails:
|
|
|
|
*/
|
|
|
|
PANIC("Cannot initialize signal handler");
|
|
|
|
}
|
2003-08-18 03:58:29 +00:00
|
|
|
__sys_sigprocmask(SIG_SETMASK, &_thr_initial->sigmask, NULL);
|
2003-12-29 23:21:09 +00:00
|
|
|
__sys_sigaltstack(NULL, &_thr_initial->sigstk);
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_thr_signal_deinit(void)
|
|
|
|
{
|
|
|
|
int i;
|
2003-12-29 23:21:09 +00:00
|
|
|
struct pthread *curthread = _get_curthread();
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
|
2004-12-18 18:07:37 +00:00
|
|
|
/* Clear process pending signals. */
|
|
|
|
sigemptyset(&_thr_proc_sigpending);
|
|
|
|
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
/* Enter a loop to get the existing signal status: */
|
|
|
|
for (i = 1; i <= _SIG_MAXSIG; i++) {
|
|
|
|
/* Check for signals which cannot be trapped: */
|
|
|
|
if (i == SIGKILL || i == SIGSTOP) {
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the signal handler details: */
|
2003-08-10 22:30:20 +00:00
|
|
|
else if (__sys_sigaction(i, &_thread_sigact[i - 1],
|
|
|
|
NULL) != 0) {
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
/*
|
|
|
|
* Abort this process if signal
|
|
|
|
* initialisation fails:
|
|
|
|
*/
|
|
|
|
PANIC("Cannot set signal handler info");
|
|
|
|
}
|
|
|
|
}
|
2003-12-29 23:21:09 +00:00
|
|
|
__sys_sigaltstack(&curthread->sigstk, NULL);
|
o Use a daemon thread to monitor signal events in kernel, if pending
signals were changed in kernel, it will retrieve the pending set and
try to find a thread to dispatch the signal. The dispatching process
can be rolled back if the signal is no longer in kernel.
o Create two functions _thr_signal_init() and _thr_signal_deinit(),
all signal action settings are retrieved from kernel when threading
mode is turned on, after a fork(), child process will reset them to
user settings by calling _thr_signal_deinit(). when threading mode
is not turned on, all signal operations are direct past to kernel.
o When a thread generated a synchoronous signals and its context returned
from completed list, UTS will retrieve the signal from its mailbox and try
to deliver the signal to thread.
o Context signal mask is now only used when delivering signals, thread's
current signal mask is always the one in pthread structure.
o Remove have_signals field in pthread structure, replace it with
psf_valid in pthread_signal_frame. when psf_valid is true, in context
switch time, thread will backout itself from some mutex/condition
internal queues, then begin to process signals. when a thread is not
at blocked state and running, check_pending indicates there are signals
for the thread, after preempted and then resumed time, UTS will try to
deliver signals to the thread.
o At signal delivering time, not only pending signals in thread will be
scanned, process's pending signals will be scanned too.
o Change sigwait code a bit, remove field sigwait in pthread_wait_data,
replace it with oldsigmask in pthread structure, when a thread calls
sigwait(), its current signal mask is backuped to oldsigmask, and waitset
is copied to its signal mask and when the thread gets a signal in the
waitset range, its current signal mask is restored from oldsigmask,
these are done in atomic fashion.
o Two additional POSIX APIs are implemented, sigwaitinfo() and sigtimedwait().
o Signal code locking is better than previous, there is fewer race conditions.
o Temporary disable most of code in _kse_single_thread as it is not safe
after fork().
2003-06-28 09:55:02 +00:00
|
|
|
}
|
|
|
|
|