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 * 3. 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
30 #include <sys/param.h>
31 #include <sys/systm.h>
32 #include <sys/kernel.h>
33 #include <sys/sysctl.h>
34 #include <sys/malloc.h>
36 #include <sys/vnode.h>
38 #include <sys/filedesc.h>
40 #include <sys/dsched.h>
41 #include <sys/signalvar.h>
42 #include <sys/spinlock.h>
43 #include <sys/random.h>
47 #include <sys/kinfo.h>
49 #include <vm/vm_map.h>
50 #include <machine/smp.h>
52 #include <sys/refcount.h>
53 #include <sys/spinlock2.h>
56 * Hash table size must be a power of two and is not currently dynamically
57 * sized. There is a trade-off between the linear scans which must iterate
58 * all HSIZE elements and the number of elements which might accumulate
59 * within each hash chain.
61 #define ALLPROC_HSIZE 256
62 #define ALLPROC_HMASK (ALLPROC_HSIZE - 1)
63 #define ALLPROC_HASH(pid) (pid & ALLPROC_HMASK)
64 #define PGRP_HASH(pid) (pid & ALLPROC_HMASK)
65 #define SESS_HASH(pid) (pid & ALLPROC_HMASK)
68 * pid_doms[] management, used to control how quickly a PID can be recycled.
69 * Must be a multiple of ALLPROC_HSIZE for the proc_makepid() inner loops.
71 * WARNING! PIDDOM_DELAY should not be defined > 20 or so unless you change
72 * the array from int8_t's to int16_t's.
74 #define PIDDOM_COUNT 10 /* 10 pids per domain - reduce array size */
75 #define PIDDOM_DELAY 10 /* min 10 seconds after exit before reuse */
76 #define PIDDOM_SCALE 10 /* (10,000*SCALE)/sec performance guarantee */
77 #define PIDSEL_DOMAINS rounddown(PID_MAX * PIDDOM_SCALE / PIDDOM_COUNT, ALLPROC_HSIZE)
80 int allproc_hsize = ALLPROC_HSIZE;
82 LIST_HEAD(pidhashhead, proc);
84 static MALLOC_DEFINE(M_PGRP, "pgrp", "process group header");
85 MALLOC_DEFINE(M_SESSION, "session", "session header");
86 MALLOC_DEFINE(M_PROC, "proc", "Proc structures");
87 MALLOC_DEFINE(M_LWP, "lwp", "lwp structures");
88 MALLOC_DEFINE(M_SUBPROC, "subproc", "Proc sub-structures");
89 MALLOC_DEFINE(M_UPMAP, "upmap", "upmap/kpmap/lpmap structures");
91 int ps_showallprocs = 1;
92 static int ps_showallthreads = 1;
93 SYSCTL_INT(_security, OID_AUTO, ps_showallprocs, CTLFLAG_RW,
95 "Unprivileged processes can see processes with different UID/GID");
96 SYSCTL_INT(_security, OID_AUTO, ps_showallthreads, CTLFLAG_RW,
97 &ps_showallthreads, 0,
98 "Unprivileged processes can see kernel threads");
99 static u_int pid_domain_skips;
100 SYSCTL_UINT(_kern, OID_AUTO, pid_domain_skips, CTLFLAG_RW,
101 &pid_domain_skips, 0,
102 "Number of pid_doms[] skipped");
103 static u_int pid_inner_skips;
104 SYSCTL_UINT(_kern, OID_AUTO, pid_inner_skips, CTLFLAG_RW,
106 "Number of pid_doms[] skipped");
108 static void orphanpg(struct pgrp *pg);
109 static void proc_makepid(struct proc *p, int random_offset);
112 * Process related lists (for proc_token, allproc, allpgrp, and allsess)
114 typedef struct procglob procglob_t;
116 static procglob_t procglob[ALLPROC_HSIZE];
119 * We try our best to avoid recycling a PID too quickly. We do this by
120 * storing (uint8_t)time_second in the related pid domain on-reap and then
121 * using that to skip-over the domain on-allocate.
123 * This array has to be fairly large to support a high fork/exec rate.
124 * A ~100,000 entry array will support a 10-second reuse latency at
125 * 10,000 execs/second, worst case. Best-case multiply by PIDDOM_COUNT
126 * (approximately 100,000 execs/second).
128 * Currently we allocate around a megabyte, making the worst-case fork
129 * rate around 100,000/second.
131 static uint8_t *pid_doms;
134 * Random component to nextpid generation. We mix in a random factor to make
135 * it a little harder to predict. We sanity check the modulus value to avoid
136 * doing it in critical paths. Don't let it be too small or we pointlessly
137 * waste randomness entropy, and don't let it be impossibly large. Using a
138 * modulus that is too big causes a LOT more process table scans and slows
139 * down fork processing as the pidchecked caching is defeated.
141 static int randompid = 0;
145 pcredcache(struct ucred *cr, struct proc *p)
147 if (cr != p->p_ucred) {
150 spin_lock(&p->p_spin);
151 if ((cr = p->p_ucred) != NULL)
153 spin_unlock(&p->p_spin);
162 sysctl_kern_randompid(SYSCTL_HANDLER_ARGS)
167 error = sysctl_handle_int(oidp, &pid, 0, req);
168 if (error || !req->newptr)
170 if (pid < 0 || pid > PID_MAX - 100) /* out of range */
172 else if (pid < 2) /* NOP */
174 else if (pid < 100) /* Make it reasonable */
180 SYSCTL_PROC(_kern, OID_AUTO, randompid, CTLTYPE_INT|CTLFLAG_RW,
181 0, 0, sysctl_kern_randompid, "I", "Random PID modulus");
184 * Initialize global process hashing structures.
186 * These functions are ONLY called from the low level boot code and do
187 * not lock their operations.
195 * Allocate dynamically. This array can be large (~1MB) so don't
196 * waste boot loader space.
198 pid_doms = kmalloc(sizeof(pid_doms[0]) * PIDSEL_DOMAINS,
199 M_PROC, M_WAITOK | M_ZERO);
202 * Avoid unnecessary stalls due to pid_doms[] values all being
203 * the same. Make sure that the allocation of pid 1 and pid 2
206 for (i = 0; i < PIDSEL_DOMAINS; ++i)
207 pid_doms[i] = (int8_t)i - (int8_t)(PIDDOM_DELAY + 1);
212 for (i = 0; i < ALLPROC_HSIZE; ++i) {
213 procglob_t *prg = &procglob[i];
214 LIST_INIT(&prg->allproc);
215 LIST_INIT(&prg->allsess);
216 LIST_INIT(&prg->allpgrp);
217 lwkt_token_init(&prg->proc_token, "allproc");
223 procinsertinit(struct proc *p)
225 LIST_INSERT_HEAD(&procglob[ALLPROC_HASH(p->p_pid)].allproc,
230 pgrpinsertinit(struct pgrp *pg)
232 LIST_INSERT_HEAD(&procglob[ALLPROC_HASH(pg->pg_id)].allpgrp,
237 sessinsertinit(struct session *sess)
239 LIST_INSERT_HEAD(&procglob[ALLPROC_HASH(sess->s_sid)].allsess,
244 * Process hold/release support functions. Called via the PHOLD(),
245 * PRELE(), and PSTALL() macros.
247 * p->p_lock is a simple hold count with a waiting interlock. No wakeup()
248 * is issued unless someone is actually waiting for the process.
250 * Most holds are short-term, allowing a process scan or other similar
251 * operation to access a proc structure without it getting ripped out from
252 * under us. procfs and process-list sysctl ops also use the hold function
253 * interlocked with various p_flags to keep the vmspace intact when reading
254 * or writing a user process's address space.
256 * There are two situations where a hold count can be longer. Exiting lwps
257 * hold the process until the lwp is reaped, and the parent will hold the
258 * child during vfork()/exec() sequences while the child is marked P_PPWAIT.
260 * The kernel waits for the hold count to drop to 0 (or 1 in some cases) at
261 * various critical points in the fork/exec and exit paths before proceeding.
263 #define PLOCK_ZOMB 0x20000000
264 #define PLOCK_WAITING 0x40000000
265 #define PLOCK_MASK 0x1FFFFFFF
268 pstall(struct proc *p, const char *wmesg, int count)
276 if ((o & PLOCK_MASK) <= count)
278 n = o | PLOCK_WAITING;
279 tsleep_interlock(&p->p_lock, 0);
282 * If someone is trying to single-step the process during
283 * an exec or an exit they can deadlock us because procfs
284 * sleeps with the process held.
287 if (p->p_flags & P_INEXEC) {
289 } else if (p->p_flags & P_POSTEXIT) {
290 spin_lock(&p->p_spin);
293 spin_unlock(&p->p_spin);
298 if (atomic_cmpset_int(&p->p_lock, o, n)) {
299 tsleep(&p->p_lock, PINTERLOCKED, wmesg, 0);
305 phold(struct proc *p)
307 atomic_add_int(&p->p_lock, 1);
311 * WARNING! On last release (p) can become instantly invalid due to
315 prele(struct proc *p)
323 if (atomic_cmpset_int(&p->p_lock, 1, 0))
331 KKASSERT((o & PLOCK_MASK) > 0);
333 n = (o - 1) & ~PLOCK_WAITING;
334 if (atomic_cmpset_int(&p->p_lock, o, n)) {
335 if (o & PLOCK_WAITING)
343 * Hold and flag serialized for zombie reaping purposes.
345 * This function will fail if it has to block, returning non-zero with
346 * neither the flag set or the hold count bumped. Note that (p) may
347 * not be valid in this case if the caller does not have some other
350 * This function does not block on other PHOLD()s, only on other
353 * Zero is returned on success. The hold count will be incremented and
354 * the serialization flag acquired. Note that serialization is only against
355 * other pholdzomb() calls, not against phold() calls.
358 pholdzomb(struct proc *p)
366 if (atomic_cmpset_int(&p->p_lock, 0, PLOCK_ZOMB | 1))
375 if ((o & PLOCK_ZOMB) == 0) {
376 n = (o + 1) | PLOCK_ZOMB;
377 if (atomic_cmpset_int(&p->p_lock, o, n))
380 KKASSERT((o & PLOCK_MASK) > 0);
381 n = o | PLOCK_WAITING;
382 tsleep_interlock(&p->p_lock, 0);
383 if (atomic_cmpset_int(&p->p_lock, o, n)) {
384 tsleep(&p->p_lock, PINTERLOCKED, "phldz", 0);
385 /* (p) can be ripped out at this point */
393 * Release PLOCK_ZOMB and the hold count, waking up any waiters.
395 * WARNING! On last release (p) can become instantly invalid due to
399 prelezomb(struct proc *p)
407 if (atomic_cmpset_int(&p->p_lock, PLOCK_ZOMB | 1, 0))
413 KKASSERT(p->p_lock & PLOCK_ZOMB);
416 KKASSERT((o & PLOCK_MASK) > 0);
418 n = (o - 1) & ~(PLOCK_ZOMB | PLOCK_WAITING);
419 if (atomic_cmpset_int(&p->p_lock, o, n)) {
420 if (o & PLOCK_WAITING)
428 * Is p an inferior of the current process?
433 inferior(struct proc *p)
438 lwkt_gettoken_shared(&p->p_token);
439 while (p != curproc) {
441 lwkt_reltoken(&p->p_token);
446 lwkt_reltoken(&p->p_token);
448 lwkt_gettoken_shared(&p2->p_token);
451 lwkt_reltoken(&p->p_token);
458 * Locate a process by number. The returned process will be referenced and
459 * must be released with PRELE().
466 struct proc *p = curproc;
471 * Shortcut the current process
473 if (p && p->p_pid == pid) {
479 * Otherwise find it in the hash table.
481 n = ALLPROC_HASH(pid);
484 lwkt_gettoken_shared(&prg->proc_token);
485 LIST_FOREACH(p, &prg->allproc, p_list) {
486 if (p->p_stat == SZOMB)
488 if (p->p_pid == pid) {
490 lwkt_reltoken(&prg->proc_token);
494 lwkt_reltoken(&prg->proc_token);
500 * Locate a process by number. The returned process is NOT referenced.
501 * The result will not be stable and is typically only used to validate
502 * against a process that the caller has in-hand.
509 struct proc *p = curproc;
514 * Shortcut the current process
516 if (p && p->p_pid == pid)
520 * Otherwise find it in the hash table.
522 n = ALLPROC_HASH(pid);
525 lwkt_gettoken_shared(&prg->proc_token);
526 LIST_FOREACH(p, &prg->allproc, p_list) {
527 if (p->p_stat == SZOMB)
529 if (p->p_pid == pid) {
530 lwkt_reltoken(&prg->proc_token);
534 lwkt_reltoken(&prg->proc_token);
540 * Locate a process on the zombie list. Return a process or NULL.
541 * The returned process will be referenced and the caller must release
544 * No other requirements.
549 struct proc *p = curproc;
554 * Shortcut the current process
556 if (p && p->p_pid == pid) {
562 * Otherwise find it in the hash table.
564 n = ALLPROC_HASH(pid);
567 lwkt_gettoken_shared(&prg->proc_token);
568 LIST_FOREACH(p, &prg->allproc, p_list) {
569 if (p->p_stat != SZOMB)
571 if (p->p_pid == pid) {
573 lwkt_reltoken(&prg->proc_token);
577 lwkt_reltoken(&prg->proc_token);
584 pgref(struct pgrp *pgrp)
586 refcount_acquire(&pgrp->pg_refs);
590 pgrel(struct pgrp *pgrp)
596 n = PGRP_HASH(pgrp->pg_id);
600 count = pgrp->pg_refs;
604 lwkt_gettoken(&prg->proc_token);
605 if (atomic_cmpset_int(&pgrp->pg_refs, 1, 0))
607 lwkt_reltoken(&prg->proc_token);
610 if (atomic_cmpset_int(&pgrp->pg_refs, count, count - 1))
617 * Successful 1->0 transition, pghash_spin is held.
619 LIST_REMOVE(pgrp, pg_list);
620 if (pid_doms[pgrp->pg_id % PIDSEL_DOMAINS] != (uint8_t)time_second)
621 pid_doms[pgrp->pg_id % PIDSEL_DOMAINS] = (uint8_t)time_second;
624 * Reset any sigio structures pointing to us as a result of
625 * F_SETOWN with our pgid.
627 funsetownlst(&pgrp->pg_sigiolst);
629 if (pgrp->pg_session->s_ttyp != NULL &&
630 pgrp->pg_session->s_ttyp->t_pgrp == pgrp) {
631 pgrp->pg_session->s_ttyp->t_pgrp = NULL;
633 lwkt_reltoken(&prg->proc_token);
635 sess_rele(pgrp->pg_session);
640 * Locate a process group by number. The returned process group will be
641 * referenced w/pgref() and must be released with pgrel() (or assigned
642 * somewhere if you wish to keep the reference).
655 lwkt_gettoken_shared(&prg->proc_token);
657 LIST_FOREACH(pgrp, &prg->allpgrp, pg_list) {
658 if (pgrp->pg_id == pgid) {
659 refcount_acquire(&pgrp->pg_refs);
660 lwkt_reltoken(&prg->proc_token);
664 lwkt_reltoken(&prg->proc_token);
669 * Move p to a new or existing process group (and session)
674 enterpgrp(struct proc *p, pid_t pgid, int mksess)
682 KASSERT(pgrp == NULL || !mksess,
683 ("enterpgrp: setsid into non-empty pgrp"));
684 KASSERT(!SESS_LEADER(p),
685 ("enterpgrp: session leader attempted setpgrp"));
688 pid_t savepid = p->p_pid;
696 KASSERT(p->p_pid == pgid,
697 ("enterpgrp: new pgrp and pid != pgid"));
698 pgrp = kmalloc(sizeof(struct pgrp), M_PGRP, M_WAITOK | M_ZERO);
700 LIST_INIT(&pgrp->pg_members);
702 SLIST_INIT(&pgrp->pg_sigiolst);
703 lwkt_token_init(&pgrp->pg_token, "pgrp_token");
704 refcount_init(&pgrp->pg_refs, 1);
705 lockinit(&pgrp->pg_lock, "pgwt", 0, 0);
710 if ((np = pfindn(savepid)) == NULL || np != p) {
711 lwkt_reltoken(&prg->proc_token);
717 lwkt_gettoken(&prg->proc_token);
719 struct session *sess;
724 sess = kmalloc(sizeof(struct session), M_SESSION,
726 lwkt_gettoken(&p->p_token);
729 sess->s_sid = p->p_pid;
731 sess->s_ttyvp = NULL;
733 bcopy(p->p_session->s_login, sess->s_login,
734 sizeof(sess->s_login));
735 pgrp->pg_session = sess;
736 KASSERT(p == curproc,
737 ("enterpgrp: mksession and p != curproc"));
738 p->p_flags &= ~P_CONTROLT;
739 LIST_INSERT_HEAD(&prg->allsess, sess, s_list);
740 lwkt_reltoken(&p->p_token);
742 lwkt_gettoken(&p->p_token);
743 pgrp->pg_session = p->p_session;
744 sess_hold(pgrp->pg_session);
745 lwkt_reltoken(&p->p_token);
747 LIST_INSERT_HEAD(&prg->allpgrp, pgrp, pg_list);
749 lwkt_reltoken(&prg->proc_token);
750 } else if (pgrp == p->p_pgrp) {
753 } /* else pgfind() referenced the pgrp */
755 lwkt_gettoken(&pgrp->pg_token);
756 lwkt_gettoken(&p->p_token);
759 * Replace p->p_pgrp, handling any races that occur.
761 while ((opgrp = p->p_pgrp) != NULL) {
763 lwkt_gettoken(&opgrp->pg_token);
764 if (opgrp != p->p_pgrp) {
765 lwkt_reltoken(&opgrp->pg_token);
769 LIST_REMOVE(p, p_pglist);
773 LIST_INSERT_HEAD(&pgrp->pg_members, p, p_pglist);
776 * Adjust eligibility of affected pgrps to participate in job control.
777 * Increment eligibility counts before decrementing, otherwise we
778 * could reach 0 spuriously during the first call.
782 fixjobc(p, opgrp, 0);
783 lwkt_reltoken(&opgrp->pg_token);
784 pgrel(opgrp); /* manual pgref */
785 pgrel(opgrp); /* p->p_pgrp ref */
787 lwkt_reltoken(&p->p_token);
788 lwkt_reltoken(&pgrp->pg_token);
796 * Remove process from process group
801 leavepgrp(struct proc *p)
803 struct pgrp *pg = p->p_pgrp;
805 lwkt_gettoken(&p->p_token);
806 while ((pg = p->p_pgrp) != NULL) {
808 lwkt_gettoken(&pg->pg_token);
809 if (p->p_pgrp != pg) {
810 lwkt_reltoken(&pg->pg_token);
815 LIST_REMOVE(p, p_pglist);
816 lwkt_reltoken(&pg->pg_token);
817 pgrel(pg); /* manual pgref */
818 pgrel(pg); /* p->p_pgrp ref */
821 lwkt_reltoken(&p->p_token);
827 * Adjust the ref count on a session structure. When the ref count falls to
828 * zero the tty is disassociated from the session and the session structure
829 * is freed. Note that tty assocation is not itself ref-counted.
834 sess_hold(struct session *sp)
836 atomic_add_int(&sp->s_count, 1);
843 sess_rele(struct session *sess)
850 n = SESS_HASH(sess->s_sid);
854 count = sess->s_count;
858 lwkt_gettoken(&prg->proc_token);
859 if (atomic_cmpset_int(&sess->s_count, 1, 0))
861 lwkt_reltoken(&prg->proc_token);
864 if (atomic_cmpset_int(&sess->s_count, count, count - 1))
871 * Successful 1->0 transition and prg->proc_token is held.
873 LIST_REMOVE(sess, s_list);
874 if (pid_doms[sess->s_sid % PIDSEL_DOMAINS] != (uint8_t)time_second)
875 pid_doms[sess->s_sid % PIDSEL_DOMAINS] = (uint8_t)time_second;
877 if (sess->s_ttyp && sess->s_ttyp->t_session) {
878 #ifdef TTY_DO_FULL_CLOSE
879 /* FULL CLOSE, see ttyclearsession() */
880 KKASSERT(sess->s_ttyp->t_session == sess);
881 sess->s_ttyp->t_session = NULL;
883 /* HALF CLOSE, see ttyclearsession() */
884 if (sess->s_ttyp->t_session == sess)
885 sess->s_ttyp->t_session = NULL;
888 if ((tp = sess->s_ttyp) != NULL) {
892 lwkt_reltoken(&prg->proc_token);
894 kfree(sess, M_SESSION);
898 * Adjust pgrp jobc counters when specified process changes process group.
899 * We count the number of processes in each process group that "qualify"
900 * the group for terminal job control (those with a parent in a different
901 * process group of the same session). If that count reaches zero, the
902 * process group becomes orphaned. Check both the specified process'
903 * process group and that of its children.
904 * entering == 0 => p is leaving specified group.
905 * entering == 1 => p is entering specified group.
910 fixjobc(struct proc *p, struct pgrp *pgrp, int entering)
912 struct pgrp *hispgrp;
913 struct session *mysession;
917 * Check p's parent to see whether p qualifies its own process
918 * group; if so, adjust count for p's process group.
920 lwkt_gettoken(&p->p_token); /* p_children scan */
921 lwkt_gettoken(&pgrp->pg_token);
923 mysession = pgrp->pg_session;
924 if ((hispgrp = p->p_pptr->p_pgrp) != pgrp &&
925 hispgrp->pg_session == mysession) {
928 else if (--pgrp->pg_jobc == 0)
933 * Check this process' children to see whether they qualify
934 * their process groups; if so, adjust counts for children's
937 LIST_FOREACH(np, &p->p_children, p_sibling) {
939 lwkt_gettoken(&np->p_token);
940 if ((hispgrp = np->p_pgrp) != pgrp &&
941 hispgrp->pg_session == mysession &&
942 np->p_stat != SZOMB) {
944 lwkt_gettoken(&hispgrp->pg_token);
947 else if (--hispgrp->pg_jobc == 0)
949 lwkt_reltoken(&hispgrp->pg_token);
952 lwkt_reltoken(&np->p_token);
955 KKASSERT(pgrp->pg_refs > 0);
956 lwkt_reltoken(&pgrp->pg_token);
957 lwkt_reltoken(&p->p_token);
961 * A process group has become orphaned;
962 * if there are any stopped processes in the group,
963 * hang-up all process in that group.
965 * The caller must hold pg_token.
968 orphanpg(struct pgrp *pg)
972 LIST_FOREACH(p, &pg->pg_members, p_pglist) {
973 if (p->p_stat == SSTOP) {
974 LIST_FOREACH(p, &pg->pg_members, p_pglist) {
984 * Add a new process to the allproc list and the PID hash. This
985 * also assigns a pid to the new process.
990 proc_add_allproc(struct proc *p)
994 if ((random_offset = randompid) != 0) {
995 read_random(&random_offset, sizeof(random_offset));
996 random_offset = (random_offset & 0x7FFFFFFF) % randompid;
998 proc_makepid(p, random_offset);
1002 * Calculate a new process pid. This function is integrated into
1003 * proc_add_allproc() to guarentee that the new pid is not reused before
1004 * the new process can be added to the allproc list.
1006 * p_pid is assigned and the process is added to the allproc hash table
1008 * WARNING! We need to allocate PIDs sequentially during early boot.
1009 * In particular, init needs to have a pid of 1.
1013 proc_makepid(struct proc *p, int random_offset)
1015 static pid_t nextpid = 1; /* heuristic, allowed to race */
1019 struct session *sess;
1026 * Select the next pid base candidate.
1028 * Check cyclement, do not allow a pid < 100.
1032 base = atomic_fetchadd_int(&nextpid, 1) + random_offset;
1033 if (base <= 0 || base >= PID_MAX) {
1034 base = base % PID_MAX;
1039 nextpid = base; /* reset (SMP race ok) */
1043 * Do not allow a base pid to be selected from a domain that has
1044 * recently seen a pid/pgid/sessid reap. Sleep a little if we looped
1045 * through all available domains.
1047 * WARNING: We want the early pids to be allocated linearly,
1048 * particularly pid 1 and pid 2.
1050 if (++retries >= PIDSEL_DOMAINS)
1051 tsleep(&nextpid, 0, "makepid", 1);
1053 delta8 = (int8_t)time_second -
1054 (int8_t)pid_doms[base % PIDSEL_DOMAINS];
1055 if (delta8 >= 0 && delta8 <= PIDDOM_DELAY) {
1062 * Calculate a hash index and find an unused process id within
1063 * the table, looping if we cannot find one.
1065 * The inner loop increments by ALLPROC_HSIZE which keeps the
1066 * PID at the same pid_doms[] index as well as the same hash index.
1068 n = ALLPROC_HASH(base);
1070 lwkt_gettoken(&prg->proc_token);
1073 LIST_FOREACH(ps, &prg->allproc, p_list) {
1074 if (ps->p_pid == base) {
1075 base += ALLPROC_HSIZE;
1076 if (base >= PID_MAX) {
1077 lwkt_reltoken(&prg->proc_token);
1084 LIST_FOREACH(pg, &prg->allpgrp, pg_list) {
1085 if (pg->pg_id == base) {
1086 base += ALLPROC_HSIZE;
1087 if (base >= PID_MAX) {
1088 lwkt_reltoken(&prg->proc_token);
1095 LIST_FOREACH(sess, &prg->allsess, s_list) {
1096 if (sess->s_sid == base) {
1097 base += ALLPROC_HSIZE;
1098 if (base >= PID_MAX) {
1099 lwkt_reltoken(&prg->proc_token);
1108 * Assign the pid and insert the process.
1111 LIST_INSERT_HEAD(&prg->allproc, p, p_list);
1112 lwkt_reltoken(&prg->proc_token);
1116 * Called from exit1 to place the process into a zombie state.
1117 * The process is removed from the pid hash and p_stat is set
1118 * to SZOMB. Normal pfind[n]() calls will not find it any more.
1120 * Caller must hold p->p_token. We are required to wait until p_lock
1121 * becomes zero before we can manipulate the list, allowing allproc
1122 * scans to guarantee consistency during a list scan.
1125 proc_move_allproc_zombie(struct proc *p)
1130 n = ALLPROC_HASH(p->p_pid);
1132 PSTALL(p, "reap1", 0);
1133 lwkt_gettoken(&prg->proc_token);
1135 PSTALL(p, "reap1a", 0);
1138 lwkt_reltoken(&prg->proc_token);
1139 dsched_exit_proc(p);
1143 * This routine is called from kern_wait() and will remove the process
1144 * from the zombie list and the sibling list. This routine will block
1145 * if someone has a lock on the proces (p_lock).
1147 * Caller must hold p->p_token. We are required to wait until p_lock
1148 * becomes one before we can manipulate the list, allowing allproc
1149 * scans to guarantee consistency during a list scan.
1151 * Assumes caller has one ref.
1154 proc_remove_zombie(struct proc *p)
1159 n = ALLPROC_HASH(p->p_pid);
1162 PSTALL(p, "reap2", 1);
1163 lwkt_gettoken(&prg->proc_token);
1164 PSTALL(p, "reap2a", 1);
1165 LIST_REMOVE(p, p_list); /* from remove master list */
1166 LIST_REMOVE(p, p_sibling); /* and from sibling list */
1169 if (pid_doms[p->p_pid % PIDSEL_DOMAINS] != (uint8_t)time_second)
1170 pid_doms[p->p_pid % PIDSEL_DOMAINS] = (uint8_t)time_second;
1171 lwkt_reltoken(&prg->proc_token);
1175 * Handle various requirements prior to returning to usermode. Called from
1176 * platform trap and system call code.
1179 lwpuserret(struct lwp *lp)
1181 struct proc *p = lp->lwp_proc;
1183 if (lp->lwp_mpflags & LWP_MP_VNLRU) {
1184 atomic_clear_int(&lp->lwp_mpflags, LWP_MP_VNLRU);
1187 if (lp->lwp_mpflags & LWP_MP_WEXIT) {
1188 lwkt_gettoken(&p->p_token);
1190 lwkt_reltoken(&p->p_token); /* NOT REACHED */
1195 * Kernel threads run from user processes can also accumulate deferred
1196 * actions which need to be acted upon. Callers include:
1198 * nfsd - Can allocate lots of vnodes
1201 lwpkthreaddeferred(void)
1203 struct lwp *lp = curthread->td_lwp;
1206 if (lp->lwp_mpflags & LWP_MP_VNLRU) {
1207 atomic_clear_int(&lp->lwp_mpflags, LWP_MP_VNLRU);
1214 proc_usermap(struct proc *p, int invfork)
1216 struct sys_upmap *upmap;
1218 lwkt_gettoken(&p->p_token);
1219 upmap = kmalloc(roundup2(sizeof(*upmap), PAGE_SIZE), M_UPMAP,
1221 if (p->p_upmap == NULL) {
1222 upmap->header[0].type = UKPTYPE_VERSION;
1223 upmap->header[0].offset = offsetof(struct sys_upmap, version);
1224 upmap->header[1].type = UPTYPE_RUNTICKS;
1225 upmap->header[1].offset = offsetof(struct sys_upmap, runticks);
1226 upmap->header[2].type = UPTYPE_FORKID;
1227 upmap->header[2].offset = offsetof(struct sys_upmap, forkid);
1228 upmap->header[3].type = UPTYPE_PID;
1229 upmap->header[3].offset = offsetof(struct sys_upmap, pid);
1230 upmap->header[4].type = UPTYPE_PROC_TITLE;
1231 upmap->header[4].offset = offsetof(struct sys_upmap,proc_title);
1232 upmap->header[5].type = UPTYPE_INVFORK;
1233 upmap->header[5].offset = offsetof(struct sys_upmap, invfork);
1235 upmap->version = UPMAP_VERSION;
1236 upmap->pid = p->p_pid;
1237 upmap->forkid = p->p_forkid;
1238 upmap->invfork = invfork;
1241 kfree(upmap, M_UPMAP);
1243 lwkt_reltoken(&p->p_token);
1247 proc_userunmap(struct proc *p)
1249 struct sys_upmap *upmap;
1251 lwkt_gettoken(&p->p_token);
1252 if ((upmap = p->p_upmap) != NULL) {
1254 kfree(upmap, M_UPMAP);
1256 lwkt_reltoken(&p->p_token);
1260 * Called when the per-thread user/kernel shared page needs to be
1261 * allocated. The function refuses to allocate the page if the
1262 * thread is exiting to avoid races against lwp_userunmap().
1265 lwp_usermap(struct lwp *lp, int invfork)
1267 struct sys_lpmap *lpmap;
1269 lwkt_gettoken(&lp->lwp_token);
1271 lpmap = kmalloc(roundup2(sizeof(*lpmap), PAGE_SIZE), M_UPMAP,
1273 if (lp->lwp_lpmap == NULL && (lp->lwp_mpflags & LWP_MP_WEXIT) == 0) {
1274 lpmap->header[0].type = UKPTYPE_VERSION;
1275 lpmap->header[0].offset = offsetof(struct sys_lpmap, version);
1276 lpmap->header[1].type = LPTYPE_BLOCKALLSIGS;
1277 lpmap->header[1].offset = offsetof(struct sys_lpmap,
1279 lpmap->header[2].type = LPTYPE_THREAD_TITLE;
1280 lpmap->header[2].offset = offsetof(struct sys_lpmap,
1283 lpmap->version = LPMAP_VERSION;
1284 lp->lwp_lpmap = lpmap;
1286 kfree(lpmap, M_UPMAP);
1288 lwkt_reltoken(&lp->lwp_token);
1292 * Called when a LWP (but not necessarily the whole process) exits.
1293 * Called when a process execs (after all other threads have been killed).
1295 * lwp-specific mappings must be removed. If userland didn't do it, then
1296 * we have to. Otherwise we could end-up disclosing kernel memory due to
1297 * the ad-hoc pmap mapping.
1300 lwp_userunmap(struct lwp *lp)
1302 struct sys_lpmap *lpmap;
1304 struct vm_map_backing *ba;
1305 struct vm_map_backing copy;
1307 lwkt_gettoken(&lp->lwp_token);
1308 map = &lp->lwp_proc->p_vmspace->vm_map;
1309 lpmap = lp->lwp_lpmap;
1310 lp->lwp_lpmap = NULL;
1312 spin_lock(&lp->lwp_spin);
1313 while ((ba = TAILQ_FIRST(&lp->lwp_lpmap_backing_list)) != NULL) {
1314 TAILQ_REMOVE(&lp->lwp_lpmap_backing_list, ba, entry);
1315 atomic_clear_int(&ba->flags, VM_MAP_LWP_LINKED);
1317 spin_unlock(&lp->lwp_spin);
1319 lwkt_gettoken(&map->token);
1320 vm_map_remove(map, copy.start, copy.end);
1321 lwkt_reltoken(&map->token);
1323 spin_lock(&lp->lwp_spin);
1325 spin_unlock(&lp->lwp_spin);
1328 kfree(lpmap, M_UPMAP);
1329 lwkt_reltoken(&lp->lwp_token);
1333 * Scan all processes on the allproc list. The process is automatically
1334 * held for the callback. A return value of -1 terminates the loop.
1335 * Zombie procs are skipped.
1337 * The callback is made with the process held and proc_token held.
1339 * We limit the scan to the number of processes as-of the start of
1340 * the scan so as not to get caught up in an endless loop if new processes
1341 * are created more quickly than we can scan the old ones. Add a little
1342 * slop to try to catch edge cases since nprocs can race.
1347 allproc_scan(int (*callback)(struct proc *, void *), void *data, int segmented)
1349 int limit = nprocs + ncpus;
1357 int id = mycpu->gd_cpuid;
1358 ns = id * ALLPROC_HSIZE / ncpus;
1359 ne = (id + 1) * ALLPROC_HSIZE / ncpus;
1366 * prg->proc_token protects the allproc list and PHOLD() prevents the
1367 * process from being removed from the allproc list or the zombproc
1370 for (n = ns; n < ne; ++n) {
1371 procglob_t *prg = &procglob[n];
1372 if (LIST_FIRST(&prg->allproc) == NULL)
1374 lwkt_gettoken(&prg->proc_token);
1375 LIST_FOREACH(p, &prg->allproc, p_list) {
1376 if (p->p_stat == SZOMB)
1379 r = callback(p, data);
1386 lwkt_reltoken(&prg->proc_token);
1389 * Check if asked to stop early
1397 * Scan all lwps of processes on the allproc list. The lwp is automatically
1398 * held for the callback. A return value of -1 terminates the loop.
1400 * The callback is made with the proces and lwp both held, and proc_token held.
1405 alllwp_scan(int (*callback)(struct lwp *, void *), void *data, int segmented)
1415 int id = mycpu->gd_cpuid;
1416 ns = id * ALLPROC_HSIZE / ncpus;
1417 ne = (id + 1) * ALLPROC_HSIZE / ncpus;
1423 for (n = ns; n < ne; ++n) {
1424 procglob_t *prg = &procglob[n];
1426 if (LIST_FIRST(&prg->allproc) == NULL)
1428 lwkt_gettoken(&prg->proc_token);
1429 LIST_FOREACH(p, &prg->allproc, p_list) {
1430 if (p->p_stat == SZOMB)
1433 lwkt_gettoken(&p->p_token);
1434 FOREACH_LWP_IN_PROC(lp, p) {
1436 r = callback(lp, data);
1439 lwkt_reltoken(&p->p_token);
1444 lwkt_reltoken(&prg->proc_token);
1447 * Asked to exit early
1455 * Scan all processes on the zombproc list. The process is automatically
1456 * held for the callback. A return value of -1 terminates the loop.
1459 * The callback is made with the proces held and proc_token held.
1462 zombproc_scan(int (*callback)(struct proc *, void *), void *data)
1469 * prg->proc_token protects the allproc list and PHOLD() prevents the
1470 * process from being removed from the allproc list or the zombproc
1473 for (n = 0; n < ALLPROC_HSIZE; ++n) {
1474 procglob_t *prg = &procglob[n];
1476 if (LIST_FIRST(&prg->allproc) == NULL)
1478 lwkt_gettoken(&prg->proc_token);
1479 LIST_FOREACH(p, &prg->allproc, p_list) {
1480 if (p->p_stat != SZOMB)
1483 r = callback(p, data);
1488 lwkt_reltoken(&prg->proc_token);
1491 * Check if asked to stop early
1498 #include "opt_ddb.h"
1500 #include <ddb/ddb.h>
1505 DB_SHOW_COMMAND(pgrpdump, pgrpdump)
1512 for (i = 0; i < ALLPROC_HSIZE; ++i) {
1515 if (LIST_EMPTY(&prg->allpgrp))
1517 kprintf("\tindx %d\n", i);
1518 LIST_FOREACH(pgrp, &prg->allpgrp, pg_list) {
1519 kprintf("\tpgrp %p, pgid %ld, sess %p, "
1520 "sesscnt %d, mem %p\n",
1521 (void *)pgrp, (long)pgrp->pg_id,
1522 (void *)pgrp->pg_session,
1523 pgrp->pg_session->s_count,
1524 (void *)LIST_FIRST(&pgrp->pg_members));
1525 LIST_FOREACH(p, &pgrp->pg_members, p_pglist) {
1526 kprintf("\t\tpid %ld addr %p pgrp %p\n",
1527 (long)p->p_pid, (void *)p,
1536 * The caller must hold proc_token.
1539 sysctl_out_proc(struct proc *p, struct sysctl_req *req, int flags)
1541 struct kinfo_proc ki;
1543 int skp = 0, had_output = 0;
1546 bzero(&ki, sizeof(ki));
1547 lwkt_gettoken_shared(&p->p_token);
1548 fill_kinfo_proc(p, &ki);
1549 if ((flags & KERN_PROC_FLAG_LWP) == 0)
1552 FOREACH_LWP_IN_PROC(lp, p) {
1554 fill_kinfo_lwp(lp, &ki.kp_lwp);
1557 error = SYSCTL_OUT(req, &ki, sizeof(ki));
1558 bzero(&ki.kp_lwp, sizeof(ki.kp_lwp));
1564 lwkt_reltoken(&p->p_token);
1567 * If aggregating threads, set the tid field to -1.
1570 ki.kp_lwp.kl_tid = -1;
1573 * We need to output at least the proc, even if there is no lwp.
1574 * If skp is non-zero we aggregated the lwps and need to output
1577 if (had_output == 0 || skp) {
1578 error = SYSCTL_OUT(req, &ki, sizeof(ki));
1584 * The caller must hold proc_token.
1587 sysctl_out_proc_kthread(struct thread *td, struct sysctl_req *req)
1589 struct kinfo_proc ki;
1592 fill_kinfo_proc_kthread(td, &ki);
1593 error = SYSCTL_OUT(req, &ki, sizeof(ki));
1603 sysctl_kern_proc(SYSCTL_HANDLER_ARGS)
1605 int *name = (int *)arg1;
1606 int oid = oidp->oid_number;
1607 u_int namelen = arg2;
1610 struct thread *marker;
1615 struct ucred *cr1 = curproc->p_ucred;
1616 struct ucred *crcache = NULL;
1618 flags = oid & KERN_PROC_FLAGMASK;
1619 oid &= ~KERN_PROC_FLAGMASK;
1621 if ((oid == KERN_PROC_ALL && namelen != 0) ||
1622 (oid != KERN_PROC_ALL && namelen != 1)) {
1627 * proc_token protects the allproc list and PHOLD() prevents the
1628 * process from being removed from the allproc list or the zombproc
1631 if (oid == KERN_PROC_PID) {
1632 p = pfind((pid_t)name[0]);
1634 crcache = pcredcache(crcache, p);
1635 if (PRISON_CHECK(cr1, crcache))
1636 error = sysctl_out_proc(p, req, flags);
1644 /* overestimate by 5 procs */
1645 error = SYSCTL_OUT(req, 0, sizeof (struct kinfo_proc) * 5);
1650 for (n = 0; n < ALLPROC_HSIZE; ++n) {
1651 procglob_t *prg = &procglob[n];
1653 if (LIST_EMPTY(&prg->allproc))
1655 lwkt_gettoken_shared(&prg->proc_token);
1656 LIST_FOREACH(p, &prg->allproc, p_list) {
1658 * Show a user only their processes.
1660 if (ps_showallprocs == 0) {
1661 crcache = pcredcache(crcache, p);
1662 if (crcache == NULL ||
1663 p_trespass(cr1, crcache)) {
1669 * Skip embryonic processes.
1671 if (p->p_stat == SIDL)
1674 * TODO - make more efficient (see notes below).
1678 case KERN_PROC_PGRP:
1679 /* could do this by traversing pgrp */
1680 if (p->p_pgrp == NULL ||
1681 p->p_pgrp->pg_id != (pid_t)name[0])
1686 if ((p->p_flags & P_CONTROLT) == 0 ||
1687 p->p_session == NULL ||
1688 p->p_session->s_ttyp == NULL ||
1689 dev2udev(p->p_session->s_ttyp->t_dev) !=
1695 crcache = pcredcache(crcache, p);
1696 if (crcache == NULL ||
1697 crcache->cr_uid != (uid_t)name[0]) {
1702 case KERN_PROC_RUID:
1703 crcache = pcredcache(crcache, p);
1704 if (crcache == NULL ||
1705 crcache->cr_ruid != (uid_t)name[0]) {
1711 crcache = pcredcache(crcache, p);
1712 if (!PRISON_CHECK(cr1, crcache))
1715 error = sysctl_out_proc(p, req, flags);
1718 lwkt_reltoken(&prg->proc_token);
1722 lwkt_reltoken(&prg->proc_token);
1726 * Iterate over all active cpus and scan their thread list. Start
1727 * with the next logical cpu and end with our original cpu. We
1728 * migrate our own thread to each target cpu in order to safely scan
1729 * its thread list. In the last loop we migrate back to our original
1732 origcpu = mycpu->gd_cpuid;
1733 if (!ps_showallthreads || jailed(cr1))
1736 marker = kmalloc(sizeof(struct thread), M_TEMP, M_WAITOK|M_ZERO);
1737 marker->td_flags = TDF_MARKER;
1740 for (n = 1; n <= ncpus; ++n) {
1744 nid = (origcpu + n) % ncpus;
1745 if (CPUMASK_TESTBIT(smp_active_mask, nid) == 0)
1747 rgd = globaldata_find(nid);
1748 lwkt_setcpu_self(rgd);
1751 TAILQ_INSERT_TAIL(&rgd->gd_tdallq, marker, td_allq);
1753 while ((td = TAILQ_PREV(marker, lwkt_queue, td_allq)) != NULL) {
1754 TAILQ_REMOVE(&rgd->gd_tdallq, marker, td_allq);
1755 TAILQ_INSERT_BEFORE(td, marker, td_allq);
1756 if (td->td_flags & TDF_MARKER)
1765 case KERN_PROC_PGRP:
1768 case KERN_PROC_RUID:
1771 error = sysctl_out_proc_kthread(td, req);
1779 TAILQ_REMOVE(&rgd->gd_tdallq, marker, td_allq);
1787 * Userland scheduler expects us to return on the same cpu we
1790 if (mycpu->gd_cpuid != origcpu)
1791 lwkt_setcpu_self(globaldata_find(origcpu));
1793 kfree(marker, M_TEMP);
1802 * This sysctl allows a process to retrieve the argument list or process
1803 * title for another process without groping around in the address space
1804 * of the other process. It also allow a process to set its own "process
1805 * title to a string of its own choice.
1810 sysctl_kern_proc_args(SYSCTL_HANDLER_ARGS)
1812 int *name = (int*) arg1;
1813 u_int namelen = arg2;
1818 struct ucred *cr1 = curproc->p_ucred;
1823 p = pfind((pid_t)name[0]);
1826 lwkt_gettoken(&p->p_token);
1828 if ((!ps_argsopen) && p_trespass(cr1, p->p_ucred))
1831 if (req->newptr && curproc != p) {
1836 if (p->p_upmap != NULL && p->p_upmap->proc_title[0]) {
1838 * Args set via writable user process mmap.
1839 * We must calculate the string length manually
1840 * because the user data can change at any time.
1845 base = p->p_upmap->proc_title;
1846 for (n = 0; n < UPMAP_MAXPROCTITLE - 1; ++n) {
1850 error = SYSCTL_OUT(req, base, n);
1852 error = SYSCTL_OUT(req, "", 1);
1853 } else if ((pa = p->p_args) != NULL) {
1855 * Args set by setproctitle() sysctl.
1857 refcount_acquire(&pa->ar_ref);
1858 error = SYSCTL_OUT(req, pa->ar_args, pa->ar_length);
1859 if (refcount_release(&pa->ar_ref))
1863 if (req->newptr == NULL)
1866 if (req->newlen + sizeof(struct pargs) > ps_arg_cache_limit) {
1870 pa = kmalloc(sizeof(struct pargs) + req->newlen, M_PARGS, M_WAITOK);
1871 refcount_init(&pa->ar_ref, 1);
1872 pa->ar_length = req->newlen;
1873 error = SYSCTL_IN(req, pa->ar_args, req->newlen);
1881 * Replace p_args with the new pa. p_args may have previously
1888 KKASSERT(opa->ar_ref > 0);
1889 if (refcount_release(&opa->ar_ref)) {
1890 kfree(opa, M_PARGS);
1896 lwkt_reltoken(&p->p_token);
1903 sysctl_kern_proc_cwd(SYSCTL_HANDLER_ARGS)
1905 int *name = (int*) arg1;
1906 u_int namelen = arg2;
1909 char *fullpath, *freepath;
1910 struct ucred *cr1 = curproc->p_ucred;
1915 p = pfind((pid_t)name[0]);
1918 lwkt_gettoken_shared(&p->p_token);
1921 * If we are not allowed to see other args, we certainly shouldn't
1922 * get the cwd either. Also check the usual trespassing.
1924 if ((!ps_argsopen) && p_trespass(cr1, p->p_ucred))
1927 if (req->oldptr && p->p_fd != NULL && p->p_fd->fd_ncdir.ncp) {
1928 struct nchandle nch;
1930 cache_copy(&p->p_fd->fd_ncdir, &nch);
1931 error = cache_fullpath(p, &nch, NULL,
1932 &fullpath, &freepath, 0);
1936 error = SYSCTL_OUT(req, fullpath, strlen(fullpath) + 1);
1937 kfree(freepath, M_TEMP);
1942 lwkt_reltoken(&p->p_token);
1949 * This sysctl allows a process to retrieve the path of the executable for
1950 * itself or another process.
1953 sysctl_kern_proc_pathname(SYSCTL_HANDLER_ARGS)
1955 pid_t *pidp = (pid_t *)arg1;
1956 unsigned int arglen = arg2;
1958 char *retbuf, *freebuf;
1960 struct nchandle nch;
1964 if (*pidp == -1) { /* -1 means this process */
1972 cache_copy(&p->p_textnch, &nch);
1973 error = cache_fullpath(p, &nch, NULL, &retbuf, &freebuf, 0);
1977 error = SYSCTL_OUT(req, retbuf, strlen(retbuf) + 1);
1978 kfree(freebuf, M_TEMP);
1987 sysctl_kern_proc_sigtramp(SYSCTL_HANDLER_ARGS)
1989 /*int *name = (int *)arg1;*/
1990 u_int namelen = arg2;
1991 struct kinfo_sigtramp kst;
1992 const struct sysentvec *sv;
1997 /* ignore pid if passed in (freebsd compatibility) */
1999 sv = curproc->p_sysent;
2000 bzero(&kst, sizeof(kst));
2001 if (sv->sv_szsigcode) {
2004 sigbase = trunc_page64((intptr_t)PS_STRINGS -
2006 sigbase -= SZSIGCODE_EXTRA_BYTES;
2008 kst.ksigtramp_start = (void *)sigbase;
2009 kst.ksigtramp_end = (void *)(sigbase + *sv->sv_szsigcode);
2011 error = SYSCTL_OUT(req, &kst, sizeof(kst));
2016 SYSCTL_NODE(_kern, KERN_PROC, proc, CTLFLAG_RD, 0, "Process table");
2018 SYSCTL_PROC(_kern_proc, KERN_PROC_ALL, all,
2019 CTLFLAG_RD | CTLTYPE_STRUCT | CTLFLAG_NOLOCK,
2020 0, 0, sysctl_kern_proc, "S,proc", "Return entire process table");
2022 SYSCTL_NODE(_kern_proc, KERN_PROC_PGRP, pgrp,
2023 CTLFLAG_RD | CTLFLAG_NOLOCK,
2024 sysctl_kern_proc, "Process table");
2026 SYSCTL_NODE(_kern_proc, KERN_PROC_TTY, tty,
2027 CTLFLAG_RD | CTLFLAG_NOLOCK,
2028 sysctl_kern_proc, "Process table");
2030 SYSCTL_NODE(_kern_proc, KERN_PROC_UID, uid,
2031 CTLFLAG_RD | CTLFLAG_NOLOCK,
2032 sysctl_kern_proc, "Process table");
2034 SYSCTL_NODE(_kern_proc, KERN_PROC_RUID, ruid,
2035 CTLFLAG_RD | CTLFLAG_NOLOCK,
2036 sysctl_kern_proc, "Process table");
2038 SYSCTL_NODE(_kern_proc, KERN_PROC_PID, pid,
2039 CTLFLAG_RD | CTLFLAG_NOLOCK,
2040 sysctl_kern_proc, "Process table");
2042 SYSCTL_NODE(_kern_proc, (KERN_PROC_ALL | KERN_PROC_FLAG_LWP), all_lwp,
2043 CTLFLAG_RD | CTLFLAG_NOLOCK,
2044 sysctl_kern_proc, "Process table");
2046 SYSCTL_NODE(_kern_proc, (KERN_PROC_PGRP | KERN_PROC_FLAG_LWP), pgrp_lwp,
2047 CTLFLAG_RD | CTLFLAG_NOLOCK,
2048 sysctl_kern_proc, "Process table");
2050 SYSCTL_NODE(_kern_proc, (KERN_PROC_TTY | KERN_PROC_FLAG_LWP), tty_lwp,
2051 CTLFLAG_RD | CTLFLAG_NOLOCK,
2052 sysctl_kern_proc, "Process table");
2054 SYSCTL_NODE(_kern_proc, (KERN_PROC_UID | KERN_PROC_FLAG_LWP), uid_lwp,
2055 CTLFLAG_RD | CTLFLAG_NOLOCK,
2056 sysctl_kern_proc, "Process table");
2058 SYSCTL_NODE(_kern_proc, (KERN_PROC_RUID | KERN_PROC_FLAG_LWP), ruid_lwp,
2059 CTLFLAG_RD | CTLFLAG_NOLOCK,
2060 sysctl_kern_proc, "Process table");
2062 SYSCTL_NODE(_kern_proc, (KERN_PROC_PID | KERN_PROC_FLAG_LWP), pid_lwp,
2063 CTLFLAG_RD | CTLFLAG_NOLOCK,
2064 sysctl_kern_proc, "Process table");
2066 SYSCTL_NODE(_kern_proc, KERN_PROC_ARGS, args,
2067 CTLFLAG_RW | CTLFLAG_ANYBODY | CTLFLAG_NOLOCK,
2068 sysctl_kern_proc_args, "Process argument list");
2070 SYSCTL_NODE(_kern_proc, KERN_PROC_CWD, cwd,
2071 CTLFLAG_RD | CTLFLAG_ANYBODY | CTLFLAG_NOLOCK,
2072 sysctl_kern_proc_cwd, "Process argument list");
2074 static SYSCTL_NODE(_kern_proc, KERN_PROC_PATHNAME, pathname,
2075 CTLFLAG_RD | CTLFLAG_NOLOCK,
2076 sysctl_kern_proc_pathname, "Process executable path");
2078 SYSCTL_PROC(_kern_proc, KERN_PROC_SIGTRAMP, sigtramp,
2079 CTLFLAG_RD | CTLTYPE_STRUCT | CTLFLAG_NOLOCK,
2080 0, 0, sysctl_kern_proc_sigtramp, "S,sigtramp",
2081 "Return sigtramp address range");