procfs_subr.c revision 1.68.14.5 1 /* $NetBSD: procfs_subr.c,v 1.68.14.5 2006/12/29 20:27:44 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.5 2006/12/29 20:27:44 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 case PFSexe: /* /proc/N/exe = lr-xr-xr-x */
212 pfs->pfs_mode = S_IRUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH;
213 vp->v_type = VLNK;
214 break;
215
216 case PFSproc: /* /proc/N = dr-xr-xr-x */
217 case PFSfd:
218 if (fd == -1) { /* /proc/N/fd = dr-xr-xr-x */
219 pfs->pfs_mode = S_IRUSR|S_IXUSR;
220 vp->v_type = VDIR;
221 } else { /* /proc/N/fd/M = [ps-]rw------- */
222 struct file *fp;
223 struct vnode *vxp;
224
225 mutex_enter(&p->p_mutex);
226 fp = fd_getfile(p->p_fd, pfs->pfs_fd);
227 mutex_exit(&p->p_mutex);
228 if (fp == NULL) {
229 error = EBADF;
230 goto bad;
231 }
232 FILE_USE(fp);
233
234 pfs->pfs_mode = S_IRUSR|S_IWUSR;
235 switch (fp->f_type) {
236 case DTYPE_VNODE:
237 vxp = (struct vnode *)fp->f_data;
238
239 /*
240 * We make symlinks for directories
241 * to avoid cycles.
242 */
243 if (vxp->v_type == VDIR)
244 goto symlink;
245 vp->v_type = vxp->v_type;
246 break;
247 case DTYPE_PIPE:
248 vp->v_type = VFIFO;
249 break;
250 case DTYPE_SOCKET:
251 vp->v_type = VSOCK;
252 break;
253 case DTYPE_KQUEUE:
254 case DTYPE_MISC:
255 symlink:
256 pfs->pfs_mode = S_IRUSR|S_IXUSR|S_IRGRP|
257 S_IXGRP|S_IROTH|S_IXOTH;
258 vp->v_type = VLNK;
259 break;
260 default:
261 error = EOPNOTSUPP;
262 FILE_UNUSE(fp, curlwp);
263 goto bad;
264 }
265 FILE_UNUSE(fp, curlwp);
266 }
267 break;
268
269 case PFSfile: /* /proc/N/file = -rw------- */
270 case PFSmem: /* /proc/N/mem = -rw------- */
271 case PFSregs: /* /proc/N/regs = -rw------- */
272 case PFSfpregs: /* /proc/N/fpregs = -rw------- */
273 pfs->pfs_mode = S_IRUSR|S_IWUSR;
274 vp->v_type = VREG;
275 break;
276
277 case PFSctl: /* /proc/N/ctl = --w------ */
278 case PFSnote: /* /proc/N/note = --w------ */
279 case PFSnotepg: /* /proc/N/notepg = --w------ */
280 pfs->pfs_mode = S_IWUSR;
281 vp->v_type = VREG;
282 break;
283
284 case PFSmap: /* /proc/N/map = -r--r--r-- */
285 case PFSmaps: /* /proc/N/maps = -r--r--r-- */
286 case PFSstatus: /* /proc/N/status = -r--r--r-- */
287 case PFSstat: /* /proc/N/stat = -r--r--r-- */
288 case PFScmdline: /* /proc/N/cmdline = -r--r--r-- */
289 case PFSemul: /* /proc/N/emul = -r--r--r-- */
290 case PFSmeminfo: /* /proc/meminfo = -r--r--r-- */
291 case PFSdevices: /* /proc/devices = -r--r--r-- */
292 case PFScpuinfo: /* /proc/cpuinfo = -r--r--r-- */
293 case PFSuptime: /* /proc/uptime = -r--r--r-- */
294 case PFSmounts: /* /proc/mounts = -r--r--r-- */
295 pfs->pfs_mode = S_IRUSR|S_IRGRP|S_IROTH;
296 vp->v_type = VREG;
297 break;
298
299 #ifdef __HAVE_PROCFS_MACHDEP
300 PROCFS_MACHDEP_NODETYPE_CASES
301 procfs_machdep_allocvp(vp);
302 break;
303 #endif
304
305 default:
306 panic("procfs_allocvp");
307 }
308
309 procfs_hashins(pfs);
310 uvm_vnp_setsize(vp, 0);
311 mutex_exit(&pfs_hashmutex);
312
313 *vpp = vp;
314 return (0);
315
316 bad:
317 mutex_exit(&pfs_hashmutex);
318 FREE(pfs, M_TEMP);
319 ungetnewvnode(vp);
320 return (error);
321 }
322
323 int
324 procfs_freevp(vp)
325 struct vnode *vp;
326 {
327 struct pfsnode *pfs = VTOPFS(vp);
328
329 procfs_hashrem(pfs);
330
331 FREE(vp->v_data, M_TEMP);
332 vp->v_data = 0;
333 return (0);
334 }
335
336 int
337 procfs_rw(v)
338 void *v;
339 {
340 struct vop_read_args *ap = v;
341 struct vnode *vp = ap->a_vp;
342 struct uio *uio = ap->a_uio;
343 struct lwp *curl;
344 struct lwp *l;
345 struct pfsnode *pfs = VTOPFS(vp);
346 struct proc *p;
347 int error;
348
349 if (uio->uio_offset < 0)
350 return EINVAL;
351
352 if ((error = procfs_proc_lock(pfs->pfs_pid, &p, ESRCH)) != 0)
353 return error;
354
355 /*
356 * Do not allow init to be modified while in secure mode; it
357 * could be duped into changing the security level.
358 */
359 if (uio->uio_rw == UIO_WRITE && p == initproc && securelevel > -1)
360 return EPERM;
361
362 /*
363 * Pick a suitable LWP to represent the process, and acquire a
364 * reference on it so that it does not exit.
365 *
366 * XXX The entire procfs interface needs work to be useful to a
367 * process with multiple LWPs. For the moment, we'll just kluge
368 * this and fail on others.
369 */
370 mutex_enter(&p->p_smutex);
371 l = proc_representative_lwp(p, NULL, 1);
372 lwp_addref(l);
373 mutex_exit(&p->p_smutex);
374
375 curl = curlwp;
376
377 switch (pfs->pfs_type) {
378 case PFSnote:
379 case PFSnotepg:
380 error = procfs_donote(curl, p, pfs, uio);
381 break;
382
383 case PFSregs:
384 error = procfs_doregs(curl, l, pfs, uio);
385 break;
386
387 case PFSfpregs:
388 error = procfs_dofpregs(curl, l, pfs, uio);
389 break;
390
391 case PFSctl:
392 error = procfs_doctl(curl, l, pfs, uio);
393 break;
394
395 case PFSstatus:
396 error = procfs_dostatus(curl, l, pfs, uio);
397 break;
398
399 case PFSstat:
400 error = procfs_do_pid_stat(curl, l, pfs, uio);
401 break;
402
403 case PFSmap:
404 error = procfs_domap(curl, p, pfs, uio, 0);
405 break;
406
407 case PFSmaps:
408 error = procfs_domap(curl, p, pfs, uio, 1);
409 break;
410
411 case PFSmem:
412 error = procfs_domem(curl, l, pfs, uio);
413 break;
414
415 case PFScmdline:
416 error = procfs_docmdline(curl, p, pfs, uio);
417 break;
418
419 case PFSmeminfo:
420 error = procfs_domeminfo(curl, p, pfs, uio);
421 break;
422
423 case PFSdevices:
424 error = procfs_dodevices(curl, p, pfs, uio);
425 break;
426
427 case PFScpuinfo:
428 error = procfs_docpuinfo(curl, p, pfs, uio);
429 break;
430
431 case PFSfd:
432 error = procfs_dofd(curl, p, pfs, uio);
433 break;
434
435 case PFSuptime:
436 error = procfs_douptime(curl, p, pfs, uio);
437 break;
438
439 case PFSmounts:
440 error = procfs_domounts(curl, p, pfs, uio);
441 break;
442
443 case PFSemul:
444 error = procfs_doemul(curl, p, pfs, uio);
445 break;
446
447 #ifdef __HAVE_PROCFS_MACHDEP
448 PROCFS_MACHDEP_NODETYPE_CASES
449 error = procfs_machdep_rw(curl, l, pfs, uio);
450 break;
451 #endif
452
453 default:
454 error = EOPNOTSUPP;
455 break;
456 }
457
458 /*
459 * Release the references that we acquired earlier.
460 */
461 lwp_delref(l);
462 procfs_proc_unlock(p);
463
464 return (error);
465 }
466
467 /*
468 * Get a string from userland into (bf). Strip a trailing
469 * nl character (to allow easy access from the shell).
470 * The buffer should be *buflenp + 1 chars long. vfs_getuserstr
471 * will automatically add a nul char at the end.
472 *
473 * Returns 0 on success or the following errors
474 *
475 * EINVAL: file offset is non-zero.
476 * EMSGSIZE: message is longer than kernel buffer
477 * EFAULT: user i/o buffer is not addressable
478 */
479 int
480 vfs_getuserstr(uio, bf, buflenp)
481 struct uio *uio;
482 char *bf;
483 int *buflenp;
484 {
485 int xlen;
486 int error;
487
488 if (uio->uio_offset != 0)
489 return (EINVAL);
490
491 xlen = *buflenp;
492
493 /* must be able to read the whole string in one go */
494 if (xlen < uio->uio_resid)
495 return (EMSGSIZE);
496 xlen = uio->uio_resid;
497
498 if ((error = uiomove(bf, xlen, uio)) != 0)
499 return (error);
500
501 /* allow multiple writes without seeks */
502 uio->uio_offset = 0;
503
504 /* cleanup string and remove trailing newline */
505 bf[xlen] = '\0';
506 xlen = strlen(bf);
507 if (xlen > 0 && bf[xlen-1] == '\n')
508 bf[--xlen] = '\0';
509 *buflenp = xlen;
510
511 return (0);
512 }
513
514 const vfs_namemap_t *
515 vfs_findname(nm, bf, buflen)
516 const vfs_namemap_t *nm;
517 const char *bf;
518 int buflen;
519 {
520
521 for (; nm->nm_name; nm++)
522 if (memcmp(bf, nm->nm_name, buflen+1) == 0)
523 return (nm);
524
525 return (0);
526 }
527
528 /*
529 * Initialize pfsnode hash table.
530 */
531 void
532 procfs_hashinit()
533 {
534 mutex_init(&pfs_hashmutex, MUTEX_DEFAULT, IPL_NONE);
535 pfs_hashtbl = hashinit(desiredvnodes / 4, HASH_LIST, M_UFSMNT,
536 M_WAITOK, &pfs_ihash);
537 simple_lock_init(&pfs_hash_slock);
538 }
539
540 void
541 procfs_hashreinit()
542 {
543 struct pfsnode *pp;
544 struct pfs_hashhead *oldhash, *hash;
545 u_long i, oldmask, mask, val;
546
547 hash = hashinit(desiredvnodes / 4, HASH_LIST, M_UFSMNT, M_WAITOK,
548 &mask);
549
550 simple_lock(&pfs_hash_slock);
551 oldhash = pfs_hashtbl;
552 oldmask = pfs_ihash;
553 pfs_hashtbl = hash;
554 pfs_ihash = mask;
555 for (i = 0; i <= oldmask; i++) {
556 while ((pp = LIST_FIRST(&oldhash[i])) != NULL) {
557 LIST_REMOVE(pp, pfs_hash);
558 val = PFSPIDHASH(pp->pfs_pid);
559 LIST_INSERT_HEAD(&hash[val], pp, pfs_hash);
560 }
561 }
562 simple_unlock(&pfs_hash_slock);
563 hashdone(oldhash, M_UFSMNT);
564 }
565
566 /*
567 * Free pfsnode hash table.
568 */
569 void
570 procfs_hashdone()
571 {
572 hashdone(pfs_hashtbl, M_UFSMNT);
573 }
574
575 struct vnode *
576 procfs_hashget(pid, type, fd, mp)
577 pid_t pid;
578 pfstype type;
579 int fd;
580 struct mount *mp;
581 {
582 struct pfs_hashhead *ppp;
583 struct pfsnode *pp;
584 struct vnode *vp;
585
586 loop:
587 simple_lock(&pfs_hash_slock);
588 ppp = &pfs_hashtbl[PFSPIDHASH(pid)];
589 LIST_FOREACH(pp, ppp, pfs_hash) {
590 vp = PFSTOV(pp);
591 if (pid == pp->pfs_pid && pp->pfs_type == type &&
592 pp->pfs_fd == fd && vp->v_mount == mp) {
593 simple_lock(&vp->v_interlock);
594 simple_unlock(&pfs_hash_slock);
595 if (vget(vp, LK_EXCLUSIVE | LK_INTERLOCK))
596 goto loop;
597 return (vp);
598 }
599 }
600 simple_unlock(&pfs_hash_slock);
601 return (NULL);
602 }
603
604 /*
605 * Insert the pfsnode into the hash table and lock it.
606 */
607 void
608 procfs_hashins(pp)
609 struct pfsnode *pp;
610 {
611 struct pfs_hashhead *ppp;
612
613 /* lock the pfsnode, then put it on the appropriate hash list */
614 lockmgr(&pp->pfs_vnode->v_lock, LK_EXCLUSIVE, (struct simplelock *)0);
615
616 simple_lock(&pfs_hash_slock);
617 ppp = &pfs_hashtbl[PFSPIDHASH(pp->pfs_pid)];
618 LIST_INSERT_HEAD(ppp, pp, pfs_hash);
619 simple_unlock(&pfs_hash_slock);
620 }
621
622 /*
623 * Remove the pfsnode from the hash table.
624 */
625 void
626 procfs_hashrem(pp)
627 struct pfsnode *pp;
628 {
629 simple_lock(&pfs_hash_slock);
630 LIST_REMOVE(pp, pfs_hash);
631 simple_unlock(&pfs_hash_slock);
632 }
633
634 void
635 procfs_revoke_vnodes(p, arg)
636 struct proc *p;
637 void *arg;
638 {
639 struct pfsnode *pfs, *pnext;
640 struct vnode *vp;
641 struct mount *mp = (struct mount *)arg;
642 struct pfs_hashhead *ppp;
643
644 if (!(p->p_flag & P_SUGID))
645 return;
646
647 ppp = &pfs_hashtbl[PFSPIDHASH(p->p_pid)];
648 for (pfs = LIST_FIRST(ppp); pfs; pfs = pnext) {
649 vp = PFSTOV(pfs);
650 pnext = LIST_NEXT(pfs, pfs_hash);
651 if (vp->v_usecount > 0 && pfs->pfs_pid == p->p_pid &&
652 vp->v_mount == mp)
653 VOP_REVOKE(vp, REVOKEALL);
654 }
655 }
656
657 int
658 procfs_proc_lock(int pid, struct proc **bunghole, int notfound)
659 {
660 struct proc *tp;
661 int error = 0;
662
663 rw_enter(&proclist_lock, RW_READER);
664
665 if (pid == 0)
666 tp = &proc0;
667 else if ((tp = p_find(pid, PFIND_LOCKED)) == NULL)
668 error = notfound;
669
670 if (tp != NULL) {
671 mutex_enter(&tp->p_mutex);
672 error = proc_addref(tp);
673 mutex_exit(&tp->p_mutex);
674 }
675
676 rw_exit(&proclist_lock);
677
678 *bunghole = tp;
679 return error;
680 }
681
682 void
683 procfs_proc_unlock(struct proc *p)
684 {
685 mutex_enter(&p->p_mutex);
686 proc_delref(p);
687 mutex_exit(&p->p_mutex);
688 }
689
690 int
691 procfs_doemul(struct lwp *curl, struct proc *p,
692 struct pfsnode *pfs, struct uio *uio)
693 {
694 const char *ename = p->p_emul->e_name;
695 return uiomove_frombuf(__UNCONST(ename), strlen(ename), uio);
696 }
697