Lines Matching +full:sig +full:- +full:dir +full:- +full:cmd
1 /*-
2 * SPDX-License-Identifier: BSD-3-Clause
105 static int killpg1(struct thread *td, int sig, int pgid, int all,
109 static int sigprop(int sig);
115 static struct thread *sigtd(struct proc *p, int sig, bool fast_sigblock);
119 int sig);
185 * Policy -- Can ucred cr1 send SIGIO to process cr2?
190 ((cr1)->cr_uid == 0 || \
191 (cr1)->cr_ruid == (cr2)->cr_ruid || \
192 (cr1)->cr_uid == (cr2)->cr_ruid || \
193 (cr1)->cr_ruid == (cr2)->cr_uid || \
194 (cr1)->cr_uid == (cr2)->cr_uid)
267 __bits &= ~(1u << (__sig - 1)); \
268 sig = __i * sizeof((set)->__bits[0]) * NBBY + __sig; \
276 __bits = (set)->__bits[__i]; \
282 for (int32_t __i = -1, __bits = 0; \
291 int old_boundary, sig; in ast_sig() local
294 p = td->td_proc; in ast_sig()
297 if (p->p_numthreads == 1 && (tda & (TDAI(TDA_SIG) | in ast_sig()
302 * Note that TDA_SIG should be re-read from in ast_sig()
308 if ((p->p_flag & P_PPWAIT) == 0 && in ast_sig()
309 (td->td_pflags & TDP_SIGFASTBLOCK) == 0) { in ast_sig()
310 if (SIGPENDING(td) && ((tda | td->td_ast) & in ast_sig()
316 p, td, tda, td->td_ast, td->td_flags); in ast_sig()
326 * p_siglist might cause process-directed signal to be handled in ast_sig()
329 if ((tda & TDAI(TDA_SIG)) != 0 || p->p_pendingcnt > 0 || in ast_sig()
330 !SIGISEMPTY(p->p_siglist)) { in ast_sig()
333 old_boundary = ~TDB_BOUNDARY | (td->td_dbgflags & TDB_BOUNDARY); in ast_sig()
334 td->td_dbgflags |= TDB_BOUNDARY; in ast_sig()
335 mtx_lock(&p->p_sigacts->ps_mtx); in ast_sig()
336 while ((sig = cursig(td)) != 0) { in ast_sig()
337 KASSERT(sig >= 0, ("sig %d", sig)); in ast_sig()
338 postsig(sig); in ast_sig()
340 mtx_unlock(&p->p_sigacts->ps_mtx); in ast_sig()
341 td->td_dbgflags &= old_boundary; in ast_sig()
360 td->td_sa.code = 0; in ast_sig()
366 MPASS((td->td_pflags & TDP_OLDMASK) != 0); in ast_sigsuspend()
367 td->td_pflags &= ~TDP_OLDMASK; in ast_sigsuspend()
368 kern_sigprocmask(td, SIG_SETMASK, &td->td_oldsigmask, NULL, 0); in ast_sigsuspend()
378 p31b_setcfg(CTL_P1003_1B_RTSIG_MAX, SIGRTMAX - SIGRTMIN + 1); in sigqueue_start()
416 if ((ksi->ksi_flags & KSI_EXT) == 0) { in ksiginfo_tryfree()
426 SIGEMPTYSET(list->sq_signals); in sigqueue_init()
427 SIGEMPTYSET(list->sq_kill); in sigqueue_init()
428 SIGEMPTYSET(list->sq_ptrace); in sigqueue_init()
429 TAILQ_INIT(&list->sq_list); in sigqueue_init()
430 list->sq_proc = p; in sigqueue_init()
431 list->sq_flags = SQ_INIT; in sigqueue_init()
437 * 0 - signal not found
438 * others - signal number
443 struct proc *p = sq->sq_proc; in sigqueue_get()
447 KASSERT(sq->sq_flags & SQ_INIT, ("sigqueue not inited")); in sigqueue_get()
449 if (!SIGISMEMBER(sq->sq_signals, signo)) in sigqueue_get()
452 if (SIGISMEMBER(sq->sq_ptrace, signo)) { in sigqueue_get()
454 SIGDELSET(sq->sq_ptrace, signo); in sigqueue_get()
455 si->ksi_flags |= KSI_PTRACE; in sigqueue_get()
457 if (SIGISMEMBER(sq->sq_kill, signo)) { in sigqueue_get()
460 SIGDELSET(sq->sq_kill, signo); in sigqueue_get()
463 TAILQ_FOREACH_SAFE(ksi, &sq->sq_list, ksi_link, next) { in sigqueue_get()
464 if (ksi->ksi_signo == signo) { in sigqueue_get()
466 TAILQ_REMOVE(&sq->sq_list, ksi, ksi_link); in sigqueue_get()
467 ksi->ksi_sigq = NULL; in sigqueue_get()
470 p->p_pendingcnt--; in sigqueue_get()
478 SIGDELSET(sq->sq_signals, signo); in sigqueue_get()
479 si->ksi_signo = signo; in sigqueue_get()
490 if (ksi == NULL || (sq = ksi->ksi_sigq) == NULL) in sigqueue_take()
493 p = sq->sq_proc; in sigqueue_take()
494 TAILQ_REMOVE(&sq->sq_list, ksi, ksi_link); in sigqueue_take()
495 ksi->ksi_sigq = NULL; in sigqueue_take()
496 if (!(ksi->ksi_flags & KSI_EXT) && p != NULL) in sigqueue_take()
497 p->p_pendingcnt--; in sigqueue_take()
499 for (kp = TAILQ_FIRST(&sq->sq_list); kp != NULL; in sigqueue_take()
501 if (kp->ksi_signo == ksi->ksi_signo) in sigqueue_take()
504 if (kp == NULL && !SIGISMEMBER(sq->sq_kill, ksi->ksi_signo) && in sigqueue_take()
505 !SIGISMEMBER(sq->sq_ptrace, ksi->ksi_signo)) in sigqueue_take()
506 SIGDELSET(sq->sq_signals, ksi->ksi_signo); in sigqueue_take()
512 struct proc *p = sq->sq_proc; in sigqueue_add()
516 KASSERT(sq->sq_flags & SQ_INIT, ("sigqueue not inited")); in sigqueue_add()
523 SIGADDSET(sq->sq_kill, signo); in sigqueue_add()
528 if (si->ksi_flags & KSI_INS) { in sigqueue_add()
529 if (si->ksi_flags & KSI_HEAD) in sigqueue_add()
530 TAILQ_INSERT_HEAD(&sq->sq_list, si, ksi_link); in sigqueue_add()
532 TAILQ_INSERT_TAIL(&sq->sq_list, si, ksi_link); in sigqueue_add()
533 si->ksi_sigq = sq; in sigqueue_add()
538 SIGADDSET(sq->sq_kill, signo); in sigqueue_add()
542 if (p != NULL && p->p_pendingcnt >= max_pending_per_proc) { in sigqueue_add()
550 p->p_pendingcnt++; in sigqueue_add()
552 ksi->ksi_signo = signo; in sigqueue_add()
553 if (si->ksi_flags & KSI_HEAD) in sigqueue_add()
554 TAILQ_INSERT_HEAD(&sq->sq_list, ksi, ksi_link); in sigqueue_add()
556 TAILQ_INSERT_TAIL(&sq->sq_list, ksi, ksi_link); in sigqueue_add()
557 ksi->ksi_sigq = sq; in sigqueue_add()
561 if ((si->ksi_flags & KSI_PTRACE) != 0) { in sigqueue_add()
562 SIGADDSET(sq->sq_ptrace, signo); in sigqueue_add()
565 } else if ((si->ksi_flags & KSI_TRAP) != 0 || in sigqueue_add()
566 (si->ksi_flags & KSI_SIGQ) == 0) { in sigqueue_add()
567 SIGADDSET(sq->sq_kill, signo); in sigqueue_add()
575 SIGADDSET(sq->sq_signals, signo); in sigqueue_add()
582 struct proc *p = sq->sq_proc; in sigqueue_flush()
585 KASSERT(sq->sq_flags & SQ_INIT, ("sigqueue not inited")); in sigqueue_flush()
590 while ((ksi = TAILQ_FIRST(&sq->sq_list)) != NULL) { in sigqueue_flush()
591 TAILQ_REMOVE(&sq->sq_list, ksi, ksi_link); in sigqueue_flush()
592 ksi->ksi_sigq = NULL; in sigqueue_flush()
594 p->p_pendingcnt--; in sigqueue_flush()
597 SIGEMPTYSET(sq->sq_signals); in sigqueue_flush()
598 SIGEMPTYSET(sq->sq_kill); in sigqueue_flush()
599 SIGEMPTYSET(sq->sq_ptrace); in sigqueue_flush()
609 KASSERT(src->sq_flags & SQ_INIT, ("src sigqueue not inited")); in sigqueue_move_set()
610 KASSERT(dst->sq_flags & SQ_INIT, ("dst sigqueue not inited")); in sigqueue_move_set()
611 p1 = src->sq_proc; in sigqueue_move_set()
612 p2 = dst->sq_proc; in sigqueue_move_set()
614 TAILQ_FOREACH_SAFE(ksi, &src->sq_list, ksi_link, next) { in sigqueue_move_set()
615 if (SIGISMEMBER(*set, ksi->ksi_signo)) { in sigqueue_move_set()
616 TAILQ_REMOVE(&src->sq_list, ksi, ksi_link); in sigqueue_move_set()
618 p1->p_pendingcnt--; in sigqueue_move_set()
619 TAILQ_INSERT_TAIL(&dst->sq_list, ksi, ksi_link); in sigqueue_move_set()
620 ksi->ksi_sigq = dst; in sigqueue_move_set()
622 p2->p_pendingcnt++; in sigqueue_move_set()
627 tmp = src->sq_kill; in sigqueue_move_set()
629 SIGSETOR(dst->sq_kill, tmp); in sigqueue_move_set()
630 SIGSETNAND(src->sq_kill, tmp); in sigqueue_move_set()
632 tmp = src->sq_ptrace; in sigqueue_move_set()
634 SIGSETOR(dst->sq_ptrace, tmp); in sigqueue_move_set()
635 SIGSETNAND(src->sq_ptrace, tmp); in sigqueue_move_set()
637 tmp = src->sq_signals; in sigqueue_move_set()
639 SIGSETOR(dst->sq_signals, tmp); in sigqueue_move_set()
640 SIGSETNAND(src->sq_signals, tmp); in sigqueue_move_set()
658 struct proc *p = sq->sq_proc; in sigqueue_delete_set()
661 KASSERT(sq->sq_flags & SQ_INIT, ("src sigqueue not inited")); in sigqueue_delete_set()
664 TAILQ_FOREACH_SAFE(ksi, &sq->sq_list, ksi_link, next) { in sigqueue_delete_set()
665 if (SIGISMEMBER(*set, ksi->ksi_signo)) { in sigqueue_delete_set()
666 TAILQ_REMOVE(&sq->sq_list, ksi, ksi_link); in sigqueue_delete_set()
667 ksi->ksi_sigq = NULL; in sigqueue_delete_set()
669 p->p_pendingcnt--; in sigqueue_delete_set()
672 SIGSETNAND(sq->sq_kill, *set); in sigqueue_delete_set()
673 SIGSETNAND(sq->sq_ptrace, *set); in sigqueue_delete_set()
674 SIGSETNAND(sq->sq_signals, *set); in sigqueue_delete_set()
697 sigqueue_move_set(&p->p_sigqueue, &worklist, set); in sigqueue_delete_set_proc()
700 sigqueue_move_set(&td0->td_sigqueue, &worklist, set); in sigqueue_delete_set_proc()
736 PROC_LOCK_ASSERT(td->td_proc, MA_OWNED); in cursig()
737 mtx_assert(&td->td_proc->p_sigacts->ps_mtx, MA_OWNED); in cursig()
751 PROC_LOCK_ASSERT(td->td_proc, MA_OWNED); in signotify()
768 if ((td->td_pflags & TDP_ALTSTACK) == 0) in sigonstack()
771 if (SV_PROC_FLAG(td->td_proc, SV_AOUT) && td->td_sigstk.ss_size == 0) in sigonstack()
772 return ((td->td_sigstk.ss_flags & SS_ONSTACK) != 0); in sigonstack()
774 return (sp >= (size_t)td->td_sigstk.ss_sp && in sigonstack()
775 sp < td->td_sigstk.ss_size + (size_t)td->td_sigstk.ss_sp); in sigonstack()
779 sigprop(int sig) in sigprop() argument
782 if (sig > 0 && sig < nitems(sigproptbl)) in sigprop()
783 return (sigproptbl[sig]); in sigprop()
796 return ((act->sa_flags & flag) != 0 && (flag != SA_SIGINFO || in sigact_flag_test()
797 ((__sighandler_t *)act->sa_sigaction != SIG_IGN && in sigact_flag_test()
798 (__sighandler_t *)act->sa_sigaction != SIG_DFL))); in sigact_flag_test()
808 kern_sigaction(struct thread *td, int sig, const struct sigaction *act, in kern_sigaction() argument
812 struct proc *p = td->td_proc; in kern_sigaction()
814 if (!_SIG_VALID(sig)) in kern_sigaction()
816 if (act != NULL && act->sa_handler != SIG_DFL && in kern_sigaction()
817 act->sa_handler != SIG_IGN && (act->sa_flags & ~(SA_ONSTACK | in kern_sigaction()
823 ps = p->p_sigacts; in kern_sigaction()
824 mtx_lock(&ps->ps_mtx); in kern_sigaction()
827 oact->sa_mask = ps->ps_catchmask[_SIG_IDX(sig)]; in kern_sigaction()
828 if (SIGISMEMBER(ps->ps_sigonstack, sig)) in kern_sigaction()
829 oact->sa_flags |= SA_ONSTACK; in kern_sigaction()
830 if (!SIGISMEMBER(ps->ps_sigintr, sig)) in kern_sigaction()
831 oact->sa_flags |= SA_RESTART; in kern_sigaction()
832 if (SIGISMEMBER(ps->ps_sigreset, sig)) in kern_sigaction()
833 oact->sa_flags |= SA_RESETHAND; in kern_sigaction()
834 if (SIGISMEMBER(ps->ps_signodefer, sig)) in kern_sigaction()
835 oact->sa_flags |= SA_NODEFER; in kern_sigaction()
836 if (SIGISMEMBER(ps->ps_siginfo, sig)) { in kern_sigaction()
837 oact->sa_flags |= SA_SIGINFO; in kern_sigaction()
838 oact->sa_sigaction = in kern_sigaction()
839 (__siginfohandler_t *)ps->ps_sigact[_SIG_IDX(sig)]; in kern_sigaction()
841 oact->sa_handler = ps->ps_sigact[_SIG_IDX(sig)]; in kern_sigaction()
842 if (sig == SIGCHLD && ps->ps_flag & PS_NOCLDSTOP) in kern_sigaction()
843 oact->sa_flags |= SA_NOCLDSTOP; in kern_sigaction()
844 if (sig == SIGCHLD && ps->ps_flag & PS_NOCLDWAIT) in kern_sigaction()
845 oact->sa_flags |= SA_NOCLDWAIT; in kern_sigaction()
848 if ((sig == SIGKILL || sig == SIGSTOP) && in kern_sigaction()
849 act->sa_handler != SIG_DFL) { in kern_sigaction()
850 mtx_unlock(&ps->ps_mtx); in kern_sigaction()
859 ps->ps_catchmask[_SIG_IDX(sig)] = act->sa_mask; in kern_sigaction()
860 SIG_CANTMASK(ps->ps_catchmask[_SIG_IDX(sig)]); in kern_sigaction()
862 ps->ps_sigact[_SIG_IDX(sig)] = in kern_sigaction()
863 (__sighandler_t *)act->sa_sigaction; in kern_sigaction()
864 SIGADDSET(ps->ps_siginfo, sig); in kern_sigaction()
866 ps->ps_sigact[_SIG_IDX(sig)] = act->sa_handler; in kern_sigaction()
867 SIGDELSET(ps->ps_siginfo, sig); in kern_sigaction()
870 SIGADDSET(ps->ps_sigintr, sig); in kern_sigaction()
872 SIGDELSET(ps->ps_sigintr, sig); in kern_sigaction()
874 SIGADDSET(ps->ps_sigonstack, sig); in kern_sigaction()
876 SIGDELSET(ps->ps_sigonstack, sig); in kern_sigaction()
878 SIGADDSET(ps->ps_sigreset, sig); in kern_sigaction()
880 SIGDELSET(ps->ps_sigreset, sig); in kern_sigaction()
882 SIGADDSET(ps->ps_signodefer, sig); in kern_sigaction()
884 SIGDELSET(ps->ps_signodefer, sig); in kern_sigaction()
885 if (sig == SIGCHLD) { in kern_sigaction()
886 if (act->sa_flags & SA_NOCLDSTOP) in kern_sigaction()
887 ps->ps_flag |= PS_NOCLDSTOP; in kern_sigaction()
889 ps->ps_flag &= ~PS_NOCLDSTOP; in kern_sigaction()
890 if (act->sa_flags & SA_NOCLDWAIT) { in kern_sigaction()
897 if (p->p_pid == 1) in kern_sigaction()
898 ps->ps_flag &= ~PS_NOCLDWAIT; in kern_sigaction()
900 ps->ps_flag |= PS_NOCLDWAIT; in kern_sigaction()
902 ps->ps_flag &= ~PS_NOCLDWAIT; in kern_sigaction()
903 if (ps->ps_sigact[_SIG_IDX(SIGCHLD)] == SIG_IGN) in kern_sigaction()
904 ps->ps_flag |= PS_CLDSIGIGN; in kern_sigaction()
906 ps->ps_flag &= ~PS_CLDSIGIGN; in kern_sigaction()
914 if (ps->ps_sigact[_SIG_IDX(sig)] == SIG_IGN || in kern_sigaction()
915 (sigprop(sig) & SIGPROP_IGNORE && in kern_sigaction()
916 ps->ps_sigact[_SIG_IDX(sig)] == SIG_DFL)) { in kern_sigaction()
918 sigqueue_delete_proc(p, sig); in kern_sigaction()
919 if (sig != SIGCONT) in kern_sigaction()
921 SIGADDSET(ps->ps_sigignore, sig); in kern_sigaction()
922 SIGDELSET(ps->ps_sigcatch, sig); in kern_sigaction()
924 SIGDELSET(ps->ps_sigignore, sig); in kern_sigaction()
925 if (ps->ps_sigact[_SIG_IDX(sig)] == SIG_DFL) in kern_sigaction()
926 SIGDELSET(ps->ps_sigcatch, sig); in kern_sigaction()
928 SIGADDSET(ps->ps_sigcatch, sig); in kern_sigaction()
931 if (ps->ps_sigact[_SIG_IDX(sig)] == SIG_IGN || in kern_sigaction()
932 ps->ps_sigact[_SIG_IDX(sig)] == SIG_DFL || in kern_sigaction()
934 SIGDELSET(ps->ps_freebsd4, sig); in kern_sigaction()
936 SIGADDSET(ps->ps_freebsd4, sig); in kern_sigaction()
939 if (ps->ps_sigact[_SIG_IDX(sig)] == SIG_IGN || in kern_sigaction()
940 ps->ps_sigact[_SIG_IDX(sig)] == SIG_DFL || in kern_sigaction()
942 SIGDELSET(ps->ps_osigset, sig); in kern_sigaction()
944 SIGADDSET(ps->ps_osigset, sig); in kern_sigaction()
947 mtx_unlock(&ps->ps_mtx); in kern_sigaction()
954 int sig; member
966 actp = (uap->act != NULL) ? &act : NULL; in sys_sigaction()
967 oactp = (uap->oact != NULL) ? &oact : NULL; in sys_sigaction()
969 error = copyin(uap->act, actp, sizeof(act)); in sys_sigaction()
973 error = kern_sigaction(td, uap->sig, actp, oactp, 0); in sys_sigaction()
975 error = copyout(oactp, uap->oact, sizeof(oact)); in sys_sigaction()
982 int sig; member
994 actp = (uap->act != NULL) ? &act : NULL; in freebsd4_sigaction()
995 oactp = (uap->oact != NULL) ? &oact : NULL; in freebsd4_sigaction()
997 error = copyin(uap->act, actp, sizeof(act)); in freebsd4_sigaction()
1001 error = kern_sigaction(td, uap->sig, actp, oactp, KSA_FREEBSD4); in freebsd4_sigaction()
1003 error = copyout(oactp, uap->oact, sizeof(oact)); in freebsd4_sigaction()
1008 #ifdef COMPAT_43 /* XXX - COMPAT_FBSD3 */
1024 if (uap->signum <= 0 || uap->signum >= ONSIG) in osigaction()
1027 nsap = (uap->nsa != NULL) ? &nsa : NULL; in osigaction()
1028 osap = (uap->osa != NULL) ? &osa : NULL; in osigaction()
1031 error = copyin(uap->nsa, &sa, sizeof(sa)); in osigaction()
1034 nsap->sa_handler = sa.sa_handler; in osigaction()
1035 nsap->sa_flags = sa.sa_flags; in osigaction()
1036 OSIG2SIG(sa.sa_mask, nsap->sa_mask); in osigaction()
1038 error = kern_sigaction(td, uap->signum, nsap, osap, KSA_OSIGSET); in osigaction()
1040 sa.sa_handler = osap->sa_handler; in osigaction()
1041 sa.sa_flags = osap->sa_flags; in osigaction()
1042 SIG2OSIG(osap->sa_mask, sa.sa_mask); in osigaction()
1043 error = copyout(&sa, uap->osa, sizeof(sa)); in osigaction()
1069 ps = p->p_sigacts; in siginit()
1070 mtx_lock(&ps->ps_mtx); in siginit()
1073 SIGADDSET(ps->ps_sigignore, i); in siginit()
1076 mtx_unlock(&ps->ps_mtx); in siginit()
1084 sigdflt(struct sigacts *ps, int sig) in sigdflt() argument
1087 mtx_assert(&ps->ps_mtx, MA_OWNED); in sigdflt()
1088 SIGDELSET(ps->ps_sigcatch, sig); in sigdflt()
1089 if ((sigprop(sig) & SIGPROP_IGNORE) != 0 && sig != SIGCONT) in sigdflt()
1090 SIGADDSET(ps->ps_sigignore, sig); in sigdflt()
1091 ps->ps_sigact[_SIG_IDX(sig)] = SIG_DFL; in sigdflt()
1092 SIGDELSET(ps->ps_siginfo, sig); in sigdflt()
1110 ps = p->p_sigacts; in execsigs()
1111 mtx_lock(&ps->ps_mtx); in execsigs()
1119 MPASS(td->td_proc == p); in execsigs()
1120 td->td_sigstk.ss_flags = SS_DISABLE; in execsigs()
1121 td->td_sigstk.ss_size = 0; in execsigs()
1122 td->td_sigstk.ss_sp = 0; in execsigs()
1123 td->td_pflags &= ~TDP_ALTSTACK; in execsigs()
1127 ps->ps_flag &= ~(PS_NOCLDWAIT | PS_CLDSIGIGN); in execsigs()
1128 if (ps->ps_sigact[_SIG_IDX(SIGCHLD)] == SIG_IGN) in execsigs()
1129 ps->ps_sigact[_SIG_IDX(SIGCHLD)] = SIG_DFL; in execsigs()
1130 mtx_unlock(&ps->ps_mtx); in execsigs()
1146 p = td->td_proc; in kern_sigprocmask()
1151 mtx_assert(&p->p_sigacts->ps_mtx, (flags & SIGPROCMASK_PS_LOCKED) != 0 in kern_sigprocmask()
1154 *oset = td->td_sigmask; in kern_sigprocmask()
1161 oset1 = td->td_sigmask; in kern_sigprocmask()
1162 SIGSETOR(td->td_sigmask, *set); in kern_sigprocmask()
1163 new_block = td->td_sigmask; in kern_sigprocmask()
1167 SIGSETNAND(td->td_sigmask, *set); in kern_sigprocmask()
1172 oset1 = td->td_sigmask; in kern_sigprocmask()
1174 SIGSETLO(td->td_sigmask, *set); in kern_sigprocmask()
1176 td->td_sigmask = *set; in kern_sigprocmask()
1177 new_block = td->td_sigmask; in kern_sigprocmask()
1195 if (p->p_numthreads != 1) in kern_sigprocmask()
1219 setp = (uap->set != NULL) ? &set : NULL; in sys_sigprocmask()
1220 osetp = (uap->oset != NULL) ? &oset : NULL; in sys_sigprocmask()
1222 error = copyin(uap->set, setp, sizeof(set)); in sys_sigprocmask()
1226 error = kern_sigprocmask(td, uap->how, setp, osetp, 0); in sys_sigprocmask()
1228 error = copyout(osetp, uap->oset, sizeof(oset)); in sys_sigprocmask()
1233 #ifdef COMPAT_43 /* XXX - COMPAT_FBSD3 */
1246 OSIG2SIG(uap->mask, set); in osigprocmask()
1247 error = kern_sigprocmask(td, uap->how, &set, &oset, 1); in osigprocmask()
1248 SIG2OSIG(oset, td->td_retval[0]); in osigprocmask()
1260 error = copyin(uap->set, &set, sizeof(set)); in sys_sigwait()
1262 td->td_retval[0] = error; in sys_sigwait()
1270 * the syscall does. Non-ancient libc provides the in sys_sigwait()
1275 if (error == EINTR && td->td_proc->p_osrel < P_OSREL_SIGWAIT) in sys_sigwait()
1277 td->td_retval[0] = error; in sys_sigwait()
1281 error = copyout(&ksi.ksi_signo, uap->sig, sizeof(ksi.ksi_signo)); in sys_sigwait()
1282 td->td_retval[0] = error; in sys_sigwait()
1295 if (uap->timeout) { in sys_sigtimedwait()
1296 error = copyin(uap->timeout, &ts, sizeof(ts)); in sys_sigtimedwait()
1304 error = copyin(uap->set, &set, sizeof(set)); in sys_sigtimedwait()
1312 if (uap->info) in sys_sigtimedwait()
1313 error = copyout(&ksi.ksi_info, uap->info, sizeof(siginfo_t)); in sys_sigtimedwait()
1316 td->td_retval[0] = ksi.ksi_signo; in sys_sigtimedwait()
1327 error = copyin(uap->set, &set, sizeof(set)); in sys_sigwaitinfo()
1335 if (uap->info) in sys_sigwaitinfo()
1336 error = copyout(&ksi.ksi_info, uap->info, sizeof(siginfo_t)); in sys_sigwaitinfo()
1339 td->td_retval[0] = ksi.ksi_signo; in sys_sigwaitinfo()
1348 FOREACH_THREAD_IN_PROC(td->td_proc, thr) { in proc_td_siginfo_capture()
1350 thr->td_si = *si; in proc_td_siginfo_capture()
1352 thr->td_si.si_signo = 0; in proc_td_siginfo_capture()
1363 int error, sig, timevalid = 0; in kern_sigtimedwait() local
1368 p = td->td_proc; in kern_sigtimedwait()
1376 if (timeout->tv_nsec >= 0 && timeout->tv_nsec < 1000000000) { in kern_sigtimedwait()
1394 ps = p->p_sigacts; in kern_sigtimedwait()
1396 saved_mask = td->td_sigmask; in kern_sigtimedwait()
1397 SIGSETNAND(td->td_sigmask, waitset); in kern_sigtimedwait()
1398 if ((p->p_sysent->sv_flags & SV_SIG_DISCIGN) != 0 || in kern_sigtimedwait()
1401 td->td_flags |= TDF_SIGWAIT; in kern_sigtimedwait()
1405 mtx_lock(&ps->ps_mtx); in kern_sigtimedwait()
1406 sig = cursig(td); in kern_sigtimedwait()
1407 mtx_unlock(&ps->ps_mtx); in kern_sigtimedwait()
1408 KASSERT(sig >= 0, ("sig %d", sig)); in kern_sigtimedwait()
1409 if (sig != 0 && SIGISMEMBER(waitset, sig)) { in kern_sigtimedwait()
1410 if (sigqueue_get(&td->td_sigqueue, sig, ksi) != 0 || in kern_sigtimedwait()
1411 sigqueue_get(&p->p_sigqueue, sig, ksi) != 0) { in kern_sigtimedwait()
1434 error = msleep_sbt(&p->p_sigacts, &p->p_mtx, PPAUSE | PCATCH, in kern_sigtimedwait()
1448 if (error == 0 && (p->p_ptevents & PTRACE_SYSCALL) != 0) in kern_sigtimedwait()
1452 td->td_flags &= ~TDF_SIGWAIT; in kern_sigtimedwait()
1456 SIGSETNAND(new_block, td->td_sigmask); in kern_sigtimedwait()
1457 td->td_sigmask = saved_mask; in kern_sigtimedwait()
1462 if (p->p_numthreads != 1) in kern_sigtimedwait()
1466 SDT_PROBE2(proc, , , signal__clear, sig, ksi); in kern_sigtimedwait()
1468 if (ksi->ksi_code == SI_TIMER) in kern_sigtimedwait()
1469 itimer_accept(p, ksi->ksi_timerid, ksi); in kern_sigtimedwait()
1475 mtx_lock(&ps->ps_mtx); in kern_sigtimedwait()
1476 action = ps->ps_sigact[_SIG_IDX(sig)]; in kern_sigtimedwait()
1477 mtx_unlock(&ps->ps_mtx); in kern_sigtimedwait()
1478 ktrpsig(sig, action, &td->td_sigmask, ksi->ksi_code); in kern_sigtimedwait()
1481 if (sig == SIGKILL) { in kern_sigtimedwait()
1482 proc_td_siginfo_capture(td, &ksi->ksi_info); in kern_sigtimedwait()
1483 sigexit(td, sig); in kern_sigtimedwait()
1498 struct proc *p = td->td_proc; in sys_sigpending()
1502 pending = p->p_sigqueue.sq_signals; in sys_sigpending()
1503 SIGSETOR(pending, td->td_sigqueue.sq_signals); in sys_sigpending()
1505 return (copyout(&pending, uap->set, sizeof(sigset_t))); in sys_sigpending()
1508 #ifdef COMPAT_43 /* XXX - COMPAT_FBSD3 */
1517 struct proc *p = td->td_proc; in osigpending()
1521 pending = p->p_sigqueue.sq_signals; in osigpending()
1522 SIGSETOR(pending, td->td_sigqueue.sq_signals); in osigpending()
1524 SIG2OSIG(pending, td->td_retval[0]); in osigpending()
1531 * Generalized interface signal handler, 4.3-compatible.
1549 if (uap->signum <= 0 || uap->signum >= ONSIG) in osigvec()
1551 nsap = (uap->nsv != NULL) ? &nsa : NULL; in osigvec()
1552 osap = (uap->osv != NULL) ? &osa : NULL; in osigvec()
1554 error = copyin(uap->nsv, &vec, sizeof(vec)); in osigvec()
1557 nsap->sa_handler = vec.sv_handler; in osigvec()
1558 OSIG2SIG(vec.sv_mask, nsap->sa_mask); in osigvec()
1559 nsap->sa_flags = vec.sv_flags; in osigvec()
1560 nsap->sa_flags ^= SA_RESTART; /* opposite of SV_INTERRUPT */ in osigvec()
1562 error = kern_sigaction(td, uap->signum, nsap, osap, KSA_OSIGSET); in osigvec()
1564 vec.sv_handler = osap->sa_handler; in osigvec()
1565 SIG2OSIG(osap->sa_mask, vec.sv_mask); in osigvec()
1566 vec.sv_flags = osap->sa_flags; in osigvec()
1569 error = copyout(&vec, uap->osv, sizeof(vec)); in osigvec()
1584 OSIG2SIG(uap->mask, set); in osigblock()
1586 SIG2OSIG(oset, td->td_retval[0]); in osigblock()
1600 OSIG2SIG(uap->mask, set); in osigsetmask()
1602 SIG2OSIG(oset, td->td_retval[0]); in osigsetmask()
1623 error = copyin(uap->sigmask, &mask, sizeof(mask)); in sys_sigsuspend()
1632 struct proc *p = td->td_proc; in kern_sigsuspend()
1633 int has_sig, sig; in kern_sigsuspend() local
1646 kern_sigprocmask(td, SIG_SETMASK, &mask, &td->td_oldsigmask, in kern_sigsuspend()
1648 td->td_pflags |= TDP_OLDMASK; in kern_sigsuspend()
1657 (p->p_sysent->sv_set_syscall_retval)(td, EINTR); in kern_sigsuspend()
1659 while (msleep(&p->p_sigacts, &p->p_mtx, PPAUSE | PCATCH, in kern_sigsuspend()
1663 mtx_lock(&p->p_sigacts->ps_mtx); in kern_sigsuspend()
1664 while ((sig = cursig(td)) != 0) { in kern_sigsuspend()
1665 KASSERT(sig >= 0, ("sig %d", sig)); in kern_sigsuspend()
1666 has_sig += postsig(sig); in kern_sigsuspend()
1668 mtx_unlock(&p->p_sigacts->ps_mtx); in kern_sigsuspend()
1675 if ((p->p_ptevents & PTRACE_SYSCALL) != 0) in kern_sigsuspend()
1679 td->td_errno = EINTR; in kern_sigsuspend()
1680 td->td_pflags |= TDP_NERRNO; in kern_sigsuspend()
1684 #ifdef COMPAT_43 /* XXX - COMPAT_FBSD3 */
1700 OSIG2SIG(uap->mask, mask); in osigsuspend()
1719 if (uap->nss != NULL) { in osigstack()
1720 error = copyin(uap->nss, &nss, sizeof(nss)); in osigstack()
1724 oss.ss_sp = td->td_sigstk.ss_sp; in osigstack()
1726 if (uap->nss != NULL) { in osigstack()
1727 td->td_sigstk.ss_sp = nss.ss_sp; in osigstack()
1728 td->td_sigstk.ss_size = 0; in osigstack()
1729 td->td_sigstk.ss_flags |= nss.ss_onstack & SS_ONSTACK; in osigstack()
1730 td->td_pflags |= TDP_ALTSTACK; in osigstack()
1732 if (uap->oss != NULL) in osigstack()
1733 error = copyout(&oss, uap->oss, sizeof(oss)); in osigstack()
1752 if (uap->ss != NULL) { in sys_sigaltstack()
1753 error = copyin(uap->ss, &ss, sizeof(ss)); in sys_sigaltstack()
1757 error = kern_sigaltstack(td, (uap->ss != NULL) ? &ss : NULL, in sys_sigaltstack()
1758 (uap->oss != NULL) ? &oss : NULL); in sys_sigaltstack()
1761 if (uap->oss != NULL) in sys_sigaltstack()
1762 error = copyout(&oss, uap->oss, sizeof(stack_t)); in sys_sigaltstack()
1769 struct proc *p = td->td_proc; in kern_sigaltstack()
1775 *oss = td->td_sigstk; in kern_sigaltstack()
1776 oss->ss_flags = (td->td_pflags & TDP_ALTSTACK) in kern_sigaltstack()
1783 if ((ss->ss_flags & ~SS_DISABLE) != 0) in kern_sigaltstack()
1785 if (!(ss->ss_flags & SS_DISABLE)) { in kern_sigaltstack()
1786 if (ss->ss_size < p->p_sysent->sv_minsigstksz) in kern_sigaltstack()
1789 td->td_sigstk = *ss; in kern_sigaltstack()
1790 td->td_pflags |= TDP_ALTSTACK; in kern_sigaltstack()
1792 td->td_pflags &= ~TDP_ALTSTACK; in kern_sigaltstack()
1801 int sig; member
1812 err = p_cansignal(arg->td, p, arg->sig); in killpg1_sendsig_locked()
1813 if (err == 0 && arg->sig != 0) in killpg1_sendsig_locked()
1814 pksignal(p, arg->sig, arg->ksi); in killpg1_sendsig_locked()
1816 arg->found = true; in killpg1_sendsig_locked()
1818 arg->sent = true; in killpg1_sendsig_locked()
1819 else if (arg->ret == 0 && err != ESRCH && err != EPERM) in killpg1_sendsig_locked()
1820 arg->ret = err; in killpg1_sendsig_locked()
1827 if (p->p_pid <= 1 || (p->p_flag & P_SYSTEM) != 0 || in killpg1_sendsig()
1828 (notself && p == arg->td->td_proc) || p->p_state == PRS_NEW) in killpg1_sendsig()
1841 if (p->p_pid <= 1 || (p->p_flag & P_SYSTEM) != 0 || in kill_processes_prison_cb()
1842 (p == ctx->td->td_proc) || p->p_state == PRS_NEW) in kill_processes_prison_cb()
1853 killpg1(struct thread *td, int sig, int pgid, int all, ksiginfo_t *ksi) in killpg1() argument
1861 arg.sig = sig; in killpg1()
1869 prison_proc_iterate(td->td_ucred->cr_prison, in killpg1()
1878 pgrp = td->td_proc->p_pgrp; in killpg1()
1888 if (!sx_try_xlock(&pgrp->pg_killsx)) { in killpg1()
1890 sx_xlock(&pgrp->pg_killsx); in killpg1()
1891 sx_xunlock(&pgrp->pg_killsx); in killpg1()
1894 LIST_FOREACH(p, &pgrp->pg_members, p_pglist) { in killpg1()
1898 sx_xunlock(&pgrp->pg_killsx); in killpg1()
1917 return (kern_kill(td, uap->pid, uap->signum)); in sys_kill()
1932 if (pid != td->td_proc->p_pid) { in kern_kill()
1947 ksi.ksi_pid = td->td_proc->p_pid; in kern_kill()
1948 ksi.ksi_uid = td->td_ucred->cr_ruid; in kern_kill()
1962 case -1: /* broadcast signal */ in kern_kill()
1967 return (killpg1(td, signum, -pid, 0, &ksi)); in kern_kill()
1978 AUDIT_ARG_SIGNUM(uap->signum); in sys_pdkill()
1979 AUDIT_ARG_FD(uap->fd); in sys_pdkill()
1980 if ((u_int)uap->signum > _SIG_MAXSIG) in sys_pdkill()
1983 error = procdesc_find(td, uap->fd, &cap_pdkill_rights, &p); in sys_pdkill()
1987 error = p_cansignal(td, p, uap->signum); in sys_pdkill()
1988 if (error == 0 && uap->signum) in sys_pdkill()
1989 kern_psignal(p, uap->signum); in sys_pdkill()
2007 AUDIT_ARG_SIGNUM(uap->signum); in okillpg()
2008 AUDIT_ARG_PID(uap->pgid); in okillpg()
2009 if ((u_int)uap->signum > _SIG_MAXSIG) in okillpg()
2013 ksi.ksi_signo = uap->signum; in okillpg()
2015 ksi.ksi_pid = td->td_proc->p_pid; in okillpg()
2016 ksi.ksi_uid = td->td_ucred->cr_ruid; in okillpg()
2017 return (killpg1(td, uap->signum, uap->pgid, 0, &ksi)); in okillpg()
2033 sv.sival_ptr = uap->value; in sys_sigqueue()
2035 return (kern_sigqueue(td, uap->pid, uap->signum, &sv)); in sys_sigqueue()
2063 p = td->td_proc; in kern_sigqueue()
2064 td2 = tdfind((lwpid_t)pid, p->p_pid); in kern_sigqueue()
2075 ksi.ksi_pid = td->td_proc->p_pid; in kern_sigqueue()
2076 ksi.ksi_uid = td->td_ucred->cr_ruid; in kern_sigqueue()
2089 pgsignal(struct pgrp *pgrp, int sig, int checkctty, ksiginfo_t *ksi) in pgsignal() argument
2095 LIST_FOREACH(p, &pgrp->pg_members, p_pglist) { in pgsignal()
2097 if (p->p_state == PRS_NORMAL && in pgsignal()
2098 (checkctty == 0 || p->p_flag & P_CONTROLT)) in pgsignal()
2099 pksignal(p, sig, ksi); in pgsignal()
2108 * mach-specific routine, because sysent->sv_sendsig() needs correct
2112 postsig_done(int sig, struct thread *td, struct sigacts *ps) in postsig_done() argument
2116 mtx_assert(&ps->ps_mtx, MA_OWNED); in postsig_done()
2117 td->td_ru.ru_nsignals++; in postsig_done()
2118 mask = ps->ps_catchmask[_SIG_IDX(sig)]; in postsig_done()
2119 if (!SIGISMEMBER(ps->ps_signodefer, sig)) in postsig_done()
2120 SIGADDSET(mask, sig); in postsig_done()
2123 if (SIGISMEMBER(ps->ps_sigreset, sig)) in postsig_done()
2124 sigdflt(ps, sig); in postsig_done()
2138 int sig; in trapsignal() local
2140 p = td->td_proc; in trapsignal()
2141 sig = ksi->ksi_signo; in trapsignal()
2142 KASSERT(_SIG_VALID(sig), ("invalid signal")); in trapsignal()
2146 ps = p->p_sigacts; in trapsignal()
2147 mtx_lock(&ps->ps_mtx); in trapsignal()
2148 sigmask = td->td_sigmask; in trapsignal()
2149 if (td->td_sigblock_val != 0) in trapsignal()
2151 if ((p->p_flag & P_TRACED) == 0 && SIGISMEMBER(ps->ps_sigcatch, sig) && in trapsignal()
2152 !SIGISMEMBER(sigmask, sig)) { in trapsignal()
2155 ktrpsig(sig, ps->ps_sigact[_SIG_IDX(sig)], in trapsignal()
2156 &td->td_sigmask, ksi->ksi_code); in trapsignal()
2158 (*p->p_sysent->sv_sendsig)(ps->ps_sigact[_SIG_IDX(sig)], in trapsignal()
2159 ksi, &td->td_sigmask); in trapsignal()
2160 postsig_done(sig, td, ps); in trapsignal()
2161 mtx_unlock(&ps->ps_mtx); in trapsignal()
2168 if (kern_forcesigexit && (SIGISMEMBER(sigmask, sig) || in trapsignal()
2169 ps->ps_sigact[_SIG_IDX(sig)] == SIG_IGN)) { in trapsignal()
2170 SIGDELSET(td->td_sigmask, sig); in trapsignal()
2171 SIGDELSET(ps->ps_sigcatch, sig); in trapsignal()
2172 SIGDELSET(ps->ps_sigignore, sig); in trapsignal()
2173 ps->ps_sigact[_SIG_IDX(sig)] = SIG_DFL; in trapsignal()
2174 td->td_pflags &= ~TDP_SIGFASTBLOCK; in trapsignal()
2175 td->td_sigblock_val = 0; in trapsignal()
2177 mtx_unlock(&ps->ps_mtx); in trapsignal()
2178 p->p_sig = sig; /* XXX to verify code */ in trapsignal()
2179 tdsendsignal(p, td, sig, ksi); in trapsignal()
2185 sigtd(struct proc *p, int sig, bool fast_sigblock) in sigtd() argument
2196 if (curproc == p && !SIGISMEMBER(curthread->td_sigmask, sig) && in sigtd()
2197 (!fast_sigblock || curthread->td_sigblock_val == 0)) in sigtd()
2200 /* Find a non-stopped thread that does not mask the signal. */ in sigtd()
2203 if (!SIGISMEMBER(td->td_sigmask, sig) && (!fast_sigblock || in sigtd()
2204 td != curthread || td->td_sigblock_val == 0) && in sigtd()
2205 (td->td_flags & TDF_BOUNDARY) == 0) { in sigtd()
2234 kern_psignal(struct proc *p, int sig) in kern_psignal() argument
2239 ksi.ksi_signo = sig; in kern_psignal()
2241 (void) tdsendsignal(p, NULL, sig, &ksi); in kern_psignal()
2245 pksignal(struct proc *p, int sig, ksiginfo_t *ksi) in pksignal() argument
2248 return (tdsendsignal(p, NULL, sig, ksi)); in pksignal()
2257 if (sigev->sigev_notify == SIGEV_THREAD_ID) { in sigev_findtd()
2258 td = tdfind(sigev->sigev_notify_thread_id, p->p_pid); in sigev_findtd()
2270 tdsignal(struct thread *td, int sig) in tdsignal() argument
2275 ksi.ksi_signo = sig; in tdsignal()
2277 (void) tdsendsignal(td->td_proc, td, sig, &ksi); in tdsignal()
2281 tdksignal(struct thread *td, int sig, ksiginfo_t *ksi) in tdksignal() argument
2284 (void) tdsendsignal(td->td_proc, td, sig, ksi); in tdksignal()
2292 if (intrval == 0 && (td->td_flags & TDF_SIGWAIT) == 0) in sig_sleepq_abort()
2299 tdsendsignal(struct proc *p, struct thread *td, int sig, ksiginfo_t *ksi) in tdsendsignal() argument
2306 MPASS(td == NULL || p == td->td_proc); in tdsendsignal()
2309 if (!_SIG_VALID(sig)) in tdsendsignal()
2310 panic("%s(): invalid signal %d", __func__, sig); in tdsendsignal()
2315 * IEEE Std 1003.1-2001: return success when killing a zombie. in tdsendsignal()
2317 if (p->p_state == PRS_ZOMBIE) { in tdsendsignal()
2318 if (ksi != NULL && (ksi->ksi_flags & KSI_INS) != 0) in tdsendsignal()
2323 ps = p->p_sigacts; in tdsendsignal()
2324 KNOTE_LOCKED(p->p_klist, NOTE_SIGNAL | sig); in tdsendsignal()
2325 prop = sigprop(sig); in tdsendsignal()
2328 td = sigtd(p, sig, false); in tdsendsignal()
2329 sigqueue = &p->p_sigqueue; in tdsendsignal()
2331 sigqueue = &td->td_sigqueue; in tdsendsignal()
2333 SDT_PROBE3(proc, , , signal__send, td, p, sig); in tdsendsignal()
2341 mtx_lock(&ps->ps_mtx); in tdsendsignal()
2342 if (SIGISMEMBER(ps->ps_sigignore, sig)) { in tdsendsignal()
2344 (p->p_sysent->sv_flags & SV_SIG_DISCIGN) == 0) { in tdsendsignal()
2345 SDT_PROBE3(proc, , , signal__discard, td, p, sig); in tdsendsignal()
2347 mtx_unlock(&ps->ps_mtx); in tdsendsignal()
2348 if (ksi != NULL && (ksi->ksi_flags & KSI_INS) != 0) in tdsendsignal()
2356 if (SIGISMEMBER(td->td_sigmask, sig)) in tdsendsignal()
2358 else if (SIGISMEMBER(ps->ps_sigcatch, sig)) in tdsendsignal()
2362 if (SIGISMEMBER(ps->ps_sigintr, sig)) in tdsendsignal()
2367 mtx_unlock(&ps->ps_mtx); in tdsendsignal()
2373 (p->p_flag & P_TRACED) != 0 && in tdsendsignal()
2374 (p->p_flag2 & P2_PTRACE_FSTP) != 0) { in tdsendsignal()
2376 sig_handle_first_stop(NULL, p, sig); in tdsendsignal()
2388 (p->p_pgrp->pg_flags & PGRP_ORPHANED) != 0 && in tdsendsignal()
2390 if (ksi != NULL && (ksi->ksi_flags & KSI_INS) != 0) in tdsendsignal()
2395 if (p->p_flag & P_CONTINUED) { in tdsendsignal()
2396 p->p_flag &= ~P_CONTINUED; in tdsendsignal()
2397 PROC_LOCK(p->p_pptr); in tdsendsignal()
2398 sigqueue_take(p->p_ksi); in tdsendsignal()
2399 PROC_UNLOCK(p->p_pptr); in tdsendsignal()
2403 ret = sigqueue_add(sigqueue, sig, ksi); in tdsendsignal()
2412 !((prop & SIGPROP_CONT) && (p->p_flag & P_STOPPED_SIG))) in tdsendsignal()
2416 * Some signals have a process-wide effect and a per-thread in tdsendsignal()
2421 * We try to do the per-process part here. in tdsendsignal()
2424 KASSERT(!(p->p_flag & P_WEXIT), in tdsendsignal()
2426 if (sig == SIGKILL) { in tdsendsignal()
2431 if (p->p_flag & P_TRACED) in tdsendsignal()
2438 p->p_flag &= ~P_STOPPED_SIG; in tdsendsignal()
2447 if (p->p_flag & P_TRACED) in tdsendsignal()
2459 p->p_flag &= ~P_STOPPED_SIG; in tdsendsignal()
2461 if (p->p_numthreads == p->p_suspcount) { in tdsendsignal()
2463 PROC_LOCK(p->p_pptr); in tdsendsignal()
2465 PROC_UNLOCK(p->p_pptr); in tdsendsignal()
2471 sigqueue_delete(sigqueue, sig); in tdsendsignal()
2495 if (p->p_flag & P_TRACED) in tdsendsignal()
2502 p->p_flag |= P_STOPPED_SIG; in tdsendsignal()
2503 sigqueue_delete(sigqueue, sig); in tdsendsignal()
2527 } else if (p->p_state == PRS_NORMAL) { in tdsendsignal()
2528 if (p->p_flag & P_TRACED || action == SIG_CATCH) { in tdsendsignal()
2529 tdsigwakeup(td, sig, action, intrval); in tdsendsignal()
2536 if (p->p_flag & (P_PPWAIT|P_WEXIT)) in tdsendsignal()
2538 p->p_flag |= P_STOPPED_SIG; in tdsendsignal()
2539 p->p_xsig = sig; in tdsendsignal()
2542 if (p->p_numthreads == p->p_suspcount) { in tdsendsignal()
2552 sigqueue_delete_proc(p, p->p_xsig); in tdsendsignal()
2559 sigqueue_delete(sigqueue, sig); in tdsendsignal()
2568 tdsigwakeup(td, sig, action, intrval); in tdsendsignal()
2585 tdsigwakeup(struct thread *td, int sig, sig_t action, int intrval) in tdsigwakeup() argument
2587 struct proc *p = td->td_proc; in tdsigwakeup()
2591 prop = sigprop(sig); in tdsigwakeup()
2602 td->td_priority > PUSER && !TD_IS_IDLETHREAD(td)) in tdsigwakeup()
2611 if ((td->td_flags & TDF_SINTR) == 0) in tdsigwakeup()
2621 sigqueue_delete(&p->p_sigqueue, sig); in tdsigwakeup()
2626 sigqueue_delete(&td->td_sigqueue, sig); in tdsigwakeup()
2634 if ((prop & SIGPROP_STOP) != 0 && (td->td_flags & (TDF_SBDRY | in tdsigwakeup()
2641 if (td->td_priority > PUSER && !TD_IS_IDLETHREAD(td)) in tdsigwakeup()
2670 if (p->p_sysent->sv_coredump == NULL) { in ptrace_coredumpreq()
2671 tcq->tc_error = ENOSYS; in ptrace_coredumpreq()
2675 rl_cookie = vn_rangelock_wlock(tcq->tc_vp, 0, OFF_MAX); in ptrace_coredumpreq()
2676 tcq->tc_error = p->p_sysent->sv_coredump(td, tcq->tc_vp, in ptrace_coredumpreq()
2677 tcq->tc_limit, tcq->tc_flags); in ptrace_coredumpreq()
2678 vn_rangelock_unlock(tcq->tc_vp, rl_cookie); in ptrace_coredumpreq()
2692 sv = p->p_sysent; in ptrace_syscallreq()
2693 if (sv->sv_table == NULL || sv->sv_size < tsr->ts_sa.code) { in ptrace_syscallreq()
2694 tsr->ts_ret.sr_error = ENOSYS; in ptrace_syscallreq()
2698 sc = tsr->ts_sa.code; in ptrace_syscallreq()
2700 sc = tsr->ts_sa.args[0]; in ptrace_syscallreq()
2701 memmove(&tsr->ts_sa.args[0], &tsr->ts_sa.args[1], in ptrace_syscallreq()
2702 sizeof(register_t) * (tsr->ts_nargs - 1)); in ptrace_syscallreq()
2705 tsr->ts_sa.callp = se = &sv->sv_table[sc]; in ptrace_syscallreq()
2708 td->td_pticks = 0; in ptrace_syscallreq()
2709 if (__predict_false(td->td_cowgen != atomic_load_int( in ptrace_syscallreq()
2710 &td->td_proc->p_cowgen))) in ptrace_syscallreq()
2713 td->td_sa = tsr->ts_sa; in ptrace_syscallreq()
2716 if ((se->sy_flags & SYF_CAPENABLED) == 0) { in ptrace_syscallreq()
2720 tsr->ts_ret.sr_error = ECAPMODE; in ptrace_syscallreq()
2726 sy_thr_static = (se->sy_thrcnt & SY_THR_STATIC) != 0; in ptrace_syscallreq()
2731 sy_thr_static = (se->sy_thrcnt & SY_THR_STATIC) != 0; in ptrace_syscallreq()
2733 tsr->ts_ret.sr_error = error; in ptrace_syscallreq()
2738 rv_saved[0] = td->td_retval[0]; in ptrace_syscallreq()
2739 rv_saved[1] = td->td_retval[1]; in ptrace_syscallreq()
2740 nerror = td->td_errno; in ptrace_syscallreq()
2741 td->td_retval[0] = 0; in ptrace_syscallreq()
2742 td->td_retval[1] = 0; in ptrace_syscallreq()
2745 if (se->sy_entry != 0) in ptrace_syscallreq()
2746 (*systrace_probe_func)(&tsr->ts_sa, SYSTRACE_ENTRY, 0); in ptrace_syscallreq()
2748 tsr->ts_ret.sr_error = se->sy_call(td, tsr->ts_sa.args); in ptrace_syscallreq()
2750 if (se->sy_return != 0) in ptrace_syscallreq()
2751 (*systrace_probe_func)(&tsr->ts_sa, SYSTRACE_RETURN, in ptrace_syscallreq()
2752 tsr->ts_ret.sr_error != 0 ? -1 : td->td_retval[0]); in ptrace_syscallreq()
2755 tsr->ts_ret.sr_retval[0] = td->td_retval[0]; in ptrace_syscallreq()
2756 tsr->ts_ret.sr_retval[1] = td->td_retval[1]; in ptrace_syscallreq()
2757 td->td_retval[0] = rv_saved[0]; in ptrace_syscallreq()
2758 td->td_retval[1] = rv_saved[1]; in ptrace_syscallreq()
2759 td->td_errno = nerror; in ptrace_syscallreq()
2773 p = td->td_proc; in ptrace_remotereq()
2775 if ((td->td_dbgflags & flag) == 0) in ptrace_remotereq()
2777 KASSERT((p->p_flag & P_STOPPED_TRACE) != 0, ("not stopped")); in ptrace_remotereq()
2778 KASSERT(td->td_remotereq != NULL, ("td_remotereq is NULL")); in ptrace_remotereq()
2783 ptrace_coredumpreq(td, p, td->td_remotereq); in ptrace_remotereq()
2786 ptrace_syscallreq(td, p, td->td_remotereq); in ptrace_remotereq()
2793 MPASS((td->td_dbgflags & flag) != 0); in ptrace_remotereq()
2794 td->td_dbgflags &= ~flag; in ptrace_remotereq()
2795 td->td_remotereq = NULL; in ptrace_remotereq()
2820 if (TD_IS_SLEEPING(td2) && (td2->td_flags & TDF_SINTR) != 0) { in sig_suspend_threads()
2821 if (td2->td_flags & TDF_SBDRY) { in sig_suspend_threads()
2850 sig_handle_first_stop(struct thread *td, struct proc *p, int sig) in sig_handle_first_stop() argument
2852 if (td != NULL && (td->td_dbgflags & TDB_FSTP) == 0 && in sig_handle_first_stop()
2853 ((p->p_flag2 & P2_PTRACE_FSTP) != 0 || p->p_xthread != NULL)) in sig_handle_first_stop()
2856 p->p_xsig = sig; in sig_handle_first_stop()
2857 p->p_xthread = td; in sig_handle_first_stop()
2863 if (td != NULL && td->td_wchan == NULL) in sig_handle_first_stop()
2864 td->td_dbgflags &= ~TDB_FSTP; in sig_handle_first_stop()
2866 p->p_flag2 &= ~P2_PTRACE_FSTP; in sig_handle_first_stop()
2867 p->p_flag |= P_STOPPED_SIG | P_STOPPED_TRACE; in sig_handle_first_stop()
2874 * non-NULL, this is a signal exchange; the new signal requested by the
2880 ptracestop(struct thread *td, int sig, ksiginfo_t *si) in ptracestop() argument
2882 struct proc *p = td->td_proc; in ptracestop()
2887 KASSERT(!(p->p_flag & P_WEXIT), ("Stopping exiting process")); in ptracestop()
2889 &p->p_mtx.lock_object, "Stopping for traced signal"); in ptracestop()
2891 td->td_xsig = sig; in ptracestop()
2893 if (si == NULL || (si->ksi_flags & KSI_PTRACE) == 0) { in ptracestop()
2894 td->td_dbgflags |= TDB_XSIG; in ptracestop()
2895 CTR4(KTR_PTRACE, "ptracestop: tid %d (pid %d) flags %#x sig %d", in ptracestop()
2896 td->td_tid, p->p_pid, td->td_dbgflags, sig); in ptracestop()
2898 while ((p->p_flag & P_TRACED) && (td->td_dbgflags & TDB_XSIG)) { in ptracestop()
2907 td->td_dbgflags &= ~TDB_XSIG; in ptracestop()
2908 td->td_xsig = SIGKILL; in ptracestop()
2909 p->p_ptevents = 0; in ptracestop()
2912 if (p->p_flag & P_SINGLE_EXIT && in ptracestop()
2913 !(td->td_dbgflags & TDB_EXIT)) { in ptracestop()
2918 td->td_dbgflags &= ~TDB_XSIG; in ptracestop()
2932 sig_handle_first_stop(td, p, sig); in ptracestop()
2934 if ((td->td_dbgflags & TDB_STOPATFORK) != 0) { in ptracestop()
2935 td->td_dbgflags &= ~TDB_STOPATFORK; in ptracestop()
2938 td->td_dbgflags |= TDB_SSWITCH; in ptracestop()
2940 td->td_dbgflags &= ~TDB_SSWITCH; in ptracestop()
2941 if ((td->td_dbgflags & (TDB_COREDUMPREQ | in ptracestop()
2943 MPASS((td->td_dbgflags & (TDB_COREDUMPREQ | in ptracestop()
2947 ptrace_remotereq(td, td->td_dbgflags & in ptracestop()
2952 if (p->p_xthread == td) in ptracestop()
2953 p->p_xthread = NULL; in ptracestop()
2954 if (!(p->p_flag & P_TRACED)) in ptracestop()
2956 if (td->td_dbgflags & TDB_SUSPEND) { in ptracestop()
2957 if (p->p_flag & P_SINGLE_EXIT) in ptracestop()
2965 if (si != NULL && sig == td->td_xsig) { in ptracestop()
2967 si->ksi_flags |= KSI_HEAD; in ptracestop()
2968 if (sigqueue_add(&td->td_sigqueue, sig, si) != 0) in ptracestop()
2969 si->ksi_signo = 0; in ptracestop()
2970 } else if (td->td_xsig != 0) { in ptracestop()
2973 * it in td->td_xsig; otherwise we just look for signals again. in ptracestop()
2976 ksi.ksi_signo = td->td_xsig; in ptracestop()
2978 td2 = sigtd(p, td->td_xsig, false); in ptracestop()
2979 tdsendsignal(p, td2, td->td_xsig, &ksi); in ptracestop()
2984 return (td->td_xsig); in ptracestop()
2992 int sig; in reschedule_signals() local
2996 ps = p->p_sigacts; in reschedule_signals()
2998 mtx_assert(&ps->ps_mtx, pslocked ? MA_OWNED : MA_NOTOWNED); in reschedule_signals()
2999 if (SIGISEMPTY(p->p_siglist)) in reschedule_signals()
3001 SIGSETAND(block, p->p_siglist); in reschedule_signals()
3003 SIG_FOREACH(sig, &block) { in reschedule_signals()
3004 td = sigtd(p, sig, fastblk); in reschedule_signals()
3016 mtx_lock(&ps->ps_mtx); in reschedule_signals()
3017 if (p->p_flag & P_TRACED || in reschedule_signals()
3018 (SIGISMEMBER(ps->ps_sigcatch, sig) && in reschedule_signals()
3019 !SIGISMEMBER(td->td_sigmask, sig))) { in reschedule_signals()
3020 tdsigwakeup(td, sig, SIG_CATCH, in reschedule_signals()
3021 (SIGISMEMBER(ps->ps_sigintr, sig) ? EINTR : in reschedule_signals()
3025 mtx_unlock(&ps->ps_mtx); in reschedule_signals()
3035 p = td->td_proc; in tdsigcleanup()
3038 sigqueue_flush(&td->td_sigqueue); in tdsigcleanup()
3039 if (p->p_numthreads == 1) in tdsigcleanup()
3051 SIGSETNAND(unblocked, td->td_sigmask); in tdsigcleanup()
3052 SIGFILLSET(td->td_sigmask); in tdsigcleanup()
3072 * cleared by the current thread, which allow the lock-less read-only
3082 cflags = sigdeferstop_curr_flags(td->td_flags); in sigdeferstop_impl()
3106 td->td_flags = (td->td_flags & ~cflags) | nflags; in sigdeferstop_impl()
3127 cflags = sigdeferstop_curr_flags(td->td_flags); in sigallowstop_impl()
3130 td->td_flags = (td->td_flags & ~cflags) | prev; in sigallowstop_impl()
3143 * The thread has signal "sig" pending. Figure out what to do with it:
3145 * _HANDLE -> the caller should handle the signal
3146 * _HANDLED -> handled internally, reload pending signal set
3147 * _IGNORE -> ignored, remove from the set of pending signals and try the
3149 * _SBDRY_STOP -> the signal should stop the thread but this is not
3153 sigprocess(struct thread *td, int sig) in sigprocess() argument
3161 KASSERT(_SIG_VALID(sig), ("%s: invalid signal %d", __func__, sig)); in sigprocess()
3163 p = td->td_proc; in sigprocess()
3164 ps = p->p_sigacts; in sigprocess()
3165 mtx_assert(&ps->ps_mtx, MA_OWNED); in sigprocess()
3173 if (SIGISMEMBER(ps->ps_sigignore, sig) && in sigprocess()
3174 (p->p_flag & P_TRACED) == 0 && in sigprocess()
3175 (td->td_flags & TDF_SIGWAIT) == 0) { in sigprocess()
3180 * If the process is going to single-thread mode to prepare in sigprocess()
3186 if ((p->p_flag2 & P2_WEXIT) != 0) in sigprocess()
3189 if ((p->p_flag & (P_TRACED | P_PPTRACE)) == P_TRACED) { in sigprocess()
3196 queue = &td->td_sigqueue; in sigprocess()
3198 if (sigqueue_get(queue, sig, &ksi) == 0) { in sigprocess()
3199 queue = &p->p_sigqueue; in sigprocess()
3200 sigqueue_get(queue, sig, &ksi); in sigprocess()
3202 td->td_si = ksi.ksi_info; in sigprocess()
3204 mtx_unlock(&ps->ps_mtx); in sigprocess()
3205 sig = ptracestop(td, sig, &ksi); in sigprocess()
3206 mtx_lock(&ps->ps_mtx); in sigprocess()
3208 td->td_si.si_signo = 0; in sigprocess()
3214 if (sig == 0) in sigprocess()
3218 * If the signal became masked, re-queue it. in sigprocess()
3220 if (SIGISMEMBER(td->td_sigmask, sig)) { in sigprocess()
3222 sigqueue_add(&p->p_sigqueue, sig, &ksi); in sigprocess()
3231 if ((p->p_flag & P_TRACED) == 0) { in sigprocess()
3234 sigqueue_add(queue, sig, &ksi); in sigprocess()
3245 switch ((intptr_t)p->p_sigacts->ps_sigact[_SIG_IDX(sig)]) { in sigprocess()
3250 if (p->p_pid <= 1) { in sigprocess()
3257 (u_long)p->p_pid, sig); in sigprocess()
3269 prop = sigprop(sig); in sigprocess()
3271 mtx_unlock(&ps->ps_mtx); in sigprocess()
3272 if ((p->p_flag & (P_TRACED | P_WEXIT | in sigprocess()
3273 P_SINGLE_EXIT)) != 0 || ((p->p_pgrp-> in sigprocess()
3276 mtx_lock(&ps->ps_mtx); in sigprocess()
3280 KASSERT((td->td_flags & TDF_SBDRY) != 0, in sigprocess()
3282 mtx_lock(&ps->ps_mtx); in sigprocess()
3286 &p->p_mtx.lock_object, "Catching SIGSTOP"); in sigprocess()
3287 sigqueue_delete(&td->td_sigqueue, sig); in sigprocess()
3288 sigqueue_delete(&p->p_sigqueue, sig); in sigprocess()
3289 p->p_flag |= P_STOPPED_SIG; in sigprocess()
3290 p->p_xsig = sig; in sigprocess()
3295 mtx_lock(&ps->ps_mtx); in sigprocess()
3298 (td->td_flags & TDF_SIGWAIT) == 0) { in sigprocess()
3309 if ((td->td_flags & TDF_SIGWAIT) == 0) in sigprocess()
3331 * while (sig = cursig(curthread))
3332 * postsig(sig);
3339 int sig; in issignal() local
3341 p = td->td_proc; in issignal()
3345 sigpending = td->td_sigqueue.sq_signals; in issignal()
3346 SIGSETOR(sigpending, p->p_sigqueue.sq_signals); in issignal()
3347 SIGSETNAND(sigpending, td->td_sigmask); in issignal()
3349 if ((p->p_flag & P_PPWAIT) != 0 || (td->td_flags & in issignal()
3363 if ((td->td_pflags & TDP_SIGFASTBLOCK) != 0) { in issignal()
3364 if (td->td_sigblock_val != 0) in issignal()
3367 td->td_pflags |= TDP_SIGFASTPENDING; in issignal()
3373 (p->p_flag & (P_TRACED | P_PPTRACE)) == P_TRACED && in issignal()
3374 (p->p_flag2 & P2_PTRACE_FSTP) != 0 && in issignal()
3382 td->td_dbgflags |= TDB_FSTP; in issignal()
3387 SIG_FOREACH(sig, &sigpending) { in issignal()
3388 switch (sigprocess(td, sig)) { in issignal()
3390 return (sig); in issignal()
3394 sigqueue_delete(&td->td_sigqueue, sig); in issignal()
3395 sigqueue_delete(&p->p_sigqueue, sig); in issignal()
3398 return (-1); in issignal()
3412 n = p->p_suspcount; in thread_stopped()
3415 if ((p->p_flag & P_STOPPED_SIG) && (n == p->p_numthreads)) { in thread_stopped()
3417 p->p_flag &= ~P_WAITED; in thread_stopped()
3418 PROC_LOCK(p->p_pptr); in thread_stopped()
3419 childproc_stopped(p, (p->p_flag & P_TRACED) ? in thread_stopped()
3421 PROC_UNLOCK(p->p_pptr); in thread_stopped()
3431 postsig(int sig) in postsig() argument
3440 KASSERT(sig != 0, ("postsig")); in postsig()
3443 p = td->td_proc; in postsig()
3445 ps = p->p_sigacts; in postsig()
3446 mtx_assert(&ps->ps_mtx, MA_OWNED); in postsig()
3448 if (sigqueue_get(&td->td_sigqueue, sig, &ksi) == 0 && in postsig()
3449 sigqueue_get(&p->p_sigqueue, sig, &ksi) == 0) in postsig()
3451 ksi.ksi_signo = sig; in postsig()
3454 action = ps->ps_sigact[_SIG_IDX(sig)]; in postsig()
3457 ktrpsig(sig, action, td->td_pflags & TDP_OLDMASK ? in postsig()
3458 &td->td_oldsigmask : &td->td_sigmask, ksi.ksi_code); in postsig()
3466 mtx_unlock(&ps->ps_mtx); in postsig()
3468 sigexit(td, sig); in postsig()
3475 KASSERT(!SIGISMEMBER(td->td_sigmask, sig), in postsig()
3476 ("postsig action: blocked sig %d", sig)); in postsig()
3487 if (td->td_pflags & TDP_OLDMASK) { in postsig()
3488 returnmask = td->td_oldsigmask; in postsig()
3489 td->td_pflags &= ~TDP_OLDMASK; in postsig()
3491 returnmask = td->td_sigmask; in postsig()
3493 if (p->p_sig == sig) { in postsig()
3494 p->p_sig = 0; in postsig()
3496 (*p->p_sysent->sv_sendsig)(action, &ksi, &returnmask); in postsig()
3497 postsig_done(sig, td, ps); in postsig()
3508 p = td->td_proc; in sig_ast_checksusp()
3524 int ret, sig; in sig_ast_needsigchk() local
3526 p = td->td_proc; in sig_ast_needsigchk()
3532 ps = p->p_sigacts; in sig_ast_needsigchk()
3533 mtx_lock(&ps->ps_mtx); in sig_ast_needsigchk()
3534 sig = cursig(td); in sig_ast_needsigchk()
3535 if (sig == -1) { in sig_ast_needsigchk()
3536 mtx_unlock(&ps->ps_mtx); in sig_ast_needsigchk()
3537 KASSERT((td->td_flags & TDF_SBDRY) != 0, ("lost TDF_SBDRY")); in sig_ast_needsigchk()
3540 KASSERT((td->td_flags & (TDF_SEINTR | TDF_SERESTART)) != in sig_ast_needsigchk()
3544 } else if (sig != 0) { in sig_ast_needsigchk()
3545 ret = SIGISMEMBER(ps->ps_sigintr, sig) ? EINTR : ERESTART; in sig_ast_needsigchk()
3546 mtx_unlock(&ps->ps_mtx); in sig_ast_needsigchk()
3548 mtx_unlock(&ps->ps_mtx); in sig_ast_needsigchk()
3558 if ((td->td_dbgflags & TDB_FSTP) != 0) { in sig_ast_needsigchk()
3561 td->td_dbgflags &= ~TDB_FSTP; in sig_ast_needsigchk()
3578 p = td->td_proc; in sig_intr()
3600 p = td->td_proc; in curproc_sigkilled()
3602 ps = p->p_sigacts; in curproc_sigkilled()
3603 mtx_lock(&ps->ps_mtx); in curproc_sigkilled()
3604 res = SIGISMEMBER(td->td_sigqueue.sq_signals, SIGKILL) || in curproc_sigkilled()
3605 SIGISMEMBER(p->p_sigqueue.sq_signals, SIGKILL); in curproc_sigkilled()
3606 mtx_unlock(&ps->ps_mtx); in curproc_sigkilled()
3616 if ((p->p_flag & P_WKILLED) == 0) in proc_wkilled()
3617 p->p_flag |= P_WKILLED; in proc_wkilled()
3628 CTR3(KTR_PROC, "killproc: proc %p (pid %d, %s)", p, p->p_pid, in killproc()
3629 p->p_comm); in killproc()
3631 p->p_pid, p->p_comm, p->p_ucred->cr_prison->pr_id, in killproc()
3632 p->p_ucred->cr_uid, why); in killproc()
3646 sigexit(struct thread *td, int sig) in sigexit() argument
3648 struct proc *p = td->td_proc; in sigexit()
3656 p->p_acflag |= AXSIG; in sigexit()
3657 if ((p->p_flag2 & P2_LOGSIGEXIT_CTL) == 0) in sigexit()
3660 logexit = (p->p_flag2 & P2_LOGSIGEXIT_ENABLE) != 0; in sigexit()
3663 * We must be single-threading to generate a core dump. This in sigexit()
3664 * ensures that the registers in the core file are up-to-date. in sigexit()
3668 * XXX If another thread attempts to single-thread before us in sigexit()
3671 if ((sigprop(sig) & SIGPROP_CORE) && in sigexit()
3673 p->p_sig = sig; in sigexit()
3684 sig |= WCOREFLAG; in sigexit()
3688 coreinfo = " (no core dump - bad address)"; in sigexit()
3691 coreinfo = " (no core dump - invalid argument)"; in sigexit()
3694 coreinfo = " (no core dump - too large)"; in sigexit()
3697 coreinfo = " (no core dump - other error)"; in sigexit()
3703 "signal %d%s\n", p->p_pid, p->p_comm, in sigexit()
3704 p->p_ucred->cr_prison->pr_id, in sigexit()
3705 td->td_ucred->cr_uid, in sigexit()
3706 sig &~ WCOREFLAG, coreinfo); in sigexit()
3709 exit1(td, 0, sig); in sigexit()
3721 PROC_LOCK_ASSERT(p->p_pptr, MA_OWNED); in sigparent()
3723 if (p->p_ksi != NULL) { in sigparent()
3724 p->p_ksi->ksi_signo = SIGCHLD; in sigparent()
3725 p->p_ksi->ksi_code = reason; in sigparent()
3726 p->p_ksi->ksi_status = status; in sigparent()
3727 p->p_ksi->ksi_pid = p->p_pid; in sigparent()
3728 p->p_ksi->ksi_uid = p->p_ucred->cr_ruid; in sigparent()
3729 if (KSI_ONQ(p->p_ksi)) in sigparent()
3738 if (p->p_pptr->p_state != PRS_ZOMBIE) in sigparent()
3739 pksignal(p->p_pptr, SIGCHLD, p->p_ksi); in sigparent()
3743 childproc_jobstate(struct proc *p, int reason, int sig) in childproc_jobstate() argument
3748 PROC_LOCK_ASSERT(p->p_pptr, MA_OWNED); in childproc_jobstate()
3756 p->p_pptr->p_flag |= P_STATCHILD; in childproc_jobstate()
3757 wakeup(p->p_pptr); in childproc_jobstate()
3759 ps = p->p_pptr->p_sigacts; in childproc_jobstate()
3760 mtx_lock(&ps->ps_mtx); in childproc_jobstate()
3761 if ((ps->ps_flag & PS_NOCLDSTOP) == 0) { in childproc_jobstate()
3762 mtx_unlock(&ps->ps_mtx); in childproc_jobstate()
3763 sigparent(p, reason, sig); in childproc_jobstate()
3765 mtx_unlock(&ps->ps_mtx); in childproc_jobstate()
3772 childproc_jobstate(p, reason, p->p_xsig); in childproc_stopped()
3779 p->p_flag |= P_CONTINUED; in childproc_continued()
3780 p->p_xsig = SIGCONT; in childproc_continued()
3789 if (WCOREDUMP(p->p_xsig)) { in childproc_exited()
3791 status = WTERMSIG(p->p_xsig); in childproc_exited()
3792 } else if (WIFSIGNALED(p->p_xsig)) { in childproc_exited()
3794 status = WTERMSIG(p->p_xsig); in childproc_exited()
3797 status = p->p_xexit; in childproc_exited()
3800 * XXX avoid calling wakeup(p->p_pptr), the work is in childproc_exited()
3821 if (error != 0 || req->newptr == NULL) in sysctl_debug_num_cores_check()
3847 if (error != 0 || req->newptr == NULL) in sysctl_compress_user_cores()
3895 vn_close(vp, FWRITE, td->td_ucred, td); in vnode_close_locked()
3902 * non-existing core file name to use. If all core files are
3930 error = vn_open_cred(&nd, &flags, cmode, oflags, td->td_ucred, in corefile_open_last()
3942 error = VOP_GETATTR(vp, &vattr, td->td_ucred); in corefile_open_last()
3953 vn_close(oldvp, FWRITE, td->td_ucred, td); in corefile_open_last()
3964 if ((td->td_proc->p_flag & P_SUGID) != 0) { in corefile_open_last()
3966 vn_close(oldvp, FWRITE, td->td_ucred, td); in corefile_open_last()
3971 vn_close(nextvp, FWRITE, td->td_ucred, in corefile_open_last()
3977 vn_close(oldvp, FWRITE, td->td_ucred, td); in corefile_open_last()
3994 * corefilename is a printf-like string, with three format specifiers:
3999 * by using "/dev/null", or all core files can be stored in "/cores/%U/%N-%P".
4016 indexpos = -1; in corefile_open()
4033 getcredhostname(td->td_ucred, hostname, in corefile_open()
4038 if (indexpos != -1) { in corefile_open()
4044 sbuf_printf(&sb, "%u", ncores - 1); in corefile_open()
4045 indexlen = sbuf_len(&sb) - indexpos; in corefile_open()
4087 if (indexpos != -1) { in corefile_open()
4101 if ((td->td_proc->p_flag & P_SUGID) != 0) in corefile_open()
4105 error = vn_open_cred(&nd, &flags, cmode, oflags, td->td_ucred, in corefile_open()
4127 * then it passes on a vnode and a size limit to the process-specific
4129 * ENOSYS; otherwise it returns the error from the process-specific routine.
4135 struct proc *p = td->td_proc; in coredump()
4136 struct ucred *cred = td->td_ucred; in coredump()
4141 int error, error1, jid, locked, ppid, sig; in coredump() local
4149 MPASS((p->p_flag & P_HADTHREADS) == 0 || p->p_singlethread == td); in coredump()
4151 if (!do_coredump || (!sugid_coredump && (p->p_flag & P_SUGID) != 0) || in coredump()
4152 (p->p_flag2 & P2_NOTRACE) != 0) { in coredump()
4171 ppid = p->p_oppid; in coredump()
4172 sig = p->p_sig; in coredump()
4173 jid = p->p_ucred->cr_prison->pr_id; in coredump()
4176 error = corefile_open(p->p_comm, cred->cr_uid, p->p_pid, td, in coredump()
4177 compress_user_cores, p->p_sig, &vp, &name); in coredump()
4182 * Don't dump to non-regular files or files with links. in coredump()
4185 if (vp->v_type != VREG || VOP_GETATTR(vp, &vattr, cred) != 0 || in coredump()
4186 vattr.va_nlink != 1 || (vp->v_vflag & VV_SYSTEM) != 0 || in coredump()
4187 vattr.va_uid != cred->cr_uid) { in coredump()
4212 p->p_acflag |= ACORE; in coredump()
4215 if (p->p_sysent->sv_coredump != NULL) { in coredump()
4216 error = p->p_sysent->sv_coredump(td, vp, limit, 0); in coredump()
4234 if (vn_fullpath_global(p->p_textvp, &fullpath, &freepath) != 0) in coredump()
4244 * if the path of the core is relative, add the current dir in front if it. in coredump()
4261 jid, p->p_pid, ppid, sig); in coredump()
4278 * Nonexistent system call-- signal process (may want to handle it). Flag
4290 return (kern_nosys(td, args->dummy)); in nosys()
4298 p = td->td_proc; in kern_nosys()
4306 uprintf("pid %d comm %s: nosys %d\n", p->p_pid, p->p_comm, in kern_nosys()
4307 td->td_sa.code); in kern_nosys()
4310 (p->p_pid == 1 && (kern_lognosys & 3) == 0)) { in kern_nosys()
4311 printf("pid %d comm %s: nosys %d\n", p->p_pid, p->p_comm, in kern_nosys()
4312 td->td_sa.code); in kern_nosys()
4322 pgsigio(struct sigio **sigiop, int sig, int checkctty) in pgsigio() argument
4328 ksi.ksi_signo = sig; in pgsigio()
4337 if (sigio->sio_pgid > 0) { in pgsigio()
4338 PROC_LOCK(sigio->sio_proc); in pgsigio()
4339 if (CANSIGIO(sigio->sio_ucred, sigio->sio_proc->p_ucred)) in pgsigio()
4340 kern_psignal(sigio->sio_proc, sig); in pgsigio()
4341 PROC_UNLOCK(sigio->sio_proc); in pgsigio()
4342 } else if (sigio->sio_pgid < 0) { in pgsigio()
4345 PGRP_LOCK(sigio->sio_pgrp); in pgsigio()
4346 LIST_FOREACH(p, &sigio->sio_pgrp->pg_members, p_pglist) { in pgsigio()
4348 if (p->p_state == PRS_NORMAL && in pgsigio()
4349 CANSIGIO(sigio->sio_ucred, p->p_ucred) && in pgsigio()
4350 (checkctty == 0 || (p->p_flag & P_CONTROLT))) in pgsigio()
4351 kern_psignal(p, sig); in pgsigio()
4354 PGRP_UNLOCK(sigio->sio_pgrp); in pgsigio()
4364 kn->kn_ptr.p_proc = p; in filt_sigattach()
4365 kn->kn_flags |= EV_CLEAR; /* automatically set */ in filt_sigattach()
4367 knlist_add(p->p_klist, kn, 0); in filt_sigattach()
4375 knlist_remove(kn->kn_knlist, kn, 0); in filt_sigdetach()
4381 * could be avoided by using a signal-specific knote list, but probably
4391 if (kn->kn_id == hint) in filt_signal()
4392 kn->kn_data++; in filt_signal()
4394 return (kn->kn_data != 0); in filt_signal()
4403 refcount_init(&ps->ps_refcnt, 1); in sigacts_alloc()
4404 mtx_init(&ps->ps_mtx, "sigacts", NULL, MTX_DEF); in sigacts_alloc()
4412 if (refcount_release(&ps->ps_refcnt) == 0) in sigacts_free()
4414 mtx_destroy(&ps->ps_mtx); in sigacts_free()
4422 refcount_acquire(&ps->ps_refcnt); in sigacts_hold()
4430 KASSERT(dest->ps_refcnt == 1, ("sigacts_copy to shared dest")); in sigacts_copy()
4431 mtx_lock(&src->ps_mtx); in sigacts_copy()
4433 mtx_unlock(&src->ps_mtx); in sigacts_copy()
4440 return (ps->ps_refcnt > 1); in sigacts_shared()
4446 int sig; in sig_drop_caught() local
4449 ps = p->p_sigacts; in sig_drop_caught()
4451 mtx_assert(&ps->ps_mtx, MA_OWNED); in sig_drop_caught()
4452 SIG_FOREACH(sig, &ps->ps_sigcatch) { in sig_drop_caught()
4453 sigdflt(ps, sig); in sig_drop_caught()
4454 if ((sigprop(sig) & SIGPROP_IGNORE) != 0) in sig_drop_caught()
4455 sigqueue_delete_proc(p, sig); in sig_drop_caught()
4475 ksi.ksi_addr = td->td_sigblock_ptr; in sigfastblock_failed()
4484 if ((td->td_pflags & TDP_SIGFASTBLOCK) == 0) in sigfastblock_fetch_sig()
4486 if (fueword32((void *)td->td_sigblock_ptr, &res) == -1) { in sigfastblock_fetch_sig()
4491 td->td_sigblock_val = res & ~SIGFASTBLOCK_FLAGS; in sigfastblock_fetch_sig()
4501 p = td->td_proc; in sigfastblock_resched()
4503 reschedule_signals(p, td->td_sigmask, 0); in sigfastblock_resched()
4517 p = td->td_proc; in sys_sigfastblock()
4518 switch (uap->cmd) { in sys_sigfastblock()
4520 if ((td->td_pflags & TDP_SIGFASTBLOCK) != 0) { in sys_sigfastblock()
4524 if (((uintptr_t)(uap->ptr) & (sizeof(uint32_t) - 1)) != 0) { in sys_sigfastblock()
4528 td->td_pflags |= TDP_SIGFASTBLOCK; in sys_sigfastblock()
4529 td->td_sigblock_ptr = uap->ptr; in sys_sigfastblock()
4533 if ((td->td_pflags & TDP_SIGFASTBLOCK) == 0) { in sys_sigfastblock()
4539 res = casueword32(td->td_sigblock_ptr, in sys_sigfastblock()
4541 if (res == -1) { in sys_sigfastblock()
4569 * non-conformance, with alternative to have read the in sys_sigfastblock()
4572 td->td_sigblock_val = 0; in sys_sigfastblock()
4579 sigfastblock_resched(td, error == 0 && p->p_numthreads != 1); in sys_sigfastblock()
4584 if ((td->td_pflags & TDP_SIGFASTBLOCK) == 0) { in sys_sigfastblock()
4611 if ((td->td_pflags & TDP_SIGFASTBLOCK) == 0) in sigfastblock_clear()
4613 td->td_sigblock_val = 0; in sigfastblock_clear()
4614 resched = (td->td_pflags & TDP_SIGFASTPENDING) != 0 || in sigfastblock_clear()
4616 td->td_pflags &= ~(TDP_SIGFASTBLOCK | TDP_SIGFASTPENDING); in sigfastblock_clear()
4634 if ((td->td_pflags & TDP_SIGFASTPENDING) == 0) in sigfastblock_setpend1()
4636 res = fueword32((void *)td->td_sigblock_ptr, &oldval); in sigfastblock_setpend1()
4637 if (res == -1) { in sigfastblock_setpend1()
4642 res = casueword32(td->td_sigblock_ptr, oldval, &oldval, in sigfastblock_setpend1()
4644 if (res == -1) { in sigfastblock_setpend1()
4649 td->td_sigblock_val = oldval & ~SIGFASTBLOCK_FLAGS; in sigfastblock_setpend1()
4650 td->td_pflags &= ~TDP_SIGFASTPENDING; in sigfastblock_setpend1()
4666 p = td->td_proc; in sigfastblock_setpend()