-/* Copyright (C) 2001,2002,2004,2006 Free Software Foundation, Inc.
+/* Copyright (C) 2001-2021 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
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. */
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
#include <errno.h>
+#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ucontext.h>
+#include <unistd.h>
static ucontext_t ctx[3];
}
void
-test_stack(volatile int a, volatile int b,
- volatile int c, volatile int d)
+test_stack (volatile int a, volatile int b,
+ volatile int c, volatile int d)
{
volatile int e = 5;
volatile int f = 6;
/* Test for cases where getcontext is clobbering the callers
stack, including parameters. */
- getcontext(&uc);
+ getcontext (&uc);
if (a != 1)
{
{
if (back_in_main == 0)
{
- puts ("program did no reach main again");
+ puts ("program did not reach main again");
_exit (1);
}
}
atexit (check_called);
char st1[32768];
+ stack_t stack_before, stack_after;
+
+ sigaltstack (NULL, &stack_before);
puts ("making contexts");
if (getcontext (&ctx[1]) != 0)
{
if (errno == ENOSYS)
- exit (0);
+ {
+ back_in_main = 1;
+ exit (0);
+ }
printf ("%s: getcontext: %m\n", __FUNCTION__);
exit (1);
puts ("back at main program");
back_in_main = 1;
+ sigaltstack (NULL, &stack_after);
+
if (was_in_f1 == 0)
{
puts ("didn't reach f1");
exit (1);
}
+ /* Check sigaltstack state is not clobbered as in BZ #16629. */
+ if (stack_before.ss_sp != stack_after.ss_sp)
+ {
+ printf ("stack ss_sp mismatch: %p %p\n",
+ stack_before.ss_sp, stack_after.ss_sp);
+ exit (1);
+ }
+
+ if (stack_before.ss_size != stack_after.ss_size)
+ {
+ printf ("stack ss_size mismatch: %zd %zd\n",
+ stack_before.ss_size, stack_after.ss_size);
+ exit (1);
+ }
+
puts ("test succeeded");
return 0;
}