This is the mail archive of the
libc-ports@sources.redhat.com
mailing list for the libc-ports project.
____longjmp_chk for MIPS
- From: "Joseph S. Myers" <joseph at codesourcery dot com>
- To: libc-ports at sourceware dot org
- Date: Sat, 16 May 2009 22:28:18 +0000 (UTC)
- Subject: ____longjmp_chk for MIPS
As with ARM, MIPS needs the ____longjmp_chk function; I've applied this
patch to implement it (simpler than the ARM version because MIPS uses C
implementations of longjmp).
I do *not* plan to fix any other ports targets (or libc targets - only x86
and x86_64 presently have this implemented in libc) for this function;
port maintainers will need to do so for their ports (along with other
sysdeps updates where those have fallen behind changes to the libc files).
diff --git a/ChangeLog.mips b/ChangeLog.mips
index 4039c01..9b0b7bd 100644
--- a/ChangeLog.mips
+++ b/ChangeLog.mips
@@ -1,5 +1,12 @@
2009-05-16 Joseph Myers <joseph@codesourcery.com>
+ * sysdeps/mips/____longjmp_chk.c: New file.
+ * sysdeps/mips/__longjmp.c: If CHECK_SP is defined, use it. Don't
+ undefine __longjmp.
+ * sysdeps/mips64/__longjmp.c: Likewise.
+
+2009-05-16 Joseph Myers <joseph@codesourcery.com>
+
* sysdeps/unix/sysv/linux/mips/mips64/n32/fallocate.c,
sysdeps/unix/sysv/linux/mips/mips64/n32/fallocate64.c,
sysdeps/unix/sysv/linux/mips/mips64/n64/fallocate.c,
diff --git a/sysdeps/mips/____longjmp_chk.c b/sysdeps/mips/____longjmp_chk.c
new file mode 100644
index 0000000..a46ed15
--- /dev/null
+++ b/sysdeps/mips/____longjmp_chk.c
@@ -0,0 +1,22 @@
+/* Copyright (C) 2009 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <stdio.h>
+#define __longjmp ____longjmp_chk
+#define CHECK_SP
+#include <__longjmp.c>
diff --git a/sysdeps/mips/__longjmp.c b/sysdeps/mips/__longjmp.c
index 386c056..340485d 100644
--- a/sysdeps/mips/__longjmp.c
+++ b/sysdeps/mips/__longjmp.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1992, 1995, 1997, 2000 Free Software Foundation, Inc.
+/* Copyright (C) 1992, 1995, 1997, 2000, 2009 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Brendan Kehoe (brendan@zen.org).
@@ -20,8 +20,6 @@
#include <setjmp.h>
#include <stdlib.h>
-#undef __longjmp
-
#ifndef __GNUC__
#error This file uses GNU C extensions; you must compile with GCC.
#endif
@@ -36,6 +34,11 @@ __longjmp (env, val_arg)
Without this it saves $a1 in a register which gets clobbered
along the way. */
register int val asm ("a1");
+#ifdef CHECK_SP
+ register long sp asm ("$29");
+ if ((long) (env[0].__sp) < sp)
+ __fortify_fail ("longjmp causes uninitialized stack frame");
+#endif
#ifdef __mips_hard_float
/* Pull back the floating point callee-saved registers. */
diff --git a/sysdeps/mips/mips64/__longjmp.c b/sysdeps/mips/mips64/__longjmp.c
index 973b078..d7e36ff 100644
--- a/sysdeps/mips/mips64/__longjmp.c
+++ b/sysdeps/mips/mips64/__longjmp.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1992, 1995, 1997, 2000, 2003, 2004
+/* Copyright (C) 1992, 1995, 1997, 2000, 2003, 2004, 2009
Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Brendan Kehoe (brendan@zen.org).
@@ -22,8 +22,6 @@
#include <sgidefs.h>
#include <stdlib.h>
-#undef __longjmp
-
#ifndef __GNUC__
#error This file uses GNU C extensions; you must compile with GCC.
#endif
@@ -38,6 +36,11 @@ __longjmp (env, val_arg)
Without this it saves $a1 in a register which gets clobbered
along the way. */
register int val asm ("a1");
+#ifdef CHECK_SP
+ register long long sp asm ("$29");
+ if ((long long) (env[0].__sp) < sp)
+ __fortify_fail ("longjmp causes uninitialized stack frame");
+#endif
#ifdef __mips_hard_float
/* Pull back the floating point callee-saved registers. */
--
Joseph S. Myers
joseph@codesourcery.com