aboutsummaryrefslogtreecommitdiff
path: root/gdb/sparc-nat.c
diff options
context:
space:
mode:
Diffstat (limited to 'gdb/sparc-nat.c')
-rw-r--r--gdb/sparc-nat.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/gdb/sparc-nat.c b/gdb/sparc-nat.c
index 3ab21f0..955e65e 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,64 @@ 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, but a future release probably will. */
+ {
+ int pid;
+
+ pid = TIDGET (inferior_ptid);
+ if (pid == 0)
+ pid = PIDGET (inferior_ptid);
+
+ /* Sanity check. The proper type for a cookie is register_t, but
+ we can't assume that this type exists on all systems supported
+ by the code in this file. */
+ gdb_assert (sizeof (wcookie) == sizeof (register_t));
+
+ /* Fetch the cookie. */
+ if (ptrace (PT_WCOOKIE, pid, (PTRACE_ARG3_TYPE) &wcookie, 0) == -1)
+ {
+ if (errno != EINVAL)
+ perror_with_name ("Couldn't get StackGhost cookie");
+
+ /* Although PT_WCOOKIE is defined on OpenBSD 3.1 and later,
+ the request wasn't implemented until after OpenBSD 3.4. If
+ the kernel doesn't support the PT_WCOOKIE request, assume
+ we're running on a kernel that uses non-randomized cookies. */
+ 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);