This is the mail archive of the frysk@sources.redhat.com mailing list for the frysk project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

PTraceByteBuffer vs errno


Hi,

While investigating some strange RuntimeExceptions (indicating
interrupted system calls) coming from PTraceByteBuffer I noticed that it
does its own errno handling when calling the Ptrace class. This seems
incorrect since Ptrace a) does its own errno handling and will throw the
appropriate exception when errno is set and b) Ptrace is not just a
simple call, but a complex chaining of calls through multiple threads so
the errno value set might not be related at all to the original errno
call. So I propose to remove all errno handling from PtraceByteBuffer.
This also made my local breakpoint tests become more predictable.

2006-07-18  Mark Wielaard  <mark@klomp.org>

        * frysk/sys/cni/PtraceByteBuffer.cxx (newPerror): Removed.
        (peek(long)): Remove errno handling.
        (peek(long,jbyteArray,jlong,jlong)): Likewise.
        (poke): Likewise.

Does this look OK?

Cheers,

Mark
Index: frysk/sys/cni/PtraceByteBuffer.cxx
===================================================================
RCS file: /cvs/frysk/frysk-sys/frysk/sys/cni/PtraceByteBuffer.cxx,v
retrieving revision 1.3
diff -u -r1.3 PtraceByteBuffer.cxx
--- frysk/sys/cni/PtraceByteBuffer.cxx	10 Jul 2006 13:35:46 -0000	1.3
+++ frysk/sys/cni/PtraceByteBuffer.cxx	18 Jul 2006 14:51:33 -0000
@@ -1,4 +1,5 @@
 // This file is part of INUA.  Copyright 2004, 2005, Andrew Cagney
+// Copyright 2006, Red Hat, Inc.
 //
 // INUA is free software; you can redistribute it and/or modify it
 // under the terms of the GNU General Public License as published by
@@ -39,34 +40,17 @@
 #include <sys/ptrace.h>
 #include <stdlib.h>
 #include <unistd.h>
-#include <errno.h>
 #include <alloca.h>
 #include <stdio.h>
 
 #include <gcj/cni.h>
 
-#include <java/lang/RuntimeException.h>
-
 #include "frysk/sys/PtraceByteBuffer.h"
 #include "frysk/sys/PtraceByteBuffer$Area.h"
 #include "frysk/sys/Ptrace.h"
 #include "inua/eio/Buffer.h"
 #include "inua/eio/ByteBuffer.h"
 
-static java::lang::RuntimeException *
-newPerror (const char *syscall, pid_t pid, jlong addr, int nr)
-{
-  const char *error = strerror (nr);
-  char *message;
-  if (asprintf (&message, "%s: %s (pid %d addr 0x%llx)",
-		syscall, error, pid, (long long unsigned) addr)
-      <= 0)
-    throw new java::lang::RuntimeException (JvNewStringLatin1 ("oops"));
-  jstring jmessage = JvNewStringLatin1 (message);
-  free (message);
-  return new java::lang::RuntimeException (jmessage);
-}
-
 
 frysk::sys::PtraceByteBuffer$Area*
 frysk::sys::PtraceByteBuffer$Area::textArea ()
@@ -112,10 +96,7 @@
   /* Word align the address, transfer one word.  */
   long paddr = addr & -sizeof (long);
 
-  errno = 0;
   tmp.word = frysk::sys::Ptrace::peek(pt_peek, pid, (jstring) (char *) paddr);
-  if (errno != 0)
-    throw newPerror ("ptrace.PEEK", pid, paddr, errno);
 
   return tmp.byte[addr & (sizeof (long) - 1)];
 }
@@ -140,10 +121,7 @@
   unsigned long paddr = addr & -sizeof (long);
 
   // Read an entire word.
-  errno = 0;
   tmp.word = frysk::sys::Ptrace::peek(pt_peek, pid, (jstring) (char *) paddr);
-  if (errno != 0)
-    throw newPerror ("ptrace.PEEK", pid, paddr, errno);
 
   /* Adjust the xfer size to ensure that it doesn't exceed the size of
      the single word being transfered.  */
@@ -173,17 +151,11 @@
   long paddr = addr & -sizeof (long);
 
   // Perform a read ...
-  errno = 0;
   tmp.word = frysk::sys::Ptrace::peek(pt_peek, pid, (jstring) (char *) paddr);
-  if (errno != 0)
-    throw newPerror ("ptrace.PEEK", pid, paddr, errno);
 
   // ... modify ...
   tmp.byte[addr & (sizeof (long) - 1)] = byte;
 
   // ... write.
-  errno = 0;
   frysk::sys::Ptrace::poke(pt_poke, pid, (jstring) (char *) paddr, tmp.word);
-  if (errno != 0)
-    throw newPerror ("ptrace.POKE", pid, paddr, errno);
 }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]