Module Name: src
Committed By: chs
Date: Fri Jun 9 01:17:25 UTC 2017
Modified Files:
src/external/bsd/libproc/dist: _libproc.h libproc.h proc_create.c
proc_util.c
Log Message:
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.
To generate a diff of this commit:
cvs rdiff -u -r1.1.1.1 -r1.2 src/external/bsd/libproc/dist/_libproc.h
cvs rdiff -u -r1.2 -r1.3 src/external/bsd/libproc/dist/libproc.h \
src/external/bsd/libproc/dist/proc_create.c
cvs rdiff -u -r1.5 -r1.6 src/external/bsd/libproc/dist/proc_util.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/external/bsd/libproc/dist/_libproc.h
diff -u src/external/bsd/libproc/dist/_libproc.h:1.1.1.1 src/external/bsd/libproc/dist/_libproc.h:1.2
--- src/external/bsd/libproc/dist/_libproc.h:1.1.1.1 Thu Sep 24 14:05:35 2015
+++ src/external/bsd/libproc/dist/_libproc.h Fri Jun 9 01:17:25 2017
@@ -41,6 +41,7 @@ struct proc_handle {
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;
Index: src/external/bsd/libproc/dist/libproc.h
diff -u src/external/bsd/libproc/dist/libproc.h:1.2 src/external/bsd/libproc/dist/libproc.h:1.3
--- src/external/bsd/libproc/dist/libproc.h:1.2 Fri Sep 25 16:07:32 2015
+++ src/external/bsd/libproc/dist/libproc.h Fri Jun 9 01:17:25 2017
@@ -114,6 +114,9 @@ typedef struct lwpstatus {
#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 @@ int proc_name2sym(struct proc_handle *,
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 *);
Index: src/external/bsd/libproc/dist/proc_create.c
diff -u src/external/bsd/libproc/dist/proc_create.c:1.2 src/external/bsd/libproc/dist/proc_create.c:1.3
--- src/external/bsd/libproc/dist/proc_create.c:1.2 Thu Sep 24 14:12:48 2015
+++ src/external/bsd/libproc/dist/proc_create.c Fri Jun 9 01:17:25 2017
@@ -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, int, int, st
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 @@ proc_init(pid_t pid, int flags, int stat
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);
}
Index: src/external/bsd/libproc/dist/proc_util.c
diff -u src/external/bsd/libproc/dist/proc_util.c:1.5 src/external/bsd/libproc/dist/proc_util.c:1.6
--- src/external/bsd/libproc/dist/proc_util.c:1.5 Wed Feb 1 20:01:39 2017
+++ src/external/bsd/libproc/dist/proc_util.c Fri Jun 9 01:17:25 2017
@@ -144,6 +144,16 @@ proc_state(struct proc_handle *phdl)
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)
{