Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/miscfs/procfs add an auxv node.
details: https://anonhg.NetBSD.org/src/rev/572e845d52ec
branches: trunk
changeset: 822663:572e845d52ec
user: christos <christos%NetBSD.org@localhost>
date: Thu Mar 30 20:16:29 2017 +0000
description:
add an auxv node.
diffstat:
sys/miscfs/procfs/files.procfs | 3 +-
sys/miscfs/procfs/procfs.h | 7 +++-
sys/miscfs/procfs/procfs_auxv.c | 74 +++++++++++++++++++++++++++++++++++++++
sys/miscfs/procfs/procfs_subr.c | 8 +++-
sys/miscfs/procfs/procfs_vfsops.c | 25 +++++++-----
sys/miscfs/procfs/procfs_vnops.c | 35 ++++++++++++++----
6 files changed, 130 insertions(+), 22 deletions(-)
diffs (truncated from 308 to 300 lines):
diff -r 0d9148da0e0a -r 572e845d52ec sys/miscfs/procfs/files.procfs
--- a/sys/miscfs/procfs/files.procfs Thu Mar 30 20:00:21 2017 +0000
+++ b/sys/miscfs/procfs/files.procfs Thu Mar 30 20:16:29 2017 +0000
@@ -1,8 +1,9 @@
-# $NetBSD: files.procfs,v 1.10 2016/11/02 00:12:00 pgoyette Exp $
+# $NetBSD: files.procfs,v 1.11 2017/03/30 20:16:29 christos Exp $
deffs PROCFS: PTRACE_HOOKS
define procfs: vfs
+file miscfs/procfs/procfs_auxv.c procfs
file miscfs/procfs/procfs_cmdline.c procfs
file miscfs/procfs/procfs_ctl.c procfs
file miscfs/procfs/procfs_fd.c procfs
diff -r 0d9148da0e0a -r 572e845d52ec sys/miscfs/procfs/procfs.h
--- a/sys/miscfs/procfs/procfs.h Thu Mar 30 20:00:21 2017 +0000
+++ b/sys/miscfs/procfs/procfs.h Thu Mar 30 20:16:29 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: procfs.h,v 1.70 2014/07/27 16:47:26 hannken Exp $ */
+/* $NetBSD: procfs.h,v 1.71 2017/03/30 20:16:29 christos Exp $ */
/*
* Copyright (c) 1993
@@ -110,6 +110,7 @@
PFSstatm, /* process memory info (if -o linux) */
PFSversion, /* kernel version (if -o linux) */
PFStask, /* task subdirector (if -o linux) */
+ PFSauxv, /* ELF Auxiliary Vector */
#ifdef __HAVE_PROCFS_MACHDEP
PROCFS_MACHDEP_NODE_TYPES
#endif
@@ -192,6 +193,7 @@
int procfs_proc_lock(int, struct proc **, int);
void procfs_proc_unlock(struct proc *);
+struct mount;
int procfs_allocvp(struct mount *, struct vnode **, pid_t, pfstype, int);
int procfs_donote(struct lwp *, struct proc *, struct pfsnode *,
struct uio *);
@@ -233,11 +235,14 @@
struct uio *);
int procfs_doversion(struct lwp *, struct proc *, struct pfsnode *,
struct uio *);
+int procfs_doauxv(struct lwp *, struct proc *, struct pfsnode *,
+ struct uio *);
void procfs_revoke_vnodes(struct proc *, void *);
int procfs_getfp(struct pfsnode *, struct proc *, struct file **);
/* functions to check whether or not files should be displayed */
+int procfs_validauxv(struct lwp *, struct mount *);
int procfs_validfile(struct lwp *, struct mount *);
int procfs_validfpregs(struct lwp *, struct mount *);
int procfs_validregs(struct lwp *, struct mount *);
diff -r 0d9148da0e0a -r 572e845d52ec sys/miscfs/procfs/procfs_auxv.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/miscfs/procfs/procfs_auxv.c Thu Mar 30 20:16:29 2017 +0000
@@ -0,0 +1,74 @@
+/* $NetBSD: procfs_auxv.c,v 1.1 2017/03/30 20:16:29 christos Exp $ */
+
+/*-
+ * Copyright (c) 2017 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Christos Zoulas.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: procfs_auxv.c,v 1.1 2017/03/30 20:16:29 christos Exp $");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/proc.h>
+#include <sys/kmem.h>
+
+#include <miscfs/procfs/procfs.h>
+
+int
+procfs_doauxv(struct lwp *curl, struct proc *p, struct pfsnode *pfs,
+ struct uio *uio)
+{
+ int error;
+ void *buffer;
+ size_t bufsize;
+
+ if (uio->uio_rw != UIO_READ)
+ return EOPNOTSUPP;
+
+ if ((error = proc_getauxv(p, &buffer, &bufsize)) != 0)
+ return error;
+
+ /*
+ * We support reading from an offset, because linux does.
+ * The map could have changed between the two reads, and
+ * that could result in junk, but typically it does not.
+ */
+ if (uio->uio_offset < bufsize)
+ error = uiomove((char *)buffer + uio->uio_offset,
+ bufsize - uio->uio_offset, uio);
+ else
+ error = 0;
+
+ kmem_free(buffer, bufsize);
+ return error;
+}
+
+int
+procfs_validauxv(struct lwp *l, struct mount *mp)
+{
+ return l != NULL && l->l_proc != NULL && l->l_proc->p_execsw != NULL;
+}
diff -r 0d9148da0e0a -r 572e845d52ec sys/miscfs/procfs/procfs_subr.c
--- a/sys/miscfs/procfs/procfs_subr.c Thu Mar 30 20:00:21 2017 +0000
+++ b/sys/miscfs/procfs/procfs_subr.c Thu Mar 30 20:16:29 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: procfs_subr.c,v 1.106 2014/11/10 18:46:34 maxv Exp $ */
+/* $NetBSD: procfs_subr.c,v 1.107 2017/03/30 20:16:29 christos Exp $ */
/*-
* Copyright (c) 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -102,7 +102,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: procfs_subr.c,v 1.106 2014/11/10 18:46:34 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: procfs_subr.c,v 1.107 2017/03/30 20:16:29 christos Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -272,6 +272,10 @@
error = procfs_doversion(curl, p, pfs, uio);
break;
+ case PFSauxv:
+ error = procfs_doauxv(curl, p, pfs, uio);
+ break;
+
#ifdef __HAVE_PROCFS_MACHDEP
PROCFS_MACHDEP_NODETYPE_CASES
error = procfs_machdep_rw(curl, l, pfs, uio);
diff -r 0d9148da0e0a -r 572e845d52ec sys/miscfs/procfs/procfs_vfsops.c
--- a/sys/miscfs/procfs/procfs_vfsops.c Thu Mar 30 20:00:21 2017 +0000
+++ b/sys/miscfs/procfs/procfs_vfsops.c Thu Mar 30 20:16:29 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: procfs_vfsops.c,v 1.96 2017/02/17 08:31:25 hannken Exp $ */
+/* $NetBSD: procfs_vfsops.c,v 1.97 2017/03/30 20:16:29 christos Exp $ */
/*
* Copyright (c) 1993
@@ -76,7 +76,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: procfs_vfsops.c,v 1.96 2017/02/17 08:31:25 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: procfs_vfsops.c,v 1.97 2017/03/30 20:16:29 christos Exp $");
#if defined(_KERNEL_OPT)
#include "opt_compat_netbsd.h"
@@ -386,20 +386,25 @@
vp->v_type = VREG;
break;
- case PFSmap: /* /proc/N/map = -r--r--r-- */
- case PFSmaps: /* /proc/N/maps = -r--r--r-- */
- case PFSstatus: /* /proc/N/status = -r--r--r-- */
- case PFSstat: /* /proc/N/stat = -r--r--r-- */
+ case PFSmap: /* /proc/N/map = -r-------- */
+ case PFSmaps: /* /proc/N/maps = -r-------- */
+ case PFSauxv: /* /proc/N/auxv = -r-------- */
+ pfs->pfs_mode = S_IRUSR;
+ vp->v_type = VREG;
+ break;
+
+ case PFSstatus: /* /proc/N/status = -r--r--r-- */
+ case PFSstat: /* /proc/N/stat = -r--r--r-- */
case PFScmdline: /* /proc/N/cmdline = -r--r--r-- */
- case PFSemul: /* /proc/N/emul = -r--r--r-- */
+ case PFSemul: /* /proc/N/emul = -r--r--r-- */
case PFSmeminfo: /* /proc/meminfo = -r--r--r-- */
case PFScpustat: /* /proc/stat = -r--r--r-- */
case PFSdevices: /* /proc/devices = -r--r--r-- */
case PFScpuinfo: /* /proc/cpuinfo = -r--r--r-- */
- case PFSuptime: /* /proc/uptime = -r--r--r-- */
- case PFSmounts: /* /proc/mounts = -r--r--r-- */
+ case PFSuptime: /* /proc/uptime = -r--r--r-- */
+ case PFSmounts: /* /proc/mounts = -r--r--r-- */
case PFSloadavg: /* /proc/loadavg = -r--r--r-- */
- case PFSstatm: /* /proc/N/statm = -r--r--r-- */
+ case PFSstatm: /* /proc/N/statm = -r--r--r-- */
case PFSversion: /* /proc/version = -r--r--r-- */
pfs->pfs_mode = S_IRUSR|S_IRGRP|S_IROTH;
vp->v_type = VREG;
diff -r 0d9148da0e0a -r 572e845d52ec sys/miscfs/procfs/procfs_vnops.c
--- a/sys/miscfs/procfs/procfs_vnops.c Thu Mar 30 20:00:21 2017 +0000
+++ b/sys/miscfs/procfs/procfs_vnops.c Thu Mar 30 20:16:29 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: procfs_vnops.c,v 1.194 2016/08/20 12:37:09 hannken Exp $ */
+/* $NetBSD: procfs_vnops.c,v 1.195 2017/03/30 20:16:29 christos Exp $ */
/*-
* Copyright (c) 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -105,7 +105,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: procfs_vnops.c,v 1.194 2016/08/20 12:37:09 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: procfs_vnops.c,v 1.195 2017/03/30 20:16:29 christos Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -123,6 +123,7 @@
#include <sys/stat.h>
#include <sys/ptrace.h>
#include <sys/kauth.h>
+#include <sys/exec.h>
#include <uvm/uvm_extern.h> /* for PAGE_SIZE */
@@ -159,6 +160,7 @@
{ DT_DIR, N(".."), PFSroot, NULL },
{ DT_DIR, N("fd"), PFSfd, NULL },
{ DT_REG, N("file"), PFSfile, procfs_validfile },
+ { DT_REG, N("auxv"), PFSauxv, procfs_validauxv },
{ DT_REG, N("mem"), PFSmem, NULL },
{ DT_REG, N("regs"), PFSregs, procfs_validregs },
{ DT_REG, N("fpregs"), PFSfpregs, procfs_validfpregs },
@@ -735,13 +737,13 @@
case PFSstat:
case PFSnote:
case PFSnotepg:
- case PFSmap:
- case PFSmaps:
case PFScmdline:
case PFSemul:
case PFSstatm:
- if (pfs->pfs_type == PFSmap || pfs->pfs_type == PFSmaps)
- vap->va_mode = S_IRUSR;
+
+ case PFSmap:
+ case PFSmaps:
+ case PFSauxv:
vap->va_nlink = 1;
vap->va_uid = kauth_cred_geteuid(procp->p_cred);
vap->va_gid = kauth_cred_getegid(procp->p_cred);
@@ -758,8 +760,20 @@
vap->va_uid = vap->va_gid = 0;
break;
+ case PFSproc:
+ case PFStask:
+ case PFSexe:
+ case PFSfile:
+ case PFSself:
+ case PFScurproc:
+ case PFScwd:
+ case PFSroot:
+ case PFSchroot:
+ case PFSfd:
+ break;
+
default:
- break;
+ panic("%s: %d/1", __func__, pfs->pfs_type);
}
/*
@@ -847,6 +861,11 @@
procp->p_vmspace->vm_ssize);
break;
+ case PFSauxv:
+ vap->va_bytes = vap->va_size = procp->p_execsw->es_arglen;
+ break;
+
+
#if defined(PT_GETREGS) || defined(PT_SETREGS)
case PFSregs:
vap->va_bytes = vap->va_size = sizeof(struct reg);
@@ -913,7 +932,7 @@
Home |
Main Index |
Thread Index |
Old Index