int procfs_validmap (struct lwp *);
int procfs_validtype (struct lwp *);
+struct proc *pfs_pfind(pid_t);
+
#define PROCFS_LOCKED 0x01
#define PROCFS_WANT 0x02
#include <sys/mount.h>
#include <sys/vnode.h>
#include <sys/malloc.h>
+#include <sys/thread2.h>
#include <vfs/procfs/procfs.h>
return (0);
}
+/*
+ * Try to find the calling pid. Note that pfind()
+ * now references the proc structure to be returned
+ * and needs to be released later with PRELE().
+ */
+struct proc *
+pfs_pfind(pid_t pfs_pid)
+{
+ struct proc *p = NULL;
+
+ if (pfs_pid == 0) {
+ p = &proc0;
+ PHOLD(p);
+ } else {
+ p = pfind(pfs_pid);
+ }
+
+ return p;
+}
+
int
procfs_rw(struct vop_read_args *ap)
{
lwkt_gettoken(&proc_token);
- p = pfind(pfs->pfs_pid);
+ p = pfs_pfind(pfs->pfs_pid);
if (p == NULL) {
- lwkt_reltoken(&proc_token);
- return (EINVAL);
+ rtval = (EINVAL);
+ goto out;
}
if (p->p_pid == 1 && securelevel > 0 && uio->uio_rw == UIO_WRITE) {
- lwkt_reltoken(&proc_token);
- PRELE(p);
- return (EACCES);
+ rtval = (EACCES);
+ goto out;
}
/* XXX lwp */
lp = FIRST_LWP_IN_PROC(p);
pfs->pfs_lockowner = 0;
lwkt_reltoken(&proc_token);
wakeup(&pfs->pfs_lockowner);
- PRELE(p);
+
+out:
+ if (LWKT_TOKEN_HELD(&proc_token))
+ lwkt_reltoken(&proc_token);
+ if (p)
+ PRELE(p);
return rtval;
}
struct proc *p1, *p2;
int error;
- p2 = pfind(pfs->pfs_pid);
+ p2 = pfs_pfind(pfs->pfs_pid);
if (p2 == NULL)
return (ENOENT);
if (pfs->pfs_pid && !PRISON_CHECK(ap->a_cred, p2->p_ucred)) {
break;
default:
- procp = pfind(pfs->pfs_pid);
+ procp = pfs_pfind(pfs->pfs_pid);
if (procp == NULL || procp->p_ucred == NULL) {
error = ENOENT;
goto done;
if (pid == NO_PID)
break;
- p = pfind(pid);
+ p = pfs_pfind(pid);
if (p == NULL)
break;
goto out;
}
- p = pfind(pfs->pfs_pid);
+ p = pfs_pfind(pfs->pfs_pid);
if (p == NULL)
break;
/* XXX lwp */
struct uio *uio = ap->a_uio;
pfs = VTOPFS(ap->a_vp);
- p = pfind(pfs->pfs_pid);
+ p = pfs_pfind(pfs->pfs_pid);
if (p == NULL)
return(0);
if (!PRISON_CHECK(ap->a_cred, p->p_ucred)) {
* from under us...
*/
case Pfile:
- procp = pfind(pfs->pfs_pid);
+ procp = pfs_pfind(pfs->pfs_pid);
if (procp == NULL || procp->p_ucred == NULL) {
kprintf("procfs_readlink: pid %d disappeared\n",
pfs->pfs_pid);