Subject: kern/15945: PT_IO
To: None <gnats-bugs@gnats.netbsd.org>
From: None <lha@stacken.kth.se>
List: netbsd-bugs
Date: 03/17/2002 15:29:03
>Number: 15945
>Category: kern
>Synopsis: PT_IO
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: kern-bug-people
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Sun Mar 17 06:31:00 PST 2002
>Closed-Date:
>Last-Modified:
>Originator: Love
>Release: NetBSD 1.5ZB
>Organization:
Stacken Computer Club
>Environment:
System: NetBSD nutcracker.stacken.kth.se 1.5ZB NetBSD 1.5ZB (NUTCRACKER) #7: Sun Mar 17 15:01:14 CET 2002 lha@nutcracker.stacken.kth.se:/usr/src/sys/arch/i386/compile/NUTCRACKER i386
Architecture: i386
Machine: i386
>Description:
Artur Grabowski <art@blahonga.org>, described a more generic
pthread API for reading/writing to a process on
<bsd-api-discuss@wasabisystems.com>.
>How-To-Repeat:
Try use use pmdb and find PT_IO missing.
>Fix:
I just adapeded the Artur's patch (including the changes
proposed to bsd-api-discuss list) to netbsd.
Index: sys/ptrace.h
===================================================================
RCS file: /sources/netbsd/NetBSD-cvs/syssrc/sys/sys/ptrace.h,v
retrieving revision 1.23
diff -u -r1.23 ptrace.h
--- sys/ptrace.h 2001/12/05 00:58:06 1.23
+++ sys/ptrace.h 2002/03/17 13:55:21
@@ -1,4 +1,4 @@
-/* $NetBSD: ptrace.h,v 1.22 2001/06/13 16:06:27 nathanw Exp $ */
+/* $NetBSD: ptrace.h,v 1.23 2001/12/05 00:58:06 thorpej Exp $ */
/*-
* Copyright (c) 1984, 1993
@@ -47,6 +47,22 @@
#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; /* I/O operation */
+ void *piod_offs; /* child offset */
+ void *piod_addr; /* parent offset */
+ size_t piod_len; /* request length */
+};
+
+/*
+ * Operations in piod_op.
+ */
+#define PIOD_READ_D 1 /* Read from D space */
+#define PIOD_WRITE_D 2 /* Write to D space */
+#define PIOD_READ_I 3 /* Read from I space */
+#define PIOD_WRITE_I 4 /* Write to I space */
#define PT_FIRSTMACH 32 /* for machine-specific requests */
#include <machine/ptrace.h> /* machine-specific requests, if any */
Index: kern/sys_process.c
===================================================================
RCS file: /sources/netbsd/NetBSD-cvs/syssrc/sys/kern/sys_process.c,v
retrieving revision 1.72
diff -u -r1.72 sys_process.c
--- kern/sys_process.c 2002/01/11 21:16:28 1.72
+++ kern/sys_process.c 2002/03/17 14:00:58
@@ -95,6 +95,7 @@
struct proc *t; /* target process */
struct uio uio;
struct iovec iov;
+ struct ptrace_io_desc piod;
int s, error, write, tmp;
/* "A foolish consistency..." XXX */
@@ -168,6 +169,7 @@
case PT_WRITE_I:
case PT_WRITE_D:
case PT_CONTINUE:
+ case PT_IO:
case PT_KILL:
case PT_DETACH:
#ifdef PT_STEP
@@ -255,6 +257,35 @@
error = procfs_domem(p, t, NULL, &uio);
if (!write)
*retval = tmp;
+ 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_READ_D:
+ case PIOD_READ_I:
+ uio.uio_rw = UIO_READ;
+ break;
+ case PIOD_WRITE_D:
+ case PIOD_WRITE_I:
+ uio.uio_rw = UIO_WRITE;
+ break;
+ default:
+ return (EINVAL);
+ }
+ error = procfs_domem(p, t, NULL, &uio);
+ piod.piod_len -= uio.uio_resid;
+ (void) copyout(&piod, SCARG(uap, addr), sizeof(piod));
return (error);
#ifdef PT_STEP
>Release-Note:
>Audit-Trail:
>Unformatted: