Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys Support PIOD_READ_AUXV so that gdb can handle PIE binari...
details: https://anonhg.NetBSD.org/src/rev/87b2cbbf7180
branches: trunk
changeset: 339178:87b2cbbf7180
user: christos <christos%NetBSD.org@localhost>
date: Thu Jul 02 03:47:54 2015 +0000
description:
Support PIOD_READ_AUXV so that gdb can handle PIE binaries. From OpenBSD.
diffstat:
sys/kern/sys_process.c | 63 +++++++++++++++++++++++++++++++++++++++++++------
sys/sys/ptrace.h | 3 +-
2 files changed, 57 insertions(+), 9 deletions(-)
diffs (133 lines):
diff -r 734fbd53594e -r 87b2cbbf7180 sys/kern/sys_process.c
--- a/sys/kern/sys_process.c Wed Jul 01 18:18:00 2015 +0000
+++ b/sys/kern/sys_process.c Thu Jul 02 03:47:54 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: sys_process.c,v 1.165 2014/11/24 02:34:04 christos Exp $ */
+/* $NetBSD: sys_process.c,v 1.166 2015/07/02 03:47:54 christos Exp $ */
/*-
* Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -118,7 +118,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sys_process.c,v 1.165 2014/11/24 02:34:04 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_process.c,v 1.166 2015/07/02 03:47:54 christos Exp $");
#include "opt_ptrace.h"
#include "opt_ktrace.h"
@@ -127,6 +127,7 @@
#include <sys/systm.h>
#include <sys/proc.h>
#include <sys/errno.h>
+#include <sys/exec.h>
#include <sys/ptrace.h>
#include <sys/uio.h>
#include <sys/ras.h>
@@ -148,6 +149,9 @@
# endif
static kauth_listener_t ptrace_listener;
+#ifdef PTRACE
+static int process_auxv_offset(struct proc *, struct uio *);
+#endif
static int
ptrace_listener_cb(kauth_cred_t cred, kauth_action_t action, void *cookie,
@@ -531,6 +535,14 @@
error = copyin(SCARG(uap, addr), &piod, sizeof(piod));
if (error)
break;
+
+ iov.iov_base = piod.piod_addr;
+ iov.iov_len = piod.piod_len;
+ uio.uio_iov = &iov;
+ uio.uio_iovcnt = 1;
+ uio.uio_offset = (off_t)(unsigned long)piod.piod_offs;
+ uio.uio_resid = piod.piod_len;
+
switch (piod.piod_op) {
case PIOD_READ_D:
case PIOD_READ_I:
@@ -546,6 +558,19 @@
}
uio.uio_rw = UIO_WRITE;
break;
+ case PIOD_READ_AUXV:
+ req = PT_READ_D;
+ uio.uio_rw = UIO_READ;
+ tmp = t->p_execsw->es_arglen * sizeof(char *);
+ if (uio.uio_offset > tmp)
+ return EIO;
+ if (uio.uio_resid > tmp - uio.uio_offset)
+ uio.uio_resid = tmp - uio.uio_offset;
+ piod.piod_len = iov.iov_len = uio.uio_resid;
+ error = process_auxv_offset(t, &uio);
+ if (error)
+ return error;
+ break;
default:
error = EINVAL;
break;
@@ -555,12 +580,6 @@
error = proc_vmspace_getref(l->l_proc, &vm);
if (error)
break;
- iov.iov_base = piod.piod_addr;
- iov.iov_len = piod.piod_len;
- uio.uio_iov = &iov;
- uio.uio_iovcnt = 1;
- uio.uio_offset = (off_t)(unsigned long)piod.piod_offs;
- uio.uio_resid = piod.piod_len;
uio.uio_vmspace = vm;
error = process_domem(l, lt, &uio);
@@ -1138,3 +1157,31 @@
mutex_exit(p->p_lock);
}
#endif /* KTRACE || PTRACE */
+
+#ifdef PTRACE
+static int
+process_auxv_offset(struct proc *p, struct uio *uio)
+{
+ struct ps_strings pss;
+ int error;
+ off_t off = (off_t)p->p_psstrp;
+
+ if ((error = copyin_psstrings(p, &pss)) != 0)
+ return error;
+
+ if (pss.ps_envstr == NULL)
+ return EIO;
+
+ uio->uio_offset += (off_t)(vaddr_t)(pss.ps_envstr + pss.ps_nenvstr + 1);
+#ifdef __MACHINE_STACK_GROWS_UP
+ if (uio->uio_offset < off)
+ return EIO;
+#else
+ if (uio->uio_offset > off)
+ return EIO;
+ if ((uio->uio_offset + uio->uio_resid) > off)
+ uio->uio_resid = off - uio->uio_offset;
+#endif
+ return 0;
+}
+#endif
diff -r 734fbd53594e -r 87b2cbbf7180 sys/sys/ptrace.h
--- a/sys/sys/ptrace.h Wed Jul 01 18:18:00 2015 +0000
+++ b/sys/sys/ptrace.h Thu Jul 02 03:47:54 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ptrace.h,v 1.45 2014/01/04 00:10:03 dsl Exp $ */
+/* $NetBSD: ptrace.h,v 1.46 2015/07/02 03:47:54 christos Exp $ */
/*-
* Copyright (c) 1984, 1993
@@ -104,6 +104,7 @@
#define PIOD_WRITE_D 2 /* write to D spcae */
#define PIOD_READ_I 3 /* read from I space */
#define PIOD_WRITE_I 4 /* write to I space */
+#define PIOD_READ_AUXV 5 /* Read from aux array */
/*
* Argument structure for PT_LWPINFO.
Home |
Main Index |
Thread Index |
Old Index