procfs_subr.c revision 1.68.14.3 1 /* $NetBSD: procfs_subr.c,v 1.68.14.3 2006/11/17 16:34:40 ad Exp $ */
2
3 /*-
4 * Copyright (c) 2006 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Andrew Doran.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 /*
40 * Copyright (c) 1993
41 * The Regents of the University of California. All rights reserved.
42 *
43 * This code is derived from software contributed to Berkeley by
44 * Jan-Simon Pendry.
45 *
46 * Redistribution and use in source and binary forms, with or without
47 * modification, are permitted provided that the following conditions
48 * are met:
49 * 1. Redistributions of source code must retain the above copyright
50 * notice, this list of conditions and the following disclaimer.
51 * 2. Redistributions in binary form must reproduce the above copyright
52 * notice, this list of conditions and the following disclaimer in the
53 * documentation and/or other materials provided with the distribution.
54 * 3. Neither the name of the University nor the names of its contributors
55 * may be used to endorse or promote products derived from this software
56 * without specific prior written permission.
57 *
58 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
59 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
60 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
61 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
62 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
63 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
64 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
65 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
66 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
67 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
68 * SUCH DAMAGE.
69 *
70 * @(#)procfs_subr.c 8.6 (Berkeley) 5/14/95
71 */
72
73 /*
74 * Copyright (c) 1994 Christopher G. Demetriou. All rights reserved.
75 * Copyright (c) 1993 Jan-Simon Pendry
76 *
77 * This code is derived from software contributed to Berkeley by
78 * Jan-Simon Pendry.
79 *
80 * Redistribution and use in source and binary forms, with or without
81 * modification, are permitted provided that the following conditions
82 * are met:
83 * 1. Redistributions of source code must retain the above copyright
84 * notice, this list of conditions and the following disclaimer.
85 * 2. Redistributions in binary form must reproduce the above copyright
86 * notice, this list of conditions and the following disclaimer in the
87 * documentation and/or other materials provided with the distribution.
88 * 3. All advertising materials mentioning features or use of this software
89 * must display the following acknowledgement:
90 * This product includes software developed by the University of
91 * California, Berkeley and its contributors.
92 * 4. Neither the name of the University nor the names of its contributors
93 * may be used to endorse or promote products derived from this software
94 * without specific prior written permission.
95 *
96 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
97 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
98 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
99 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
100 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
101 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
102 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
103 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
104 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
105 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
106 * SUCH DAMAGE.
107 *
108 * @(#)procfs_subr.c 8.6 (Berkeley) 5/14/95
109 */
110
111 #include <sys/cdefs.h>
112 __KERNEL_RCSID(0, "$NetBSD: procfs_subr.c,v 1.68.14.3 2006/11/17 16:34:40 ad Exp $");
113
114 #include <sys/param.h>
115 #include <sys/systm.h>
116 #include <sys/time.h>
117 #include <sys/kernel.h>
118 #include <sys/proc.h>
119 #include <sys/vnode.h>
120 #include <sys/malloc.h>
121 #include <sys/stat.h>
122 #include <sys/file.h>
123 #include <sys/filedesc.h>
124
125 #include <miscfs/procfs/procfs.h>
126
127 void procfs_hashins(struct pfsnode *);
128 void procfs_hashrem(struct pfsnode *);
129 struct vnode *procfs_hashget(pid_t, pfstype, int, struct mount *);
130
131 LIST_HEAD(pfs_hashhead, pfsnode) *pfs_hashtbl;
132 u_long pfs_ihash; /* size of hash table - 1 */
133 #define PFSPIDHASH(pid) ((pid) & pfs_ihash)
134
135 kmutex_t pfs_hashmutex;
136 struct simplelock pfs_hash_slock;
137
138 #define ISSET(t, f) ((t) & (f))
139
140 /*
141 * allocate a pfsnode/vnode pair. the vnode is
142 * referenced, and locked.
143 *
144 * the pid, pfs_type, and mount point uniquely
145 * identify a pfsnode. the mount point is needed
146 * because someone might mount this filesystem
147 * twice.
148 *
149 * all pfsnodes are maintained on a singly-linked
150 * list. new nodes are only allocated when they cannot
151 * be found on this list. entries on the list are
152 * removed when the vfs reclaim entry is called.
153 *
154 * a single lock is kept for the entire list. this is
155 * needed because the getnewvnode() function can block
156 * waiting for a vnode to become free, in which case there
157 * may be more than one process trying to get the same
158 * vnode. this lock is only taken if we are going to
159 * call getnewvnode, since the kernel itself is single-threaded.
160 *
161 * if an entry is found on the list, then call vget() to
162 * take a reference. this is done because there may be
163 * zero references to it and so it needs to removed from
164 * the vnode free list.
165 */
166 int
167 procfs_allocvp(mp, vpp, pid, pfs_type, fd, p)
168 struct mount *mp;
169 struct vnode **vpp;
170 pid_t pid;
171 pfstype pfs_type;
172 int fd;
173 struct proc *p;
174 {
175 struct pfsnode *pfs;
176 struct vnode *vp;
177 int error;
178
179 do {
180 if ((*vpp = procfs_hashget(pid, pfs_type, fd, mp)) != NULL)
181 return (0);
182 } while (!mutex_tryenter(&pfs_hashmutex));
183
184 if ((error = getnewvnode(VT_PROCFS, mp, procfs_vnodeop_p, &vp)) != 0) {
185 *vpp = NULL;
186 mutex_exit(&pfs_hashmutex);
187 return (error);
188 }
189
190 MALLOC(pfs, void *, sizeof(struct pfsnode), M_TEMP, M_WAITOK);
191 vp->v_data = pfs;
192
193 pfs->pfs_pid = pid;
194 pfs->pfs_type = pfs_type;
195 pfs->pfs_vnode = vp;
196 pfs->pfs_flags = 0;
197 pfs->pfs_fileno = PROCFS_FILENO(pid, pfs_type, fd);
198 pfs->pfs_fd = fd;
199
200 switch (pfs_type) {
201 case PFSroot: /* /proc = dr-xr-xr-x */
202 pfs->pfs_mode = S_IRUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH;
203 vp->v_type = VDIR;
204 vp->v_flag = VROOT;
205 break;
206
207 case PFScurproc: /* /proc/curproc = lr-xr-xr-x */
208 case PFSself: /* /proc/self = lr-xr-xr-x */
209 case PFScwd: /* /proc/N/cwd = lr-xr-xr-x */
210 case PFSchroot: /* /proc/N/chroot = lr-xr-xr-x */
211 pfs->pfs_mode = S_IRUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH;
212 vp->v_type = VLNK;
213 break;
214
215 case PFSproc: /* /proc/N = dr-xr-xr-x */
216 case PFSfd:
217 if (fd == -1) { /* /proc/N/fd = dr-xr-xr-x */
218 pfs->pfs_mode = S_IRUSR|S_IXUSR;
219 vp->v_type = VDIR;
220 } else { /* /proc/N/fd/M = [ps-]rw------- */
221 struct file *fp;
222 struct vnode *vxp;
223
224 mutex_enter(&p->p_mutex);
225 fp = fd_getfile(p->p_fd, pfs->pfs_fd);
226 mutex_exit(&p->p_mutex);
227 if (fp == NULL) {
228 error = EBADF;
229 goto bad;
230 }
231 FILE_USE(fp);
232
233 pfs->pfs_mode = S_IRUSR|S_IWUSR;
234 switch (fp->f_type) {
235 case DTYPE_VNODE:
236 vxp = (struct vnode *)fp->f_data;
237
238 /*
239 * We make symlinks for directories
240 * to avoid cycles.
241 */
242 if (vxp->v_type == VDIR)
243 goto symlink;
244 vp->v_type = vxp->v_type;
245 break;
246 case DTYPE_PIPE:
247 vp->v_type = VFIFO;
248 break;
249 case DTYPE_SOCKET:
250 vp->v_type = VSOCK;
251 break;
252 case DTYPE_KQUEUE:
253 case DTYPE_MISC:
254 symlink:
255 pfs->pfs_mode = S_IRUSR|S_IXUSR|S_IRGRP|
256 S_IXGRP|S_IROTH|S_IXOTH;
257 vp->v_type = VLNK;
258 break;
259 default:
260 error = EOPNOTSUPP;
261 FILE_UNUSE(fp, curlwp);
262 goto bad;
263 }
264 FILE_UNUSE(fp, curlwp);
265 }
266 break;
267
268 case PFSfile: /* /proc/N/file = -rw------- */
269 case PFSmem: /* /proc/N/mem = -rw------- */
270 case PFSregs: /* /proc/N/regs = -rw------- */
271 case PFSfpregs: /* /proc/N/fpregs = -rw------- */
272 pfs->pfs_mode = S_IRUSR|S_IWUSR;
273 vp->v_type = VREG;
274 break;
275
276 case PFSctl: /* /proc/N/ctl = --w------ */
277 case PFSnote: /* /proc/N/note = --w------ */
278 case PFSnotepg: /* /proc/N/notepg = --w------ */
279 pfs->pfs_mode = S_IWUSR;
280 vp->v_type = VREG;
281 break;
282
283 case PFSmap: /* /proc/N/map = -r--r--r-- */
284 case PFSmaps: /* /proc/N/maps = -r--r--r-- */
285 case PFSstatus: /* /proc/N/status = -r--r--r-- */
286 case PFSstat: /* /proc/N/stat = -r--r--r-- */
287 case PFScmdline: /* /proc/N/cmdline = -r--r--r-- */
288 case PFSmeminfo: /* /proc/meminfo = -r--r--r-- */
289 case PFScpuinfo: /* /proc/cpuinfo = -r--r--r-- */
290 case PFSuptime: /* /proc/uptime = -r--r--r-- */
291 case PFSmounts: /* /proc/mounts = -r--r--r-- */
292 pfs->pfs_mode = S_IRUSR|S_IRGRP|S_IROTH;
293 vp->v_type = VREG;
294 break;
295
296 #ifdef __HAVE_PROCFS_MACHDEP
297 PROCFS_MACHDEP_NODETYPE_CASES
298 procfs_machdep_allocvp(vp);
299 break;
300 #endif
301
302 default:
303 panic("procfs_allocvp");
304 }
305
306 procfs_hashins(pfs);
307 uvm_vnp_setsize(vp, 0);
308 mutex_exit(&pfs_hashmutex);
309
310 *vpp = vp;
311 return (0);
312
313 bad:
314 mutex_exit(&pfs_hashmutex);
315 FREE(pfs, M_TEMP);
316 ungetnewvnode(vp);
317 return (error);
318 }
319
320 int
321 procfs_freevp(vp)
322 struct vnode *vp;
323 {
324 struct pfsnode *pfs = VTOPFS(vp);
325
326 procfs_hashrem(pfs);
327
328 FREE(vp->v_data, M_TEMP);
329 vp->v_data = 0;
330 return (0);
331 }
332
333 int
334 procfs_rw(v)
335 void *v;
336 {
337 struct vop_read_args *ap = v;
338 struct vnode *vp = ap->a_vp;
339 struct uio *uio = ap->a_uio;
340 struct lwp *curl;
341 struct lwp *l;
342 struct pfsnode *pfs = VTOPFS(vp);
343 struct proc *p;
344 int error;
345
346 if (uio->uio_offset < 0)
347 return EINVAL;
348
349 if ((error = procfs_proc_lock(pfs->pfs_pid, &p, ESRCH)) != 0)
350 return error;
351
352 /*
353 * Do not allow init to be modified while in secure mode; it
354 * could be duped into changing the security level.
355 */
356 if (uio->uio_rw == UIO_WRITE && p == initproc && securelevel > -1)
357 return EPERM;
358
359 /*
360 * Pick a suitable LWP to represent the process, and acquire a
361 * reference on it so that it does not exit.
362 *
363 * XXX The entire procfs interface needs work to be useful to a
364 * process with multiple LWPs. For the moment, we'll just kluge
365 * this and fail on others.
366 */
367 mutex_enter(&p->p_smutex);
368 l = proc_representative_lwp(p, NULL, 1);
369 lwp_addref(l);
370 lwp_unlock(l);
371 mutex_exit(&p->p_smutex);
372
373 curl = curlwp;
374
375 switch (pfs->pfs_type) {
376 case PFSnote:
377 case PFSnotepg:
378 error = procfs_donote(curl, p, pfs, uio);
379 break;
380
381 case PFSregs:
382 error = procfs_doregs(curl, l, pfs, uio);
383 break;
384
385 case PFSfpregs:
386 error = procfs_dofpregs(curl, l, pfs, uio);
387 break;
388
389 case PFSctl:
390 error = procfs_doctl(curl, l, pfs, uio);
391 break;
392
393 case PFSstatus:
394 error = procfs_dostatus(curl, l, pfs, uio);
395 break;
396
397 case PFSstat:
398 error = procfs_do_pid_stat(curl, l, pfs, uio);
399 break;
400
401 case PFSmap:
402 error = procfs_domap(curl, p, pfs, uio, 0);
403 break;
404
405 case PFSmaps:
406 error = procfs_domap(curl, p, pfs, uio, 1);
407 break;
408
409 case PFSmem:
410 error = procfs_domem(curl, l, pfs, uio);
411 break;
412
413 case PFScmdline:
414 error = procfs_docmdline(curl, p, pfs, uio);
415 break;
416
417 case PFSmeminfo:
418 error = procfs_domeminfo(curl, p, pfs, uio);
419 break;
420
421 case PFScpuinfo:
422 error = procfs_docpuinfo(curl, p, pfs, uio);
423 break;
424
425 case PFSfd:
426 error = procfs_dofd(curl, p, pfs, uio);
427 break;
428
429 case PFSuptime:
430 error = procfs_douptime(curl, p, pfs, uio);
431 break;
432
433 case PFSmounts:
434 error = procfs_domounts(curl, p, pfs, uio);
435 break;
436
437 #ifdef __HAVE_PROCFS_MACHDEP
438 PROCFS_MACHDEP_NODETYPE_CASES
439 error = procfs_machdep_rw(curl, l, pfs, uio);
440 break;
441 #endif
442
443 default:
444 error = EOPNOTSUPP;
445 break;
446 }
447
448 /*
449 * Release the references that we acquired earlier.
450 */
451 lwp_delref(l);
452 procfs_proc_unlock(p);
453
454 return (error);
455 }
456
457 /*
458 * Get a string from userland into (bf). Strip a trailing
459 * nl character (to allow easy access from the shell).
460 * The buffer should be *buflenp + 1 chars long. vfs_getuserstr
461 * will automatically add a nul char at the end.
462 *
463 * Returns 0 on success or the following errors
464 *
465 * EINVAL: file offset is non-zero.
466 * EMSGSIZE: message is longer than kernel buffer
467 * EFAULT: user i/o buffer is not addressable
468 */
469 int
470 vfs_getuserstr(uio, bf, buflenp)
471 struct uio *uio;
472 char *bf;
473 int *buflenp;
474 {
475 int xlen;
476 int error;
477
478 if (uio->uio_offset != 0)
479 return (EINVAL);
480
481 xlen = *buflenp;
482
483 /* must be able to read the whole string in one go */
484 if (xlen < uio->uio_resid)
485 return (EMSGSIZE);
486 xlen = uio->uio_resid;
487
488 if ((error = uiomove(bf, xlen, uio)) != 0)
489 return (error);
490
491 /* allow multiple writes without seeks */
492 uio->uio_offset = 0;
493
494 /* cleanup string and remove trailing newline */
495 bf[xlen] = '\0';
496 xlen = strlen(bf);
497 if (xlen > 0 && bf[xlen-1] == '\n')
498 bf[--xlen] = '\0';
499 *buflenp = xlen;
500
501 return (0);
502 }
503
504 const vfs_namemap_t *
505 vfs_findname(nm, bf, buflen)
506 const vfs_namemap_t *nm;
507 const char *bf;
508 int buflen;
509 {
510
511 for (; nm->nm_name; nm++)
512 if (memcmp(bf, nm->nm_name, buflen+1) == 0)
513 return (nm);
514
515 return (0);
516 }
517
518 /*
519 * Initialize pfsnode hash table.
520 */
521 void
522 procfs_hashinit()
523 {
524 mutex_init(&pfs_hashmutex, MUTEX_DEFAULT, IPL_NONE);
525 pfs_hashtbl = hashinit(desiredvnodes / 4, HASH_LIST, M_UFSMNT,
526 M_WAITOK, &pfs_ihash);
527 simple_lock_init(&pfs_hash_slock);
528 }
529
530 void
531 procfs_hashreinit()
532 {
533 struct pfsnode *pp;
534 struct pfs_hashhead *oldhash, *hash;
535 u_long i, oldmask, mask, val;
536
537 hash = hashinit(desiredvnodes / 4, HASH_LIST, M_UFSMNT, M_WAITOK,
538 &mask);
539
540 simple_lock(&pfs_hash_slock);
541 oldhash = pfs_hashtbl;
542 oldmask = pfs_ihash;
543 pfs_hashtbl = hash;
544 pfs_ihash = mask;
545 for (i = 0; i <= oldmask; i++) {
546 while ((pp = LIST_FIRST(&oldhash[i])) != NULL) {
547 LIST_REMOVE(pp, pfs_hash);
548 val = PFSPIDHASH(pp->pfs_pid);
549 LIST_INSERT_HEAD(&hash[val], pp, pfs_hash);
550 }
551 }
552 simple_unlock(&pfs_hash_slock);
553 hashdone(oldhash, M_UFSMNT);
554 }
555
556 /*
557 * Free pfsnode hash table.
558 */
559 void
560 procfs_hashdone()
561 {
562 hashdone(pfs_hashtbl, M_UFSMNT);
563 }
564
565 struct vnode *
566 procfs_hashget(pid, type, fd, mp)
567 pid_t pid;
568 pfstype type;
569 int fd;
570 struct mount *mp;
571 {
572 struct pfs_hashhead *ppp;
573 struct pfsnode *pp;
574 struct vnode *vp;
575
576 loop:
577 simple_lock(&pfs_hash_slock);
578 ppp = &pfs_hashtbl[PFSPIDHASH(pid)];
579 LIST_FOREACH(pp, ppp, pfs_hash) {
580 vp = PFSTOV(pp);
581 if (pid == pp->pfs_pid && pp->pfs_type == type &&
582 pp->pfs_fd == fd && vp->v_mount == mp) {
583 simple_lock(&vp->v_interlock);
584 simple_unlock(&pfs_hash_slock);
585 if (vget(vp, LK_EXCLUSIVE | LK_INTERLOCK))
586 goto loop;
587 return (vp);
588 }
589 }
590 simple_unlock(&pfs_hash_slock);
591 return (NULL);
592 }
593
594 /*
595 * Insert the pfsnode into the hash table and lock it.
596 */
597 void
598 procfs_hashins(pp)
599 struct pfsnode *pp;
600 {
601 struct pfs_hashhead *ppp;
602
603 /* lock the pfsnode, then put it on the appropriate hash list */
604 lockmgr(&pp->pfs_vnode->v_lock, LK_EXCLUSIVE, (struct simplelock *)0);
605
606 simple_lock(&pfs_hash_slock);
607 ppp = &pfs_hashtbl[PFSPIDHASH(pp->pfs_pid)];
608 LIST_INSERT_HEAD(ppp, pp, pfs_hash);
609 simple_unlock(&pfs_hash_slock);
610 }
611
612 /*
613 * Remove the pfsnode from the hash table.
614 */
615 void
616 procfs_hashrem(pp)
617 struct pfsnode *pp;
618 {
619 simple_lock(&pfs_hash_slock);
620 LIST_REMOVE(pp, pfs_hash);
621 simple_unlock(&pfs_hash_slock);
622 }
623
624 void
625 procfs_revoke_vnodes(p, arg)
626 struct proc *p;
627 void *arg;
628 {
629 struct pfsnode *pfs, *pnext;
630 struct vnode *vp;
631 struct mount *mp = (struct mount *)arg;
632 struct pfs_hashhead *ppp;
633
634 if (!(p->p_flag & P_SUGID))
635 return;
636
637 ppp = &pfs_hashtbl[PFSPIDHASH(p->p_pid)];
638 for (pfs = LIST_FIRST(ppp); pfs; pfs = pnext) {
639 vp = PFSTOV(pfs);
640 pnext = LIST_NEXT(pfs, pfs_hash);
641 if (vp->v_usecount > 0 && pfs->pfs_pid == p->p_pid &&
642 vp->v_mount == mp)
643 VOP_REVOKE(vp, REVOKEALL);
644 }
645 }
646
647 int
648 procfs_proc_lock(int pid, struct proc **bunghole, int notfound)
649 {
650 struct proc *tp;
651 int error = 0;
652
653 rw_enter(&proclist_lock, RW_READER);
654
655 if (pid == 0)
656 tp = &proc0;
657 else if ((tp = p_find(pid, PFIND_LOCKED)) == NULL)
658 error = notfound;
659
660 if (tp != NULL) {
661 mutex_enter(&tp->p_mutex);
662 error = proc_addref(tp);
663 mutex_exit(&tp->p_mutex);
664 }
665
666 rw_exit(&proclist_lock);
667
668 *bunghole = tp;
669 return error;
670 }
671
672 void
673 procfs_proc_unlock(struct proc *p)
674 {
675 mutex_enter(&p->p_mutex);
676 proc_delref(p);
677 mutex_exit(&p->p_mutex);
678 }
679