- /* Integer registers */
-
-#define gregs ((struct regs *)core_reg_sect)
- /* G0 *always* holds 0. */
- *(int *) ®isters[REGISTER_BYTE (0)] = 0;
-
- /* The globals and output registers. */
- memcpy (®isters[REGISTER_BYTE (G1_REGNUM)], &gregs->r_g1,
- 15 * REGISTER_RAW_SIZE (G1_REGNUM));
- *(int *) ®isters[REGISTER_BYTE (PS_REGNUM)] = gregs->r_ps;
- *(int *) ®isters[REGISTER_BYTE (PC_REGNUM)] = gregs->r_pc;
- *(int *) ®isters[REGISTER_BYTE (NPC_REGNUM)] = gregs->r_npc;
- *(int *) ®isters[REGISTER_BYTE (Y_REGNUM)] = gregs->r_y;
-
- /* My best guess at where to get the locals and input
- registers is exactly where they usually are, right above
- the stack pointer. If the core dump was caused by a bus error
- from blowing away the stack pointer (as is possible) then this
- won't work, but it's worth the try. */
+\f
+/* Implement the to_xfer_partial target_ops method for
+ TARGET_OBJECT_WCOOKIE. Fetch StackGhost Per-Process XOR cookie. */
+
+static enum target_xfer_status
+sparc_xfer_wcookie (struct target_ops *ops, enum target_object object,
+ const char *annex, gdb_byte *readbuf,
+ const gdb_byte *writebuf, ULONGEST offset, ULONGEST len,
+ ULONGEST *xfered_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 TARGET_XFER_EOF; /* Signal EOF. */
+ if (offset > sizeof (unsigned long))
+ return TARGET_XFER_E_IO;
+
+#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). Since release 3.6, OpenBSD uses a fully randomized
+ cookie. */
+ {
+ int pid = ptid_get_pid (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_TYPE_ARG3) &wcookie, 0) == -1)