diff options
author | Ulrich Drepper <drepper@redhat.com> | 2001-03-16 21:07:22 +0000 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 2001-03-16 21:07:22 +0000 |
commit | aeba9785a6e2e8dca120bb0b62b74ea1eda0a4a8 (patch) | |
tree | 8438c4d6081766a1ede6c89328dfbcd389dbff82 /stdlib/tst-setcontext.c | |
parent | b8a8413c6f7970bc4d5659791c3b3670cc037578 (diff) | |
download | glibc-aeba9785a6e2e8dca120bb0b62b74ea1eda0a4a8.zip glibc-aeba9785a6e2e8dca120bb0b62b74ea1eda0a4a8.tar.gz glibc-aeba9785a6e2e8dca120bb0b62b74ea1eda0a4a8.tar.bz2 |
Update.
2001-03-16 David Mosberger <davidm@hpl.hp.com>
* sysdeps/unix/sysv/linux/ia64/bits/sigcontext.h (struct sigcontext):
Drop hack that was needed for 2.1.1 kernel headers.
* sysdeps/unix/sysv/linux/ia64/ucontext_i.h: New file.
* sysdeps/unix/sysv/linux/ia64/sys/ucontext.h: Rewrite to make it
overlay with kernel's "struct sigcontext".
* sysdeps/unix/sysv/linux/ia64/Makefile (sysdep_headers): Add
sys/rse.h for "misc" subdir.
(sysdep_routines): Add __start_context for "stdlib" subdir.
* sysdeps/unix/sysv/linux/ia64/sys/rse.h: New file (based on
kernel file of the same name).
* stdlib/Makefile (tests): Add tst-setcontext.
* stdlib/tst-setcontext.c: New file (based on a sample program by
Uli Drepper).
* sysdeps/unix/sysv/linux/ia64/setcontext.S: New file.
* sysdeps/unix/sysv/linux/ia64/getcontext.S: New file.
* sysdeps/unix/sysv/linux/ia64/__start_context.S: New file.
* sysdeps/unix/sysv/linux/ia64/makecontext.c: New file.
* sysdeps/unix/sysv/linux/ia64/__longjmp.S (__longjmp): Use extr.u
instead of shift & and.
Diffstat (limited to 'stdlib/tst-setcontext.c')
-rw-r--r-- | stdlib/tst-setcontext.c | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/stdlib/tst-setcontext.c b/stdlib/tst-setcontext.c new file mode 100644 index 0000000..6ee1b51 --- /dev/null +++ b/stdlib/tst-setcontext.c @@ -0,0 +1,113 @@ +/* Copyright (C) 2001 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#include <errno.h> +#include <stdio.h> +#include <stdlib.h> +#include <ucontext.h> + +static ucontext_t ctx[3]; + +static int was_in_f1; +static int was_in_f2; + +static void +f1 (long a0, long a1, long a2, long a3) +{ + printf ("start f1(a0=%lx,a1=%lx,a2=%lx,a3=%lx)\n", a0, a1, a2, a3); + + 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) +{ + puts ("start f2"); + if (swapcontext (&ctx[2], &ctx[1]) != 0) + { + printf ("%s: swapcontext: %m\n", __FUNCTION__); + exit (1); + } + puts ("finish f2"); + was_in_f2 = 1; +} + +int +main (void) +{ + char st1[8192]; + char st2[8192]; + + puts ("making contexts"); + if (getcontext (&ctx[1]) != 0) + { + if (errno == ENOSYS) + exit (0); + + printf ("%s: getcontext: %m\n", __FUNCTION__); + exit (1); + } + ctx[1].uc_stack.ss_sp = st1; + ctx[1].uc_stack.ss_size = sizeof st1; + ctx[1].uc_link = &ctx[0]; + makecontext (&ctx[1], (void (*) (void)) f1, 4, 1, 2, 3, -4); + + 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"); + + if (was_in_f1 == 0) + { + puts ("didn't reach f1"); + exit (1); + } + if (was_in_f2 == 0) + { + puts ("didn't reach f2"); + exit (1); + } + + puts ("test succeeded"); + return 0; +} |