Lines Matching +full:proc +full:- +full:id

1 /*-
41 #include <sys/proc.h>
55 protect_setchild(struct thread *td, struct proc *p, int flags)
59 if (p->p_flag & P_SYSTEM || p_cansched(td, p) != 0)
62 p->p_flag |= P_PROTECTED;
64 p->p_flag2 |= P2_INHERIT_PROTECTED;
66 p->p_flag &= ~P_PROTECTED;
67 p->p_flag2 &= ~P2_INHERIT_PROTECTED;
73 protect_setchildren(struct thread *td, struct proc *top, int flags)
75 struct proc *p;
89 if (!LIST_EMPTY(&p->p_children))
90 p = LIST_FIRST(&p->p_children);
100 p = p->p_pptr;
107 protect_set(struct thread *td, struct proc *p, void *data)
137 reap_acquire(struct thread *td, struct proc *p, void *data __unused)
141 if (p != td->td_proc)
143 if ((p->p_treeflag & P_TREE_REAPER) != 0)
145 p->p_treeflag |= P_TREE_REAPER;
148 * under them to us, since p->p_reaper already seen them.
154 reap_release(struct thread *td, struct proc *p, void *data __unused)
158 if (p != td->td_proc)
162 if ((p->p_treeflag & P_TREE_REAPER) == 0)
169 reap_status(struct thread *td, struct proc *p, void *data)
171 struct proc *reap, *p2, *first_p;
176 if ((p->p_treeflag & P_TREE_REAPER) == 0) {
177 reap = p->p_reaper;
180 rs->rs_flags |= REAPER_STATUS_OWNED;
183 rs->rs_flags |= REAPER_STATUS_REALINIT;
184 rs->rs_reaper = reap->p_pid;
185 rs->rs_descendants = 0;
186 rs->rs_children = 0;
187 if (!LIST_EMPTY(&reap->p_reaplist)) {
188 first_p = LIST_FIRST(&reap->p_children);
190 first_p = LIST_FIRST(&reap->p_reaplist);
191 rs->rs_pid = first_p->p_pid;
192 LIST_FOREACH(p2, &reap->p_reaplist, p_reapsibling) {
194 rs->rs_children++;
195 rs->rs_descendants++;
198 rs->rs_pid = -1;
204 reap_getpids(struct thread *td, struct proc *p, void *data)
206 struct proc *reap, *p2;
215 reap = (p->p_treeflag & P_TREE_REAPER) == 0 ? p->p_reaper : p;
218 LIST_FOREACH(p2, &reap->p_reaplist, p_reapsibling)
221 if (rp->rp_count < n)
222 n = rp->rp_count;
225 LIST_FOREACH(p2, &reap->p_reaplist, p_reapsibling) {
230 pip->pi_pid = p2->p_pid;
231 pip->pi_subtree = p2->p_reapsubtree;
232 pip->pi_flags = REAPER_PIDINFO_VALID;
234 pip->pi_flags |= REAPER_PIDINFO_CHILD;
235 if ((p2->p_treeflag & P_TREE_REAPER) != 0)
236 pip->pi_flags |= REAPER_PIDINFO_REAPER;
237 if ((p2->p_flag & P_STOPPED) != 0)
238 pip->pi_flags |= REAPER_PIDINFO_STOPPED;
239 if (p2->p_state == PRS_ZOMBIE)
240 pip->pi_flags |= REAPER_PIDINFO_ZOMBIE;
241 else if ((p2->p_flag & P_WEXIT) != 0)
242 pip->pi_flags |= REAPER_PIDINFO_EXITING;
246 error = copyout(pi, rp->rp_pids, i * sizeof(*pi));
255 struct proc *target;
268 PROC_LOCK_ASSERT(w->target, MA_OWNED);
269 PROC_ASSERT_HELD(w->target);
271 error1 = cr_cansignal(w->cr, w->target, w->rk->rk_sig);
273 if (*w->error == ESRCH) {
274 w->rk->rk_fpid = w->target->p_pid;
275 *w->error = error1;
293 if ((w->target->p_flag & (P_KPROC | P_SYSTEM | P_STOPPED)) == 0)
294 need_stop = thread_single(w->target, SINGLE_ALLPROC) == 0;
298 (void)pksignal(w->target, w->rk->rk_sig, w->ksi);
299 w->rk->rk_killed++;
300 *w->error = error1;
303 thread_single_end(w->target, SINGLE_ALLPROC);
312 PROC_LOCK(w->target);
313 if ((w->target->p_flag2 & P2_WEXIT) == 0)
315 PROC_UNLOCK(w->target);
318 w->target = NULL;
319 wakeup(&w->target);
324 struct proc *parent;
331 reap_kill_sched(struct reap_kill_tracker_head *tracker, struct proc *p2)
336 if ((p2->p_flag2 & P2_WEXIT) != 0) {
343 t->parent = p2;
350 PRELE(t->parent);
355 reap_kill_children(struct thread *td, struct proc *reaper,
358 struct proc *p2;
361 LIST_FOREACH(p2, &reaper->p_children, p_sibling) {
363 if ((p2->p_flag2 & P2_WEXIT) == 0) {
364 error1 = p_cansignal(td, p2, rk->rk_sig);
367 rk->rk_fpid = p2->p_pid;
376 (void)pksignal(p2, rk->rk_sig, ksi);
377 rk->rk_killed++;
385 reap_kill_subtree_once(struct thread *td, struct proc *p, struct proc *reaper,
390 struct proc *p2;
406 if ((t->parent->p_treeflag & P_TREE_REAPER) == 0) {
412 LIST_FOREACH(p2, &t->parent->p_reaplist, p_reapsibling) {
413 if (t->parent == reaper &&
414 (w->rk->rk_flags & REAPER_KILL_SUBTREE) != 0 &&
415 p2->p_reapsubtree != w->rk->rk_subtree)
417 if ((p2->p_treeflag & P_TREE_REAPER) != 0)
424 * terminated and its id was reused by other
427 * Unlocked read of p2->p_flag2 is fine, it is
430 if (alloc_unr_specific(pids, p2->p_pid) != p2->p_pid &&
431 (atomic_load_int(&p2->p_flag2) &
435 if (p2 == td->td_proc) {
436 if ((p2->p_flag & P_HADTHREADS) != 0 &&
437 (p2->p_flag2 & P2_WEXIT) == 0) {
449 p2->p_flag2 |= P2_REAPKILLED;
452 (void)pksignal(p2, w->rk->rk_sig, w->ksi);
453 w->rk->rk_killed++;
465 if ((p2->p_flag2 & P2_WEXIT) == 0) {
467 p2->p_flag2 |= P2_REAPKILLED;
469 w->target = p2;
471 &w->t);
472 while (w->target != NULL) {
473 sx_sleep(&w->target,
490 reap_kill_subtree(struct thread *td, struct proc *p, struct proc *reaper,
495 struct proc *p2;
504 PROC_LOCK(td->td_proc);
505 if ((td->td_proc->p_flag2 & P2_WEXIT) != 0) {
506 PROC_UNLOCK(td->td_proc);
509 PROC_UNLOCK(td->td_proc);
514 while ((pid = next_iter_unr(ihandle)) != -1) {
517 p2->p_flag2 &= ~P2_REAPKILLED;
534 return ((rk->rk_flags & REAPER_KILL_CHILDREN) == 0);
538 reap_kill(struct thread *td, struct proc *p, void *data)
541 struct proc *reaper;
549 ktrcapfail(CAPFAIL_SIGNAL, &rk->rk_sig);
552 if (rk->rk_sig <= 0 || rk->rk_sig > _SIG_MAXSIG ||
553 (rk->rk_flags & ~(REAPER_KILL_CHILDREN |
554 REAPER_KILL_SUBTREE)) != 0 || (rk->rk_flags &
559 reaper = (p->p_treeflag & P_TREE_REAPER) == 0 ? p->p_reaper : p;
561 ksi.ksi_signo = rk->rk_sig;
563 ksi.ksi_pid = td->td_proc->p_pid;
564 ksi.ksi_uid = td->td_ucred->cr_ruid;
566 rk->rk_killed = 0;
567 rk->rk_fpid = -1;
568 if ((rk->rk_flags & REAPER_KILL_CHILDREN) != 0) {
571 w.cr = crhold(td->td_ucred);
584 trace_ctl(struct thread *td, struct proc *p, void *data)
596 if ((p->p_flag & P_TRACED) != 0 || p->p_traceflag != 0)
601 if (td->td_proc != p)
603 p->p_flag2 &= ~(P2_NOTRACE | P2_NOTRACE_EXEC);
606 p->p_flag2 |= P2_NOTRACE_EXEC | P2_NOTRACE;
609 if ((p->p_flag2 & P2_NOTRACE_EXEC) != 0) {
610 KASSERT((p->p_flag2 & P2_NOTRACE) != 0,
612 if (td->td_proc != p)
614 p->p_flag2 &= ~P2_NOTRACE_EXEC;
616 p->p_flag2 |= P2_NOTRACE;
626 trace_status(struct thread *td, struct proc *p, void *data)
631 if ((p->p_flag2 & P2_NOTRACE) != 0) {
632 KASSERT((p->p_flag & P_TRACED) == 0,
633 ("%d traced but tracing disabled", p->p_pid));
634 *status = -1;
635 } else if ((p->p_flag & P_TRACED) != 0) {
636 *status = p->p_pptr->p_pid;
644 trapcap_ctl(struct thread *td, struct proc *p, void *data)
653 p->p_flag2 |= P2_TRAPCAP;
656 p->p_flag2 &= ~P2_TRAPCAP;
665 trapcap_status(struct thread *td, struct proc *p, void *data)
670 *status = (p->p_flag2 & P2_TRAPCAP) != 0 ? PROC_TRAPCAP_CTL_ENABLE :
676 no_new_privs_ctl(struct thread *td, struct proc *p, void *data)
685 p->p_flag2 |= P2_NO_NEW_PRIVS;
690 no_new_privs_status(struct thread *td, struct proc *p, void *data)
693 *(int *)data = (p->p_flag2 & P2_NO_NEW_PRIVS) != 0 ?
699 protmax_ctl(struct thread *td, struct proc *p, void *data)
708 p->p_flag2 &= ~P2_PROTMAX_DISABLE;
709 p->p_flag2 |= P2_PROTMAX_ENABLE;
712 p->p_flag2 |= P2_PROTMAX_DISABLE;
713 p->p_flag2 &= ~P2_PROTMAX_ENABLE;
716 p->p_flag2 &= ~(P2_PROTMAX_ENABLE | P2_PROTMAX_DISABLE);
725 protmax_status(struct thread *td, struct proc *p, void *data)
729 switch (p->p_flag2 & (P2_PROTMAX_ENABLE | P2_PROTMAX_DISABLE)) {
747 aslr_ctl(struct thread *td, struct proc *p, void *data)
756 p->p_flag2 &= ~P2_ASLR_DISABLE;
757 p->p_flag2 |= P2_ASLR_ENABLE;
760 p->p_flag2 |= P2_ASLR_DISABLE;
761 p->p_flag2 &= ~P2_ASLR_ENABLE;
764 p->p_flag2 &= ~(P2_ASLR_ENABLE | P2_ASLR_DISABLE);
773 aslr_status(struct thread *td, struct proc *p, void *data)
778 switch (p->p_flag2 & (P2_ASLR_ENABLE | P2_ASLR_DISABLE)) {
789 if ((p->p_flag & P_WEXIT) == 0) {
794 if ((vm->vm_map.flags & MAP_ASLR) != 0)
806 stackgap_ctl(struct thread *td, struct proc *p, void *data)
818 if ((p->p_flag2 & P2_STKGAP_DISABLE) != 0)
822 p->p_flag2 |= P2_STKGAP_DISABLE;
832 p->p_flag2 &= ~P2_STKGAP_DISABLE_EXEC;
835 p->p_flag2 |= P2_STKGAP_DISABLE_EXEC;
846 stackgap_status(struct thread *td, struct proc *p, void *data)
852 d = (p->p_flag2 & P2_STKGAP_DISABLE) != 0 ? PROC_STACKGAP_DISABLE :
854 d |= (p->p_flag2 & P2_STKGAP_DISABLE_EXEC) != 0 ?
861 wxmap_ctl(struct thread *td, struct proc *p, void *data)
868 if ((p->p_flag & P_WEXIT) != 0)
874 p->p_flag2 |= P2_WXORX_DISABLE;
879 map = &vm->vm_map;
881 map->flags &= ~MAP_WXORX;
889 p->p_flag2 |= P2_WXORX_ENABLE_EXEC;
899 wxmap_status(struct thread *td, struct proc *p, void *data)
905 if ((p->p_flag & P_WEXIT) != 0)
909 if ((p->p_flag2 & P2_WXORX_DISABLE) != 0)
911 if ((p->p_flag2 & P2_WXORX_ENABLE_EXEC) != 0)
917 if ((vm->vm_map.flags & MAP_WXORX) != 0)
928 pdeathsig_ctl(struct thread *td, struct proc *p, void *data)
933 if (p != td->td_proc || (signum != 0 && !_SIG_VALID(signum)))
935 p->p_pdeathsig = signum;
940 pdeathsig_status(struct thread *td, struct proc *p, void *data)
942 if (p != td->td_proc)
944 *(int *)data = p->p_pdeathsig;
949 logsigexit_ctl(struct thread *td, struct proc *p, void *data)
958 p->p_flag2 &= ~(P2_LOGSIGEXIT_CTL | P2_LOGSIGEXIT_ENABLE);
961 p->p_flag2 |= P2_LOGSIGEXIT_CTL | P2_LOGSIGEXIT_ENABLE;
964 p->p_flag2 |= P2_LOGSIGEXIT_CTL;
965 p->p_flag2 &= ~P2_LOGSIGEXIT_ENABLE;
974 logsigexit_status(struct thread *td, struct proc *p, void *data)
978 if ((p->p_flag2 & P2_LOGSIGEXIT_CTL) == 0)
980 else if ((p->p_flag2 & P2_LOGSIGEXIT_ENABLE) != 0)
1003 int (*exec)(struct thread *, struct proc *, void *);
1169 if (uap->com >= PROC_PROCCTL_MD_MIN)
1170 return (cpu_procctl(td, uap->idtype, uap->id,
1171 uap->com, uap->data));
1172 if (uap->com <= 0 || uap->com >= nitems(procctl_cmds_info))
1174 cmd_info = &procctl_cmds_info[uap->com];
1177 if (cmd_info->copyin_sz > 0) {
1178 error = copyin(uap->data, &x, cmd_info->copyin_sz);
1181 } else if (cmd_info->no_nonnull_data && uap->data != NULL) {
1185 error = kern_procctl(td, uap->idtype, uap->id, uap->com, &x);
1187 if (cmd_info->copyout_sz > 0 && (error == 0 ||
1188 cmd_info->copyout_on_error)) {
1189 error1 = copyout(&x, uap->data, cmd_info->copyout_sz);
1197 kern_procctl_single(struct thread *td, struct proc *p, int com, void *data)
1205 kern_procctl(struct thread *td, idtype_t idtype, id_t id, int com, void *data)
1208 struct proc *p;
1215 if (idtype != P_PID && cmd_info->one_proc)
1219 if (cmd_info->sapblk != NULL) {
1220 sapblk = cmd_info->sapblk(td, data);
1225 switch (cmd_info->lock_tree) {
1238 if (id == 0) {
1239 p = td->td_proc;
1243 p = pfind(id);
1245 error = cmd_info->esrch_is_einval ?
1249 error = cmd_info->need_candebug ? p_candebug(td, p) :
1263 pg = pgfind(id);
1271 LIST_FOREACH(p, &pg->pg_members, p_pglist) {
1273 if (p->p_state == PRS_NEW ||
1274 p->p_state == PRS_ZOMBIE ||
1275 (cmd_info->need_candebug ? p_candebug(td, p) :
1303 switch (cmd_info->lock_tree) {