kern_proc.c revision 1.136 1 /* $NetBSD: kern_proc.c,v 1.136 2008/04/24 15:35:29 ad Exp $ */
2
3 /*-
4 * Copyright (c) 1999, 2006, 2007, 2008 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 * NASA Ames Research Center, and by Andrew Doran.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by the NetBSD
22 * Foundation, Inc. and its contributors.
23 * 4. Neither the name of The NetBSD Foundation nor the names of its
24 * contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGE.
38 */
39
40 /*
41 * Copyright (c) 1982, 1986, 1989, 1991, 1993
42 * The Regents of the University of California. All rights reserved.
43 *
44 * Redistribution and use in source and binary forms, with or without
45 * modification, are permitted provided that the following conditions
46 * are met:
47 * 1. Redistributions of source code must retain the above copyright
48 * notice, this list of conditions and the following disclaimer.
49 * 2. Redistributions in binary form must reproduce the above copyright
50 * notice, this list of conditions and the following disclaimer in the
51 * documentation and/or other materials provided with the distribution.
52 * 3. Neither the name of the University nor the names of its contributors
53 * may be used to endorse or promote products derived from this software
54 * without specific prior written permission.
55 *
56 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
57 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
58 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
59 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
60 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
61 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
62 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
63 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
64 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
65 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
66 * SUCH DAMAGE.
67 *
68 * @(#)kern_proc.c 8.7 (Berkeley) 2/14/95
69 */
70
71 #include <sys/cdefs.h>
72 __KERNEL_RCSID(0, "$NetBSD: kern_proc.c,v 1.136 2008/04/24 15:35:29 ad Exp $");
73
74 #include "opt_kstack.h"
75 #include "opt_maxuprc.h"
76 #include "opt_multiprocessor.h"
77 #include "opt_lockdebug.h"
78
79 #include <sys/param.h>
80 #include <sys/systm.h>
81 #include <sys/kernel.h>
82 #include <sys/proc.h>
83 #include <sys/resourcevar.h>
84 #include <sys/buf.h>
85 #include <sys/acct.h>
86 #include <sys/wait.h>
87 #include <sys/file.h>
88 #include <ufs/ufs/quota.h>
89 #include <sys/uio.h>
90 #include <sys/malloc.h>
91 #include <sys/pool.h>
92 #include <sys/mbuf.h>
93 #include <sys/ioctl.h>
94 #include <sys/tty.h>
95 #include <sys/signalvar.h>
96 #include <sys/ras.h>
97 #include <sys/filedesc.h>
98 #include "sys/syscall_stats.h"
99 #include <sys/kauth.h>
100 #include <sys/sleepq.h>
101 #include <sys/atomic.h>
102 #include <sys/kmem.h>
103
104 #include <uvm/uvm.h>
105 #include <uvm/uvm_extern.h>
106
107 /*
108 * Other process lists
109 */
110
111 struct proclist allproc;
112 struct proclist zombproc; /* resources have been freed */
113
114 kmutex_t *proc_lock;
115
116 /*
117 * pid to proc lookup is done by indexing the pid_table array.
118 * Since pid numbers are only allocated when an empty slot
119 * has been found, there is no need to search any lists ever.
120 * (an orphaned pgrp will lock the slot, a session will lock
121 * the pgrp with the same number.)
122 * If the table is too small it is reallocated with twice the
123 * previous size and the entries 'unzipped' into the two halves.
124 * A linked list of free entries is passed through the pt_proc
125 * field of 'free' items - set odd to be an invalid ptr.
126 */
127
128 struct pid_table {
129 struct proc *pt_proc;
130 struct pgrp *pt_pgrp;
131 };
132 #if 1 /* strongly typed cast - should be a noop */
133 static inline uint p2u(struct proc *p) { return (uint)(uintptr_t)p; }
134 #else
135 #define p2u(p) ((uint)p)
136 #endif
137 #define P_VALID(p) (!(p2u(p) & 1))
138 #define P_NEXT(p) (p2u(p) >> 1)
139 #define P_FREE(pid) ((struct proc *)(uintptr_t)((pid) << 1 | 1))
140
141 #define INITIAL_PID_TABLE_SIZE (1 << 5)
142 static struct pid_table *pid_table;
143 static uint pid_tbl_mask = INITIAL_PID_TABLE_SIZE - 1;
144 static uint pid_alloc_lim; /* max we allocate before growing table */
145 static uint pid_alloc_cnt; /* number of allocated pids */
146
147 /* links through free slots - never empty! */
148 static uint next_free_pt, last_free_pt;
149 static pid_t pid_max = PID_MAX; /* largest value we allocate */
150
151 /* Components of the first process -- never freed. */
152
153 extern const struct emul emul_netbsd; /* defined in kern_exec.c */
154
155 struct session session0 = {
156 .s_count = 1,
157 .s_sid = 0,
158 };
159 struct pgrp pgrp0 = {
160 .pg_members = LIST_HEAD_INITIALIZER(&pgrp0.pg_members),
161 .pg_session = &session0,
162 };
163 filedesc_t filedesc0;
164 struct cwdinfo cwdi0 = {
165 .cwdi_cmask = CMASK, /* see cmask below */
166 .cwdi_refcnt = 1,
167 };
168 struct plimit limit0 = {
169 .pl_corename = defcorename,
170 .pl_refcnt = 1,
171 .pl_rlimit = {
172 [0 ... __arraycount(limit0.pl_rlimit) - 1] = {
173 .rlim_cur = RLIM_INFINITY,
174 .rlim_max = RLIM_INFINITY,
175 },
176 },
177 };
178 struct pstats pstat0;
179 struct vmspace vmspace0;
180 struct sigacts sigacts0;
181 struct turnstile turnstile0;
182 struct proc proc0 = {
183 .p_lwps = LIST_HEAD_INITIALIZER(&proc0.p_lwps),
184 .p_sigwaiters = LIST_HEAD_INITIALIZER(&proc0.p_sigwaiters),
185 .p_nlwps = 1,
186 .p_nrlwps = 1,
187 .p_nlwpid = 1, /* must match lwp0.l_lid */
188 .p_pgrp = &pgrp0,
189 .p_comm = "system",
190 /*
191 * Set P_NOCLDWAIT so that kernel threads are reparented to init(8)
192 * when they exit. init(8) can easily wait them out for us.
193 */
194 .p_flag = PK_SYSTEM | PK_NOCLDWAIT,
195 .p_stat = SACTIVE,
196 .p_nice = NZERO,
197 .p_emul = &emul_netbsd,
198 .p_cwdi = &cwdi0,
199 .p_limit = &limit0,
200 .p_fd = &filedesc0,
201 .p_vmspace = &vmspace0,
202 .p_stats = &pstat0,
203 .p_sigacts = &sigacts0,
204 };
205 struct lwp lwp0 __aligned(MIN_LWP_ALIGNMENT) = {
206 #ifdef LWP0_CPU_INFO
207 .l_cpu = LWP0_CPU_INFO,
208 #endif
209 .l_proc = &proc0,
210 .l_lid = 1,
211 .l_flag = LW_INMEM | LW_SYSTEM,
212 .l_stat = LSONPROC,
213 .l_ts = &turnstile0,
214 .l_syncobj = &sched_syncobj,
215 .l_refcnt = 1,
216 .l_priority = PRI_USER + NPRI_USER - 1,
217 .l_inheritedprio = -1,
218 .l_class = SCHED_OTHER,
219 .l_pi_lenders = SLIST_HEAD_INITIALIZER(&lwp0.l_pi_lenders),
220 .l_name = __UNCONST("swapper"),
221 };
222 kauth_cred_t cred0;
223
224 extern struct user *proc0paddr;
225
226 int nofile = NOFILE;
227 int maxuprc = MAXUPRC;
228 int cmask = CMASK;
229
230 MALLOC_DEFINE(M_EMULDATA, "emuldata", "Per-process emulation data");
231 MALLOC_DEFINE(M_PROC, "proc", "Proc structures");
232 MALLOC_DEFINE(M_SUBPROC, "subproc", "Proc sub-structures");
233
234 /*
235 * The process list descriptors, used during pid allocation and
236 * by sysctl. No locking on this data structure is needed since
237 * it is completely static.
238 */
239 const struct proclist_desc proclists[] = {
240 { &allproc },
241 { &zombproc },
242 { NULL },
243 };
244
245 static void orphanpg(struct pgrp *);
246 static void pg_delete(pid_t);
247
248 static specificdata_domain_t proc_specificdata_domain;
249
250 static pool_cache_t proc_cache;
251
252 /*
253 * Initialize global process hashing structures.
254 */
255 void
256 procinit(void)
257 {
258 const struct proclist_desc *pd;
259 int i;
260 #define LINK_EMPTY ((PID_MAX + INITIAL_PID_TABLE_SIZE) & ~(INITIAL_PID_TABLE_SIZE - 1))
261
262 for (pd = proclists; pd->pd_list != NULL; pd++)
263 LIST_INIT(pd->pd_list);
264
265 proc_lock = mutex_obj_alloc(MUTEX_DEFAULT, IPL_NONE);
266
267 pid_table = malloc(INITIAL_PID_TABLE_SIZE * sizeof *pid_table,
268 M_PROC, M_WAITOK);
269 /* Set free list running through table...
270 Preset 'use count' above PID_MAX so we allocate pid 1 next. */
271 for (i = 0; i <= pid_tbl_mask; i++) {
272 pid_table[i].pt_proc = P_FREE(LINK_EMPTY + i + 1);
273 pid_table[i].pt_pgrp = 0;
274 }
275 /* slot 0 is just grabbed */
276 next_free_pt = 1;
277 /* Need to fix last entry. */
278 last_free_pt = pid_tbl_mask;
279 pid_table[last_free_pt].pt_proc = P_FREE(LINK_EMPTY);
280 /* point at which we grow table - to avoid reusing pids too often */
281 pid_alloc_lim = pid_tbl_mask - 1;
282 #undef LINK_EMPTY
283
284 proc_specificdata_domain = specificdata_domain_create();
285 KASSERT(proc_specificdata_domain != NULL);
286
287 proc_cache = pool_cache_init(sizeof(struct proc), 0, 0, 0,
288 "procpl", NULL, IPL_NONE, NULL, NULL, NULL);
289 }
290
291 /*
292 * Initialize process 0.
293 */
294 void
295 proc0_init(void)
296 {
297 struct proc *p;
298 struct pgrp *pg;
299 struct session *sess;
300 struct lwp *l;
301 rlim_t lim;
302
303 p = &proc0;
304 pg = &pgrp0;
305 sess = &session0;
306 l = &lwp0;
307
308 KASSERT(l->l_lid == p->p_nlwpid);
309
310 mutex_init(&p->p_smutex, MUTEX_DEFAULT, IPL_SCHED);
311 mutex_init(&p->p_stmutex, MUTEX_DEFAULT, IPL_HIGH);
312 mutex_init(&p->p_auxlock, MUTEX_DEFAULT, IPL_NONE);
313 mutex_init(&p->p_mutex, MUTEX_DEFAULT, IPL_NONE);
314 mutex_init(&l->l_swaplock, MUTEX_DEFAULT, IPL_NONE);
315
316 rw_init(&p->p_reflock);
317 cv_init(&p->p_waitcv, "wait");
318 cv_init(&p->p_lwpcv, "lwpwait");
319
320 LIST_INSERT_HEAD(&p->p_lwps, l, l_sibling);
321
322 pid_table[0].pt_proc = p;
323 LIST_INSERT_HEAD(&allproc, p, p_list);
324 LIST_INSERT_HEAD(&alllwp, l, l_list);
325
326 pid_table[0].pt_pgrp = pg;
327 LIST_INSERT_HEAD(&pg->pg_members, p, p_pglist);
328
329 #ifdef __HAVE_SYSCALL_INTERN
330 (*p->p_emul->e_syscall_intern)(p);
331 #endif
332
333 callout_init(&l->l_timeout_ch, CALLOUT_MPSAFE);
334 callout_setfunc(&l->l_timeout_ch, sleepq_timeout, l);
335 cv_init(&l->l_sigcv, "sigwait");
336
337 /* Create credentials. */
338 cred0 = kauth_cred_alloc();
339 p->p_cred = cred0;
340 kauth_cred_hold(cred0);
341 l->l_cred = cred0;
342
343 /* Create the CWD info. */
344 rw_init(&cwdi0.cwdi_lock);
345
346 /* Create the limits structures. */
347 mutex_init(&limit0.pl_lock, MUTEX_DEFAULT, IPL_NONE);
348
349 limit0.pl_rlimit[RLIMIT_NOFILE].rlim_max = maxfiles;
350 limit0.pl_rlimit[RLIMIT_NOFILE].rlim_cur =
351 maxfiles < nofile ? maxfiles : nofile;
352
353 limit0.pl_rlimit[RLIMIT_NPROC].rlim_max = maxproc;
354 limit0.pl_rlimit[RLIMIT_NPROC].rlim_cur =
355 maxproc < maxuprc ? maxproc : maxuprc;
356
357 lim = ptoa(uvmexp.free);
358 limit0.pl_rlimit[RLIMIT_RSS].rlim_max = lim;
359 limit0.pl_rlimit[RLIMIT_MEMLOCK].rlim_max = lim;
360 limit0.pl_rlimit[RLIMIT_MEMLOCK].rlim_cur = lim / 3;
361
362 /* Configure virtual memory system, set vm rlimits. */
363 uvm_init_limits(p);
364
365 /* Initialize file descriptor table for proc0. */
366 fd_init(&filedesc0);
367
368 /*
369 * Initialize proc0's vmspace, which uses the kernel pmap.
370 * All kernel processes (which never have user space mappings)
371 * share proc0's vmspace, and thus, the kernel pmap.
372 */
373 uvmspace_init(&vmspace0, pmap_kernel(), round_page(VM_MIN_ADDRESS),
374 trunc_page(VM_MAX_ADDRESS));
375
376 l->l_addr = proc0paddr; /* XXX */
377
378 /* Initialize signal state for proc0. XXX IPL_SCHED */
379 mutex_init(&p->p_sigacts->sa_mutex, MUTEX_DEFAULT, IPL_SCHED);
380 siginit(p);
381
382 proc_initspecific(p);
383 lwp_initspecific(l);
384
385 SYSCALL_TIME_LWP_INIT(l);
386 }
387
388 /*
389 * Check that the specified process group is in the session of the
390 * specified process.
391 * Treats -ve ids as process ids.
392 * Used to validate TIOCSPGRP requests.
393 */
394 int
395 pgid_in_session(struct proc *p, pid_t pg_id)
396 {
397 struct pgrp *pgrp;
398 struct session *session;
399 int error;
400
401 mutex_enter(proc_lock);
402 if (pg_id < 0) {
403 struct proc *p1 = p_find(-pg_id, PFIND_LOCKED | PFIND_UNLOCK_FAIL);
404 if (p1 == NULL)
405 return EINVAL;
406 pgrp = p1->p_pgrp;
407 } else {
408 pgrp = pg_find(pg_id, PFIND_LOCKED | PFIND_UNLOCK_FAIL);
409 if (pgrp == NULL)
410 return EINVAL;
411 }
412 session = pgrp->pg_session;
413 if (session != p->p_pgrp->pg_session)
414 error = EPERM;
415 else
416 error = 0;
417 mutex_exit(proc_lock);
418
419 return error;
420 }
421
422 /*
423 * Is p an inferior of q?
424 *
425 * Call with the proc_lock held.
426 */
427 int
428 inferior(struct proc *p, struct proc *q)
429 {
430
431 for (; p != q; p = p->p_pptr)
432 if (p->p_pid == 0)
433 return 0;
434 return 1;
435 }
436
437 /*
438 * Locate a process by number
439 */
440 struct proc *
441 p_find(pid_t pid, uint flags)
442 {
443 struct proc *p;
444 char stat;
445
446 if (!(flags & PFIND_LOCKED))
447 mutex_enter(proc_lock);
448
449 p = pid_table[pid & pid_tbl_mask].pt_proc;
450
451 /* Only allow live processes to be found by pid. */
452 /* XXXSMP p_stat */
453 if (P_VALID(p) && p->p_pid == pid && ((stat = p->p_stat) == SACTIVE ||
454 stat == SSTOP || ((flags & PFIND_ZOMBIE) &&
455 (stat == SZOMB || stat == SDEAD || stat == SDYING)))) {
456 if (flags & PFIND_UNLOCK_OK)
457 mutex_exit(proc_lock);
458 return p;
459 }
460 if (flags & PFIND_UNLOCK_FAIL)
461 mutex_exit(proc_lock);
462 return NULL;
463 }
464
465
466 /*
467 * Locate a process group by number
468 */
469 struct pgrp *
470 pg_find(pid_t pgid, uint flags)
471 {
472 struct pgrp *pg;
473
474 if (!(flags & PFIND_LOCKED))
475 mutex_enter(proc_lock);
476 pg = pid_table[pgid & pid_tbl_mask].pt_pgrp;
477 /*
478 * Can't look up a pgrp that only exists because the session
479 * hasn't died yet (traditional)
480 */
481 if (pg == NULL || pg->pg_id != pgid || LIST_EMPTY(&pg->pg_members)) {
482 if (flags & PFIND_UNLOCK_FAIL)
483 mutex_exit(proc_lock);
484 return NULL;
485 }
486
487 if (flags & PFIND_UNLOCK_OK)
488 mutex_exit(proc_lock);
489 return pg;
490 }
491
492 static void
493 expand_pid_table(void)
494 {
495 uint pt_size = pid_tbl_mask + 1;
496 struct pid_table *n_pt, *new_pt;
497 struct proc *proc;
498 struct pgrp *pgrp;
499 int i;
500 pid_t pid;
501
502 new_pt = malloc(pt_size * 2 * sizeof *new_pt, M_PROC, M_WAITOK);
503
504 mutex_enter(proc_lock);
505 if (pt_size != pid_tbl_mask + 1) {
506 /* Another process beat us to it... */
507 mutex_exit(proc_lock);
508 FREE(new_pt, M_PROC);
509 return;
510 }
511
512 /*
513 * Copy entries from old table into new one.
514 * If 'pid' is 'odd' we need to place in the upper half,
515 * even pid's to the lower half.
516 * Free items stay in the low half so we don't have to
517 * fixup the reference to them.
518 * We stuff free items on the front of the freelist
519 * because we can't write to unmodified entries.
520 * Processing the table backwards maintains a semblance
521 * of issueing pid numbers that increase with time.
522 */
523 i = pt_size - 1;
524 n_pt = new_pt + i;
525 for (; ; i--, n_pt--) {
526 proc = pid_table[i].pt_proc;
527 pgrp = pid_table[i].pt_pgrp;
528 if (!P_VALID(proc)) {
529 /* Up 'use count' so that link is valid */
530 pid = (P_NEXT(proc) + pt_size) & ~pt_size;
531 proc = P_FREE(pid);
532 if (pgrp)
533 pid = pgrp->pg_id;
534 } else
535 pid = proc->p_pid;
536
537 /* Save entry in appropriate half of table */
538 n_pt[pid & pt_size].pt_proc = proc;
539 n_pt[pid & pt_size].pt_pgrp = pgrp;
540
541 /* Put other piece on start of free list */
542 pid = (pid ^ pt_size) & ~pid_tbl_mask;
543 n_pt[pid & pt_size].pt_proc =
544 P_FREE((pid & ~pt_size) | next_free_pt);
545 n_pt[pid & pt_size].pt_pgrp = 0;
546 next_free_pt = i | (pid & pt_size);
547 if (i == 0)
548 break;
549 }
550
551 /* Switch tables */
552 n_pt = pid_table;
553 pid_table = new_pt;
554 pid_tbl_mask = pt_size * 2 - 1;
555
556 /*
557 * pid_max starts as PID_MAX (= 30000), once we have 16384
558 * allocated pids we need it to be larger!
559 */
560 if (pid_tbl_mask > PID_MAX) {
561 pid_max = pid_tbl_mask * 2 + 1;
562 pid_alloc_lim |= pid_alloc_lim << 1;
563 } else
564 pid_alloc_lim <<= 1; /* doubles number of free slots... */
565
566 mutex_exit(proc_lock);
567 FREE(n_pt, M_PROC);
568 }
569
570 struct proc *
571 proc_alloc(void)
572 {
573 struct proc *p;
574 int nxt;
575 pid_t pid;
576 struct pid_table *pt;
577
578 p = pool_cache_get(proc_cache, PR_WAITOK);
579 p->p_stat = SIDL; /* protect against others */
580
581 proc_initspecific(p);
582 /* allocate next free pid */
583
584 for (;;expand_pid_table()) {
585 if (__predict_false(pid_alloc_cnt >= pid_alloc_lim))
586 /* ensure pids cycle through 2000+ values */
587 continue;
588 mutex_enter(proc_lock);
589 pt = &pid_table[next_free_pt];
590 #ifdef DIAGNOSTIC
591 if (__predict_false(P_VALID(pt->pt_proc) || pt->pt_pgrp))
592 panic("proc_alloc: slot busy");
593 #endif
594 nxt = P_NEXT(pt->pt_proc);
595 if (nxt & pid_tbl_mask)
596 break;
597 /* Table full - expand (NB last entry not used....) */
598 mutex_exit(proc_lock);
599 }
600
601 /* pid is 'saved use count' + 'size' + entry */
602 pid = (nxt & ~pid_tbl_mask) + pid_tbl_mask + 1 + next_free_pt;
603 if ((uint)pid > (uint)pid_max)
604 pid &= pid_tbl_mask;
605 p->p_pid = pid;
606 next_free_pt = nxt & pid_tbl_mask;
607
608 /* Grab table slot */
609 pt->pt_proc = p;
610 pid_alloc_cnt++;
611
612 mutex_exit(proc_lock);
613
614 return p;
615 }
616
617 /*
618 * Free a process id - called from proc_free (in kern_exit.c)
619 *
620 * Called with the proc_lock held.
621 */
622 void
623 proc_free_pid(struct proc *p)
624 {
625 pid_t pid = p->p_pid;
626 struct pid_table *pt;
627
628 KASSERT(mutex_owned(proc_lock));
629
630 pt = &pid_table[pid & pid_tbl_mask];
631 #ifdef DIAGNOSTIC
632 if (__predict_false(pt->pt_proc != p))
633 panic("proc_free: pid_table mismatch, pid %x, proc %p",
634 pid, p);
635 #endif
636 /* save pid use count in slot */
637 pt->pt_proc = P_FREE(pid & ~pid_tbl_mask);
638
639 if (pt->pt_pgrp == NULL) {
640 /* link last freed entry onto ours */
641 pid &= pid_tbl_mask;
642 pt = &pid_table[last_free_pt];
643 pt->pt_proc = P_FREE(P_NEXT(pt->pt_proc) | pid);
644 last_free_pt = pid;
645 pid_alloc_cnt--;
646 }
647
648 atomic_dec_uint(&nprocs);
649 }
650
651 void
652 proc_free_mem(struct proc *p)
653 {
654
655 pool_cache_put(proc_cache, p);
656 }
657
658 /*
659 * Move p to a new or existing process group (and session)
660 *
661 * If we are creating a new pgrp, the pgid should equal
662 * the calling process' pid.
663 * If is only valid to enter a process group that is in the session
664 * of the process.
665 * Also mksess should only be set if we are creating a process group
666 *
667 * Only called from sys_setsid and sys_setpgid.
668 */
669 int
670 enterpgrp(struct proc *curp, pid_t pid, pid_t pgid, int mksess)
671 {
672 struct pgrp *new_pgrp, *pgrp;
673 struct session *sess;
674 struct proc *p;
675 int rval;
676 pid_t pg_id = NO_PGID;
677
678 if (mksess)
679 sess = kmem_alloc(sizeof(*sess), KM_SLEEP);
680 else
681 sess = NULL;
682
683 /* Allocate data areas we might need before doing any validity checks */
684 mutex_enter(proc_lock); /* Because pid_table might change */
685 if (pid_table[pgid & pid_tbl_mask].pt_pgrp == 0) {
686 mutex_exit(proc_lock);
687 new_pgrp = kmem_alloc(sizeof(*new_pgrp), KM_SLEEP);
688 mutex_enter(proc_lock);
689 } else
690 new_pgrp = NULL;
691 rval = EPERM; /* most common error (to save typing) */
692
693 /* Check pgrp exists or can be created */
694 pgrp = pid_table[pgid & pid_tbl_mask].pt_pgrp;
695 if (pgrp != NULL && pgrp->pg_id != pgid)
696 goto done;
697
698 /* Can only set another process under restricted circumstances. */
699 if (pid != curp->p_pid) {
700 /* must exist and be one of our children... */
701 if ((p = p_find(pid, PFIND_LOCKED)) == NULL ||
702 !inferior(p, curp)) {
703 rval = ESRCH;
704 goto done;
705 }
706 /* ... in the same session... */
707 if (sess != NULL || p->p_session != curp->p_session)
708 goto done;
709 /* ... existing pgid must be in same session ... */
710 if (pgrp != NULL && pgrp->pg_session != p->p_session)
711 goto done;
712 /* ... and not done an exec. */
713 if (p->p_flag & PK_EXEC) {
714 rval = EACCES;
715 goto done;
716 }
717 } else {
718 /* ... setsid() cannot re-enter a pgrp */
719 if (mksess && (curp->p_pgid == curp->p_pid ||
720 pg_find(curp->p_pid, PFIND_LOCKED)))
721 goto done;
722 p = curp;
723 }
724
725 /* Changing the process group/session of a session
726 leader is definitely off limits. */
727 if (SESS_LEADER(p)) {
728 if (sess == NULL && p->p_pgrp == pgrp)
729 /* unless it's a definite noop */
730 rval = 0;
731 goto done;
732 }
733
734 /* Can only create a process group with id of process */
735 if (pgrp == NULL && pgid != pid)
736 goto done;
737
738 /* Can only create a session if creating pgrp */
739 if (sess != NULL && pgrp != NULL)
740 goto done;
741
742 /* Check we allocated memory for a pgrp... */
743 if (pgrp == NULL && new_pgrp == NULL)
744 goto done;
745
746 /* Don't attach to 'zombie' pgrp */
747 if (pgrp != NULL && LIST_EMPTY(&pgrp->pg_members))
748 goto done;
749
750 /* Expect to succeed now */
751 rval = 0;
752
753 if (pgrp == p->p_pgrp)
754 /* nothing to do */
755 goto done;
756
757 /* Ok all setup, link up required structures */
758
759 if (pgrp == NULL) {
760 pgrp = new_pgrp;
761 new_pgrp = 0;
762 if (sess != NULL) {
763 sess->s_sid = p->p_pid;
764 sess->s_leader = p;
765 sess->s_count = 1;
766 sess->s_ttyvp = NULL;
767 sess->s_ttyp = NULL;
768 sess->s_flags = p->p_session->s_flags & ~S_LOGIN_SET;
769 memcpy(sess->s_login, p->p_session->s_login,
770 sizeof(sess->s_login));
771 p->p_lflag &= ~PL_CONTROLT;
772 } else {
773 sess = p->p_pgrp->pg_session;
774 SESSHOLD(sess);
775 }
776 pgrp->pg_session = sess;
777 sess = 0;
778
779 pgrp->pg_id = pgid;
780 LIST_INIT(&pgrp->pg_members);
781 #ifdef DIAGNOSTIC
782 if (__predict_false(pid_table[pgid & pid_tbl_mask].pt_pgrp))
783 panic("enterpgrp: pgrp table slot in use");
784 if (__predict_false(mksess && p != curp))
785 panic("enterpgrp: mksession and p != curproc");
786 #endif
787 pid_table[pgid & pid_tbl_mask].pt_pgrp = pgrp;
788 pgrp->pg_jobc = 0;
789 }
790
791 /*
792 * Adjust eligibility of affected pgrps to participate in job control.
793 * Increment eligibility counts before decrementing, otherwise we
794 * could reach 0 spuriously during the first call.
795 */
796 fixjobc(p, pgrp, 1);
797 fixjobc(p, p->p_pgrp, 0);
798
799 /* Interlock with ttread(). */
800 mutex_spin_enter(&tty_lock);
801
802 /* Move process to requested group. */
803 LIST_REMOVE(p, p_pglist);
804 if (LIST_EMPTY(&p->p_pgrp->pg_members))
805 /* defer delete until we've dumped the lock */
806 pg_id = p->p_pgrp->pg_id;
807 p->p_pgrp = pgrp;
808 LIST_INSERT_HEAD(&pgrp->pg_members, p, p_pglist);
809
810 /* Done with the swap; we can release the tty mutex. */
811 mutex_spin_exit(&tty_lock);
812
813 done:
814 if (pg_id != NO_PGID)
815 pg_delete(pg_id);
816 mutex_exit(proc_lock);
817 if (sess != NULL)
818 kmem_free(sess, sizeof(*sess));
819 if (new_pgrp != NULL)
820 kmem_free(new_pgrp, sizeof(*new_pgrp));
821 #ifdef DEBUG_PGRP
822 if (__predict_false(rval))
823 printf("enterpgrp(%d,%d,%d), curproc %d, rval %d\n",
824 pid, pgid, mksess, curp->p_pid, rval);
825 #endif
826 return rval;
827 }
828
829 /*
830 * Remove a process from its process group. Must be called with the
831 * proc_lock held.
832 */
833 void
834 leavepgrp(struct proc *p)
835 {
836 struct pgrp *pgrp;
837
838 KASSERT(mutex_owned(proc_lock));
839
840 mutex_spin_enter(&tty_lock);
841 pgrp = p->p_pgrp;
842 LIST_REMOVE(p, p_pglist);
843 p->p_pgrp = NULL;
844 mutex_spin_exit(&tty_lock);
845
846 if (LIST_EMPTY(&pgrp->pg_members))
847 pg_delete(pgrp->pg_id);
848 }
849
850 /*
851 * Free a process group. Must be called with the proc_lock held.
852 */
853 static void
854 pg_free(pid_t pg_id)
855 {
856 struct pgrp *pgrp;
857 struct pid_table *pt;
858
859 KASSERT(mutex_owned(proc_lock));
860
861 pt = &pid_table[pg_id & pid_tbl_mask];
862 pgrp = pt->pt_pgrp;
863 #ifdef DIAGNOSTIC
864 if (__predict_false(!pgrp || pgrp->pg_id != pg_id
865 || !LIST_EMPTY(&pgrp->pg_members)))
866 panic("pg_free: process group absent or has members");
867 #endif
868 pt->pt_pgrp = 0;
869
870 if (!P_VALID(pt->pt_proc)) {
871 /* orphaned pgrp, put slot onto free list */
872 #ifdef DIAGNOSTIC
873 if (__predict_false(P_NEXT(pt->pt_proc) & pid_tbl_mask))
874 panic("pg_free: process slot on free list");
875 #endif
876 pg_id &= pid_tbl_mask;
877 pt = &pid_table[last_free_pt];
878 pt->pt_proc = P_FREE(P_NEXT(pt->pt_proc) | pg_id);
879 last_free_pt = pg_id;
880 pid_alloc_cnt--;
881 }
882 kmem_free(pgrp, sizeof(*pgrp));
883 }
884
885 /*
886 * Delete a process group. Must be called with the proc_lock held.
887 */
888 static void
889 pg_delete(pid_t pg_id)
890 {
891 struct pgrp *pgrp;
892 struct tty *ttyp;
893 struct session *ss;
894 int is_pgrp_leader;
895
896 KASSERT(mutex_owned(proc_lock));
897
898 pgrp = pid_table[pg_id & pid_tbl_mask].pt_pgrp;
899 if (pgrp == NULL || pgrp->pg_id != pg_id ||
900 !LIST_EMPTY(&pgrp->pg_members))
901 return;
902
903 ss = pgrp->pg_session;
904
905 /* Remove reference (if any) from tty to this process group */
906 mutex_spin_enter(&tty_lock);
907 ttyp = ss->s_ttyp;
908 if (ttyp != NULL && ttyp->t_pgrp == pgrp) {
909 ttyp->t_pgrp = NULL;
910 #ifdef DIAGNOSTIC
911 if (ttyp->t_session != ss)
912 panic("pg_delete: wrong session on terminal");
913 #endif
914 }
915 mutex_spin_exit(&tty_lock);
916
917 /*
918 * The leading process group in a session is freed
919 * by sessdelete() if last reference.
920 */
921 is_pgrp_leader = (ss->s_sid == pgrp->pg_id);
922 SESSRELE(ss);
923
924 if (is_pgrp_leader)
925 return;
926
927 pg_free(pg_id);
928 }
929
930 /*
931 * Delete session - called from SESSRELE when s_count becomes zero.
932 * Must be called with the proc_lock held.
933 */
934 void
935 sessdelete(struct session *ss)
936 {
937
938 KASSERT(mutex_owned(proc_lock));
939
940 /*
941 * We keep the pgrp with the same id as the session in
942 * order to stop a process being given the same pid.
943 * Since the pgrp holds a reference to the session, it
944 * must be a 'zombie' pgrp by now.
945 */
946 pg_free(ss->s_sid);
947 kmem_free(ss, sizeof(*ss));
948 }
949
950 /*
951 * Adjust pgrp jobc counters when specified process changes process group.
952 * We count the number of processes in each process group that "qualify"
953 * the group for terminal job control (those with a parent in a different
954 * process group of the same session). If that count reaches zero, the
955 * process group becomes orphaned. Check both the specified process'
956 * process group and that of its children.
957 * entering == 0 => p is leaving specified group.
958 * entering == 1 => p is entering specified group.
959 *
960 * Call with proc_lock held.
961 */
962 void
963 fixjobc(struct proc *p, struct pgrp *pgrp, int entering)
964 {
965 struct pgrp *hispgrp;
966 struct session *mysession = pgrp->pg_session;
967 struct proc *child;
968
969 KASSERT(mutex_owned(proc_lock));
970
971 /*
972 * Check p's parent to see whether p qualifies its own process
973 * group; if so, adjust count for p's process group.
974 */
975 hispgrp = p->p_pptr->p_pgrp;
976 if (hispgrp != pgrp && hispgrp->pg_session == mysession) {
977 if (entering) {
978 pgrp->pg_jobc++;
979 p->p_lflag &= ~PL_ORPHANPG;
980 } else if (--pgrp->pg_jobc == 0)
981 orphanpg(pgrp);
982 }
983
984 /*
985 * Check this process' children to see whether they qualify
986 * their process groups; if so, adjust counts for children's
987 * process groups.
988 */
989 LIST_FOREACH(child, &p->p_children, p_sibling) {
990 hispgrp = child->p_pgrp;
991 if (hispgrp != pgrp && hispgrp->pg_session == mysession &&
992 !P_ZOMBIE(child)) {
993 if (entering) {
994 child->p_lflag &= ~PL_ORPHANPG;
995 hispgrp->pg_jobc++;
996 } else if (--hispgrp->pg_jobc == 0)
997 orphanpg(hispgrp);
998 }
999 }
1000 }
1001
1002 /*
1003 * A process group has become orphaned;
1004 * if there are any stopped processes in the group,
1005 * hang-up all process in that group.
1006 *
1007 * Call with proc_lock held.
1008 */
1009 static void
1010 orphanpg(struct pgrp *pg)
1011 {
1012 struct proc *p;
1013 int doit;
1014
1015 KASSERT(mutex_owned(proc_lock));
1016
1017 doit = 0;
1018
1019 LIST_FOREACH(p, &pg->pg_members, p_pglist) {
1020 if (p->p_stat == SSTOP) {
1021 p->p_lflag |= PL_ORPHANPG;
1022 mutex_spin_exit(&tty_lock);
1023 psignal(p, SIGHUP);
1024 psignal(p, SIGCONT);
1025 mutex_spin_enter(&tty_lock);
1026 }
1027 }
1028 }
1029
1030 #ifdef DDB
1031 #include <ddb/db_output.h>
1032 void pidtbl_dump(void);
1033 void
1034 pidtbl_dump(void)
1035 {
1036 struct pid_table *pt;
1037 struct proc *p;
1038 struct pgrp *pgrp;
1039 int id;
1040
1041 db_printf("pid table %p size %x, next %x, last %x\n",
1042 pid_table, pid_tbl_mask+1,
1043 next_free_pt, last_free_pt);
1044 for (pt = pid_table, id = 0; id <= pid_tbl_mask; id++, pt++) {
1045 p = pt->pt_proc;
1046 if (!P_VALID(p) && !pt->pt_pgrp)
1047 continue;
1048 db_printf(" id %x: ", id);
1049 if (P_VALID(p))
1050 db_printf("proc %p id %d (0x%x) %s\n",
1051 p, p->p_pid, p->p_pid, p->p_comm);
1052 else
1053 db_printf("next %x use %x\n",
1054 P_NEXT(p) & pid_tbl_mask,
1055 P_NEXT(p) & ~pid_tbl_mask);
1056 if ((pgrp = pt->pt_pgrp)) {
1057 db_printf("\tsession %p, sid %d, count %d, login %s\n",
1058 pgrp->pg_session, pgrp->pg_session->s_sid,
1059 pgrp->pg_session->s_count,
1060 pgrp->pg_session->s_login);
1061 db_printf("\tpgrp %p, pg_id %d, pg_jobc %d, members %p\n",
1062 pgrp, pgrp->pg_id, pgrp->pg_jobc,
1063 LIST_FIRST(&pgrp->pg_members));
1064 LIST_FOREACH(p, &pgrp->pg_members, p_pglist) {
1065 db_printf("\t\tpid %d addr %p pgrp %p %s\n",
1066 p->p_pid, p, p->p_pgrp, p->p_comm);
1067 }
1068 }
1069 }
1070 }
1071 #endif /* DDB */
1072
1073 #ifdef KSTACK_CHECK_MAGIC
1074 #include <sys/user.h>
1075
1076 #define KSTACK_MAGIC 0xdeadbeaf
1077
1078 /* XXX should be per process basis? */
1079 int kstackleftmin = KSTACK_SIZE;
1080 int kstackleftthres = KSTACK_SIZE / 8; /* warn if remaining stack is
1081 less than this */
1082
1083 void
1084 kstack_setup_magic(const struct lwp *l)
1085 {
1086 uint32_t *ip;
1087 uint32_t const *end;
1088
1089 KASSERT(l != NULL);
1090 KASSERT(l != &lwp0);
1091
1092 /*
1093 * fill all the stack with magic number
1094 * so that later modification on it can be detected.
1095 */
1096 ip = (uint32_t *)KSTACK_LOWEST_ADDR(l);
1097 end = (uint32_t *)((char *)KSTACK_LOWEST_ADDR(l) + KSTACK_SIZE);
1098 for (; ip < end; ip++) {
1099 *ip = KSTACK_MAGIC;
1100 }
1101 }
1102
1103 void
1104 kstack_check_magic(const struct lwp *l)
1105 {
1106 uint32_t const *ip, *end;
1107 int stackleft;
1108
1109 KASSERT(l != NULL);
1110
1111 /* don't check proc0 */ /*XXX*/
1112 if (l == &lwp0)
1113 return;
1114
1115 #ifdef __MACHINE_STACK_GROWS_UP
1116 /* stack grows upwards (eg. hppa) */
1117 ip = (uint32_t *)((void *)KSTACK_LOWEST_ADDR(l) + KSTACK_SIZE);
1118 end = (uint32_t *)KSTACK_LOWEST_ADDR(l);
1119 for (ip--; ip >= end; ip--)
1120 if (*ip != KSTACK_MAGIC)
1121 break;
1122
1123 stackleft = (void *)KSTACK_LOWEST_ADDR(l) + KSTACK_SIZE - (void *)ip;
1124 #else /* __MACHINE_STACK_GROWS_UP */
1125 /* stack grows downwards (eg. i386) */
1126 ip = (uint32_t *)KSTACK_LOWEST_ADDR(l);
1127 end = (uint32_t *)((char *)KSTACK_LOWEST_ADDR(l) + KSTACK_SIZE);
1128 for (; ip < end; ip++)
1129 if (*ip != KSTACK_MAGIC)
1130 break;
1131
1132 stackleft = ((const char *)ip) - (const char *)KSTACK_LOWEST_ADDR(l);
1133 #endif /* __MACHINE_STACK_GROWS_UP */
1134
1135 if (kstackleftmin > stackleft) {
1136 kstackleftmin = stackleft;
1137 if (stackleft < kstackleftthres)
1138 printf("warning: kernel stack left %d bytes"
1139 "(pid %u:lid %u)\n", stackleft,
1140 (u_int)l->l_proc->p_pid, (u_int)l->l_lid);
1141 }
1142
1143 if (stackleft <= 0) {
1144 panic("magic on the top of kernel stack changed for "
1145 "pid %u, lid %u: maybe kernel stack overflow",
1146 (u_int)l->l_proc->p_pid, (u_int)l->l_lid);
1147 }
1148 }
1149 #endif /* KSTACK_CHECK_MAGIC */
1150
1151 int
1152 proclist_foreach_call(struct proclist *list,
1153 int (*callback)(struct proc *, void *arg), void *arg)
1154 {
1155 struct proc marker;
1156 struct proc *p;
1157 struct lwp * const l = curlwp;
1158 int ret = 0;
1159
1160 marker.p_flag = PK_MARKER;
1161 uvm_lwp_hold(l);
1162 mutex_enter(proc_lock);
1163 for (p = LIST_FIRST(list); ret == 0 && p != NULL;) {
1164 if (p->p_flag & PK_MARKER) {
1165 p = LIST_NEXT(p, p_list);
1166 continue;
1167 }
1168 LIST_INSERT_AFTER(p, &marker, p_list);
1169 ret = (*callback)(p, arg);
1170 KASSERT(mutex_owned(proc_lock));
1171 p = LIST_NEXT(&marker, p_list);
1172 LIST_REMOVE(&marker, p_list);
1173 }
1174 mutex_exit(proc_lock);
1175 uvm_lwp_rele(l);
1176
1177 return ret;
1178 }
1179
1180 int
1181 proc_vmspace_getref(struct proc *p, struct vmspace **vm)
1182 {
1183
1184 /* XXXCDC: how should locking work here? */
1185
1186 /* curproc exception is for coredump. */
1187
1188 if ((p != curproc && (p->p_sflag & PS_WEXIT) != 0) ||
1189 (p->p_vmspace->vm_refcnt < 1)) { /* XXX */
1190 return EFAULT;
1191 }
1192
1193 uvmspace_addref(p->p_vmspace);
1194 *vm = p->p_vmspace;
1195
1196 return 0;
1197 }
1198
1199 /*
1200 * Acquire a write lock on the process credential.
1201 */
1202 void
1203 proc_crmod_enter(void)
1204 {
1205 struct lwp *l = curlwp;
1206 struct proc *p = l->l_proc;
1207 struct plimit *lim;
1208 kauth_cred_t oc;
1209 char *cn;
1210
1211 /* Reset what needs to be reset in plimit. */
1212 if (p->p_limit->pl_corename != defcorename) {
1213 lim_privatise(p, false);
1214 lim = p->p_limit;
1215 mutex_enter(&lim->pl_lock);
1216 cn = lim->pl_corename;
1217 lim->pl_corename = defcorename;
1218 mutex_exit(&lim->pl_lock);
1219 if (cn != defcorename)
1220 free(cn, M_TEMP);
1221 }
1222
1223 mutex_enter(&p->p_mutex);
1224
1225 /* Ensure the LWP cached credentials are up to date. */
1226 if ((oc = l->l_cred) != p->p_cred) {
1227 kauth_cred_hold(p->p_cred);
1228 l->l_cred = p->p_cred;
1229 kauth_cred_free(oc);
1230 }
1231
1232 }
1233
1234 /*
1235 * Set in a new process credential, and drop the write lock. The credential
1236 * must have a reference already. Optionally, free a no-longer required
1237 * credential. The scheduler also needs to inspect p_cred, so we also
1238 * briefly acquire the sched state mutex.
1239 */
1240 void
1241 proc_crmod_leave(kauth_cred_t scred, kauth_cred_t fcred, bool sugid)
1242 {
1243 struct lwp *l = curlwp, *l2;
1244 struct proc *p = l->l_proc;
1245 kauth_cred_t oc;
1246
1247 /* Is there a new credential to set in? */
1248 if (scred != NULL) {
1249 mutex_enter(&p->p_smutex);
1250 p->p_cred = scred;
1251 LIST_FOREACH(l2, &p->p_lwps, l_sibling) {
1252 if (l2 != l)
1253 l2->l_prflag |= LPR_CRMOD;
1254 }
1255 mutex_exit(&p->p_smutex);
1256
1257 /* Ensure the LWP cached credentials are up to date. */
1258 if ((oc = l->l_cred) != scred) {
1259 kauth_cred_hold(scred);
1260 l->l_cred = scred;
1261 }
1262 } else
1263 oc = NULL; /* XXXgcc */
1264
1265 if (sugid) {
1266 /*
1267 * Mark process as having changed credentials, stops
1268 * tracing etc.
1269 */
1270 p->p_flag |= PK_SUGID;
1271 }
1272
1273 mutex_exit(&p->p_mutex);
1274
1275 /* If there is a credential to be released, free it now. */
1276 if (fcred != NULL) {
1277 KASSERT(scred != NULL);
1278 kauth_cred_free(fcred);
1279 if (oc != scred)
1280 kauth_cred_free(oc);
1281 }
1282 }
1283
1284 /*
1285 * proc_specific_key_create --
1286 * Create a key for subsystem proc-specific data.
1287 */
1288 int
1289 proc_specific_key_create(specificdata_key_t *keyp, specificdata_dtor_t dtor)
1290 {
1291
1292 return (specificdata_key_create(proc_specificdata_domain, keyp, dtor));
1293 }
1294
1295 /*
1296 * proc_specific_key_delete --
1297 * Delete a key for subsystem proc-specific data.
1298 */
1299 void
1300 proc_specific_key_delete(specificdata_key_t key)
1301 {
1302
1303 specificdata_key_delete(proc_specificdata_domain, key);
1304 }
1305
1306 /*
1307 * proc_initspecific --
1308 * Initialize a proc's specificdata container.
1309 */
1310 void
1311 proc_initspecific(struct proc *p)
1312 {
1313 int error;
1314
1315 error = specificdata_init(proc_specificdata_domain, &p->p_specdataref);
1316 KASSERT(error == 0);
1317 }
1318
1319 /*
1320 * proc_finispecific --
1321 * Finalize a proc's specificdata container.
1322 */
1323 void
1324 proc_finispecific(struct proc *p)
1325 {
1326
1327 specificdata_fini(proc_specificdata_domain, &p->p_specdataref);
1328 }
1329
1330 /*
1331 * proc_getspecific --
1332 * Return proc-specific data corresponding to the specified key.
1333 */
1334 void *
1335 proc_getspecific(struct proc *p, specificdata_key_t key)
1336 {
1337
1338 return (specificdata_getspecific(proc_specificdata_domain,
1339 &p->p_specdataref, key));
1340 }
1341
1342 /*
1343 * proc_setspecific --
1344 * Set proc-specific data corresponding to the specified key.
1345 */
1346 void
1347 proc_setspecific(struct proc *p, specificdata_key_t key, void *data)
1348 {
1349
1350 specificdata_setspecific(proc_specificdata_domain,
1351 &p->p_specdataref, key, data);
1352 }
1353