2 * Copyright (c) 1982, 1986, 1989, 1991, 1993
3 * The Regents of the University of California. All rights reserved.
4 * (c) UNIX System Laboratories, Inc.
5 * All or some portions of this file are derived from material licensed
6 * to the University of California by American Telephone and Telegraph
7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8 * the permission of UNIX System Laboratories, Inc.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 4. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * @(#)kern_sig.c 8.7 (Berkeley) 4/18/94
37 #include <sys/cdefs.h>
38 __FBSDID("$FreeBSD$");
40 #include "opt_compat.h"
41 #include "opt_ktrace.h"
43 #include <sys/param.h>
44 #include <sys/systm.h>
45 #include <sys/signalvar.h>
46 #include <sys/vnode.h>
48 #include <sys/condvar.h>
49 #include <sys/event.h>
50 #include <sys/fcntl.h>
51 #include <sys/kernel.h>
54 #include <sys/ktrace.h>
56 #include <sys/malloc.h>
57 #include <sys/mutex.h>
58 #include <sys/namei.h>
60 #include <sys/pioctl.h>
61 #include <sys/resourcevar.h>
62 #include <sys/sched.h>
63 #include <sys/sleepqueue.h>
67 #include <sys/syscallsubr.h>
68 #include <sys/sysctl.h>
69 #include <sys/sysent.h>
70 #include <sys/syslog.h>
71 #include <sys/sysproto.h>
72 #include <sys/unistd.h>
75 #include <machine/cpu.h>
77 #if defined (__alpha__) && !defined(COMPAT_43)
78 #error "You *really* need COMPAT_43 on the alpha for longjmp(3)"
81 #define ONSIG 32 /* NSIG for osig* syscalls. XXX. */
83 static int coredump(struct thread *);
84 static char *expand_name(const char *, uid_t, pid_t);
85 static int killpg1(struct thread *td, int sig, int pgid, int all);
86 static int issignal(struct thread *p);
87 static int sigprop(int sig);
88 static void tdsigwakeup(struct thread *td, int sig, sig_t action);
89 static int filt_sigattach(struct knote *kn);
90 static void filt_sigdetach(struct knote *kn);
91 static int filt_signal(struct knote *kn, long hint);
92 static struct thread *sigtd(struct proc *p, int sig, int prop);
93 static int kern_sigtimedwait(struct thread *td, sigset_t set,
94 siginfo_t *info, struct timespec *timeout);
95 static void do_tdsignal(struct thread *td, int sig, sigtarget_t target);
97 struct filterops sig_filtops =
98 { 0, filt_sigattach, filt_sigdetach, filt_signal };
100 static int kern_logsigexit = 1;
101 SYSCTL_INT(_kern, KERN_LOGSIGEXIT, logsigexit, CTLFLAG_RW,
103 "Log processes quitting on abnormal signals to syslog(3)");
106 * Policy -- Can ucred cr1 send SIGIO to process cr2?
107 * Should use cr_cansignal() once cr_cansignal() allows SIGIO and SIGURG
108 * in the right situations.
110 #define CANSIGIO(cr1, cr2) \
111 ((cr1)->cr_uid == 0 || \
112 (cr1)->cr_ruid == (cr2)->cr_ruid || \
113 (cr1)->cr_uid == (cr2)->cr_ruid || \
114 (cr1)->cr_ruid == (cr2)->cr_uid || \
115 (cr1)->cr_uid == (cr2)->cr_uid)
118 SYSCTL_INT(_kern, OID_AUTO, sugid_coredump, CTLFLAG_RW,
119 &sugid_coredump, 0, "Enable coredumping set user/group ID processes");
121 static int do_coredump = 1;
122 SYSCTL_INT(_kern, OID_AUTO, coredump, CTLFLAG_RW,
123 &do_coredump, 0, "Enable/Disable coredumps");
125 static int set_core_nodump_flag = 0;
126 SYSCTL_INT(_kern, OID_AUTO, nodump_coredump, CTLFLAG_RW, &set_core_nodump_flag,
127 0, "Enable setting the NODUMP flag on coredump files");
130 * Signal properties and actions.
131 * The array below categorizes the signals and their default actions
132 * according to the following properties:
134 #define SA_KILL 0x01 /* terminates process by default */
135 #define SA_CORE 0x02 /* ditto and coredumps */
136 #define SA_STOP 0x04 /* suspend process */
137 #define SA_TTYSTOP 0x08 /* ditto, from tty */
138 #define SA_IGNORE 0x10 /* ignore by default */
139 #define SA_CONT 0x20 /* continue if suspended */
140 #define SA_CANTMASK 0x40 /* non-maskable, catchable */
141 #define SA_PROC 0x80 /* deliverable to any thread */
143 static int sigproptbl[NSIG] = {
144 SA_KILL|SA_PROC, /* SIGHUP */
145 SA_KILL|SA_PROC, /* SIGINT */
146 SA_KILL|SA_CORE|SA_PROC, /* SIGQUIT */
147 SA_KILL|SA_CORE, /* SIGILL */
148 SA_KILL|SA_CORE, /* SIGTRAP */
149 SA_KILL|SA_CORE, /* SIGABRT */
150 SA_KILL|SA_CORE|SA_PROC, /* SIGEMT */
151 SA_KILL|SA_CORE, /* SIGFPE */
152 SA_KILL|SA_PROC, /* SIGKILL */
153 SA_KILL|SA_CORE, /* SIGBUS */
154 SA_KILL|SA_CORE, /* SIGSEGV */
155 SA_KILL|SA_CORE, /* SIGSYS */
156 SA_KILL|SA_PROC, /* SIGPIPE */
157 SA_KILL|SA_PROC, /* SIGALRM */
158 SA_KILL|SA_PROC, /* SIGTERM */
159 SA_IGNORE|SA_PROC, /* SIGURG */
160 SA_STOP|SA_PROC, /* SIGSTOP */
161 SA_STOP|SA_TTYSTOP|SA_PROC, /* SIGTSTP */
162 SA_IGNORE|SA_CONT|SA_PROC, /* SIGCONT */
163 SA_IGNORE|SA_PROC, /* SIGCHLD */
164 SA_STOP|SA_TTYSTOP|SA_PROC, /* SIGTTIN */
165 SA_STOP|SA_TTYSTOP|SA_PROC, /* SIGTTOU */
166 SA_IGNORE|SA_PROC, /* SIGIO */
167 SA_KILL, /* SIGXCPU */
168 SA_KILL, /* SIGXFSZ */
169 SA_KILL|SA_PROC, /* SIGVTALRM */
170 SA_KILL|SA_PROC, /* SIGPROF */
171 SA_IGNORE|SA_PROC, /* SIGWINCH */
172 SA_IGNORE|SA_PROC, /* SIGINFO */
173 SA_KILL|SA_PROC, /* SIGUSR1 */
174 SA_KILL|SA_PROC, /* SIGUSR2 */
178 * Determine signal that should be delivered to process p, the current
179 * process, 0 if none. If there is a pending stop signal with default
180 * action, the process stops in issignal().
181 * XXXKSE the check for a pending stop is not done under KSE
186 cursig(struct thread *td)
188 PROC_LOCK_ASSERT(td->td_proc, MA_OWNED);
189 mtx_assert(&td->td_proc->p_sigacts->ps_mtx, MA_OWNED);
190 mtx_assert(&sched_lock, MA_NOTOWNED);
191 return (SIGPENDING(td) ? issignal(td) : 0);
195 * Arrange for ast() to handle unmasked pending signals on return to user
196 * mode. This must be called whenever a signal is added to td_siglist or
197 * unmasked in td_sigmask.
200 signotify(struct thread *td)
207 PROC_LOCK_ASSERT(p, MA_OWNED);
210 * If our mask changed we may have to move signal that were
211 * previously masked by all threads to our siglist.
214 if (p->p_flag & P_SA)
215 saved = p->p_siglist;
216 SIGSETNAND(set, td->td_sigmask);
217 SIGSETNAND(p->p_siglist, set);
218 SIGSETOR(td->td_siglist, set);
220 if (SIGPENDING(td)) {
221 mtx_lock_spin(&sched_lock);
222 td->td_flags |= TDF_NEEDSIGCHK | TDF_ASTPENDING;
223 mtx_unlock_spin(&sched_lock);
225 if ((p->p_flag & P_SA) && !(p->p_flag & P_SIGEVENT)) {
226 if (!SIGSETEQ(saved, p->p_siglist)) {
227 /* pending set changed */
228 p->p_flag |= P_SIGEVENT;
229 wakeup(&p->p_siglist);
235 sigonstack(size_t sp)
237 struct thread *td = curthread;
239 return ((td->td_pflags & TDP_ALTSTACK) ?
240 #if defined(COMPAT_43)
241 ((td->td_sigstk.ss_size == 0) ?
242 (td->td_sigstk.ss_flags & SS_ONSTACK) :
243 ((sp - (size_t)td->td_sigstk.ss_sp) < td->td_sigstk.ss_size))
245 ((sp - (size_t)td->td_sigstk.ss_sp) < td->td_sigstk.ss_size)
254 if (sig > 0 && sig < NSIG)
255 return (sigproptbl[_SIG_IDX(sig)]);
260 sig_ffs(sigset_t *set)
264 for (i = 0; i < _SIG_WORDS; i++)
266 return (ffs(set->__bits[i]) + (i * 32));
279 kern_sigaction(td, sig, act, oact, flags)
282 struct sigaction *act, *oact;
287 struct proc *p = td->td_proc;
289 if (!_SIG_VALID(sig))
294 mtx_lock(&ps->ps_mtx);
296 oact->sa_handler = ps->ps_sigact[_SIG_IDX(sig)];
297 oact->sa_mask = ps->ps_catchmask[_SIG_IDX(sig)];
299 if (SIGISMEMBER(ps->ps_sigonstack, sig))
300 oact->sa_flags |= SA_ONSTACK;
301 if (!SIGISMEMBER(ps->ps_sigintr, sig))
302 oact->sa_flags |= SA_RESTART;
303 if (SIGISMEMBER(ps->ps_sigreset, sig))
304 oact->sa_flags |= SA_RESETHAND;
305 if (SIGISMEMBER(ps->ps_signodefer, sig))
306 oact->sa_flags |= SA_NODEFER;
307 if (SIGISMEMBER(ps->ps_siginfo, sig))
308 oact->sa_flags |= SA_SIGINFO;
309 if (sig == SIGCHLD && ps->ps_flag & PS_NOCLDSTOP)
310 oact->sa_flags |= SA_NOCLDSTOP;
311 if (sig == SIGCHLD && ps->ps_flag & PS_NOCLDWAIT)
312 oact->sa_flags |= SA_NOCLDWAIT;
315 if ((sig == SIGKILL || sig == SIGSTOP) &&
316 act->sa_handler != SIG_DFL) {
317 mtx_unlock(&ps->ps_mtx);
323 * Change setting atomically.
326 ps->ps_catchmask[_SIG_IDX(sig)] = act->sa_mask;
327 SIG_CANTMASK(ps->ps_catchmask[_SIG_IDX(sig)]);
328 if (act->sa_flags & SA_SIGINFO) {
329 ps->ps_sigact[_SIG_IDX(sig)] =
330 (__sighandler_t *)act->sa_sigaction;
331 SIGADDSET(ps->ps_siginfo, sig);
333 ps->ps_sigact[_SIG_IDX(sig)] = act->sa_handler;
334 SIGDELSET(ps->ps_siginfo, sig);
336 if (!(act->sa_flags & SA_RESTART))
337 SIGADDSET(ps->ps_sigintr, sig);
339 SIGDELSET(ps->ps_sigintr, sig);
340 if (act->sa_flags & SA_ONSTACK)
341 SIGADDSET(ps->ps_sigonstack, sig);
343 SIGDELSET(ps->ps_sigonstack, sig);
344 if (act->sa_flags & SA_RESETHAND)
345 SIGADDSET(ps->ps_sigreset, sig);
347 SIGDELSET(ps->ps_sigreset, sig);
348 if (act->sa_flags & SA_NODEFER)
349 SIGADDSET(ps->ps_signodefer, sig);
351 SIGDELSET(ps->ps_signodefer, sig);
352 if (sig == SIGCHLD) {
353 if (act->sa_flags & SA_NOCLDSTOP)
354 ps->ps_flag |= PS_NOCLDSTOP;
356 ps->ps_flag &= ~PS_NOCLDSTOP;
357 if (act->sa_flags & SA_NOCLDWAIT) {
359 * Paranoia: since SA_NOCLDWAIT is implemented
360 * by reparenting the dying child to PID 1 (and
361 * trust it to reap the zombie), PID 1 itself
362 * is forbidden to set SA_NOCLDWAIT.
365 ps->ps_flag &= ~PS_NOCLDWAIT;
367 ps->ps_flag |= PS_NOCLDWAIT;
369 ps->ps_flag &= ~PS_NOCLDWAIT;
370 if (ps->ps_sigact[_SIG_IDX(SIGCHLD)] == SIG_IGN)
371 ps->ps_flag |= PS_CLDSIGIGN;
373 ps->ps_flag &= ~PS_CLDSIGIGN;
376 * Set bit in ps_sigignore for signals that are set to SIG_IGN,
377 * and for signals set to SIG_DFL where the default is to
378 * ignore. However, don't put SIGCONT in ps_sigignore, as we
379 * have to restart the process.
381 if (ps->ps_sigact[_SIG_IDX(sig)] == SIG_IGN ||
382 (sigprop(sig) & SA_IGNORE &&
383 ps->ps_sigact[_SIG_IDX(sig)] == SIG_DFL)) {
384 if ((p->p_flag & P_SA) &&
385 SIGISMEMBER(p->p_siglist, sig)) {
386 p->p_flag |= P_SIGEVENT;
387 wakeup(&p->p_siglist);
389 /* never to be seen again */
390 SIGDELSET(p->p_siglist, sig);
391 mtx_lock_spin(&sched_lock);
392 FOREACH_THREAD_IN_PROC(p, td0)
393 SIGDELSET(td0->td_siglist, sig);
394 mtx_unlock_spin(&sched_lock);
396 /* easier in psignal */
397 SIGADDSET(ps->ps_sigignore, sig);
398 SIGDELSET(ps->ps_sigcatch, sig);
400 SIGDELSET(ps->ps_sigignore, sig);
401 if (ps->ps_sigact[_SIG_IDX(sig)] == SIG_DFL)
402 SIGDELSET(ps->ps_sigcatch, sig);
404 SIGADDSET(ps->ps_sigcatch, sig);
406 #ifdef COMPAT_FREEBSD4
407 if (ps->ps_sigact[_SIG_IDX(sig)] == SIG_IGN ||
408 ps->ps_sigact[_SIG_IDX(sig)] == SIG_DFL ||
409 (flags & KSA_FREEBSD4) == 0)
410 SIGDELSET(ps->ps_freebsd4, sig);
412 SIGADDSET(ps->ps_freebsd4, sig);
415 if (ps->ps_sigact[_SIG_IDX(sig)] == SIG_IGN ||
416 ps->ps_sigact[_SIG_IDX(sig)] == SIG_DFL ||
417 (flags & KSA_OSIGSET) == 0)
418 SIGDELSET(ps->ps_osigset, sig);
420 SIGADDSET(ps->ps_osigset, sig);
423 mtx_unlock(&ps->ps_mtx);
428 #ifndef _SYS_SYSPROTO_H_
429 struct sigaction_args {
431 struct sigaction *act;
432 struct sigaction *oact;
441 register struct sigaction_args *uap;
443 struct sigaction act, oact;
444 register struct sigaction *actp, *oactp;
447 actp = (uap->act != NULL) ? &act : NULL;
448 oactp = (uap->oact != NULL) ? &oact : NULL;
450 error = copyin(uap->act, actp, sizeof(act));
454 error = kern_sigaction(td, uap->sig, actp, oactp, 0);
456 error = copyout(oactp, uap->oact, sizeof(oact));
460 #ifdef COMPAT_FREEBSD4
461 #ifndef _SYS_SYSPROTO_H_
462 struct freebsd4_sigaction_args {
464 struct sigaction *act;
465 struct sigaction *oact;
472 freebsd4_sigaction(td, uap)
474 register struct freebsd4_sigaction_args *uap;
476 struct sigaction act, oact;
477 register struct sigaction *actp, *oactp;
481 actp = (uap->act != NULL) ? &act : NULL;
482 oactp = (uap->oact != NULL) ? &oact : NULL;
484 error = copyin(uap->act, actp, sizeof(act));
488 error = kern_sigaction(td, uap->sig, actp, oactp, KSA_FREEBSD4);
490 error = copyout(oactp, uap->oact, sizeof(oact));
493 #endif /* COMAPT_FREEBSD4 */
495 #ifdef COMPAT_43 /* XXX - COMPAT_FBSD3 */
496 #ifndef _SYS_SYSPROTO_H_
497 struct osigaction_args {
499 struct osigaction *nsa;
500 struct osigaction *osa;
509 register struct osigaction_args *uap;
511 struct osigaction sa;
512 struct sigaction nsa, osa;
513 register struct sigaction *nsap, *osap;
516 if (uap->signum <= 0 || uap->signum >= ONSIG)
519 nsap = (uap->nsa != NULL) ? &nsa : NULL;
520 osap = (uap->osa != NULL) ? &osa : NULL;
523 error = copyin(uap->nsa, &sa, sizeof(sa));
526 nsap->sa_handler = sa.sa_handler;
527 nsap->sa_flags = sa.sa_flags;
528 OSIG2SIG(sa.sa_mask, nsap->sa_mask);
530 error = kern_sigaction(td, uap->signum, nsap, osap, KSA_OSIGSET);
531 if (osap && !error) {
532 sa.sa_handler = osap->sa_handler;
533 sa.sa_flags = osap->sa_flags;
534 SIG2OSIG(osap->sa_mask, sa.sa_mask);
535 error = copyout(&sa, uap->osa, sizeof(sa));
540 #if !defined(__i386__) && !defined(__alpha__)
541 /* Avoid replicating the same stub everywhere */
545 struct osigreturn_args *uap;
548 return (nosys(td, (struct nosys_args *)uap));
551 #endif /* COMPAT_43 */
554 * Initialize signal state for process 0;
555 * set to ignore signals that are ignored by default.
566 mtx_lock(&ps->ps_mtx);
567 for (i = 1; i <= NSIG; i++)
568 if (sigprop(i) & SA_IGNORE && i != SIGCONT)
569 SIGADDSET(ps->ps_sigignore, i);
570 mtx_unlock(&ps->ps_mtx);
575 * Reset signals for an exec of the specified process.
578 execsigs(struct proc *p)
585 * Reset caught signals. Held signals remain held
586 * through td_sigmask (unless they were caught,
587 * and are now ignored by default).
589 PROC_LOCK_ASSERT(p, MA_OWNED);
590 td = FIRST_THREAD_IN_PROC(p);
592 mtx_lock(&ps->ps_mtx);
593 while (SIGNOTEMPTY(ps->ps_sigcatch)) {
594 sig = sig_ffs(&ps->ps_sigcatch);
595 SIGDELSET(ps->ps_sigcatch, sig);
596 if (sigprop(sig) & SA_IGNORE) {
598 SIGADDSET(ps->ps_sigignore, sig);
599 SIGDELSET(p->p_siglist, sig);
601 * There is only one thread at this point.
603 SIGDELSET(td->td_siglist, sig);
605 ps->ps_sigact[_SIG_IDX(sig)] = SIG_DFL;
608 * Reset stack state to the user stack.
609 * Clear set of signals caught on the signal stack.
611 td->td_sigstk.ss_flags = SS_DISABLE;
612 td->td_sigstk.ss_size = 0;
613 td->td_sigstk.ss_sp = 0;
614 td->td_pflags &= ~TDP_ALTSTACK;
616 * Reset no zombies if child dies flag as Solaris does.
618 ps->ps_flag &= ~(PS_NOCLDWAIT | PS_CLDSIGIGN);
619 if (ps->ps_sigact[_SIG_IDX(SIGCHLD)] == SIG_IGN)
620 ps->ps_sigact[_SIG_IDX(SIGCHLD)] = SIG_DFL;
621 mtx_unlock(&ps->ps_mtx);
627 * Manipulate signal mask.
630 kern_sigprocmask(td, how, set, oset, old)
633 sigset_t *set, *oset;
638 PROC_LOCK(td->td_proc);
640 *oset = td->td_sigmask;
647 SIGSETOR(td->td_sigmask, *set);
650 SIGSETNAND(td->td_sigmask, *set);
656 SIGSETLO(td->td_sigmask, *set);
658 td->td_sigmask = *set;
666 PROC_UNLOCK(td->td_proc);
671 * sigprocmask() - MP SAFE
674 #ifndef _SYS_SYSPROTO_H_
675 struct sigprocmask_args {
683 register struct thread *td;
684 struct sigprocmask_args *uap;
687 sigset_t *setp, *osetp;
690 setp = (uap->set != NULL) ? &set : NULL;
691 osetp = (uap->oset != NULL) ? &oset : NULL;
693 error = copyin(uap->set, setp, sizeof(set));
697 error = kern_sigprocmask(td, uap->how, setp, osetp, 0);
698 if (osetp && !error) {
699 error = copyout(osetp, uap->oset, sizeof(oset));
704 #ifdef COMPAT_43 /* XXX - COMPAT_FBSD3 */
706 * osigprocmask() - MP SAFE
708 #ifndef _SYS_SYSPROTO_H_
709 struct osigprocmask_args {
715 osigprocmask(td, uap)
716 register struct thread *td;
717 struct osigprocmask_args *uap;
722 OSIG2SIG(uap->mask, set);
723 error = kern_sigprocmask(td, uap->how, &set, &oset, 1);
724 SIG2OSIG(oset, td->td_retval[0]);
727 #endif /* COMPAT_43 */
729 #ifndef _SYS_SYSPROTO_H_
730 struct sigpending_args {
738 sigwait(struct thread *td, struct sigwait_args *uap)
744 error = copyin(uap->set, &set, sizeof(set));
746 td->td_retval[0] = error;
750 error = kern_sigtimedwait(td, set, &info, NULL);
752 if (error == ERESTART)
754 td->td_retval[0] = error;
758 error = copyout(&info.si_signo, uap->sig, sizeof(info.si_signo));
759 /* Repost if we got an error. */
760 if (error && info.si_signo) {
761 PROC_LOCK(td->td_proc);
762 tdsignal(td, info.si_signo, SIGTARGET_TD);
763 PROC_UNLOCK(td->td_proc);
765 td->td_retval[0] = error;
772 sigtimedwait(struct thread *td, struct sigtimedwait_args *uap)
775 struct timespec *timeout;
781 error = copyin(uap->timeout, &ts, sizeof(ts));
789 error = copyin(uap->set, &set, sizeof(set));
793 error = kern_sigtimedwait(td, set, &info, timeout);
798 error = copyout(&info, uap->info, sizeof(info));
799 /* Repost if we got an error. */
800 if (error && info.si_signo) {
801 PROC_LOCK(td->td_proc);
802 tdsignal(td, info.si_signo, SIGTARGET_TD);
803 PROC_UNLOCK(td->td_proc);
805 td->td_retval[0] = info.si_signo;
814 sigwaitinfo(struct thread *td, struct sigwaitinfo_args *uap)
820 error = copyin(uap->set, &set, sizeof(set));
824 error = kern_sigtimedwait(td, set, &info, NULL);
829 error = copyout(&info, uap->info, sizeof(info));
830 /* Repost if we got an error. */
831 if (error && info.si_signo) {
832 PROC_LOCK(td->td_proc);
833 tdsignal(td, info.si_signo, SIGTARGET_TD);
834 PROC_UNLOCK(td->td_proc);
836 td->td_retval[0] = info.si_signo;
842 kern_sigtimedwait(struct thread *td, sigset_t waitset, siginfo_t *info,
843 struct timespec *timeout)
848 int error, sig, hz, i, timevalid = 0;
849 struct timespec rts, ets, ts;
855 SIG_CANTMASK(waitset);
859 savedmask = td->td_sigmask;
861 if (timeout->tv_nsec >= 0 && timeout->tv_nsec < 1000000000) {
865 timespecadd(&ets, timeout);
870 for (i = 1; i <= _SIG_MAXSIG; ++i) {
871 if (!SIGISMEMBER(waitset, i))
873 if (SIGISMEMBER(td->td_siglist, i)) {
874 SIGFILLSET(td->td_sigmask);
875 SIG_CANTMASK(td->td_sigmask);
876 SIGDELSET(td->td_sigmask, i);
877 mtx_lock(&ps->ps_mtx);
880 mtx_unlock(&ps->ps_mtx);
881 } else if (SIGISMEMBER(p->p_siglist, i)) {
882 if (p->p_flag & P_SA) {
883 p->p_flag |= P_SIGEVENT;
884 wakeup(&p->p_siglist);
886 SIGDELSET(p->p_siglist, i);
887 SIGADDSET(td->td_siglist, i);
888 SIGFILLSET(td->td_sigmask);
889 SIG_CANTMASK(td->td_sigmask);
890 SIGDELSET(td->td_sigmask, i);
891 mtx_lock(&ps->ps_mtx);
894 mtx_unlock(&ps->ps_mtx);
903 * POSIX says this must be checked after looking for pending
912 if (timespeccmp(&rts, &ets, >=)) {
917 timespecsub(&ts, &rts);
918 TIMESPEC_TO_TIMEVAL(&tv, &ts);
923 td->td_sigmask = savedmask;
924 SIGSETNAND(td->td_sigmask, waitset);
926 error = msleep(&ps, &p->p_mtx, PPAUSE|PCATCH, "sigwait", hz);
928 if (error == ERESTART) {
929 /* timeout can not be restarted. */
931 } else if (error == EAGAIN) {
932 /* will calculate timeout by ourself. */
939 td->td_sigmask = savedmask;
945 mtx_lock(&ps->ps_mtx);
946 action = ps->ps_sigact[_SIG_IDX(sig)];
947 mtx_unlock(&ps->ps_mtx);
949 if (KTRPOINT(td, KTR_PSIG))
950 ktrpsig(sig, action, &td->td_sigmask, 0);
952 _STOPEVENT(p, S_SIG, sig);
954 SIGDELSET(td->td_siglist, sig);
955 bzero(info, sizeof(*info));
956 info->si_signo = sig;
969 struct sigpending_args *uap;
971 struct proc *p = td->td_proc;
975 siglist = p->p_siglist;
976 SIGSETOR(siglist, td->td_siglist);
978 return (copyout(&siglist, uap->set, sizeof(sigset_t)));
981 #ifdef COMPAT_43 /* XXX - COMPAT_FBSD3 */
982 #ifndef _SYS_SYSPROTO_H_
983 struct osigpending_args {
993 struct osigpending_args *uap;
995 struct proc *p = td->td_proc;
999 siglist = p->p_siglist;
1000 SIGSETOR(siglist, td->td_siglist);
1002 SIG2OSIG(siglist, td->td_retval[0]);
1005 #endif /* COMPAT_43 */
1007 #if defined(COMPAT_43)
1009 * Generalized interface signal handler, 4.3-compatible.
1011 #ifndef _SYS_SYSPROTO_H_
1012 struct osigvec_args {
1025 register struct osigvec_args *uap;
1028 struct sigaction nsa, osa;
1029 register struct sigaction *nsap, *osap;
1032 if (uap->signum <= 0 || uap->signum >= ONSIG)
1034 nsap = (uap->nsv != NULL) ? &nsa : NULL;
1035 osap = (uap->osv != NULL) ? &osa : NULL;
1037 error = copyin(uap->nsv, &vec, sizeof(vec));
1040 nsap->sa_handler = vec.sv_handler;
1041 OSIG2SIG(vec.sv_mask, nsap->sa_mask);
1042 nsap->sa_flags = vec.sv_flags;
1043 nsap->sa_flags ^= SA_RESTART; /* opposite of SV_INTERRUPT */
1045 error = kern_sigaction(td, uap->signum, nsap, osap, KSA_OSIGSET);
1046 if (osap && !error) {
1047 vec.sv_handler = osap->sa_handler;
1048 SIG2OSIG(osap->sa_mask, vec.sv_mask);
1049 vec.sv_flags = osap->sa_flags;
1050 vec.sv_flags &= ~SA_NOCLDWAIT;
1051 vec.sv_flags ^= SA_RESTART;
1052 error = copyout(&vec, uap->osv, sizeof(vec));
1057 #ifndef _SYS_SYSPROTO_H_
1058 struct osigblock_args {
1067 register struct thread *td;
1068 struct osigblock_args *uap;
1070 struct proc *p = td->td_proc;
1073 OSIG2SIG(uap->mask, set);
1076 SIG2OSIG(td->td_sigmask, td->td_retval[0]);
1077 SIGSETOR(td->td_sigmask, set);
1082 #ifndef _SYS_SYSPROTO_H_
1083 struct osigsetmask_args {
1091 osigsetmask(td, uap)
1093 struct osigsetmask_args *uap;
1095 struct proc *p = td->td_proc;
1098 OSIG2SIG(uap->mask, set);
1101 SIG2OSIG(td->td_sigmask, td->td_retval[0]);
1102 SIGSETLO(td->td_sigmask, set);
1107 #endif /* COMPAT_43 */
1110 * Suspend process until signal, providing mask to be set
1112 ***** XXXKSE this doesn't make sense under KSE.
1113 ***** Do we suspend the thread or all threads in the process?
1114 ***** How do we suspend threads running NOW on another processor?
1116 #ifndef _SYS_SYSPROTO_H_
1117 struct sigsuspend_args {
1118 const sigset_t *sigmask;
1128 struct sigsuspend_args *uap;
1133 error = copyin(uap->sigmask, &mask, sizeof(mask));
1136 return (kern_sigsuspend(td, mask));
1140 kern_sigsuspend(struct thread *td, sigset_t mask)
1142 struct proc *p = td->td_proc;
1145 * When returning from sigsuspend, we want
1146 * the old mask to be restored after the
1147 * signal handler has finished. Thus, we
1148 * save it here and mark the sigacts structure
1152 td->td_oldsigmask = td->td_sigmask;
1153 td->td_pflags |= TDP_OLDMASK;
1155 td->td_sigmask = mask;
1157 while (msleep(&p->p_sigacts, &p->p_mtx, PPAUSE|PCATCH, "pause", 0) == 0)
1160 /* always return EINTR rather than ERESTART... */
1164 #ifdef COMPAT_43 /* XXX - COMPAT_FBSD3 */
1166 * Compatibility sigsuspend call for old binaries. Note nonstandard calling
1167 * convention: libc stub passes mask, not pointer, to save a copyin.
1169 #ifndef _SYS_SYSPROTO_H_
1170 struct osigsuspend_args {
1179 osigsuspend(td, uap)
1181 struct osigsuspend_args *uap;
1183 struct proc *p = td->td_proc;
1187 td->td_oldsigmask = td->td_sigmask;
1188 td->td_pflags |= TDP_OLDMASK;
1189 OSIG2SIG(uap->mask, mask);
1191 SIGSETLO(td->td_sigmask, mask);
1193 while (msleep(&p->p_sigacts, &p->p_mtx, PPAUSE|PCATCH, "opause", 0) == 0)
1196 /* always return EINTR rather than ERESTART... */
1199 #endif /* COMPAT_43 */
1201 #if defined(COMPAT_43)
1202 #ifndef _SYS_SYSPROTO_H_
1203 struct osigstack_args {
1204 struct sigstack *nss;
1205 struct sigstack *oss;
1215 register struct osigstack_args *uap;
1217 struct sigstack nss, oss;
1220 if (uap->nss != NULL) {
1221 error = copyin(uap->nss, &nss, sizeof(nss));
1225 oss.ss_sp = td->td_sigstk.ss_sp;
1226 oss.ss_onstack = sigonstack(cpu_getstack(td));
1227 if (uap->nss != NULL) {
1228 td->td_sigstk.ss_sp = nss.ss_sp;
1229 td->td_sigstk.ss_size = 0;
1230 td->td_sigstk.ss_flags |= nss.ss_onstack & SS_ONSTACK;
1231 td->td_pflags |= TDP_ALTSTACK;
1233 if (uap->oss != NULL)
1234 error = copyout(&oss, uap->oss, sizeof(oss));
1238 #endif /* COMPAT_43 */
1240 #ifndef _SYS_SYSPROTO_H_
1241 struct sigaltstack_args {
1251 sigaltstack(td, uap)
1253 register struct sigaltstack_args *uap;
1258 if (uap->ss != NULL) {
1259 error = copyin(uap->ss, &ss, sizeof(ss));
1263 error = kern_sigaltstack(td, (uap->ss != NULL) ? &ss : NULL,
1264 (uap->oss != NULL) ? &oss : NULL);
1267 if (uap->oss != NULL)
1268 error = copyout(&oss, uap->oss, sizeof(stack_t));
1273 kern_sigaltstack(struct thread *td, stack_t *ss, stack_t *oss)
1275 struct proc *p = td->td_proc;
1278 oonstack = sigonstack(cpu_getstack(td));
1281 *oss = td->td_sigstk;
1282 oss->ss_flags = (td->td_pflags & TDP_ALTSTACK)
1283 ? ((oonstack) ? SS_ONSTACK : 0) : SS_DISABLE;
1289 if ((ss->ss_flags & ~SS_DISABLE) != 0)
1291 if (!(ss->ss_flags & SS_DISABLE)) {
1292 if (ss->ss_size < p->p_sysent->sv_minsigstksz) {
1295 td->td_sigstk = *ss;
1296 td->td_pflags |= TDP_ALTSTACK;
1298 td->td_pflags &= ~TDP_ALTSTACK;
1305 * Common code for kill process group/broadcast kill.
1306 * cp is calling process.
1309 killpg1(td, sig, pgid, all)
1310 register struct thread *td;
1313 register struct proc *p;
1321 sx_slock(&allproc_lock);
1322 LIST_FOREACH(p, &allproc, p_list) {
1324 if (p->p_pid <= 1 || p->p_flag & P_SYSTEM ||
1329 if (p_cansignal(td, p, sig) == 0) {
1336 sx_sunlock(&allproc_lock);
1338 sx_slock(&proctree_lock);
1341 * zero pgid means send to my process group.
1343 pgrp = td->td_proc->p_pgrp;
1346 pgrp = pgfind(pgid);
1348 sx_sunlock(&proctree_lock);
1352 sx_sunlock(&proctree_lock);
1353 LIST_FOREACH(p, &pgrp->pg_members, p_pglist) {
1355 if (p->p_pid <= 1 || p->p_flag & P_SYSTEM) {
1359 if (p_cansignal(td, p, sig) == 0) {
1368 return (nfound ? 0 : ESRCH);
1371 #ifndef _SYS_SYSPROTO_H_
1383 register struct thread *td;
1384 register struct kill_args *uap;
1386 register struct proc *p;
1389 if ((u_int)uap->signum > _SIG_MAXSIG)
1393 /* kill single process */
1394 if ((p = pfind(uap->pid)) == NULL) {
1395 if ((p = zpfind(uap->pid)) == NULL)
1398 error = p_cansignal(td, p, uap->signum);
1399 if (error == 0 && uap->signum)
1400 psignal(p, uap->signum);
1405 case -1: /* broadcast signal */
1406 return (killpg1(td, uap->signum, 0, 1));
1407 case 0: /* signal own process group */
1408 return (killpg1(td, uap->signum, 0, 0));
1409 default: /* negative explicit process group */
1410 return (killpg1(td, uap->signum, -uap->pid, 0));
1415 #if defined(COMPAT_43)
1416 #ifndef _SYS_SYSPROTO_H_
1417 struct okillpg_args {
1429 register struct okillpg_args *uap;
1432 if ((u_int)uap->signum > _SIG_MAXSIG)
1434 return (killpg1(td, uap->signum, uap->pgid, 0));
1436 #endif /* COMPAT_43 */
1439 * Send a signal to a process group.
1448 sx_slock(&proctree_lock);
1449 pgrp = pgfind(pgid);
1450 sx_sunlock(&proctree_lock);
1452 pgsignal(pgrp, sig, 0);
1459 * Send a signal to a process group. If checktty is 1,
1460 * limit to members which have a controlling terminal.
1463 pgsignal(pgrp, sig, checkctty)
1467 register struct proc *p;
1470 PGRP_LOCK_ASSERT(pgrp, MA_OWNED);
1471 LIST_FOREACH(p, &pgrp->pg_members, p_pglist) {
1473 if (checkctty == 0 || p->p_flag & P_CONTROLT)
1481 * Send a signal caused by a trap to the current thread.
1482 * If it will be caught immediately, deliver it with correct code.
1483 * Otherwise, post it normally.
1488 trapsignal(struct thread *td, int sig, u_long code)
1496 if (td->td_pflags & TDP_SA) {
1497 if (td->td_mailbox == NULL)
1498 thread_user_enter(td);
1500 SIGDELSET(td->td_sigmask, sig);
1501 mtx_lock_spin(&sched_lock);
1503 * Force scheduling an upcall, so UTS has chance to
1504 * process the signal before thread runs again in
1508 td->td_upcall->ku_flags |= KUF_DOUPCALL;
1509 mtx_unlock_spin(&sched_lock);
1514 mtx_lock(&ps->ps_mtx);
1515 if ((p->p_flag & P_TRACED) == 0 && SIGISMEMBER(ps->ps_sigcatch, sig) &&
1516 !SIGISMEMBER(td->td_sigmask, sig)) {
1517 p->p_stats->p_ru.ru_nsignals++;
1519 if (KTRPOINT(curthread, KTR_PSIG))
1520 ktrpsig(sig, ps->ps_sigact[_SIG_IDX(sig)],
1521 &td->td_sigmask, code);
1523 if (!(td->td_pflags & TDP_SA))
1524 (*p->p_sysent->sv_sendsig)(
1525 ps->ps_sigact[_SIG_IDX(sig)], sig,
1526 &td->td_sigmask, code);
1527 else if (td->td_mailbox == NULL) {
1528 mtx_unlock(&ps->ps_mtx);
1529 /* UTS caused a sync signal */
1530 p->p_code = code; /* XXX for core dump/debugger */
1531 p->p_sig = sig; /* XXX to verify code */
1534 cpu_thread_siginfo(sig, code, &siginfo);
1535 mtx_unlock(&ps->ps_mtx);
1536 SIGADDSET(td->td_sigmask, sig);
1538 error = copyout(&siginfo, &td->td_mailbox->tm_syncsig,
1541 /* UTS memory corrupted */
1543 sigexit(td, SIGSEGV);
1544 mtx_lock(&ps->ps_mtx);
1546 SIGSETOR(td->td_sigmask, ps->ps_catchmask[_SIG_IDX(sig)]);
1547 if (!SIGISMEMBER(ps->ps_signodefer, sig))
1548 SIGADDSET(td->td_sigmask, sig);
1549 if (SIGISMEMBER(ps->ps_sigreset, sig)) {
1551 * See kern_sigaction() for origin of this code.
1553 SIGDELSET(ps->ps_sigcatch, sig);
1554 if (sig != SIGCONT &&
1555 sigprop(sig) & SA_IGNORE)
1556 SIGADDSET(ps->ps_sigignore, sig);
1557 ps->ps_sigact[_SIG_IDX(sig)] = SIG_DFL;
1559 mtx_unlock(&ps->ps_mtx);
1561 mtx_unlock(&ps->ps_mtx);
1562 p->p_code = code; /* XXX for core dump/debugger */
1563 p->p_sig = sig; /* XXX to verify code */
1564 tdsignal(td, sig, SIGTARGET_TD);
1569 static struct thread *
1570 sigtd(struct proc *p, int sig, int prop)
1572 struct thread *td, *signal_td;
1574 PROC_LOCK_ASSERT(p, MA_OWNED);
1577 * Check if current thread can handle the signal without
1578 * switching conetxt to another thread.
1580 if (curproc == p && !SIGISMEMBER(curthread->td_sigmask, sig))
1583 mtx_lock_spin(&sched_lock);
1584 FOREACH_THREAD_IN_PROC(p, td) {
1585 if (!SIGISMEMBER(td->td_sigmask, sig)) {
1590 if (signal_td == NULL)
1591 signal_td = FIRST_THREAD_IN_PROC(p);
1592 mtx_unlock_spin(&sched_lock);
1597 * Send the signal to the process. If the signal has an action, the action
1598 * is usually performed by the target process rather than the caller; we add
1599 * the signal to the set of pending signals for the process.
1602 * o When a stop signal is sent to a sleeping process that takes the
1603 * default action, the process is stopped without awakening it.
1604 * o SIGCONT restarts stopped processes (or puts them back to sleep)
1605 * regardless of the signal action (eg, blocked or ignored).
1607 * Other ignored signals are discarded immediately.
1612 psignal(struct proc *p, int sig)
1617 if (!_SIG_VALID(sig))
1618 panic("psignal(): invalid signal");
1620 PROC_LOCK_ASSERT(p, MA_OWNED);
1622 * IEEE Std 1003.1-2001: return success when killing a zombie.
1624 if (p->p_state == PRS_ZOMBIE)
1626 prop = sigprop(sig);
1629 * Find a thread to deliver the signal to.
1631 td = sigtd(p, sig, prop);
1633 tdsignal(td, sig, SIGTARGET_P);
1640 tdsignal(struct thread *td, int sig, sigtarget_t target)
1643 struct proc *p = td->td_proc;
1645 if (p->p_flag & P_SA)
1646 saved = p->p_siglist;
1647 do_tdsignal(td, sig, target);
1648 if ((p->p_flag & P_SA) && !(p->p_flag & P_SIGEVENT)) {
1649 if (!SIGSETEQ(saved, p->p_siglist)) {
1650 /* pending set changed */
1651 p->p_flag |= P_SIGEVENT;
1652 wakeup(&p->p_siglist);
1658 do_tdsignal(struct thread *td, int sig, sigtarget_t target)
1661 register sig_t action;
1667 if (!_SIG_VALID(sig))
1668 panic("do_tdsignal(): invalid signal");
1673 PROC_LOCK_ASSERT(p, MA_OWNED);
1674 KNOTE_LOCKED(&p->p_klist, NOTE_SIGNAL | sig);
1676 prop = sigprop(sig);
1679 * If the signal is blocked and not destined for this thread, then
1680 * assign it to the process so that we can find it later in the first
1681 * thread that unblocks it. Otherwise, assign it to this thread now.
1683 if (target == SIGTARGET_TD) {
1684 siglist = &td->td_siglist;
1686 if (!SIGISMEMBER(td->td_sigmask, sig))
1687 siglist = &td->td_siglist;
1689 siglist = &p->p_siglist;
1693 * If the signal is being ignored,
1694 * then we forget about it immediately.
1695 * (Note: we don't set SIGCONT in ps_sigignore,
1696 * and if it is set to SIG_IGN,
1697 * action will be SIG_DFL here.)
1699 mtx_lock(&ps->ps_mtx);
1700 if (SIGISMEMBER(ps->ps_sigignore, sig) ||
1701 (p->p_flag & P_WEXIT)) {
1702 mtx_unlock(&ps->ps_mtx);
1705 if (SIGISMEMBER(td->td_sigmask, sig))
1707 else if (SIGISMEMBER(ps->ps_sigcatch, sig))
1711 mtx_unlock(&ps->ps_mtx);
1713 if (prop & SA_CONT) {
1714 SIG_STOPSIGMASK(p->p_siglist);
1716 * XXX Should investigate leaving STOP and CONT sigs only in
1717 * the proc's siglist.
1719 mtx_lock_spin(&sched_lock);
1720 FOREACH_THREAD_IN_PROC(p, td0)
1721 SIG_STOPSIGMASK(td0->td_siglist);
1722 mtx_unlock_spin(&sched_lock);
1725 if (prop & SA_STOP) {
1727 * If sending a tty stop signal to a member of an orphaned
1728 * process group, discard the signal here if the action
1729 * is default; don't stop the process below if sleeping,
1730 * and don't clear any pending SIGCONT.
1732 if ((prop & SA_TTYSTOP) &&
1733 (p->p_pgrp->pg_jobc == 0) &&
1734 (action == SIG_DFL))
1736 SIG_CONTSIGMASK(p->p_siglist);
1737 mtx_lock_spin(&sched_lock);
1738 FOREACH_THREAD_IN_PROC(p, td0)
1739 SIG_CONTSIGMASK(td0->td_siglist);
1740 mtx_unlock_spin(&sched_lock);
1741 p->p_flag &= ~P_CONTINUED;
1744 SIGADDSET(*siglist, sig);
1745 signotify(td); /* uses schedlock */
1747 * Defer further processing for signals which are held,
1748 * except that stopped processes must be continued by SIGCONT.
1750 if (action == SIG_HOLD &&
1751 !((prop & SA_CONT) && (p->p_flag & P_STOPPED_SIG)))
1754 * SIGKILL: Remove procfs STOPEVENTs.
1756 if (sig == SIGKILL) {
1757 /* from procfs_ioctl.c: PIOCBIC */
1759 /* from procfs_ioctl.c: PIOCCONT */
1764 * Some signals have a process-wide effect and a per-thread
1765 * component. Most processing occurs when the process next
1766 * tries to cross the user boundary, however there are some
1767 * times when processing needs to be done immediatly, such as
1768 * waking up threads so that they can cross the user boundary.
1769 * We try do the per-process part here.
1771 if (P_SHOULDSTOP(p)) {
1773 * The process is in stopped mode. All the threads should be
1774 * either winding down or already on the suspended queue.
1776 if (p->p_flag & P_TRACED) {
1778 * The traced process is already stopped,
1779 * so no further action is necessary.
1780 * No signal can restart us.
1785 if (sig == SIGKILL) {
1787 * SIGKILL sets process running.
1788 * It will die elsewhere.
1789 * All threads must be restarted.
1791 p->p_flag &= ~P_STOPPED_SIG;
1795 if (prop & SA_CONT) {
1797 * If SIGCONT is default (or ignored), we continue the
1798 * process but don't leave the signal in siglist as
1799 * it has no further action. If SIGCONT is held, we
1800 * continue the process and leave the signal in
1801 * siglist. If the process catches SIGCONT, let it
1802 * handle the signal itself. If it isn't waiting on
1803 * an event, it goes back to run state.
1804 * Otherwise, process goes back to sleep state.
1806 p->p_flag &= ~P_STOPPED_SIG;
1807 p->p_flag |= P_CONTINUED;
1808 if (action == SIG_DFL) {
1809 SIGDELSET(*siglist, sig);
1810 } else if (action == SIG_CATCH) {
1812 * The process wants to catch it so it needs
1813 * to run at least one thread, but which one?
1814 * It would seem that the answer would be to
1815 * run an upcall in the next KSE to run, and
1816 * deliver the signal that way. In a NON KSE
1817 * process, we need to make sure that the
1818 * single thread is runnable asap.
1819 * XXXKSE for now however, make them all run.
1824 * The signal is not ignored or caught.
1826 mtx_lock_spin(&sched_lock);
1827 thread_unsuspend(p);
1828 mtx_unlock_spin(&sched_lock);
1832 if (prop & SA_STOP) {
1834 * Already stopped, don't need to stop again
1835 * (If we did the shell could get confused).
1836 * Just make sure the signal STOP bit set.
1838 p->p_flag |= P_STOPPED_SIG;
1839 SIGDELSET(*siglist, sig);
1844 * All other kinds of signals:
1845 * If a thread is sleeping interruptibly, simulate a
1846 * wakeup so that when it is continued it will be made
1847 * runnable and can look at the signal. However, don't make
1848 * the PROCESS runnable, leave it stopped.
1849 * It may run a bit until it hits a thread_suspend_check().
1851 mtx_lock_spin(&sched_lock);
1852 if (TD_ON_SLEEPQ(td) && (td->td_flags & TDF_SINTR))
1854 mtx_unlock_spin(&sched_lock);
1857 * Mutexes are short lived. Threads waiting on them will
1858 * hit thread_suspend_check() soon.
1860 } else if (p->p_state == PRS_NORMAL) {
1861 if (p->p_flag & P_TRACED || action == SIG_CATCH) {
1862 mtx_lock_spin(&sched_lock);
1863 tdsigwakeup(td, sig, action);
1864 mtx_unlock_spin(&sched_lock);
1868 MPASS(action == SIG_DFL);
1870 if (prop & SA_STOP) {
1871 if (p->p_flag & P_PPWAIT)
1873 p->p_flag |= P_STOPPED_SIG;
1876 mtx_lock_spin(&sched_lock);
1877 FOREACH_THREAD_IN_PROC(p, td0) {
1878 if (TD_IS_SLEEPING(td0) &&
1879 (td0->td_flags & TDF_SINTR) &&
1880 !TD_IS_SUSPENDED(td0)) {
1881 thread_suspend_one(td0);
1882 } else if (td != td0) {
1883 td0->td_flags |= TDF_ASTPENDING;
1887 if (p->p_numthreads == p->p_suspcount) {
1888 SIGDELSET(p->p_siglist, p->p_xstat);
1889 FOREACH_THREAD_IN_PROC(p, td0)
1890 SIGDELSET(td0->td_siglist, p->p_xstat);
1892 mtx_unlock_spin(&sched_lock);
1899 /* Not in "NORMAL" state. discard the signal. */
1900 SIGDELSET(*siglist, sig);
1905 * The process is not stopped so we need to apply the signal to all the
1910 mtx_lock_spin(&sched_lock);
1911 tdsigwakeup(td, sig, action);
1912 thread_unsuspend(p);
1913 mtx_unlock_spin(&sched_lock);
1915 /* If we jump here, sched_lock should not be owned. */
1916 mtx_assert(&sched_lock, MA_NOTOWNED);
1920 * The force of a signal has been directed against a single
1921 * thread. We need to see what we can do about knocking it
1922 * out of any sleep it may be in etc.
1925 tdsigwakeup(struct thread *td, int sig, sig_t action)
1927 struct proc *p = td->td_proc;
1930 PROC_LOCK_ASSERT(p, MA_OWNED);
1931 mtx_assert(&sched_lock, MA_OWNED);
1932 prop = sigprop(sig);
1935 * Bring the priority of a thread up if we want it to get
1936 * killed in this lifetime.
1938 if (action == SIG_DFL && (prop & SA_KILL)) {
1940 sched_nice(td->td_proc, 0);
1941 if (td->td_priority > PUSER)
1942 sched_prio(td, PUSER);
1945 if (TD_ON_SLEEPQ(td)) {
1947 * If thread is sleeping uninterruptibly
1948 * we can't interrupt the sleep... the signal will
1949 * be noticed when the process returns through
1950 * trap() or syscall().
1952 if ((td->td_flags & TDF_SINTR) == 0)
1955 * If SIGCONT is default (or ignored) and process is
1956 * asleep, we are finished; the process should not
1959 if ((prop & SA_CONT) && action == SIG_DFL) {
1960 SIGDELSET(p->p_siglist, sig);
1962 * It may be on either list in this state.
1963 * Remove from both for now.
1965 SIGDELSET(td->td_siglist, sig);
1970 * Give low priority threads a better chance to run.
1972 if (td->td_priority > PUSER)
1973 sched_prio(td, PUSER);
1978 * Other states do nothing with the signal immediately,
1979 * other than kicking ourselves if we are running.
1980 * It will either never be noticed, or noticed very soon.
1983 if (TD_IS_RUNNING(td) && td != curthread)
1990 ptracestop(struct thread *td, int sig)
1992 struct proc *p = td->td_proc;
1995 PROC_LOCK_ASSERT(p, MA_OWNED);
1996 WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK,
1997 &p->p_mtx.mtx_object, "Stopping for traced signal");
1999 mtx_lock_spin(&sched_lock);
2000 td->td_flags |= TDF_XSIG;
2001 mtx_unlock_spin(&sched_lock);
2003 while ((p->p_flag & P_TRACED) && (td->td_flags & TDF_XSIG)) {
2004 if (p->p_flag & P_SINGLE_EXIT) {
2005 mtx_lock_spin(&sched_lock);
2006 td->td_flags &= ~TDF_XSIG;
2007 mtx_unlock_spin(&sched_lock);
2011 * Just make wait() to work, the last stopped thread
2016 p->p_flag |= (P_STOPPED_SIG|P_STOPPED_TRACE);
2017 mtx_lock_spin(&sched_lock);
2018 FOREACH_THREAD_IN_PROC(p, td0) {
2019 if (TD_IS_SLEEPING(td0) &&
2020 (td0->td_flags & TDF_SINTR) &&
2021 !TD_IS_SUSPENDED(td0)) {
2022 thread_suspend_one(td0);
2023 } else if (td != td0) {
2024 td0->td_flags |= TDF_ASTPENDING;
2029 thread_suspend_one(td);
2032 mi_switch(SW_VOL, NULL);
2033 mtx_unlock_spin(&sched_lock);
2036 if (!(p->p_flag & P_TRACED))
2038 if (td->td_flags & TDF_DBSUSPEND) {
2039 if (p->p_flag & P_SINGLE_EXIT)
2041 mtx_lock_spin(&sched_lock);
2045 return (td->td_xsig);
2049 * If the current process has received a signal (should be caught or cause
2050 * termination, should interrupt current syscall), return the signal number.
2051 * Stop signals with default action are processed immediately, then cleared;
2052 * they aren't returned. This is checked after each entry to the system for
2053 * a syscall or trap (though this can usually be done without calling issignal
2054 * by checking the pending signal masks in cursig.) The normal call
2057 * while (sig = cursig(curthread))
2066 sigset_t sigpending;
2067 int sig, prop, newsig;
2072 mtx_assert(&ps->ps_mtx, MA_OWNED);
2073 PROC_LOCK_ASSERT(p, MA_OWNED);
2075 int traced = (p->p_flag & P_TRACED) || (p->p_stops & S_SIG);
2077 sigpending = td->td_siglist;
2078 SIGSETNAND(sigpending, td->td_sigmask);
2080 if (p->p_flag & P_PPWAIT)
2081 SIG_STOPSIGMASK(sigpending);
2082 if (SIGISEMPTY(sigpending)) /* no signal to send */
2084 sig = sig_ffs(&sigpending);
2086 if (p->p_stops & S_SIG) {
2087 mtx_unlock(&ps->ps_mtx);
2088 stopevent(p, S_SIG, sig);
2089 mtx_lock(&ps->ps_mtx);
2093 * We should see pending but ignored signals
2094 * only if P_TRACED was on when they were posted.
2096 if (SIGISMEMBER(ps->ps_sigignore, sig) && (traced == 0)) {
2097 SIGDELSET(td->td_siglist, sig);
2098 if (td->td_pflags & TDP_SA)
2099 SIGADDSET(td->td_sigmask, sig);
2102 if (p->p_flag & P_TRACED && (p->p_flag & P_PPWAIT) == 0) {
2104 * If traced, always stop.
2106 mtx_unlock(&ps->ps_mtx);
2107 newsig = ptracestop(td, sig);
2108 mtx_lock(&ps->ps_mtx);
2111 * If parent wants us to take the signal,
2112 * then it will leave it in p->p_xstat;
2113 * otherwise we just look for signals again.
2115 SIGDELSET(td->td_siglist, sig); /* clear old signal */
2116 if (td->td_pflags & TDP_SA)
2117 SIGADDSET(td->td_sigmask, sig);
2122 * If the traced bit got turned off, go back up
2123 * to the top to rescan signals. This ensures
2124 * that p_sig* and p_sigact are consistent.
2126 if ((p->p_flag & P_TRACED) == 0)
2130 * Put the new signal into td_siglist. If the
2131 * signal is being masked, look for other signals.
2133 SIGADDSET(td->td_siglist, sig);
2134 if (td->td_pflags & TDP_SA)
2135 SIGDELSET(td->td_sigmask, sig);
2136 if (SIGISMEMBER(td->td_sigmask, sig))
2141 prop = sigprop(sig);
2144 * Decide whether the signal should be returned.
2145 * Return the signal's number, or fall through
2146 * to clear it from the pending mask.
2148 switch ((intptr_t)p->p_sigacts->ps_sigact[_SIG_IDX(sig)]) {
2150 case (intptr_t)SIG_DFL:
2152 * Don't take default actions on system processes.
2154 if (p->p_pid <= 1) {
2157 * Are you sure you want to ignore SIGSEGV
2160 printf("Process (pid %lu) got signal %d\n",
2161 (u_long)p->p_pid, sig);
2163 break; /* == ignore */
2166 * If there is a pending stop signal to process
2167 * with default action, stop here,
2168 * then clear the signal. However,
2169 * if process is member of an orphaned
2170 * process group, ignore tty stop signals.
2172 if (prop & SA_STOP) {
2173 if (p->p_flag & P_TRACED ||
2174 (p->p_pgrp->pg_jobc == 0 &&
2176 break; /* == ignore */
2177 mtx_unlock(&ps->ps_mtx);
2178 WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK,
2179 &p->p_mtx.mtx_object, "Catching SIGSTOP");
2180 p->p_flag |= P_STOPPED_SIG;
2183 mtx_lock_spin(&sched_lock);
2184 FOREACH_THREAD_IN_PROC(p, td0) {
2185 if (TD_IS_SLEEPING(td0) &&
2186 (td0->td_flags & TDF_SINTR) &&
2187 !TD_IS_SUSPENDED(td0)) {
2188 thread_suspend_one(td0);
2189 } else if (td != td0) {
2190 td0->td_flags |= TDF_ASTPENDING;
2194 thread_suspend_one(td);
2197 mi_switch(SW_INVOL, NULL);
2198 mtx_unlock_spin(&sched_lock);
2201 mtx_lock(&ps->ps_mtx);
2203 } else if (prop & SA_IGNORE) {
2205 * Except for SIGCONT, shouldn't get here.
2206 * Default action is to ignore; drop it.
2208 break; /* == ignore */
2213 case (intptr_t)SIG_IGN:
2215 * Masking above should prevent us ever trying
2216 * to take action on an ignored signal other
2217 * than SIGCONT, unless process is traced.
2219 if ((prop & SA_CONT) == 0 &&
2220 (p->p_flag & P_TRACED) == 0)
2221 printf("issignal\n");
2222 break; /* == ignore */
2226 * This signal has an action, let
2227 * postsig() process it.
2231 SIGDELSET(td->td_siglist, sig); /* take the signal! */
2240 thread_stopped(struct proc *p)
2242 struct proc *p1 = curthread->td_proc;
2246 PROC_LOCK_ASSERT(p, MA_OWNED);
2247 mtx_assert(&sched_lock, MA_OWNED);
2251 if ((p->p_flag & P_STOPPED_SIG) && (n == p->p_numthreads)) {
2252 mtx_unlock_spin(&sched_lock);
2253 p->p_flag &= ~P_WAITED;
2254 PROC_LOCK(p->p_pptr);
2256 * Wake up parent sleeping in kern_wait(), also send
2257 * SIGCHLD to parent, but SIGCHLD does not guarantee
2258 * that parent will awake, because parent may masked
2261 p->p_pptr->p_flag |= P_STATCHILD;
2263 ps = p->p_pptr->p_sigacts;
2264 mtx_lock(&ps->ps_mtx);
2265 if ((ps->ps_flag & PS_NOCLDSTOP) == 0) {
2266 mtx_unlock(&ps->ps_mtx);
2267 psignal(p->p_pptr, SIGCHLD);
2269 mtx_unlock(&ps->ps_mtx);
2270 PROC_UNLOCK(p->p_pptr);
2271 mtx_lock_spin(&sched_lock);
2276 * Take the action for the specified signal
2277 * from the current set of pending signals.
2283 struct thread *td = curthread;
2284 register struct proc *p = td->td_proc;
2287 sigset_t returnmask;
2290 KASSERT(sig != 0, ("postsig"));
2292 PROC_LOCK_ASSERT(p, MA_OWNED);
2294 mtx_assert(&ps->ps_mtx, MA_OWNED);
2295 SIGDELSET(td->td_siglist, sig);
2296 action = ps->ps_sigact[_SIG_IDX(sig)];
2298 if (KTRPOINT(td, KTR_PSIG))
2299 ktrpsig(sig, action, td->td_pflags & TDP_OLDMASK ?
2300 &td->td_oldsigmask : &td->td_sigmask, 0);
2302 if (p->p_stops & S_SIG) {
2303 mtx_unlock(&ps->ps_mtx);
2304 stopevent(p, S_SIG, sig);
2305 mtx_lock(&ps->ps_mtx);
2308 if (!(td->td_pflags & TDP_SA) && action == SIG_DFL) {
2310 * Default action, where the default is to kill
2311 * the process. (Other cases were ignored above.)
2313 mtx_unlock(&ps->ps_mtx);
2317 if (td->td_pflags & TDP_SA) {
2318 if (sig == SIGKILL) {
2319 mtx_unlock(&ps->ps_mtx);
2325 * If we get here, the signal must be caught.
2327 KASSERT(action != SIG_IGN && !SIGISMEMBER(td->td_sigmask, sig),
2328 ("postsig action"));
2330 * Set the new mask value and also defer further
2331 * occurrences of this signal.
2333 * Special case: user has done a sigsuspend. Here the
2334 * current mask is not of interest, but rather the
2335 * mask from before the sigsuspend is what we want
2336 * restored after the signal processing is completed.
2338 if (td->td_pflags & TDP_OLDMASK) {
2339 returnmask = td->td_oldsigmask;
2340 td->td_pflags &= ~TDP_OLDMASK;
2342 returnmask = td->td_sigmask;
2344 SIGSETOR(td->td_sigmask, ps->ps_catchmask[_SIG_IDX(sig)]);
2345 if (!SIGISMEMBER(ps->ps_signodefer, sig))
2346 SIGADDSET(td->td_sigmask, sig);
2348 if (SIGISMEMBER(ps->ps_sigreset, sig)) {
2350 * See kern_sigaction() for origin of this code.
2352 SIGDELSET(ps->ps_sigcatch, sig);
2353 if (sig != SIGCONT &&
2354 sigprop(sig) & SA_IGNORE)
2355 SIGADDSET(ps->ps_sigignore, sig);
2356 ps->ps_sigact[_SIG_IDX(sig)] = SIG_DFL;
2358 p->p_stats->p_ru.ru_nsignals++;
2359 if (p->p_sig != sig) {
2366 if (td->td_pflags & TDP_SA)
2367 thread_signal_add(curthread, sig);
2369 (*p->p_sysent->sv_sendsig)(action, sig,
2375 * Kill the current process for stated reason.
2383 PROC_LOCK_ASSERT(p, MA_OWNED);
2384 CTR3(KTR_PROC, "killproc: proc %p (pid %d, %s)",
2385 p, p->p_pid, p->p_comm);
2386 log(LOG_ERR, "pid %d (%s), uid %d, was killed: %s\n", p->p_pid, p->p_comm,
2387 p->p_ucred ? p->p_ucred->cr_uid : -1, why);
2388 psignal(p, SIGKILL);
2392 * Force the current process to exit with the specified signal, dumping core
2393 * if appropriate. We bypass the normal tests for masked and caught signals,
2394 * allowing unrecoverable failures to terminate the process without changing
2395 * signal state. Mark the accounting record with the signal termination.
2396 * If dumping core, save the signal number for the debugger. Calls exit and
2406 struct proc *p = td->td_proc;
2408 PROC_LOCK_ASSERT(p, MA_OWNED);
2409 p->p_acflag |= AXSIG;
2411 * We must be single-threading to generate a core dump. This
2412 * ensures that the registers in the core file are up-to-date.
2413 * Also, the ELF dump handler assumes that the thread list doesn't
2414 * change out from under it.
2416 * XXX If another thread attempts to single-thread before us
2417 * (e.g. via fork()), we won't get a dump at all.
2419 if ((sigprop(sig) & SA_CORE) && (thread_single(SINGLE_NO_EXIT) == 0)) {
2422 * Log signals which would cause core dumps
2423 * (Log as LOG_INFO to appease those who don't want
2425 * XXX : Todo, as well as euid, write out ruid too
2426 * Note that coredump() drops proc lock.
2428 if (coredump(td) == 0)
2430 if (kern_logsigexit)
2432 "pid %d (%s), uid %d: exited on signal %d%s\n",
2433 p->p_pid, p->p_comm,
2434 td->td_ucred ? td->td_ucred->cr_uid : -1,
2436 sig & WCOREFLAG ? " (core dumped)" : "");
2439 exit1(td, W_EXITCODE(0, sig));
2443 static char corefilename[MAXPATHLEN] = {"%N.core"};
2444 SYSCTL_STRING(_kern, OID_AUTO, corefile, CTLFLAG_RW, corefilename,
2445 sizeof(corefilename), "process corefile name format string");
2448 * expand_name(name, uid, pid)
2449 * Expand the name described in corefilename, using name, uid, and pid.
2450 * corefilename is a printf-like string, with three format specifiers:
2451 * %N name of process ("name")
2452 * %P process id (pid)
2454 * For example, "%N.core" is the default; they can be disabled completely
2455 * by using "/dev/null", or all core files can be stored in "/cores/%U/%N-%P".
2456 * This is controlled by the sysctl variable kern.corefile (see above).
2460 expand_name(name, uid, pid)
2465 const char *format, *appendstr;
2467 char buf[11]; /* Buffer for pid/uid -- max 4B */
2470 format = corefilename;
2471 temp = malloc(MAXPATHLEN, M_TEMP, M_NOWAIT | M_ZERO);
2474 for (i = 0, n = 0; n < MAXPATHLEN && format[i]; i++) {
2475 switch (format[i]) {
2476 case '%': /* Format character */
2478 switch (format[i]) {
2482 case 'N': /* process name */
2485 case 'P': /* process id */
2486 sprintf(buf, "%u", pid);
2489 case 'U': /* user id */
2490 sprintf(buf, "%u", uid);
2496 "Unknown format character %c in `%s'\n",
2499 l = strlen(appendstr);
2500 if ((n + l) >= MAXPATHLEN)
2502 memcpy(temp + n, appendstr, l);
2506 temp[n++] = format[i];
2509 if (format[i] != '\0')
2513 log(LOG_ERR, "pid %ld (%s), uid (%lu): corename is too long\n",
2514 (long)pid, name, (u_long)uid);
2520 * Dump a process' core. The main routine does some
2521 * policy checking, and creates the name of the coredump;
2522 * then it passes on a vnode and a size limit to the process-specific
2523 * coredump routine if there is one; if there _is not_ one, it returns
2524 * ENOSYS; otherwise it returns the error from the process-specific routine.
2528 coredump(struct thread *td)
2530 struct proc *p = td->td_proc;
2531 register struct vnode *vp;
2532 register struct ucred *cred = td->td_ucred;
2534 struct nameidata nd;
2536 int error, error1, flags, locked;
2538 char *name; /* name of corefile */
2541 PROC_LOCK_ASSERT(p, MA_OWNED);
2542 MPASS((p->p_flag & P_HADTHREADS) == 0 || p->p_singlethread == td);
2543 _STOPEVENT(p, S_CORE, 0);
2545 if (((sugid_coredump == 0) && p->p_flag & P_SUGID) || do_coredump == 0) {
2551 * Note that the bulk of limit checking is done after
2552 * the corefile is created. The exception is if the limit
2553 * for corefiles is 0, in which case we don't bother
2554 * creating the corefile at all. This layout means that
2555 * a corefile is truncated instead of not being created,
2556 * if it is larger than the limit.
2558 limit = (off_t)lim_cur(p, RLIMIT_CORE);
2565 name = expand_name(p->p_comm, td->td_ucred->cr_uid, p->p_pid);
2570 NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_SYSSPACE, name, td); /* XXXKSE */
2571 flags = O_CREAT | FWRITE | O_NOFOLLOW;
2572 error = vn_open(&nd, &flags, S_IRUSR | S_IWUSR, -1);
2578 NDFREE(&nd, NDF_ONLY_PNBUF);
2581 /* Don't dump to non-regular files or files with links. */
2582 if (vp->v_type != VREG ||
2583 VOP_GETATTR(vp, &vattr, cred, td) || vattr.va_nlink != 1) {
2584 VOP_UNLOCK(vp, 0, td);
2589 VOP_UNLOCK(vp, 0, td);
2590 lf.l_whence = SEEK_SET;
2593 lf.l_type = F_WRLCK;
2594 locked = (VOP_ADVLOCK(vp, (caddr_t)p, F_SETLK, &lf, F_FLOCK) == 0);
2596 if (vn_start_write(vp, &mp, V_NOWAIT) != 0) {
2597 lf.l_type = F_UNLCK;
2599 VOP_ADVLOCK(vp, (caddr_t)p, F_UNLCK, &lf, F_FLOCK);
2600 if ((error = vn_close(vp, FWRITE, cred, td)) != 0)
2602 if ((error = vn_start_write(NULL, &mp, V_XSLEEP | PCATCH)) != 0)
2609 if (set_core_nodump_flag)
2610 vattr.va_flags = UF_NODUMP;
2611 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
2612 VOP_LEASE(vp, td, cred, LEASE_WRITE);
2613 VOP_SETATTR(vp, &vattr, cred, td);
2614 VOP_UNLOCK(vp, 0, td);
2616 p->p_acflag |= ACORE;
2619 error = p->p_sysent->sv_coredump ?
2620 p->p_sysent->sv_coredump(td, vp, limit) :
2624 lf.l_type = F_UNLCK;
2625 VOP_ADVLOCK(vp, (caddr_t)p, F_UNLCK, &lf, F_FLOCK);
2627 vn_finished_write(mp);
2629 error1 = vn_close(vp, FWRITE, cred, td);
2637 * Nonexistent system call-- signal process (may want to handle it).
2638 * Flag error in case process won't see signal immediately (blocked or ignored).
2640 #ifndef _SYS_SYSPROTO_H_
2652 struct nosys_args *args;
2654 struct proc *p = td->td_proc;
2663 * Send a SIGIO or SIGURG signal to a process or process group using
2664 * stored credentials rather than those of the current process.
2667 pgsigio(sigiop, sig, checkctty)
2668 struct sigio **sigiop;
2671 struct sigio *sigio;
2675 if (sigio == NULL) {
2679 if (sigio->sio_pgid > 0) {
2680 PROC_LOCK(sigio->sio_proc);
2681 if (CANSIGIO(sigio->sio_ucred, sigio->sio_proc->p_ucred))
2682 psignal(sigio->sio_proc, sig);
2683 PROC_UNLOCK(sigio->sio_proc);
2684 } else if (sigio->sio_pgid < 0) {
2687 PGRP_LOCK(sigio->sio_pgrp);
2688 LIST_FOREACH(p, &sigio->sio_pgrp->pg_members, p_pglist) {
2690 if (CANSIGIO(sigio->sio_ucred, p->p_ucred) &&
2691 (checkctty == 0 || (p->p_flag & P_CONTROLT)))
2695 PGRP_UNLOCK(sigio->sio_pgrp);
2701 filt_sigattach(struct knote *kn)
2703 struct proc *p = curproc;
2705 kn->kn_ptr.p_proc = p;
2706 kn->kn_flags |= EV_CLEAR; /* automatically set */
2708 knlist_add(&p->p_klist, kn, 0);
2714 filt_sigdetach(struct knote *kn)
2716 struct proc *p = kn->kn_ptr.p_proc;
2718 knlist_remove(&p->p_klist, kn, 0);
2722 * signal knotes are shared with proc knotes, so we apply a mask to
2723 * the hint in order to differentiate them from process hints. This
2724 * could be avoided by using a signal-specific knote list, but probably
2725 * isn't worth the trouble.
2728 filt_signal(struct knote *kn, long hint)
2731 if (hint & NOTE_SIGNAL) {
2732 hint &= ~NOTE_SIGNAL;
2734 if (kn->kn_id == hint)
2737 return (kn->kn_data != 0);
2745 ps = malloc(sizeof(struct sigacts), M_SUBPROC, M_WAITOK | M_ZERO);
2747 mtx_init(&ps->ps_mtx, "sigacts", NULL, MTX_DEF);
2752 sigacts_free(struct sigacts *ps)
2755 mtx_lock(&ps->ps_mtx);
2757 if (ps->ps_refcnt == 0) {
2758 mtx_destroy(&ps->ps_mtx);
2759 free(ps, M_SUBPROC);
2761 mtx_unlock(&ps->ps_mtx);
2765 sigacts_hold(struct sigacts *ps)
2767 mtx_lock(&ps->ps_mtx);
2769 mtx_unlock(&ps->ps_mtx);
2774 sigacts_copy(struct sigacts *dest, struct sigacts *src)
2777 KASSERT(dest->ps_refcnt == 1, ("sigacts_copy to shared dest"));
2778 mtx_lock(&src->ps_mtx);
2779 bcopy(src, dest, offsetof(struct sigacts, ps_refcnt));
2780 mtx_unlock(&src->ps_mtx);
2784 sigacts_shared(struct sigacts *ps)
2788 mtx_lock(&ps->ps_mtx);
2789 shared = ps->ps_refcnt > 1;
2790 mtx_unlock(&ps->ps_mtx);