2 * Copyright (c) 1982, 1986, 1989, 1991, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 4. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * @(#)kern_proc.c 8.7 (Berkeley) 2/14/95
32 #include <sys/cdefs.h>
33 __FBSDID("$FreeBSD$");
35 #include "opt_compat.h"
37 #include "opt_ktrace.h"
38 #include "opt_kstack_pages.h"
39 #include "opt_stack.h"
41 #include <sys/param.h>
42 #include <sys/systm.h>
45 #include <sys/kernel.h>
46 #include <sys/limits.h>
48 #include <sys/loginclass.h>
49 #include <sys/malloc.h>
51 #include <sys/mount.h>
52 #include <sys/mutex.h>
54 #include <sys/ptrace.h>
55 #include <sys/refcount.h>
56 #include <sys/resourcevar.h>
57 #include <sys/rwlock.h>
59 #include <sys/sysent.h>
60 #include <sys/sched.h>
62 #include <sys/stack.h>
64 #include <sys/sysctl.h>
65 #include <sys/filedesc.h>
67 #include <sys/signalvar.h>
72 #include <sys/vnode.h>
73 #include <sys/eventhandler.h>
80 #include <vm/vm_param.h>
81 #include <vm/vm_extern.h>
83 #include <vm/vm_map.h>
84 #include <vm/vm_object.h>
85 #include <vm/vm_page.h>
88 #ifdef COMPAT_FREEBSD32
89 #include <compat/freebsd32/freebsd32.h>
90 #include <compat/freebsd32/freebsd32_util.h>
93 SDT_PROVIDER_DEFINE(proc);
94 SDT_PROBE_DEFINE4(proc, kernel, ctor, entry, "struct proc *", "int",
96 SDT_PROBE_DEFINE4(proc, kernel, ctor, return, "struct proc *", "int",
98 SDT_PROBE_DEFINE4(proc, kernel, dtor, entry, "struct proc *", "int",
99 "void *", "struct thread *");
100 SDT_PROBE_DEFINE3(proc, kernel, dtor, return, "struct proc *", "int",
102 SDT_PROBE_DEFINE3(proc, kernel, init, entry, "struct proc *", "int",
104 SDT_PROBE_DEFINE3(proc, kernel, init, return, "struct proc *", "int",
107 MALLOC_DEFINE(M_PGRP, "pgrp", "process group header");
108 MALLOC_DEFINE(M_SESSION, "session", "session header");
109 static MALLOC_DEFINE(M_PROC, "proc", "Proc structures");
110 MALLOC_DEFINE(M_SUBPROC, "subproc", "Proc sub-structures");
112 static void doenterpgrp(struct proc *, struct pgrp *);
113 static void orphanpg(struct pgrp *pg);
114 static void fill_kinfo_aggregate(struct proc *p, struct kinfo_proc *kp);
115 static void fill_kinfo_proc_only(struct proc *p, struct kinfo_proc *kp);
116 static void fill_kinfo_thread(struct thread *td, struct kinfo_proc *kp,
118 static void pgadjustjobc(struct pgrp *pgrp, int entering);
119 static void pgdelete(struct pgrp *);
120 static int proc_ctor(void *mem, int size, void *arg, int flags);
121 static void proc_dtor(void *mem, int size, void *arg);
122 static int proc_init(void *mem, int size, int flags);
123 static void proc_fini(void *mem, int size);
124 static void pargs_free(struct pargs *pa);
125 static struct proc *zpfind_locked(pid_t pid);
128 * Other process lists
130 struct pidhashhead *pidhashtbl;
132 struct pgrphashhead *pgrphashtbl;
134 struct proclist allproc;
135 struct proclist zombproc;
136 struct sx allproc_lock;
137 struct sx proctree_lock;
138 struct mtx ppeers_lock;
139 uma_zone_t proc_zone;
141 int kstack_pages = KSTACK_PAGES;
142 SYSCTL_INT(_kern, OID_AUTO, kstack_pages, CTLFLAG_RD, &kstack_pages, 0,
143 "Kernel stack size in pages");
145 CTASSERT(sizeof(struct kinfo_proc) == KINFO_PROC_SIZE);
146 #ifdef COMPAT_FREEBSD32
147 CTASSERT(sizeof(struct kinfo_proc32) == KINFO_PROC32_SIZE);
151 * Initialize global process hashing structures.
157 sx_init(&allproc_lock, "allproc");
158 sx_init(&proctree_lock, "proctree");
159 mtx_init(&ppeers_lock, "p_peers", NULL, MTX_DEF);
161 LIST_INIT(&zombproc);
162 pidhashtbl = hashinit(maxproc / 4, M_PROC, &pidhash);
163 pgrphashtbl = hashinit(maxproc / 4, M_PROC, &pgrphash);
164 proc_zone = uma_zcreate("PROC", sched_sizeof_proc(),
165 proc_ctor, proc_dtor, proc_init, proc_fini,
166 UMA_ALIGN_PTR, UMA_ZONE_NOFREE);
171 * Prepare a proc for use.
174 proc_ctor(void *mem, int size, void *arg, int flags)
178 p = (struct proc *)mem;
179 SDT_PROBE(proc, kernel, ctor , entry, p, size, arg, flags, 0);
180 EVENTHANDLER_INVOKE(process_ctor, p);
181 SDT_PROBE(proc, kernel, ctor , return, p, size, arg, flags, 0);
186 * Reclaim a proc after use.
189 proc_dtor(void *mem, int size, void *arg)
194 /* INVARIANTS checks go here */
195 p = (struct proc *)mem;
196 td = FIRST_THREAD_IN_PROC(p);
197 SDT_PROBE(proc, kernel, dtor, entry, p, size, arg, td, 0);
200 KASSERT((p->p_numthreads == 1),
201 ("bad number of threads in exiting process"));
202 KASSERT(STAILQ_EMPTY(&p->p_ktr), ("proc_dtor: non-empty p_ktr"));
204 /* Free all OSD associated to this thread. */
207 EVENTHANDLER_INVOKE(process_dtor, p);
208 if (p->p_ksi != NULL)
209 KASSERT(! KSI_ONQ(p->p_ksi), ("SIGCHLD queue"));
210 SDT_PROBE(proc, kernel, dtor, return, p, size, arg, 0, 0);
214 * Initialize type-stable parts of a proc (when newly created).
217 proc_init(void *mem, int size, int flags)
221 p = (struct proc *)mem;
222 SDT_PROBE(proc, kernel, init, entry, p, size, flags, 0, 0);
223 p->p_sched = (struct p_sched *)&p[1];
224 bzero(&p->p_mtx, sizeof(struct mtx));
225 mtx_init(&p->p_mtx, "process lock", NULL, MTX_DEF | MTX_DUPOK);
226 mtx_init(&p->p_slock, "process slock", NULL, MTX_SPIN | MTX_RECURSE);
227 cv_init(&p->p_pwait, "ppwait");
228 cv_init(&p->p_dbgwait, "dbgwait");
229 TAILQ_INIT(&p->p_threads); /* all threads in proc */
230 EVENTHANDLER_INVOKE(process_init, p);
231 p->p_stats = pstats_alloc();
232 SDT_PROBE(proc, kernel, init, return, p, size, flags, 0, 0);
237 * UMA should ensure that this function is never called.
238 * Freeing a proc structure would violate type stability.
241 proc_fini(void *mem, int size)
246 p = (struct proc *)mem;
247 EVENTHANDLER_INVOKE(process_fini, p);
248 pstats_free(p->p_stats);
249 thread_free(FIRST_THREAD_IN_PROC(p));
250 mtx_destroy(&p->p_mtx);
251 if (p->p_ksi != NULL)
252 ksiginfo_free(p->p_ksi);
254 panic("proc reclaimed");
259 * Is p an inferior of the current process?
263 register struct proc *p;
266 sx_assert(&proctree_lock, SX_LOCKED);
267 for (; p != curproc; p = p->p_pptr)
274 pfind_locked(pid_t pid)
278 sx_assert(&allproc_lock, SX_LOCKED);
279 LIST_FOREACH(p, PIDHASH(pid), p_hash) {
280 if (p->p_pid == pid) {
282 if (p->p_state == PRS_NEW) {
293 * Locate a process by number; return only "live" processes -- i.e., neither
294 * zombies nor newly born but incompletely initialized processes. By not
295 * returning processes in the PRS_NEW state, we allow callers to avoid
296 * testing for that condition to avoid dereferencing p_ucred, et al.
303 sx_slock(&allproc_lock);
304 p = pfind_locked(pid);
305 sx_sunlock(&allproc_lock);
310 pfind_tid_locked(pid_t tid)
315 sx_assert(&allproc_lock, SX_LOCKED);
316 FOREACH_PROC_IN_SYSTEM(p) {
318 if (p->p_state == PRS_NEW) {
322 FOREACH_THREAD_IN_PROC(p, td) {
323 if (td->td_tid == tid)
333 * Locate a process group by number.
334 * The caller must hold proctree_lock.
340 register struct pgrp *pgrp;
342 sx_assert(&proctree_lock, SX_LOCKED);
344 LIST_FOREACH(pgrp, PGRPHASH(pgid), pg_hash) {
345 if (pgrp->pg_id == pgid) {
354 * Locate process and do additional manipulations, depending on flags.
357 pget(pid_t pid, int flags, struct proc **pp)
362 sx_slock(&allproc_lock);
363 if (pid <= PID_MAX) {
364 p = pfind_locked(pid);
365 if (p == NULL && (flags & PGET_NOTWEXIT) == 0)
366 p = zpfind_locked(pid);
367 } else if ((flags & PGET_NOTID) == 0) {
368 p = pfind_tid_locked(pid);
372 sx_sunlock(&allproc_lock);
375 if ((flags & PGET_CANSEE) != 0) {
376 error = p_cansee(curthread, p);
380 if ((flags & PGET_CANDEBUG) != 0) {
381 error = p_candebug(curthread, p);
385 if ((flags & PGET_ISCURRENT) != 0 && curproc != p) {
389 if ((flags & PGET_NOTWEXIT) != 0 && (p->p_flag & P_WEXIT) != 0) {
393 if ((flags & PGET_NOTINEXEC) != 0 && (p->p_flag & P_INEXEC) != 0) {
395 * XXXRW: Not clear ESRCH is the right error during proc
401 if ((flags & PGET_HOLD) != 0) {
413 * Create a new process group.
414 * pgid must be equal to the pid of p.
415 * Begin a new session if required.
418 enterpgrp(p, pgid, pgrp, sess)
419 register struct proc *p;
422 struct session *sess;
425 sx_assert(&proctree_lock, SX_XLOCKED);
427 KASSERT(pgrp != NULL, ("enterpgrp: pgrp == NULL"));
428 KASSERT(p->p_pid == pgid,
429 ("enterpgrp: new pgrp and pid != pgid"));
430 KASSERT(pgfind(pgid) == NULL,
431 ("enterpgrp: pgrp with pgid exists"));
432 KASSERT(!SESS_LEADER(p),
433 ("enterpgrp: session leader attempted setpgrp"));
435 mtx_init(&pgrp->pg_mtx, "process group", NULL, MTX_DEF | MTX_DUPOK);
441 mtx_init(&sess->s_mtx, "session", NULL, MTX_DEF);
443 p->p_flag &= ~P_CONTROLT;
447 sess->s_sid = p->p_pid;
448 refcount_init(&sess->s_count, 1);
449 sess->s_ttyvp = NULL;
450 sess->s_ttydp = NULL;
452 bcopy(p->p_session->s_login, sess->s_login,
453 sizeof(sess->s_login));
454 pgrp->pg_session = sess;
455 KASSERT(p == curproc,
456 ("enterpgrp: mksession and p != curproc"));
458 pgrp->pg_session = p->p_session;
459 sess_hold(pgrp->pg_session);
463 LIST_INIT(&pgrp->pg_members);
466 * As we have an exclusive lock of proctree_lock,
467 * this should not deadlock.
469 LIST_INSERT_HEAD(PGRPHASH(pgid), pgrp, pg_hash);
471 SLIST_INIT(&pgrp->pg_sigiolst);
474 doenterpgrp(p, pgrp);
480 * Move p to an existing process group
483 enterthispgrp(p, pgrp)
484 register struct proc *p;
488 sx_assert(&proctree_lock, SX_XLOCKED);
489 PROC_LOCK_ASSERT(p, MA_NOTOWNED);
490 PGRP_LOCK_ASSERT(pgrp, MA_NOTOWNED);
491 PGRP_LOCK_ASSERT(p->p_pgrp, MA_NOTOWNED);
492 SESS_LOCK_ASSERT(p->p_session, MA_NOTOWNED);
493 KASSERT(pgrp->pg_session == p->p_session,
494 ("%s: pgrp's session %p, p->p_session %p.\n",
498 KASSERT(pgrp != p->p_pgrp,
499 ("%s: p belongs to pgrp.", __func__));
501 doenterpgrp(p, pgrp);
507 * Move p to a process group
514 struct pgrp *savepgrp;
516 sx_assert(&proctree_lock, SX_XLOCKED);
517 PROC_LOCK_ASSERT(p, MA_NOTOWNED);
518 PGRP_LOCK_ASSERT(pgrp, MA_NOTOWNED);
519 PGRP_LOCK_ASSERT(p->p_pgrp, MA_NOTOWNED);
520 SESS_LOCK_ASSERT(p->p_session, MA_NOTOWNED);
522 savepgrp = p->p_pgrp;
525 * Adjust eligibility of affected pgrps to participate in job control.
526 * Increment eligibility counts before decrementing, otherwise we
527 * could reach 0 spuriously during the first call.
530 fixjobc(p, p->p_pgrp, 0);
535 LIST_REMOVE(p, p_pglist);
538 LIST_INSERT_HEAD(&pgrp->pg_members, p, p_pglist);
539 PGRP_UNLOCK(savepgrp);
541 if (LIST_EMPTY(&savepgrp->pg_members))
546 * remove process from process group
550 register struct proc *p;
552 struct pgrp *savepgrp;
554 sx_assert(&proctree_lock, SX_XLOCKED);
555 savepgrp = p->p_pgrp;
558 LIST_REMOVE(p, p_pglist);
561 PGRP_UNLOCK(savepgrp);
562 if (LIST_EMPTY(&savepgrp->pg_members))
568 * delete a process group
572 register struct pgrp *pgrp;
574 struct session *savesess;
577 sx_assert(&proctree_lock, SX_XLOCKED);
578 PGRP_LOCK_ASSERT(pgrp, MA_NOTOWNED);
579 SESS_LOCK_ASSERT(pgrp->pg_session, MA_NOTOWNED);
582 * Reset any sigio structures pointing to us as a result of
583 * F_SETOWN with our pgid.
585 funsetownlst(&pgrp->pg_sigiolst);
588 tp = pgrp->pg_session->s_ttyp;
589 LIST_REMOVE(pgrp, pg_hash);
590 savesess = pgrp->pg_session;
593 /* Remove the reference to the pgrp before deallocating it. */
596 tty_rel_pgrp(tp, pgrp);
599 mtx_destroy(&pgrp->pg_mtx);
601 sess_release(savesess);
605 pgadjustjobc(pgrp, entering)
615 if (pgrp->pg_jobc == 0)
622 * Adjust pgrp jobc counters when specified process changes process group.
623 * We count the number of processes in each process group that "qualify"
624 * the group for terminal job control (those with a parent in a different
625 * process group of the same session). If that count reaches zero, the
626 * process group becomes orphaned. Check both the specified process'
627 * process group and that of its children.
628 * entering == 0 => p is leaving specified group.
629 * entering == 1 => p is entering specified group.
632 fixjobc(p, pgrp, entering)
633 register struct proc *p;
634 register struct pgrp *pgrp;
637 register struct pgrp *hispgrp;
638 register struct session *mysession;
640 sx_assert(&proctree_lock, SX_LOCKED);
641 PROC_LOCK_ASSERT(p, MA_NOTOWNED);
642 PGRP_LOCK_ASSERT(pgrp, MA_NOTOWNED);
643 SESS_LOCK_ASSERT(pgrp->pg_session, MA_NOTOWNED);
646 * Check p's parent to see whether p qualifies its own process
647 * group; if so, adjust count for p's process group.
649 mysession = pgrp->pg_session;
650 if ((hispgrp = p->p_pptr->p_pgrp) != pgrp &&
651 hispgrp->pg_session == mysession)
652 pgadjustjobc(pgrp, entering);
655 * Check this process' children to see whether they qualify
656 * their process groups; if so, adjust counts for children's
659 LIST_FOREACH(p, &p->p_children, p_sibling) {
661 if (hispgrp == pgrp ||
662 hispgrp->pg_session != mysession)
665 if (p->p_state == PRS_ZOMBIE) {
670 pgadjustjobc(hispgrp, entering);
675 * A process group has become orphaned;
676 * if there are any stopped processes in the group,
677 * hang-up all process in that group.
683 register struct proc *p;
685 PGRP_LOCK_ASSERT(pg, MA_OWNED);
687 LIST_FOREACH(p, &pg->pg_members, p_pglist) {
689 if (P_SHOULDSTOP(p)) {
691 LIST_FOREACH(p, &pg->pg_members, p_pglist) {
693 kern_psignal(p, SIGHUP);
694 kern_psignal(p, SIGCONT);
704 sess_hold(struct session *s)
707 refcount_acquire(&s->s_count);
711 sess_release(struct session *s)
714 if (refcount_release(&s->s_count)) {
715 if (s->s_ttyp != NULL) {
717 tty_rel_sess(s->s_ttyp, s);
719 mtx_destroy(&s->s_mtx);
726 DB_SHOW_COMMAND(pgrpdump, pgrpdump)
728 register struct pgrp *pgrp;
729 register struct proc *p;
732 for (i = 0; i <= pgrphash; i++) {
733 if (!LIST_EMPTY(&pgrphashtbl[i])) {
734 printf("\tindx %d\n", i);
735 LIST_FOREACH(pgrp, &pgrphashtbl[i], pg_hash) {
737 "\tpgrp %p, pgid %ld, sess %p, sesscnt %d, mem %p\n",
738 (void *)pgrp, (long)pgrp->pg_id,
739 (void *)pgrp->pg_session,
740 pgrp->pg_session->s_count,
741 (void *)LIST_FIRST(&pgrp->pg_members));
742 LIST_FOREACH(p, &pgrp->pg_members, p_pglist) {
743 printf("\t\tpid %ld addr %p pgrp %p\n",
744 (long)p->p_pid, (void *)p,
754 * Calculate the kinfo_proc members which contain process-wide
756 * Must be called with the target process locked.
759 fill_kinfo_aggregate(struct proc *p, struct kinfo_proc *kp)
763 PROC_LOCK_ASSERT(p, MA_OWNED);
767 FOREACH_THREAD_IN_PROC(p, td) {
769 kp->ki_pctcpu += sched_pctcpu(td);
770 kp->ki_estcpu += td->td_estcpu;
776 * Clear kinfo_proc and fill in any information that is common
777 * to all threads in the process.
778 * Must be called with the target process locked.
781 fill_kinfo_proc_only(struct proc *p, struct kinfo_proc *kp)
789 PROC_LOCK_ASSERT(p, MA_OWNED);
790 bzero(kp, sizeof(*kp));
792 kp->ki_structsize = sizeof(*kp);
794 kp->ki_addr =/* p->p_addr; */0; /* XXX */
795 kp->ki_args = p->p_args;
796 kp->ki_textvp = p->p_textvp;
798 kp->ki_tracep = p->p_tracevp;
799 kp->ki_traceflag = p->p_traceflag;
802 kp->ki_vmspace = p->p_vmspace;
803 kp->ki_flag = p->p_flag;
804 kp->ki_flag2 = p->p_flag2;
807 kp->ki_uid = cred->cr_uid;
808 kp->ki_ruid = cred->cr_ruid;
809 kp->ki_svuid = cred->cr_svuid;
811 if (cred->cr_flags & CRED_FLAG_CAPMODE)
812 kp->ki_cr_flags |= KI_CRF_CAPABILITY_MODE;
813 /* XXX bde doesn't like KI_NGROUPS */
814 if (cred->cr_ngroups > KI_NGROUPS) {
815 kp->ki_ngroups = KI_NGROUPS;
816 kp->ki_cr_flags |= KI_CRF_GRP_OVERFLOW;
818 kp->ki_ngroups = cred->cr_ngroups;
819 bcopy(cred->cr_groups, kp->ki_groups,
820 kp->ki_ngroups * sizeof(gid_t));
821 kp->ki_rgid = cred->cr_rgid;
822 kp->ki_svgid = cred->cr_svgid;
823 /* If jailed(cred), emulate the old P_JAILED flag. */
825 kp->ki_flag |= P_JAILED;
826 /* If inside the jail, use 0 as a jail ID. */
827 if (cred->cr_prison != curthread->td_ucred->cr_prison)
828 kp->ki_jid = cred->cr_prison->pr_id;
830 strlcpy(kp->ki_loginclass, cred->cr_loginclass->lc_name,
831 sizeof(kp->ki_loginclass));
835 mtx_lock(&ps->ps_mtx);
836 kp->ki_sigignore = ps->ps_sigignore;
837 kp->ki_sigcatch = ps->ps_sigcatch;
838 mtx_unlock(&ps->ps_mtx);
840 if (p->p_state != PRS_NEW &&
841 p->p_state != PRS_ZOMBIE &&
842 p->p_vmspace != NULL) {
843 struct vmspace *vm = p->p_vmspace;
845 kp->ki_size = vm->vm_map.size;
846 kp->ki_rssize = vmspace_resident_count(vm); /*XXX*/
847 FOREACH_THREAD_IN_PROC(p, td0) {
848 if (!TD_IS_SWAPPED(td0))
849 kp->ki_rssize += td0->td_kstack_pages;
851 kp->ki_swrss = vm->vm_swrss;
852 kp->ki_tsize = vm->vm_tsize;
853 kp->ki_dsize = vm->vm_dsize;
854 kp->ki_ssize = vm->vm_ssize;
855 } else if (p->p_state == PRS_ZOMBIE)
857 if (kp->ki_flag & P_INMEM)
858 kp->ki_sflag = PS_INMEM;
861 /* Calculate legacy swtime as seconds since 'swtick'. */
862 kp->ki_swtime = (ticks - p->p_swtick) / hz;
863 kp->ki_pid = p->p_pid;
864 kp->ki_nice = p->p_nice;
865 kp->ki_fibnum = p->p_fibnum;
866 kp->ki_start = p->p_stats->p_start;
867 timevaladd(&kp->ki_start, &boottime);
869 rufetch(p, &kp->ki_rusage);
870 kp->ki_runtime = cputick2usec(p->p_rux.rux_runtime);
871 calcru(p, &kp->ki_rusage.ru_utime, &kp->ki_rusage.ru_stime);
873 calccru(p, &kp->ki_childutime, &kp->ki_childstime);
874 /* Some callers want child times in a single value. */
875 kp->ki_childtime = kp->ki_childstime;
876 timevaladd(&kp->ki_childtime, &kp->ki_childutime);
878 FOREACH_THREAD_IN_PROC(p, td0)
879 kp->ki_cow += td0->td_cow;
883 kp->ki_pgid = p->p_pgrp->pg_id;
884 kp->ki_jobc = p->p_pgrp->pg_jobc;
885 sp = p->p_pgrp->pg_session;
888 kp->ki_sid = sp->s_sid;
890 strlcpy(kp->ki_login, sp->s_login,
891 sizeof(kp->ki_login));
893 kp->ki_kiflag |= KI_CTTY;
895 kp->ki_kiflag |= KI_SLEADER;
896 /* XXX proctree_lock */
901 if ((p->p_flag & P_CONTROLT) && tp != NULL) {
902 kp->ki_tdev = tty_udev(tp);
903 kp->ki_tpgid = tp->t_pgrp ? tp->t_pgrp->pg_id : NO_PID;
905 kp->ki_tsid = tp->t_session->s_sid;
908 if (p->p_comm[0] != '\0')
909 strlcpy(kp->ki_comm, p->p_comm, sizeof(kp->ki_comm));
910 if (p->p_sysent && p->p_sysent->sv_name != NULL &&
911 p->p_sysent->sv_name[0] != '\0')
912 strlcpy(kp->ki_emul, p->p_sysent->sv_name, sizeof(kp->ki_emul));
913 kp->ki_siglist = p->p_siglist;
914 kp->ki_xstat = p->p_xstat;
915 kp->ki_acflag = p->p_acflag;
916 kp->ki_lock = p->p_lock;
918 kp->ki_ppid = p->p_pptr->p_pid;
922 * Fill in information that is thread specific. Must be called with
923 * target process locked. If 'preferthread' is set, overwrite certain
924 * process-related fields that are maintained for both threads and
928 fill_kinfo_thread(struct thread *td, struct kinfo_proc *kp, int preferthread)
934 PROC_LOCK_ASSERT(p, MA_OWNED);
939 if (td->td_wmesg != NULL)
940 strlcpy(kp->ki_wmesg, td->td_wmesg, sizeof(kp->ki_wmesg));
942 bzero(kp->ki_wmesg, sizeof(kp->ki_wmesg));
943 strlcpy(kp->ki_tdname, td->td_name, sizeof(kp->ki_tdname));
944 if (TD_ON_LOCK(td)) {
945 kp->ki_kiflag |= KI_LOCKBLOCK;
946 strlcpy(kp->ki_lockname, td->td_lockname,
947 sizeof(kp->ki_lockname));
949 kp->ki_kiflag &= ~KI_LOCKBLOCK;
950 bzero(kp->ki_lockname, sizeof(kp->ki_lockname));
953 if (p->p_state == PRS_NORMAL) { /* approximate. */
954 if (TD_ON_RUNQ(td) ||
958 } else if (P_SHOULDSTOP(p)) {
960 } else if (TD_IS_SLEEPING(td)) {
961 kp->ki_stat = SSLEEP;
962 } else if (TD_ON_LOCK(td)) {
967 } else if (p->p_state == PRS_ZOMBIE) {
973 /* Things in the thread */
974 kp->ki_wchan = td->td_wchan;
975 kp->ki_pri.pri_level = td->td_priority;
976 kp->ki_pri.pri_native = td->td_base_pri;
977 kp->ki_lastcpu = td->td_lastcpu;
978 kp->ki_oncpu = td->td_oncpu;
979 kp->ki_tdflags = td->td_flags;
980 kp->ki_tid = td->td_tid;
981 kp->ki_numthreads = p->p_numthreads;
982 kp->ki_pcb = td->td_pcb;
983 kp->ki_kstack = (void *)td->td_kstack;
984 kp->ki_slptime = (ticks - td->td_slptick) / hz;
985 kp->ki_pri.pri_class = td->td_pri_class;
986 kp->ki_pri.pri_user = td->td_user_pri;
989 rufetchtd(td, &kp->ki_rusage);
990 kp->ki_runtime = cputick2usec(td->td_rux.rux_runtime);
991 kp->ki_pctcpu = sched_pctcpu(td);
992 kp->ki_estcpu = td->td_estcpu;
993 kp->ki_cow = td->td_cow;
996 /* We can't get this anymore but ps etc never used it anyway. */
1000 kp->ki_siglist = td->td_siglist;
1001 kp->ki_sigmask = td->td_sigmask;
1008 * Fill in a kinfo_proc structure for the specified process.
1009 * Must be called with the target process locked.
1012 fill_kinfo_proc(struct proc *p, struct kinfo_proc *kp)
1015 MPASS(FIRST_THREAD_IN_PROC(p) != NULL);
1017 fill_kinfo_proc_only(p, kp);
1018 fill_kinfo_thread(FIRST_THREAD_IN_PROC(p), kp, 0);
1019 fill_kinfo_aggregate(p, kp);
1026 return (malloc(sizeof(struct pstats), M_SUBPROC, M_ZERO|M_WAITOK));
1030 * Copy parts of p_stats; zero the rest of p_stats (statistics).
1033 pstats_fork(struct pstats *src, struct pstats *dst)
1036 bzero(&dst->pstat_startzero,
1037 __rangeof(struct pstats, pstat_startzero, pstat_endzero));
1038 bcopy(&src->pstat_startcopy, &dst->pstat_startcopy,
1039 __rangeof(struct pstats, pstat_startcopy, pstat_endcopy));
1043 pstats_free(struct pstats *ps)
1046 free(ps, M_SUBPROC);
1049 static struct proc *
1050 zpfind_locked(pid_t pid)
1054 sx_assert(&allproc_lock, SX_LOCKED);
1055 LIST_FOREACH(p, &zombproc, p_list) {
1056 if (p->p_pid == pid) {
1065 * Locate a zombie process by number
1072 sx_slock(&allproc_lock);
1073 p = zpfind_locked(pid);
1074 sx_sunlock(&allproc_lock);
1078 #ifdef COMPAT_FREEBSD32
1081 * This function is typically used to copy out the kernel address, so
1082 * it can be replaced by assignment of zero.
1084 static inline uint32_t
1085 ptr32_trim(void *ptr)
1089 uptr = (uintptr_t)ptr;
1090 return ((uptr > UINT_MAX) ? 0 : uptr);
1093 #define PTRTRIM_CP(src,dst,fld) \
1094 do { (dst).fld = ptr32_trim((src).fld); } while (0)
1097 freebsd32_kinfo_proc_out(const struct kinfo_proc *ki, struct kinfo_proc32 *ki32)
1101 bzero(ki32, sizeof(struct kinfo_proc32));
1102 ki32->ki_structsize = sizeof(struct kinfo_proc32);
1103 CP(*ki, *ki32, ki_layout);
1104 PTRTRIM_CP(*ki, *ki32, ki_args);
1105 PTRTRIM_CP(*ki, *ki32, ki_paddr);
1106 PTRTRIM_CP(*ki, *ki32, ki_addr);
1107 PTRTRIM_CP(*ki, *ki32, ki_tracep);
1108 PTRTRIM_CP(*ki, *ki32, ki_textvp);
1109 PTRTRIM_CP(*ki, *ki32, ki_fd);
1110 PTRTRIM_CP(*ki, *ki32, ki_vmspace);
1111 PTRTRIM_CP(*ki, *ki32, ki_wchan);
1112 CP(*ki, *ki32, ki_pid);
1113 CP(*ki, *ki32, ki_ppid);
1114 CP(*ki, *ki32, ki_pgid);
1115 CP(*ki, *ki32, ki_tpgid);
1116 CP(*ki, *ki32, ki_sid);
1117 CP(*ki, *ki32, ki_tsid);
1118 CP(*ki, *ki32, ki_jobc);
1119 CP(*ki, *ki32, ki_tdev);
1120 CP(*ki, *ki32, ki_siglist);
1121 CP(*ki, *ki32, ki_sigmask);
1122 CP(*ki, *ki32, ki_sigignore);
1123 CP(*ki, *ki32, ki_sigcatch);
1124 CP(*ki, *ki32, ki_uid);
1125 CP(*ki, *ki32, ki_ruid);
1126 CP(*ki, *ki32, ki_svuid);
1127 CP(*ki, *ki32, ki_rgid);
1128 CP(*ki, *ki32, ki_svgid);
1129 CP(*ki, *ki32, ki_ngroups);
1130 for (i = 0; i < KI_NGROUPS; i++)
1131 CP(*ki, *ki32, ki_groups[i]);
1132 CP(*ki, *ki32, ki_size);
1133 CP(*ki, *ki32, ki_rssize);
1134 CP(*ki, *ki32, ki_swrss);
1135 CP(*ki, *ki32, ki_tsize);
1136 CP(*ki, *ki32, ki_dsize);
1137 CP(*ki, *ki32, ki_ssize);
1138 CP(*ki, *ki32, ki_xstat);
1139 CP(*ki, *ki32, ki_acflag);
1140 CP(*ki, *ki32, ki_pctcpu);
1141 CP(*ki, *ki32, ki_estcpu);
1142 CP(*ki, *ki32, ki_slptime);
1143 CP(*ki, *ki32, ki_swtime);
1144 CP(*ki, *ki32, ki_cow);
1145 CP(*ki, *ki32, ki_runtime);
1146 TV_CP(*ki, *ki32, ki_start);
1147 TV_CP(*ki, *ki32, ki_childtime);
1148 CP(*ki, *ki32, ki_flag);
1149 CP(*ki, *ki32, ki_kiflag);
1150 CP(*ki, *ki32, ki_traceflag);
1151 CP(*ki, *ki32, ki_stat);
1152 CP(*ki, *ki32, ki_nice);
1153 CP(*ki, *ki32, ki_lock);
1154 CP(*ki, *ki32, ki_rqindex);
1155 CP(*ki, *ki32, ki_oncpu);
1156 CP(*ki, *ki32, ki_lastcpu);
1157 bcopy(ki->ki_tdname, ki32->ki_tdname, TDNAMLEN + 1);
1158 bcopy(ki->ki_wmesg, ki32->ki_wmesg, WMESGLEN + 1);
1159 bcopy(ki->ki_login, ki32->ki_login, LOGNAMELEN + 1);
1160 bcopy(ki->ki_lockname, ki32->ki_lockname, LOCKNAMELEN + 1);
1161 bcopy(ki->ki_comm, ki32->ki_comm, COMMLEN + 1);
1162 bcopy(ki->ki_emul, ki32->ki_emul, KI_EMULNAMELEN + 1);
1163 bcopy(ki->ki_loginclass, ki32->ki_loginclass, LOGINCLASSLEN + 1);
1164 CP(*ki, *ki32, ki_flag2);
1165 CP(*ki, *ki32, ki_fibnum);
1166 CP(*ki, *ki32, ki_cr_flags);
1167 CP(*ki, *ki32, ki_jid);
1168 CP(*ki, *ki32, ki_numthreads);
1169 CP(*ki, *ki32, ki_tid);
1170 CP(*ki, *ki32, ki_pri);
1171 freebsd32_rusage_out(&ki->ki_rusage, &ki32->ki_rusage);
1172 freebsd32_rusage_out(&ki->ki_rusage_ch, &ki32->ki_rusage_ch);
1173 PTRTRIM_CP(*ki, *ki32, ki_pcb);
1174 PTRTRIM_CP(*ki, *ki32, ki_kstack);
1175 PTRTRIM_CP(*ki, *ki32, ki_udata);
1176 CP(*ki, *ki32, ki_sflag);
1177 CP(*ki, *ki32, ki_tdflags);
1182 kern_proc_out(struct proc *p, struct sbuf *sb, int flags)
1185 struct kinfo_proc ki;
1186 #ifdef COMPAT_FREEBSD32
1187 struct kinfo_proc32 ki32;
1191 PROC_LOCK_ASSERT(p, MA_OWNED);
1192 MPASS(FIRST_THREAD_IN_PROC(p) != NULL);
1195 fill_kinfo_proc(p, &ki);
1196 if ((flags & KERN_PROC_NOTHREADS) != 0) {
1197 #ifdef COMPAT_FREEBSD32
1198 if ((flags & KERN_PROC_MASK32) != 0) {
1199 freebsd32_kinfo_proc_out(&ki, &ki32);
1200 error = sbuf_bcat(sb, &ki32, sizeof(ki32));
1203 error = sbuf_bcat(sb, &ki, sizeof(ki));
1205 FOREACH_THREAD_IN_PROC(p, td) {
1206 fill_kinfo_thread(td, &ki, 1);
1207 #ifdef COMPAT_FREEBSD32
1208 if ((flags & KERN_PROC_MASK32) != 0) {
1209 freebsd32_kinfo_proc_out(&ki, &ki32);
1210 error = sbuf_bcat(sb, &ki32, sizeof(ki32));
1213 error = sbuf_bcat(sb, &ki, sizeof(ki));
1223 sysctl_out_proc(struct proc *p, struct sysctl_req *req, int flags,
1227 struct kinfo_proc ki;
1233 sbuf_new_for_sysctl(&sb, (char *)&ki, sizeof(ki), req);
1234 error = kern_proc_out(p, &sb, flags);
1235 error2 = sbuf_finish(&sb);
1239 else if (error2 != 0)
1259 sysctl_kern_proc(SYSCTL_HANDLER_ARGS)
1261 int *name = (int *)arg1;
1262 u_int namelen = arg2;
1264 int flags, doingzomb, oid_number;
1267 oid_number = oidp->oid_number;
1268 if (oid_number != KERN_PROC_ALL &&
1269 (oid_number & KERN_PROC_INC_THREAD) == 0)
1270 flags = KERN_PROC_NOTHREADS;
1273 oid_number &= ~KERN_PROC_INC_THREAD;
1275 #ifdef COMPAT_FREEBSD32
1276 if (req->flags & SCTL_MASK32)
1277 flags |= KERN_PROC_MASK32;
1279 if (oid_number == KERN_PROC_PID) {
1282 error = sysctl_wire_old_buffer(req, 0);
1285 error = pget((pid_t)name[0], PGET_CANSEE, &p);
1288 error = sysctl_out_proc(p, req, flags, 0);
1292 switch (oid_number) {
1297 case KERN_PROC_PROC:
1298 if (namelen != 0 && namelen != 1)
1308 /* overestimate by 5 procs */
1309 error = SYSCTL_OUT(req, 0, sizeof (struct kinfo_proc) * 5);
1313 error = sysctl_wire_old_buffer(req, 0);
1316 sx_slock(&allproc_lock);
1317 for (doingzomb=0 ; doingzomb < 2 ; doingzomb++) {
1319 p = LIST_FIRST(&allproc);
1321 p = LIST_FIRST(&zombproc);
1322 for (; p != 0; p = LIST_NEXT(p, p_list)) {
1324 * Skip embryonic processes.
1327 if (p->p_state == PRS_NEW) {
1331 KASSERT(p->p_ucred != NULL,
1332 ("process credential is NULL for non-NEW proc"));
1334 * Show a user only appropriate processes.
1336 if (p_cansee(curthread, p)) {
1341 * TODO - make more efficient (see notes below).
1344 switch (oid_number) {
1347 if (p->p_ucred->cr_gid != (gid_t)name[0]) {
1353 case KERN_PROC_PGRP:
1354 /* could do this by traversing pgrp */
1355 if (p->p_pgrp == NULL ||
1356 p->p_pgrp->pg_id != (pid_t)name[0]) {
1362 case KERN_PROC_RGID:
1363 if (p->p_ucred->cr_rgid != (gid_t)name[0]) {
1369 case KERN_PROC_SESSION:
1370 if (p->p_session == NULL ||
1371 p->p_session->s_sid != (pid_t)name[0]) {
1378 if ((p->p_flag & P_CONTROLT) == 0 ||
1379 p->p_session == NULL) {
1383 /* XXX proctree_lock */
1384 SESS_LOCK(p->p_session);
1385 if (p->p_session->s_ttyp == NULL ||
1386 tty_udev(p->p_session->s_ttyp) !=
1388 SESS_UNLOCK(p->p_session);
1392 SESS_UNLOCK(p->p_session);
1396 if (p->p_ucred->cr_uid != (uid_t)name[0]) {
1402 case KERN_PROC_RUID:
1403 if (p->p_ucred->cr_ruid != (uid_t)name[0]) {
1409 case KERN_PROC_PROC:
1417 error = sysctl_out_proc(p, req, flags, doingzomb);
1419 sx_sunlock(&allproc_lock);
1424 sx_sunlock(&allproc_lock);
1429 pargs_alloc(int len)
1433 pa = malloc(sizeof(struct pargs) + len, M_PARGS,
1435 refcount_init(&pa->ar_ref, 1);
1436 pa->ar_length = len;
1441 pargs_free(struct pargs *pa)
1448 pargs_hold(struct pargs *pa)
1453 refcount_acquire(&pa->ar_ref);
1457 pargs_drop(struct pargs *pa)
1462 if (refcount_release(&pa->ar_ref))
1467 proc_read_mem(struct thread *td, struct proc *p, vm_offset_t offset, void* buf,
1473 iov.iov_base = (caddr_t)buf;
1477 uio.uio_offset = offset;
1478 uio.uio_resid = (ssize_t)len;
1479 uio.uio_segflg = UIO_SYSSPACE;
1480 uio.uio_rw = UIO_READ;
1483 return (proc_rwmem(p, &uio));
1487 proc_read_string(struct thread *td, struct proc *p, const char *sptr, char *buf,
1493 error = proc_read_mem(td, p, (vm_offset_t)sptr, buf, len);
1495 * Reading the chunk may validly return EFAULT if the string is shorter
1496 * than the chunk and is aligned at the end of the page, assuming the
1497 * next page is not mapped. So if EFAULT is returned do a fallback to
1498 * one byte read loop.
1500 if (error == EFAULT) {
1501 for (i = 0; i < len; i++, buf++, sptr++) {
1502 error = proc_read_mem(td, p, (vm_offset_t)sptr, buf, 1);
1513 #define PROC_AUXV_MAX 256 /* Safety limit on auxv size. */
1515 enum proc_vector_type {
1521 #ifdef COMPAT_FREEBSD32
1523 get_proc_vector32(struct thread *td, struct proc *p, char ***proc_vectorp,
1524 size_t *vsizep, enum proc_vector_type type)
1526 struct freebsd32_ps_strings pss;
1528 vm_offset_t vptr, ptr;
1529 uint32_t *proc_vector32;
1534 error = proc_read_mem(td, p, (vm_offset_t)(p->p_sysent->sv_psstrings),
1540 vptr = (vm_offset_t)PTRIN(pss.ps_argvstr);
1541 vsize = pss.ps_nargvstr;
1542 if (vsize > ARG_MAX)
1544 size = vsize * sizeof(int32_t);
1547 vptr = (vm_offset_t)PTRIN(pss.ps_envstr);
1548 vsize = pss.ps_nenvstr;
1549 if (vsize > ARG_MAX)
1551 size = vsize * sizeof(int32_t);
1554 vptr = (vm_offset_t)PTRIN(pss.ps_envstr) +
1555 (pss.ps_nenvstr + 1) * sizeof(int32_t);
1558 for (ptr = vptr, i = 0; i < PROC_AUXV_MAX; i++) {
1559 error = proc_read_mem(td, p, ptr, &aux, sizeof(aux));
1562 if (aux.a_type == AT_NULL)
1566 if (aux.a_type != AT_NULL)
1569 size = vsize * sizeof(aux);
1572 KASSERT(0, ("Wrong proc vector type: %d", type));
1575 proc_vector32 = malloc(size, M_TEMP, M_WAITOK);
1576 error = proc_read_mem(td, p, vptr, proc_vector32, size);
1579 if (type == PROC_AUX) {
1580 *proc_vectorp = (char **)proc_vector32;
1584 proc_vector = malloc(vsize * sizeof(char *), M_TEMP, M_WAITOK);
1585 for (i = 0; i < (int)vsize; i++)
1586 proc_vector[i] = PTRIN(proc_vector32[i]);
1587 *proc_vectorp = proc_vector;
1590 free(proc_vector32, M_TEMP);
1596 get_proc_vector(struct thread *td, struct proc *p, char ***proc_vectorp,
1597 size_t *vsizep, enum proc_vector_type type)
1599 struct ps_strings pss;
1601 vm_offset_t vptr, ptr;
1606 #ifdef COMPAT_FREEBSD32
1607 if (SV_PROC_FLAG(p, SV_ILP32) != 0)
1608 return (get_proc_vector32(td, p, proc_vectorp, vsizep, type));
1610 error = proc_read_mem(td, p, (vm_offset_t)(p->p_sysent->sv_psstrings),
1616 vptr = (vm_offset_t)pss.ps_argvstr;
1617 vsize = pss.ps_nargvstr;
1618 if (vsize > ARG_MAX)
1620 size = vsize * sizeof(char *);
1623 vptr = (vm_offset_t)pss.ps_envstr;
1624 vsize = pss.ps_nenvstr;
1625 if (vsize > ARG_MAX)
1627 size = vsize * sizeof(char *);
1631 * The aux array is just above env array on the stack. Check
1632 * that the address is naturally aligned.
1634 vptr = (vm_offset_t)pss.ps_envstr + (pss.ps_nenvstr + 1)
1636 #if __ELF_WORD_SIZE == 64
1637 if (vptr % sizeof(uint64_t) != 0)
1639 if (vptr % sizeof(uint32_t) != 0)
1643 * We count the array size reading the aux vectors from the
1644 * stack until AT_NULL vector is returned. So (to keep the code
1645 * simple) we read the process stack twice: the first time here
1646 * to find the size and the second time when copying the vectors
1647 * to the allocated proc_vector.
1649 for (ptr = vptr, i = 0; i < PROC_AUXV_MAX; i++) {
1650 error = proc_read_mem(td, p, ptr, &aux, sizeof(aux));
1653 if (aux.a_type == AT_NULL)
1658 * If the PROC_AUXV_MAX entries are iterated over, and we have
1659 * not reached AT_NULL, it is most likely we are reading wrong
1660 * data: either the process doesn't have auxv array or data has
1661 * been modified. Return the error in this case.
1663 if (aux.a_type != AT_NULL)
1666 size = vsize * sizeof(aux);
1669 KASSERT(0, ("Wrong proc vector type: %d", type));
1670 return (EINVAL); /* In case we are built without INVARIANTS. */
1672 proc_vector = malloc(size, M_TEMP, M_WAITOK);
1673 if (proc_vector == NULL)
1675 error = proc_read_mem(td, p, vptr, proc_vector, size);
1677 free(proc_vector, M_TEMP);
1680 *proc_vectorp = proc_vector;
1686 #define GET_PS_STRINGS_CHUNK_SZ 256 /* Chunk size (bytes) for ps_strings operations. */
1689 get_ps_strings(struct thread *td, struct proc *p, struct sbuf *sb,
1690 enum proc_vector_type type)
1692 size_t done, len, nchr, vsize;
1694 char **proc_vector, *sptr;
1695 char pss_string[GET_PS_STRINGS_CHUNK_SZ];
1697 PROC_ASSERT_HELD(p);
1700 * We are not going to read more than 2 * (PATH_MAX + ARG_MAX) bytes.
1702 nchr = 2 * (PATH_MAX + ARG_MAX);
1704 error = get_proc_vector(td, p, &proc_vector, &vsize, type);
1707 for (done = 0, i = 0; i < (int)vsize && done < nchr; i++) {
1709 * The program may have scribbled into its argv array, e.g. to
1710 * remove some arguments. If that has happened, break out
1711 * before trying to read from NULL.
1713 if (proc_vector[i] == NULL)
1715 for (sptr = proc_vector[i]; ; sptr += GET_PS_STRINGS_CHUNK_SZ) {
1716 error = proc_read_string(td, p, sptr, pss_string,
1717 sizeof(pss_string));
1720 len = strnlen(pss_string, GET_PS_STRINGS_CHUNK_SZ);
1721 if (done + len >= nchr)
1722 len = nchr - done - 1;
1723 sbuf_bcat(sb, pss_string, len);
1724 if (len != GET_PS_STRINGS_CHUNK_SZ)
1726 done += GET_PS_STRINGS_CHUNK_SZ;
1728 sbuf_bcat(sb, "", 1);
1732 free(proc_vector, M_TEMP);
1737 proc_getargv(struct thread *td, struct proc *p, struct sbuf *sb)
1740 return (get_ps_strings(curthread, p, sb, PROC_ARG));
1744 proc_getenvv(struct thread *td, struct proc *p, struct sbuf *sb)
1747 return (get_ps_strings(curthread, p, sb, PROC_ENV));
1751 proc_getauxv(struct thread *td, struct proc *p, struct sbuf *sb)
1757 error = get_proc_vector(td, p, &auxv, &vsize, PROC_AUX);
1759 #ifdef COMPAT_FREEBSD32
1760 if (SV_PROC_FLAG(p, SV_ILP32) != 0)
1761 size = vsize * sizeof(Elf32_Auxinfo);
1764 size = vsize * sizeof(Elf_Auxinfo);
1765 error = sbuf_bcat(sb, auxv, size);
1772 * This sysctl allows a process to retrieve the argument list or process
1773 * title for another process without groping around in the address space
1774 * of the other process. It also allow a process to set its own "process
1775 * title to a string of its own choice.
1778 sysctl_kern_proc_args(SYSCTL_HANDLER_ARGS)
1780 int *name = (int *)arg1;
1781 u_int namelen = arg2;
1782 struct pargs *newpa, *pa;
1785 int flags, error = 0, error2;
1790 flags = PGET_CANSEE;
1791 if (req->newptr != NULL)
1792 flags |= PGET_ISCURRENT;
1793 error = pget((pid_t)name[0], flags, &p);
1801 error = SYSCTL_OUT(req, pa->ar_args, pa->ar_length);
1803 } else if ((p->p_flag & (P_WEXIT | P_SYSTEM)) == 0) {
1806 sbuf_new_for_sysctl(&sb, NULL, GET_PS_STRINGS_CHUNK_SZ, req);
1807 error = proc_getargv(curthread, p, &sb);
1808 error2 = sbuf_finish(&sb);
1811 if (error == 0 && error2 != 0)
1816 if (error != 0 || req->newptr == NULL)
1819 if (req->newlen + sizeof(struct pargs) > ps_arg_cache_limit)
1821 newpa = pargs_alloc(req->newlen);
1822 error = SYSCTL_IN(req, newpa->ar_args, req->newlen);
1836 * This sysctl allows a process to retrieve environment of another process.
1839 sysctl_kern_proc_env(SYSCTL_HANDLER_ARGS)
1841 int *name = (int *)arg1;
1842 u_int namelen = arg2;
1850 error = pget((pid_t)name[0], PGET_WANTREAD, &p);
1853 if ((p->p_flag & P_SYSTEM) != 0) {
1858 sbuf_new_for_sysctl(&sb, NULL, GET_PS_STRINGS_CHUNK_SZ, req);
1859 error = proc_getenvv(curthread, p, &sb);
1860 error2 = sbuf_finish(&sb);
1863 return (error != 0 ? error : error2);
1867 * This sysctl allows a process to retrieve ELF auxiliary vector of
1871 sysctl_kern_proc_auxv(SYSCTL_HANDLER_ARGS)
1873 int *name = (int *)arg1;
1874 u_int namelen = arg2;
1882 error = pget((pid_t)name[0], PGET_WANTREAD, &p);
1885 if ((p->p_flag & P_SYSTEM) != 0) {
1889 sbuf_new_for_sysctl(&sb, NULL, GET_PS_STRINGS_CHUNK_SZ, req);
1890 error = proc_getauxv(curthread, p, &sb);
1891 error2 = sbuf_finish(&sb);
1894 return (error != 0 ? error : error2);
1898 * This sysctl allows a process to retrieve the path of the executable for
1899 * itself or another process.
1902 sysctl_kern_proc_pathname(SYSCTL_HANDLER_ARGS)
1904 pid_t *pidp = (pid_t *)arg1;
1905 unsigned int arglen = arg2;
1908 char *retbuf, *freebuf;
1913 if (*pidp == -1) { /* -1 means this process */
1914 p = req->td->td_proc;
1916 error = pget(*pidp, PGET_CANSEE, &p);
1930 error = vn_fullpath(req->td, vp, &retbuf, &freebuf);
1934 error = SYSCTL_OUT(req, retbuf, strlen(retbuf) + 1);
1935 free(freebuf, M_TEMP);
1940 sysctl_kern_proc_sv_name(SYSCTL_HANDLER_ARGS)
1953 error = pget((pid_t)name[0], PGET_CANSEE, &p);
1956 sv_name = p->p_sysent->sv_name;
1958 return (sysctl_handle_string(oidp, sv_name, 0, req));
1961 #ifdef KINFO_OVMENTRY_SIZE
1962 CTASSERT(sizeof(struct kinfo_ovmentry) == KINFO_OVMENTRY_SIZE);
1965 #ifdef COMPAT_FREEBSD7
1967 sysctl_kern_proc_ovmmap(SYSCTL_HANDLER_ARGS)
1969 vm_map_entry_t entry, tmp_entry;
1970 unsigned int last_timestamp;
1971 char *fullpath, *freepath;
1972 struct kinfo_ovmentry *kve;
1982 error = pget((pid_t)name[0], PGET_WANTREAD, &p);
1985 vm = vmspace_acquire_ref(p);
1990 kve = malloc(sizeof(*kve), M_TEMP, M_WAITOK);
1993 vm_map_lock_read(map);
1994 for (entry = map->header.next; entry != &map->header;
1995 entry = entry->next) {
1996 vm_object_t obj, tobj, lobj;
1999 if (entry->eflags & MAP_ENTRY_IS_SUB_MAP)
2002 bzero(kve, sizeof(*kve));
2003 kve->kve_structsize = sizeof(*kve);
2005 kve->kve_private_resident = 0;
2006 obj = entry->object.vm_object;
2008 VM_OBJECT_RLOCK(obj);
2009 if (obj->shadow_count == 1)
2010 kve->kve_private_resident =
2011 obj->resident_page_count;
2013 kve->kve_resident = 0;
2014 addr = entry->start;
2015 while (addr < entry->end) {
2016 if (pmap_extract(map->pmap, addr))
2017 kve->kve_resident++;
2021 for (lobj = tobj = obj; tobj; tobj = tobj->backing_object) {
2023 VM_OBJECT_RLOCK(tobj);
2025 VM_OBJECT_RUNLOCK(lobj);
2029 kve->kve_start = (void*)entry->start;
2030 kve->kve_end = (void*)entry->end;
2031 kve->kve_offset = (off_t)entry->offset;
2033 if (entry->protection & VM_PROT_READ)
2034 kve->kve_protection |= KVME_PROT_READ;
2035 if (entry->protection & VM_PROT_WRITE)
2036 kve->kve_protection |= KVME_PROT_WRITE;
2037 if (entry->protection & VM_PROT_EXECUTE)
2038 kve->kve_protection |= KVME_PROT_EXEC;
2040 if (entry->eflags & MAP_ENTRY_COW)
2041 kve->kve_flags |= KVME_FLAG_COW;
2042 if (entry->eflags & MAP_ENTRY_NEEDS_COPY)
2043 kve->kve_flags |= KVME_FLAG_NEEDS_COPY;
2044 if (entry->eflags & MAP_ENTRY_NOCOREDUMP)
2045 kve->kve_flags |= KVME_FLAG_NOCOREDUMP;
2047 last_timestamp = map->timestamp;
2048 vm_map_unlock_read(map);
2050 kve->kve_fileid = 0;
2056 switch (lobj->type) {
2058 kve->kve_type = KVME_TYPE_DEFAULT;
2061 kve->kve_type = KVME_TYPE_VNODE;
2066 kve->kve_type = KVME_TYPE_SWAP;
2069 kve->kve_type = KVME_TYPE_DEVICE;
2072 kve->kve_type = KVME_TYPE_PHYS;
2075 kve->kve_type = KVME_TYPE_DEAD;
2078 kve->kve_type = KVME_TYPE_SG;
2081 kve->kve_type = KVME_TYPE_UNKNOWN;
2085 VM_OBJECT_RUNLOCK(lobj);
2087 kve->kve_ref_count = obj->ref_count;
2088 kve->kve_shadow_count = obj->shadow_count;
2089 VM_OBJECT_RUNLOCK(obj);
2091 vn_fullpath(curthread, vp, &fullpath,
2093 cred = curthread->td_ucred;
2094 vn_lock(vp, LK_SHARED | LK_RETRY);
2095 if (VOP_GETATTR(vp, &va, cred) == 0) {
2096 kve->kve_fileid = va.va_fileid;
2097 kve->kve_fsid = va.va_fsid;
2102 kve->kve_type = KVME_TYPE_NONE;
2103 kve->kve_ref_count = 0;
2104 kve->kve_shadow_count = 0;
2107 strlcpy(kve->kve_path, fullpath, sizeof(kve->kve_path));
2108 if (freepath != NULL)
2109 free(freepath, M_TEMP);
2111 error = SYSCTL_OUT(req, kve, sizeof(*kve));
2112 vm_map_lock_read(map);
2115 if (last_timestamp != map->timestamp) {
2116 vm_map_lookup_entry(map, addr - 1, &tmp_entry);
2120 vm_map_unlock_read(map);
2126 #endif /* COMPAT_FREEBSD7 */
2128 #ifdef KINFO_VMENTRY_SIZE
2129 CTASSERT(sizeof(struct kinfo_vmentry) == KINFO_VMENTRY_SIZE);
2133 * Must be called with the process locked and will return unlocked.
2136 kern_proc_vmmap_out(struct proc *p, struct sbuf *sb)
2138 vm_map_entry_t entry, tmp_entry;
2139 unsigned int last_timestamp;
2140 char *fullpath, *freepath;
2141 struct kinfo_vmentry *kve;
2149 PROC_LOCK_ASSERT(p, MA_OWNED);
2153 vm = vmspace_acquire_ref(p);
2158 kve = malloc(sizeof(*kve), M_TEMP, M_WAITOK);
2162 vm_map_lock_read(map);
2163 for (entry = map->header.next; entry != &map->header;
2164 entry = entry->next) {
2165 vm_object_t obj, tobj, lobj;
2167 vm_paddr_t locked_pa;
2170 if (entry->eflags & MAP_ENTRY_IS_SUB_MAP)
2173 bzero(kve, sizeof(*kve));
2175 kve->kve_private_resident = 0;
2176 obj = entry->object.vm_object;
2178 VM_OBJECT_RLOCK(obj);
2179 if (obj->shadow_count == 1)
2180 kve->kve_private_resident =
2181 obj->resident_page_count;
2183 kve->kve_resident = 0;
2184 addr = entry->start;
2185 while (addr < entry->end) {
2187 mincoreinfo = pmap_mincore(map->pmap, addr, &locked_pa);
2189 vm_page_unlock(PHYS_TO_VM_PAGE(locked_pa));
2190 if (mincoreinfo & MINCORE_INCORE)
2191 kve->kve_resident++;
2192 if (mincoreinfo & MINCORE_SUPER)
2193 kve->kve_flags |= KVME_FLAG_SUPER;
2197 for (lobj = tobj = obj; tobj; tobj = tobj->backing_object) {
2199 VM_OBJECT_RLOCK(tobj);
2201 VM_OBJECT_RUNLOCK(lobj);
2205 kve->kve_start = entry->start;
2206 kve->kve_end = entry->end;
2207 kve->kve_offset = entry->offset;
2209 if (entry->protection & VM_PROT_READ)
2210 kve->kve_protection |= KVME_PROT_READ;
2211 if (entry->protection & VM_PROT_WRITE)
2212 kve->kve_protection |= KVME_PROT_WRITE;
2213 if (entry->protection & VM_PROT_EXECUTE)
2214 kve->kve_protection |= KVME_PROT_EXEC;
2216 if (entry->eflags & MAP_ENTRY_COW)
2217 kve->kve_flags |= KVME_FLAG_COW;
2218 if (entry->eflags & MAP_ENTRY_NEEDS_COPY)
2219 kve->kve_flags |= KVME_FLAG_NEEDS_COPY;
2220 if (entry->eflags & MAP_ENTRY_NOCOREDUMP)
2221 kve->kve_flags |= KVME_FLAG_NOCOREDUMP;
2222 if (entry->eflags & MAP_ENTRY_GROWS_UP)
2223 kve->kve_flags |= KVME_FLAG_GROWS_UP;
2224 if (entry->eflags & MAP_ENTRY_GROWS_DOWN)
2225 kve->kve_flags |= KVME_FLAG_GROWS_DOWN;
2227 last_timestamp = map->timestamp;
2228 vm_map_unlock_read(map);
2234 switch (lobj->type) {
2236 kve->kve_type = KVME_TYPE_DEFAULT;
2239 kve->kve_type = KVME_TYPE_VNODE;
2244 kve->kve_type = KVME_TYPE_SWAP;
2247 kve->kve_type = KVME_TYPE_DEVICE;
2250 kve->kve_type = KVME_TYPE_PHYS;
2253 kve->kve_type = KVME_TYPE_DEAD;
2256 kve->kve_type = KVME_TYPE_SG;
2258 case OBJT_MGTDEVICE:
2259 kve->kve_type = KVME_TYPE_MGTDEVICE;
2262 kve->kve_type = KVME_TYPE_UNKNOWN;
2266 VM_OBJECT_RUNLOCK(lobj);
2268 kve->kve_ref_count = obj->ref_count;
2269 kve->kve_shadow_count = obj->shadow_count;
2270 VM_OBJECT_RUNLOCK(obj);
2272 vn_fullpath(curthread, vp, &fullpath,
2274 kve->kve_vn_type = vntype_to_kinfo(vp->v_type);
2275 cred = curthread->td_ucred;
2276 vn_lock(vp, LK_SHARED | LK_RETRY);
2277 if (VOP_GETATTR(vp, &va, cred) == 0) {
2278 kve->kve_vn_fileid = va.va_fileid;
2279 kve->kve_vn_fsid = va.va_fsid;
2281 MAKEIMODE(va.va_type, va.va_mode);
2282 kve->kve_vn_size = va.va_size;
2283 kve->kve_vn_rdev = va.va_rdev;
2284 kve->kve_status = KF_ATTR_VALID;
2289 kve->kve_type = KVME_TYPE_NONE;
2290 kve->kve_ref_count = 0;
2291 kve->kve_shadow_count = 0;
2294 strlcpy(kve->kve_path, fullpath, sizeof(kve->kve_path));
2295 if (freepath != NULL)
2296 free(freepath, M_TEMP);
2298 /* Pack record size down */
2299 kve->kve_structsize = offsetof(struct kinfo_vmentry, kve_path) +
2300 strlen(kve->kve_path) + 1;
2301 kve->kve_structsize = roundup(kve->kve_structsize,
2303 error = sbuf_bcat(sb, kve, kve->kve_structsize);
2304 vm_map_lock_read(map);
2307 if (last_timestamp != map->timestamp) {
2308 vm_map_lookup_entry(map, addr - 1, &tmp_entry);
2312 vm_map_unlock_read(map);
2320 sysctl_kern_proc_vmmap(SYSCTL_HANDLER_ARGS)
2324 int error, error2, *name;
2327 sbuf_new_for_sysctl(&sb, NULL, sizeof(struct kinfo_vmentry), req);
2328 error = pget((pid_t)name[0], PGET_CANDEBUG | PGET_NOTWEXIT, &p);
2333 error = kern_proc_vmmap_out(p, &sb);
2334 error2 = sbuf_finish(&sb);
2336 return (error != 0 ? error : error2);
2339 #if defined(STACK) || defined(DDB)
2341 sysctl_kern_proc_kstack(SYSCTL_HANDLER_ARGS)
2343 struct kinfo_kstack *kkstp;
2344 int error, i, *name, numthreads;
2345 lwpid_t *lwpidarray;
2352 error = pget((pid_t)name[0], PGET_NOTINEXEC | PGET_WANTREAD, &p);
2356 kkstp = malloc(sizeof(*kkstp), M_TEMP, M_WAITOK);
2357 st = stack_create();
2363 if (numthreads < p->p_numthreads) {
2364 if (lwpidarray != NULL) {
2365 free(lwpidarray, M_TEMP);
2368 numthreads = p->p_numthreads;
2370 lwpidarray = malloc(sizeof(*lwpidarray) * numthreads, M_TEMP,
2378 * XXXRW: During the below loop, execve(2) and countless other sorts
2379 * of changes could have taken place. Should we check to see if the
2380 * vmspace has been replaced, or the like, in order to prevent
2381 * giving a snapshot that spans, say, execve(2), with some threads
2382 * before and some after? Among other things, the credentials could
2383 * have changed, in which case the right to extract debug info might
2384 * no longer be assured.
2386 FOREACH_THREAD_IN_PROC(p, td) {
2387 KASSERT(i < numthreads,
2388 ("sysctl_kern_proc_kstack: numthreads"));
2389 lwpidarray[i] = td->td_tid;
2393 for (i = 0; i < numthreads; i++) {
2394 td = thread_find(p, lwpidarray[i]);
2398 bzero(kkstp, sizeof(*kkstp));
2399 (void)sbuf_new(&sb, kkstp->kkst_trace,
2400 sizeof(kkstp->kkst_trace), SBUF_FIXEDLEN);
2402 kkstp->kkst_tid = td->td_tid;
2403 if (TD_IS_SWAPPED(td))
2404 kkstp->kkst_state = KKST_STATE_SWAPPED;
2405 else if (TD_IS_RUNNING(td))
2406 kkstp->kkst_state = KKST_STATE_RUNNING;
2408 kkstp->kkst_state = KKST_STATE_STACKOK;
2409 stack_save_td(st, td);
2413 stack_sbuf_print(&sb, st);
2416 error = SYSCTL_OUT(req, kkstp, sizeof(*kkstp));
2423 if (lwpidarray != NULL)
2424 free(lwpidarray, M_TEMP);
2426 free(kkstp, M_TEMP);
2432 * This sysctl allows a process to retrieve the full list of groups from
2433 * itself or another process.
2436 sysctl_kern_proc_groups(SYSCTL_HANDLER_ARGS)
2438 pid_t *pidp = (pid_t *)arg1;
2439 unsigned int arglen = arg2;
2446 if (*pidp == -1) { /* -1 means this process */
2447 p = req->td->td_proc;
2449 error = pget(*pidp, PGET_CANSEE, &p);
2454 cred = crhold(p->p_ucred);
2458 error = SYSCTL_OUT(req, cred->cr_groups,
2459 cred->cr_ngroups * sizeof(gid_t));
2465 * This sysctl allows a process to retrieve or/and set the resource limit for
2469 sysctl_kern_proc_rlimit(SYSCTL_HANDLER_ARGS)
2471 int *name = (int *)arg1;
2472 u_int namelen = arg2;
2481 which = (u_int)name[1];
2482 if (which >= RLIM_NLIMITS)
2485 if (req->newptr != NULL && req->newlen != sizeof(rlim))
2488 flags = PGET_HOLD | PGET_NOTWEXIT;
2489 if (req->newptr != NULL)
2490 flags |= PGET_CANDEBUG;
2492 flags |= PGET_CANSEE;
2493 error = pget((pid_t)name[0], flags, &p);
2500 if (req->oldptr != NULL) {
2502 lim_rlimit(p, which, &rlim);
2505 error = SYSCTL_OUT(req, &rlim, sizeof(rlim));
2512 if (req->newptr != NULL) {
2513 error = SYSCTL_IN(req, &rlim, sizeof(rlim));
2515 error = kern_proc_setrlimit(curthread, p, which, &rlim);
2524 * This sysctl allows a process to retrieve ps_strings structure location of
2528 sysctl_kern_proc_ps_strings(SYSCTL_HANDLER_ARGS)
2530 int *name = (int *)arg1;
2531 u_int namelen = arg2;
2533 vm_offset_t ps_strings;
2535 #ifdef COMPAT_FREEBSD32
2536 uint32_t ps_strings32;
2542 error = pget((pid_t)name[0], PGET_CANDEBUG, &p);
2545 #ifdef COMPAT_FREEBSD32
2546 if ((req->flags & SCTL_MASK32) != 0) {
2548 * We return 0 if the 32 bit emulation request is for a 64 bit
2551 ps_strings32 = SV_PROC_FLAG(p, SV_ILP32) != 0 ?
2552 PTROUT(p->p_sysent->sv_psstrings) : 0;
2554 error = SYSCTL_OUT(req, &ps_strings32, sizeof(ps_strings32));
2558 ps_strings = p->p_sysent->sv_psstrings;
2560 error = SYSCTL_OUT(req, &ps_strings, sizeof(ps_strings));
2565 * This sysctl allows a process to retrieve umask of another process.
2568 sysctl_kern_proc_umask(SYSCTL_HANDLER_ARGS)
2570 int *name = (int *)arg1;
2571 u_int namelen = arg2;
2579 error = pget((pid_t)name[0], PGET_WANTREAD, &p);
2583 FILEDESC_SLOCK(p->p_fd);
2584 fd_cmask = p->p_fd->fd_cmask;
2585 FILEDESC_SUNLOCK(p->p_fd);
2587 error = SYSCTL_OUT(req, &fd_cmask, sizeof(fd_cmask));
2592 * This sysctl allows a process to set and retrieve binary osreldate of
2596 sysctl_kern_proc_osrel(SYSCTL_HANDLER_ARGS)
2598 int *name = (int *)arg1;
2599 u_int namelen = arg2;
2601 int flags, error, osrel;
2606 if (req->newptr != NULL && req->newlen != sizeof(osrel))
2609 flags = PGET_HOLD | PGET_NOTWEXIT;
2610 if (req->newptr != NULL)
2611 flags |= PGET_CANDEBUG;
2613 flags |= PGET_CANSEE;
2614 error = pget((pid_t)name[0], flags, &p);
2618 error = SYSCTL_OUT(req, &p->p_osrel, sizeof(p->p_osrel));
2622 if (req->newptr != NULL) {
2623 error = SYSCTL_IN(req, &osrel, sizeof(osrel));
2638 sysctl_kern_proc_sigtramp(SYSCTL_HANDLER_ARGS)
2640 int *name = (int *)arg1;
2641 u_int namelen = arg2;
2643 struct kinfo_sigtramp kst;
2644 const struct sysentvec *sv;
2646 #ifdef COMPAT_FREEBSD32
2647 struct kinfo_sigtramp32 kst32;
2653 error = pget((pid_t)name[0], PGET_CANDEBUG, &p);
2657 #ifdef COMPAT_FREEBSD32
2658 if ((req->flags & SCTL_MASK32) != 0) {
2659 bzero(&kst32, sizeof(kst32));
2660 if (SV_PROC_FLAG(p, SV_ILP32)) {
2661 if (sv->sv_sigcode_base != 0) {
2662 kst32.ksigtramp_start = sv->sv_sigcode_base;
2663 kst32.ksigtramp_end = sv->sv_sigcode_base +
2666 kst32.ksigtramp_start = sv->sv_psstrings -
2668 kst32.ksigtramp_end = sv->sv_psstrings;
2672 error = SYSCTL_OUT(req, &kst32, sizeof(kst32));
2676 bzero(&kst, sizeof(kst));
2677 if (sv->sv_sigcode_base != 0) {
2678 kst.ksigtramp_start = (char *)sv->sv_sigcode_base;
2679 kst.ksigtramp_end = (char *)sv->sv_sigcode_base +
2682 kst.ksigtramp_start = (char *)sv->sv_psstrings -
2684 kst.ksigtramp_end = (char *)sv->sv_psstrings;
2687 error = SYSCTL_OUT(req, &kst, sizeof(kst));
2691 SYSCTL_NODE(_kern, KERN_PROC, proc, CTLFLAG_RD, 0, "Process table");
2693 SYSCTL_PROC(_kern_proc, KERN_PROC_ALL, all, CTLFLAG_RD|CTLTYPE_STRUCT|
2694 CTLFLAG_MPSAFE, 0, 0, sysctl_kern_proc, "S,proc",
2695 "Return entire process table");
2697 static SYSCTL_NODE(_kern_proc, KERN_PROC_GID, gid, CTLFLAG_RD | CTLFLAG_MPSAFE,
2698 sysctl_kern_proc, "Process table");
2700 static SYSCTL_NODE(_kern_proc, KERN_PROC_PGRP, pgrp, CTLFLAG_RD | CTLFLAG_MPSAFE,
2701 sysctl_kern_proc, "Process table");
2703 static SYSCTL_NODE(_kern_proc, KERN_PROC_RGID, rgid, CTLFLAG_RD | CTLFLAG_MPSAFE,
2704 sysctl_kern_proc, "Process table");
2706 static SYSCTL_NODE(_kern_proc, KERN_PROC_SESSION, sid, CTLFLAG_RD |
2707 CTLFLAG_MPSAFE, sysctl_kern_proc, "Process table");
2709 static SYSCTL_NODE(_kern_proc, KERN_PROC_TTY, tty, CTLFLAG_RD | CTLFLAG_MPSAFE,
2710 sysctl_kern_proc, "Process table");
2712 static SYSCTL_NODE(_kern_proc, KERN_PROC_UID, uid, CTLFLAG_RD | CTLFLAG_MPSAFE,
2713 sysctl_kern_proc, "Process table");
2715 static SYSCTL_NODE(_kern_proc, KERN_PROC_RUID, ruid, CTLFLAG_RD | CTLFLAG_MPSAFE,
2716 sysctl_kern_proc, "Process table");
2718 static SYSCTL_NODE(_kern_proc, KERN_PROC_PID, pid, CTLFLAG_RD | CTLFLAG_MPSAFE,
2719 sysctl_kern_proc, "Process table");
2721 static SYSCTL_NODE(_kern_proc, KERN_PROC_PROC, proc, CTLFLAG_RD | CTLFLAG_MPSAFE,
2722 sysctl_kern_proc, "Return process table, no threads");
2724 static SYSCTL_NODE(_kern_proc, KERN_PROC_ARGS, args,
2725 CTLFLAG_RW | CTLFLAG_ANYBODY | CTLFLAG_MPSAFE,
2726 sysctl_kern_proc_args, "Process argument list");
2728 static SYSCTL_NODE(_kern_proc, KERN_PROC_ENV, env, CTLFLAG_RD | CTLFLAG_MPSAFE,
2729 sysctl_kern_proc_env, "Process environment");
2731 static SYSCTL_NODE(_kern_proc, KERN_PROC_AUXV, auxv, CTLFLAG_RD |
2732 CTLFLAG_MPSAFE, sysctl_kern_proc_auxv, "Process ELF auxiliary vector");
2734 static SYSCTL_NODE(_kern_proc, KERN_PROC_PATHNAME, pathname, CTLFLAG_RD |
2735 CTLFLAG_MPSAFE, sysctl_kern_proc_pathname, "Process executable path");
2737 static SYSCTL_NODE(_kern_proc, KERN_PROC_SV_NAME, sv_name, CTLFLAG_RD |
2738 CTLFLAG_MPSAFE, sysctl_kern_proc_sv_name,
2739 "Process syscall vector name (ABI type)");
2741 static SYSCTL_NODE(_kern_proc, (KERN_PROC_GID | KERN_PROC_INC_THREAD), gid_td,
2742 CTLFLAG_RD | CTLFLAG_MPSAFE, sysctl_kern_proc, "Process table");
2744 static SYSCTL_NODE(_kern_proc, (KERN_PROC_PGRP | KERN_PROC_INC_THREAD), pgrp_td,
2745 CTLFLAG_RD | CTLFLAG_MPSAFE, sysctl_kern_proc, "Process table");
2747 static SYSCTL_NODE(_kern_proc, (KERN_PROC_RGID | KERN_PROC_INC_THREAD), rgid_td,
2748 CTLFLAG_RD | CTLFLAG_MPSAFE, sysctl_kern_proc, "Process table");
2750 static SYSCTL_NODE(_kern_proc, (KERN_PROC_SESSION | KERN_PROC_INC_THREAD),
2751 sid_td, CTLFLAG_RD | CTLFLAG_MPSAFE, sysctl_kern_proc, "Process table");
2753 static SYSCTL_NODE(_kern_proc, (KERN_PROC_TTY | KERN_PROC_INC_THREAD), tty_td,
2754 CTLFLAG_RD | CTLFLAG_MPSAFE, sysctl_kern_proc, "Process table");
2756 static SYSCTL_NODE(_kern_proc, (KERN_PROC_UID | KERN_PROC_INC_THREAD), uid_td,
2757 CTLFLAG_RD | CTLFLAG_MPSAFE, sysctl_kern_proc, "Process table");
2759 static SYSCTL_NODE(_kern_proc, (KERN_PROC_RUID | KERN_PROC_INC_THREAD), ruid_td,
2760 CTLFLAG_RD | CTLFLAG_MPSAFE, sysctl_kern_proc, "Process table");
2762 static SYSCTL_NODE(_kern_proc, (KERN_PROC_PID | KERN_PROC_INC_THREAD), pid_td,
2763 CTLFLAG_RD | CTLFLAG_MPSAFE, sysctl_kern_proc, "Process table");
2765 static SYSCTL_NODE(_kern_proc, (KERN_PROC_PROC | KERN_PROC_INC_THREAD), proc_td,
2766 CTLFLAG_RD | CTLFLAG_MPSAFE, sysctl_kern_proc,
2767 "Return process table, no threads");
2769 #ifdef COMPAT_FREEBSD7
2770 static SYSCTL_NODE(_kern_proc, KERN_PROC_OVMMAP, ovmmap, CTLFLAG_RD |
2771 CTLFLAG_MPSAFE, sysctl_kern_proc_ovmmap, "Old Process vm map entries");
2774 static SYSCTL_NODE(_kern_proc, KERN_PROC_VMMAP, vmmap, CTLFLAG_RD |
2775 CTLFLAG_MPSAFE, sysctl_kern_proc_vmmap, "Process vm map entries");
2777 #if defined(STACK) || defined(DDB)
2778 static SYSCTL_NODE(_kern_proc, KERN_PROC_KSTACK, kstack, CTLFLAG_RD |
2779 CTLFLAG_MPSAFE, sysctl_kern_proc_kstack, "Process kernel stacks");
2782 static SYSCTL_NODE(_kern_proc, KERN_PROC_GROUPS, groups, CTLFLAG_RD |
2783 CTLFLAG_MPSAFE, sysctl_kern_proc_groups, "Process groups");
2785 static SYSCTL_NODE(_kern_proc, KERN_PROC_RLIMIT, rlimit, CTLFLAG_RW |
2786 CTLFLAG_ANYBODY | CTLFLAG_MPSAFE, sysctl_kern_proc_rlimit,
2787 "Process resource limits");
2789 static SYSCTL_NODE(_kern_proc, KERN_PROC_PS_STRINGS, ps_strings, CTLFLAG_RD |
2790 CTLFLAG_MPSAFE, sysctl_kern_proc_ps_strings,
2791 "Process ps_strings location");
2793 static SYSCTL_NODE(_kern_proc, KERN_PROC_UMASK, umask, CTLFLAG_RD |
2794 CTLFLAG_MPSAFE, sysctl_kern_proc_umask, "Process umask");
2796 static SYSCTL_NODE(_kern_proc, KERN_PROC_OSREL, osrel, CTLFLAG_RW |
2797 CTLFLAG_ANYBODY | CTLFLAG_MPSAFE, sysctl_kern_proc_osrel,
2798 "Process binary osreldate");
2800 static SYSCTL_NODE(_kern_proc, KERN_PROC_SIGTRAMP, sigtramp, CTLFLAG_RD |
2801 CTLFLAG_MPSAFE, sysctl_kern_proc_sigtramp,
2802 "Process signal trampoline location");