This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
[PATCH] Add StackGhost native support for OpenBSD/sparc
- From: Mark Kettenis <kettenis at chello dot nl>
- To: gdb-patches at sources dot redhat dot com
- Date: Sun, 8 Feb 2004 22:25:49 +0100 (CET)
- Subject: [PATCH] Add StackGhost native support for OpenBSD/sparc
I submitted my first OpenBSD kernel patch yesterday, and it has been
checked in already! Now that there are kernels out there that
actually implement PT_WCOOKIE, it makes sense to commit this bit of
code.
Mark
Index: ChangeLog
from Mark Kettenis <kettenis@gnu.org>
* sparc-nat.c (sparc_xfer_wcookie): Try to fetch the cookie using
the PT_WCOOKIE request.
Index: sparc-nat.c
===================================================================
RCS file: /cvs/src/src/gdb/sparc-nat.c,v
retrieving revision 1.25
diff -u -p -r1.25 sparc-nat.c
--- sparc-nat.c 4 Feb 2004 21:49:55 -0000 1.25
+++ sparc-nat.c 8 Feb 2004 21:20:54 -0000
@@ -270,8 +270,32 @@ sparc_xfer_wcookie (struct target_ops *o
/* 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;
+ 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)