diff options
author | Mark Kettenis <kettenis@gnu.org> | 2004-02-04 21:49:58 +0000 |
---|---|---|
committer | Mark Kettenis <kettenis@gnu.org> | 2004-02-04 21:49:58 +0000 |
commit | baf92889ebd77dceec279733db08e537eefbff49 (patch) | |
tree | 46f836a0e5e0b0fe877ce37226f1c6ac3bb60282 | |
parent | 6e4c6c91defcde7bd46625742b7df8108e8d597f (diff) | |
download | gdb-baf92889ebd77dceec279733db08e537eefbff49.zip gdb-baf92889ebd77dceec279733db08e537eefbff49.tar.gz gdb-baf92889ebd77dceec279733db08e537eefbff49.tar.bz2 |
* target.h (target_object): Add TARGET_OBJECT_WCOOKIE.
* inftarg.c: Update copyright year.
(child_xfer_partial): Add support for TARGET_OBJECT_WCOOKIE.
* sparc-nat.c: Include "target.h" and "gdb_assert.h".
(sparc_xfer_wcookie): New function.
* sparc-tdep.c (sparc_fetch_wcookie): New function.
* Makefile.in (sparc-nat.o): Update dependencies.
* config/sparc/nm-nbsd.h: Include "target.h".
(NATIVE_XFER_WCOOKIE): New define.
(sparc_xfer_wcookie): New prototype.
-rw-r--r-- | gdb/Makefile.in | 5 | ||||
-rw-r--r-- | gdb/config/sparc/nm-nbsd.h | 12 | ||||
-rw-r--r-- | gdb/inftarg.c | 9 | ||||
-rw-r--r-- | gdb/sparc-nat.c | 34 | ||||
-rw-r--r-- | gdb/sparc-tdep.c | 18 | ||||
-rw-r--r-- | gdb/target.h | 2 |
6 files changed, 72 insertions, 8 deletions
diff --git a/gdb/Makefile.in b/gdb/Makefile.in index e5fbe7e..0a2d210 100644 --- a/gdb/Makefile.in +++ b/gdb/Makefile.in @@ -2383,8 +2383,9 @@ sparc-linux-tdep.o: sparc-linux-tdep.c $(defs_h) $(floatformat_h) $(frame_h) \ $(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) \ diff --git a/gdb/config/sparc/nm-nbsd.h b/gdb/config/sparc/nm-nbsd.h index 089a5ac..5e05234 100644 --- a/gdb/config/sparc/nm-nbsd.h +++ b/gdb/config/sparc/nm-nbsd.h @@ -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 */ diff --git a/gdb/inftarg.c b/gdb/inftarg.c index 67706d2..a6f40ec 100644 --- a/gdb/inftarg.c +++ b/gdb/inftarg.c @@ -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. @@ -585,6 +585,13 @@ child_xfer_partial (struct target_ops *ops, enum target_object object, 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; } diff --git a/gdb/sparc-nat.c b/gdb/sparc-nat.c index 3ab21f0..477fc97 100644 --- a/gdb/sparc-nat.c +++ b/gdb/sparc-nat.c @@ -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); diff --git a/gdb/sparc-tdep.c b/gdb/sparc-tdep.c index 1719109..bbe5665 100644 --- a/gdb/sparc-tdep.c +++ b/gdb/sparc-tdep.c @@ -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 = ¤t_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 diff --git a/gdb/target.h b/gdb/target.h index 97feb7d..2d8ce37 100644 --- a/gdb/target.h +++ b/gdb/target.h @@ -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, ... */ }; |