getdents64 fallback d_type support
[glibc.git] / stdlib / tst-makecontext3.c
bloba44169ae363faadc8f1e6829363ab75dd3a40335
1 /* Copyright (C) 2001,2002,2004,2006,2009 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
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.
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.
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, 51 Franklin Street - Fifth Floor, Boston, MA
17 02110-1301, USA. */
19 #include <errno.h>
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include <ucontext.h>
24 #include <unistd.h>
26 static ucontext_t ctx[3];
28 static int was_in_f1;
29 static int was_in_f2;
31 static char st2[32768];
33 static volatile int flag;
35 static void
36 f1 (int a00, int a01, int a02, int a03, int a04, int a05, int a06, int a07,
37 int a08, int a09, int a10, int a11, int a12, int a13, int a14, int a15,
38 int a16, int a17, int a18, int a19, int a20, int a21, int a22, int a23,
39 int a24, int a25, int a26, int a27, int a28, int a29, int a30, int a31,
40 int a32)
42 printf ("start f1(a00=%08x,a01=%08x,a02=%08x,a03=%08x,\n"
43 " a04=%08x,a05=%08x,a06=%08x,a07=%08x,\n"
44 " a08=%08x,a09=%08x,a10=%08x,a11=%08x,\n"
45 " a12=%08x,a13=%08x,a14=%08x,a15=%08x,\n"
46 " a16=%08x,a17=%08x,a18=%08x,a19=%08x,\n"
47 " a20=%08x,a21=%08x,a22=%08x,a23=%08x,\n"
48 " a24=%08x,a25=%08x,a26=%08x,a27=%08x,\n"
49 " a28=%08x,a29=%08x,a30=%08x,a31=%08x,\n"
50 " a32=%08x) [%d]\n",
51 a00, a01, a02, a03, a04, a05, a06, a07,
52 a08, a09, a10, a11, a12, a13, a14, a15,
53 a16, a17, a18, a19, a20, a21, a22, a23,
54 a24, a25, a26, a27, a28, a29, a30, a31,
55 a32, flag);
57 if (a00 != (0x00000001 << flag) || a01 != (0x00000004 << flag)
58 || a02 != (0x00000012 << flag) || a03 != (0x00000048 << flag)
59 || a04 != (0x00000123 << flag) || a05 != (0x0000048d << flag)
60 || a06 != (0x00001234 << flag) || a07 != (0x000048d1 << flag)
61 || a08 != (0x00012345 << flag) || a09 != (0x00048d15 << flag)
62 || a10 != (0x00123456 << flag) || a11 != (0x0048d159 << flag)
63 || a12 != (0x01234567 << flag) || a13 != (0x048d159e << flag)
64 || a14 != (0x12345678 << flag) || a15 != (0x48d159e2 << flag)
65 || a16 != (0x23456789 << flag) || a17 != (0x8d159e26 << flag)
66 || a18 != (0x3456789a << flag) || a19 != (0xd159e26a << flag)
67 || a20 != (0x456789ab << flag) || a21 != (0x159e26af << flag)
68 || a22 != (0x56789abc << flag) || a23 != (0x59e26af3 << flag)
69 || a24 != (0x6789abcd << flag) || a25 != (0x9e26af37 << flag)
70 || a26 != (0x789abcde << flag) || a27 != (0xe26af37b << flag)
71 || a28 != (0x89abcdef << flag) || a29 != (0x26af37bc << flag)
72 || a30 != (0x9abcdef0 << flag) || a31 != (0x6af37bc3 << flag)
73 || a32 != (0xabcdef0f << flag))
75 puts ("arg mismatch");
76 exit (-1);
79 if (flag && swapcontext (&ctx[1], &ctx[2]) != 0)
81 printf ("%s: swapcontext: %m\n", __FUNCTION__);
82 exit (1);
84 printf ("finish f1 [%d]\n", flag);
85 flag++;
86 was_in_f1++;
89 static void
90 f2 (void)
92 puts ("start f2");
93 if (swapcontext (&ctx[2], &ctx[1]) != 0)
95 printf ("%s: swapcontext: %m\n", __FUNCTION__);
96 exit (1);
98 puts ("finish f2");
99 was_in_f2 = 1;
102 volatile int global;
105 static int back_in_main;
108 static void
109 check_called (void)
111 if (back_in_main == 0)
113 puts ("program did not reach main again");
114 _exit (1);
120 main (void)
122 atexit (check_called);
124 char st1[32768];
126 puts ("making contexts");
127 if (getcontext (&ctx[0]) != 0)
129 if (errno == ENOSYS)
131 back_in_main = 1;
132 exit (0);
135 printf ("%s: getcontext: %m\n", __FUNCTION__);
136 exit (1);
139 if (getcontext (&ctx[1]) != 0)
141 printf ("%s: getcontext: %m\n", __FUNCTION__);
142 exit (1);
145 ctx[1].uc_stack.ss_sp = st1;
146 ctx[1].uc_stack.ss_size = sizeof st1;
147 ctx[1].uc_link = &ctx[0];
148 errno = 0;
149 makecontext (&ctx[1], (void (*) (void)) f1, 33,
150 0x00000001 << flag, 0x00000004 << flag,
151 0x00000012 << flag, 0x00000048 << flag,
152 0x00000123 << flag, 0x0000048d << flag,
153 0x00001234 << flag, 0x000048d1 << flag,
154 0x00012345 << flag, 0x00048d15 << flag,
155 0x00123456 << flag, 0x0048d159 << flag,
156 0x01234567 << flag, 0x048d159e << flag,
157 0x12345678 << flag, 0x48d159e2 << flag,
158 0x23456789 << flag, 0x8d159e26 << flag,
159 0x3456789a << flag, 0xd159e26a << flag,
160 0x456789ab << flag, 0x159e26af << flag,
161 0x56789abc << flag, 0x59e26af3 << flag,
162 0x6789abcd << flag, 0x9e26af37 << flag,
163 0x789abcde << flag, 0xe26af37b << flag,
164 0x89abcdef << flag, 0x26af37bc << flag,
165 0x9abcdef0 << flag, 0x6af37bc3 << flag,
166 0xabcdef0f << flag);
168 /* Without this check, a stub makecontext can make us spin forever. */
169 if (errno == ENOSYS)
171 puts ("makecontext not implemented");
172 back_in_main = 1;
173 return 0;
176 /* Play some tricks with this context. */
177 if (++global == 1)
178 if (setcontext (&ctx[1]) != 0)
180 printf ("%s: setcontext: %m\n", __FUNCTION__);
181 exit (1);
183 if (global != 2)
185 printf ("%s: 'global' not incremented twice\n", __FUNCTION__);
186 exit (1);
189 if (getcontext (&ctx[2]) != 0)
191 printf ("%s: second getcontext: %m\n", __FUNCTION__);
192 exit (1);
194 ctx[2].uc_stack.ss_sp = st2;
195 ctx[2].uc_stack.ss_size = sizeof st2;
196 ctx[2].uc_link = &ctx[1];
197 makecontext (&ctx[2], f2, 0);
199 puts ("swapping contexts");
200 if (swapcontext (&ctx[0], &ctx[2]) != 0)
202 printf ("%s: swapcontext: %m\n", __FUNCTION__);
203 exit (1);
205 puts ("back at main program");
206 back_in_main = 1;
208 if (was_in_f1 < 2)
210 puts ("didn't reach f1 twice");
211 exit (1);
213 if (was_in_f2 == 0)
215 puts ("didn't reach f2");
216 exit (1);
219 puts ("test succeeded");
220 return 0;