summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArtur Grabowski <art@cvs.openbsd.org>2002-03-11 14:20:36 +0000
committerArtur Grabowski <art@cvs.openbsd.org>2002-03-11 14:20:36 +0000
commit18b3305e0bdbac6a1d25f73f9941c22133f94648 (patch)
tree51d1d2f33e2ff300e60d42e8d720d0d1cbfa0ab9
parentf3a174ffc2b6a6ca8bbdb6ad0a35c2a9c7513955 (diff)
Add a more sane API for reading/writing traced process memory
with ptrace - PT_IO. Man page update in a few.
-rw-r--r--sys/kern/sys_process.c32
-rw-r--r--sys/sys/ptrace.h14
2 files changed, 43 insertions, 3 deletions
diff --git a/sys/kern/sys_process.c b/sys/kern/sys_process.c
index 9799445a778..ef529d30f07 100644
--- a/sys/kern/sys_process.c
+++ b/sys/kern/sys_process.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sys_process.c,v 1.17 2002/01/30 20:45:35 nordin Exp $ */
+/* $OpenBSD: sys_process.c,v 1.18 2002/03/11 14:20:35 art Exp $ */
/* $NetBSD: sys_process.c,v 1.55 1996/05/15 06:17:47 tls Exp $ */
/*-
@@ -91,6 +91,7 @@ sys_ptrace(p, v, retval)
struct iovec iov;
int error, write;
int temp;
+ struct ptrace_io_desc piod;
/* "A foolish consistency..." XXX */
if (SCARG(uap, req) == PT_TRACE_ME)
@@ -155,6 +156,7 @@ sys_ptrace(p, v, retval)
case PT_READ_D:
case PT_WRITE_I:
case PT_WRITE_D:
+ case PT_IO:
case PT_CONTINUE:
case PT_KILL:
case PT_DETACH:
@@ -231,7 +233,33 @@ sys_ptrace(p, v, retval)
if (write == 0)
*retval = temp;
return (error);
-
+ case PT_IO:
+ error = copyin(SCARG(uap, addr), &piod, sizeof(piod));
+ if (error)
+ return (error);
+ 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)(long)piod.piod_offs;
+ uio.uio_resid = piod.piod_len;
+ uio.uio_segflg = UIO_USERSPACE;
+ uio.uio_procp = p;
+ switch (piod.piod_op) {
+ case PIOD_OP_READ_DATA:
+ case PIOD_OP_READ_TEXT:
+ uio.uio_rw = UIO_READ;
+ break;
+ case PIOD_OP_WRITE_DATA:
+ case PIOD_OP_WRITE_TEXT:
+ uio.uio_rw = UIO_WRITE;
+ break;
+ default:
+ return (EINVAL);
+ }
+ error = procfs_domem(p, t, NULL, &uio);
+ *retval = piod.piod_len - uio.uio_resid;
+ return (error);
#ifdef PT_STEP
case PT_STEP:
/*
diff --git a/sys/sys/ptrace.h b/sys/sys/ptrace.h
index a5d0886442d..b8e023d62c6 100644
--- a/sys/sys/ptrace.h
+++ b/sys/sys/ptrace.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: ptrace.h,v 1.3 2001/06/18 09:01:52 art Exp $ */
+/* $OpenBSD: ptrace.h,v 1.4 2002/03/11 14:20:35 art Exp $ */
/* $NetBSD: ptrace.h,v 1.21 1996/02/09 18:25:26 christos Exp $ */
/*-
@@ -48,6 +48,18 @@
#define PT_KILL 8 /* kill the child process */
#define PT_ATTACH 9 /* attach to running process */
#define PT_DETACH 10 /* detach from running process */
+#define PT_IO 11 /* do I/O to/from the stopped process. */
+
+struct ptrace_io_desc {
+ int piod_op;
+#define PIOD_OP_READ_DATA 1
+#define PIOD_OP_WRITE_DATA 2
+#define PIOD_OP_READ_TEXT 3
+#define PIOD_OP_WRITE_TEXT 4
+ void *piod_offs; /* child offset */
+ void *piod_addr; /* parent offset */
+ size_t piod_len; /* request length */
+};
#define PT_FIRSTMACH 32 /* for machine-specific requests */
#include <machine/ptrace.h> /* machine-specific requests, if any */