]>
Commit | Line | Data |
---|---|---|
148e12ed UD |
1 | /* Copyright (C) 2008 Free Software Foundation, Inc. |
2 | This file is part of the GNU C Library. | |
3 | ||
4 | The GNU C Library is free software; you can redistribute it and/or | |
5 | modify it under the terms of the GNU Lesser General Public | |
6 | License as published by the Free Software Foundation; either | |
7 | version 2.1 of the License, or (at your option) any later version. | |
8 | ||
9 | The GNU C Library is distributed in the hope that it will be useful, | |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
12 | Lesser General Public License for more details. | |
13 | ||
14 | You should have received a copy of the GNU Lesser General Public | |
15 | License along with the GNU C Library; if not, write to the Free | |
16 | Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | |
17 | 02111-1307 USA. */ | |
18 | ||
19 | #include <errno.h> | |
20 | #include <stdlib.h> | |
21 | #include <stdio.h> | |
22 | #include <string.h> | |
23 | #include <ucontext.h> | |
24 | #include <tst-stack-align.h> | |
25 | ||
26 | ucontext_t ucp, ucp2; | |
27 | char st1[262144] __attribute__((aligned (16))); | |
28 | ||
29 | void | |
30 | cf (int i, int j) | |
31 | { | |
32 | if (i != 78 || j != 274) | |
33 | { | |
34 | printf ("i %d j %d\n", i, j); | |
35 | exit (1); | |
36 | } | |
37 | else if (TEST_STACK_ALIGN ()) | |
38 | { | |
39 | puts ("insufficiently aligned stack"); | |
40 | exit (2); | |
41 | } | |
42 | } | |
43 | ||
44 | int | |
45 | do_test (void) | |
46 | { | |
47 | for (size_t j = 32; j < 64; j += sizeof (long)) | |
48 | { | |
49 | if (getcontext (&ucp) != 0) | |
50 | { | |
51 | if (errno == ENOSYS) | |
52 | { | |
53 | puts ("context handling not supported"); | |
54 | return 0; | |
55 | } | |
56 | ||
57 | puts ("getcontext failed"); | |
58 | return 1; | |
59 | } | |
60 | ucp.uc_link = &ucp2; | |
61 | ucp.uc_stack.ss_sp = st1; | |
62 | ucp.uc_stack.ss_size = sizeof (st1) - j; | |
63 | memset (&st1[sizeof (st1) - j], 0x55, j); | |
64 | makecontext (&ucp, (void (*) (void)) cf, 2, 78, 274); | |
65 | if (swapcontext (&ucp2, &ucp) != 0) | |
66 | { | |
67 | puts ("setcontext failed"); | |
68 | return 1; | |
69 | } | |
70 | ||
71 | for (size_t i = j; i > 0; i--) | |
72 | if (st1[sizeof (st1) - j + i - 1] != 0x55) | |
73 | { printf ("fail %zd %zd\n", i, j); break; } | |
74 | } | |
75 | ||
76 | return 0; | |
77 | } | |
78 | ||
79 | #define TEST_FUNCTION do_test () | |
80 | #include "../test-skeleton.c" |