sig.c revision cbdce38d10d5be98a33cfee749ff29d7cee05b58
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
#pragma ident "%Z%%M% %I% %E% SMI"
#include <sys/sysmacros.h>
#include <sys/ucontext.h>
#include <sys/schedctl.h>
/* MUST be contiguous */
k_sigset_t nullsmask = {0, 0};
0};
static int isjobstop(int);
/*
* Internal variables for counting number of user thread stop requests posted.
* They may not be accurate at some special situation such as that a virtually
* stopped thread starts to run.
*/
static int num_utstop;
/*
* Internal variables for broadcasting an event when all thread stop requests
* are processed.
*/
static kcondvar_t utstop_cv;
static kmutex_t thread_stop_lock;
void del_one_utstop(void);
/*
* Send the specified signal to the specified process.
*/
void
{
mutex_enter(&p->p_lock);
mutex_exit(&p->p_lock);
}
/*
* Send the specified signal to the specified thread.
*/
void
{
mutex_enter(&p->p_lock);
mutex_exit(&p->p_lock);
}
int
{
}
/*
* Return true if the signal can safely be discarded on generation.
* That is, if there is no need for the signal on the receiving end.
* The answer is true if the process is a zombie or
* if all of these conditions are true:
* the signal is being ignored
* the process is single-threaded
* the signal is not being traced by /proc
* the signal is not blocked by the process
*/
static int
{
return (t == NULL || /* if zombie or ... */
t->t_forw == t && /* and single-threaded */
}
/*
* Return true if this thread is going to eat this signal soon.
* Note that, if the signal is SIGKILL, we force stopped threads to be
* set running (to make SIGKILL be a sure kill), but only if the process
* is not currently locked by /proc (the P_PR_LOCK flag). Code in /proc
* relies on the fact that a process will not change shape while P_PR_LOCK
* is set (it drops and reacquires p->p_lock while leaving P_PR_LOCK set).
* We wish that we could simply call prbarrier() below, in sigtoproc(), to
* ensure that the process is not locked by /proc, but prbarrier() drops
* and reacquires p->p_lock and dropping p->p_lock here would be damaging.
*/
int
{
int rval = 0;
ASSERT(THREAD_LOCK_HELD(t));
/*
* Do not do anything if the target thread has the signal blocked.
*/
if (!signal_is_blocked(t, sig)) {
if (ISWAKEABLE(t) || ISWAITING(t)) {
setrun_locked(t);
rval = 1;
t->t_dtrace_stop = 0;
setrun_locked(t);
aston(t); /* make it do issig promptly */
rval = 1;
rval = 1;
}
}
return (rval);
}
/*
* Post a signal.
* If a non-null thread pointer is passed, then post the signal
*/
void
{
return;
/*
* Regardless of origin or directedness,
* SIGKILL kills all lwps in the process immediately
* and jobcontrol signals affect all lwps in the process.
*/
t = NULL;
/*
* The SSCONT flag will remain set until a stopping
* signal comes in (below). This is harmless.
*/
p->p_stopsig = 0;
do {
}
do {
}
}
/*
* This test has a race condition which we can't fix:
* By the time the stopping signal is received by
*/
do {
}
}
if (sig_discardable(p, sig)) {
return;
}
if (t != NULL) {
/*
* This is a directed signal, wake up the lwp.
*/
if (ext)
thread_lock(t);
(void) eat_signal(t, sig);
thread_unlock(t);
/*
* Make sure that some lwp that already exists
* in the process fields the signal soon.
* Wake up an interruptibly sleeping lwp if necessary.
* For SIGKILL make all of the lwps see the signal;
* This is needed to guarantee a sure kill for processes
* with a mix of realtime and non-realtime threads.
*/
int su = 0;
if (ext)
do {
break;
}
su++;
/*
* If the process is deadlocked, make somebody run and die.
*/
!(p->p_proc_flag & P_PR_LOCK)) {
p->p_lwprcnt++;
}
}
}
static int
{
/*
* If SIGCONT has been posted since we promoted this signal
* from pending to current, then don't do a jobcontrol stop.
*/
mutex_exit(&p->p_lock);
/*
* Only the first lwp to continue notifies the parent.
*/
else {
p->p_wcode = CLD_CONTINUED;
}
mutex_enter(&p->p_lock);
}
return (1);
}
return (0);
}
/*
* Returns true if the current process has a signal to process, and
* the signal is not held. The signal to process is put in p_cursig.
* This is asked at least once each time a process enters the system
* (though this can usually be done without actually calling issig by
* checking the pending signal masks). A signal does not do anything
* directly to a process; it sets a flag that asks the process to do
* something to itself.
*
* The "why" argument indicates the allowable side-effects of the call:
*
* FORREAL: Extract the next pending signal from p_sig into p_cursig;
* stop the process if a stop has been requested or if a traced signal
* is pending.
*
* JUSTLOOKING: Don't stop the process, just indicate whether or not
* a signal might be pending (FORREAL is needed to tell for sure).
*
* XXX: Changes to the logic in these routines should be propagated
* to lm_sigispending(). See bug 1201594.
*/
static int issig_forreal(void);
static int issig_justlooking(void);
int
{
}
static int
issig_justlooking(void)
{
/*
* This function answers the question:
* "Is there any reason to call issig_forreal()?"
*
* We have to answer the question w/o grabbing any locks
* because we are (most likely) being called after we
* put ourselves on the sleep queue.
*/
if (t->t_dtrace_stop | t->t_dtrace_sig)
return (1);
/*
* Another piece of complexity in this process. When single-stepping a
* process, we don't want an intervening signal or TP_PAUSE request to
* suspend the current thread. Otherwise, the controlling process will
* hang beacuse we will be stopped with TS_PSTART set in t_schedflag.
* We will trigger any remaining signals when we re-enter the kernel on
* the single step trap.
*/
return (0);
(lwp->lwp_nostop == 0 &&
(t->t_proc_flag &
return (1);
return (0);
if (schedctl_sigblock(t)) /* all blockable signals blocked */
else
if (!sigisempty(&set)) {
int sig;
/*
* Don't promote a signal that will stop
* the process when lwp_nostop is set.
*/
if (!lwp->lwp_nostop ||
return (1);
}
}
}
return (0);
}
static int
issig_forreal(void)
{
int toproc = 0;
int sigcld_found = 0;
int nostop_break = 0;
mutex_enter(&p->p_lock);
if (t->t_dtrace_stop | t->t_dtrace_sig) {
if (t->t_dtrace_stop) {
/*
* If DTrace's "stop" action has been invoked on us,
* set TP_PRSTOP.
*/
t->t_proc_flag |= TP_PRSTOP;
}
if (t->t_dtrace_sig != 0) {
/*
* Post the signal generated as the result of
* DTrace's "raise" action as a normal signal before
* the full-fledged signal checking begins.
*/
t->t_dtrace_sig = 0;
}
}
for (;;) {
t->t_sig_check = 1;
break;
}
/*
* Another piece of complexity in this process. When
* single-stepping a process, we don't want an intervening
* signal or TP_PAUSE request to suspend the current thread.
* Otherwise, the controlling process will hang beacuse we will
* be stopped with TS_PSTART set in t_schedflag. We will
* trigger any remaining signals when we re-enter the kernel on
* the single step trap.
*/
sig = 0;
break;
}
/*
* Hold the lwp here for watchpoint manipulation.
*/
continue;
}
/*
* Make sure we call ISSIG() in post_syscall()
* to re-validate this current signal.
*/
t->t_sig_check = 1;
}
break;
}
/*
* If the request is PR_CHECKPOINT, ignore the rest of signals
* or requests. Honor other stop requests or signals later.
* Go back to top of loop here to check if an exit or hold
* event has occurred while stopped.
*/
stop(PR_CHECKPOINT, 0);
continue;
}
/*
* Honor SHOLDFORK1, SHOLDWATCH, and TP_HOLDLWP before dealing
* with signals or /proc. Another lwp is executing fork1(),
* or is undergoing watchpoint activity (remapping a page),
* or is executing lwp_suspend() on this lwp.
* Again, go back to top of loop to check if an exit
* or hold event has occurred while stopped.
*/
continue;
}
/*
* Honor requested stop before dealing with the
* current signal; a debugger may change it.
* Do not want to go back to loop here since this is a special
* stop that means: make incremental progress before the next
* stop. The danger is that returning to top of loop would most
* likely drop the thread right back here to stop soon after it
* was continued, violating the incremental progress request.
*/
stop(PR_REQUESTED, 0);
/*
* If a debugger wants us to take a signal it will have
* left it in lwp->lwp_cursig. If lwp_cursig has been cleared
* or if it's being ignored, we continue on looking for another
* signal. Otherwise we return the specified signal, provided
* it's not a signal that causes a job control stop.
*
* When stopped on PR_JOBCONTROL, there is no current
* signal; we cancel lwp->lwp_cursig temporarily before
* calling isjobstop(). The current signal may be reset
* by a debugger while we are stopped in isjobstop().
*/
lwp->lwp_cursig = 0;
lwp->lwp_extsig = 0;
}
break;
}
/*
* The signal is being ignored or it caused a
* job-control stop. If another current signal
* has not been established, return the current
* siginfo, if any, to the memory manager.
*/
}
/*
* Loop around again in case we were stopped
* on a job control signal and a /proc stop
* request was posted or another current signal
* was established while we were stopped.
*/
continue;
}
/*
* Some lwp in the process has already stopped
* showing PR_JOBCONTROL. This is a stop in
* sympathy with the other lwp, even if this
* lwp is blocking the stopping signal.
*/
continue;
}
/*
* Loop on the pending signals until we find a
* non-held signal that is traced or not ignored.
* First check the signals pending for the lwp,
* then the signals pending for the process as a whole.
*/
for (;;) {
sigcld_found = 1;
toproc = 0;
ext = 1;
break;
}
sigcld_found = 1;
toproc = 1;
ext = 1;
break;
}
} else {
/* no signal was found */
break;
}
}
if (sig == 0) { /* no signal was found */
}
break;
}
/*
* If we have been informed not to stop (i.e., we are being
* called from within a network operation), then don't promote
* the signal at this time, just return the signal number.
* We will call issig() again later when it is safe.
*
* fsig() does not return a jobcontrol stopping signal
* with a default action of stopping the process if
* lwp_nostop is set, so we won't be causing a bogus
* EINTR by this action. (Such a signal is eaten by
* isjobstop() when we loop around to do final checks.)
*/
if (lwp->lwp_nostop) {
nostop_break = 1;
break;
}
/*
* Promote the signal from pending to current.
*
* Note that sigdeq() will set lwp->lwp_curinfo to NULL
* if no siginfo_t exists for this signal.
*/
/*
* Loop around to check for requested stop before
* performing the usual current-signal actions.
*/
}
mutex_exit(&p->p_lock);
/*
* If SIGCLD was dequeued, search for other pending SIGCLD's.
* Don't do it if we are returning SIGCLD and the signal
* handler will be reset by psig(); this enables reliable
* delivery of SIGCLD even when using the old, broken
* signal() interface for setting the signal handler.
*/
if (sigcld_found &&
SIGCLD)))
if (sig != 0)
(void) undo_watch_step(NULL);
/*
* If we have been blocked since the p_lock was dropped off
* above, then this promoted signal might have been handled
* already when we were on the way back from sleep queue, so
* just ignore it.
* If we have been informed not to stop, just return the signal
* number. Also see comments above.
*/
if (!nostop_break) {
}
return (sig != 0);
}
/*
* Return true if the process is currently stopped showing PR_JOBCONTROL.
* This is true only if all of the process's lwp's are so stopped.
* If this is asked by one of the lwps in the process, exclude that lwp.
*/
int
jobstopped(proc_t *p)
{
kthread_t *t;
return (0);
do {
thread_lock(t);
/* ignore current, zombie and suspended lwps in the test */
SUSPENDED(t)) &&
(t->t_state != TS_STOPPED ||
t->t_whystop != PR_JOBCONTROL)) {
thread_unlock(t);
return (0);
}
thread_unlock(t);
return (1);
}
/*
* Put ourself (curthread) into the stopped state and notify tracers.
*/
void
{
int procstop;
int flags = TS_ALLSTART;
/*
* Can't stop a system process.
*/
return;
/*
* Don't stop an lwp with SIGKILL pending.
* Don't stop if the process or lwp is exiting.
*/
(t->t_proc_flag & TP_LWPEXIT) ||
p->p_stopsig = 0;
return;
}
}
/*
* Make sure we don't deadlock on a recursive call to prstop().
* prstop() sets the lwp_nostop flag.
*/
if (lwp->lwp_nostop)
return;
/*
* Make sure the lwp is in an orderly state for inspection
* by a debugger through /proc or for dumping via core().
*/
mutex_exit(&p->p_lock);
(void) undo_watch_step(NULL);
mutex_enter(&p->p_lock);
switch (why) {
case PR_CHECKPOINT:
/*
* The situation may have changed since we dropped
* and reacquired p->p_lock. Double-check now
* whether we should stop or not.
*/
if (!(t->t_proc_flag & TP_CHKPT)) {
t->t_proc_flag &= ~TP_STOPPING;
return;
}
t->t_proc_flag &= ~TP_CHKPT;
break;
case PR_JOBCONTROL:
break;
case PR_SUSPENDED:
/*
* The situation may have changed since we dropped
* and reacquired p->p_lock. Double-check now
* whether we should stop or not.
*/
if (what == SUSPEND_PAUSE) {
if (!(t->t_proc_flag & TP_PAUSE)) {
t->t_proc_flag &= ~TP_STOPPING;
return;
}
flags &= ~TS_UNPAUSE;
} else {
if (!((t->t_proc_flag & TP_HOLDLWP) ||
t->t_proc_flag &= ~TP_STOPPING;
return;
}
/*
* If SHOLDFORK is in effect and we are stopping
* while asleep (not at the top of the stack),
* we return now to allow the hold to take effect
* when we reach the top of the kernel stack.
*/
t->t_proc_flag &= ~TP_STOPPING;
return;
}
}
break;
default: /* /proc stop */
/*
* Do synchronous stop unless the async-stop flag is set.
* If why is PR_REQUESTED and t->t_dtrace_stop flag is set,
* then no debugger is present and we also do synchronous stop.
*/
!(p->p_proc_flag & P_PR_ASYNC)) {
int notify;
notify = 0;
continue;
}
/*
* Don't actually wake it up if it's
* in one of the lwp_*() syscalls.
* Mark it virtually stopped and
* notify /proc waiters (below).
*/
else {
notify = 1;
}
}
/* Move waiting thread to run queue */
/*
* force the thread into the kernel
* if it is not already there.
*/
}
/*
* We do this just in case one of the threads we asked
* to stop is in holdlwps() (called from cfork()) or
* lwp_suspend().
*/
cv_broadcast(&p->p_holdlwps);
}
break;
}
t->t_stoptime = stoptime;
/*
* Determine if the whole process is jobstopped.
*/
if (jobstopped(p)) {
int sig;
mutex_exit(&p->p_lock);
/*
* The last lwp to stop notifies the parent.
* Turn off the CLDCONT flag now so the first
* lwp to continue knows what to do.
*/
p->p_wcode = CLD_STOPPED;
/*
* Grab p->p_lock before releasing pidlock so the
* parent and the child don't have a race condition.
*/
mutex_enter(&p->p_lock);
p->p_stopsig = 0;
/*
* Set p->p_stopsig and wake up sleeping lwps
* so they will stop in sympathy with this lwp.
*/
pokelwps(p);
/*
* We do this just in case one of the threads we asked
* to stop is in holdlwps() (called from cfork()) or
* lwp_suspend().
*/
cv_broadcast(&p->p_holdlwps);
}
}
/*
* Do process-level notification when all lwps are
* either stopped on events of interest to /proc
* or are stopped showing PR_SUSPENDED or are zombies.
*/
procstop = 1;
continue;
case TS_ZOMB:
break;
case TS_STOPPED:
/* neither ISTOPPED nor SUSPENDED? */
if ((tx->t_schedflag &
procstop = 0;
break;
case TS_SLEEP:
/* not paused for watchpoints? */
procstop = 0;
break;
default:
procstop = 0;
break;
}
}
if (procstop) {
/* there must not be any remapped watched pages now */
if (p->p_proc_flag & P_PR_PTRACE) {
/* ptrace() compatibility */
mutex_exit(&p->p_lock);
p->p_wcode = CLD_TRAPPED;
/*
* Grab p->p_lock before releasing pidlock so
* parent and child don't have a race condition.
*/
mutex_enter(&p->p_lock);
}
if (p->p_trace) /* /proc */
}
if (why != PR_SUSPENDED) {
/*
* Special notification for creation of the agent lwp.
*/
if (t == p->p_agenttp &&
(t->t_proc_flag & TP_PRSTOP) &&
p->p_trace)
/*
* The situation may have changed since we dropped
* and reacquired p->p_lock. Double-check now
* whether we should stop or not.
*/
if (!(t->t_proc_flag & TP_STOPPING)) {
if (t->t_proc_flag & TP_PRSTOP)
t->t_proc_flag |= TP_STOPPING;
}
}
}
if (why == PR_SUSPENDED) {
/*
* We always broadcast in the case of SUSPEND_PAUSE. This is
* because checks for TP_PAUSE take precedence over checks for
* SHOLDWATCH. If a thread is trying to stop because of
* SUSPEND_PAUSE and tries to do a holdwatch(), it will be
* waiting for the rest of the threads to enter a stopped state.
* If we are stopping for a SUSPEND_PAUSE, we may be the last
* lwp and not know it, so broadcast just in case.
*/
if (what == SUSPEND_PAUSE ||
cv_broadcast(&p->p_holdlwps);
}
/*
* Need to do this here (rather than after the thread is officially
* stopped) because we can't call mutex_enter from a stopped thread.
*/
if (why == PR_CHECKPOINT)
thread_lock(t);
t->t_schedflag |= flags;
t->t_whatstop = (short)what;
(void) new_mstate(t, LMS_STOPPED);
thread_stop(t); /* set stop state and drop lock */
/*
* We may have gotten a SIGKILL or a SIGCONT when
* we released p->p_lock; make one last check.
* Also check for a /proc run-on-last-close.
*/
(t->t_proc_flag & TP_LWPEXIT) ||
p->p_stopsig = 0;
thread_lock(t);
setrun_locked(t);
} else if (why == PR_JOBCONTROL) {
/*
* This resulted from a SIGCONT posted
* while we were not holding p->p_lock.
*/
p->p_stopsig = 0;
thread_lock(t);
t->t_schedflag |= TS_XSTART;
setrun_locked(t);
}
} else if (!(t->t_proc_flag & TP_STOPPING)) {
/*
* This resulted from a /proc run-on-last-close.
*/
thread_lock(t);
t->t_schedflag |= TS_PSTART;
setrun_locked(t);
}
}
t->t_proc_flag &= ~TP_STOPPING;
mutex_exit(&p->p_lock);
swtch();
setallwatch(); /* reestablish any watchpoints set while stopped */
mutex_enter(&p->p_lock);
prbarrier(p); /* barrier against /proc locking */
}
/* Interface for resetting user thread stop count. */
void
utstop_init(void)
{
num_utstop = 0;
}
/* Interface for registering a user thread stop request. */
void
add_one_utstop(void)
{
num_utstop++;
}
/* Interface for cancelling a user thread stop request */
void
del_one_utstop(void)
{
num_utstop--;
if (num_utstop == 0)
}
/* Interface to wait for all user threads to be stopped */
void
{
if (num_utstop > 0)
}
/*
* Perform the action specified by the current signal.
* The usual sequence is:
* if (issig())
* psig();
* The signal bit has already been cleared by issig(),
* the current signal number has been stored in lwp_cursig,
* and the current siginfo is now referenced by lwp_curinfo.
*/
void
psig(void)
{
void (*func)();
mutex_enter(&p->p_lock);
code = CLD_KILLED;
lwp_exit();
return; /* not reached */
}
/*
* Re-check lwp_cursig after we acquire p_lock. Since p_lock was
* dropped between issig() and psig(), a debugger may have cleared
* lwp_cursig via /proc in the intervening window.
*/
if (sig == 0) {
if (lwp->lwp_curinfo) {
}
}
mutex_exit(&p->p_lock);
return;
}
/*
* The signal disposition could have changed since we promoted
* this signal from pending to current (we dropped p->p_lock).
* This can happen only in a multi-threaded process.
*/
lwp->lwp_cursig = 0;
lwp->lwp_extsig = 0;
if (lwp->lwp_curinfo) {
}
}
mutex_exit(&p->p_lock);
return;
}
/*
* We check lwp_curinfo first since pr_setsig can actually
* stuff a sigqueue_t there for SIGKILL.
*/
if (lwp->lwp_curinfo) {
}
}
/*
* If we have a sigqueue_t, its sq_external value
* trumps the lwp_extsig value. It is theoretically
* possible to make lwp_extsig reflect reality, but it
* would unnecessarily complicate things elsewhere.
*/
}
mutex_exit(&p->p_lock);
} else {
/*
* If DTrace user-land tracing is active, give DTrace a
* chance to defer the signal until after tracing is
* complete.
*/
if (t->t_dtrace_on && dtrace_safe_defer_signal()) {
mutex_exit(&p->p_lock);
return;
}
/*
* save siginfo pointer here, in case the
* the signal's reset bit is on
*
* The presence of a current signal prevents paging
* from succeeding over a network. We copy the current
* signal information to the side and cancel the current
* signal so that sendsig() will succeed.
*/
if (sqp) {
/* EMPTY */;
} else {
}
}
else
lwp->lwp_cursig = 0;
lwp->lwp_extsig = 0;
if (lwp->lwp_curinfo) {
/* p->p_killsqp is freed by freeproc */
}
mutex_exit(&p->p_lock);
if (p->p_model == DATAMODEL_NATIVE)
#ifdef _SYSCALL32_IMPL
else
#endif /* _SYSCALL32_IMPL */
if (rc)
return;
ext = 0; /* lwp_extsig was set above */
pid = -1;
ctid = 0;
}
/*
* Terminate all LWPs but don't discard them.
* If another lwp beat us to the punch by calling exit(),
* evaporate now.
*/
proc_is_exiting(p);
if (exitlwps(1) != 0) {
mutex_enter(&p->p_lock);
lwp_exit();
}
/* if we got a SIGKILL from anywhere, no core dump */
} else {
#ifdef C2_AUDIT
if (audit_active) /* audit core dump */
#endif
code = CLD_DUMPED;
#ifdef C2_AUDIT
if (audit_active) /* audit core dump */
#endif
}
}
/*
* Generate a contract event once if the process is killed
* by a signal.
*/
if (ext) {
proc_is_exiting(p);
if (exitlwps(0) != 0) {
mutex_enter(&p->p_lock);
lwp_exit();
}
zoneid);
}
}
/*
* Find next unheld signal in ssp for thread t.
*/
int
{
int i;
/*
* Don't promote any signals for the parent of a vfork()d
* child that hasn't yet released the parent's memory.
*/
return (0);
/*
* Don't promote stopping signals (except SIGSTOP) for a child
* of vfork() that hasn't yet released the parent's memory.
*/
/*
* Don't promote a signal that will stop
* the process when lwp_nostop is set.
*/
if (ttolwp(t)->lwp_nostop) {
if (!p->p_pgidp->pid_pgorphaned) {
}
}
/*
* Choose SIGKILL and SIGPROF before all other pending signals.
* The rest are promoted in signal number order.
*/
return (SIGKILL);
return (SIGPROF);
}
return (0);
}
void
{
kthread_t *t;
/*
* Honor the SA_SIGINFO flag if the signal is being caught.
* Force the SA_SIGINFO flag if the signal is not being caught.
* This is necessary to make sigqueue() and sigwaitinfo() work
* properly together when the signal is set to default or is
* being temporarily ignored.
*/
else
if (flags & SA_RESETHAND)
else
}
if (flags & SA_NODEFER)
else
if (flags & SA_RESTART)
else
if (flags & SA_ONSTACK)
else
/*
* Setting the signal action to SIG_IGN results in the
* discarding of all pending signals of that signal number.
* Setting the signal action to SIG_DFL does the same *only*
* if the signal's default behavior is to be ignored.
*/
t = p->p_tlist;
do {
} else {
/*
* The signal action is being set to SIG_DFL and the default
* behavior is to do something: make sure it is not ignored.
*/
}
if (flags & SA_NOCLDWAIT)
else
if (flags & SA_NOCLDSTOP)
else
mutex_exit(&p->p_lock);
}
mutex_enter(&p->p_lock);
}
}
}
/*
* Set all signal actions not already set to SIG_DFL or SIG_IGN to SIG_DFL.
* Called from exec_common() for a process undergoing execve()
* and from cfork() for a newly-created child of vfork().
* In the vfork() case, 'p' is not the current process.
* In both cases, there is only one thread in the process.
*/
void
sigdefault(proc_t *p)
{
int sig;
}
}
}
sigfillset(&p->p_siginfo);
}
void
{
case CLD_EXITED:
case CLD_DUMPED:
case CLD_KILLED:
/*
* The broadcast on p_srwchan_cv is a kludge to
* wakeup a possible thread in uadmin(A_SHUTDOWN).
*/
/*
* Add to newstate list of the parent
*/
}
break;
case CLD_STOPPED:
case CLD_CONTINUED:
}
break;
}
if (sqp)
}
/*
* Common code called from sigcld() and issig_forreal()
* Give the parent process a SIGCLD if it does not have one pending,
* else mark the child process so a SIGCLD can be posted later.
*/
static void
{
/*
* If a SIGCLD is pending, or if SIGCLD is not now being caught,
* then just mark the child process so that its SIGCLD will
* be posted later, when the first SIGCLD is taken off the
* queue or when the parent is ready to receive it, if ever.
*/
else {
/*
* This can only happen when the parent is init.
* (See call to sigcld(q, NULL) in exit().)
* Use KM_NOSLEEP to avoid deadlock.
*/
} else {
}
}
if (sqp)
}
/*
* Search for a child that has a pending SIGCLD for us, the parent.
* The queue of SIGCLD signals is implied by the list of children.
* We post the SIGCLD signals one at a time so they don't get lost.
* When one is dequeued, another is enqueued, until there are no more.
*/
void
{
/*
* Don't bother if SIGCLD is not now being caught.
*/
return;
return;
}
}
}
/*
* count number of sigqueue send by sigaddqa()
*/
void
{
else
}
int
{
return (EPERM);
/* Make sure we should be setting si_pid and friends */
return (EAGAIN);
mutex_enter(&p->p_lock);
mutex_exit(&p->p_lock);
} else {
mutex_enter(&p->p_lock);
/*
* XXX: Should be KM_SLEEP but
* we have to avoid deadlock.
*/
mutex_exit(&p->p_lock);
}
}
}
return (0);
}
int
{
int error;
return (EPERM);
return (error);
}
/*
* Dequeue a queued siginfo structure.
* If a non-null thread pointer is passed then dequeue from
* the thread queue, otherwise dequeue from the process queue.
*/
void
{
if (t != NULL) {
psqp = &t->t_sigqueue;
} else {
psqp = &p->p_sigqueue;
}
for (;;) {
return;
break;
else
}
t->t_sig_check = 1;
} else {
set_proc_ast(p);
}
break;
}
}
}
/*
* Delete a queued SIGCLD siginfo structure matching the k_siginfo_t argument.
*/
void
{
int another_sigcld = 0;
mutex_enter(&p->p_lock);
mutex_exit(&p->p_lock);
return;
}
psqp = &p->p_sigqueue;
for (;;) {
mutex_exit(&p->p_lock);
return;
}
break;
another_sigcld = 1;
}
}
another_sigcld = 1;
}
if (!another_sigcld) {
}
mutex_exit(&p->p_lock);
}
/*
* Delete queued siginfo structures.
* If a non-null thread pointer is passed then delete from
* the thread queue, otherwise delete from the process queue.
*/
void
{
/*
* We must be holding p->p_lock unless the process is
* being reaped or has failed to get started on fork.
*/
psqp = &t->t_sigqueue;
else
psqp = &p->p_sigqueue;
while (*psqp) {
} else
}
}
/*
* Insert a siginfo structure into a queue.
* If a non-null thread pointer is passed then add to the thread queue,
* otherwise add to the process queue.
*
* The function sigaddqins() is called with sigqueue already allocated.
* It is called from sigaddqa() and sigaddq() below.
*
* The value of si_code implicitly indicates whether sigp is to be
* explicitly queued, or to be queued to depth one.
*/
static void
{
sigqueue_t **psqp;
/*
* issig_forreal() doesn't bother dequeueing signals if SKILLED
* is set, and even if it did, we would want to avoid situation
* (which would be unique to SIGKILL) where one thread dequeued
* the sigqueue_t and another executed psig(). So we create a
* separate stash for SIGKILL's sigqueue_t. Because a second
* SIGKILL can set SEXTKILLED, we overwrite the existing entry
* if (and only if) it was non-extracontractual.
*/
siginfofree(p->p_killsqp);
} else {
}
return;
}
if (t != NULL) /* directed to a thread */
psqp = &t->t_sigqueue;
else /* directed to a process */
psqp = &p->p_sigqueue;
;
} else {
return;
}
}
}
}
/*
* The function sigaddqa() is called with sigqueue already allocated.
* If signal is ignored, discard but guarantee KILL and generation semantics.
* It is called from sigqueue() and other places.
*/
void
{
if (sig_discardable(p, sig))
else
sigaddqins(p, t, sigqp);
}
/*
* Allocate the sigqueue_t structure and call sigaddqins().
*/
void
{
/*
* If the signal will be discarded by sigtoproc() or
* if the process isn't requesting siginfo and it isn't
* blocking the signal (it *could* change it's mind while
* the signal is pending) then don't bother creating one.
*/
if (!sig_discardable(p, sig) &&
sigaddqins(p, t, sqp);
}
}
/*
* Handle stop-on-fault processing for the debugger. Returns 0
* if the fault is cleared during the stop, nonzero if it isn't.
*/
int
{
/*
* Record current fault and siginfo structure so debugger can
* find it.
*/
mutex_enter(&p->p_lock);
lwp->lwp_curflt = 0;
mutex_exit(&p->p_lock);
return (fault);
}
void
{
}
void
{
}
void
{
}
/*
* Return non-zero if curthread->t_sig_check should be set to 1, that is,
* if there are any signals the thread might take on return from the kernel.
* If ksigset_t's were a single word, we would do:
* return (((p->p_sig | t->t_sig) & ~t->t_hold) & fillset);
*/
int
{
/*
* If signals are blocked via the schedctl interface
* then we only check for the unmaskable signals.
*/
}
/* ONC_PLUS EXTRACT START */
void
{
proc_t *p;
int owned;
/*
* Mask out all signals except SIGHUP, SIGINT, SIGQUIT
* and SIGTERM. (Preserving the existing masks).
* This function supports the -intr nfs and ufs mount option.
*/
/*
* don't do kernel threads
*/
return;
/*
* get access to signal mask
*/
if (!owned)
mutex_enter(&p->p_lock);
/*
* remember the current mask
*/
/*
* mask out all signals
*/
/*
* Unmask the non-maskable signals (e.g., KILL), as long as
* they aren't already masked (which could happen at exit).
* The first sigdiffset sets lmask to (cantmask & ~curhold). The
* second sets the current hold mask to (~0 & ~lmask), which reduces
* to (~cantmask | curhold).
*/
/*
* Re-enable HUP, QUIT, and TERM iff they were originally enabled
* Re-enable INT if it's originally enabled and the NFS mount option
* nointr is not set.
*/
/*
* release access to signal mask
*/
if (!owned)
mutex_exit(&p->p_lock);
/*
* Indicate that this lwp is not to be stopped.
*/
lwp->lwp_nostop++;
}
/* ONC_PLUS EXTRACT END */
void
{
proc_t *p;
int owned;
/*
* Reset previous mask (See sigintr() above)
*/
if (!owned)
mutex_enter(&p->p_lock);
/* so unmasked signals will be seen */
if (!owned)
mutex_exit(&p->p_lock);
}
}
void
{
proc_t *p;
int owned;
/*
* Save current signal mask in oldmask, then
* set it to newmask.
*/
if (!owned)
mutex_enter(&p->p_lock);
if (!owned)
mutex_exit(&p->p_lock);
}
}
/*
* Return true if the signal number is in range
* and the signal code specifies signal queueing.
*/
int
{
switch (code) {
case SI_QUEUE:
case SI_TIMER:
case SI_ASYNCIO:
case SI_MESGQ:
return (1);
}
}
return (0);
}
#ifndef UCHAR_MAX
#define UCHAR_MAX 255
#endif
/*
* The entire pool (with maxcount entries) is pre-allocated at
*/
{
size_t i;
sqh->sqb_pexited = 0;
for (i = maxcount - 1; i != 0; i--) {
}
return (sqh);
}
static void sigqrel(sigqueue_t *);
/*
* pre-allocated pool.
*/
{
sq->sq_external = 0;
} else {
}
}
return (sq);
}
/*
* Return a sigqueue structure back to the pre-allocated pool.
*/
static void
{
/* make sure that p_lock of the affected process is held */
} else {
}
}
/*
* Free up the pre-allocated sigqueue headers of sigqueue pool
* and signotify pool, if possible.
* Called only by the owning process during exec() and exit().
*/
void
{
sigqhdrfree(p->p_sigqhdr);
}
sigqhdrfree(p->p_signhdr);
}
}
/*
* Free up the pre-allocated header and sigq pool if possible.
*/
void
{
} else {
}
}
/*
* Free up a single sigqueue structure.
* No other code should free a sigqueue directly.
*/
void
{
else
}
}
/*
* Generate a synchronous signal caused by a hardware
* condition encountered by an lwp. Called from trap().
*/
void
{
if (curthread->t_dtrace_on)
mutex_enter(&p->p_lock);
/*
* Avoid a possible infinite loop if the lwp is holding the
* signal generated by a trap of a restartable instruction or
* if the signal so generated is being ignored by the process.
*/
if (restartable &&
}
mutex_exit(&p->p_lock);
}
#ifdef _SYSCALL32_IMPL
/*
* It's tricky to transmit a sigval between 32-bit and 64-bit
* process, since in the 64-bit world, a pointer and an integer
* are different sizes. Since we're constrained by the standards
* world not to change the types, and it's unclear how useful it is
* to send pointers between address spaces this way, we preserve
* the 'int' interpretation for 32-bit processes interoperating
* with 64-bit processes. The full semantics (pointers or integers)
* are available for N-bit processes interoperating with N-bit
* processes.
*/
void
{
/*
* The absolute minimum content is si_signo and si_code.
*/
return;
/*
* A siginfo generated by user level is structured
* differently from one generated by the kernel.
*/
if (SI_FROMUSER(src)) {
return;
}
default:
break;
case SIGCLD:
break;
case SIGSEGV:
case SIGBUS:
case SIGILL:
case SIGTRAP:
case SIGFPE:
case SIGEMT:
break;
case SIGPOLL:
case SIGXFSZ:
break;
case SIGPROF:
break;
}
}
void
{
/*
* The absolute minimum content is si_signo and si_code.
*/
return;
/*
* A siginfo generated by user level is structured
* differently from one generated by the kernel.
*/
if (SI_FROMUSER(src)) {
return;
}
default:
break;
case SIGCLD:
break;
case SIGSEGV:
case SIGBUS:
case SIGILL:
case SIGTRAP:
case SIGFPE:
case SIGEMT:
break;
case SIGPOLL:
case SIGXFSZ:
break;
case SIGPROF:
break;
}
}
#endif /* _SYSCALL32_IMPL */