]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - 6/sys/kern/kern_proc.c
merge fix for boot-time hang on centos' xen
[FreeBSD/FreeBSD.git] / 6 / sys / kern / kern_proc.c
1 /*-
2  * Copyright (c) 1982, 1986, 1989, 1991, 1993
3  *      The Regents of the University of California.  All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
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.
16  *
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
27  * SUCH DAMAGE.
28  *
29  *      @(#)kern_proc.c 8.7 (Berkeley) 2/14/95
30  * $FreeBSD$
31  */
32
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
35
36 #include "opt_ktrace.h"
37 #include "opt_kstack_pages.h"
38
39 #include <sys/param.h>
40 #include <sys/systm.h>
41 #include <sys/kernel.h>
42 #include <sys/lock.h>
43 #include <sys/malloc.h>
44 #include <sys/mutex.h>
45 #include <sys/proc.h>
46 #include <sys/sysent.h>
47 #include <sys/sched.h>
48 #include <sys/smp.h>
49 #include <sys/sysctl.h>
50 #include <sys/filedesc.h>
51 #include <sys/tty.h>
52 #include <sys/signalvar.h>
53 #include <sys/sx.h>
54 #include <sys/user.h>
55 #include <sys/jail.h>
56 #include <sys/vnode.h>
57 #ifdef KTRACE
58 #include <sys/uio.h>
59 #include <sys/ktrace.h>
60 #endif
61
62 #include <vm/vm.h>
63 #include <vm/vm_extern.h>
64 #include <vm/pmap.h>
65 #include <vm/vm_map.h>
66 #include <vm/uma.h>
67
68 MALLOC_DEFINE(M_PGRP, "pgrp", "process group header");
69 MALLOC_DEFINE(M_SESSION, "session", "session header");
70 static MALLOC_DEFINE(M_PROC, "proc", "Proc structures");
71 MALLOC_DEFINE(M_SUBPROC, "subproc", "Proc sub-structures");
72
73 static void doenterpgrp(struct proc *, struct pgrp *);
74 static void orphanpg(struct pgrp *pg);
75 static void fill_kinfo_proc_only(struct proc *p, struct kinfo_proc *kp);
76 static void fill_kinfo_thread(struct thread *td, struct kinfo_proc *kp);
77 static void pgadjustjobc(struct pgrp *pgrp, int entering);
78 static void pgdelete(struct pgrp *);
79 static int proc_ctor(void *mem, int size, void *arg, int flags);
80 static void proc_dtor(void *mem, int size, void *arg);
81 static int proc_init(void *mem, int size, int flags);
82 static void proc_fini(void *mem, int size);
83
84 /*
85  * Other process lists
86  */
87 struct pidhashhead *pidhashtbl;
88 u_long pidhash;
89 struct pgrphashhead *pgrphashtbl;
90 u_long pgrphash;
91 struct proclist allproc;
92 struct proclist zombproc;
93 struct sx allproc_lock;
94 struct sx proctree_lock;
95 struct mtx pargs_ref_lock;
96 struct mtx ppeers_lock;
97 uma_zone_t proc_zone;
98 uma_zone_t ithread_zone;
99
100 int kstack_pages = KSTACK_PAGES;
101 SYSCTL_INT(_kern, OID_AUTO, kstack_pages, CTLFLAG_RD, &kstack_pages, 0, "");
102
103 CTASSERT(sizeof(struct kinfo_proc) == KINFO_PROC_SIZE);
104
105 /*
106  * Initialize global process hashing structures.
107  */
108 void
109 procinit()
110 {
111
112         sx_init(&allproc_lock, "allproc");
113         sx_init(&proctree_lock, "proctree");
114         mtx_init(&pargs_ref_lock, "struct pargs.ref", NULL, MTX_DEF);
115         mtx_init(&ppeers_lock, "p_peers", NULL, MTX_DEF);
116         LIST_INIT(&allproc);
117         LIST_INIT(&zombproc);
118         pidhashtbl = hashinit(maxproc / 4, M_PROC, &pidhash);
119         pgrphashtbl = hashinit(maxproc / 4, M_PROC, &pgrphash);
120         proc_zone = uma_zcreate("PROC", sched_sizeof_proc(),
121             proc_ctor, proc_dtor, proc_init, proc_fini,
122             UMA_ALIGN_PTR, UMA_ZONE_NOFREE);
123         uihashinit();
124 }
125
126 /*
127  * Prepare a proc for use.
128  */
129 static int
130 proc_ctor(void *mem, int size, void *arg, int flags)
131 {
132         struct proc *p;
133
134         p = (struct proc *)mem;
135         return (0);
136 }
137
138 /*
139  * Reclaim a proc after use.
140  */
141 static void
142 proc_dtor(void *mem, int size, void *arg)
143 {
144         struct proc *p;
145         struct thread *td;
146 #ifdef INVARIANTS
147         struct ksegrp *kg;
148 #endif
149
150         /* INVARIANTS checks go here */
151         p = (struct proc *)mem;
152         td = FIRST_THREAD_IN_PROC(p);
153 #ifdef INVARIANTS
154         KASSERT((p->p_numthreads == 1),
155             ("bad number of threads in exiting process"));
156         KASSERT((p->p_numksegrps == 1), ("free proc with > 1 ksegrp"));
157         KASSERT((td != NULL), ("proc_dtor: bad thread pointer"));
158         kg = FIRST_KSEGRP_IN_PROC(p);
159         KASSERT((kg != NULL), ("proc_dtor: bad kg pointer"));
160         KASSERT(STAILQ_EMPTY(&p->p_ktr), ("proc_dtor: non-empty p_ktr"));
161 #endif
162
163         /* Dispose of an alternate kstack, if it exists.
164          * XXX What if there are more than one thread in the proc?
165          *     The first thread in the proc is special and not
166          *     freed, so you gotta do this here.
167          */
168         if (((p->p_flag & P_KTHREAD) != 0) && (td->td_altkstack != 0))
169                 vm_thread_dispose_altkstack(td);
170 }
171
172 /*
173  * Initialize type-stable parts of a proc (when newly created).
174  */
175 static int
176 proc_init(void *mem, int size, int flags)
177 {
178         struct proc *p;
179         struct thread *td;
180         struct ksegrp *kg;
181
182         p = (struct proc *)mem;
183         p->p_sched = (struct p_sched *)&p[1];
184         td = thread_alloc();
185         kg = ksegrp_alloc();
186         bzero(&p->p_mtx, sizeof(struct mtx));
187         mtx_init(&p->p_mtx, "process lock", NULL, MTX_DEF | MTX_DUPOK);
188         p->p_stats = pstats_alloc();
189         proc_linkup(p, kg, td);
190         sched_newproc(p, kg, td);
191         return (0);
192 }
193
194 /*
195  * UMA should ensure that this function is never called.
196  * Freeing a proc structure would violate type stability.
197  */
198 static void
199 proc_fini(void *mem, int size)
200 {
201
202         panic("proc reclaimed");
203 }
204
205 /*
206  * Is p an inferior of the current process?
207  */
208 int
209 inferior(p)
210         register struct proc *p;
211 {
212
213         sx_assert(&proctree_lock, SX_LOCKED);
214         for (; p != curproc; p = p->p_pptr)
215                 if (p->p_pid == 0)
216                         return (0);
217         return (1);
218 }
219
220 /*
221  * Locate a process by number; return only "live" processes -- i.e., neither
222  * zombies nor newly born but incompletely initialized processes.  By not
223  * returning processes in the PRS_NEW state, we allow callers to avoid
224  * testing for that condition to avoid dereferencing p_ucred, et al.
225  */
226 struct proc *
227 pfind(pid)
228         register pid_t pid;
229 {
230         register struct proc *p;
231
232         sx_slock(&allproc_lock);
233         LIST_FOREACH(p, PIDHASH(pid), p_hash)
234                 if (p->p_pid == pid) {
235                         if (p->p_state == PRS_NEW) {
236                                 p = NULL;
237                                 break;
238                         }
239                         PROC_LOCK(p);
240                         break;
241                 }
242         sx_sunlock(&allproc_lock);
243         return (p);
244 }
245
246 /*
247  * Locate a process group by number.
248  * The caller must hold proctree_lock.
249  */
250 struct pgrp *
251 pgfind(pgid)
252         register pid_t pgid;
253 {
254         register struct pgrp *pgrp;
255
256         sx_assert(&proctree_lock, SX_LOCKED);
257
258         LIST_FOREACH(pgrp, PGRPHASH(pgid), pg_hash) {
259                 if (pgrp->pg_id == pgid) {
260                         PGRP_LOCK(pgrp);
261                         return (pgrp);
262                 }
263         }
264         return (NULL);
265 }
266
267 /*
268  * Create a new process group.
269  * pgid must be equal to the pid of p.
270  * Begin a new session if required.
271  */
272 int
273 enterpgrp(p, pgid, pgrp, sess)
274         register struct proc *p;
275         pid_t pgid;
276         struct pgrp *pgrp;
277         struct session *sess;
278 {
279         struct pgrp *pgrp2;
280
281         sx_assert(&proctree_lock, SX_XLOCKED);
282
283         KASSERT(pgrp != NULL, ("enterpgrp: pgrp == NULL"));
284         KASSERT(p->p_pid == pgid,
285             ("enterpgrp: new pgrp and pid != pgid"));
286
287         pgrp2 = pgfind(pgid);
288
289         KASSERT(pgrp2 == NULL,
290             ("enterpgrp: pgrp with pgid exists"));
291         KASSERT(!SESS_LEADER(p),
292             ("enterpgrp: session leader attempted setpgrp"));
293
294         mtx_init(&pgrp->pg_mtx, "process group", NULL, MTX_DEF | MTX_DUPOK);
295
296         if (sess != NULL) {
297                 /*
298                  * new session
299                  */
300                 mtx_init(&sess->s_mtx, "session", NULL, MTX_DEF);
301                 mtx_lock(&Giant);       /* XXX TTY */
302                 PROC_LOCK(p);
303                 p->p_flag &= ~P_CONTROLT;
304                 PROC_UNLOCK(p);
305                 PGRP_LOCK(pgrp);
306                 sess->s_leader = p;
307                 sess->s_sid = p->p_pid;
308                 sess->s_count = 1;
309                 sess->s_ttyvp = NULL;
310                 sess->s_ttyp = NULL;
311                 bcopy(p->p_session->s_login, sess->s_login,
312                             sizeof(sess->s_login));
313                 pgrp->pg_session = sess;
314                 KASSERT(p == curproc,
315                     ("enterpgrp: mksession and p != curproc"));
316         } else {
317                 mtx_lock(&Giant);       /* XXX TTY */
318                 pgrp->pg_session = p->p_session;
319                 SESS_LOCK(pgrp->pg_session);
320                 pgrp->pg_session->s_count++;
321                 SESS_UNLOCK(pgrp->pg_session);
322                 PGRP_LOCK(pgrp);
323         }
324         pgrp->pg_id = pgid;
325         LIST_INIT(&pgrp->pg_members);
326
327         /*
328          * As we have an exclusive lock of proctree_lock,
329          * this should not deadlock.
330          */
331         LIST_INSERT_HEAD(PGRPHASH(pgid), pgrp, pg_hash);
332         pgrp->pg_jobc = 0;
333         SLIST_INIT(&pgrp->pg_sigiolst);
334         PGRP_UNLOCK(pgrp);
335         mtx_unlock(&Giant);       /* XXX TTY */
336
337         doenterpgrp(p, pgrp);
338
339         return (0);
340 }
341
342 /*
343  * Move p to an existing process group
344  */
345 int
346 enterthispgrp(p, pgrp)
347         register struct proc *p;
348         struct pgrp *pgrp;
349 {
350
351         sx_assert(&proctree_lock, SX_XLOCKED);
352         PROC_LOCK_ASSERT(p, MA_NOTOWNED);
353         PGRP_LOCK_ASSERT(pgrp, MA_NOTOWNED);
354         PGRP_LOCK_ASSERT(p->p_pgrp, MA_NOTOWNED);
355         SESS_LOCK_ASSERT(p->p_session, MA_NOTOWNED);
356         KASSERT(pgrp->pg_session == p->p_session,
357                 ("%s: pgrp's session %p, p->p_session %p.\n",
358                 __func__,
359                 pgrp->pg_session,
360                 p->p_session));
361         KASSERT(pgrp != p->p_pgrp,
362                 ("%s: p belongs to pgrp.", __func__));
363
364         doenterpgrp(p, pgrp);
365
366         return (0);
367 }
368
369 /*
370  * Move p to a process group
371  */
372 static void
373 doenterpgrp(p, pgrp)
374         struct proc *p;
375         struct pgrp *pgrp;
376 {
377         struct pgrp *savepgrp;
378
379         sx_assert(&proctree_lock, SX_XLOCKED);
380         PROC_LOCK_ASSERT(p, MA_NOTOWNED);
381         PGRP_LOCK_ASSERT(pgrp, MA_NOTOWNED);
382         PGRP_LOCK_ASSERT(p->p_pgrp, MA_NOTOWNED);
383         SESS_LOCK_ASSERT(p->p_session, MA_NOTOWNED);
384
385         savepgrp = p->p_pgrp;
386
387         /*
388          * Adjust eligibility of affected pgrps to participate in job control.
389          * Increment eligibility counts before decrementing, otherwise we
390          * could reach 0 spuriously during the first call.
391          */
392         fixjobc(p, pgrp, 1);
393         fixjobc(p, p->p_pgrp, 0);
394
395         mtx_lock(&Giant);       /* XXX TTY */
396         PGRP_LOCK(pgrp);
397         PGRP_LOCK(savepgrp);
398         PROC_LOCK(p);
399         LIST_REMOVE(p, p_pglist);
400         p->p_pgrp = pgrp;
401         PROC_UNLOCK(p);
402         LIST_INSERT_HEAD(&pgrp->pg_members, p, p_pglist);
403         PGRP_UNLOCK(savepgrp);
404         PGRP_UNLOCK(pgrp);
405         mtx_unlock(&Giant);     /* XXX TTY */
406         if (LIST_EMPTY(&savepgrp->pg_members))
407                 pgdelete(savepgrp);
408 }
409
410 /*
411  * remove process from process group
412  */
413 int
414 leavepgrp(p)
415         register struct proc *p;
416 {
417         struct pgrp *savepgrp;
418
419         sx_assert(&proctree_lock, SX_XLOCKED);
420         savepgrp = p->p_pgrp;
421         mtx_lock(&Giant);       /* XXX TTY */
422         PGRP_LOCK(savepgrp);
423         PROC_LOCK(p);
424         LIST_REMOVE(p, p_pglist);
425         p->p_pgrp = NULL;
426         PROC_UNLOCK(p);
427         PGRP_UNLOCK(savepgrp);
428         mtx_unlock(&Giant);     /* XXX TTY */
429         if (LIST_EMPTY(&savepgrp->pg_members))
430                 pgdelete(savepgrp);
431         return (0);
432 }
433
434 /*
435  * delete a process group
436  */
437 static void
438 pgdelete(pgrp)
439         register struct pgrp *pgrp;
440 {
441         struct session *savesess;
442
443         sx_assert(&proctree_lock, SX_XLOCKED);
444         PGRP_LOCK_ASSERT(pgrp, MA_NOTOWNED);
445         SESS_LOCK_ASSERT(pgrp->pg_session, MA_NOTOWNED);
446
447         /*
448          * Reset any sigio structures pointing to us as a result of
449          * F_SETOWN with our pgid.
450          */
451         funsetownlst(&pgrp->pg_sigiolst);
452
453         mtx_lock(&Giant);       /* XXX TTY */
454         PGRP_LOCK(pgrp);
455         if (pgrp->pg_session->s_ttyp != NULL &&
456             pgrp->pg_session->s_ttyp->t_pgrp == pgrp)
457                 pgrp->pg_session->s_ttyp->t_pgrp = NULL;
458         LIST_REMOVE(pgrp, pg_hash);
459         savesess = pgrp->pg_session;
460         SESSRELE(savesess);
461         PGRP_UNLOCK(pgrp);
462         mtx_destroy(&pgrp->pg_mtx);
463         FREE(pgrp, M_PGRP);
464         mtx_unlock(&Giant);     /* XXX TTY */
465 }
466
467 static void
468 pgadjustjobc(pgrp, entering)
469         struct pgrp *pgrp;
470         int entering;
471 {
472
473         PGRP_LOCK(pgrp);
474         if (entering)
475                 pgrp->pg_jobc++;
476         else {
477                 --pgrp->pg_jobc;
478                 if (pgrp->pg_jobc == 0)
479                         orphanpg(pgrp);
480         }
481         PGRP_UNLOCK(pgrp);
482 }
483
484 /*
485  * Adjust pgrp jobc counters when specified process changes process group.
486  * We count the number of processes in each process group that "qualify"
487  * the group for terminal job control (those with a parent in a different
488  * process group of the same session).  If that count reaches zero, the
489  * process group becomes orphaned.  Check both the specified process'
490  * process group and that of its children.
491  * entering == 0 => p is leaving specified group.
492  * entering == 1 => p is entering specified group.
493  */
494 void
495 fixjobc(p, pgrp, entering)
496         register struct proc *p;
497         register struct pgrp *pgrp;
498         int entering;
499 {
500         register struct pgrp *hispgrp;
501         register struct session *mysession;
502
503         sx_assert(&proctree_lock, SX_LOCKED);
504         PROC_LOCK_ASSERT(p, MA_NOTOWNED);
505         PGRP_LOCK_ASSERT(pgrp, MA_NOTOWNED);
506         SESS_LOCK_ASSERT(pgrp->pg_session, MA_NOTOWNED);
507
508         /*
509          * Check p's parent to see whether p qualifies its own process
510          * group; if so, adjust count for p's process group.
511          */
512         mysession = pgrp->pg_session;
513         if ((hispgrp = p->p_pptr->p_pgrp) != pgrp &&
514             hispgrp->pg_session == mysession)
515                 pgadjustjobc(pgrp, entering);
516
517         /*
518          * Check this process' children to see whether they qualify
519          * their process groups; if so, adjust counts for children's
520          * process groups.
521          */
522         LIST_FOREACH(p, &p->p_children, p_sibling) {
523                 hispgrp = p->p_pgrp;
524                 if (hispgrp == pgrp ||
525                     hispgrp->pg_session != mysession)
526                         continue;
527                 PROC_LOCK(p);
528                 if (p->p_state == PRS_ZOMBIE) {
529                         PROC_UNLOCK(p);
530                         continue;
531                 }
532                 PROC_UNLOCK(p);
533                 pgadjustjobc(hispgrp, entering);
534         }
535 }
536
537 /*
538  * A process group has become orphaned;
539  * if there are any stopped processes in the group,
540  * hang-up all process in that group.
541  */
542 static void
543 orphanpg(pg)
544         struct pgrp *pg;
545 {
546         register struct proc *p;
547
548         PGRP_LOCK_ASSERT(pg, MA_OWNED);
549
550         LIST_FOREACH(p, &pg->pg_members, p_pglist) {
551                 PROC_LOCK(p);
552                 if (P_SHOULDSTOP(p)) {
553                         PROC_UNLOCK(p);
554                         LIST_FOREACH(p, &pg->pg_members, p_pglist) {
555                                 PROC_LOCK(p);
556                                 psignal(p, SIGHUP);
557                                 psignal(p, SIGCONT);
558                                 PROC_UNLOCK(p);
559                         }
560                         return;
561                 }
562                 PROC_UNLOCK(p);
563         }
564 }
565
566 void
567 sessrele(struct session *s)
568 {
569         int i;
570
571         SESS_LOCK(s);
572         i = --s->s_count;
573         SESS_UNLOCK(s);
574         if (i == 0) {
575                 if (s->s_ttyp != NULL)
576                         ttyrel(s->s_ttyp);
577                 mtx_destroy(&s->s_mtx);
578                 FREE(s, M_SESSION);
579         }
580 }
581
582 #include "opt_ddb.h"
583 #ifdef DDB
584 #include <ddb/ddb.h>
585
586 DB_SHOW_COMMAND(pgrpdump, pgrpdump)
587 {
588         register struct pgrp *pgrp;
589         register struct proc *p;
590         register int i;
591
592         for (i = 0; i <= pgrphash; i++) {
593                 if (!LIST_EMPTY(&pgrphashtbl[i])) {
594                         printf("\tindx %d\n", i);
595                         LIST_FOREACH(pgrp, &pgrphashtbl[i], pg_hash) {
596                                 printf(
597                         "\tpgrp %p, pgid %ld, sess %p, sesscnt %d, mem %p\n",
598                                     (void *)pgrp, (long)pgrp->pg_id,
599                                     (void *)pgrp->pg_session,
600                                     pgrp->pg_session->s_count,
601                                     (void *)LIST_FIRST(&pgrp->pg_members));
602                                 LIST_FOREACH(p, &pgrp->pg_members, p_pglist) {
603                                         printf("\t\tpid %ld addr %p pgrp %p\n", 
604                                             (long)p->p_pid, (void *)p,
605                                             (void *)p->p_pgrp);
606                                 }
607                         }
608                 }
609         }
610 }
611 #endif /* DDB */
612
613 /*
614  * Clear kinfo_proc and fill in any information that is common
615  * to all threads in the process.
616  * Must be called with the target process locked.
617  */
618 static void
619 fill_kinfo_proc_only(struct proc *p, struct kinfo_proc *kp)
620 {
621         struct thread *td0;
622         struct tty *tp;
623         struct session *sp;
624         struct timeval tv;
625         struct ucred *cred;
626         struct sigacts *ps;
627
628         bzero(kp, sizeof(*kp));
629
630         kp->ki_structsize = sizeof(*kp);
631         kp->ki_paddr = p;
632         PROC_LOCK_ASSERT(p, MA_OWNED);
633         kp->ki_addr =/* p->p_addr; */0; /* XXXKSE */
634         kp->ki_args = p->p_args;
635         kp->ki_textvp = p->p_textvp;
636 #ifdef KTRACE
637         kp->ki_tracep = p->p_tracevp;
638         mtx_lock(&ktrace_mtx);
639         kp->ki_traceflag = p->p_traceflag;
640         mtx_unlock(&ktrace_mtx);
641 #endif
642         kp->ki_fd = p->p_fd;
643         kp->ki_vmspace = p->p_vmspace;
644         kp->ki_flag = p->p_flag;
645         cred = p->p_ucred;
646         if (cred) {
647                 kp->ki_uid = cred->cr_uid;
648                 kp->ki_ruid = cred->cr_ruid;
649                 kp->ki_svuid = cred->cr_svuid;
650                 /* XXX bde doesn't like KI_NGROUPS */
651                 kp->ki_ngroups = min(cred->cr_ngroups, KI_NGROUPS);
652                 bcopy(cred->cr_groups, kp->ki_groups,
653                     kp->ki_ngroups * sizeof(gid_t));
654                 kp->ki_rgid = cred->cr_rgid;
655                 kp->ki_svgid = cred->cr_svgid;
656                 /* If jailed(cred), emulate the old P_JAILED flag. */
657                 if (jailed(cred)) {
658                         kp->ki_flag |= P_JAILED;
659                         /* If inside a jail, use 0 as a jail ID. */
660                         if (!jailed(curthread->td_ucred))
661                                 kp->ki_jid = cred->cr_prison->pr_id;
662                 }
663         }
664         ps = p->p_sigacts;
665         if (ps) {
666                 mtx_lock(&ps->ps_mtx);
667                 kp->ki_sigignore = ps->ps_sigignore;
668                 kp->ki_sigcatch = ps->ps_sigcatch;
669                 mtx_unlock(&ps->ps_mtx);
670         }
671         mtx_lock_spin(&sched_lock);
672         if (p->p_state != PRS_NEW &&
673             p->p_state != PRS_ZOMBIE &&
674             p->p_vmspace != NULL) {
675                 struct vmspace *vm = p->p_vmspace;
676
677                 kp->ki_size = vm->vm_map.size;
678                 kp->ki_rssize = vmspace_resident_count(vm); /*XXX*/
679                 FOREACH_THREAD_IN_PROC(p, td0) {
680                         if (!TD_IS_SWAPPED(td0))
681                                 kp->ki_rssize += td0->td_kstack_pages;
682                         if (td0->td_altkstack_obj != NULL)
683                                 kp->ki_rssize += td0->td_altkstack_pages;
684                 }
685                 kp->ki_swrss = vm->vm_swrss;
686                 kp->ki_tsize = vm->vm_tsize;
687                 kp->ki_dsize = vm->vm_dsize;
688                 kp->ki_ssize = vm->vm_ssize;
689         } else if (p->p_state == PRS_ZOMBIE)
690                 kp->ki_stat = SZOMB;
691         kp->ki_sflag = p->p_sflag;
692         kp->ki_swtime = p->p_swtime;
693         kp->ki_pid = p->p_pid;
694         kp->ki_nice = p->p_nice;
695         bintime2timeval(&p->p_rux.rux_runtime, &tv);
696         kp->ki_runtime = tv.tv_sec * (u_int64_t)1000000 + tv.tv_usec;
697         mtx_unlock_spin(&sched_lock);
698         if ((p->p_sflag & PS_INMEM) && p->p_stats != NULL) {
699                 kp->ki_start = p->p_stats->p_start;
700                 timevaladd(&kp->ki_start, &boottime);
701                 kp->ki_rusage = p->p_stats->p_ru;
702                 calcru(p, &kp->ki_rusage.ru_utime, &kp->ki_rusage.ru_stime);
703                 calccru(p, &kp->ki_childutime, &kp->ki_childstime);
704
705                 /* Some callers want child-times in a single value */
706                 kp->ki_childtime = kp->ki_childstime;
707                 timevaladd(&kp->ki_childtime, &kp->ki_childutime);
708         }
709         tp = NULL;
710         if (p->p_pgrp) {
711                 kp->ki_pgid = p->p_pgrp->pg_id;
712                 kp->ki_jobc = p->p_pgrp->pg_jobc;
713                 sp = p->p_pgrp->pg_session;
714
715                 if (sp != NULL) {
716                         kp->ki_sid = sp->s_sid;
717                         SESS_LOCK(sp);
718                         strlcpy(kp->ki_login, sp->s_login,
719                             sizeof(kp->ki_login));
720                         if (sp->s_ttyvp)
721                                 kp->ki_kiflag |= KI_CTTY;
722                         if (SESS_LEADER(p))
723                                 kp->ki_kiflag |= KI_SLEADER;
724                         tp = sp->s_ttyp;
725                         SESS_UNLOCK(sp);
726                 }
727         }
728         if ((p->p_flag & P_CONTROLT) && tp != NULL) {
729                 kp->ki_tdev = dev2udev(tp->t_dev);
730                 kp->ki_tpgid = tp->t_pgrp ? tp->t_pgrp->pg_id : NO_PID;
731                 if (tp->t_session)
732                         kp->ki_tsid = tp->t_session->s_sid;
733         } else
734                 kp->ki_tdev = NODEV;
735         if (p->p_comm[0] != '\0') {
736                 strlcpy(kp->ki_comm, p->p_comm, sizeof(kp->ki_comm));
737                 strlcpy(kp->ki_ocomm, p->p_comm, sizeof(kp->ki_ocomm));
738         }
739         if (p->p_sysent && p->p_sysent->sv_name != NULL &&
740             p->p_sysent->sv_name[0] != '\0')
741                 strlcpy(kp->ki_emul, p->p_sysent->sv_name, sizeof(kp->ki_emul));
742         kp->ki_siglist = p->p_siglist;
743         kp->ki_xstat = p->p_xstat;
744         kp->ki_acflag = p->p_acflag;
745         kp->ki_lock = p->p_lock;
746         if (p->p_pptr)
747                 kp->ki_ppid = p->p_pptr->p_pid;
748 }
749
750 /*
751  * Fill in information that is thread specific.
752  * Must be called with sched_lock locked.
753  */
754 static void
755 fill_kinfo_thread(struct thread *td, struct kinfo_proc *kp)
756 {
757         struct ksegrp *kg;
758         struct proc *p;
759
760         p = td->td_proc;
761
762         if (td->td_wmesg != NULL)
763                 strlcpy(kp->ki_wmesg, td->td_wmesg, sizeof(kp->ki_wmesg));
764         else
765                 bzero(kp->ki_wmesg, sizeof(kp->ki_wmesg));
766         if (TD_ON_LOCK(td)) {
767                 kp->ki_kiflag |= KI_LOCKBLOCK;
768                 strlcpy(kp->ki_lockname, td->td_lockname,
769                     sizeof(kp->ki_lockname));
770         } else {
771                 kp->ki_kiflag &= ~KI_LOCKBLOCK;
772                 bzero(kp->ki_lockname, sizeof(kp->ki_lockname));
773         }
774
775         if (p->p_state == PRS_NORMAL) { /*  XXXKSE very approximate */
776                 if (TD_ON_RUNQ(td) ||
777                     TD_CAN_RUN(td) ||
778                     TD_IS_RUNNING(td)) {
779                         kp->ki_stat = SRUN;
780                 } else if (P_SHOULDSTOP(p)) {
781                         kp->ki_stat = SSTOP;
782                 } else if (TD_IS_SLEEPING(td)) {
783                         kp->ki_stat = SSLEEP;
784                 } else if (TD_ON_LOCK(td)) {
785                         kp->ki_stat = SLOCK;
786                 } else {
787                         kp->ki_stat = SWAIT;
788                 }
789         } else if (p->p_state == PRS_ZOMBIE) {
790                 kp->ki_stat = SZOMB;
791         } else {
792                 kp->ki_stat = SIDL;
793         }
794
795         kg = td->td_ksegrp;
796
797         /* things in the KSE GROUP */
798         kp->ki_estcpu = kg->kg_estcpu;
799         kp->ki_slptime = kg->kg_slptime;
800         kp->ki_pri.pri_user = kg->kg_user_pri;
801         kp->ki_pri.pri_class = kg->kg_pri_class;
802
803         /* Things in the thread */
804         kp->ki_wchan = td->td_wchan;
805         kp->ki_pri.pri_level = td->td_priority;
806         kp->ki_pri.pri_native = td->td_base_pri;
807         kp->ki_lastcpu = td->td_lastcpu;
808         kp->ki_oncpu = td->td_oncpu;
809         kp->ki_tdflags = td->td_flags;
810         kp->ki_tid = td->td_tid;
811         kp->ki_numthreads = p->p_numthreads;
812         kp->ki_pcb = td->td_pcb;
813         kp->ki_kstack = (void *)td->td_kstack;
814         kp->ki_pctcpu = sched_pctcpu(td);
815
816         /* We can't get this anymore but ps etc never used it anyway. */
817         kp->ki_rqindex = 0;
818
819         SIGSETOR(kp->ki_siglist, td->td_siglist);
820         kp->ki_sigmask = td->td_sigmask;
821 }
822
823 /*
824  * Fill in a kinfo_proc structure for the specified process.
825  * Must be called with the target process locked.
826  */
827 void
828 fill_kinfo_proc(struct proc *p, struct kinfo_proc *kp)
829 {
830
831         fill_kinfo_proc_only(p, kp);
832         mtx_lock_spin(&sched_lock);
833         if (FIRST_THREAD_IN_PROC(p) != NULL)
834                 fill_kinfo_thread(FIRST_THREAD_IN_PROC(p), kp);
835         mtx_unlock_spin(&sched_lock);
836 }
837
838 struct pstats *
839 pstats_alloc(void)
840 {
841
842         return (malloc(sizeof(struct pstats), M_SUBPROC, M_ZERO|M_WAITOK));
843 }
844
845 /*
846  * Copy parts of p_stats; zero the rest of p_stats (statistics).
847  */
848 void
849 pstats_fork(struct pstats *src, struct pstats *dst)
850 {
851
852         bzero(&dst->pstat_startzero,
853             __rangeof(struct pstats, pstat_startzero, pstat_endzero));
854         bcopy(&src->pstat_startcopy, &dst->pstat_startcopy,
855             __rangeof(struct pstats, pstat_startcopy, pstat_endcopy));
856 }
857
858 void
859 pstats_free(struct pstats *ps)
860 {
861
862         free(ps, M_SUBPROC);
863 }
864
865 /*
866  * Locate a zombie process by number
867  */
868 struct proc *
869 zpfind(pid_t pid)
870 {
871         struct proc *p;
872
873         sx_slock(&allproc_lock);
874         LIST_FOREACH(p, &zombproc, p_list)
875                 if (p->p_pid == pid) {
876                         PROC_LOCK(p);
877                         break;
878                 }
879         sx_sunlock(&allproc_lock);
880         return (p);
881 }
882
883 #define KERN_PROC_ZOMBMASK      0x3
884 #define KERN_PROC_NOTHREADS     0x4
885
886 /*
887  * Must be called with the process locked and will return with it unlocked.
888  */
889 static int
890 sysctl_out_proc(struct proc *p, struct sysctl_req *req, int flags)
891 {
892         struct thread *td;
893         struct kinfo_proc kinfo_proc;
894         int error = 0;
895         struct proc *np;
896         pid_t pid = p->p_pid;
897
898         PROC_LOCK_ASSERT(p, MA_OWNED);
899
900         fill_kinfo_proc_only(p, &kinfo_proc);
901         if (flags & KERN_PROC_NOTHREADS) {
902                 mtx_lock_spin(&sched_lock);
903                 if (FIRST_THREAD_IN_PROC(p) != NULL)
904                         fill_kinfo_thread(FIRST_THREAD_IN_PROC(p), &kinfo_proc);
905                 mtx_unlock_spin(&sched_lock);
906                 error = SYSCTL_OUT(req, (caddr_t)&kinfo_proc,
907                                    sizeof(kinfo_proc));
908         } else {
909                 mtx_lock_spin(&sched_lock);
910                 if (FIRST_THREAD_IN_PROC(p) != NULL)
911                         FOREACH_THREAD_IN_PROC(p, td) {
912                                 fill_kinfo_thread(td, &kinfo_proc);
913                                 error = SYSCTL_OUT(req, (caddr_t)&kinfo_proc,
914                                                 sizeof(kinfo_proc));
915                                 if (error)
916                                         break;
917                         }
918                 else
919                         error = SYSCTL_OUT(req, (caddr_t)&kinfo_proc,
920                                         sizeof(kinfo_proc));
921                 mtx_unlock_spin(&sched_lock);
922         }
923         PROC_UNLOCK(p);
924         if (error)
925                 return (error);
926         if (flags & KERN_PROC_ZOMBMASK)
927                 np = zpfind(pid);
928         else {
929                 if (pid == 0)
930                         return (0);
931                 np = pfind(pid);
932         }
933         if (np == NULL)
934                 return EAGAIN;
935         if (np != p) {
936                 PROC_UNLOCK(np);
937                 return EAGAIN;
938         }
939         PROC_UNLOCK(np);
940         return (0);
941 }
942
943 static int
944 sysctl_kern_proc(SYSCTL_HANDLER_ARGS)
945 {
946         int *name = (int*) arg1;
947         u_int namelen = arg2;
948         struct proc *p;
949         int flags, doingzomb, oid_number;
950         int error = 0;
951
952         oid_number = oidp->oid_number;
953         if (oid_number != KERN_PROC_ALL &&
954             (oid_number & KERN_PROC_INC_THREAD) == 0)
955                 flags = KERN_PROC_NOTHREADS;
956         else {
957                 flags = 0;
958                 oid_number &= ~KERN_PROC_INC_THREAD;
959         }
960         if (oid_number == KERN_PROC_PID) {
961                 if (namelen != 1) 
962                         return (EINVAL);
963                 error = sysctl_wire_old_buffer(req, 0);
964                 if (error)
965                         return (error);         
966                 p = pfind((pid_t)name[0]);
967                 if (!p)
968                         return (ESRCH);
969                 if ((error = p_cansee(curthread, p))) {
970                         PROC_UNLOCK(p);
971                         return (error);
972                 }
973                 error = sysctl_out_proc(p, req, flags);
974                 return (error);
975         }
976
977         switch (oid_number) {
978         case KERN_PROC_ALL:
979                 if (namelen != 0)
980                         return (EINVAL);
981                 break;
982         case KERN_PROC_PROC:
983                 if (namelen != 0 && namelen != 1)
984                         return (EINVAL);
985                 break;
986         default:
987                 if (namelen != 1)
988                         return (EINVAL);
989                 break;
990         }
991         
992         if (!req->oldptr) {
993                 /* overestimate by 5 procs */
994                 error = SYSCTL_OUT(req, 0, sizeof (struct kinfo_proc) * 5);
995                 if (error)
996                         return (error);
997         }
998         error = sysctl_wire_old_buffer(req, 0);
999         if (error != 0)
1000                 return (error);
1001         sx_slock(&allproc_lock);
1002         for (doingzomb=0 ; doingzomb < 2 ; doingzomb++) {
1003                 if (!doingzomb)
1004                         p = LIST_FIRST(&allproc);
1005                 else
1006                         p = LIST_FIRST(&zombproc);
1007                 for (; p != 0; p = LIST_NEXT(p, p_list)) {
1008                         /*
1009                          * Skip embryonic processes.
1010                          */
1011                         mtx_lock_spin(&sched_lock);
1012                         if (p->p_state == PRS_NEW) {
1013                                 mtx_unlock_spin(&sched_lock);
1014                                 continue;
1015                         }
1016                         mtx_unlock_spin(&sched_lock);
1017                         PROC_LOCK(p);
1018                         /*
1019                          * Show a user only appropriate processes.
1020                          */
1021                         if (p_cansee(curthread, p)) {
1022                                 PROC_UNLOCK(p);
1023                                 continue;
1024                         }
1025                         /*
1026                          * TODO - make more efficient (see notes below).
1027                          * do by session.
1028                          */
1029                         switch (oid_number) {
1030
1031                         case KERN_PROC_GID:
1032                                 if (p->p_ucred == NULL ||
1033                                     p->p_ucred->cr_gid != (gid_t)name[0]) {
1034                                         PROC_UNLOCK(p);
1035                                         continue;
1036                                 }
1037                                 break;
1038
1039                         case KERN_PROC_PGRP:
1040                                 /* could do this by traversing pgrp */
1041                                 if (p->p_pgrp == NULL || 
1042                                     p->p_pgrp->pg_id != (pid_t)name[0]) {
1043                                         PROC_UNLOCK(p);
1044                                         continue;
1045                                 }
1046                                 break;
1047
1048                         case KERN_PROC_RGID:
1049                                 if (p->p_ucred == NULL ||
1050                                     p->p_ucred->cr_rgid != (gid_t)name[0]) {
1051                                         PROC_UNLOCK(p);
1052                                         continue;
1053                                 }
1054                                 break;
1055
1056                         case KERN_PROC_SESSION:
1057                                 if (p->p_session == NULL ||
1058                                     p->p_session->s_sid != (pid_t)name[0]) {
1059                                         PROC_UNLOCK(p);
1060                                         continue;
1061                                 }
1062                                 break;
1063
1064                         case KERN_PROC_TTY:
1065                                 if ((p->p_flag & P_CONTROLT) == 0 ||
1066                                     p->p_session == NULL) {
1067                                         PROC_UNLOCK(p);
1068                                         continue;
1069                                 }
1070                                 SESS_LOCK(p->p_session);
1071                                 if (p->p_session->s_ttyp == NULL ||
1072                                     dev2udev(p->p_session->s_ttyp->t_dev) != 
1073                                     (dev_t)name[0]) {
1074                                         SESS_UNLOCK(p->p_session);
1075                                         PROC_UNLOCK(p);
1076                                         continue;
1077                                 }
1078                                 SESS_UNLOCK(p->p_session);
1079                                 break;
1080
1081                         case KERN_PROC_UID:
1082                                 if (p->p_ucred == NULL || 
1083                                     p->p_ucred->cr_uid != (uid_t)name[0]) {
1084                                         PROC_UNLOCK(p);
1085                                         continue;
1086                                 }
1087                                 break;
1088
1089                         case KERN_PROC_RUID:
1090                                 if (p->p_ucred == NULL || 
1091                                     p->p_ucred->cr_ruid != (uid_t)name[0]) {
1092                                         PROC_UNLOCK(p);
1093                                         continue;
1094                                 }
1095                                 break;
1096
1097                         case KERN_PROC_PROC:
1098                                 break;
1099
1100                         default:
1101                                 break;
1102
1103                         }
1104
1105                         error = sysctl_out_proc(p, req, flags | doingzomb);
1106                         if (error) {
1107                                 sx_sunlock(&allproc_lock);
1108                                 return (error);
1109                         }
1110                 }
1111         }
1112         sx_sunlock(&allproc_lock);
1113         return (0);
1114 }
1115
1116 struct pargs *
1117 pargs_alloc(int len)
1118 {
1119         struct pargs *pa;
1120
1121         MALLOC(pa, struct pargs *, sizeof(struct pargs) + len, M_PARGS,
1122                 M_WAITOK);
1123         pa->ar_ref = 1;
1124         pa->ar_length = len;
1125         return (pa);
1126 }
1127
1128 void
1129 pargs_free(struct pargs *pa)
1130 {
1131
1132         FREE(pa, M_PARGS);
1133 }
1134
1135 void
1136 pargs_hold(struct pargs *pa)
1137 {
1138
1139         if (pa == NULL)
1140                 return;
1141         PARGS_LOCK(pa);
1142         pa->ar_ref++;
1143         PARGS_UNLOCK(pa);
1144 }
1145
1146 void
1147 pargs_drop(struct pargs *pa)
1148 {
1149
1150         if (pa == NULL)
1151                 return;
1152         PARGS_LOCK(pa);
1153         if (--pa->ar_ref == 0) {
1154                 PARGS_UNLOCK(pa);
1155                 pargs_free(pa);
1156         } else
1157                 PARGS_UNLOCK(pa);
1158 }
1159
1160 /*
1161  * This sysctl allows a process to retrieve the argument list or process
1162  * title for another process without groping around in the address space
1163  * of the other process.  It also allow a process to set its own "process 
1164  * title to a string of its own choice.
1165  */
1166 static int
1167 sysctl_kern_proc_args(SYSCTL_HANDLER_ARGS)
1168 {
1169         int *name = (int*) arg1;
1170         u_int namelen = arg2;
1171         struct pargs *newpa, *pa;
1172         struct proc *p;
1173         int error = 0;
1174
1175         if (namelen != 1) 
1176                 return (EINVAL);
1177
1178         p = pfind((pid_t)name[0]);
1179         if (!p)
1180                 return (ESRCH);
1181
1182         if ((error = p_cansee(curthread, p)) != 0) {
1183                 PROC_UNLOCK(p);
1184                 return (error);
1185         }
1186
1187         if (req->newptr && curproc != p) {
1188                 PROC_UNLOCK(p);
1189                 return (EPERM);
1190         }
1191
1192         pa = p->p_args;
1193         pargs_hold(pa);
1194         PROC_UNLOCK(p);
1195         if (req->oldptr != NULL && pa != NULL)
1196                 error = SYSCTL_OUT(req, pa->ar_args, pa->ar_length);
1197         pargs_drop(pa);
1198         if (error != 0 || req->newptr == NULL)
1199                 return (error);
1200
1201         if (req->newlen + sizeof(struct pargs) > ps_arg_cache_limit)
1202                 return (ENOMEM);
1203         newpa = pargs_alloc(req->newlen);
1204         error = SYSCTL_IN(req, newpa->ar_args, req->newlen);
1205         if (error != 0) {
1206                 pargs_free(newpa);
1207                 return (error);
1208         }
1209         PROC_LOCK(p);
1210         pa = p->p_args;
1211         p->p_args = newpa;
1212         PROC_UNLOCK(p);
1213         pargs_drop(pa);
1214         return (0);
1215 }
1216
1217 /*
1218  * This sysctl allows a process to retrieve the path of the executable for
1219  * itself or another process.
1220  */
1221 static int
1222 sysctl_kern_proc_pathname(SYSCTL_HANDLER_ARGS)
1223 {
1224         pid_t *pidp = (pid_t *)arg1;
1225         unsigned int arglen = arg2;
1226         struct proc *p;
1227         struct vnode *vp;
1228         char *retbuf, *freebuf;
1229         int error;
1230
1231         if (arglen != 1)
1232                 return (EINVAL);
1233         if (*pidp == -1) {      /* -1 means this process */
1234                 p = req->td->td_proc;
1235         } else {
1236                 p = pfind(*pidp);
1237                 if (p == NULL)
1238                         return (ESRCH);
1239                 if ((error = p_cansee(curthread, p)) != 0) {
1240                         PROC_UNLOCK(p);
1241                         return (error);
1242                 }
1243         }
1244
1245         vp = p->p_textvp;
1246         if (vp == NULL) {
1247                 if (*pidp != -1)
1248                         PROC_UNLOCK(p);
1249                 return (0);
1250         }
1251         vref(vp);
1252         if (*pidp != -1)
1253                 PROC_UNLOCK(p);
1254         error = vn_fullpath(req->td, vp, &retbuf, &freebuf);
1255         vrele(vp);
1256         if (error)
1257                 return (error);
1258         error = SYSCTL_OUT(req, retbuf, strlen(retbuf) + 1);
1259         free(freebuf, M_TEMP);
1260         return (error);
1261 }
1262
1263 static int
1264 sysctl_kern_proc_sv_name(SYSCTL_HANDLER_ARGS)
1265 {
1266         struct proc *p;
1267         char *sv_name;
1268         int *name;
1269         int namelen;
1270         int error;
1271
1272         namelen = arg2;
1273         if (namelen != 1) 
1274                 return (EINVAL);
1275
1276         name = (int *)arg1;
1277         if ((p = pfind((pid_t)name[0])) == NULL)
1278                 return (ESRCH);
1279         if ((error = p_cansee(curthread, p))) {
1280                 PROC_UNLOCK(p);
1281                 return (error);
1282         }
1283         sv_name = p->p_sysent->sv_name;
1284         PROC_UNLOCK(p);
1285         return (sysctl_handle_string(oidp, sv_name, 0, req));
1286 }
1287
1288
1289 static SYSCTL_NODE(_kern, KERN_PROC, proc, CTLFLAG_RD,  0, "Process table");
1290
1291 SYSCTL_PROC(_kern_proc, KERN_PROC_ALL, all, CTLFLAG_RD|CTLTYPE_STRUCT,
1292         0, 0, sysctl_kern_proc, "S,proc", "Return entire process table");
1293
1294 static SYSCTL_NODE(_kern_proc, KERN_PROC_GID, gid, CTLFLAG_RD,
1295         sysctl_kern_proc, "Process table");
1296
1297 static SYSCTL_NODE(_kern_proc, KERN_PROC_PGRP, pgrp, CTLFLAG_RD, 
1298         sysctl_kern_proc, "Process table");
1299
1300 static SYSCTL_NODE(_kern_proc, KERN_PROC_RGID, rgid, CTLFLAG_RD,
1301         sysctl_kern_proc, "Process table");
1302
1303 static SYSCTL_NODE(_kern_proc, KERN_PROC_SESSION, sid, CTLFLAG_RD,
1304         sysctl_kern_proc, "Process table");
1305
1306 static SYSCTL_NODE(_kern_proc, KERN_PROC_TTY, tty, CTLFLAG_RD, 
1307         sysctl_kern_proc, "Process table");
1308
1309 static SYSCTL_NODE(_kern_proc, KERN_PROC_UID, uid, CTLFLAG_RD, 
1310         sysctl_kern_proc, "Process table");
1311
1312 static SYSCTL_NODE(_kern_proc, KERN_PROC_RUID, ruid, CTLFLAG_RD, 
1313         sysctl_kern_proc, "Process table");
1314
1315 static SYSCTL_NODE(_kern_proc, KERN_PROC_PID, pid, CTLFLAG_RD, 
1316         sysctl_kern_proc, "Process table");
1317
1318 static SYSCTL_NODE(_kern_proc, KERN_PROC_PROC, proc, CTLFLAG_RD,
1319         sysctl_kern_proc, "Return process table, no threads");
1320
1321 static SYSCTL_NODE(_kern_proc, KERN_PROC_ARGS, args,
1322         CTLFLAG_RW | CTLFLAG_ANYBODY,
1323         sysctl_kern_proc_args, "Process argument list");
1324
1325 static SYSCTL_NODE(_kern_proc, KERN_PROC_PATHNAME, pathname, CTLFLAG_RD,
1326         sysctl_kern_proc_pathname, "Process executable path");
1327
1328 static SYSCTL_NODE(_kern_proc, KERN_PROC_SV_NAME, sv_name, CTLFLAG_RD,
1329         sysctl_kern_proc_sv_name, "Process syscall vector name (ABI type)");
1330
1331 static SYSCTL_NODE(_kern_proc, (KERN_PROC_GID | KERN_PROC_INC_THREAD), gid_td,
1332         CTLFLAG_RD, sysctl_kern_proc, "Process table");
1333
1334 static SYSCTL_NODE(_kern_proc, (KERN_PROC_PGRP | KERN_PROC_INC_THREAD), pgrp_td,
1335         CTLFLAG_RD, sysctl_kern_proc, "Process table");
1336
1337 static SYSCTL_NODE(_kern_proc, (KERN_PROC_RGID | KERN_PROC_INC_THREAD), rgid_td,
1338         CTLFLAG_RD, sysctl_kern_proc, "Process table");
1339
1340 static SYSCTL_NODE(_kern_proc, (KERN_PROC_SESSION | KERN_PROC_INC_THREAD),
1341         sid_td, CTLFLAG_RD, sysctl_kern_proc, "Process table");
1342
1343 static SYSCTL_NODE(_kern_proc, (KERN_PROC_TTY | KERN_PROC_INC_THREAD), tty_td,
1344         CTLFLAG_RD, sysctl_kern_proc, "Process table");
1345
1346 static SYSCTL_NODE(_kern_proc, (KERN_PROC_UID | KERN_PROC_INC_THREAD), uid_td,
1347         CTLFLAG_RD, sysctl_kern_proc, "Process table");
1348
1349 static SYSCTL_NODE(_kern_proc, (KERN_PROC_RUID | KERN_PROC_INC_THREAD), ruid_td,
1350         CTLFLAG_RD, sysctl_kern_proc, "Process table");
1351
1352 static SYSCTL_NODE(_kern_proc, (KERN_PROC_PID | KERN_PROC_INC_THREAD), pid_td,
1353         CTLFLAG_RD, sysctl_kern_proc, "Process table");
1354
1355 static SYSCTL_NODE(_kern_proc, (KERN_PROC_PROC | KERN_PROC_INC_THREAD), proc_td,
1356         CTLFLAG_RD, sysctl_kern_proc, "Return process table, no threads");