2021-01-02 19:32:25 +00:00
|
|
|
/* Copyright (C) 2001-2021 Free Software Foundation, Inc.
|
2001-03-16 21:07:22 +00:00
|
|
|
This file is part of the GNU C Library.
|
|
|
|
|
|
|
|
The GNU C Library is free software; you can redistribute it and/or
|
2001-07-06 04:58:11 +00:00
|
|
|
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.
|
2001-03-16 21:07:22 +00:00
|
|
|
|
|
|
|
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
|
2001-07-06 04:58:11 +00:00
|
|
|
Lesser General Public License for more details.
|
2001-03-16 21:07:22 +00:00
|
|
|
|
2001-07-06 04:58:11 +00:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
2012-02-09 23:18:22 +00:00
|
|
|
License along with the GNU C Library; if not, see
|
Prefer https to http for gnu.org and fsf.org URLs
Also, change sources.redhat.com to sourceware.org.
This patch was automatically generated by running the following shell
script, which uses GNU sed, and which avoids modifying files imported
from upstream:
sed -ri '
s,(http|ftp)(://(.*\.)?(gnu|fsf|sourceware)\.org($|[^.]|\.[^a-z])),https\2,g
s,(http|ftp)(://(.*\.)?)sources\.redhat\.com($|[^.]|\.[^a-z]),https\2sourceware.org\4,g
' \
$(find $(git ls-files) -prune -type f \
! -name '*.po' \
! -name 'ChangeLog*' \
! -path COPYING ! -path COPYING.LIB \
! -path manual/fdl-1.3.texi ! -path manual/lgpl-2.1.texi \
! -path manual/texinfo.tex ! -path scripts/config.guess \
! -path scripts/config.sub ! -path scripts/install-sh \
! -path scripts/mkinstalldirs ! -path scripts/move-if-change \
! -path INSTALL ! -path locale/programs/charmap-kw.h \
! -path po/libc.pot ! -path sysdeps/gnu/errlist.c \
! '(' -name configure \
-execdir test -f configure.ac -o -f configure.in ';' ')' \
! '(' -name preconfigure \
-execdir test -f preconfigure.ac ';' ')' \
-print)
and then by running 'make dist-prepare' to regenerate files built
from the altered files, and then executing the following to cleanup:
chmod a+x sysdeps/unix/sysv/linux/riscv/configure
# Omit irrelevant whitespace and comment-only changes,
# perhaps from a slightly-different Autoconf version.
git checkout -f \
sysdeps/csky/configure \
sysdeps/hppa/configure \
sysdeps/riscv/configure \
sysdeps/unix/sysv/linux/csky/configure
# Omit changes that caused a pre-commit check to fail like this:
# remote: *** error: sysdeps/powerpc/powerpc64/ppc-mcount.S: trailing lines
git checkout -f \
sysdeps/powerpc/powerpc64/ppc-mcount.S \
sysdeps/unix/sysv/linux/s390/s390-64/syscall.S
# Omit change that caused a pre-commit check to fail like this:
# remote: *** error: sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S: last line does not end in newline
git checkout -f sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S
2019-09-07 05:40:42 +00:00
|
|
|
<https://www.gnu.org/licenses/>. */
|
2001-03-16 21:07:22 +00:00
|
|
|
|
|
|
|
#include <errno.h>
|
2014-02-25 14:29:32 +00:00
|
|
|
#include <signal.h>
|
2001-03-16 21:07:22 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2002-08-31 03:21:56 +00:00
|
|
|
#include <string.h>
|
2001-03-16 21:07:22 +00:00
|
|
|
#include <ucontext.h>
|
2008-04-30 18:08:16 +00:00
|
|
|
#include <unistd.h>
|
2001-03-16 21:07:22 +00:00
|
|
|
|
|
|
|
static ucontext_t ctx[3];
|
|
|
|
|
|
|
|
static int was_in_f1;
|
|
|
|
static int was_in_f2;
|
|
|
|
|
2004-12-17 04:05:22 +00:00
|
|
|
static char st2[32768];
|
2001-04-06 21:58:34 +00:00
|
|
|
|
2001-03-16 21:07:22 +00:00
|
|
|
static void
|
2006-03-03 11:51:37 +00:00
|
|
|
f1 (int a0, int a1, int a2, int a3)
|
2001-03-16 21:07:22 +00:00
|
|
|
{
|
2006-03-03 11:51:37 +00:00
|
|
|
printf ("start f1(a0=%x,a1=%x,a2=%x,a3=%x)\n", a0, a1, a2, a3);
|
2001-03-16 21:07:22 +00:00
|
|
|
|
|
|
|
if (a0 != 1 || a1 != 2 || a2 != 3 || a3 != -4)
|
|
|
|
{
|
|
|
|
puts ("arg mismatch");
|
|
|
|
exit (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (swapcontext (&ctx[1], &ctx[2]) != 0)
|
|
|
|
{
|
|
|
|
printf ("%s: swapcontext: %m\n", __FUNCTION__);
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
puts ("finish f1");
|
|
|
|
was_in_f1 = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
f2 (void)
|
|
|
|
{
|
2001-04-06 21:58:34 +00:00
|
|
|
char on_stack[1];
|
|
|
|
|
2001-03-16 21:07:22 +00:00
|
|
|
puts ("start f2");
|
2001-04-06 21:58:34 +00:00
|
|
|
|
|
|
|
printf ("&on_stack=%p\n", on_stack);
|
|
|
|
if (on_stack < st2 || on_stack >= st2 + sizeof (st2))
|
|
|
|
{
|
|
|
|
printf ("%s: memory stack is not where it belongs!", __FUNCTION__);
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
2001-03-16 21:07:22 +00:00
|
|
|
if (swapcontext (&ctx[2], &ctx[1]) != 0)
|
|
|
|
{
|
|
|
|
printf ("%s: swapcontext: %m\n", __FUNCTION__);
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
puts ("finish f2");
|
|
|
|
was_in_f2 = 1;
|
|
|
|
}
|
|
|
|
|
2004-12-17 04:05:22 +00:00
|
|
|
void
|
2014-08-03 12:55:20 +00:00
|
|
|
test_stack (volatile int a, volatile int b,
|
|
|
|
volatile int c, volatile int d)
|
2004-09-02 18:59:24 +00:00
|
|
|
{
|
|
|
|
volatile int e = 5;
|
|
|
|
volatile int f = 6;
|
|
|
|
ucontext_t uc;
|
|
|
|
|
|
|
|
/* Test for cases where getcontext is clobbering the callers
|
|
|
|
stack, including parameters. */
|
2014-08-03 12:55:20 +00:00
|
|
|
getcontext (&uc);
|
2004-12-17 04:05:22 +00:00
|
|
|
|
2004-09-02 18:59:24 +00:00
|
|
|
if (a != 1)
|
|
|
|
{
|
|
|
|
printf ("%s: getcontext clobbers parm a\n", __FUNCTION__);
|
|
|
|
exit (1);
|
|
|
|
}
|
2004-12-17 04:05:22 +00:00
|
|
|
|
2004-09-02 18:59:24 +00:00
|
|
|
if (b != 2)
|
|
|
|
{
|
|
|
|
printf ("%s: getcontext clobbers parm b\n", __FUNCTION__);
|
|
|
|
exit (1);
|
|
|
|
}
|
2004-12-17 04:05:22 +00:00
|
|
|
|
2004-09-02 18:59:24 +00:00
|
|
|
if (c != 3)
|
|
|
|
{
|
|
|
|
printf ("%s: getcontext clobbers parm c\n", __FUNCTION__);
|
|
|
|
exit (1);
|
|
|
|
}
|
2004-12-17 04:05:22 +00:00
|
|
|
|
2004-09-02 18:59:24 +00:00
|
|
|
if (d != 4)
|
|
|
|
{
|
|
|
|
printf ("%s: getcontext clobbers parm d\n", __FUNCTION__);
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (e != 5)
|
|
|
|
{
|
|
|
|
printf ("%s: getcontext clobbers varible e\n", __FUNCTION__);
|
|
|
|
exit (1);
|
|
|
|
}
|
2004-12-17 04:05:22 +00:00
|
|
|
|
2004-09-02 18:59:24 +00:00
|
|
|
if (f != 6)
|
|
|
|
{
|
|
|
|
printf ("%s: getcontext clobbers variable f\n", __FUNCTION__);
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-04-07 20:39:34 +00:00
|
|
|
volatile int global;
|
|
|
|
|
2007-12-03 04:12:05 +00:00
|
|
|
|
|
|
|
static int back_in_main;
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
check_called (void)
|
|
|
|
{
|
|
|
|
if (back_in_main == 0)
|
|
|
|
{
|
2009-12-24 21:22:33 +00:00
|
|
|
puts ("program did not reach main again");
|
2007-12-03 04:12:05 +00:00
|
|
|
_exit (1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-03-16 21:07:22 +00:00
|
|
|
int
|
|
|
|
main (void)
|
|
|
|
{
|
2007-12-03 04:12:05 +00:00
|
|
|
atexit (check_called);
|
|
|
|
|
2004-12-17 04:05:22 +00:00
|
|
|
char st1[32768];
|
2014-02-25 14:29:32 +00:00
|
|
|
stack_t stack_before, stack_after;
|
|
|
|
|
2014-08-03 12:55:20 +00:00
|
|
|
sigaltstack (NULL, &stack_before);
|
2001-03-16 21:07:22 +00:00
|
|
|
|
|
|
|
puts ("making contexts");
|
|
|
|
if (getcontext (&ctx[1]) != 0)
|
|
|
|
{
|
|
|
|
if (errno == ENOSYS)
|
2008-06-25 17:59:16 +00:00
|
|
|
{
|
|
|
|
back_in_main = 1;
|
|
|
|
exit (0);
|
|
|
|
}
|
2001-03-16 21:07:22 +00:00
|
|
|
|
|
|
|
printf ("%s: getcontext: %m\n", __FUNCTION__);
|
|
|
|
exit (1);
|
|
|
|
}
|
2004-12-17 04:05:22 +00:00
|
|
|
|
2004-09-02 18:59:24 +00:00
|
|
|
test_stack (1, 2, 3, 4);
|
2001-04-07 20:39:34 +00:00
|
|
|
|
|
|
|
/* Play some tricks with this context. */
|
|
|
|
if (++global == 1)
|
|
|
|
if (setcontext (&ctx[1]) != 0)
|
|
|
|
{
|
|
|
|
printf ("%s: setcontext: %m\n", __FUNCTION__);
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
if (global != 2)
|
|
|
|
{
|
|
|
|
printf ("%s: 'global' not incremented twice\n", __FUNCTION__);
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
2001-03-16 21:07:22 +00:00
|
|
|
ctx[1].uc_stack.ss_sp = st1;
|
|
|
|
ctx[1].uc_stack.ss_size = sizeof st1;
|
|
|
|
ctx[1].uc_link = &ctx[0];
|
2002-08-31 03:21:56 +00:00
|
|
|
{
|
|
|
|
ucontext_t tempctx = ctx[1];
|
|
|
|
makecontext (&ctx[1], (void (*) (void)) f1, 4, 1, 2, 3, -4);
|
|
|
|
|
|
|
|
/* Without this check, a stub makecontext can make us spin forever. */
|
|
|
|
if (memcmp (&tempctx, &ctx[1], sizeof ctx[1]) == 0)
|
|
|
|
{
|
|
|
|
puts ("makecontext was a no-op, presuming not implemented");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2001-03-16 21:07:22 +00:00
|
|
|
|
|
|
|
if (getcontext (&ctx[2]) != 0)
|
|
|
|
{
|
|
|
|
printf ("%s: second getcontext: %m\n", __FUNCTION__);
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
ctx[2].uc_stack.ss_sp = st2;
|
|
|
|
ctx[2].uc_stack.ss_size = sizeof st2;
|
|
|
|
ctx[2].uc_link = &ctx[1];
|
|
|
|
makecontext (&ctx[2], f2, 0);
|
|
|
|
|
|
|
|
puts ("swapping contexts");
|
|
|
|
if (swapcontext (&ctx[0], &ctx[2]) != 0)
|
|
|
|
{
|
|
|
|
printf ("%s: swapcontext: %m\n", __FUNCTION__);
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
puts ("back at main program");
|
2007-12-03 04:12:05 +00:00
|
|
|
back_in_main = 1;
|
2001-03-16 21:07:22 +00:00
|
|
|
|
2014-08-03 12:55:20 +00:00
|
|
|
sigaltstack (NULL, &stack_after);
|
2014-02-25 14:29:32 +00:00
|
|
|
|
2001-03-16 21:07:22 +00:00
|
|
|
if (was_in_f1 == 0)
|
|
|
|
{
|
|
|
|
puts ("didn't reach f1");
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
if (was_in_f2 == 0)
|
|
|
|
{
|
|
|
|
puts ("didn't reach f2");
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
2014-02-25 14:29:32 +00:00
|
|
|
/* 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);
|
|
|
|
}
|
|
|
|
|
2001-03-16 21:07:22 +00:00
|
|
|
puts ("test succeeded");
|
|
|
|
return 0;
|
|
|
|
}
|