Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/external/bsd/libproc/dist add a proc_getmodel() interface to...



details:   https://anonhg.NetBSD.org/src/rev/0c0f6e6380d5
branches:  trunk
changeset: 354268:0c0f6e6380d5
user:      chs <chs%NetBSD.org@localhost>
date:      Fri Jun 09 01:17:25 2017 +0000

description:
add a proc_getmodel() interface to return whether a process
is a 32-bit or 64-bit process.  the interface is from freebsd
but the implementation is different.
needed by dtrace.

diffstat:

 external/bsd/libproc/dist/_libproc.h    |   1 +
 external/bsd/libproc/dist/libproc.h     |   4 ++++
 external/bsd/libproc/dist/proc_create.c |  23 +++++++++++++++++++++--
 external/bsd/libproc/dist/proc_util.c   |  10 ++++++++++
 4 files changed, 36 insertions(+), 2 deletions(-)

diffs (99 lines):

diff -r c748d2b8c486 -r 0c0f6e6380d5 external/bsd/libproc/dist/_libproc.h
--- a/external/bsd/libproc/dist/_libproc.h      Fri Jun 09 01:16:54 2017 +0000
+++ b/external/bsd/libproc/dist/_libproc.h      Fri Jun 09 01:17:25 2017 +0000
@@ -41,6 +41,7 @@
        int     flags;                  /* Process flags. */
        int     status;                 /* Process status (PS_*). */
        int     wstat;                  /* Process wait status. */
+       int     model;                  /* Process data model. */
        rd_agent_t *rdap;               /* librtld_db agent */
        rd_loadobj_t *rdobjs;
        size_t  rdobjsz;
diff -r c748d2b8c486 -r 0c0f6e6380d5 external/bsd/libproc/dist/libproc.h
--- a/external/bsd/libproc/dist/libproc.h       Fri Jun 09 01:16:54 2017 +0000
+++ b/external/bsd/libproc/dist/libproc.h       Fri Jun 09 01:17:25 2017 +0000
@@ -114,6 +114,9 @@
 #define FLTBPT         -1
 } lwpstatus_t;
 
+#define        PR_MODEL_ILP32  1
+#define        PR_MODEL_LP64   2
+
 typedef struct {
        uint8_t data[PTRACE_BREAKPOINT_SIZE];
 } proc_breakpoint_t;
@@ -143,6 +146,7 @@
 struct ctf_file *proc_name2ctf(struct proc_handle *, const char *);
 int    proc_setflags(struct proc_handle *, int);
 int    proc_state(struct proc_handle *);
+int    proc_getmodel(struct proc_handle *);
 pid_t  proc_getpid(struct proc_handle *);
 int    proc_wstatus(struct proc_handle *);
 int    proc_getwstat(struct proc_handle *);
diff -r c748d2b8c486 -r 0c0f6e6380d5 external/bsd/libproc/dist/proc_create.c
--- a/external/bsd/libproc/dist/proc_create.c   Fri Jun 09 01:16:54 2017 +0000
+++ b/external/bsd/libproc/dist/proc_create.c   Fri Jun 09 01:17:25 2017 +0000
@@ -26,7 +26,7 @@
  * $FreeBSD: head/lib/libproc/proc_create.c 265255 2014-05-03 04:44:03Z markj $
  */
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: proc_create.c,v 1.2 2015/09/24 14:12:48 christos Exp $");
+__RCSID("$NetBSD: proc_create.c,v 1.3 2017/06/09 01:17:25 chs Exp $");
 
 #include <sys/types.h>
 #include <sys/sysctl.h>
@@ -47,7 +47,8 @@
 static int
 proc_init(pid_t pid, int flags, int status, struct proc_handle *phdl)
 {
-       int mib[4], error;
+       struct kinfo_proc2 kp;
+       int mib[6], error;
        size_t len;
 
        memset(phdl, 0, sizeof(*phdl));
@@ -68,6 +69,24 @@
        if (len == 0)
                phdl->execname[0] = '\0';
 
+#ifdef _LP64
+       len = sizeof(kp);
+       mib[0] = CTL_KERN;
+       mib[1] = KERN_PROC2;
+       mib[2] = KERN_PROC_PID;
+       mib[3] = pid;
+       mib[4] = len;
+       mib[5] = 1;
+       if (sysctl(mib, 6, &kp, &len, NULL, 0) != 0) {
+               error = errno;
+               DPRINTF("ERROR: cannot get kinfo_proc2 for pid %d", pid);
+               return (error);
+       }
+       phdl->model = (kp.p_flag & P_32) ? PR_MODEL_ILP32 : PR_MODEL_LP64;
+#else
+       phdl->model = PR_MODEL_ILP32;
+#endif
+
        return (0);
 }
 
diff -r c748d2b8c486 -r 0c0f6e6380d5 external/bsd/libproc/dist/proc_util.c
--- a/external/bsd/libproc/dist/proc_util.c     Fri Jun 09 01:16:54 2017 +0000
+++ b/external/bsd/libproc/dist/proc_util.c     Fri Jun 09 01:17:25 2017 +0000
@@ -144,6 +144,16 @@
        return (phdl->status);
 }
 
+int
+proc_getmodel(struct proc_handle *phdl)
+{
+
+       if (phdl == NULL)
+               return (-1);
+
+       return (phdl->model);
+}
+
 pid_t
 proc_getpid(struct proc_handle *phdl)
 {



Home | Main Index | Thread Index | Old Index