This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB 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]

[PATCH] Finalize SPARC StackGhost support; add TARGET_OBJECT_WCOOKIE


This should make GDB work much better on OpenBSD/sparc native.

Committed,

Mark


Index: target.h
===================================================================
RCS file: /cvs/src/src/gdb/target.h,v
retrieving revision 1.56
diff -u -p -r1.56 target.h
--- target.h 1 Feb 2004 22:35:10 -0000 1.56
+++ target.h 4 Feb 2004 21:47:07 -0000
@@ -228,6 +228,8 @@ enum target_object
   TARGET_OBJECT_UNWIND_TABLE,
   /* Transfer auxilliary vector.  */
   TARGET_OBJECT_AUXV,
+  /* StackGhost cookie.  See "sparc-tdep.c".  */
+  TARGET_OBJECT_WCOOKIE
 
   /* Possible future objects: TARGET_OBJECT_FILE, TARGET_OBJECT_PROC, ... */
 };
Index: inftarg.c
===================================================================
RCS file: /cvs/src/src/gdb/inftarg.c,v
retrieving revision 1.22
diff -u -p -r1.22 inftarg.c
--- inftarg.c 1 Feb 2004 22:35:10 -0000 1.22
+++ inftarg.c 4 Feb 2004 21:47:07 -0000
@@ -1,7 +1,7 @@
 /* Target-vector operations for controlling Unix child processes, for GDB.
 
    Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1998, 1999,
-   2000, 2002, 2003 Free Software Foundation, Inc.
+   2000, 2002, 2003, 2004 Free Software Foundation, Inc.
 
    Contributed by Cygnus Support.
 
@@ -584,6 +584,13 @@ child_xfer_partial (struct target_ops *o
 #endif
       return NATIVE_XFER_AUXV (ops, object, annex, readbuf, writebuf,
 			       offset, len);
+
+    case TARGET_OBJECT_WCOOKIE:
+#ifndef NATIVE_XFER_WCOOKIE
+#define NATIVE_XFER_WCOOKIE(OPS,OBJECT,ANNEX,WRITEBUF,READBUF,OFFSET,LEN) (-1)
+#endif
+      return NATIVE_XFER_WCOOKIE (ops, object, annex, readbuf, writebuf,
+				  offset, len);
 
     default:
       return -1;
Index: sparc-nat.c
===================================================================
RCS file: /cvs/src/src/gdb/sparc-nat.c,v
retrieving revision 1.24
diff -u -p -r1.24 sparc-nat.c
--- sparc-nat.c 12 Jan 2004 18:33:47 -0000 1.24
+++ sparc-nat.c 4 Feb 2004 21:47:07 -0000
@@ -22,7 +22,9 @@
 #include "defs.h"
 #include "inferior.h"
 #include "regcache.h"
+#include "target.h"
 
+#include "gdb_assert.h"
 #include <signal.h>
 #include "gdb_string.h"
 #include <sys/ptrace.h>
@@ -246,8 +248,40 @@ store_inferior_registers (int regnum)
 	return;
     }
 }
+
 
+/* Fetch StackGhost Per-Process XOR cookie.  */
+
+LONGEST
+sparc_xfer_wcookie (struct target_ops *ops, enum target_object object,
+		    const char *annex, void *readbuf, const void *writebuf,
+		    ULONGEST offset, LONGEST len)
+{
+  unsigned long wcookie = 0;
+  char *buf = (char *)&wcookie;
+
+  gdb_assert (object == TARGET_OBJECT_WCOOKIE);
+  gdb_assert (readbuf && writebuf == NULL);
+
+  if (offset >= sizeof (unsigned long))
+    return -1;
 
+#ifdef PT_WCOOKIE
+  /* If PT_WCOOKIE is defined (by <sys/ptrace.h>), assume we're
+     running on an OpenBSD release that uses StackGhost (3.1 or
+     later).  As of release 3.4, OpenBSD doesn't use a randomized
+     cookie yet.  */
+  wcookie = 0x3;
+#endif /* PT_WCOOKIE */
+
+  if (len > sizeof (unsigned long) - offset)
+    len = sizeof (unsigned long) - offset;
+
+  memcpy (readbuf, buf + offset, len);
+  return len;
+}
+
+
 /* Provide a prototype to silence -Wmissing-prototypes.  */
 void _initialize_sparc_nat (void);
 
Index: sparc-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/sparc-tdep.c,v
retrieving revision 1.147
diff -u -p -r1.147 sparc-tdep.c
--- sparc-tdep.c 31 Jan 2004 15:42:24 -0000 1.147
+++ sparc-tdep.c 4 Feb 2004 21:47:08 -0000
@@ -141,13 +141,21 @@ sparc_fetch_instruction (CORE_ADDR pc)
 ULONGEST
 sparc_fetch_wcookie (void)
 {
-  /* FIXME: kettenis/20040131: We should fetch the cookie from the
-     target.  For now, return zero, which is right for targets without
-     StackGhost.  */
-  return 0;
-}
+  struct target_ops *ops = &current_target;
+  char buf[8];
+  int len;
+
+  len = target_read_partial (ops, TARGET_OBJECT_WCOOKIE, NULL, buf, 0, 8);
+  if (len == -1)
+    return 0;
+
+  /* We should have either an 32-bit or an 64-bit cookie.  */
+  gdb_assert (len == 4 || len == 8);
 
+  return extract_unsigned_integer (buf, len);
+}
 
+
 /* Return the contents if register REGNUM as an address.  */
 
 static CORE_ADDR
Index: Makefile.in
===================================================================
RCS file: /cvs/src/src/gdb/Makefile.in,v
retrieving revision 1.486
diff -u -p -r1.486 Makefile.in
--- Makefile.in 2 Feb 2004 03:12:32 -0000 1.486
+++ Makefile.in 4 Feb 2004 21:47:10 -0000
@@ -2383,8 +2383,9 @@ sparc-linux-tdep.o: sparc-linux-tdep.c $
 	$(frame_unwind_h) $(gdbarch_h) $(gdbcore_h) $(osabi_h) $(regcache_h) \
 	$(solib_svr4_h) $(symtab_h) $(trad_frame_h) $(gdb_assert_h) \
 	$(gdb_string_h) $(sparc_tdep_h)
-sparc-nat.o: sparc-nat.c $(defs_h) $(inferior_h) $(regcache_h) \
-	$(gdb_string_h) $(gdb_wait_h) $(sparc_tdep_h) $(sparc_nat_h)
+sparc-nat.o: sparc-nat.c $(defs_h) $(inferior_h) $(regcache_h) $(target_h) \
+	$(gdb_assert_h) $(gdb_string_h) $(gdb_wait_h) $(sparc_tdep_h) \
+	$(sparc_nat_h)
 sparcnbsd-nat.o: sparcnbsd-nat.c $(defs_h) $(sparc_tdep_h) $(sparc_nat_h)
 sparcnbsd-tdep.o: sparcnbsd-tdep.c $(defs_h) $(floatformat_h) $(frame_h) \
 	$(frame_unwind_h) $(gdbcore_h) $(osabi_h) $(regcache_h) $(regset_h) \
Index: config/sparc/nm-nbsd.h
===================================================================
RCS file: /cvs/src/src/gdb/config/sparc/nm-nbsd.h,v
retrieving revision 1.8
diff -u -p -r1.8 nm-nbsd.h
--- config/sparc/nm-nbsd.h 3 Jan 2004 10:08:45 -0000 1.8
+++ config/sparc/nm-nbsd.h 4 Feb 2004 21:47:10 -0000
@@ -25,5 +25,17 @@
 
 /* Get generic NetBSD native definitions.  */
 #include "config/nm-nbsd.h"
+
+
+/* Support for StackGhost cookies.  */
+
+#include "target.h"
+
+#define NATIVE_XFER_WCOOKIE sparc_xfer_wcookie
+extern LONGEST sparc_xfer_wcookie (struct target_ops *ops,
+				   enum target_object object,
+				   const char *annex,
+				   void *readbuf, const void *writebuf,
+				   ULONGEST offset, LONGEST len);
 
 #endif /* nm-nbsd.h */


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