diff --git a/ChangeLog.mips b/ChangeLog.mips index 4039c01815..9b0b7bddfb 100644 --- a/ChangeLog.mips +++ b/ChangeLog.mips @@ -1,3 +1,10 @@ +2009-05-16 Joseph Myers + + * 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 * sysdeps/unix/sysv/linux/mips/mips64/n32/fallocate.c, diff --git a/sysdeps/mips/____longjmp_chk.c b/sysdeps/mips/____longjmp_chk.c new file mode 100644 index 0000000000..a46ed150d7 --- /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 +#define __longjmp ____longjmp_chk +#define CHECK_SP +#include <__longjmp.c> diff --git a/sysdeps/mips/__longjmp.c b/sysdeps/mips/__longjmp.c index 386c05625b..340485de8c 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 #include -#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 973b078ae7..d7e36ff686 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 #include -#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. */