Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/external/bsd/libproc Add glue, adjust for NetBSD.
details: https://anonhg.NetBSD.org/src/rev/3d4d84a1261d
branches: trunk
changeset: 340660:3d4d84a1261d
user: christos <christos%NetBSD.org@localhost>
date: Thu Sep 24 14:12:47 2015 +0000
description:
Add glue, adjust for NetBSD.
diffstat:
external/bsd/libproc/Makefile | 5 ++
external/bsd/libproc/Makefile.inc | 3 +
external/bsd/libproc/dist/proc_bkpt.c | 6 ++-
external/bsd/libproc/dist/proc_create.c | 8 ++-
external/bsd/libproc/dist/proc_regs.c | 21 ++++++++++
external/bsd/libproc/dist/proc_rtld.c | 9 +++-
external/bsd/libproc/dist/proc_sym.c | 25 ++++++++++--
external/bsd/libproc/dist/proc_util.c | 2 +
external/bsd/libproc/dist/tests/proc_test.c | 43 +++++++++++++++++++--
external/bsd/libproc/dist/tests/target_prog.c | 3 +
external/bsd/libproc/lib/Makefile | 53 +++++++++++++++++++++++++++
external/bsd/libproc/tests/Makefile | 24 ++++++++++++
12 files changed, 185 insertions(+), 17 deletions(-)
diffs (truncated from 485 to 300 lines):
diff -r 35fdc1df2925 -r 3d4d84a1261d external/bsd/libproc/Makefile
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/external/bsd/libproc/Makefile Thu Sep 24 14:12:47 2015 +0000
@@ -0,0 +1,5 @@
+# $NetBSD: Makefile,v 1.1 2015/09/24 14:12:47 christos Exp $
+
+SUBDIR= lib .WAIT tests
+
+.include <bsd.subdir.mk>
diff -r 35fdc1df2925 -r 3d4d84a1261d external/bsd/libproc/Makefile.inc
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/external/bsd/libproc/Makefile.inc Thu Sep 24 14:12:47 2015 +0000
@@ -0,0 +1,3 @@
+# $NetBSD: Makefile.inc,v 1.1 2015/09/24 14:12:48 christos Exp $
+
+LIBPROCDIR:= ${.PARSEDIR}/dist
diff -r 35fdc1df2925 -r 3d4d84a1261d external/bsd/libproc/dist/proc_bkpt.c
--- a/external/bsd/libproc/dist/proc_bkpt.c Thu Sep 24 14:05:35 2015 +0000
+++ b/external/bsd/libproc/dist/proc_bkpt.c Thu Sep 24 14:12:47 2015 +0000
@@ -28,16 +28,20 @@
*/
#include <sys/cdefs.h>
+#ifdef __FBSDID
__FBSDID("$FreeBSD: head/lib/libproc/proc_bkpt.c 287106 2015-08-24 12:17:15Z andrew $");
+#else
+__RCSID("$NetBSD: proc_bkpt.c,v 1.2 2015/09/24 14:12:48 christos Exp $");
+#endif
#include <sys/types.h>
#include <sys/ptrace.h>
#include <sys/wait.h>
-#include <machine/_inttypes.h>
#include <assert.h>
#include <err.h>
#include <errno.h>
+#include <inttypes.h>
#include <signal.h>
#include <stdio.h>
#include "_libproc.h"
diff -r 35fdc1df2925 -r 3d4d84a1261d external/bsd/libproc/dist/proc_create.c
--- a/external/bsd/libproc/dist/proc_create.c Thu Sep 24 14:05:35 2015 +0000
+++ b/external/bsd/libproc/dist/proc_create.c Thu Sep 24 14:12:47 2015 +0000
@@ -25,6 +25,8 @@
*
* $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 $");
#include <sys/types.h>
#include <sys/sysctl.h>
@@ -54,9 +56,9 @@
phdl->status = status;
mib[0] = CTL_KERN;
- mib[1] = KERN_PROC;
- mib[2] = KERN_PROC_PATHNAME;
- mib[3] = pid;
+ mib[1] = KERN_PROC_ARGS;
+ mib[2] = pid;
+ mib[3] = KERN_PROC_PATHNAME;
len = sizeof(phdl->execname);
if (sysctl(mib, 4, phdl->execname, &len, NULL, 0) != 0) {
error = errno;
diff -r 35fdc1df2925 -r 3d4d84a1261d external/bsd/libproc/dist/proc_regs.c
--- a/external/bsd/libproc/dist/proc_regs.c Thu Sep 24 14:05:35 2015 +0000
+++ b/external/bsd/libproc/dist/proc_regs.c Thu Sep 24 14:12:47 2015 +0000
@@ -28,7 +28,11 @@
*/
#include <sys/cdefs.h>
+#ifdef __FBSDID
__FBSDID("$FreeBSD: head/lib/libproc/proc_regs.c 285003 2015-07-01 13:59:26Z br $");
+#else
+__RCSID("$NetBSD: proc_regs.c,v 1.2 2015/09/24 14:12:48 christos Exp $");
+#endif
#include <sys/types.h>
#include <sys/ptrace.h>
@@ -37,6 +41,7 @@
#include <stdio.h>
#include <string.h>
#include <errno.h>
+#include <sys/ucontext.h>
#include "_libproc.h"
int
@@ -54,6 +59,9 @@
return (-1);
switch (reg) {
case REG_PC:
+#ifdef PTRACE_REG_PC
+ *regvalue = PTRACE_REG_PC(®s);
+#else
#if defined(__aarch64__)
*regvalue = regs.elr;
#elif defined(__amd64__)
@@ -67,8 +75,12 @@
#elif defined(__powerpc__)
*regvalue = regs.pc;
#endif
+#endif
break;
case REG_SP:
+#ifdef PTRACE_REG_SP
+ *regvalue = PTRACE_REG_SP(®s);
+#else
#if defined(__aarch64__)
*regvalue = regs.sp;
#elif defined(__amd64__)
@@ -82,6 +94,7 @@
#elif defined(__powerpc__)
*regvalue = regs.fixreg[1];
#endif
+#endif
break;
default:
DPRINTFX("ERROR: no support for reg number %d", reg);
@@ -105,6 +118,9 @@
return (-1);
switch (reg) {
case REG_PC:
+#ifdef PTRACE_REG_SET_PC
+ PTRACE_REG_SET_PC(®s, regvalue);
+#else
#if defined(__aarch64__)
regs.elr = regvalue;
#elif defined(__amd64__)
@@ -118,8 +134,12 @@
#elif defined(__powerpc__)
regs.pc = regvalue;
#endif
+#endif
break;
case REG_SP:
+#ifdef PTRACE_REG_SP
+ PTRACE_REG_SP(®s) = regvalue;
+#else
#if defined(__aarch64__)
regs.sp = regvalue;
#elif defined(__amd64__)
@@ -133,6 +153,7 @@
#elif defined(__powerpc__)
regs.fixreg[1] = regvalue;
#endif
+#endif
break;
default:
DPRINTFX("ERROR: no support for reg number %d", reg);
diff -r 35fdc1df2925 -r 3d4d84a1261d external/bsd/libproc/dist/proc_rtld.c
--- a/external/bsd/libproc/dist/proc_rtld.c Thu Sep 24 14:05:35 2015 +0000
+++ b/external/bsd/libproc/dist/proc_rtld.c Thu Sep 24 14:12:47 2015 +0000
@@ -28,7 +28,11 @@
*/
#include <sys/cdefs.h>
+#ifdef __FBSDID
__FBSDID("$FreeBSD: head/lib/libproc/proc_rtld.c 265255 2014-05-03 04:44:03Z markj $");
+#else
+__RCSID("$NetBSD: proc_rtld.c,v 1.2 2015/09/24 14:12:48 christos Exp $");
+#endif
#include <stdio.h>
#include <string.h>
@@ -44,9 +48,8 @@
if (phdl->nobjs >= phdl->rdobjsz) {
phdl->rdobjsz *= 2;
- phdl->rdobjs = reallocf(phdl->rdobjs, sizeof(*phdl->rdobjs) *
- phdl->rdobjsz);
- if (phdl->rdobjs == NULL)
+ if (reallocarr(&phdl->rdobjs, sizeof(*phdl->rdobjs),
+ phdl->rdobjsz))
return (-1);
}
if (strcmp(lop->rdl_path, phdl->execname) == 0 &&
diff -r 35fdc1df2925 -r 3d4d84a1261d external/bsd/libproc/dist/proc_sym.c
--- a/external/bsd/libproc/dist/proc_sym.c Thu Sep 24 14:05:35 2015 +0000
+++ b/external/bsd/libproc/dist/proc_sym.c Thu Sep 24 14:12:47 2015 +0000
@@ -29,7 +29,11 @@
*/
#include <sys/cdefs.h>
+#ifdef __FBSDID
__FBSDID("$FreeBSD: head/lib/libproc/proc_sym.c 279946 2015-03-13 04:26:48Z stas $");
+#else
+__RCSID("$NetBSD: proc_sym.c,v 1.2 2015/09/24 14:12:48 christos Exp $");
+#endif
#include <sys/types.h>
#ifndef NO_CTF
@@ -37,6 +41,7 @@
#include <sys/ctf_api.h>
#endif
#include <sys/user.h>
+#include <sys/sysctl.h>
#include <assert.h>
#include <err.h>
@@ -49,7 +54,7 @@
#ifndef NO_CTF
#include <libctf.h>
#endif
-#include <libutil.h>
+#include <util.h>
#include "_libproc.h"
@@ -63,6 +68,18 @@
static void proc_rdl2prmap(rd_loadobj_t *, prmap_t *);
+#ifdef __NetBSD__
+static char *basename_r(const char *path, char *buf)
+{
+ // We "know" this works.
+ if (path[0])
+ strlcpy(buf, strrchr(path, '/') + 1, PATH_MAX);
+ else
+ buf[0] = '\0';
+ return buf;
+}
+#endif
+
static void
demangle(const char *symbol, char *buf, size_t len)
{
@@ -197,8 +214,7 @@
prmap_t *
proc_addr2map(struct proc_handle *p, uintptr_t addr)
{
- size_t i;
- int cnt, lastvn = 0;
+ size_t i, cnt, lastvn = 0;
prmap_t *map;
rd_loadobj_t *rdl;
struct kinfo_vmentry *kves, *kve;
@@ -370,8 +386,7 @@
prmap_t *
proc_name2map(struct proc_handle *p, const char *name)
{
- size_t i;
- int cnt;
+ size_t i, cnt;
prmap_t *map = NULL;
char tmppath[MAXPATHLEN];
struct kinfo_vmentry *kves, *kve;
diff -r 35fdc1df2925 -r 3d4d84a1261d external/bsd/libproc/dist/proc_util.c
--- a/external/bsd/libproc/dist/proc_util.c Thu Sep 24 14:05:35 2015 +0000
+++ b/external/bsd/libproc/dist/proc_util.c Thu Sep 24 14:12:47 2015 +0000
@@ -208,6 +208,7 @@
if (ptrace(PT_LWPINFO, phdl->pid, (caddr_t)&lwpinfo,
sizeof(lwpinfo)) < 0)
return (NULL);
+#ifdef PL_FLAG_SI
siginfo = &lwpinfo.pl_siginfo;
if (lwpinfo.pl_event == PL_EVENT_SIGNAL &&
(lwpinfo.pl_flags & PL_FLAG_SI) != 0) {
@@ -225,6 +226,7 @@
} else if (lwpinfo.pl_flags & PL_FLAG_SCX) {
psp->pr_why = PR_SYSEXIT;
}
+#endif
return (psp);
}
diff -r 35fdc1df2925 -r 3d4d84a1261d external/bsd/libproc/dist/tests/proc_test.c
--- a/external/bsd/libproc/dist/tests/proc_test.c Thu Sep 24 14:05:35 2015 +0000
+++ b/external/bsd/libproc/dist/tests/proc_test.c Thu Sep 24 14:12:47 2015 +0000
@@ -25,7 +25,10 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/lib/libproc/tests/proc_test.c 287333 2015-08-31 20:30:06Z emaste $");
+#ifdef __FBSDID
+__FBSDID("$FreeBSD: head/lib/libproc/tests/proc_test.c 286863 2015-08-17 23:19:36Z emaste $");
+#endif
+__RCSID("$NetBSD: proc_test.c,v 1.2 2015/09/24 14:12:48 christos Exp $");
#include <sys/types.h>
#include <sys/wait.h>
@@ -40,9 +43,31 @@
#include <libproc.h>
static const char *aout_object = "a.out";
+#if defined(__NetBSD__)
+static const char *r_debug_state = "_rtld_debug_state";
+#elif defined(__FreeBSD__)
+static const char *r_debug_state = "r_debug_state";
+#endif
+
+#if !defined(__aarch64__)
+#if defined(__NetBSD__)
+static const char *ldelf_object = "ld.elf_so";
+#elif defined(__FreeBSD__)
static const char *ldelf_object = "ld-elf.so.1";
+#endif
+#endif
Home |
Main Index |
Thread Index |
Old Index