|
Packit |
6c4009 |
/* Copyright (C) 2008-2018 Free Software Foundation, Inc.
|
|
Packit |
6c4009 |
This file is part of the GNU C Library.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is free software; you can redistribute it and/or
|
|
Packit |
6c4009 |
modify it under the terms of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License as published by the Free Software Foundation; either
|
|
Packit |
6c4009 |
version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is distributed in the hope that it will be useful,
|
|
Packit |
6c4009 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
6c4009 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
6c4009 |
Lesser General Public License for more details.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
You should have received a copy of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License along with the GNU C Library; if not, see
|
|
Packit |
6c4009 |
<http://www.gnu.org/licenses/>. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include <errno.h>
|
|
Packit |
6c4009 |
#include <stdlib.h>
|
|
Packit |
6c4009 |
#include <stdio.h>
|
|
Packit |
6c4009 |
#include <string.h>
|
|
Packit |
6c4009 |
#include <ucontext.h>
|
|
Packit |
6c4009 |
#include <tst-stack-align.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
ucontext_t ucp, ucp2;
|
|
Packit |
6c4009 |
char st1[262144] __attribute__((aligned (16)));
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
void
|
|
Packit |
6c4009 |
cf (int i, int j)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
if (i != 78 || j != 274)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
printf ("i %d j %d\n", i, j);
|
|
Packit |
6c4009 |
exit (1);
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
else if (TEST_STACK_ALIGN ())
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
puts ("insufficiently aligned stack");
|
|
Packit |
6c4009 |
exit (2);
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
int
|
|
Packit |
6c4009 |
do_test (void)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
for (size_t j = 32; j < 64; j += sizeof (long))
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
if (getcontext (&ucp) != 0)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
if (errno == ENOSYS)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
puts ("context handling not supported");
|
|
Packit |
6c4009 |
return 0;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
puts ("getcontext failed");
|
|
Packit |
6c4009 |
return 1;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
ucp.uc_link = &ucp;;
|
|
Packit |
6c4009 |
ucp.uc_stack.ss_sp = st1;
|
|
Packit |
6c4009 |
ucp.uc_stack.ss_size = sizeof (st1) - j;
|
|
Packit |
6c4009 |
memset (&st1[sizeof (st1) - j], 0x55, j);
|
|
Packit |
6c4009 |
makecontext (&ucp, (void (*) (void)) cf, 2, 78, 274);
|
|
Packit |
6c4009 |
if (swapcontext (&ucp2, &ucp) != 0)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
puts ("setcontext failed");
|
|
Packit |
6c4009 |
return 1;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
for (size_t i = j; i > 0; i--)
|
|
Packit |
6c4009 |
if (st1[sizeof (st1) - j + i - 1] != 0x55)
|
|
Packit |
6c4009 |
{ printf ("fail %zd %zd\n", i, j); break; }
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
return 0;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#define TEST_FUNCTION do_test ()
|
|
Packit |
6c4009 |
#include "../test-skeleton.c"
|