Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Mark Kettenis <mark.kettenis@xs4all.nl>
To: stanshebs@earthlink.net
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH] PIE support for OpenBSD
Date: Tue, 27 Dec 2011 22:03:00 -0000	[thread overview]
Message-ID: <201112272138.pBRLcpI1006890@glazunov.sibelius.xs4all.nl> (raw)
In-Reply-To: <4EF3841C.2050603@earthlink.net> (message from Stan Shebs on Thu,	22 Dec 2011 11:25:16 -0800)

> Date: Thu, 22 Dec 2011 11:25:16 -0800
> From: Stan Shebs <stanshebs@earthlink.net>
> 
> Looks fine to me.  It would be helpful to mention somewhere in the 
> vicinity of the #if's that the code is BSD-specific or BSDish, so as to 
> forestall people hunting around in other OS headers wondering if those 
> macros are defined or not.

Fair enough.  The diff below is what I committed.


2011-12-27  Mark Kettenis  <kettenis@gnu.org>

	* inf-ptrace.c [PT_IO && PIOD_READ_AUXV]
	(inf_ptrace_xfer_partial): Implement TARGET_OBJECT_AUXV.
	(inf_ptrace_auxv_parse): New function.
	(inf_ptrace_target): Initialize to_auxv_parse field.

Index: inf-ptrace.c
===================================================================
RCS file: /cvs/src/src/gdb/inf-ptrace.c,v
retrieving revision 1.75
diff -u -p -r1.75 inf-ptrace.c
--- inf-ptrace.c	22 Sep 2011 10:22:28 -0000	1.75
+++ inf-ptrace.c	27 Dec 2011 21:35:05 -0000
@@ -582,6 +582,26 @@ inf_ptrace_xfer_partial (struct target_o
       return -1;
 
     case TARGET_OBJECT_AUXV:
+#if defined (PT_IO) && defined (PIOD_READ_AUXV)
+      /* OpenBSD 4.5 has a new PIOD_READ_AUXV operation for the PT_IO
+	 request that allows us to read the auxilliary vector.  Other
+	 BSD's may follow if they feel the need to support PIE.  */
+      {
+	struct ptrace_io_desc piod;
+
+	if (writebuf)
+		return -1;
+	piod.piod_op = PIOD_READ_AUXV;
+	piod.piod_addr = readbuf;
+	piod.piod_offs = (void *) (long) offset;
+	piod.piod_len = len;
+
+	errno = 0;
+	if (ptrace (PT_IO, pid, (caddr_t)&piod, 0) == 0)
+	  /* Return the actual number of bytes read or written.  */
+	  return piod.piod_len;
+      }
+#endif
       return -1;
 
     case TARGET_OBJECT_WCOOKIE:
@@ -619,6 +639,41 @@ inf_ptrace_pid_to_str (struct target_ops
   return normal_pid_to_str (ptid);
 }
 
+#if defined (PT_IO) && defined (PIOD_READ_AUXV)
+
+/* Read one auxv entry from *READPTR, not reading locations >= ENDPTR.
+   Return 0 if *READPTR is already at the end of the buffer.
+   Return -1 if there is insufficient buffer for a whole entry.
+   Return 1 if an entry was read into *TYPEP and *VALP.  */
+
+static int
+inf_ptrace_auxv_parse (struct target_ops *ops, gdb_byte **readptr,
+		       gdb_byte *endptr, CORE_ADDR *typep, CORE_ADDR *valp)
+{
+  struct type *int_type = builtin_type (target_gdbarch)->builtin_int;
+  struct type *ptr_type = builtin_type (target_gdbarch)->builtin_data_ptr;
+  const int sizeof_auxv_type = TYPE_LENGTH (int_type);
+  const int sizeof_auxv_val = TYPE_LENGTH (ptr_type);
+  enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch);
+  gdb_byte *ptr = *readptr;
+
+  if (endptr == ptr)
+    return 0;
+
+  if (endptr - ptr < 2 * sizeof_auxv_val)
+    return -1;
+
+  *typep = extract_unsigned_integer (ptr, sizeof_auxv_type, byte_order);
+  ptr += sizeof_auxv_val;	/* Alignment.  */
+  *valp = extract_unsigned_integer (ptr, sizeof_auxv_val, byte_order);
+  ptr += sizeof_auxv_val;
+
+  *readptr = ptr;
+  return 1;
+}
+
+#endif
+
 /* Create a prototype ptrace target.  The client can override it with
    local methods.  */
 
@@ -644,6 +699,9 @@ inf_ptrace_target (void)
   t->to_pid_to_str = inf_ptrace_pid_to_str;
   t->to_stop = inf_ptrace_stop;
   t->to_xfer_partial = inf_ptrace_xfer_partial;
+#if defined (PT_IO) && defined (PIOD_READ_AUXV)
+  t->to_auxv_parse = inf_ptrace_auxv_parse;
+#endif
 
   return t;
 }


  reply	other threads:[~2011-12-27 21:39 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-18  1:14 Mark Kettenis
2011-12-21 17:16 ` Jan Kratochvil
2011-12-21 21:27   ` Mark Kettenis
2011-12-21 22:01     ` Jan Kratochvil
2011-12-22  2:34     ` Stan Shebs
2011-12-22 10:25       ` Mark Kettenis
2011-12-22 19:40         ` Stan Shebs
2011-12-27 22:03           ` Mark Kettenis [this message]
2012-01-02  3:58             ` Yao Qi
2012-01-02  9:05               ` Mark Kettenis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=201112272138.pBRLcpI1006890@glazunov.sibelius.xs4all.nl \
    --to=mark.kettenis@xs4all.nl \
    --cc=gdb-patches@sourceware.org \
    --cc=stanshebs@earthlink.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox