Run ctfconvert/ctfmerge for all objects
[openafs.git] / src / cf / ucontext.m4
1 dnl Test getcontext() and makecontext() to ensure that we are able to
2 dnl copy the current user context, modify it with our own private stack
3 dnl and return to the original user context.
4 dnl
5 AC_DEFUN([OPENAFS_WORKING_UCONTEXT],[
6   AC_MSG_CHECKING([if user context manipulation is complete])
7   AC_RUN_IFELSE(
8     [AC_LANG_SOURCE(
9       [[
10 #include <stdio.h>
11 #include <stdlib.h>
12 #ifdef HAVE_UCONTEXT_H
13 #include <ucontext.h>
14 #endif
15
16 #define STACK_SIZE 16384
17
18 static ucontext_t main_context, thread_context;
19 static char *alt_stack;
20
21 static void
22 thread(void)
23 {
24         unsigned long stack_ptr;
25         unsigned long offset;
26
27         offset = (unsigned long) &stack_ptr - (unsigned long) alt_stack;
28         if (offset > STACK_SIZE)
29                 exit(EXIT_FAILURE);
30         swapcontext(&thread_context, &main_context);
31         /* should never get here */
32         exit(EXIT_FAILURE);
33 }
34
35 int
36 main(int argc, char **argv)
37 {
38         if (getcontext(&thread_context) == -1)
39                 exit(EXIT_FAILURE);
40         alt_stack = malloc(STACK_SIZE);
41         if (!alt_stack)
42                 exit(EXIT_FAILURE);
43         thread_context.uc_stack.ss_sp = alt_stack;
44         thread_context.uc_stack.ss_size = STACK_SIZE;
45         makecontext(&thread_context, thread, 0);
46
47         if (swapcontext(&main_context, &thread_context) == -1)
48                 exit(EXIT_FAILURE);
49
50         free(alt_stack);
51         exit(EXIT_SUCCESS);
52 }
53       ]])],
54       [AC_MSG_RESULT(yes)
55        AC_DEFINE(HAVE_WORKING_SWAPCONTEXT, 1,
56          user context manipulation is complete)],
57       [AC_MSG_RESULT(no)],
58       [])])