• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Test of correct simulation for uc->uc_link. */
2 
3 #include <assert.h>
4 #include <stdio.h>
5 #include <ucontext.h>
6 
print_value(int value)7 static void print_value(int value)
8 {
9    printf("Value is %d.\n", value);
10 }
11 
main(void)12 int main(void)
13 {
14    ucontext_t uc;
15    char stack[8096];
16    volatile int done = 0;
17 
18    /* Get current context. */
19    getcontext(&uc);
20    if (done) {
21       /* Execution resumes here when print_value() returns. */
22       return 0;
23    }
24    done = 1;
25 
26    /* Setup the stack. */
27    uc.uc_stack.ss_sp = stack;
28    uc.uc_stack.ss_size = sizeof(stack);
29 
30    /* Call print_value(). */
31    makecontext(&uc, print_value, 1, 42);
32    setcontext(&uc);
33 
34    /* This code should not be reached. */
35    assert(0);
36    return 0;
37 }
38 
39