1 /* Copyright (C) 2001,02 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, Inc., 59 Temple Place, Suite 330, Boston, MA
25 static ucontext_t ctx
[3];
30 static char st2
[8192];
33 f1 (long a0
, long a1
, long a2
, long a3
)
35 printf ("start f1(a0=%lx,a1=%lx,a2=%lx,a3=%lx)\n", a0
, a1
, a2
, a3
);
37 if (a0
!= 1 || a1
!= 2 || a2
!= 3 || a3
!= -4)
39 puts ("arg mismatch");
43 if (swapcontext (&ctx
[1], &ctx
[2]) != 0)
45 printf ("%s: swapcontext: %m\n", __FUNCTION__
);
59 printf ("&on_stack=%p\n", on_stack
);
60 if (on_stack
< st2
|| on_stack
>= st2
+ sizeof (st2
))
62 printf ("%s: memory stack is not where it belongs!", __FUNCTION__
);
66 if (swapcontext (&ctx
[2], &ctx
[1]) != 0)
68 printf ("%s: swapcontext: %m\n", __FUNCTION__
);
82 puts ("making contexts");
83 if (getcontext (&ctx
[1]) != 0)
88 printf ("%s: getcontext: %m\n", __FUNCTION__
);
92 /* Play some tricks with this context. */
94 if (setcontext (&ctx
[1]) != 0)
96 printf ("%s: setcontext: %m\n", __FUNCTION__
);
101 printf ("%s: 'global' not incremented twice\n", __FUNCTION__
);
105 ctx
[1].uc_stack
.ss_sp
= st1
;
106 ctx
[1].uc_stack
.ss_size
= sizeof st1
;
107 ctx
[1].uc_link
= &ctx
[0];
109 ucontext_t tempctx
= ctx
[1];
110 makecontext (&ctx
[1], (void (*) (void)) f1
, 4, 1, 2, 3, -4);
112 /* Without this check, a stub makecontext can make us spin forever. */
113 if (memcmp (&tempctx
, &ctx
[1], sizeof ctx
[1]) == 0)
115 puts ("makecontext was a no-op, presuming not implemented");
120 if (getcontext (&ctx
[2]) != 0)
122 printf ("%s: second getcontext: %m\n", __FUNCTION__
);
125 ctx
[2].uc_stack
.ss_sp
= st2
;
126 ctx
[2].uc_stack
.ss_size
= sizeof st2
;
127 ctx
[2].uc_link
= &ctx
[1];
128 makecontext (&ctx
[2], f2
, 0);
130 puts ("swapping contexts");
131 if (swapcontext (&ctx
[0], &ctx
[2]) != 0)
133 printf ("%s: swapcontext: %m\n", __FUNCTION__
);
136 puts ("back at main program");
140 puts ("didn't reach f1");
145 puts ("didn't reach f2");
149 puts ("test succeeded");