1 /* Copyright (c) 2010, 2014. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
14 static void child(void)
16 if (swapcontext(&uc_child, &uc_main) != 0)
20 int main(int argc, char *argv[])
25 /* the default is that it fails */
26 if ((fp = fopen("conftestval", "w")) == NULL)
31 /* configure a child user-space context */
32 if ((stack = malloc(64 * 1024)) == NULL)
34 if (getcontext(&uc_child) != 0)
36 uc_child.uc_link = NULL;
37 uc_child.uc_stack.ss_sp = (char *) stack + (32 * 1024);
38 uc_child.uc_stack.ss_size = 32 * 1024;
39 uc_child.uc_stack.ss_flags = 0;
40 makecontext(&uc_child, child, 0);
42 /* switch into the user context */
43 if (swapcontext(&uc_main, &uc_child) != 0)
46 /* Fine, child came home */
47 if ((fp = fopen("conftestval", "w")) == NULL)
52 /* die successfully */