42#include "opt_ktrace.h"
47#include <sys/signalvar.h>
50#include <sys/capsicum.h>
51#include <sys/compressor.h>
52#include <sys/condvar.h>
53#include <sys/devctl.h>
56#include <sys/imgact.h>
57#include <sys/kernel.h>
59#include <sys/ktrace.h>
60#include <sys/limits.h>
62#include <sys/malloc.h>
64#include <sys/refcount.h>
67#include <sys/procdesc.h>
68#include <sys/ptrace.h>
69#include <sys/posix4.h>
71#include <sys/resourcevar.h>
74#include <sys/sleepqueue.h>
78#include <sys/syscallsubr.h>
79#include <sys/sysctl.h>
80#include <sys/sysent.h>
81#include <sys/syslog.h>
82#include <sys/sysproto.h>
83#include <sys/timers.h>
84#include <sys/unistd.h>
87#include <vm/vm_extern.h>
92#include <machine/cpu.h>
94#include <security/audit/audit.h>
100 "struct thread *",
"struct proc *",
"int");
102 "int",
"ksiginfo_t *");
104 "struct thread *",
"struct proc *",
"int");
106static int coredump(
struct thread *);
107static int killpg1(
struct thread *td,
int sig,
int pgid,
int all,
109static int issignal(
struct thread *td);
112static void tdsigwakeup(
struct thread *,
int, sig_t,
int);
117static struct thread *
sigtd(
struct proc *p,
int sig,
bool fast_sigblock);
131 "Log processes quitting on abnormal signals to syslog(3)");
137static SYSCTL_NODE(_kern, OID_AUTO, sigqueue, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
138 "POSIX real time signal");
145SYSCTL_INT(_kern_sigqueue, OID_AUTO, preallocate, CTLFLAG_RDTUN,
158 "Log invalid syscalls");
163 "Fetch sigfastblock word on each syscall entry for proper "
164 "blocking semantic");
169 "Discard ignored signals on delivery, otherwise queue them to "
179#define CANSIGIO(cr1, cr2) \
180 ((cr1)->cr_uid == 0 || \
181 (cr1)->cr_ruid == (cr2)->cr_ruid || \
182 (cr1)->cr_uid == (cr2)->cr_ruid || \
183 (cr1)->cr_ruid == (cr2)->cr_uid || \
184 (cr1)->cr_uid == (cr2)->cr_uid)
188 &
sugid_coredump, 0,
"Allow setuid and setgid processes to dump core");
200 0,
"Enable setting the NODUMP flag on coredump files");
204 0,
"Generate a devctl notification when processes coredump");
211#define SIGPROP_KILL 0x01
212#define SIGPROP_CORE 0x02
213#define SIGPROP_STOP 0x04
214#define SIGPROP_TTYSTOP 0x08
215#define SIGPROP_IGNORE 0x10
216#define SIGPROP_CONT 0x20
252#define _SIG_FOREACH_ADVANCE(i, set) ({ \
256 int __sig = ffs(__bits); \
257 __bits &= ~(1u << (__sig - 1)); \
258 sig = __i * sizeof((set)->__bits[0]) * NBBY + __sig; \
262 if (++__i == _SIG_WORDS) { \
266 __bits = (set)->__bits[__i]; \
271#define SIG_FOREACH(i, set) \
272 for (int32_t __i = -1, __bits = 0; \
273 _SIG_FOREACH_ADVANCE(i, set); ) \
281 NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, 0);
283 p31b_setcfg(CTL_P1003_1B_REALTIME_SIGNALS, _POSIX_REALTIME_SIGNALS);
284 p31b_setcfg(CTL_P1003_1B_RTSIG_MAX, SIGRTMAX - SIGRTMIN + 1);
312 if (!(ksi->ksi_flags & KSI_EXT)) {
322 SIGEMPTYSET(list->sq_signals);
323 SIGEMPTYSET(list->sq_kill);
324 SIGEMPTYSET(list->sq_ptrace);
325 TAILQ_INIT(&list->sq_list);
327 list->sq_flags = SQ_INIT;
339 struct proc *p = sq->sq_proc;
340 struct ksiginfo *ksi, *next;
343 KASSERT(sq->sq_flags & SQ_INIT, (
"sigqueue not inited"));
345 if (!SIGISMEMBER(sq->sq_signals, signo))
348 if (SIGISMEMBER(sq->sq_ptrace, signo)) {
350 SIGDELSET(sq->sq_ptrace, signo);
351 si->ksi_flags |= KSI_PTRACE;
353 if (SIGISMEMBER(sq->sq_kill, signo)) {
356 SIGDELSET(sq->sq_kill, signo);
359 TAILQ_FOREACH_SAFE(ksi, &sq->sq_list, ksi_link, next) {
360 if (ksi->ksi_signo == signo) {
362 TAILQ_REMOVE(&sq->sq_list, ksi, ksi_link);
363 ksi->ksi_sigq = NULL;
364 ksiginfo_copy(ksi, si);
374 SIGDELSET(sq->sq_signals, signo);
375 si->ksi_signo = signo;
386 if (ksi == NULL || (sq = ksi->ksi_sigq) == NULL)
390 TAILQ_REMOVE(&sq->sq_list, ksi, ksi_link);
391 ksi->ksi_sigq = NULL;
392 if (!(ksi->ksi_flags & KSI_EXT) && p != NULL)
395 for (kp = TAILQ_FIRST(&sq->sq_list); kp != NULL;
396 kp = TAILQ_NEXT(kp, ksi_link)) {
397 if (kp->ksi_signo == ksi->ksi_signo)
400 if (kp == NULL && !SIGISMEMBER(sq->sq_kill, ksi->ksi_signo) &&
401 !SIGISMEMBER(sq->sq_ptrace, ksi->ksi_signo))
402 SIGDELSET(sq->sq_signals, ksi->ksi_signo);
408 struct proc *p = sq->sq_proc;
409 struct ksiginfo *ksi;
412 KASSERT(sq->sq_flags & SQ_INIT, (
"sigqueue not inited"));
418 if (signo == SIGKILL || signo == SIGSTOP || si == NULL) {
419 SIGADDSET(sq->sq_kill, signo);
424 if (si->ksi_flags & KSI_INS) {
425 if (si->ksi_flags & KSI_HEAD)
426 TAILQ_INSERT_HEAD(&sq->sq_list, si, ksi_link);
428 TAILQ_INSERT_TAIL(&sq->sq_list, si, ksi_link);
434 SIGADDSET(sq->sq_kill, signo);
447 ksiginfo_copy(si, ksi);
448 ksi->ksi_signo = signo;
449 if (si->ksi_flags & KSI_HEAD)
450 TAILQ_INSERT_HEAD(&sq->sq_list, ksi, ksi_link);
452 TAILQ_INSERT_TAIL(&sq->sq_list, ksi, ksi_link);
457 if ((si->ksi_flags & KSI_PTRACE) != 0) {
458 SIGADDSET(sq->sq_ptrace, signo);
461 }
else if ((si->ksi_flags & KSI_TRAP) != 0 ||
462 (si->ksi_flags & KSI_SIGQ) == 0) {
463 SIGADDSET(sq->sq_kill, signo);
471 SIGADDSET(sq->sq_signals, signo);
478 struct proc *p = sq->sq_proc;
481 KASSERT(sq->sq_flags & SQ_INIT, (
"sigqueue not inited"));
484 PROC_LOCK_ASSERT(p, MA_OWNED);
486 while ((ksi = TAILQ_FIRST(&sq->sq_list)) != NULL) {
487 TAILQ_REMOVE(&sq->sq_list, ksi, ksi_link);
488 ksi->ksi_sigq = NULL;
493 SIGEMPTYSET(sq->sq_signals);
494 SIGEMPTYSET(sq->sq_kill);
495 SIGEMPTYSET(sq->sq_ptrace);
502 struct proc *p1, *p2;
503 ksiginfo_t *ksi, *next;
505 KASSERT(
src->sq_flags & SQ_INIT, (
"src sigqueue not inited"));
506 KASSERT(dst->sq_flags & SQ_INIT, (
"dst sigqueue not inited"));
510 TAILQ_FOREACH_SAFE(ksi, &
src->sq_list, ksi_link, next) {
511 if (SIGISMEMBER(*
set, ksi->ksi_signo)) {
512 TAILQ_REMOVE(&
src->sq_list, ksi, ksi_link);
515 TAILQ_INSERT_TAIL(&dst->sq_list, ksi, ksi_link);
524 SIGSETAND(tmp, *
set);
525 SIGSETOR(dst->sq_kill, tmp);
526 SIGSETNAND(
src->sq_kill, tmp);
528 tmp =
src->sq_ptrace;
529 SIGSETAND(tmp, *
set);
530 SIGSETOR(dst->sq_ptrace, tmp);
531 SIGSETNAND(
src->sq_ptrace, tmp);
533 tmp =
src->sq_signals;
534 SIGSETAND(tmp, *
set);
535 SIGSETOR(dst->sq_signals, tmp);
536 SIGSETNAND(
src->sq_signals, tmp);
541sigqueue_move(sigqueue_t *
src, sigqueue_t *dst,
int signo)
546 SIGADDSET(
set, signo);
554 struct proc *p = sq->sq_proc;
555 ksiginfo_t *ksi, *next;
557 KASSERT(sq->sq_flags & SQ_INIT, (
"src sigqueue not inited"));
560 TAILQ_FOREACH_SAFE(ksi, &sq->sq_list, ksi_link, next) {
561 if (SIGISMEMBER(*
set, ksi->ksi_signo)) {
562 TAILQ_REMOVE(&sq->sq_list, ksi, ksi_link);
563 ksi->ksi_sigq = NULL;
568 SIGSETNAND(sq->sq_kill, *
set);
569 SIGSETNAND(sq->sq_ptrace, *
set);
570 SIGSETNAND(sq->sq_signals, *
set);
579 SIGADDSET(
set, signo);
590 PROC_LOCK_ASSERT(p, MA_OWNED);
595 FOREACH_THREAD_IN_PROC(p, td0)
607 SIGADDSET(
set, signo);
617 SIGADDSET(
set, SIGSTOP);
618 SIGADDSET(
set, SIGTSTP);
619 SIGADDSET(
set, SIGTTIN);
620 SIGADDSET(
set, SIGTTOU);
632 PROC_LOCK_ASSERT(td->td_proc, MA_OWNED);
633 mtx_assert(&td->td_proc->p_sigacts->ps_mtx, MA_OWNED);
634 THREAD_LOCK_ASSERT(td, MA_NOTOWNED);
635 return (SIGPENDING(td) ?
issignal(td) : 0);
647 PROC_LOCK_ASSERT(td->td_proc, MA_OWNED);
649 if (SIGPENDING(td)) {
651 td->td_flags |= TDF_NEEDSIGCHK | TDF_ASTPENDING;
667 if ((td->td_pflags & TDP_ALTSTACK) == 0)
669#if defined(COMPAT_43)
670 if (SV_PROC_FLAG(td->td_proc, SV_AOUT) && td->td_sigstk.ss_size == 0)
671 return ((td->td_sigstk.ss_flags & SS_ONSTACK) != 0);
673 return (sp >= (
size_t)td->td_sigstk.ss_sp &&
674 sp < td->td_sigstk.ss_size + (
size_t)td->td_sigstk.ss_sp);
695 return ((act->sa_flags &
flag) != 0 && (
flag != SA_SIGINFO ||
696 ((__sighandler_t *)act->sa_sigaction != SIG_IGN &&
697 (__sighandler_t *)act->sa_sigaction != SIG_DFL)));
708 struct sigaction *oact,
int flags)
711 struct proc *p = td->td_proc;
713 if (!_SIG_VALID(sig))
715 if (act != NULL && act->sa_handler != SIG_DFL &&
716 act->sa_handler != SIG_IGN && (act->sa_flags & ~(SA_ONSTACK |
717 SA_RESTART | SA_RESETHAND | SA_NOCLDSTOP | SA_NODEFER |
718 SA_NOCLDWAIT | SA_SIGINFO)) != 0)
723 mtx_lock(&ps->ps_mtx);
725 memset(oact, 0,
sizeof(*oact));
726 oact->sa_mask = ps->ps_catchmask[_SIG_IDX(sig)];
727 if (SIGISMEMBER(ps->ps_sigonstack, sig))
728 oact->sa_flags |= SA_ONSTACK;
729 if (!SIGISMEMBER(ps->ps_sigintr, sig))
730 oact->sa_flags |= SA_RESTART;
731 if (SIGISMEMBER(ps->ps_sigreset, sig))
732 oact->sa_flags |= SA_RESETHAND;
733 if (SIGISMEMBER(ps->ps_signodefer, sig))
734 oact->sa_flags |= SA_NODEFER;
735 if (SIGISMEMBER(ps->ps_siginfo, sig)) {
736 oact->sa_flags |= SA_SIGINFO;
738 (__siginfohandler_t *)ps->ps_sigact[_SIG_IDX(sig)];
740 oact->sa_handler = ps->ps_sigact[_SIG_IDX(sig)];
741 if (sig == SIGCHLD && ps->ps_flag & PS_NOCLDSTOP)
742 oact->sa_flags |= SA_NOCLDSTOP;
743 if (sig == SIGCHLD && ps->ps_flag & PS_NOCLDWAIT)
744 oact->sa_flags |= SA_NOCLDWAIT;
747 if ((sig == SIGKILL || sig == SIGSTOP) &&
748 act->sa_handler != SIG_DFL) {
749 mtx_unlock(&ps->ps_mtx);
758 ps->ps_catchmask[_SIG_IDX(sig)] = act->sa_mask;
759 SIG_CANTMASK(ps->ps_catchmask[_SIG_IDX(sig)]);
761 ps->ps_sigact[_SIG_IDX(sig)] =
762 (__sighandler_t *)act->sa_sigaction;
763 SIGADDSET(ps->ps_siginfo, sig);
765 ps->ps_sigact[_SIG_IDX(sig)] = act->sa_handler;
766 SIGDELSET(ps->ps_siginfo, sig);
769 SIGADDSET(ps->ps_sigintr, sig);
771 SIGDELSET(ps->ps_sigintr, sig);
773 SIGADDSET(ps->ps_sigonstack, sig);
775 SIGDELSET(ps->ps_sigonstack, sig);
777 SIGADDSET(ps->ps_sigreset, sig);
779 SIGDELSET(ps->ps_sigreset, sig);
781 SIGADDSET(ps->ps_signodefer, sig);
783 SIGDELSET(ps->ps_signodefer, sig);
784 if (sig == SIGCHLD) {
785 if (act->sa_flags & SA_NOCLDSTOP)
786 ps->ps_flag |= PS_NOCLDSTOP;
788 ps->ps_flag &= ~PS_NOCLDSTOP;
789 if (act->sa_flags & SA_NOCLDWAIT) {
797 ps->ps_flag &= ~PS_NOCLDWAIT;
799 ps->ps_flag |= PS_NOCLDWAIT;
801 ps->ps_flag &= ~PS_NOCLDWAIT;
802 if (ps->ps_sigact[_SIG_IDX(SIGCHLD)] == SIG_IGN)
803 ps->ps_flag |= PS_CLDSIGIGN;
805 ps->ps_flag &= ~PS_CLDSIGIGN;
813 if (ps->ps_sigact[_SIG_IDX(sig)] == SIG_IGN ||
815 ps->ps_sigact[_SIG_IDX(sig)] == SIG_DFL)) {
820 SIGADDSET(ps->ps_sigignore, sig);
821 SIGDELSET(ps->ps_sigcatch, sig);
823 SIGDELSET(ps->ps_sigignore, sig);
824 if (ps->ps_sigact[_SIG_IDX(sig)] == SIG_DFL)
825 SIGDELSET(ps->ps_sigcatch, sig);
827 SIGADDSET(ps->ps_sigcatch, sig);
829#ifdef COMPAT_FREEBSD4
830 if (ps->ps_sigact[_SIG_IDX(sig)] == SIG_IGN ||
831 ps->ps_sigact[_SIG_IDX(sig)] == SIG_DFL ||
832 (
flags & KSA_FREEBSD4) == 0)
833 SIGDELSET(ps->ps_freebsd4, sig);
835 SIGADDSET(ps->ps_freebsd4, sig);
838 if (ps->ps_sigact[_SIG_IDX(sig)] == SIG_IGN ||
839 ps->ps_sigact[_SIG_IDX(sig)] == SIG_DFL ||
840 (
flags & KSA_OSIGSET) == 0)
841 SIGDELSET(ps->ps_osigset, sig);
843 SIGADDSET(ps->ps_osigset, sig);
846 mtx_unlock(&ps->ps_mtx);
851#ifndef _SYS_SYSPROTO_H_
861 struct sigaction act, oact;
862 struct sigaction *actp, *oactp;
865 actp = (uap->
act != NULL) ? &act : NULL;
866 oactp = (uap->
oact != NULL) ? &oact : NULL;
868 error = copyin(uap->
act, actp,
sizeof(act));
874 error = copyout(oactp, uap->
oact,
sizeof(oact));
878#ifdef COMPAT_FREEBSD4
879#ifndef _SYS_SYSPROTO_H_
880struct freebsd4_sigaction_args {
882 struct sigaction *act;
883 struct sigaction *oact;
887freebsd4_sigaction(
struct thread *td,
struct freebsd4_sigaction_args *uap)
889 struct sigaction act, oact;
890 struct sigaction *actp, *oactp;
893 actp = (uap->act != NULL) ? &act : NULL;
894 oactp = (uap->oact != NULL) ? &oact : NULL;
896 error = copyin(uap->act, actp,
sizeof(act));
902 error = copyout(oactp, uap->oact,
sizeof(oact));
908#ifndef _SYS_SYSPROTO_H_
909struct osigaction_args {
911 struct osigaction *nsa;
912 struct osigaction *osa;
916osigaction(
struct thread *td,
struct osigaction_args *uap)
918 struct osigaction sa;
919 struct sigaction nsa, osa;
920 struct sigaction *nsap, *osap;
923 if (uap->signum <= 0 || uap->signum >=
ONSIG)
926 nsap = (uap->nsa != NULL) ? &nsa : NULL;
927 osap = (uap->osa != NULL) ? &osa : NULL;
930 error = copyin(uap->nsa, &sa,
sizeof(sa));
933 nsap->sa_handler = sa.sa_handler;
934 nsap->sa_flags = sa.sa_flags;
935 OSIG2SIG(sa.sa_mask, nsap->sa_mask);
938 if (osap && !error) {
939 sa.sa_handler = osap->sa_handler;
940 sa.sa_flags = osap->sa_flags;
941 SIG2OSIG(osap->sa_mask, sa.sa_mask);
942 error = copyout(&sa, uap->osa,
sizeof(sa));
947#if !defined(__i386__)
950osigreturn(
struct thread *td,
struct osigreturn_args *uap)
970 mtx_lock(&ps->ps_mtx);
971 for (i = 1; i <= NSIG; i++) {
973 SIGADDSET(ps->ps_sigignore, i);
976 mtx_unlock(&ps->ps_mtx);
987 mtx_assert(&ps->ps_mtx, MA_OWNED);
988 SIGDELSET(ps->ps_sigcatch, sig);
990 SIGADDSET(ps->ps_sigignore, sig);
991 ps->ps_sigact[_SIG_IDX(sig)] = SIG_DFL;
992 SIGDELSET(ps->ps_siginfo, sig);
1009 PROC_LOCK_ASSERT(p, MA_OWNED);
1011 mtx_lock(&ps->ps_mtx);
1019 MPASS(td->td_proc == p);
1020 td->td_sigstk.ss_flags = SS_DISABLE;
1021 td->td_sigstk.ss_size = 0;
1022 td->td_sigstk.ss_sp = 0;
1023 td->td_pflags &= ~TDP_ALTSTACK;
1027 ps->ps_flag &= ~(PS_NOCLDWAIT | PS_CLDSIGIGN);
1028 if (ps->ps_sigact[_SIG_IDX(SIGCHLD)] == SIG_IGN)
1029 ps->ps_sigact[_SIG_IDX(SIGCHLD)] = SIG_DFL;
1030 mtx_unlock(&ps->ps_mtx);
1042 sigset_t new_block, oset1;
1047 if ((
flags & SIGPROCMASK_PROC_LOCKED) != 0)
1048 PROC_LOCK_ASSERT(p, MA_OWNED);
1051 mtx_assert(&p->p_sigacts->ps_mtx, (
flags & SIGPROCMASK_PS_LOCKED) != 0
1052 ? MA_OWNED : MA_NOTOWNED);
1054 *oset = td->td_sigmask;
1061 oset1 = td->td_sigmask;
1062 SIGSETOR(td->td_sigmask, *
set);
1063 new_block = td->td_sigmask;
1064 SIGSETNAND(new_block, oset1);
1067 SIGSETNAND(td->td_sigmask, *
set);
1072 oset1 = td->td_sigmask;
1073 if (
flags & SIGPROCMASK_OLD)
1074 SIGSETLO(td->td_sigmask, *
set);
1076 td->td_sigmask = *
set;
1077 new_block = td->td_sigmask;
1078 SIGSETNAND(new_block, oset1);
1095 if (p->p_numthreads != 1)
1100 if (!(
flags & SIGPROCMASK_PROC_LOCKED))
1105#ifndef _SYS_SYSPROTO_H_
1116 sigset_t *setp, *osetp;
1119 setp = (uap->
set != NULL) ? &
set : NULL;
1120 osetp = (uap->
oset != NULL) ? &oset : NULL;
1122 error = copyin(uap->
set, setp,
sizeof(
set));
1127 if (osetp && !error) {
1128 error = copyout(osetp, uap->
oset,
sizeof(oset));
1134#ifndef _SYS_SYSPROTO_H_
1135struct osigprocmask_args {
1141osigprocmask(
struct thread *td,
struct osigprocmask_args *uap)
1146 OSIG2SIG(uap->mask,
set);
1148 SIG2OSIG(oset, td->td_retval[0]);
1160 error = copyin(uap->set, &
set,
sizeof(
set));
1162 td->td_retval[0] = error;
1175 if (error == EINTR && td->td_proc->p_osrel < P_OSREL_SIGWAIT)
1177 td->td_retval[0] = error;
1181 error = copyout(&ksi.ksi_signo, uap->sig,
sizeof(ksi.ksi_signo));
1182 td->td_retval[0] = error;
1190 struct timespec *timeout;
1196 error = copyin(uap->timeout, &
ts,
sizeof(
ts));
1204 error = copyin(uap->set, &
set,
sizeof(
set));
1213 error = copyout(&ksi.ksi_info, uap->info,
sizeof(siginfo_t));
1216 td->td_retval[0] = ksi.ksi_signo;
1227 error = copyin(uap->set, &
set,
sizeof(
set));
1236 error = copyout(&ksi.ksi_info, uap->info,
sizeof(siginfo_t));
1239 td->td_retval[0] = ksi.ksi_signo;
1248 FOREACH_THREAD_IN_PROC(td->td_proc, thr) {
1252 thr->td_si.si_signo = 0;
1258 struct timespec *timeout)
1261 sigset_t saved_mask, new_block;
1263 int error, sig, timo, timevalid = 0;
1264 struct timespec rts, ets,
ts;
1277 if (timeout != NULL) {
1278 if (timeout->tv_nsec >= 0 && timeout->tv_nsec < 1000000000) {
1281 timespecadd(&rts, timeout, &ets);
1286 SIG_CANTMASK(waitset);
1289 saved_mask = td->td_sigmask;
1290 SIGSETNAND(td->td_sigmask, waitset);
1291 if ((p->p_sysent->sv_flags & SV_SIG_DISCIGN) != 0 ||
1294 td->td_flags |= TDF_SIGWAIT;
1298 mtx_lock(&ps->ps_mtx);
1300 mtx_unlock(&ps->ps_mtx);
1301 KASSERT(sig >= 0, (
"sig %d", sig));
1302 if (sig != 0 && SIGISMEMBER(waitset, sig)) {
1317 if (timeout != NULL) {
1323 if (timespeccmp(&rts, &ets, >=)) {
1327 timespecsub(&ets, &rts, &
ts);
1328 TIMESPEC_TO_TIMEVAL(&tv, &
ts);
1339 error = msleep(&p->p_sigacts, &p->p_mtx, PPAUSE | PCATCH,
1343 if (error == ERESTART)
1347 if (timeout != NULL && error == EAGAIN)
1357 if (error == 0 && (p->p_ptevents & PTRACE_SYSCALL) != 0)
1361 td->td_flags &= ~TDF_SIGWAIT;
1364 new_block = saved_mask;
1365 SIGSETNAND(new_block, td->td_sigmask);
1366 td->td_sigmask = saved_mask;
1371 if (p->p_numthreads != 1)
1375 SDT_PROBE2(proc, , , signal__clear, sig, ksi);
1377 if (ksi->ksi_code == SI_TIMER)
1381 if (KTRPOINT(td, KTR_PSIG)) {
1384 mtx_lock(&ps->ps_mtx);
1385 action = ps->ps_sigact[_SIG_IDX(sig)];
1386 mtx_unlock(&ps->ps_mtx);
1387 ktrpsig(sig, action, &td->td_sigmask, ksi->ksi_code);
1390 if (sig == SIGKILL) {
1399#ifndef _SYS_SYSPROTO_H_
1407 struct proc *p = td->td_proc;
1411 pending = p->p_sigqueue.sq_signals;
1412 SIGSETOR(pending, td->td_sigqueue.sq_signals);
1414 return (copyout(&pending, uap->
set,
sizeof(sigset_t)));
1418#ifndef _SYS_SYSPROTO_H_
1419struct osigpending_args {
1424osigpending(
struct thread *td,
struct osigpending_args *uap)
1426 struct proc *p = td->td_proc;
1430 pending = p->p_sigqueue.sq_signals;
1431 SIGSETOR(pending, td->td_sigqueue.sq_signals);
1433 SIG2OSIG(pending, td->td_retval[0]);
1438#if defined(COMPAT_43)
1442#ifndef _SYS_SYSPROTO_H_
1443struct osigvec_args {
1451osigvec(
struct thread *td,
struct osigvec_args *uap)
1454 struct sigaction nsa, osa;
1455 struct sigaction *nsap, *osap;
1458 if (uap->signum <= 0 || uap->signum >=
ONSIG)
1460 nsap = (uap->nsv != NULL) ? &nsa : NULL;
1461 osap = (uap->osv != NULL) ? &osa : NULL;
1463 error = copyin(uap->nsv, &vec,
sizeof(vec));
1466 nsap->sa_handler = vec.sv_handler;
1467 OSIG2SIG(vec.sv_mask, nsap->sa_mask);
1468 nsap->sa_flags = vec.sv_flags;
1469 nsap->sa_flags ^= SA_RESTART;
1471 error =
kern_sigaction(td, uap->signum, nsap, osap, KSA_OSIGSET);
1472 if (osap && !error) {
1473 vec.sv_handler = osap->sa_handler;
1474 SIG2OSIG(osap->sa_mask, vec.sv_mask);
1475 vec.sv_flags = osap->sa_flags;
1476 vec.sv_flags &= ~SA_NOCLDWAIT;
1477 vec.sv_flags ^= SA_RESTART;
1478 error = copyout(&vec, uap->osv,
sizeof(vec));
1483#ifndef _SYS_SYSPROTO_H_
1484struct osigblock_args {
1489osigblock(
struct thread *td,
struct osigblock_args *uap)
1493 OSIG2SIG(uap->mask,
set);
1495 SIG2OSIG(oset, td->td_retval[0]);
1499#ifndef _SYS_SYSPROTO_H_
1500struct osigsetmask_args {
1505osigsetmask(
struct thread *td,
struct osigsetmask_args *uap)
1509 OSIG2SIG(uap->mask,
set);
1511 SIG2OSIG(oset, td->td_retval[0]);
1520#ifndef _SYS_SYSPROTO_H_
1541 struct proc *p = td->td_proc;
1556 SIGPROCMASK_PROC_LOCKED);
1557 td->td_pflags |= TDP_OLDMASK;
1565 (p->p_sysent->sv_set_syscall_retval)(td, EINTR);
1566 for (has_sig = 0; !has_sig;) {
1567 while (msleep(&p->p_sigacts, &p->p_mtx, PPAUSE|PCATCH,
"pause",
1571 mtx_lock(&p->p_sigacts->ps_mtx);
1572 while ((sig =
cursig(td)) != 0) {
1573 KASSERT(sig >= 0, (
"sig %d", sig));
1576 mtx_unlock(&p->p_sigacts->ps_mtx);
1583 if ((p->p_ptevents & PTRACE_SYSCALL) != 0)
1587 td->td_errno = EINTR;
1588 td->td_pflags |= TDP_NERRNO;
1589 return (EJUSTRETURN);
1597#ifndef _SYS_SYSPROTO_H_
1598struct osigsuspend_args {
1604osigsuspend(
struct thread *td,
struct osigsuspend_args *uap)
1608 OSIG2SIG(uap->mask,
mask);
1613#if defined(COMPAT_43)
1614#ifndef _SYS_SYSPROTO_H_
1615struct osigstack_args {
1616 struct sigstack *nss;
1617 struct sigstack *oss;
1622osigstack(
struct thread *td,
struct osigstack_args *uap)
1624 struct sigstack nss, oss;
1627 if (uap->nss != NULL) {
1628 error = copyin(uap->nss, &nss,
sizeof(nss));
1632 oss.ss_sp = td->td_sigstk.ss_sp;
1633 oss.ss_onstack =
sigonstack(cpu_getstack(td));
1634 if (uap->nss != NULL) {
1635 td->td_sigstk.ss_sp = nss.ss_sp;
1636 td->td_sigstk.ss_size = 0;
1637 td->td_sigstk.ss_flags |= nss.ss_onstack & SS_ONSTACK;
1638 td->td_pflags |= TDP_ALTSTACK;
1640 if (uap->oss != NULL)
1641 error = copyout(&oss, uap->oss,
sizeof(oss));
1647#ifndef _SYS_SYSPROTO_H_
1660 if (uap->
ss != NULL) {
1661 error = copyin(uap->
ss, &ss,
sizeof(ss));
1666 (uap->
oss != NULL) ? &oss : NULL);
1669 if (uap->
oss != NULL)
1670 error = copyout(&oss, uap->
oss,
sizeof(stack_t));
1677 struct proc *p = td->td_proc;
1683 *oss = td->td_sigstk;
1684 oss->ss_flags = (td->td_pflags & TDP_ALTSTACK)
1685 ? ((oonstack) ? SS_ONSTACK : 0) : SS_DISABLE;
1691 if ((ss->ss_flags & ~SS_DISABLE) != 0)
1693 if (!(ss->ss_flags & SS_DISABLE)) {
1694 if (ss->ss_size < p->p_sysent->sv_minsigstksz)
1697 td->td_sigstk = *ss;
1698 td->td_pflags |= TDP_ALTSTACK;
1700 td->td_pflags &= ~TDP_ALTSTACK;
1720 if (p->p_pid <= 1 || (p->p_flag & P_SYSTEM) != 0 ||
1721 (notself && p == arg->
td->td_proc) || p->p_state == PRS_NEW)
1725 if (err == 0 && arg->
sig != 0)
1732 else if (arg->
ret == 0 && err != ESRCH && err != EPERM)
1741killpg1(
struct thread *td,
int sig,
int pgid,
int all, ksiginfo_t *ksi)
1758 FOREACH_PROC_IN_SYSTEM(p) {
1768 pgrp =
td->td_proc->p_pgrp;
1778 LIST_FOREACH(p, &pgrp->pg_members, p_pglist) {
1784 if (arg.
ret == 0 && !arg.
sent)
1785 arg.
ret = arg.
found ? EPERM : ESRCH;
1789#ifndef _SYS_SYSPROTO_H_
1815 if (IN_CAPABILITY_MODE(td) && pid != td->td_proc->p_pid)
1818 AUDIT_ARG_SIGNUM(signum);
1820 if ((u_int)signum > _SIG_MAXSIG)
1823 ksiginfo_init(&ksi);
1824 ksi.ksi_signo = signum;
1825 ksi.ksi_code = SI_USER;
1826 ksi.ksi_pid = td->td_proc->p_pid;
1827 ksi.ksi_uid = td->td_ucred->cr_ruid;
1833 AUDIT_ARG_PROCESS(p);
1835 if (error == 0 && signum)
1842 return (
killpg1(td, signum, 0, 1, &ksi));
1844 return (
killpg1(td, signum, 0, 0, &ksi));
1846 return (
killpg1(td, signum, -pid, 0, &ksi));
1857 AUDIT_ARG_SIGNUM(uap->signum);
1858 AUDIT_ARG_FD(uap->fd);
1859 if ((u_int)uap->signum > _SIG_MAXSIG)
1865 AUDIT_ARG_PROCESS(p);
1867 if (error == 0 && uap->signum)
1873#if defined(COMPAT_43)
1874#ifndef _SYS_SYSPROTO_H_
1875struct okillpg_args {
1882okillpg(
struct thread *td,
struct okillpg_args *uap)
1886 AUDIT_ARG_SIGNUM(uap->signum);
1887 AUDIT_ARG_PID(uap->pgid);
1888 if ((u_int)uap->signum > _SIG_MAXSIG)
1891 ksiginfo_init(&ksi);
1892 ksi.ksi_signo = uap->signum;
1893 ksi.ksi_code = SI_USER;
1894 ksi.ksi_pid = td->td_proc->p_pid;
1895 ksi.ksi_uid = td->td_ucred->cr_ruid;
1896 return (
killpg1(td, uap->signum, uap->pgid, 0, &ksi));
1900#ifndef _SYS_SYSPROTO_H_
1912 sv.sival_ptr = uap->
value;
1924 if ((u_int)signum > _SIG_MAXSIG)
1937 if (error == 0 && signum != 0) {
1938 ksiginfo_init(&ksi);
1939 ksi.ksi_flags = KSI_SIGQ;
1940 ksi.ksi_signo = signum;
1941 ksi.ksi_code = SI_QUEUE;
1942 ksi.ksi_pid = td->td_proc->p_pid;
1943 ksi.ksi_uid = td->td_ucred->cr_ruid;
1944 ksi.ksi_value = *
value;
1945 error =
pksignal(p, ksi.ksi_signo, &ksi);
1975pgsignal(
struct pgrp *pgrp,
int sig,
int checkctty, ksiginfo_t *ksi)
1980 PGRP_LOCK_ASSERT(pgrp, MA_OWNED);
1981 LIST_FOREACH(p, &pgrp->pg_members, p_pglist) {
1983 if (p->p_state == PRS_NORMAL &&
1984 (checkctty == 0 || p->p_flag & P_CONTROLT))
2002 mtx_assert(&ps->ps_mtx, MA_OWNED);
2003 td->td_ru.ru_nsignals++;
2004 mask = ps->ps_catchmask[_SIG_IDX(sig)];
2005 if (!SIGISMEMBER(ps->ps_signodefer, sig))
2006 SIGADDSET(
mask, sig);
2008 SIGPROCMASK_PROC_LOCKED | SIGPROCMASK_PS_LOCKED);
2009 if (SIGISMEMBER(ps->ps_sigreset, sig))
2027 sig = ksi->ksi_signo;
2028 code = ksi->ksi_code;
2029 KASSERT(_SIG_VALID(sig), (
"invalid signal"));
2034 mtx_lock(&ps->ps_mtx);
2035 sigmask = td->td_sigmask;
2036 if (td->td_sigblock_val != 0)
2038 if ((p->p_flag & P_TRACED) == 0 && SIGISMEMBER(ps->ps_sigcatch, sig) &&
2039 !SIGISMEMBER(sigmask, sig)) {
2041 if (KTRPOINT(curthread, KTR_PSIG))
2042 ktrpsig(sig, ps->ps_sigact[_SIG_IDX(sig)],
2043 &td->td_sigmask, code);
2045 (*p->p_sysent->sv_sendsig)(ps->ps_sigact[_SIG_IDX(sig)],
2046 ksi, &td->td_sigmask);
2048 mtx_unlock(&ps->ps_mtx);
2056 ps->ps_sigact[_SIG_IDX(sig)] == SIG_IGN)) {
2057 SIGDELSET(td->td_sigmask, sig);
2058 SIGDELSET(ps->ps_sigcatch, sig);
2059 SIGDELSET(ps->ps_sigignore, sig);
2060 ps->ps_sigact[_SIG_IDX(sig)] = SIG_DFL;
2061 td->td_pflags &= ~TDP_SIGFASTBLOCK;
2062 td->td_sigblock_val = 0;
2064 mtx_unlock(&ps->ps_mtx);
2071static struct thread *
2072sigtd(
struct proc *p,
int sig,
bool fast_sigblock)
2074 struct thread *td, *signal_td;
2076 PROC_LOCK_ASSERT(p, MA_OWNED);
2077 MPASS(!fast_sigblock || p == curproc);
2083 if (curproc == p && !SIGISMEMBER(curthread->td_sigmask, sig) &&
2084 (!fast_sigblock || curthread->td_sigblock_val == 0))
2087 FOREACH_THREAD_IN_PROC(p, td) {
2088 if (!SIGISMEMBER(td->td_sigmask, sig) && (!fast_sigblock ||
2089 td != curthread || td->td_sigblock_val == 0)) {
2094 if (signal_td == NULL)
2095 signal_td = FIRST_THREAD_IN_PROC(p);
2121 ksiginfo_init(&ksi);
2122 ksi.ksi_signo = sig;
2123 ksi.ksi_code = SI_KERNEL;
2140 if (sigev->sigev_notify == SIGEV_THREAD_ID) {
2141 td =
tdfind(sigev->sigev_notify_thread_id, p->p_pid);
2157 ksiginfo_init(&ksi);
2158 ksi.ksi_signo = sig;
2159 ksi.ksi_code = SI_KERNEL;
2173 THREAD_LOCK_ASSERT(td, MA_OWNED);
2175 if (intrval == 0 && (td->td_flags & TDF_SIGWAIT) == 0) {
2186 sigqueue_t *sigqueue;
2193 MPASS(td == NULL || p == td->td_proc);
2194 PROC_LOCK_ASSERT(p, MA_OWNED);
2196 if (!_SIG_VALID(sig))
2197 panic(
"%s(): invalid signal %d", __func__, sig);
2199 KASSERT(ksi == NULL || !KSI_ONQ(ksi), (
"%s: ksi on queue", __func__));
2204 if (p->p_state == PRS_ZOMBIE) {
2205 if (ksi && (ksi->ksi_flags & KSI_INS))
2211 KNOTE_LOCKED(p->p_klist, NOTE_SIGNAL | sig);
2215 td =
sigtd(p, sig,
false);
2216 sigqueue = &p->p_sigqueue;
2218 sigqueue = &td->td_sigqueue;
2220 SDT_PROBE3(proc, , , signal__send, td, p, sig);
2228 mtx_lock(&ps->ps_mtx);
2229 if (SIGISMEMBER(ps->ps_sigignore, sig)) {
2231 (p->p_sysent->sv_flags & SV_SIG_DISCIGN) == 0) {
2232 SDT_PROBE3(proc, , , signal__discard, td, p, sig);
2234 mtx_unlock(&ps->ps_mtx);
2235 if (ksi && (ksi->ksi_flags & KSI_INS))
2243 if (SIGISMEMBER(td->td_sigmask, sig))
2245 else if (SIGISMEMBER(ps->ps_sigcatch, sig))
2249 if (SIGISMEMBER(ps->ps_sigintr, sig))
2254 mtx_unlock(&ps->ps_mtx);
2266 (p->p_pgrp->pg_flags & PGRP_ORPHANED) != 0 &&
2267 action == SIG_DFL) {
2268 if (ksi && (ksi->ksi_flags & KSI_INS))
2273 if (p->p_flag & P_CONTINUED) {
2274 p->p_flag &= ~P_CONTINUED;
2275 PROC_LOCK(p->p_pptr);
2277 PROC_UNLOCK(p->p_pptr);
2289 if (action == SIG_HOLD &&
2290 !((prop &
SIGPROP_CONT) && (p->p_flag & P_STOPPED_SIG)))
2303 if (P_SHOULDSTOP(p)) {
2304 KASSERT(!(p->p_flag & P_WEXIT),
2305 (
"signal to stopped but exiting process"));
2306 if (sig == SIGKILL) {
2311 if (p->p_flag & P_TRACED)
2318 p->p_flag &= ~P_STOPPED_SIG;
2327 if (p->p_flag & P_TRACED)
2339 p->p_flag &= ~P_STOPPED_SIG;
2341 if (p->p_numthreads == p->p_suspcount) {
2343 p->p_flag |= P_CONTINUED;
2344 p->p_xsig = SIGCONT;
2345 PROC_LOCK(p->p_pptr);
2347 PROC_UNLOCK(p->p_pptr);
2350 if (action == SIG_DFL) {
2356 if (action == SIG_CATCH) {
2377 if (p->p_flag & P_TRACED)
2384 p->p_flag |= P_STOPPED_SIG;
2399 if (TD_CAN_ABORT(td))
2409 }
else if (p->p_state == PRS_NORMAL) {
2410 if (p->p_flag & P_TRACED || action == SIG_CATCH) {
2415 MPASS(action == SIG_DFL);
2418 if (p->p_flag & (P_PPWAIT|P_WEXIT))
2420 p->p_flag |= P_STOPPED_SIG;
2424 if (p->p_numthreads == p->p_suspcount) {
2459 PROC_SLOCK_ASSERT(p, MA_NOTOWNED);
2474 struct proc *p = td->td_proc;
2475 int prop, wakeup_swapper;
2477 PROC_LOCK_ASSERT(p, MA_OWNED);
2489 td->td_priority > PUSER && !TD_IS_IDLETHREAD(td))
2491 if (TD_ON_SLEEPQ(td)) {
2498 if ((td->td_flags & TDF_SINTR) == 0)
2521 if ((prop &
SIGPROP_STOP) != 0 && (td->td_flags & (TDF_SBDRY |
2522 TDF_SERESTART | TDF_SEINTR)) == TDF_SBDRY)
2528 if (td->td_priority > PUSER && !TD_IS_IDLETHREAD(td))
2544 if (TD_IS_RUNNING(td) && td != curthread)
2557 struct thr_coredump_req *tcq;
2560 MPASS(td == curthread);
2562 PROC_LOCK_ASSERT(p, MA_OWNED);
2563 if ((td->td_dbgflags & TDB_COREDUMPRQ) == 0)
2565 KASSERT((p->p_flag & P_STOPPED_TRACE) != 0, (
"not stopped"));
2567 tcq = td->td_coredump;
2568 KASSERT(tcq != NULL, (
"td_coredump is NULL"));
2570 if (p->p_sysent->sv_coredump == NULL) {
2571 tcq->tc_error = ENOSYS;
2576 rl_cookie = vn_rangelock_wlock(tcq->tc_vp, 0, OFF_MAX);
2578 tcq->tc_error = p->p_sysent->sv_coredump(td, tcq->tc_vp,
2579 tcq->tc_limit, tcq->tc_flags);
2581 vn_rangelock_unlock(tcq->tc_vp, rl_cookie);
2584 td->td_dbgflags &= ~TDB_COREDUMPRQ;
2585 td->td_coredump = NULL;
2595 PROC_LOCK_ASSERT(p, MA_OWNED);
2596 PROC_SLOCK_ASSERT(p, MA_OWNED);
2597 MPASS(sending || td == curthread);
2600 FOREACH_THREAD_IN_PROC(p, td2) {
2602 td2->td_flags |= TDF_ASTPENDING | TDF_NEEDSUSPCHK;
2603 if ((TD_IS_SLEEPING(td2) || TD_IS_SWAPPED(td2)) &&
2604 (td2->td_flags & TDF_SINTR)) {
2605 if (td2->td_flags & TDF_SBDRY) {
2612 KASSERT(!TD_IS_SUSPENDED(td2),
2613 (
"thread with deferred stops suspended"));
2614 if (TD_SBDRY_INTR(td2)) {
2616 TD_SBDRY_ERRNO(td2));
2619 }
else if (!TD_IS_SUSPENDED(td2))
2621 }
else if (!TD_IS_SUSPENDED(td2)) {
2622 if (sending || td != td2)
2623 td2->td_flags |= TDF_ASTPENDING;
2625 if (TD_IS_RUNNING(td2) && td2 != td)
2626 forward_signal(td2);
2631 return (wakeup_swapper);
2644 struct proc *p = td->td_proc;
2648 PROC_LOCK_ASSERT(p, MA_OWNED);
2649 KASSERT(!(p->p_flag & P_WEXIT), (
"Stopping exiting process"));
2650 WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK,
2651 &p->p_mtx.lock_object,
"Stopping for traced signal");
2655 if (si == NULL || (si->ksi_flags & KSI_PTRACE) == 0) {
2656 td->td_dbgflags |= TDB_XSIG;
2657 CTR4(KTR_PTRACE,
"ptracestop: tid %d (pid %d) flags %#x sig %d",
2658 td->td_tid, p->p_pid, td->td_dbgflags, sig);
2660 while ((p->p_flag & P_TRACED) && (td->td_dbgflags & TDB_XSIG)) {
2669 td->td_dbgflags &= ~TDB_XSIG;
2670 td->td_xsig = SIGKILL;
2674 if (p->p_flag & P_SINGLE_EXIT &&
2675 !(td->td_dbgflags & TDB_EXIT)) {
2680 td->td_dbgflags &= ~TDB_XSIG;
2694 if ((td->td_dbgflags & TDB_FSTP) != 0 ||
2695 ((p->p_flag2 & P2_PTRACE_FSTP) == 0 &&
2696 p->p_xthread == NULL)) {
2705 if (td->td_wchan == NULL)
2706 td->td_dbgflags &= ~TDB_FSTP;
2708 p->p_flag2 &= ~P2_PTRACE_FSTP;
2709 p->p_flag |= P_STOPPED_SIG | P_STOPPED_TRACE;
2712 if ((td->td_dbgflags & TDB_STOPATFORK) != 0) {
2713 td->td_dbgflags &= ~TDB_STOPATFORK;
2716 td->td_dbgflags |= TDB_SSWITCH;
2718 td->td_dbgflags &= ~TDB_SSWITCH;
2719 if ((td->td_dbgflags & TDB_COREDUMPRQ) != 0) {
2725 if (p->p_xthread == td)
2726 p->p_xthread = NULL;
2727 if (!(p->p_flag & P_TRACED))
2729 if (td->td_dbgflags & TDB_SUSPEND) {
2730 if (p->p_flag & P_SINGLE_EXIT)
2738 if (si != NULL && sig == td->td_xsig) {
2740 si->ksi_flags |= KSI_HEAD;
2743 }
else if (td->td_xsig != 0) {
2748 ksiginfo_init(&ksi);
2749 ksi.ksi_signo = td->td_xsig;
2750 ksi.ksi_flags |= KSI_PTRACE;
2751 td2 =
sigtd(p, td->td_xsig,
false);
2757 return (td->td_xsig);
2766 bool fastblk, pslocked;
2768 PROC_LOCK_ASSERT(p, MA_OWNED);
2770 pslocked = (
flags & SIGPROCMASK_PS_LOCKED) != 0;
2771 mtx_assert(&ps->ps_mtx, pslocked ? MA_OWNED : MA_NOTOWNED);
2772 if (SIGISEMPTY(p->p_siglist))
2774 SIGSETAND(block, p->p_siglist);
2775 fastblk = (
flags & SIGPROCMASK_FASTBLK) != 0;
2777 td =
sigtd(p, sig, fastblk);
2784 if (fastblk && td == curthread)
2789 mtx_lock(&ps->ps_mtx);
2790 if (p->p_flag & P_TRACED ||
2791 (SIGISMEMBER(ps->ps_sigcatch, sig) &&
2792 !SIGISMEMBER(td->td_sigmask, sig))) {
2794 (SIGISMEMBER(ps->ps_sigintr, sig) ? EINTR :
2798 mtx_unlock(&ps->ps_mtx);
2809 PROC_LOCK_ASSERT(p, MA_OWNED);
2812 if (p->p_numthreads == 1)
2823 SIGFILLSET(unblocked);
2824 SIGSETNAND(unblocked, td->td_sigmask);
2825 SIGFILLSET(td->td_sigmask);
2834 MPASS((cflags & (TDF_SEINTR | TDF_SERESTART)) == 0 ||
2835 (cflags & TDF_SBDRY) != 0);
2836 return (cflags & (TDF_SBDRY | TDF_SEINTR | TDF_SERESTART));
2857 case SIGDEFERSTOP_NOP:
2860 case SIGDEFERSTOP_OFF:
2863 case SIGDEFERSTOP_SILENT:
2864 nflags = (cflags | TDF_SBDRY) & ~(TDF_SEINTR | TDF_SERESTART);
2866 case SIGDEFERSTOP_EINTR:
2867 nflags = (cflags | TDF_SBDRY | TDF_SEINTR) & ~TDF_SERESTART;
2869 case SIGDEFERSTOP_ERESTART:
2870 nflags = (cflags | TDF_SBDRY | TDF_SERESTART) & ~TDF_SEINTR;
2873 panic(
"sigdeferstop: invalid mode %x",
mode);
2876 if (cflags == nflags)
2877 return (SIGDEFERSTOP_VAL_NCHG);
2879 td->td_flags = (td->td_flags & ~cflags) | nflags;
2896 KASSERT(prev != SIGDEFERSTOP_VAL_NCHG, (
"failed sigallowstop"));
2897 KASSERT((prev & ~(TDF_SBDRY | TDF_SEINTR | TDF_SERESTART)) == 0,
2898 (
"sigallowstop: incorrect previous mode %x", prev));
2901 if (cflags != prev) {
2903 td->td_flags = (td->td_flags & ~cflags) | prev;
2930 struct sigqueue *queue;
2934 KASSERT(_SIG_VALID(sig), (
"%s: invalid signal %d", __func__, sig));
2938 mtx_assert(&ps->ps_mtx, MA_OWNED);
2939 PROC_LOCK_ASSERT(p, MA_OWNED);
2946 if (SIGISMEMBER(ps->ps_sigignore, sig) &&
2947 (p->p_flag & P_TRACED) == 0 &&
2948 (td->td_flags & TDF_SIGWAIT) == 0) {
2952 if ((p->p_flag & (P_TRACED | P_PPTRACE)) == P_TRACED) {
2959 queue = &td->td_sigqueue;
2960 ksiginfo_init(&ksi);
2962 queue = &p->p_sigqueue;
2965 td->td_si = ksi.ksi_info;
2967 mtx_unlock(&ps->ps_mtx);
2969 mtx_lock(&ps->ps_mtx);
2971 td->td_si.si_signo = 0;
2983 if (SIGISMEMBER(td->td_sigmask, sig)) {
2984 ksi.ksi_flags |= KSI_HEAD;
2994 if ((p->p_flag & P_TRACED) == 0) {
2995 if ((ksi.ksi_flags & KSI_PTRACE) == 0) {
2996 ksi.ksi_flags |= KSI_HEAD;
3008 switch ((intptr_t)p->p_sigacts->ps_sigact[_SIG_IDX(sig)]) {
3009 case (intptr_t)SIG_DFL:
3013 if (p->p_pid <= 1) {
3019 printf(
"Process (pid %lu) got signal %d\n",
3020 (u_long)p->p_pid, sig);
3034 mtx_unlock(&ps->ps_mtx);
3035 if ((p->p_flag & (P_TRACED | P_WEXIT |
3036 P_SINGLE_EXIT)) != 0 || ((p->p_pgrp->
3037 pg_flags & PGRP_ORPHANED) != 0 &&
3039 mtx_lock(&ps->ps_mtx);
3042 if (TD_SBDRY_INTR(td)) {
3043 KASSERT((td->td_flags & TDF_SBDRY) != 0,
3044 (
"lost TDF_SBDRY"));
3045 mtx_lock(&ps->ps_mtx);
3048 WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK,
3049 &p->p_mtx.lock_object,
"Catching SIGSTOP");
3052 p->p_flag |= P_STOPPED_SIG;
3058 mtx_lock(&ps->ps_mtx);
3061 (td->td_flags & TDF_SIGWAIT) == 0) {
3071 case (intptr_t)SIG_IGN:
3072 if ((td->td_flags & TDF_SIGWAIT) == 0)
3101 sigset_t sigpending;
3105 PROC_LOCK_ASSERT(p, MA_OWNED);
3108 sigpending = td->td_sigqueue.sq_signals;
3109 SIGSETOR(sigpending, p->p_sigqueue.sq_signals);
3110 SIGSETNAND(sigpending, td->td_sigmask);
3112 if ((p->p_flag & P_PPWAIT) != 0 || (td->td_flags &
3113 (TDF_SBDRY | TDF_SERESTART | TDF_SEINTR)) == TDF_SBDRY)
3114 SIG_STOPSIGMASK(sigpending);
3115 if (SIGISEMPTY(sigpending))
3126 if ((td->td_pflags & TDP_SIGFASTBLOCK) != 0) {
3127 if (td->td_sigblock_val != 0)
3129 if (SIGISEMPTY(sigpending)) {
3130 td->td_pflags |= TDP_SIGFASTPENDING;
3135 if ((p->p_flag & (P_TRACED | P_PPTRACE)) == P_TRACED &&
3136 (p->p_flag2 & P2_PTRACE_FSTP) != 0 &&
3137 SIGISMEMBER(sigpending, SIGSTOP)) {
3144 td->td_dbgflags |= TDB_FSTP;
3145 SIGEMPTYSET(sigpending);
3146 SIGADDSET(sigpending, SIGSTOP);
3172 PROC_LOCK_ASSERT(p, MA_OWNED);
3173 PROC_SLOCK_ASSERT(p, MA_OWNED);
3177 if ((p->p_flag & P_STOPPED_SIG) && (n == p->p_numthreads)) {
3179 p->p_flag &= ~P_WAITED;
3180 PROC_LOCK(p->p_pptr);
3182 CLD_TRAPPED : CLD_STOPPED);
3183 PROC_UNLOCK(p->p_pptr);
3200 sigset_t returnmask;
3202 KASSERT(sig != 0, (
"postsig"));
3206 PROC_LOCK_ASSERT(p, MA_OWNED);
3208 mtx_assert(&ps->ps_mtx, MA_OWNED);
3209 ksiginfo_init(&ksi);
3213 ksi.ksi_signo = sig;
3214 if (ksi.ksi_code == SI_TIMER)
3216 action = ps->ps_sigact[_SIG_IDX(sig)];
3218 if (KTRPOINT(td, KTR_PSIG))
3219 ktrpsig(sig, action, td->td_pflags & TDP_OLDMASK ?
3220 &td->td_oldsigmask : &td->td_sigmask, ksi.ksi_code);
3223 if (action == SIG_DFL) {
3228 mtx_unlock(&ps->ps_mtx);
3236 KASSERT(action != SIG_IGN, (
"postsig action %p", action));
3237 KASSERT(!SIGISMEMBER(td->td_sigmask, sig),
3238 (
"postsig action: blocked sig %d", sig));
3249 if (td->td_pflags & TDP_OLDMASK) {
3250 returnmask = td->td_oldsigmask;
3251 td->td_pflags &= ~TDP_OLDMASK;
3253 returnmask = td->td_sigmask;
3255 if (p->p_sig == sig) {
3258 (*p->p_sysent->sv_sendsig)(action, &ksi, &returnmask);
3267 struct proc *p __diagused;
3271 PROC_LOCK_ASSERT(p, MA_OWNED);
3273 if ((td->td_flags & TDF_NEEDSUSPCHK) == 0)
3277 MPASS(ret == 0 || ret == EINTR || ret == ERESTART);
3289 PROC_LOCK_ASSERT(p, MA_OWNED);
3291 if ((td->td_flags & TDF_NEEDSIGCHK) == 0)
3295 mtx_lock(&ps->ps_mtx);
3298 mtx_unlock(&ps->ps_mtx);
3299 KASSERT((td->td_flags & TDF_SBDRY) != 0, (
"lost TDF_SBDRY"));
3300 KASSERT(TD_SBDRY_INTR(td),
3301 (
"lost TDF_SERESTART of TDF_SEINTR"));
3302 KASSERT((td->td_flags & (TDF_SEINTR | TDF_SERESTART)) !=
3303 (TDF_SEINTR | TDF_SERESTART),
3304 (
"both TDF_SEINTR and TDF_SERESTART"));
3305 ret = TD_SBDRY_ERRNO(td);
3306 }
else if (sig != 0) {
3307 ret = SIGISMEMBER(ps->ps_sigintr, sig) ? EINTR : ERESTART;
3308 mtx_unlock(&ps->ps_mtx);
3310 mtx_unlock(&ps->ps_mtx);
3320 if ((td->td_dbgflags & TDB_FSTP) != 0) {
3323 td->td_dbgflags &= ~TDB_FSTP;
3337 if ((td->td_flags & (TDF_NEEDSIGCHK | TDF_NEEDSUSPCHK)) == 0)
3359 if ((td->td_flags & TDF_NEEDSIGCHK) == 0)
3365 mtx_lock(&ps->ps_mtx);
3366 res = SIGISMEMBER(td->td_sigqueue.sq_signals, SIGKILL) ||
3367 SIGISMEMBER(p->p_sigqueue.sq_signals, SIGKILL);
3368 mtx_unlock(&ps->ps_mtx);
3377 PROC_LOCK_ASSERT(p, MA_OWNED);
3378 if ((p->p_flag & P_WKILLED) == 0) {
3379 p->p_flag |= P_WKILLED;
3385 if ((p->p_flag & (P_INMEM | P_SWAPPINGIN)) == 0)
3397 PROC_LOCK_ASSERT(p, MA_OWNED);
3398 CTR3(KTR_PROC,
"killproc: proc %p (pid %d, %s)", p, p->p_pid,
3400 log(LOG_ERR,
"pid %d (%s), jid %d, uid %d, was killed: %s\n",
3401 p->p_pid, p->p_comm, p->p_ucred->cr_prison->pr_id,
3402 p->p_ucred->cr_uid, why);
3418 struct proc *p = td->td_proc;
3420 PROC_LOCK_ASSERT(p, MA_OWNED);
3421 p->p_acflag |= AXSIG;
3445 "pid %d (%s), jid %d, uid %d: exited on "
3446 "signal %d%s\n", p->p_pid, p->p_comm,
3447 p->p_ucred->cr_prison->pr_id,
3448 td->td_ucred->cr_uid,
3450 sig & WCOREFLAG ?
" (core dumped)" :
"");
3464 PROC_LOCK_ASSERT(p, MA_OWNED);
3465 PROC_LOCK_ASSERT(p->p_pptr, MA_OWNED);
3467 if (p->p_ksi != NULL) {
3468 p->p_ksi->ksi_signo = SIGCHLD;
3469 p->p_ksi->ksi_code = reason;
3470 p->p_ksi->ksi_status = status;
3471 p->p_ksi->ksi_pid = p->p_pid;
3472 p->p_ksi->ksi_uid = p->p_ucred->cr_ruid;
3473 if (KSI_ONQ(p->p_ksi))
3476 pksignal(p->p_pptr, SIGCHLD, p->p_ksi);
3484 PROC_LOCK_ASSERT(p, MA_OWNED);
3485 PROC_LOCK_ASSERT(p->p_pptr, MA_OWNED);
3493 p->p_pptr->p_flag |= P_STATCHILD;
3496 ps = p->p_pptr->p_sigacts;
3497 mtx_lock(&ps->ps_mtx);
3498 if ((ps->ps_flag & PS_NOCLDSTOP) == 0) {
3499 mtx_unlock(&ps->ps_mtx);
3502 mtx_unlock(&ps->ps_mtx);
3523 if (WCOREDUMP(p->p_xsig)) {
3524 reason = CLD_DUMPED;
3525 status = WTERMSIG(p->p_xsig);
3526 }
else if (WIFSIGNALED(p->p_xsig)) {
3527 reason = CLD_KILLED;
3528 status = WTERMSIG(p->p_xsig);
3530 reason = CLD_EXITED;
3531 status = p->p_xexit;
3540#define MAX_NUM_CORE_FILES 100000
3541#ifndef NUM_CORE_FILES
3542#define NUM_CORE_FILES 5
3555 if (error != 0 || req->newptr == NULL)
3565 CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
sizeof(
int),
3567 "Maximum number of generated process corefiles while using index format");
3569#define GZIP_SUFFIX ".gz"
3570#define ZSTD_SUFFIX ".zst"
3581 if (error != 0 || req->newptr == NULL)
3589 CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_NEEDGIANT, 0,
sizeof(
int),
3591 "Enable compression of user corefiles ("
3592 __XSTRING(COMPRESS_GZIP)
" = gzip, "
3593 __XSTRING(COMPRESS_ZSTD)
" = zstd)");
3598 "Corefile compression level");
3603#define corefilename_lock allproc_lock
3622 "Process corefile name format string");
3629 vn_close(vp, FWRITE, td->td_ucred, td);
3641 int indexlen,
int ncores,
struct vnode **vpp)
3643 struct vnode *oldvp, *nextvp, *vp;
3645 struct nameidata nd;
3646 int error, i,
flags, oflags, cmode;
3648 struct timespec lasttime;
3650 nextvp = oldvp = NULL;
3651 cmode = S_IRUSR | S_IWUSR;
3652 oflags = VN_OPEN_NOAUDIT | VN_OPEN_NAMECACHE |
3655 for (i = 0; i < ncores; i++) {
3656 flags = O_CREAT | FWRITE | O_NOFOLLOW;
3658 ch =
name[indexpos + indexlen];
3659 (void)
snprintf(
name + indexpos, indexlen + 1,
"%.*u", indexlen,
3661 name[indexpos + indexlen] = ch;
3663 NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_SYSSPACE,
name);
3670 NDFREE(&nd, NDF_ONLY_PNBUF);
3671 if ((
flags & O_CREAT) == O_CREAT) {
3676 error = VOP_GETATTR(vp, &vattr, td->td_ucred);
3682 if (oldvp == NULL ||
3683 lasttime.tv_sec > vattr.va_mtime.tv_sec ||
3684 (lasttime.tv_sec == vattr.va_mtime.tv_sec &&
3685 lasttime.tv_nsec >= vattr.va_mtime.tv_nsec)) {
3687 vn_close(oldvp, FWRITE, td->td_ucred, td);
3690 lasttime = vattr.va_mtime;
3696 if (oldvp != NULL) {
3697 if (nextvp == NULL) {
3698 if ((td->td_proc->p_flag & P_SUGID) != 0) {
3700 vn_close(oldvp, FWRITE, td->td_ucred, td);
3703 error = vn_lock(nextvp, LK_EXCLUSIVE);
3705 vn_close(nextvp, FWRITE, td->td_ucred,
3711 vn_close(oldvp, FWRITE, td->td_ucred, td);
3738 int compress,
int signum,
struct vnode **vpp,
char **namep)
3741 struct nameidata nd;
3743 char *hostname, *
name;
3744 int cmode, error,
flags, i, indexpos, indexlen, oflags, ncores;
3748 name =
malloc(MAXPATHLEN, M_TEMP, M_WAITOK | M_ZERO);
3754 for (i = 0; format[i] !=
'\0'; i++) {
3755 switch (format[i]) {
3758 switch (format[i]) {
3763 if (hostname == NULL) {
3764 hostname =
malloc(MAXHOSTNAMELEN,
3772 if (indexpos != -1) {
3779 indexlen =
sbuf_len(&sb) - indexpos;
3795 "Unknown format character %c in "
3796 "corename `%s'\n", format[i], format);
3806 free(hostname, M_TEMP);
3807 if (compress == COMPRESS_GZIP)
3809 else if (compress == COMPRESS_ZSTD)
3812 log(LOG_ERR,
"pid %ld (%s), uid (%lu): corename is too "
3813 "long\n", (
long)pid, comm, (u_long)uid);
3821 if (indexpos != -1) {
3826 "pid %d (%s), uid (%u): Path `%s' failed "
3827 "on initial open test, error = %d\n",
3828 pid, comm, uid,
name, error);
3831 cmode = S_IRUSR | S_IWUSR;
3832 oflags = VN_OPEN_NOAUDIT | VN_OPEN_NAMECACHE |
3834 flags = O_CREAT | FWRITE | O_NOFOLLOW;
3835 if ((td->td_proc->p_flag & P_SUGID) != 0)
3838 NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_SYSSPACE,
name);
3843 NDFREE(&nd, NDF_ONLY_PNBUF);
3849 audit_proc_coredump(td,
name, error);
3869 struct proc *p = td->td_proc;
3870 struct ucred *cred = td->td_ucred;
3874 size_t fullpathsize;
3875 int error, error1, locked;
3879 char *fullpath, *freepath = NULL;
3882 PROC_LOCK_ASSERT(p, MA_OWNED);
3883 MPASS((p->p_flag & P_HADTHREADS) == 0 || p->p_singlethread == td);
3886 (p->p_flag2 & P2_NOTRACE) != 0) {
3899 limit = (off_t)
lim_cur(td, RLIMIT_CORE);
3900 if (limit == 0 || racct_get_available(p, RACCT_CORE) == 0) {
3906 error =
corefile_open(p->p_comm, cred->cr_uid, p->p_pid, td,
3915 if (vp->v_type != VREG || VOP_GETATTR(vp, &vattr, cred) != 0 ||
3916 vattr.va_nlink != 1 || (vp->v_vflag & VV_SYSTEM) != 0 ||
3917 vattr.va_uid != cred->cr_uid) {
3926 rl_cookie = vn_rangelock_wlock(vp, 0, OFF_MAX);
3928 lf.l_whence = SEEK_SET;
3931 lf.l_type = F_WRLCK;
3932 locked = (VOP_ADVLOCK(vp, (caddr_t)p, F_SETLK, &lf, F_FLOCK) == 0);
3937 vattr.va_flags = UF_NODUMP;
3938 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
3939 VOP_SETATTR(vp, &vattr, cred);
3942 p->p_acflag |= ACORE;
3945 if (p->p_sysent->sv_coredump != NULL) {
3946 error = p->p_sysent->sv_coredump(td, vp, limit, 0);
3952 lf.l_type = F_UNLCK;
3953 VOP_ADVLOCK(vp, (caddr_t)p, F_UNLCK, &lf, F_FLOCK);
3955 vn_rangelock_unlock(vp, rl_cookie);
3963 sb = sbuf_new_auto();
3968 free(freepath, M_TEMP);
3976 if (
name[0] !=
'/') {
3977 fullpathsize = MAXPATHLEN;
3978 freepath =
malloc(fullpathsize, M_TEMP, M_WAITOK);
3979 if (
vn_getcwd(freepath, &fullpath, &fullpathsize) != 0) {
3980 free(freepath, M_TEMP);
3984 free(freepath, M_TEMP);
3994 error1 =
vn_close(vp, FWRITE, cred, td);
3998 audit_proc_coredump(td,
name, error);
4008#ifndef _SYS_SYSPROTO_H_
4025 uprintf(
"pid %d comm %s: nosys %d\n", p->p_pid, p->p_comm,
4030 printf(
"pid %d comm %s: nosys %d\n", p->p_pid, p->p_comm,
4041pgsigio(
struct sigio **sigiop,
int sig,
int checkctty)
4044 struct sigio *sigio;
4046 ksiginfo_init(&ksi);
4047 ksi.ksi_signo = sig;
4048 ksi.ksi_code = SI_KERNEL;
4052 if (sigio == NULL) {
4056 if (sigio->sio_pgid > 0) {
4057 PROC_LOCK(sigio->sio_proc);
4058 if (
CANSIGIO(sigio->sio_ucred, sigio->sio_proc->p_ucred))
4060 PROC_UNLOCK(sigio->sio_proc);
4061 }
else if (sigio->sio_pgid < 0) {
4064 PGRP_LOCK(sigio->sio_pgrp);
4065 LIST_FOREACH(p, &sigio->sio_pgrp->pg_members, p_pglist) {
4067 if (p->p_state == PRS_NORMAL &&
4068 CANSIGIO(sigio->sio_ucred, p->p_ucred) &&
4069 (checkctty == 0 || (p->p_flag & P_CONTROLT)))
4073 PGRP_UNLOCK(sigio->sio_pgrp);
4081 struct proc *p = curproc;
4083 kn->kn_ptr.p_proc = p;
4084 kn->kn_flags |= EV_CLEAR;
4094 struct proc *p = kn->kn_ptr.p_proc;
4109 if (hint & NOTE_SIGNAL) {
4110 hint &= ~NOTE_SIGNAL;
4112 if (kn->kn_id == hint)
4115 return (kn->kn_data != 0);
4123 ps =
malloc(
sizeof(
struct sigacts), M_SUBPROC, M_WAITOK | M_ZERO);
4124 refcount_init(&ps->ps_refcnt, 1);
4125 mtx_init(&ps->ps_mtx,
"sigacts", NULL, MTX_DEF);
4133 if (refcount_release(&ps->ps_refcnt) == 0)
4135 mtx_destroy(&ps->ps_mtx);
4136 free(ps, M_SUBPROC);
4143 refcount_acquire(&ps->ps_refcnt);
4151 KASSERT(dest->ps_refcnt == 1, (
"sigacts_copy to shared dest"));
4152 mtx_lock(&
src->ps_mtx);
4153 bcopy(
src, dest, offsetof(
struct sigacts, ps_refcnt));
4154 mtx_unlock(&
src->ps_mtx);
4161 return (ps->ps_refcnt > 1);
4171 PROC_LOCK_ASSERT(p, MA_OWNED);
4172 mtx_assert(&ps->ps_mtx, MA_OWNED);
4193 ksiginfo_init_trap(&ksi);
4194 ksi.ksi_signo = SIGSEGV;
4195 ksi.ksi_code = write ? SEGV_ACCERR : SEGV_MAPERR;
4196 ksi.ksi_addr = td->td_sigblock_ptr;
4205 if ((td->td_pflags & TDP_SIGFASTBLOCK) == 0)
4207 if (fueword32((
void *)td->td_sigblock_ptr, &
res) == -1) {
4212 td->td_sigblock_val =
res & ~SIGFASTBLOCK_FLAGS;
4228 td->td_flags |= TDF_ASTPENDING | TDF_NEEDSIGCHK;
4242 case SIGFASTBLOCK_SETPTR:
4243 if ((td->td_pflags & TDP_SIGFASTBLOCK) != 0) {
4247 if (((uintptr_t)(uap->ptr) & (
sizeof(uint32_t) - 1)) != 0) {
4251 td->td_pflags |= TDP_SIGFASTBLOCK;
4252 td->td_sigblock_ptr = uap->ptr;
4255 case SIGFASTBLOCK_UNBLOCK:
4256 if ((td->td_pflags & TDP_SIGFASTBLOCK) == 0) {
4262 res = casueword32(td->td_sigblock_ptr,
4263 SIGFASTBLOCK_PEND, &oldval, 0);
4272 if (oldval != SIGFASTBLOCK_PEND) {
4295 td->td_sigblock_val = 0;
4306 case SIGFASTBLOCK_UNSETPTR:
4307 if ((td->td_pflags & TDP_SIGFASTBLOCK) == 0) {
4315 if (oldval != 0 && oldval != SIGFASTBLOCK_PEND) {
4334 if ((td->td_pflags & TDP_SIGFASTBLOCK) == 0)
4336 td->td_sigblock_val = 0;
4337 resched = (td->td_pflags & TDP_SIGFASTPENDING) != 0 ||
4339 td->td_pflags &= ~(TDP_SIGFASTBLOCK | TDP_SIGFASTPENDING);
4357 if ((td->td_pflags & TDP_SIGFASTPENDING) == 0)
4359 res = fueword32((
void *)td->td_sigblock_ptr, &oldval);
4365 res = casueword32(td->td_sigblock_ptr, oldval, &oldval,
4366 oldval | SIGFASTBLOCK_PEND);
4372 td->td_sigblock_val = oldval & ~SIGFASTBLOCK_FLAGS;
4373 td->td_pflags &= ~TDP_SIGFASTPENDING;
int tvtohz(struct timeval *tv)
void knlist_remove(struct knlist *knl, struct knote *kn, int islocked)
void knlist_add(struct knlist *knl, struct knote *kn, int islocked)
void kqtimer_proc_continue(struct proc *p)
void knote(struct knlist *list, long hint, int lockflags)
void exit1(struct thread *td, int rval, int signo)
void getcredhostname(struct ucred *cred, char *buf, size_t size)
void *() malloc(size_t size, struct malloc_type *mtp, int flags)
void free(void *addr, struct malloc_type *mtp)
struct proc * pfind_any(pid_t pid)
struct sx __exclusive_cache_line proctree_lock
struct sx __exclusive_cache_line allproc_lock
struct pgrp * pgfind(pid_t pgid)
int p_cansignal(struct thread *td, struct proc *p, int signum)
rlim_t() lim_cur(struct thread *td, int which)
void panic(const char *fmt,...)
SYSCTL_PROC(_debug, OID_AUTO, ncores, CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_MPSAFE, 0, sizeof(int), sysctl_debug_num_cores_check, "I", "Maximum number of generated process corefiles while using index format")
static void sigparent(struct proc *p, int reason, int status)
void killproc(struct proc *p, const char *why)
SYSCTL_INT(_kern, KERN_LOGSIGEXIT, logsigexit, CTLFLAG_RW, &kern_logsigexit, 0, "Log processes quitting on abnormal signals to syslog(3)")
#define MAX_NUM_CORE_FILES
int sig_ast_needsigchk(struct thread *td)
static int kern_forcesigexit
void gsignal(int pgid, int sig, ksiginfo_t *ksi)
struct filterops sig_filtops
static void sigqueue_delete_set_proc(struct proc *p, const sigset_t *set)
void tdsigcleanup(struct thread *td)
void tdksignal(struct thread *td, int sig, ksiginfo_t *ksi)
static void sigqueue_move_set(sigqueue_t *src, sigqueue_t *dst, const sigset_t *set)
void signotify(struct thread *td)
int sigacts_shared(struct sigacts *ps)
int pksignal(struct proc *p, int sig, ksiginfo_t *ksi)
int compress_user_cores_level
static int sig_suspend_threads(struct thread *, struct proc *, int)
void sigfastblock_clear(struct thread *td)
int kern_sigsuspend(struct thread *td, sigset_t mask)
int nosys(struct thread *td, struct nosys_args *args)
void childproc_continued(struct proc *p)
SDT_PROBE_DEFINE3(proc,,, signal__send, "struct thread *", "struct proc *", "int")
struct sigacts * sigacts_alloc(void)
void sigallowstop_impl(int prev)
static struct thread * sigtd(struct proc *p, int sig, bool fast_sigblock)
int sys_sigwait(struct thread *td, struct sigwait_args *uap)
TUNABLE_STR("kern.corefile", corefilename, sizeof(corefilename))
int sys_sigaction(struct thread *td, struct sigaction_args *uap)
static int coredump_devctl
int sys_sigtimedwait(struct thread *td, struct sigtimedwait_args *uap)
void pgsigio(struct sigio **sigiop, int sig, int checkctty)
static int signal_overflow
void pgsignal(struct pgrp *pgrp, int sig, int checkctty, ksiginfo_t *ksi)
SDT_PROBE_DEFINE2(proc,,, signal__clear, "int", "ksiginfo_t *")
int sys_sigaltstack(struct thread *td, struct sigaltstack_args *uap)
void sigfastblock_fetch(struct thread *td)
void siginit(struct proc *p)
static int filt_sigattach(struct knote *kn)
void sigqueue_flush(sigqueue_t *sq)
static int sigqueue_add(sigqueue_t *sq, int signo, ksiginfo_t *si)
static int sigproptbl[NSIG]
void sigacts_copy(struct sigacts *dest, struct sigacts *src)
static uma_zone_t ksiginfo_zone
static void sigfastblock_failed(struct thread *td, bool sendsig, bool write)
void sigqueue_delete(sigqueue_t *sq, int signo)
void trapsignal(struct thread *td, ksiginfo_t *ksi)
static void sigfastblock_resched(struct thread *td, bool resched)
#define CANSIGIO(cr1, cr2)
static int killpg1(struct thread *td, int sig, int pgid, int all, ksiginfo_t *ksi)
static int set_core_nodump_flag
static int corefile_open(const char *comm, uid_t uid, pid_t pid, struct thread *td, int compress, int signum, struct vnode **vpp, char **namep)
void sigacts_free(struct sigacts *ps)
static int sugid_coredump
void sigqueue_init(sigqueue_t *list, struct proc *p)
void proc_wkilled(struct proc *p)
static enum sigstatus sigprocess(struct thread *td, int sig)
static int max_pending_per_proc
SYSINIT(signal, SI_SUB_P1003_1B, SI_ORDER_FIRST+3, sigqueue_start, NULL)
int sys_sigsuspend(struct thread *td, struct sigsuspend_args *uap)
static int sysctl_kern_corefile(SYSCTL_HANDLER_ARGS)
static void ptrace_coredump(struct thread *td)
void tdsignal(struct thread *td, int sig)
int sys_sigfastblock(struct thread *td, struct sigfastblock_args *uap)
static SYSCTL_NODE(_kern, OID_AUTO, sigqueue, CTLFLAG_RW|CTLFLAG_MPSAFE, 0, "POSIX real time signal")
static int preallocate_siginfo
static int sigqueue_get(sigqueue_t *sq, int signo, ksiginfo_t *si)
void sigqueue_delete_proc(struct proc *p, int signo)
int sys_sigwaitinfo(struct thread *td, struct sigwaitinfo_args *uap)
static int filt_signal(struct knote *kn, long hint)
bool curproc_sigkilled(void)
static void sigqueue_start(void)
static int capmode_coredump
static void postsig_done(int sig, struct thread *td, struct sigacts *ps)
int sys_sigpending(struct thread *td, struct sigpending_args *uap)
static int coredump(struct thread *)
struct sigacts * sigacts_hold(struct sigacts *ps)
static void sigfastblock_setpend1(struct thread *td)
static int sig_sleepq_abort(struct thread *td, int intrval)
static void sigqueue_delete_stopmask_proc(struct proc *p)
int sys_sigqueue(struct thread *td, struct sigqueue_args *uap)
static void killpg1_sendsig(struct proc *p, bool notself, struct killpg1_ctx *arg)
static void vnode_close_locked(struct thread *td, struct vnode *vp)
CTASSERT(NUM_CORE_FILES >=0 &&NUM_CORE_FILES<=MAX_NUM_CORE_FILES)
static void reschedule_signals(struct proc *p, sigset_t block, int flags)
void sigqueue_take(ksiginfo_t *ksi)
static int signal_alloc_fail
int kern_sigqueue(struct thread *td, pid_t pid, int signum, union sigval *value)
void childproc_exited(struct proc *p)
static char corefilename[MAXPATHLEN]
static void childproc_jobstate(struct proc *p, int reason, int sig)
int cursig(struct thread *td)
static void tdsigwakeup(struct thread *, int, sig_t, int)
int kern_sigaction(struct thread *td, int sig, const struct sigaction *act, struct sigaction *oact, int flags)
void kern_psignal(struct proc *p, int sig)
__read_frequently bool sigfastblock_fetch_always
int kern_sigaltstack(struct thread *td, stack_t *ss, stack_t *oss)
int sys_kill(struct thread *td, struct kill_args *uap)
void sigfastblock_setpend(struct thread *td, bool resched)
int kern_kill(struct thread *td, pid_t pid, int signum)
static bool sigact_flag_test(const struct sigaction *act, int flag)
int tdsendsignal(struct proc *p, struct thread *td, int sig, ksiginfo_t *ksi)
#define SIG_FOREACH(i, set)
int sys_pdkill(struct thread *td, struct pdkill_args *uap)
int sigev_findtd(struct proc *p, struct sigevent *sigev, struct thread **ttd)
SYSCTL_BOOL(_kern, OID_AUTO, sigfastblock_fetch_always, CTLFLAG_RWTUN, &sigfastblock_fetch_always, 0, "Fetch sigfastblock word on each syscall entry for proper " "blocking semantic")
static bool kern_sig_discard_ign
static void sigqueue_delete_set(sigqueue_t *sq, const sigset_t *set)
#define corefilename_lock
static int corefile_open_last(struct thread *td, char *name, int indexpos, int indexlen, int ncores, struct vnode **vpp)
static void filt_sigdetach(struct knote *kn)
void sig_drop_caught(struct proc *p)
void childproc_stopped(struct proc *p, int reason)
SDT_PROVIDER_DECLARE(proc)
ksiginfo_t * ksiginfo_alloc(int wait)
int kern_sigtimedwait(struct thread *td, sigset_t waitset, ksiginfo_t *ksi, struct timespec *timeout)
void thread_stopped(struct proc *p)
static __inline int ksiginfo_tryfree(ksiginfo_t *ksi)
int kern_sigprocmask(struct thread *td, int how, sigset_t *set, sigset_t *oset, int flags)
static void sigdflt(struct sigacts *ps, int sig)
static int sigprop(int sig)
int sig_ast_checksusp(struct thread *td)
int sigdeferstop_impl(int mode)
void ksiginfo_free(ksiginfo_t *ksi)
static int sysctl_compress_user_cores(SYSCTL_HANDLER_ARGS)
static void proc_td_siginfo_capture(struct thread *td, siginfo_t *si)
static int kern_logsigexit
void sigexit(struct thread *td, int sig)
void execsigs(struct proc *p)
static int sigdeferstop_curr_flags(int cflags)
int sigonstack(size_t sp)
static bool sigfastblock_fetch_sig(struct thread *td, bool sendsig, uint32_t *valp)
int ptracestop(struct thread *td, int sig, ksiginfo_t *si)
static int issignal(struct thread *td)
int sys_sigprocmask(struct thread *td, struct sigprocmask_args *uap)
static int sysctl_debug_num_cores_check(SYSCTL_HANDLER_ARGS)
void wakeup(const void *ident)
int sysctl_handle_int(SYSCTL_HANDLER_ARGS)
int sysctl_handle_string(SYSCTL_HANDLER_ARGS)
void getnanouptime(struct timespec *tsp)
int thread_check_susp(struct thread *td, bool sleep)
int thread_suspend_check(int return_instead)
struct thread * tdfind(lwpid_t tid, pid_t pid)
int thread_single(struct proc *p, int mode)
void thread_unsuspend(struct proc *p)
void thread_suspend_one(struct thread *td)
void thread_suspend_switch(struct thread *td, struct proc *p)
int itimer_accept(struct proc *p, int timerid, ksiginfo_t *ksi)
void itimer_proc_continue(struct proc *p)
struct intr_irqsrc ** src
void p31b_setcfg(int num, int value)
void sched_prio(struct thread *td, u_char prio)
void devctl_notify(const char *system, const char *subsystem, const char *type, const char *data)
Send a 'notification' to userland, using standard ways.
void devctl_safe_quote_sb(struct sbuf *sb, const char *src)
safely quotes strings that might have double quotes in them.
__read_mostly cap_rights_t cap_pdkill_rights
bool compressor_avail(int format)
int printf(const char *fmt,...)
int snprintf(char *str, size_t size, const char *format,...)
int uprintf(const char *fmt,...)
void log(int level, const char *fmt,...)
int sbuf_finish(struct sbuf *s)
int sbuf_putc(struct sbuf *s, int c)
void sbuf_delete(struct sbuf *s)
int sbuf_printf(struct sbuf *s, const char *fmt,...)
ssize_t sbuf_len(struct sbuf *s)
char * sbuf_data(struct sbuf *s)
int sbuf_error(const struct sbuf *s)
struct sbuf * sbuf_new(struct sbuf *s, char *buf, int length, int flags)
int sleepq_abort(struct thread *td, int intrval)
int procdesc_find(struct thread *td, int fd, cap_rights_t *rightsp, struct proc **p)
int vn_fullpath_global(struct vnode *vp, char **retbuf, char **freebuf)
int vn_getcwd(char *buf, char **retbuf, size_t *buflen)
void() NDFREE(struct nameidata *ndp, const u_int flags)
int vn_open_cred(struct nameidata *ndp, int *flagp, int cmode, u_int vn_open_flags, struct ucred *cred, struct file *fp)
int vn_close(struct vnode *vp, int flags, struct ucred *file_cred, struct thread *td)