Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Reorganize directories.
[simgrid.git] / buildtools / CPACK / prog_test / prog_AC_CHECK_MCSC.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <ucontext.h>
4
5 void child(void);
6
7 ucontext_t uc_child;
8 ucontext_t uc_main;
9
10
11
12 void child(void)
13 {
14     if (swapcontext(&uc_child, &uc_main) != 0)
15         exit(2);
16 }
17
18 int main(int argc, char *argv[])
19 {
20     FILE *fp;
21     void *stack;
22
23     /* the default is that it fails */
24     if ((fp = fopen("conftestval", "w")) == NULL)
25         exit(3);
26     fprintf(fp, "no\n");
27     fclose(fp);
28
29     /* configure a child user-space context */
30     if ((stack = malloc(64*1024)) == NULL)
31         exit(4);
32     if (getcontext(&uc_child) != 0)
33         exit(5);
34     uc_child.uc_link = NULL;
35     uc_child.uc_stack.ss_sp = (char *)stack+(32*1024);
36     uc_child.uc_stack.ss_size = 32*1024;
37     uc_child.uc_stack.ss_flags = 0;
38     makecontext(&uc_child, child, 0);
39
40     /* switch into the user context */
41     if (swapcontext(&uc_main, &uc_child) != 0)
42         exit(6);
43
44     /* Fine, child came home */
45     if ((fp = fopen("conftestval", "w")) == NULL)
46         exit(7);
47     fprintf(fp, "yes\n");
48     fclose(fp);
49
50     /* die successfully */
51     exit(0);
52         return 1;
53 }