Patrick Welche <prlw1@cam.ac.uk>
[netbsd-mini2440.git] / regress / lib / libc / context / context.c
blob96397857a404c9e65d9dcc7a62b133babf733bb0
1 /* $NetBSD: context.c,v 1.2 2004/03/01 12:04:18 drochner Exp $ */
3 #include <malloc.h>
4 #include <ucontext.h>
5 #include <stdarg.h>
6 #include <err.h>
8 #define STACKSZ (10*1024)
9 #define DEPTH 3
11 int calls;
13 void
14 run(int n, ...)
16 va_list va;
17 int i, ia;
19 if (n != DEPTH - calls - 1)
20 exit (1);
22 va_start(va, n);
23 for (i = 0; i < 9; i++) {
24 ia = va_arg(va, int);
25 if (ia != i)
26 errx(2, "arg[%d]=%d", i, ia);
28 va_end(va);
29 calls++;
32 main()
34 ucontext_t uc[DEPTH];
35 int i, res;
37 for (i = 0; i < DEPTH; i++) {
38 res = getcontext(&uc[i]);
39 if (res)
40 err(1, "getcontext");
41 uc[i].uc_stack.ss_sp = malloc(STACKSZ);
42 uc[i].uc_stack.ss_size = STACKSZ;
43 if (i > 0)
44 uc[i].uc_link = &uc[i - 1];
45 makecontext(&uc[i], (void *)run, 10, i,
46 0, 1, 2, 3, 4, 5, 6, 7, 8);
48 res = setcontext(&uc[DEPTH-1]);
49 if (res)
50 err(1, "setcontext");
51 /* NOTREACHED */
52 return (3);