2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright (c) 1982, 1986, 1989, 1991, 1993
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * @(#)kern_proc.c 8.7 (Berkeley) 2/14/95
34 #include <sys/cdefs.h>
35 __FBSDID("$FreeBSD$");
38 #include "opt_ktrace.h"
39 #include "opt_kstack_pages.h"
40 #include "opt_stack.h"
42 #include <sys/param.h>
43 #include <sys/systm.h>
44 #include <sys/bitstring.h>
46 #include <sys/eventhandler.h>
49 #include <sys/kernel.h>
50 #include <sys/limits.h>
52 #include <sys/loginclass.h>
53 #include <sys/malloc.h>
55 #include <sys/mount.h>
56 #include <sys/mutex.h>
58 #include <sys/ptrace.h>
59 #include <sys/refcount.h>
60 #include <sys/resourcevar.h>
61 #include <sys/rwlock.h>
63 #include <sys/sysent.h>
64 #include <sys/sched.h>
66 #include <sys/stack.h>
68 #include <sys/dtrace_bsd.h>
69 #include <sys/sysctl.h>
70 #include <sys/filedesc.h>
72 #include <sys/signalvar.h>
76 #include <sys/vnode.h>
79 #include <sys/ktrace.h>
87 #include <vm/vm_param.h>
88 #include <vm/vm_extern.h>
90 #include <vm/vm_map.h>
91 #include <vm/vm_object.h>
92 #include <vm/vm_page.h>
95 #include <fs/devfs/devfs.h>
97 #ifdef COMPAT_FREEBSD32
98 #include <compat/freebsd32/freebsd32.h>
99 #include <compat/freebsd32/freebsd32_util.h>
102 SDT_PROVIDER_DEFINE(proc);
104 MALLOC_DEFINE(M_SESSION, "session", "session header");
105 static MALLOC_DEFINE(M_PROC, "proc", "Proc structures");
106 MALLOC_DEFINE(M_SUBPROC, "subproc", "Proc sub-structures");
108 static void doenterpgrp(struct proc *, struct pgrp *);
109 static void orphanpg(struct pgrp *pg);
110 static void fill_kinfo_aggregate(struct proc *p, struct kinfo_proc *kp);
111 static void fill_kinfo_proc_only(struct proc *p, struct kinfo_proc *kp);
112 static void fill_kinfo_thread(struct thread *td, struct kinfo_proc *kp,
114 static void pgdelete(struct pgrp *);
115 static int pgrp_init(void *mem, int size, int flags);
116 static int proc_ctor(void *mem, int size, void *arg, int flags);
117 static void proc_dtor(void *mem, int size, void *arg);
118 static int proc_init(void *mem, int size, int flags);
119 static void proc_fini(void *mem, int size);
120 static void pargs_free(struct pargs *pa);
123 * Other process lists
125 struct pidhashhead *pidhashtbl;
126 struct sx *pidhashtbl_lock;
129 struct pgrphashhead *pgrphashtbl;
131 struct proclist allproc;
132 struct sx __exclusive_cache_line allproc_lock;
133 struct sx __exclusive_cache_line proctree_lock;
134 struct mtx __exclusive_cache_line ppeers_lock;
135 struct mtx __exclusive_cache_line procid_lock;
136 uma_zone_t proc_zone;
137 uma_zone_t pgrp_zone;
140 * The offset of various fields in struct proc and struct thread.
141 * These are used by kernel debuggers to enumerate kernel threads and
144 const int proc_off_p_pid = offsetof(struct proc, p_pid);
145 const int proc_off_p_comm = offsetof(struct proc, p_comm);
146 const int proc_off_p_list = offsetof(struct proc, p_list);
147 const int proc_off_p_hash = offsetof(struct proc, p_hash);
148 const int proc_off_p_threads = offsetof(struct proc, p_threads);
149 const int thread_off_td_tid = offsetof(struct thread, td_tid);
150 const int thread_off_td_name = offsetof(struct thread, td_name);
151 const int thread_off_td_oncpu = offsetof(struct thread, td_oncpu);
152 const int thread_off_td_pcb = offsetof(struct thread, td_pcb);
153 const int thread_off_td_plist = offsetof(struct thread, td_plist);
155 EVENTHANDLER_LIST_DEFINE(process_ctor);
156 EVENTHANDLER_LIST_DEFINE(process_dtor);
157 EVENTHANDLER_LIST_DEFINE(process_init);
158 EVENTHANDLER_LIST_DEFINE(process_fini);
159 EVENTHANDLER_LIST_DEFINE(process_exit);
160 EVENTHANDLER_LIST_DEFINE(process_fork);
161 EVENTHANDLER_LIST_DEFINE(process_exec);
163 int kstack_pages = KSTACK_PAGES;
164 SYSCTL_INT(_kern, OID_AUTO, kstack_pages, CTLFLAG_RD, &kstack_pages, 0,
165 "Kernel stack size in pages");
166 static int vmmap_skip_res_cnt = 0;
167 SYSCTL_INT(_kern, OID_AUTO, proc_vmmap_skip_resident_count, CTLFLAG_RW,
168 &vmmap_skip_res_cnt, 0,
169 "Skip calculation of the pages resident count in kern.proc.vmmap");
171 CTASSERT(sizeof(struct kinfo_proc) == KINFO_PROC_SIZE);
172 #ifdef COMPAT_FREEBSD32
173 CTASSERT(sizeof(struct kinfo_proc32) == KINFO_PROC32_SIZE);
177 * Initialize global process hashing structures.
184 sx_init(&allproc_lock, "allproc");
185 sx_init(&proctree_lock, "proctree");
186 mtx_init(&ppeers_lock, "p_peers", NULL, MTX_DEF);
187 mtx_init(&procid_lock, "procid", NULL, MTX_DEF);
189 pidhashtbl = hashinit(maxproc / 4, M_PROC, &pidhash);
190 pidhashlock = (pidhash + 1) / 64;
193 pidhashtbl_lock = malloc(sizeof(*pidhashtbl_lock) * (pidhashlock + 1),
194 M_PROC, M_WAITOK | M_ZERO);
195 for (i = 0; i < pidhashlock + 1; i++)
196 sx_init_flags(&pidhashtbl_lock[i], "pidhash", SX_DUPOK);
197 pgrphashtbl = hashinit(maxproc / 4, M_PROC, &pgrphash);
198 proc_zone = uma_zcreate("PROC", sched_sizeof_proc(),
199 proc_ctor, proc_dtor, proc_init, proc_fini,
200 UMA_ALIGN_PTR, UMA_ZONE_NOFREE);
201 pgrp_zone = uma_zcreate("PGRP", sizeof(struct pgrp), NULL, NULL,
202 pgrp_init, NULL, UMA_ALIGN_PTR, UMA_ZONE_NOFREE);
207 * Prepare a proc for use.
210 proc_ctor(void *mem, int size, void *arg, int flags)
215 p = (struct proc *)mem;
217 kdtrace_proc_ctor(p);
219 EVENTHANDLER_DIRECT_INVOKE(process_ctor, p);
220 td = FIRST_THREAD_IN_PROC(p);
222 /* Make sure all thread constructors are executed */
223 EVENTHANDLER_DIRECT_INVOKE(thread_ctor, td);
229 * Reclaim a proc after use.
232 proc_dtor(void *mem, int size, void *arg)
237 /* INVARIANTS checks go here */
238 p = (struct proc *)mem;
239 td = FIRST_THREAD_IN_PROC(p);
242 KASSERT((p->p_numthreads == 1),
243 ("bad number of threads in exiting process"));
244 KASSERT(STAILQ_EMPTY(&p->p_ktr), ("proc_dtor: non-empty p_ktr"));
246 /* Free all OSD associated to this thread. */
248 td_softdep_cleanup(td);
249 MPASS(td->td_su == NULL);
251 /* Make sure all thread destructors are executed */
252 EVENTHANDLER_DIRECT_INVOKE(thread_dtor, td);
254 EVENTHANDLER_DIRECT_INVOKE(process_dtor, p);
256 kdtrace_proc_dtor(p);
258 if (p->p_ksi != NULL)
259 KASSERT(! KSI_ONQ(p->p_ksi), ("SIGCHLD queue"));
263 * Initialize type-stable parts of a proc (when newly created).
266 proc_init(void *mem, int size, int flags)
270 p = (struct proc *)mem;
271 mtx_init(&p->p_mtx, "process lock", NULL, MTX_DEF | MTX_DUPOK | MTX_NEW);
272 mtx_init(&p->p_slock, "process slock", NULL, MTX_SPIN | MTX_NEW);
273 mtx_init(&p->p_statmtx, "pstatl", NULL, MTX_SPIN | MTX_NEW);
274 mtx_init(&p->p_itimmtx, "pitiml", NULL, MTX_SPIN | MTX_NEW);
275 mtx_init(&p->p_profmtx, "pprofl", NULL, MTX_SPIN | MTX_NEW);
276 cv_init(&p->p_pwait, "ppwait");
277 TAILQ_INIT(&p->p_threads); /* all threads in proc */
278 EVENTHANDLER_DIRECT_INVOKE(process_init, p);
279 p->p_stats = pstats_alloc();
285 * UMA should ensure that this function is never called.
286 * Freeing a proc structure would violate type stability.
289 proc_fini(void *mem, int size)
294 p = (struct proc *)mem;
295 EVENTHANDLER_DIRECT_INVOKE(process_fini, p);
296 pstats_free(p->p_stats);
297 thread_free(FIRST_THREAD_IN_PROC(p));
298 mtx_destroy(&p->p_mtx);
299 if (p->p_ksi != NULL)
300 ksiginfo_free(p->p_ksi);
302 panic("proc reclaimed");
307 pgrp_init(void *mem, int size, int flags)
312 mtx_init(&pg->pg_mtx, "process group", NULL, MTX_DEF | MTX_DUPOK);
317 * PID space management.
319 * These bitmaps are used by fork_findpid.
321 bitstr_t bit_decl(proc_id_pidmap, PID_MAX);
322 bitstr_t bit_decl(proc_id_grpidmap, PID_MAX);
323 bitstr_t bit_decl(proc_id_sessidmap, PID_MAX);
324 bitstr_t bit_decl(proc_id_reapmap, PID_MAX);
326 static bitstr_t *proc_id_array[] = {
334 proc_id_set(int type, pid_t id)
337 KASSERT(type >= 0 && type < nitems(proc_id_array),
338 ("invalid type %d\n", type));
339 mtx_lock(&procid_lock);
340 KASSERT(bit_test(proc_id_array[type], id) == 0,
341 ("bit %d already set in %d\n", id, type));
342 bit_set(proc_id_array[type], id);
343 mtx_unlock(&procid_lock);
347 proc_id_set_cond(int type, pid_t id)
350 KASSERT(type >= 0 && type < nitems(proc_id_array),
351 ("invalid type %d\n", type));
352 if (bit_test(proc_id_array[type], id))
354 mtx_lock(&procid_lock);
355 bit_set(proc_id_array[type], id);
356 mtx_unlock(&procid_lock);
360 proc_id_clear(int type, pid_t id)
363 KASSERT(type >= 0 && type < nitems(proc_id_array),
364 ("invalid type %d\n", type));
365 mtx_lock(&procid_lock);
366 KASSERT(bit_test(proc_id_array[type], id) != 0,
367 ("bit %d not set in %d\n", id, type));
368 bit_clear(proc_id_array[type], id);
369 mtx_unlock(&procid_lock);
373 * Is p an inferior of the current process?
376 inferior(struct proc *p)
379 sx_assert(&proctree_lock, SX_LOCKED);
380 PROC_LOCK_ASSERT(p, MA_OWNED);
381 for (; p != curproc; p = proc_realparent(p)) {
389 * Shared lock all the pid hash lists.
392 pidhash_slockall(void)
396 for (i = 0; i < pidhashlock + 1; i++)
397 sx_slock(&pidhashtbl_lock[i]);
401 * Shared unlock all the pid hash lists.
404 pidhash_sunlockall(void)
408 for (i = 0; i < pidhashlock + 1; i++)
409 sx_sunlock(&pidhashtbl_lock[i]);
413 * Similar to pfind_any(), this function finds zombies.
416 pfind_any_locked(pid_t pid)
420 sx_assert(PIDHASHLOCK(pid), SX_LOCKED);
421 LIST_FOREACH(p, PIDHASH(pid), p_hash) {
422 if (p->p_pid == pid) {
424 if (p->p_state == PRS_NEW) {
435 * Locate a process by number.
437 * By not returning processes in the PRS_NEW state, we allow callers to avoid
438 * testing for that condition to avoid dereferencing p_ucred, et al.
440 static __always_inline struct proc *
441 _pfind(pid_t pid, bool zombie)
446 if (p->p_pid == pid) {
450 sx_slock(PIDHASHLOCK(pid));
451 LIST_FOREACH(p, PIDHASH(pid), p_hash) {
452 if (p->p_pid == pid) {
454 if (p->p_state == PRS_NEW ||
455 (!zombie && p->p_state == PRS_ZOMBIE)) {
462 sx_sunlock(PIDHASHLOCK(pid));
470 return (_pfind(pid, false));
474 * Same as pfind but allow zombies.
480 return (_pfind(pid, true));
484 * Locate a process group by number.
485 * The caller must hold proctree_lock.
492 sx_assert(&proctree_lock, SX_LOCKED);
494 LIST_FOREACH(pgrp, PGRPHASH(pgid), pg_hash) {
495 if (pgrp->pg_id == pgid) {
504 * Locate process and do additional manipulations, depending on flags.
507 pget(pid_t pid, int flags, struct proc **pp)
514 if (p->p_pid == pid) {
518 if (pid <= PID_MAX) {
519 if ((flags & PGET_NOTWEXIT) == 0)
523 } else if ((flags & PGET_NOTID) == 0) {
524 td1 = tdfind(pid, -1);
530 if ((flags & PGET_CANSEE) != 0) {
531 error = p_cansee(curthread, p);
536 if ((flags & PGET_CANDEBUG) != 0) {
537 error = p_candebug(curthread, p);
541 if ((flags & PGET_ISCURRENT) != 0 && curproc != p) {
545 if ((flags & PGET_NOTWEXIT) != 0 && (p->p_flag & P_WEXIT) != 0) {
549 if ((flags & PGET_NOTINEXEC) != 0 && (p->p_flag & P_INEXEC) != 0) {
551 * XXXRW: Not clear ESRCH is the right error during proc
557 if ((flags & PGET_HOLD) != 0) {
569 * Create a new process group.
570 * pgid must be equal to the pid of p.
571 * Begin a new session if required.
574 enterpgrp(struct proc *p, pid_t pgid, struct pgrp *pgrp, struct session *sess)
577 sx_assert(&proctree_lock, SX_XLOCKED);
579 KASSERT(pgrp != NULL, ("enterpgrp: pgrp == NULL"));
580 KASSERT(p->p_pid == pgid,
581 ("enterpgrp: new pgrp and pid != pgid"));
582 KASSERT(pgfind(pgid) == NULL,
583 ("enterpgrp: pgrp with pgid exists"));
584 KASSERT(!SESS_LEADER(p),
585 ("enterpgrp: session leader attempted setpgrp"));
591 mtx_init(&sess->s_mtx, "session", NULL, MTX_DEF);
593 p->p_flag &= ~P_CONTROLT;
597 sess->s_sid = p->p_pid;
598 proc_id_set(PROC_ID_SESSION, p->p_pid);
599 refcount_init(&sess->s_count, 1);
600 sess->s_ttyvp = NULL;
601 sess->s_ttydp = NULL;
603 bcopy(p->p_session->s_login, sess->s_login,
604 sizeof(sess->s_login));
605 pgrp->pg_session = sess;
606 KASSERT(p == curproc,
607 ("enterpgrp: mksession and p != curproc"));
609 pgrp->pg_session = p->p_session;
610 sess_hold(pgrp->pg_session);
614 proc_id_set(PROC_ID_GROUP, p->p_pid);
615 LIST_INIT(&pgrp->pg_members);
619 * As we have an exclusive lock of proctree_lock,
620 * this should not deadlock.
622 LIST_INSERT_HEAD(PGRPHASH(pgid), pgrp, pg_hash);
623 SLIST_INIT(&pgrp->pg_sigiolst);
626 doenterpgrp(p, pgrp);
632 * Move p to an existing process group
635 enterthispgrp(struct proc *p, struct pgrp *pgrp)
638 sx_assert(&proctree_lock, SX_XLOCKED);
639 PROC_LOCK_ASSERT(p, MA_NOTOWNED);
640 PGRP_LOCK_ASSERT(pgrp, MA_NOTOWNED);
641 PGRP_LOCK_ASSERT(p->p_pgrp, MA_NOTOWNED);
642 SESS_LOCK_ASSERT(p->p_session, MA_NOTOWNED);
643 KASSERT(pgrp->pg_session == p->p_session,
644 ("%s: pgrp's session %p, p->p_session %p proc %p\n",
645 __func__, pgrp->pg_session, p->p_session, p));
646 KASSERT(pgrp != p->p_pgrp,
647 ("%s: p %p belongs to pgrp %p", __func__, p, pgrp));
649 doenterpgrp(p, pgrp);
655 * If true, any child of q which belongs to group pgrp, qualifies the
656 * process group pgrp as not orphaned.
659 isjobproc(struct proc *q, struct pgrp *pgrp)
661 sx_assert(&proctree_lock, SX_LOCKED);
663 return (q->p_pgrp != pgrp &&
664 q->p_pgrp->pg_session == pgrp->pg_session);
668 jobc_reaper(struct proc *p)
672 sx_assert(&proctree_lock, SA_LOCKED);
676 if (pp->p_reaper == pp ||
677 (pp->p_treeflag & P_TREE_GRPEXITED) == 0)
683 jobc_parent(struct proc *p, struct proc *p_exiting)
687 sx_assert(&proctree_lock, SA_LOCKED);
689 pp = proc_realparent(p);
690 if (pp->p_pptr == NULL || pp == p_exiting ||
691 (pp->p_treeflag & P_TREE_GRPEXITED) == 0)
693 return (jobc_reaper(pp));
697 pgrp_calc_jobc(struct pgrp *pgrp)
703 if (!mtx_owned(&pgrp->pg_mtx))
704 sx_assert(&proctree_lock, SA_LOCKED);
708 LIST_FOREACH(q, &pgrp->pg_members, p_pglist) {
709 if ((q->p_treeflag & P_TREE_GRPEXITED) != 0 ||
712 if (isjobproc(jobc_parent(q, NULL), pgrp))
719 * Move p to a process group
722 doenterpgrp(struct proc *p, struct pgrp *pgrp)
724 struct pgrp *savepgrp;
727 sx_assert(&proctree_lock, SX_XLOCKED);
728 PROC_LOCK_ASSERT(p, MA_NOTOWNED);
729 PGRP_LOCK_ASSERT(pgrp, MA_NOTOWNED);
730 PGRP_LOCK_ASSERT(p->p_pgrp, MA_NOTOWNED);
731 SESS_LOCK_ASSERT(p->p_session, MA_NOTOWNED);
733 savepgrp = p->p_pgrp;
734 pp = jobc_parent(p, NULL);
738 if (isjobproc(pp, savepgrp) && pgrp_calc_jobc(savepgrp) == 1)
741 LIST_REMOVE(p, p_pglist);
744 LIST_INSERT_HEAD(&pgrp->pg_members, p, p_pglist);
745 if (isjobproc(pp, pgrp))
746 pgrp->pg_flags &= ~PGRP_ORPHANED;
747 PGRP_UNLOCK(savepgrp);
749 if (LIST_EMPTY(&savepgrp->pg_members))
754 * remove process from process group
757 leavepgrp(struct proc *p)
759 struct pgrp *savepgrp;
761 sx_assert(&proctree_lock, SX_XLOCKED);
762 savepgrp = p->p_pgrp;
765 LIST_REMOVE(p, p_pglist);
768 PGRP_UNLOCK(savepgrp);
769 if (LIST_EMPTY(&savepgrp->pg_members))
775 * delete a process group
778 pgdelete(struct pgrp *pgrp)
780 struct session *savesess;
783 sx_assert(&proctree_lock, SX_XLOCKED);
784 PGRP_LOCK_ASSERT(pgrp, MA_NOTOWNED);
785 SESS_LOCK_ASSERT(pgrp->pg_session, MA_NOTOWNED);
788 * Reset any sigio structures pointing to us as a result of
789 * F_SETOWN with our pgid. The proctree lock ensures that
790 * new sigio structures will not be added after this point.
792 funsetownlst(&pgrp->pg_sigiolst);
795 tp = pgrp->pg_session->s_ttyp;
796 LIST_REMOVE(pgrp, pg_hash);
797 savesess = pgrp->pg_session;
800 /* Remove the reference to the pgrp before deallocating it. */
803 tty_rel_pgrp(tp, pgrp);
806 proc_id_clear(PROC_ID_GROUP, pgrp->pg_id);
807 uma_zfree(pgrp_zone, pgrp);
808 sess_release(savesess);
813 fixjobc_kill(struct proc *p)
818 sx_assert(&proctree_lock, SX_LOCKED);
819 PROC_LOCK_ASSERT(p, MA_NOTOWNED);
821 PGRP_LOCK_ASSERT(pgrp, MA_NOTOWNED);
822 SESS_LOCK_ASSERT(pgrp->pg_session, MA_NOTOWNED);
825 * p no longer affects process group orphanage for children.
826 * It is marked by the flag because p is only physically
827 * removed from its process group on wait(2).
829 MPASS((p->p_treeflag & P_TREE_GRPEXITED) == 0);
830 p->p_treeflag |= P_TREE_GRPEXITED;
833 * Check if exiting p orphans its own group.
836 if (isjobproc(jobc_parent(p, NULL), pgrp)) {
838 if (pgrp_calc_jobc(pgrp) == 0)
844 * Check this process' children to see whether they qualify
845 * their process groups after reparenting to reaper.
847 LIST_FOREACH(q, &p->p_children, p_sibling) {
850 if (pgrp_calc_jobc(pgrp) == 0) {
852 * We want to handle exactly the children that
853 * has p as realparent. Then, when calculating
854 * jobc_parent for children, we should ignore
855 * P_TREE_GRPEXITED flag already set on p.
857 if (jobc_parent(q, p) == p && isjobproc(p, pgrp))
860 pgrp->pg_flags &= ~PGRP_ORPHANED;
863 LIST_FOREACH(q, &p->p_orphans, p_orphan) {
866 if (pgrp_calc_jobc(pgrp) == 0) {
867 if (isjobproc(p, pgrp))
870 pgrp->pg_flags &= ~PGRP_ORPHANED;
884 MPASS(p->p_flag & P_WEXIT);
885 sx_assert(&proctree_lock, SX_LOCKED);
887 if (SESS_LEADER(p)) {
891 * s_ttyp is not zero'd; we use this to indicate that
892 * the session once had a controlling terminal. (for
893 * logging and informational purposes)
904 * Signal foreground pgrp and revoke access to
905 * controlling terminal if it has not been revoked
908 * Because the TTY may have been revoked in the mean
909 * time and could already have a new session associated
910 * with it, make sure we don't send a SIGHUP to a
911 * foreground process group that does not belong to this
917 if (tp->t_session == sp)
918 tty_signal_pgrp(tp, SIGHUP);
923 sx_xunlock(&proctree_lock);
924 if (vn_lock(ttyvp, LK_EXCLUSIVE) == 0) {
925 VOP_REVOKE(ttyvp, REVOKEALL);
928 devfs_ctty_unref(ttyvp);
929 sx_xlock(&proctree_lock);
936 * A process group has become orphaned, mark it as such for signal
937 * delivery code. If there are any stopped processes in the group,
938 * hang-up all process in that group.
941 orphanpg(struct pgrp *pg)
945 PGRP_LOCK_ASSERT(pg, MA_OWNED);
947 pg->pg_flags |= PGRP_ORPHANED;
949 LIST_FOREACH(p, &pg->pg_members, p_pglist) {
951 if (P_SHOULDSTOP(p) == P_STOPPED_SIG) {
953 LIST_FOREACH(p, &pg->pg_members, p_pglist) {
955 kern_psignal(p, SIGHUP);
956 kern_psignal(p, SIGCONT);
966 sess_hold(struct session *s)
969 refcount_acquire(&s->s_count);
973 sess_release(struct session *s)
976 if (refcount_release(&s->s_count)) {
977 if (s->s_ttyp != NULL) {
979 tty_rel_sess(s->s_ttyp, s);
981 proc_id_clear(PROC_ID_SESSION, s->s_sid);
982 mtx_destroy(&s->s_mtx);
990 db_print_pgrp_one(struct pgrp *pgrp, struct proc *p)
993 " pid %d at %p pr %d pgrp %p e %d jc %d\n",
994 p->p_pid, p, p->p_pptr == NULL ? -1 : p->p_pptr->p_pid,
995 p->p_pgrp, (p->p_treeflag & P_TREE_GRPEXITED) != 0,
996 p->p_pptr == NULL ? 0 : isjobproc(p->p_pptr, pgrp));
999 DB_SHOW_COMMAND(pgrpdump, pgrpdump)
1005 for (i = 0; i <= pgrphash; i++) {
1006 if (!LIST_EMPTY(&pgrphashtbl[i])) {
1007 db_printf("indx %d\n", i);
1008 LIST_FOREACH(pgrp, &pgrphashtbl[i], pg_hash) {
1010 " pgrp %p, pgid %d, sess %p, sesscnt %d, mem %p\n",
1011 pgrp, (int)pgrp->pg_id, pgrp->pg_session,
1012 pgrp->pg_session->s_count,
1013 LIST_FIRST(&pgrp->pg_members));
1014 LIST_FOREACH(p, &pgrp->pg_members, p_pglist)
1015 db_print_pgrp_one(pgrp, p);
1023 * Calculate the kinfo_proc members which contain process-wide
1025 * Must be called with the target process locked.
1028 fill_kinfo_aggregate(struct proc *p, struct kinfo_proc *kp)
1032 PROC_LOCK_ASSERT(p, MA_OWNED);
1036 FOREACH_THREAD_IN_PROC(p, td) {
1038 kp->ki_pctcpu += sched_pctcpu(td);
1039 kp->ki_estcpu += sched_estcpu(td);
1045 * Fill in any information that is common to all threads in the process.
1046 * Must be called with the target process locked.
1049 fill_kinfo_proc_only(struct proc *p, struct kinfo_proc *kp)
1054 struct timeval boottime;
1056 PROC_LOCK_ASSERT(p, MA_OWNED);
1058 kp->ki_structsize = sizeof(*kp);
1060 kp->ki_addr =/* p->p_addr; */0; /* XXX */
1061 kp->ki_args = p->p_args;
1062 kp->ki_textvp = p->p_textvp;
1064 kp->ki_tracep = ktr_get_tracevp(p, false);
1065 kp->ki_traceflag = p->p_traceflag;
1067 kp->ki_fd = p->p_fd;
1068 kp->ki_pd = p->p_pd;
1069 kp->ki_vmspace = p->p_vmspace;
1070 kp->ki_flag = p->p_flag;
1071 kp->ki_flag2 = p->p_flag2;
1074 kp->ki_uid = cred->cr_uid;
1075 kp->ki_ruid = cred->cr_ruid;
1076 kp->ki_svuid = cred->cr_svuid;
1077 kp->ki_cr_flags = 0;
1078 if (cred->cr_flags & CRED_FLAG_CAPMODE)
1079 kp->ki_cr_flags |= KI_CRF_CAPABILITY_MODE;
1080 /* XXX bde doesn't like KI_NGROUPS */
1081 if (cred->cr_ngroups > KI_NGROUPS) {
1082 kp->ki_ngroups = KI_NGROUPS;
1083 kp->ki_cr_flags |= KI_CRF_GRP_OVERFLOW;
1085 kp->ki_ngroups = cred->cr_ngroups;
1086 bcopy(cred->cr_groups, kp->ki_groups,
1087 kp->ki_ngroups * sizeof(gid_t));
1088 kp->ki_rgid = cred->cr_rgid;
1089 kp->ki_svgid = cred->cr_svgid;
1090 /* If jailed(cred), emulate the old P_JAILED flag. */
1092 kp->ki_flag |= P_JAILED;
1093 /* If inside the jail, use 0 as a jail ID. */
1094 if (cred->cr_prison != curthread->td_ucred->cr_prison)
1095 kp->ki_jid = cred->cr_prison->pr_id;
1097 strlcpy(kp->ki_loginclass, cred->cr_loginclass->lc_name,
1098 sizeof(kp->ki_loginclass));
1102 mtx_lock(&ps->ps_mtx);
1103 kp->ki_sigignore = ps->ps_sigignore;
1104 kp->ki_sigcatch = ps->ps_sigcatch;
1105 mtx_unlock(&ps->ps_mtx);
1107 if (p->p_state != PRS_NEW &&
1108 p->p_state != PRS_ZOMBIE &&
1109 p->p_vmspace != NULL) {
1110 struct vmspace *vm = p->p_vmspace;
1112 kp->ki_size = vm->vm_map.size;
1113 kp->ki_rssize = vmspace_resident_count(vm); /*XXX*/
1114 FOREACH_THREAD_IN_PROC(p, td0) {
1115 if (!TD_IS_SWAPPED(td0))
1116 kp->ki_rssize += td0->td_kstack_pages;
1118 kp->ki_swrss = vm->vm_swrss;
1119 kp->ki_tsize = vm->vm_tsize;
1120 kp->ki_dsize = vm->vm_dsize;
1121 kp->ki_ssize = vm->vm_ssize;
1122 } else if (p->p_state == PRS_ZOMBIE)
1123 kp->ki_stat = SZOMB;
1124 if (kp->ki_flag & P_INMEM)
1125 kp->ki_sflag = PS_INMEM;
1128 /* Calculate legacy swtime as seconds since 'swtick'. */
1129 kp->ki_swtime = (ticks - p->p_swtick) / hz;
1130 kp->ki_pid = p->p_pid;
1131 kp->ki_nice = p->p_nice;
1132 kp->ki_fibnum = p->p_fibnum;
1133 kp->ki_start = p->p_stats->p_start;
1134 getboottime(&boottime);
1135 timevaladd(&kp->ki_start, &boottime);
1137 rufetch(p, &kp->ki_rusage);
1138 kp->ki_runtime = cputick2usec(p->p_rux.rux_runtime);
1139 calcru(p, &kp->ki_rusage.ru_utime, &kp->ki_rusage.ru_stime);
1141 calccru(p, &kp->ki_childutime, &kp->ki_childstime);
1142 /* Some callers want child times in a single value. */
1143 kp->ki_childtime = kp->ki_childstime;
1144 timevaladd(&kp->ki_childtime, &kp->ki_childutime);
1146 FOREACH_THREAD_IN_PROC(p, td0)
1147 kp->ki_cow += td0->td_cow;
1149 if (p->p_comm[0] != '\0')
1150 strlcpy(kp->ki_comm, p->p_comm, sizeof(kp->ki_comm));
1151 if (p->p_sysent && p->p_sysent->sv_name != NULL &&
1152 p->p_sysent->sv_name[0] != '\0')
1153 strlcpy(kp->ki_emul, p->p_sysent->sv_name, sizeof(kp->ki_emul));
1154 kp->ki_siglist = p->p_siglist;
1155 kp->ki_xstat = KW_EXITCODE(p->p_xexit, p->p_xsig);
1156 kp->ki_acflag = p->p_acflag;
1157 kp->ki_lock = p->p_lock;
1159 kp->ki_ppid = p->p_oppid;
1160 if (p->p_flag & P_TRACED)
1161 kp->ki_tracer = p->p_pptr->p_pid;
1166 * Fill job-related process information.
1169 fill_kinfo_proc_pgrp(struct proc *p, struct kinfo_proc *kp)
1175 sx_assert(&proctree_lock, SA_LOCKED);
1176 PROC_LOCK_ASSERT(p, MA_OWNED);
1182 kp->ki_pgid = pgrp->pg_id;
1183 kp->ki_jobc = pgrp_calc_jobc(pgrp);
1185 sp = pgrp->pg_session;
1189 kp->ki_sid = sp->s_sid;
1191 strlcpy(kp->ki_login, sp->s_login, sizeof(kp->ki_login));
1193 kp->ki_kiflag |= KI_CTTY;
1195 kp->ki_kiflag |= KI_SLEADER;
1200 if ((p->p_flag & P_CONTROLT) && tp != NULL) {
1201 kp->ki_tdev = tty_udev(tp);
1202 kp->ki_tdev_freebsd11 = kp->ki_tdev; /* truncate */
1203 kp->ki_tpgid = tp->t_pgrp ? tp->t_pgrp->pg_id : NO_PID;
1205 kp->ki_tsid = tp->t_session->s_sid;
1207 kp->ki_tdev = NODEV;
1208 kp->ki_tdev_freebsd11 = kp->ki_tdev; /* truncate */
1213 * Fill in information that is thread specific. Must be called with
1214 * target process locked. If 'preferthread' is set, overwrite certain
1215 * process-related fields that are maintained for both threads and
1219 fill_kinfo_thread(struct thread *td, struct kinfo_proc *kp, int preferthread)
1225 PROC_LOCK_ASSERT(p, MA_OWNED);
1230 if (td->td_wmesg != NULL)
1231 strlcpy(kp->ki_wmesg, td->td_wmesg, sizeof(kp->ki_wmesg));
1233 bzero(kp->ki_wmesg, sizeof(kp->ki_wmesg));
1234 if (strlcpy(kp->ki_tdname, td->td_name, sizeof(kp->ki_tdname)) >=
1235 sizeof(kp->ki_tdname)) {
1236 strlcpy(kp->ki_moretdname,
1237 td->td_name + sizeof(kp->ki_tdname) - 1,
1238 sizeof(kp->ki_moretdname));
1240 bzero(kp->ki_moretdname, sizeof(kp->ki_moretdname));
1242 if (TD_ON_LOCK(td)) {
1243 kp->ki_kiflag |= KI_LOCKBLOCK;
1244 strlcpy(kp->ki_lockname, td->td_lockname,
1245 sizeof(kp->ki_lockname));
1247 kp->ki_kiflag &= ~KI_LOCKBLOCK;
1248 bzero(kp->ki_lockname, sizeof(kp->ki_lockname));
1251 if (p->p_state == PRS_NORMAL) { /* approximate. */
1252 if (TD_ON_RUNQ(td) ||
1254 TD_IS_RUNNING(td)) {
1256 } else if (P_SHOULDSTOP(p)) {
1257 kp->ki_stat = SSTOP;
1258 } else if (TD_IS_SLEEPING(td)) {
1259 kp->ki_stat = SSLEEP;
1260 } else if (TD_ON_LOCK(td)) {
1261 kp->ki_stat = SLOCK;
1263 kp->ki_stat = SWAIT;
1265 } else if (p->p_state == PRS_ZOMBIE) {
1266 kp->ki_stat = SZOMB;
1271 /* Things in the thread */
1272 kp->ki_wchan = td->td_wchan;
1273 kp->ki_pri.pri_level = td->td_priority;
1274 kp->ki_pri.pri_native = td->td_base_pri;
1277 * Note: legacy fields; clamp at the old NOCPU value and/or
1278 * the maximum u_char CPU value.
1280 if (td->td_lastcpu == NOCPU)
1281 kp->ki_lastcpu_old = NOCPU_OLD;
1282 else if (td->td_lastcpu > MAXCPU_OLD)
1283 kp->ki_lastcpu_old = MAXCPU_OLD;
1285 kp->ki_lastcpu_old = td->td_lastcpu;
1287 if (td->td_oncpu == NOCPU)
1288 kp->ki_oncpu_old = NOCPU_OLD;
1289 else if (td->td_oncpu > MAXCPU_OLD)
1290 kp->ki_oncpu_old = MAXCPU_OLD;
1292 kp->ki_oncpu_old = td->td_oncpu;
1294 kp->ki_lastcpu = td->td_lastcpu;
1295 kp->ki_oncpu = td->td_oncpu;
1296 kp->ki_tdflags = td->td_flags;
1297 kp->ki_tid = td->td_tid;
1298 kp->ki_numthreads = p->p_numthreads;
1299 kp->ki_pcb = td->td_pcb;
1300 kp->ki_kstack = (void *)td->td_kstack;
1301 kp->ki_slptime = (ticks - td->td_slptick) / hz;
1302 kp->ki_pri.pri_class = td->td_pri_class;
1303 kp->ki_pri.pri_user = td->td_user_pri;
1306 rufetchtd(td, &kp->ki_rusage);
1307 kp->ki_runtime = cputick2usec(td->td_rux.rux_runtime);
1308 kp->ki_pctcpu = sched_pctcpu(td);
1309 kp->ki_estcpu = sched_estcpu(td);
1310 kp->ki_cow = td->td_cow;
1313 /* We can't get this anymore but ps etc never used it anyway. */
1317 kp->ki_siglist = td->td_siglist;
1318 kp->ki_sigmask = td->td_sigmask;
1325 * Fill in a kinfo_proc structure for the specified process.
1326 * Must be called with the target process locked.
1329 fill_kinfo_proc(struct proc *p, struct kinfo_proc *kp)
1331 MPASS(FIRST_THREAD_IN_PROC(p) != NULL);
1333 bzero(kp, sizeof(*kp));
1335 fill_kinfo_proc_pgrp(p,kp);
1336 fill_kinfo_proc_only(p, kp);
1337 fill_kinfo_thread(FIRST_THREAD_IN_PROC(p), kp, 0);
1338 fill_kinfo_aggregate(p, kp);
1345 return (malloc(sizeof(struct pstats), M_SUBPROC, M_ZERO|M_WAITOK));
1349 * Copy parts of p_stats; zero the rest of p_stats (statistics).
1352 pstats_fork(struct pstats *src, struct pstats *dst)
1355 bzero(&dst->pstat_startzero,
1356 __rangeof(struct pstats, pstat_startzero, pstat_endzero));
1357 bcopy(&src->pstat_startcopy, &dst->pstat_startcopy,
1358 __rangeof(struct pstats, pstat_startcopy, pstat_endcopy));
1362 pstats_free(struct pstats *ps)
1365 free(ps, M_SUBPROC);
1368 #ifdef COMPAT_FREEBSD32
1371 * This function is typically used to copy out the kernel address, so
1372 * it can be replaced by assignment of zero.
1374 static inline uint32_t
1375 ptr32_trim(const void *ptr)
1379 uptr = (uintptr_t)ptr;
1380 return ((uptr > UINT_MAX) ? 0 : uptr);
1383 #define PTRTRIM_CP(src,dst,fld) \
1384 do { (dst).fld = ptr32_trim((src).fld); } while (0)
1387 freebsd32_kinfo_proc_out(const struct kinfo_proc *ki, struct kinfo_proc32 *ki32)
1391 bzero(ki32, sizeof(struct kinfo_proc32));
1392 ki32->ki_structsize = sizeof(struct kinfo_proc32);
1393 CP(*ki, *ki32, ki_layout);
1394 PTRTRIM_CP(*ki, *ki32, ki_args);
1395 PTRTRIM_CP(*ki, *ki32, ki_paddr);
1396 PTRTRIM_CP(*ki, *ki32, ki_addr);
1397 PTRTRIM_CP(*ki, *ki32, ki_tracep);
1398 PTRTRIM_CP(*ki, *ki32, ki_textvp);
1399 PTRTRIM_CP(*ki, *ki32, ki_fd);
1400 PTRTRIM_CP(*ki, *ki32, ki_vmspace);
1401 PTRTRIM_CP(*ki, *ki32, ki_wchan);
1402 CP(*ki, *ki32, ki_pid);
1403 CP(*ki, *ki32, ki_ppid);
1404 CP(*ki, *ki32, ki_pgid);
1405 CP(*ki, *ki32, ki_tpgid);
1406 CP(*ki, *ki32, ki_sid);
1407 CP(*ki, *ki32, ki_tsid);
1408 CP(*ki, *ki32, ki_jobc);
1409 CP(*ki, *ki32, ki_tdev);
1410 CP(*ki, *ki32, ki_tdev_freebsd11);
1411 CP(*ki, *ki32, ki_siglist);
1412 CP(*ki, *ki32, ki_sigmask);
1413 CP(*ki, *ki32, ki_sigignore);
1414 CP(*ki, *ki32, ki_sigcatch);
1415 CP(*ki, *ki32, ki_uid);
1416 CP(*ki, *ki32, ki_ruid);
1417 CP(*ki, *ki32, ki_svuid);
1418 CP(*ki, *ki32, ki_rgid);
1419 CP(*ki, *ki32, ki_svgid);
1420 CP(*ki, *ki32, ki_ngroups);
1421 for (i = 0; i < KI_NGROUPS; i++)
1422 CP(*ki, *ki32, ki_groups[i]);
1423 CP(*ki, *ki32, ki_size);
1424 CP(*ki, *ki32, ki_rssize);
1425 CP(*ki, *ki32, ki_swrss);
1426 CP(*ki, *ki32, ki_tsize);
1427 CP(*ki, *ki32, ki_dsize);
1428 CP(*ki, *ki32, ki_ssize);
1429 CP(*ki, *ki32, ki_xstat);
1430 CP(*ki, *ki32, ki_acflag);
1431 CP(*ki, *ki32, ki_pctcpu);
1432 CP(*ki, *ki32, ki_estcpu);
1433 CP(*ki, *ki32, ki_slptime);
1434 CP(*ki, *ki32, ki_swtime);
1435 CP(*ki, *ki32, ki_cow);
1436 CP(*ki, *ki32, ki_runtime);
1437 TV_CP(*ki, *ki32, ki_start);
1438 TV_CP(*ki, *ki32, ki_childtime);
1439 CP(*ki, *ki32, ki_flag);
1440 CP(*ki, *ki32, ki_kiflag);
1441 CP(*ki, *ki32, ki_traceflag);
1442 CP(*ki, *ki32, ki_stat);
1443 CP(*ki, *ki32, ki_nice);
1444 CP(*ki, *ki32, ki_lock);
1445 CP(*ki, *ki32, ki_rqindex);
1446 CP(*ki, *ki32, ki_oncpu);
1447 CP(*ki, *ki32, ki_lastcpu);
1449 /* XXX TODO: wrap cpu value as appropriate */
1450 CP(*ki, *ki32, ki_oncpu_old);
1451 CP(*ki, *ki32, ki_lastcpu_old);
1453 bcopy(ki->ki_tdname, ki32->ki_tdname, TDNAMLEN + 1);
1454 bcopy(ki->ki_wmesg, ki32->ki_wmesg, WMESGLEN + 1);
1455 bcopy(ki->ki_login, ki32->ki_login, LOGNAMELEN + 1);
1456 bcopy(ki->ki_lockname, ki32->ki_lockname, LOCKNAMELEN + 1);
1457 bcopy(ki->ki_comm, ki32->ki_comm, COMMLEN + 1);
1458 bcopy(ki->ki_emul, ki32->ki_emul, KI_EMULNAMELEN + 1);
1459 bcopy(ki->ki_loginclass, ki32->ki_loginclass, LOGINCLASSLEN + 1);
1460 bcopy(ki->ki_moretdname, ki32->ki_moretdname, MAXCOMLEN - TDNAMLEN + 1);
1461 CP(*ki, *ki32, ki_tracer);
1462 CP(*ki, *ki32, ki_flag2);
1463 CP(*ki, *ki32, ki_fibnum);
1464 CP(*ki, *ki32, ki_cr_flags);
1465 CP(*ki, *ki32, ki_jid);
1466 CP(*ki, *ki32, ki_numthreads);
1467 CP(*ki, *ki32, ki_tid);
1468 CP(*ki, *ki32, ki_pri);
1469 freebsd32_rusage_out(&ki->ki_rusage, &ki32->ki_rusage);
1470 freebsd32_rusage_out(&ki->ki_rusage_ch, &ki32->ki_rusage_ch);
1471 PTRTRIM_CP(*ki, *ki32, ki_pcb);
1472 PTRTRIM_CP(*ki, *ki32, ki_kstack);
1473 PTRTRIM_CP(*ki, *ki32, ki_udata);
1474 PTRTRIM_CP(*ki, *ki32, ki_tdaddr);
1475 CP(*ki, *ki32, ki_sflag);
1476 CP(*ki, *ki32, ki_tdflags);
1481 kern_proc_out_size(struct proc *p, int flags)
1485 PROC_LOCK_ASSERT(p, MA_OWNED);
1487 if ((flags & KERN_PROC_NOTHREADS) != 0) {
1488 #ifdef COMPAT_FREEBSD32
1489 if ((flags & KERN_PROC_MASK32) != 0) {
1490 size += sizeof(struct kinfo_proc32);
1493 size += sizeof(struct kinfo_proc);
1495 #ifdef COMPAT_FREEBSD32
1496 if ((flags & KERN_PROC_MASK32) != 0)
1497 size += sizeof(struct kinfo_proc32) * p->p_numthreads;
1500 size += sizeof(struct kinfo_proc) * p->p_numthreads;
1507 kern_proc_out(struct proc *p, struct sbuf *sb, int flags)
1510 struct kinfo_proc ki;
1511 #ifdef COMPAT_FREEBSD32
1512 struct kinfo_proc32 ki32;
1516 PROC_LOCK_ASSERT(p, MA_OWNED);
1517 MPASS(FIRST_THREAD_IN_PROC(p) != NULL);
1520 fill_kinfo_proc(p, &ki);
1521 if ((flags & KERN_PROC_NOTHREADS) != 0) {
1522 #ifdef COMPAT_FREEBSD32
1523 if ((flags & KERN_PROC_MASK32) != 0) {
1524 freebsd32_kinfo_proc_out(&ki, &ki32);
1525 if (sbuf_bcat(sb, &ki32, sizeof(ki32)) != 0)
1529 if (sbuf_bcat(sb, &ki, sizeof(ki)) != 0)
1532 FOREACH_THREAD_IN_PROC(p, td) {
1533 fill_kinfo_thread(td, &ki, 1);
1534 #ifdef COMPAT_FREEBSD32
1535 if ((flags & KERN_PROC_MASK32) != 0) {
1536 freebsd32_kinfo_proc_out(&ki, &ki32);
1537 if (sbuf_bcat(sb, &ki32, sizeof(ki32)) != 0)
1541 if (sbuf_bcat(sb, &ki, sizeof(ki)) != 0)
1552 sysctl_out_proc(struct proc *p, struct sysctl_req *req, int flags)
1555 struct kinfo_proc ki;
1558 if (req->oldptr == NULL)
1559 return (SYSCTL_OUT(req, 0, kern_proc_out_size(p, flags)));
1561 sbuf_new_for_sysctl(&sb, (char *)&ki, sizeof(ki), req);
1562 sbuf_clear_flags(&sb, SBUF_INCLUDENUL);
1563 error = kern_proc_out(p, &sb, flags);
1564 error2 = sbuf_finish(&sb);
1568 else if (error2 != 0)
1574 proc_iterate(int (*cb)(struct proc *, void *), void *cbarg)
1579 for (i = 0; i < pidhashlock + 1; i++) {
1580 sx_slock(&proctree_lock);
1581 sx_slock(&pidhashtbl_lock[i]);
1582 for (j = i; j <= pidhash; j += pidhashlock + 1) {
1583 LIST_FOREACH(p, &pidhashtbl[j], p_hash) {
1584 if (p->p_state == PRS_NEW)
1586 error = cb(p, cbarg);
1587 PROC_LOCK_ASSERT(p, MA_NOTOWNED);
1589 sx_sunlock(&pidhashtbl_lock[i]);
1590 sx_sunlock(&proctree_lock);
1595 sx_sunlock(&pidhashtbl_lock[i]);
1596 sx_sunlock(&proctree_lock);
1601 struct kern_proc_out_args {
1602 struct sysctl_req *req;
1609 sysctl_kern_proc_iterate(struct proc *p, void *origarg)
1611 struct kern_proc_out_args *arg = origarg;
1612 int *name = arg->name;
1613 int oid_number = arg->oid_number;
1614 int flags = arg->flags;
1615 struct sysctl_req *req = arg->req;
1620 KASSERT(p->p_ucred != NULL,
1621 ("process credential is NULL for non-NEW proc"));
1623 * Show a user only appropriate processes.
1625 if (p_cansee(curthread, p))
1628 * TODO - make more efficient (see notes below).
1631 switch (oid_number) {
1633 if (p->p_ucred->cr_gid != (gid_t)name[0])
1637 case KERN_PROC_PGRP:
1638 /* could do this by traversing pgrp */
1639 if (p->p_pgrp == NULL ||
1640 p->p_pgrp->pg_id != (pid_t)name[0])
1644 case KERN_PROC_RGID:
1645 if (p->p_ucred->cr_rgid != (gid_t)name[0])
1649 case KERN_PROC_SESSION:
1650 if (p->p_session == NULL ||
1651 p->p_session->s_sid != (pid_t)name[0])
1656 if ((p->p_flag & P_CONTROLT) == 0 ||
1657 p->p_session == NULL)
1659 /* XXX proctree_lock */
1660 SESS_LOCK(p->p_session);
1661 if (p->p_session->s_ttyp == NULL ||
1662 tty_udev(p->p_session->s_ttyp) !=
1664 SESS_UNLOCK(p->p_session);
1667 SESS_UNLOCK(p->p_session);
1671 if (p->p_ucred->cr_uid != (uid_t)name[0])
1675 case KERN_PROC_RUID:
1676 if (p->p_ucred->cr_ruid != (uid_t)name[0])
1680 case KERN_PROC_PROC:
1686 error = sysctl_out_proc(p, req, flags);
1687 PROC_LOCK_ASSERT(p, MA_NOTOWNED);
1695 sysctl_kern_proc(SYSCTL_HANDLER_ARGS)
1697 struct kern_proc_out_args iterarg;
1698 int *name = (int *)arg1;
1699 u_int namelen = arg2;
1701 int flags, oid_number;
1704 oid_number = oidp->oid_number;
1705 if (oid_number != KERN_PROC_ALL &&
1706 (oid_number & KERN_PROC_INC_THREAD) == 0)
1707 flags = KERN_PROC_NOTHREADS;
1710 oid_number &= ~KERN_PROC_INC_THREAD;
1712 #ifdef COMPAT_FREEBSD32
1713 if (req->flags & SCTL_MASK32)
1714 flags |= KERN_PROC_MASK32;
1716 if (oid_number == KERN_PROC_PID) {
1719 error = sysctl_wire_old_buffer(req, 0);
1722 sx_slock(&proctree_lock);
1723 error = pget((pid_t)name[0], PGET_CANSEE, &p);
1725 error = sysctl_out_proc(p, req, flags);
1726 sx_sunlock(&proctree_lock);
1730 switch (oid_number) {
1735 case KERN_PROC_PROC:
1736 if (namelen != 0 && namelen != 1)
1745 if (req->oldptr == NULL) {
1746 /* overestimate by 5 procs */
1747 error = SYSCTL_OUT(req, 0, sizeof (struct kinfo_proc) * 5);
1751 error = sysctl_wire_old_buffer(req, 0);
1755 iterarg.flags = flags;
1756 iterarg.oid_number = oid_number;
1758 iterarg.name = name;
1759 error = proc_iterate(sysctl_kern_proc_iterate, &iterarg);
1764 pargs_alloc(int len)
1768 pa = malloc(sizeof(struct pargs) + len, M_PARGS,
1770 refcount_init(&pa->ar_ref, 1);
1771 pa->ar_length = len;
1776 pargs_free(struct pargs *pa)
1783 pargs_hold(struct pargs *pa)
1788 refcount_acquire(&pa->ar_ref);
1792 pargs_drop(struct pargs *pa)
1797 if (refcount_release(&pa->ar_ref))
1802 proc_read_string(struct thread *td, struct proc *p, const char *sptr, char *buf,
1808 * This may return a short read if the string is shorter than the chunk
1809 * and is aligned at the end of the page, and the following page is not
1812 n = proc_readmem(td, p, (vm_offset_t)sptr, buf, len);
1818 #define PROC_AUXV_MAX 256 /* Safety limit on auxv size. */
1820 enum proc_vector_type {
1826 #ifdef COMPAT_FREEBSD32
1828 get_proc_vector32(struct thread *td, struct proc *p, char ***proc_vectorp,
1829 size_t *vsizep, enum proc_vector_type type)
1831 struct freebsd32_ps_strings pss;
1833 vm_offset_t vptr, ptr;
1834 uint32_t *proc_vector32;
1840 if (proc_readmem(td, p, (vm_offset_t)p->p_sysent->sv_psstrings, &pss,
1841 sizeof(pss)) != sizeof(pss))
1845 vptr = (vm_offset_t)PTRIN(pss.ps_argvstr);
1846 vsize = pss.ps_nargvstr;
1847 if (vsize > ARG_MAX)
1849 size = vsize * sizeof(int32_t);
1852 vptr = (vm_offset_t)PTRIN(pss.ps_envstr);
1853 vsize = pss.ps_nenvstr;
1854 if (vsize > ARG_MAX)
1856 size = vsize * sizeof(int32_t);
1859 vptr = (vm_offset_t)PTRIN(pss.ps_envstr) +
1860 (pss.ps_nenvstr + 1) * sizeof(int32_t);
1863 for (ptr = vptr, i = 0; i < PROC_AUXV_MAX; i++) {
1864 if (proc_readmem(td, p, ptr, &aux, sizeof(aux)) !=
1867 if (aux.a_type == AT_NULL)
1871 if (aux.a_type != AT_NULL)
1874 size = vsize * sizeof(aux);
1877 KASSERT(0, ("Wrong proc vector type: %d", type));
1880 proc_vector32 = malloc(size, M_TEMP, M_WAITOK);
1881 if (proc_readmem(td, p, vptr, proc_vector32, size) != size) {
1885 if (type == PROC_AUX) {
1886 *proc_vectorp = (char **)proc_vector32;
1890 proc_vector = malloc(vsize * sizeof(char *), M_TEMP, M_WAITOK);
1891 for (i = 0; i < (int)vsize; i++)
1892 proc_vector[i] = PTRIN(proc_vector32[i]);
1893 *proc_vectorp = proc_vector;
1896 free(proc_vector32, M_TEMP);
1902 get_proc_vector(struct thread *td, struct proc *p, char ***proc_vectorp,
1903 size_t *vsizep, enum proc_vector_type type)
1905 struct ps_strings pss;
1907 vm_offset_t vptr, ptr;
1912 #ifdef COMPAT_FREEBSD32
1913 if (SV_PROC_FLAG(p, SV_ILP32) != 0)
1914 return (get_proc_vector32(td, p, proc_vectorp, vsizep, type));
1916 if (proc_readmem(td, p, (vm_offset_t)p->p_sysent->sv_psstrings, &pss,
1917 sizeof(pss)) != sizeof(pss))
1921 vptr = (vm_offset_t)pss.ps_argvstr;
1922 vsize = pss.ps_nargvstr;
1923 if (vsize > ARG_MAX)
1925 size = vsize * sizeof(char *);
1928 vptr = (vm_offset_t)pss.ps_envstr;
1929 vsize = pss.ps_nenvstr;
1930 if (vsize > ARG_MAX)
1932 size = vsize * sizeof(char *);
1936 * The aux array is just above env array on the stack. Check
1937 * that the address is naturally aligned.
1939 vptr = (vm_offset_t)pss.ps_envstr + (pss.ps_nenvstr + 1)
1941 #if __ELF_WORD_SIZE == 64
1942 if (vptr % sizeof(uint64_t) != 0)
1944 if (vptr % sizeof(uint32_t) != 0)
1948 * We count the array size reading the aux vectors from the
1949 * stack until AT_NULL vector is returned. So (to keep the code
1950 * simple) we read the process stack twice: the first time here
1951 * to find the size and the second time when copying the vectors
1952 * to the allocated proc_vector.
1954 for (ptr = vptr, i = 0; i < PROC_AUXV_MAX; i++) {
1955 if (proc_readmem(td, p, ptr, &aux, sizeof(aux)) !=
1958 if (aux.a_type == AT_NULL)
1963 * If the PROC_AUXV_MAX entries are iterated over, and we have
1964 * not reached AT_NULL, it is most likely we are reading wrong
1965 * data: either the process doesn't have auxv array or data has
1966 * been modified. Return the error in this case.
1968 if (aux.a_type != AT_NULL)
1971 size = vsize * sizeof(aux);
1974 KASSERT(0, ("Wrong proc vector type: %d", type));
1975 return (EINVAL); /* In case we are built without INVARIANTS. */
1977 proc_vector = malloc(size, M_TEMP, M_WAITOK);
1978 if (proc_readmem(td, p, vptr, proc_vector, size) != size) {
1979 free(proc_vector, M_TEMP);
1982 *proc_vectorp = proc_vector;
1988 #define GET_PS_STRINGS_CHUNK_SZ 256 /* Chunk size (bytes) for ps_strings operations. */
1991 get_ps_strings(struct thread *td, struct proc *p, struct sbuf *sb,
1992 enum proc_vector_type type)
1994 size_t done, len, nchr, vsize;
1996 char **proc_vector, *sptr;
1997 char pss_string[GET_PS_STRINGS_CHUNK_SZ];
1999 PROC_ASSERT_HELD(p);
2002 * We are not going to read more than 2 * (PATH_MAX + ARG_MAX) bytes.
2004 nchr = 2 * (PATH_MAX + ARG_MAX);
2006 error = get_proc_vector(td, p, &proc_vector, &vsize, type);
2009 for (done = 0, i = 0; i < (int)vsize && done < nchr; i++) {
2011 * The program may have scribbled into its argv array, e.g. to
2012 * remove some arguments. If that has happened, break out
2013 * before trying to read from NULL.
2015 if (proc_vector[i] == NULL)
2017 for (sptr = proc_vector[i]; ; sptr += GET_PS_STRINGS_CHUNK_SZ) {
2018 error = proc_read_string(td, p, sptr, pss_string,
2019 sizeof(pss_string));
2022 len = strnlen(pss_string, GET_PS_STRINGS_CHUNK_SZ);
2023 if (done + len >= nchr)
2024 len = nchr - done - 1;
2025 sbuf_bcat(sb, pss_string, len);
2026 if (len != GET_PS_STRINGS_CHUNK_SZ)
2028 done += GET_PS_STRINGS_CHUNK_SZ;
2030 sbuf_bcat(sb, "", 1);
2034 free(proc_vector, M_TEMP);
2039 proc_getargv(struct thread *td, struct proc *p, struct sbuf *sb)
2042 return (get_ps_strings(curthread, p, sb, PROC_ARG));
2046 proc_getenvv(struct thread *td, struct proc *p, struct sbuf *sb)
2049 return (get_ps_strings(curthread, p, sb, PROC_ENV));
2053 proc_getauxv(struct thread *td, struct proc *p, struct sbuf *sb)
2059 error = get_proc_vector(td, p, &auxv, &vsize, PROC_AUX);
2061 #ifdef COMPAT_FREEBSD32
2062 if (SV_PROC_FLAG(p, SV_ILP32) != 0)
2063 size = vsize * sizeof(Elf32_Auxinfo);
2066 size = vsize * sizeof(Elf_Auxinfo);
2067 if (sbuf_bcat(sb, auxv, size) != 0)
2075 * This sysctl allows a process to retrieve the argument list or process
2076 * title for another process without groping around in the address space
2077 * of the other process. It also allow a process to set its own "process
2078 * title to a string of its own choice.
2081 sysctl_kern_proc_args(SYSCTL_HANDLER_ARGS)
2083 int *name = (int *)arg1;
2084 u_int namelen = arg2;
2085 struct pargs *newpa, *pa;
2088 int flags, error = 0, error2;
2095 pid = (pid_t)name[0];
2101 * If the query is for this process and it is single-threaded, there
2102 * is nobody to modify pargs, thus we can just read.
2104 if (pid == p->p_pid && p->p_numthreads == 1 && req->newptr == NULL &&
2105 (pa = p->p_args) != NULL)
2106 return (SYSCTL_OUT(req, pa->ar_args, pa->ar_length));
2108 flags = PGET_CANSEE;
2109 if (req->newptr != NULL)
2110 flags |= PGET_ISCURRENT;
2111 error = pget(pid, flags, &p);
2119 error = SYSCTL_OUT(req, pa->ar_args, pa->ar_length);
2121 } else if ((p->p_flag & (P_WEXIT | P_SYSTEM)) == 0) {
2124 sbuf_new_for_sysctl(&sb, NULL, GET_PS_STRINGS_CHUNK_SZ, req);
2125 sbuf_clear_flags(&sb, SBUF_INCLUDENUL);
2126 error = proc_getargv(curthread, p, &sb);
2127 error2 = sbuf_finish(&sb);
2130 if (error == 0 && error2 != 0)
2135 if (error != 0 || req->newptr == NULL)
2138 if (req->newlen > ps_arg_cache_limit - sizeof(struct pargs))
2141 if (req->newlen == 0) {
2143 * Clear the argument pointer, so that we'll fetch arguments
2144 * with proc_getargv() until further notice.
2148 newpa = pargs_alloc(req->newlen);
2149 error = SYSCTL_IN(req, newpa->ar_args, req->newlen);
2164 * This sysctl allows a process to retrieve environment of another process.
2167 sysctl_kern_proc_env(SYSCTL_HANDLER_ARGS)
2169 int *name = (int *)arg1;
2170 u_int namelen = arg2;
2178 error = pget((pid_t)name[0], PGET_WANTREAD, &p);
2181 if ((p->p_flag & P_SYSTEM) != 0) {
2186 sbuf_new_for_sysctl(&sb, NULL, GET_PS_STRINGS_CHUNK_SZ, req);
2187 sbuf_clear_flags(&sb, SBUF_INCLUDENUL);
2188 error = proc_getenvv(curthread, p, &sb);
2189 error2 = sbuf_finish(&sb);
2192 return (error != 0 ? error : error2);
2196 * This sysctl allows a process to retrieve ELF auxiliary vector of
2200 sysctl_kern_proc_auxv(SYSCTL_HANDLER_ARGS)
2202 int *name = (int *)arg1;
2203 u_int namelen = arg2;
2211 error = pget((pid_t)name[0], PGET_WANTREAD, &p);
2214 if ((p->p_flag & P_SYSTEM) != 0) {
2218 sbuf_new_for_sysctl(&sb, NULL, GET_PS_STRINGS_CHUNK_SZ, req);
2219 sbuf_clear_flags(&sb, SBUF_INCLUDENUL);
2220 error = proc_getauxv(curthread, p, &sb);
2221 error2 = sbuf_finish(&sb);
2224 return (error != 0 ? error : error2);
2228 * This sysctl allows a process to retrieve the path of the executable for
2229 * itself or another process.
2232 sysctl_kern_proc_pathname(SYSCTL_HANDLER_ARGS)
2234 pid_t *pidp = (pid_t *)arg1;
2235 unsigned int arglen = arg2;
2238 char *retbuf, *freebuf;
2243 if (*pidp == -1) { /* -1 means this process */
2244 p = req->td->td_proc;
2246 error = pget(*pidp, PGET_CANSEE, &p);
2260 error = vn_fullpath(vp, &retbuf, &freebuf);
2264 error = SYSCTL_OUT(req, retbuf, strlen(retbuf) + 1);
2265 free(freebuf, M_TEMP);
2270 sysctl_kern_proc_sv_name(SYSCTL_HANDLER_ARGS)
2283 error = pget((pid_t)name[0], PGET_CANSEE, &p);
2286 sv_name = p->p_sysent->sv_name;
2288 return (sysctl_handle_string(oidp, sv_name, 0, req));
2291 #ifdef KINFO_OVMENTRY_SIZE
2292 CTASSERT(sizeof(struct kinfo_ovmentry) == KINFO_OVMENTRY_SIZE);
2295 #ifdef COMPAT_FREEBSD7
2297 sysctl_kern_proc_ovmmap(SYSCTL_HANDLER_ARGS)
2299 vm_map_entry_t entry, tmp_entry;
2300 unsigned int last_timestamp, namelen;
2301 char *fullpath, *freepath;
2302 struct kinfo_ovmentry *kve;
2316 error = pget((pid_t)name[0], PGET_WANTREAD, &p);
2319 vm = vmspace_acquire_ref(p);
2324 kve = malloc(sizeof(*kve), M_TEMP, M_WAITOK);
2327 vm_map_lock_read(map);
2328 VM_MAP_ENTRY_FOREACH(entry, map) {
2329 vm_object_t obj, tobj, lobj;
2332 if (entry->eflags & MAP_ENTRY_IS_SUB_MAP)
2335 bzero(kve, sizeof(*kve));
2336 kve->kve_structsize = sizeof(*kve);
2338 kve->kve_private_resident = 0;
2339 obj = entry->object.vm_object;
2341 VM_OBJECT_RLOCK(obj);
2342 if (obj->shadow_count == 1)
2343 kve->kve_private_resident =
2344 obj->resident_page_count;
2346 kve->kve_resident = 0;
2347 addr = entry->start;
2348 while (addr < entry->end) {
2349 if (pmap_extract(map->pmap, addr))
2350 kve->kve_resident++;
2354 for (lobj = tobj = obj; tobj; tobj = tobj->backing_object) {
2356 VM_OBJECT_RLOCK(tobj);
2357 kve->kve_offset += tobj->backing_object_offset;
2360 VM_OBJECT_RUNLOCK(lobj);
2364 kve->kve_start = (void*)entry->start;
2365 kve->kve_end = (void*)entry->end;
2366 kve->kve_offset += (off_t)entry->offset;
2368 if (entry->protection & VM_PROT_READ)
2369 kve->kve_protection |= KVME_PROT_READ;
2370 if (entry->protection & VM_PROT_WRITE)
2371 kve->kve_protection |= KVME_PROT_WRITE;
2372 if (entry->protection & VM_PROT_EXECUTE)
2373 kve->kve_protection |= KVME_PROT_EXEC;
2375 if (entry->eflags & MAP_ENTRY_COW)
2376 kve->kve_flags |= KVME_FLAG_COW;
2377 if (entry->eflags & MAP_ENTRY_NEEDS_COPY)
2378 kve->kve_flags |= KVME_FLAG_NEEDS_COPY;
2379 if (entry->eflags & MAP_ENTRY_NOCOREDUMP)
2380 kve->kve_flags |= KVME_FLAG_NOCOREDUMP;
2382 last_timestamp = map->timestamp;
2383 vm_map_unlock_read(map);
2385 kve->kve_fileid = 0;
2390 kve->kve_type = vm_object_kvme_type(lobj, &vp);
2391 if (kve->kve_type == KVME_TYPE_MGTDEVICE)
2392 kve->kve_type = KVME_TYPE_UNKNOWN;
2396 VM_OBJECT_RUNLOCK(lobj);
2398 kve->kve_ref_count = obj->ref_count;
2399 kve->kve_shadow_count = obj->shadow_count;
2400 VM_OBJECT_RUNLOCK(obj);
2402 vn_fullpath(vp, &fullpath, &freepath);
2403 cred = curthread->td_ucred;
2404 vn_lock(vp, LK_SHARED | LK_RETRY);
2405 if (VOP_GETATTR(vp, &va, cred) == 0) {
2406 kve->kve_fileid = va.va_fileid;
2408 kve->kve_fsid = va.va_fsid;
2413 kve->kve_type = KVME_TYPE_NONE;
2414 kve->kve_ref_count = 0;
2415 kve->kve_shadow_count = 0;
2418 strlcpy(kve->kve_path, fullpath, sizeof(kve->kve_path));
2419 if (freepath != NULL)
2420 free(freepath, M_TEMP);
2422 error = SYSCTL_OUT(req, kve, sizeof(*kve));
2423 vm_map_lock_read(map);
2426 if (last_timestamp != map->timestamp) {
2427 vm_map_lookup_entry(map, addr - 1, &tmp_entry);
2431 vm_map_unlock_read(map);
2437 #endif /* COMPAT_FREEBSD7 */
2439 #ifdef KINFO_VMENTRY_SIZE
2440 CTASSERT(sizeof(struct kinfo_vmentry) == KINFO_VMENTRY_SIZE);
2444 kern_proc_vmmap_resident(vm_map_t map, vm_map_entry_t entry,
2445 int *resident_count, bool *super)
2447 vm_object_t obj, tobj;
2451 vm_pindex_t pi, pi_adv, pindex;
2454 *resident_count = 0;
2455 if (vmmap_skip_res_cnt)
2459 obj = entry->object.vm_object;
2460 addr = entry->start;
2462 pi = OFF_TO_IDX(entry->offset);
2463 for (; addr < entry->end; addr += IDX_TO_OFF(pi_adv), pi += pi_adv) {
2464 if (m_adv != NULL) {
2467 pi_adv = atop(entry->end - addr);
2469 for (tobj = obj;; tobj = tobj->backing_object) {
2470 m = vm_page_find_least(tobj, pindex);
2472 if (m->pindex == pindex)
2474 if (pi_adv > m->pindex - pindex) {
2475 pi_adv = m->pindex - pindex;
2479 if (tobj->backing_object == NULL)
2481 pindex += OFF_TO_IDX(tobj->
2482 backing_object_offset);
2486 if (m->psind != 0 && addr + pagesizes[1] <= entry->end &&
2487 (addr & (pagesizes[1] - 1)) == 0 &&
2488 (pmap_mincore(map->pmap, addr, &pa) & MINCORE_SUPER) != 0) {
2490 pi_adv = atop(pagesizes[1]);
2493 * We do not test the found page on validity.
2494 * Either the page is busy and being paged in,
2495 * or it was invalidated. The first case
2496 * should be counted as resident, the second
2497 * is not so clear; we do account both.
2501 *resident_count += pi_adv;
2507 * Must be called with the process locked and will return unlocked.
2510 kern_proc_vmmap_out(struct proc *p, struct sbuf *sb, ssize_t maxlen, int flags)
2512 vm_map_entry_t entry, tmp_entry;
2515 vm_object_t lobj, nobj, obj, tobj;
2516 char *fullpath, *freepath;
2517 struct kinfo_vmentry *kve;
2522 unsigned int last_timestamp;
2526 PROC_LOCK_ASSERT(p, MA_OWNED);
2530 vm = vmspace_acquire_ref(p);
2535 kve = malloc(sizeof(*kve), M_TEMP, M_WAITOK | M_ZERO);
2539 vm_map_lock_read(map);
2540 VM_MAP_ENTRY_FOREACH(entry, map) {
2541 if (entry->eflags & MAP_ENTRY_IS_SUB_MAP)
2545 bzero(kve, sizeof(*kve));
2546 obj = entry->object.vm_object;
2548 if ((obj->flags & OBJ_ANON) != 0)
2549 kve->kve_obj = (uintptr_t)obj;
2551 for (tobj = obj; tobj != NULL;
2552 tobj = tobj->backing_object) {
2553 VM_OBJECT_RLOCK(tobj);
2554 kve->kve_offset += tobj->backing_object_offset;
2557 if (obj->backing_object == NULL)
2558 kve->kve_private_resident =
2559 obj->resident_page_count;
2560 kern_proc_vmmap_resident(map, entry,
2561 &kve->kve_resident, &super);
2563 kve->kve_flags |= KVME_FLAG_SUPER;
2564 for (tobj = obj; tobj != NULL; tobj = nobj) {
2565 nobj = tobj->backing_object;
2566 if (tobj != obj && tobj != lobj)
2567 VM_OBJECT_RUNLOCK(tobj);
2573 kve->kve_start = entry->start;
2574 kve->kve_end = entry->end;
2575 kve->kve_offset += entry->offset;
2577 if (entry->protection & VM_PROT_READ)
2578 kve->kve_protection |= KVME_PROT_READ;
2579 if (entry->protection & VM_PROT_WRITE)
2580 kve->kve_protection |= KVME_PROT_WRITE;
2581 if (entry->protection & VM_PROT_EXECUTE)
2582 kve->kve_protection |= KVME_PROT_EXEC;
2584 if (entry->eflags & MAP_ENTRY_COW)
2585 kve->kve_flags |= KVME_FLAG_COW;
2586 if (entry->eflags & MAP_ENTRY_NEEDS_COPY)
2587 kve->kve_flags |= KVME_FLAG_NEEDS_COPY;
2588 if (entry->eflags & MAP_ENTRY_NOCOREDUMP)
2589 kve->kve_flags |= KVME_FLAG_NOCOREDUMP;
2590 if (entry->eflags & MAP_ENTRY_GROWS_UP)
2591 kve->kve_flags |= KVME_FLAG_GROWS_UP;
2592 if (entry->eflags & MAP_ENTRY_GROWS_DOWN)
2593 kve->kve_flags |= KVME_FLAG_GROWS_DOWN;
2594 if (entry->eflags & MAP_ENTRY_USER_WIRED)
2595 kve->kve_flags |= KVME_FLAG_USER_WIRED;
2597 guard = (entry->eflags & MAP_ENTRY_GUARD) != 0;
2599 last_timestamp = map->timestamp;
2600 vm_map_unlock_read(map);
2605 kve->kve_type = vm_object_kvme_type(lobj, &vp);
2609 VM_OBJECT_RUNLOCK(lobj);
2611 kve->kve_ref_count = obj->ref_count;
2612 kve->kve_shadow_count = obj->shadow_count;
2613 VM_OBJECT_RUNLOCK(obj);
2615 vn_fullpath(vp, &fullpath, &freepath);
2616 kve->kve_vn_type = vntype_to_kinfo(vp->v_type);
2617 cred = curthread->td_ucred;
2618 vn_lock(vp, LK_SHARED | LK_RETRY);
2619 if (VOP_GETATTR(vp, &va, cred) == 0) {
2620 kve->kve_vn_fileid = va.va_fileid;
2621 kve->kve_vn_fsid = va.va_fsid;
2622 kve->kve_vn_fsid_freebsd11 =
2623 kve->kve_vn_fsid; /* truncate */
2625 MAKEIMODE(va.va_type, va.va_mode);
2626 kve->kve_vn_size = va.va_size;
2627 kve->kve_vn_rdev = va.va_rdev;
2628 kve->kve_vn_rdev_freebsd11 =
2629 kve->kve_vn_rdev; /* truncate */
2630 kve->kve_status = KF_ATTR_VALID;
2635 kve->kve_type = guard ? KVME_TYPE_GUARD :
2637 kve->kve_ref_count = 0;
2638 kve->kve_shadow_count = 0;
2641 strlcpy(kve->kve_path, fullpath, sizeof(kve->kve_path));
2642 if (freepath != NULL)
2643 free(freepath, M_TEMP);
2645 /* Pack record size down */
2646 if ((flags & KERN_VMMAP_PACK_KINFO) != 0)
2647 kve->kve_structsize =
2648 offsetof(struct kinfo_vmentry, kve_path) +
2649 strlen(kve->kve_path) + 1;
2651 kve->kve_structsize = sizeof(*kve);
2652 kve->kve_structsize = roundup(kve->kve_structsize,
2655 /* Halt filling and truncate rather than exceeding maxlen */
2656 if (maxlen != -1 && maxlen < kve->kve_structsize) {
2658 vm_map_lock_read(map);
2660 } else if (maxlen != -1)
2661 maxlen -= kve->kve_structsize;
2663 if (sbuf_bcat(sb, kve, kve->kve_structsize) != 0)
2665 vm_map_lock_read(map);
2668 if (last_timestamp != map->timestamp) {
2669 vm_map_lookup_entry(map, addr - 1, &tmp_entry);
2673 vm_map_unlock_read(map);
2681 sysctl_kern_proc_vmmap(SYSCTL_HANDLER_ARGS)
2686 int error, error2, *name;
2693 sbuf_new_for_sysctl(&sb, NULL, sizeof(struct kinfo_vmentry), req);
2694 sbuf_clear_flags(&sb, SBUF_INCLUDENUL);
2695 error = pget((pid_t)name[0], PGET_CANDEBUG | PGET_NOTWEXIT, &p);
2700 error = kern_proc_vmmap_out(p, &sb, -1, KERN_VMMAP_PACK_KINFO);
2701 error2 = sbuf_finish(&sb);
2703 return (error != 0 ? error : error2);
2706 #if defined(STACK) || defined(DDB)
2708 sysctl_kern_proc_kstack(SYSCTL_HANDLER_ARGS)
2710 struct kinfo_kstack *kkstp;
2711 int error, i, *name, numthreads;
2712 lwpid_t *lwpidarray;
2724 error = pget((pid_t)name[0], PGET_NOTINEXEC | PGET_WANTREAD, &p);
2728 kkstp = malloc(sizeof(*kkstp), M_TEMP, M_WAITOK);
2729 st = stack_create(M_WAITOK);
2734 if (lwpidarray != NULL) {
2735 free(lwpidarray, M_TEMP);
2738 numthreads = p->p_numthreads;
2740 lwpidarray = malloc(sizeof(*lwpidarray) * numthreads, M_TEMP,
2743 } while (numthreads < p->p_numthreads);
2746 * XXXRW: During the below loop, execve(2) and countless other sorts
2747 * of changes could have taken place. Should we check to see if the
2748 * vmspace has been replaced, or the like, in order to prevent
2749 * giving a snapshot that spans, say, execve(2), with some threads
2750 * before and some after? Among other things, the credentials could
2751 * have changed, in which case the right to extract debug info might
2752 * no longer be assured.
2755 FOREACH_THREAD_IN_PROC(p, td) {
2756 KASSERT(i < numthreads,
2757 ("sysctl_kern_proc_kstack: numthreads"));
2758 lwpidarray[i] = td->td_tid;
2763 for (i = 0; i < numthreads; i++) {
2764 td = tdfind(lwpidarray[i], p->p_pid);
2768 bzero(kkstp, sizeof(*kkstp));
2769 (void)sbuf_new(&sb, kkstp->kkst_trace,
2770 sizeof(kkstp->kkst_trace), SBUF_FIXEDLEN);
2772 kkstp->kkst_tid = td->td_tid;
2773 if (TD_IS_SWAPPED(td))
2774 kkstp->kkst_state = KKST_STATE_SWAPPED;
2775 else if (stack_save_td(st, td) == 0)
2776 kkstp->kkst_state = KKST_STATE_STACKOK;
2778 kkstp->kkst_state = KKST_STATE_RUNNING;
2781 stack_sbuf_print(&sb, st);
2784 error = SYSCTL_OUT(req, kkstp, sizeof(*kkstp));
2789 if (lwpidarray != NULL)
2790 free(lwpidarray, M_TEMP);
2792 free(kkstp, M_TEMP);
2798 * This sysctl allows a process to retrieve the full list of groups from
2799 * itself or another process.
2802 sysctl_kern_proc_groups(SYSCTL_HANDLER_ARGS)
2804 pid_t *pidp = (pid_t *)arg1;
2805 unsigned int arglen = arg2;
2812 if (*pidp == -1) { /* -1 means this process */
2813 p = req->td->td_proc;
2816 error = pget(*pidp, PGET_CANSEE, &p);
2821 cred = crhold(p->p_ucred);
2824 error = SYSCTL_OUT(req, cred->cr_groups,
2825 cred->cr_ngroups * sizeof(gid_t));
2831 * This sysctl allows a process to retrieve or/and set the resource limit for
2835 sysctl_kern_proc_rlimit(SYSCTL_HANDLER_ARGS)
2837 int *name = (int *)arg1;
2838 u_int namelen = arg2;
2847 which = (u_int)name[1];
2848 if (which >= RLIM_NLIMITS)
2851 if (req->newptr != NULL && req->newlen != sizeof(rlim))
2854 flags = PGET_HOLD | PGET_NOTWEXIT;
2855 if (req->newptr != NULL)
2856 flags |= PGET_CANDEBUG;
2858 flags |= PGET_CANSEE;
2859 error = pget((pid_t)name[0], flags, &p);
2866 if (req->oldptr != NULL) {
2868 lim_rlimit_proc(p, which, &rlim);
2871 error = SYSCTL_OUT(req, &rlim, sizeof(rlim));
2878 if (req->newptr != NULL) {
2879 error = SYSCTL_IN(req, &rlim, sizeof(rlim));
2881 error = kern_proc_setrlimit(curthread, p, which, &rlim);
2890 * This sysctl allows a process to retrieve ps_strings structure location of
2894 sysctl_kern_proc_ps_strings(SYSCTL_HANDLER_ARGS)
2896 int *name = (int *)arg1;
2897 u_int namelen = arg2;
2899 vm_offset_t ps_strings;
2901 #ifdef COMPAT_FREEBSD32
2902 uint32_t ps_strings32;
2908 error = pget((pid_t)name[0], PGET_CANDEBUG, &p);
2911 #ifdef COMPAT_FREEBSD32
2912 if ((req->flags & SCTL_MASK32) != 0) {
2914 * We return 0 if the 32 bit emulation request is for a 64 bit
2917 ps_strings32 = SV_PROC_FLAG(p, SV_ILP32) != 0 ?
2918 PTROUT(p->p_sysent->sv_psstrings) : 0;
2920 error = SYSCTL_OUT(req, &ps_strings32, sizeof(ps_strings32));
2924 ps_strings = p->p_sysent->sv_psstrings;
2926 error = SYSCTL_OUT(req, &ps_strings, sizeof(ps_strings));
2931 * This sysctl allows a process to retrieve umask of another process.
2934 sysctl_kern_proc_umask(SYSCTL_HANDLER_ARGS)
2936 int *name = (int *)arg1;
2937 u_int namelen = arg2;
2946 pid = (pid_t)name[0];
2948 if (pid == p->p_pid || pid == 0) {
2949 cmask = p->p_pd->pd_cmask;
2953 error = pget(pid, PGET_WANTREAD, &p);
2957 cmask = p->p_pd->pd_cmask;
2960 error = SYSCTL_OUT(req, &cmask, sizeof(cmask));
2965 * This sysctl allows a process to set and retrieve binary osreldate of
2969 sysctl_kern_proc_osrel(SYSCTL_HANDLER_ARGS)
2971 int *name = (int *)arg1;
2972 u_int namelen = arg2;
2974 int flags, error, osrel;
2979 if (req->newptr != NULL && req->newlen != sizeof(osrel))
2982 flags = PGET_HOLD | PGET_NOTWEXIT;
2983 if (req->newptr != NULL)
2984 flags |= PGET_CANDEBUG;
2986 flags |= PGET_CANSEE;
2987 error = pget((pid_t)name[0], flags, &p);
2991 error = SYSCTL_OUT(req, &p->p_osrel, sizeof(p->p_osrel));
2995 if (req->newptr != NULL) {
2996 error = SYSCTL_IN(req, &osrel, sizeof(osrel));
3011 sysctl_kern_proc_sigtramp(SYSCTL_HANDLER_ARGS)
3013 int *name = (int *)arg1;
3014 u_int namelen = arg2;
3016 struct kinfo_sigtramp kst;
3017 const struct sysentvec *sv;
3019 #ifdef COMPAT_FREEBSD32
3020 struct kinfo_sigtramp32 kst32;
3026 error = pget((pid_t)name[0], PGET_CANDEBUG, &p);
3030 #ifdef COMPAT_FREEBSD32
3031 if ((req->flags & SCTL_MASK32) != 0) {
3032 bzero(&kst32, sizeof(kst32));
3033 if (SV_PROC_FLAG(p, SV_ILP32)) {
3034 if (sv->sv_sigcode_base != 0) {
3035 kst32.ksigtramp_start = sv->sv_sigcode_base;
3036 kst32.ksigtramp_end = sv->sv_sigcode_base +
3039 kst32.ksigtramp_start = sv->sv_psstrings -
3041 kst32.ksigtramp_end = sv->sv_psstrings;
3045 error = SYSCTL_OUT(req, &kst32, sizeof(kst32));
3049 bzero(&kst, sizeof(kst));
3050 if (sv->sv_sigcode_base != 0) {
3051 kst.ksigtramp_start = (char *)sv->sv_sigcode_base;
3052 kst.ksigtramp_end = (char *)sv->sv_sigcode_base +
3055 kst.ksigtramp_start = (char *)sv->sv_psstrings -
3057 kst.ksigtramp_end = (char *)sv->sv_psstrings;
3060 error = SYSCTL_OUT(req, &kst, sizeof(kst));
3065 sysctl_kern_proc_sigfastblk(SYSCTL_HANDLER_ARGS)
3067 int *name = (int *)arg1;
3068 u_int namelen = arg2;
3073 #ifdef COMPAT_FREEBSD32
3078 if (namelen != 1 || req->newptr != NULL)
3081 pid = (pid_t)name[0];
3082 error = pget(pid, PGET_HOLD | PGET_NOTWEXIT | PGET_CANDEBUG, &p);
3087 #ifdef COMPAT_FREEBSD32
3088 if (SV_CURPROC_FLAG(SV_ILP32)) {
3089 if (!SV_PROC_FLAG(p, SV_ILP32)) {
3095 if (pid <= PID_MAX) {
3096 td1 = FIRST_THREAD_IN_PROC(p);
3098 FOREACH_THREAD_IN_PROC(p, td1) {
3099 if (td1->td_tid == pid)
3108 * The access to the private thread flags. It is fine as far
3109 * as no out-of-thin-air values are read from td_pflags, and
3110 * usermode read of the td_sigblock_ptr is racy inherently,
3111 * since target process might have already changed it
3114 if ((td1->td_pflags & TDP_SIGFASTBLOCK) != 0)
3115 addr = (uintptr_t)td1->td_sigblock_ptr;
3125 #ifdef COMPAT_FREEBSD32
3126 if (SV_CURPROC_FLAG(SV_ILP32)) {
3128 error = SYSCTL_OUT(req, &addr32, sizeof(addr32));
3131 error = SYSCTL_OUT(req, &addr, sizeof(addr));
3135 SYSCTL_NODE(_kern, KERN_PROC, proc, CTLFLAG_RD | CTLFLAG_MPSAFE, 0,
3138 SYSCTL_PROC(_kern_proc, KERN_PROC_ALL, all, CTLFLAG_RD|CTLTYPE_STRUCT|
3139 CTLFLAG_MPSAFE, 0, 0, sysctl_kern_proc, "S,proc",
3140 "Return entire process table");
3142 static SYSCTL_NODE(_kern_proc, KERN_PROC_GID, gid, CTLFLAG_RD | CTLFLAG_MPSAFE,
3143 sysctl_kern_proc, "Process table");
3145 static SYSCTL_NODE(_kern_proc, KERN_PROC_PGRP, pgrp, CTLFLAG_RD | CTLFLAG_MPSAFE,
3146 sysctl_kern_proc, "Process table");
3148 static SYSCTL_NODE(_kern_proc, KERN_PROC_RGID, rgid, CTLFLAG_RD | CTLFLAG_MPSAFE,
3149 sysctl_kern_proc, "Process table");
3151 static SYSCTL_NODE(_kern_proc, KERN_PROC_SESSION, sid, CTLFLAG_RD |
3152 CTLFLAG_MPSAFE, sysctl_kern_proc, "Process table");
3154 static SYSCTL_NODE(_kern_proc, KERN_PROC_TTY, tty, CTLFLAG_RD | CTLFLAG_MPSAFE,
3155 sysctl_kern_proc, "Process table");
3157 static SYSCTL_NODE(_kern_proc, KERN_PROC_UID, uid, CTLFLAG_RD | CTLFLAG_MPSAFE,
3158 sysctl_kern_proc, "Process table");
3160 static SYSCTL_NODE(_kern_proc, KERN_PROC_RUID, ruid, CTLFLAG_RD | CTLFLAG_MPSAFE,
3161 sysctl_kern_proc, "Process table");
3163 static SYSCTL_NODE(_kern_proc, KERN_PROC_PID, pid, CTLFLAG_RD | CTLFLAG_MPSAFE,
3164 sysctl_kern_proc, "Process table");
3166 static SYSCTL_NODE(_kern_proc, KERN_PROC_PROC, proc, CTLFLAG_RD | CTLFLAG_MPSAFE,
3167 sysctl_kern_proc, "Return process table, no threads");
3169 static SYSCTL_NODE(_kern_proc, KERN_PROC_ARGS, args,
3170 CTLFLAG_RW | CTLFLAG_CAPWR | CTLFLAG_ANYBODY | CTLFLAG_MPSAFE,
3171 sysctl_kern_proc_args, "Process argument list");
3173 static SYSCTL_NODE(_kern_proc, KERN_PROC_ENV, env, CTLFLAG_RD | CTLFLAG_MPSAFE,
3174 sysctl_kern_proc_env, "Process environment");
3176 static SYSCTL_NODE(_kern_proc, KERN_PROC_AUXV, auxv, CTLFLAG_RD |
3177 CTLFLAG_MPSAFE, sysctl_kern_proc_auxv, "Process ELF auxiliary vector");
3179 static SYSCTL_NODE(_kern_proc, KERN_PROC_PATHNAME, pathname, CTLFLAG_RD |
3180 CTLFLAG_MPSAFE, sysctl_kern_proc_pathname, "Process executable path");
3182 static SYSCTL_NODE(_kern_proc, KERN_PROC_SV_NAME, sv_name, CTLFLAG_RD |
3183 CTLFLAG_MPSAFE, sysctl_kern_proc_sv_name,
3184 "Process syscall vector name (ABI type)");
3186 static SYSCTL_NODE(_kern_proc, (KERN_PROC_GID | KERN_PROC_INC_THREAD), gid_td,
3187 CTLFLAG_RD | CTLFLAG_MPSAFE, sysctl_kern_proc, "Process table");
3189 static SYSCTL_NODE(_kern_proc, (KERN_PROC_PGRP | KERN_PROC_INC_THREAD), pgrp_td,
3190 CTLFLAG_RD | CTLFLAG_MPSAFE, sysctl_kern_proc, "Process table");
3192 static SYSCTL_NODE(_kern_proc, (KERN_PROC_RGID | KERN_PROC_INC_THREAD), rgid_td,
3193 CTLFLAG_RD | CTLFLAG_MPSAFE, sysctl_kern_proc, "Process table");
3195 static SYSCTL_NODE(_kern_proc, (KERN_PROC_SESSION | KERN_PROC_INC_THREAD),
3196 sid_td, CTLFLAG_RD | CTLFLAG_MPSAFE, sysctl_kern_proc, "Process table");
3198 static SYSCTL_NODE(_kern_proc, (KERN_PROC_TTY | KERN_PROC_INC_THREAD), tty_td,
3199 CTLFLAG_RD | CTLFLAG_MPSAFE, sysctl_kern_proc, "Process table");
3201 static SYSCTL_NODE(_kern_proc, (KERN_PROC_UID | KERN_PROC_INC_THREAD), uid_td,
3202 CTLFLAG_RD | CTLFLAG_MPSAFE, sysctl_kern_proc, "Process table");
3204 static SYSCTL_NODE(_kern_proc, (KERN_PROC_RUID | KERN_PROC_INC_THREAD), ruid_td,
3205 CTLFLAG_RD | CTLFLAG_MPSAFE, sysctl_kern_proc, "Process table");
3207 static SYSCTL_NODE(_kern_proc, (KERN_PROC_PID | KERN_PROC_INC_THREAD), pid_td,
3208 CTLFLAG_RD | CTLFLAG_MPSAFE, sysctl_kern_proc, "Process table");
3210 static SYSCTL_NODE(_kern_proc, (KERN_PROC_PROC | KERN_PROC_INC_THREAD), proc_td,
3211 CTLFLAG_RD | CTLFLAG_MPSAFE, sysctl_kern_proc,
3212 "Return process table, including threads");
3214 #ifdef COMPAT_FREEBSD7
3215 static SYSCTL_NODE(_kern_proc, KERN_PROC_OVMMAP, ovmmap, CTLFLAG_RD |
3216 CTLFLAG_MPSAFE, sysctl_kern_proc_ovmmap, "Old Process vm map entries");
3219 static SYSCTL_NODE(_kern_proc, KERN_PROC_VMMAP, vmmap, CTLFLAG_RD |
3220 CTLFLAG_MPSAFE, sysctl_kern_proc_vmmap, "Process vm map entries");
3222 #if defined(STACK) || defined(DDB)
3223 static SYSCTL_NODE(_kern_proc, KERN_PROC_KSTACK, kstack, CTLFLAG_RD |
3224 CTLFLAG_MPSAFE, sysctl_kern_proc_kstack, "Process kernel stacks");
3227 static SYSCTL_NODE(_kern_proc, KERN_PROC_GROUPS, groups, CTLFLAG_RD |
3228 CTLFLAG_MPSAFE, sysctl_kern_proc_groups, "Process groups");
3230 static SYSCTL_NODE(_kern_proc, KERN_PROC_RLIMIT, rlimit, CTLFLAG_RW |
3231 CTLFLAG_ANYBODY | CTLFLAG_MPSAFE, sysctl_kern_proc_rlimit,
3232 "Process resource limits");
3234 static SYSCTL_NODE(_kern_proc, KERN_PROC_PS_STRINGS, ps_strings, CTLFLAG_RD |
3235 CTLFLAG_MPSAFE, sysctl_kern_proc_ps_strings,
3236 "Process ps_strings location");
3238 static SYSCTL_NODE(_kern_proc, KERN_PROC_UMASK, umask, CTLFLAG_RD |
3239 CTLFLAG_MPSAFE, sysctl_kern_proc_umask, "Process umask");
3241 static SYSCTL_NODE(_kern_proc, KERN_PROC_OSREL, osrel, CTLFLAG_RW |
3242 CTLFLAG_ANYBODY | CTLFLAG_MPSAFE, sysctl_kern_proc_osrel,
3243 "Process binary osreldate");
3245 static SYSCTL_NODE(_kern_proc, KERN_PROC_SIGTRAMP, sigtramp, CTLFLAG_RD |
3246 CTLFLAG_MPSAFE, sysctl_kern_proc_sigtramp,
3247 "Process signal trampoline location");
3249 static SYSCTL_NODE(_kern_proc, KERN_PROC_SIGFASTBLK, sigfastblk, CTLFLAG_RD |
3250 CTLFLAG_ANYBODY | CTLFLAG_MPSAFE, sysctl_kern_proc_sigfastblk,
3251 "Thread sigfastblock address");
3256 * stop_all_proc() purpose is to stop all process which have usermode,
3257 * except current process for obvious reasons. This makes it somewhat
3258 * unreliable when invoked from multithreaded process. The service
3259 * must not be user-callable anyway.
3264 struct proc *cp, *p;
3266 bool restart, seen_stopped, seen_exiting, stopped_some;
3270 sx_xlock(&allproc_lock);
3272 seen_exiting = seen_stopped = stopped_some = restart = false;
3273 LIST_REMOVE(cp, p_list);
3274 LIST_INSERT_HEAD(&allproc, cp, p_list);
3276 p = LIST_NEXT(cp, p_list);
3279 LIST_REMOVE(cp, p_list);
3280 LIST_INSERT_AFTER(p, cp, p_list);
3282 if ((p->p_flag & (P_KPROC | P_SYSTEM | P_TOTAL_STOP)) != 0) {
3286 if ((p->p_flag & P_WEXIT) != 0) {
3287 seen_exiting = true;
3291 if (P_SHOULDSTOP(p) == P_STOPPED_SINGLE) {
3293 * Stopped processes are tolerated when there
3294 * are no other processes which might continue
3295 * them. P_STOPPED_SINGLE but not
3296 * P_TOTAL_STOP process still has at least one
3299 seen_stopped = true;
3303 sx_xunlock(&allproc_lock);
3305 r = thread_single(p, SINGLE_ALLPROC);
3309 stopped_some = true;
3312 sx_xlock(&allproc_lock);
3314 /* Catch forked children we did not see in iteration. */
3315 if (gen != allproc_gen)
3317 sx_xunlock(&allproc_lock);
3318 if (restart || stopped_some || seen_exiting || seen_stopped) {
3319 kern_yield(PRI_USER);
3325 resume_all_proc(void)
3327 struct proc *cp, *p;
3330 sx_xlock(&allproc_lock);
3332 LIST_REMOVE(cp, p_list);
3333 LIST_INSERT_HEAD(&allproc, cp, p_list);
3335 p = LIST_NEXT(cp, p_list);
3338 LIST_REMOVE(cp, p_list);
3339 LIST_INSERT_AFTER(p, cp, p_list);
3341 if ((p->p_flag & P_TOTAL_STOP) != 0) {
3342 sx_xunlock(&allproc_lock);
3344 thread_single_end(p, SINGLE_ALLPROC);
3347 sx_xlock(&allproc_lock);
3352 /* Did the loop above missed any stopped process ? */
3353 FOREACH_PROC_IN_SYSTEM(p) {
3354 /* No need for proc lock. */
3355 if ((p->p_flag & P_TOTAL_STOP) != 0)
3358 sx_xunlock(&allproc_lock);
3361 /* #define TOTAL_STOP_DEBUG 1 */
3362 #ifdef TOTAL_STOP_DEBUG
3363 volatile static int ap_resume;
3364 #include <sys/mount.h>
3367 sysctl_debug_stop_all_proc(SYSCTL_HANDLER_ARGS)
3373 error = sysctl_handle_int(oidp, &val, 0, req);
3374 if (error != 0 || req->newptr == NULL)
3379 while (ap_resume == 0)
3387 SYSCTL_PROC(_debug, OID_AUTO, stop_all_proc, CTLTYPE_INT | CTLFLAG_RW |
3388 CTLFLAG_MPSAFE, __DEVOLATILE(int *, &ap_resume), 0,
3389 sysctl_debug_stop_all_proc, "I",