1 /* Copyright (c) 2010-2023. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
7 #define _XOPEN_SOURCE 700
14 unsigned char *stack[64 * 1024];
18 static void child(void)
20 /* switch back to the main context */
21 if (swapcontext(&uc_child, &uc_main) != 0)
25 int main(int argc, char *argv[])
27 /* configure a child user-space context */
28 if (getcontext(&uc_child) != 0)
30 uc_child.uc_link = NULL;
31 uc_child.uc_stack.ss_sp = stack + (32 * 1024);
32 uc_child.uc_stack.ss_size = 32 * 1024;
33 uc_child.uc_stack.ss_flags = 0;
34 makecontext(&uc_child, child, 0);
36 /* switch into the user context */
37 if (swapcontext(&uc_main, &uc_child) != 0)
40 /* Fine, child came home */
43 /* die successfully */