1 // obtained from https://www.ibm.com/support/knowledgecenter/en/SSLTBW_2.3.0/com.ibm.zos.v2r3.bpxbd00/rswctx.htm
8 #define STACK_SIZE 2097152+16384 /* large enough value for AMODE 64 */
10 ucontext_t fcontext
,mcontext
;
15 printf("function called with value %d\n",arg
);
17 printf("function returning to main\n");
18 setcontext(&mcontext
);
25 getcontext(&fcontext
);
26 if ((fcontext
.uc_stack
.ss_sp
= (char *) malloc(STACK_SIZE
)) != NULL
)
28 fcontext
.uc_stack
.ss_size
= STACK_SIZE
;
29 fcontext
.uc_stack
.ss_flags
= 0;
30 fcontext
.uc_sigmask
.__bits
[3] = -1;
32 makecontext(&fcontext
,(void (*)(void))func
,1,value
);
35 perror("Error reported by makecontext()");
36 return -1; /* Error occurred exit */
41 perror("not enough storage for stack");
45 printf("context has been built\n");
46 swapcontext(&mcontext
,&fcontext
);
50 perror("incorrect return from swapcontext");
55 printf("returned from function\n");
57 free(fcontext
.uc_stack
.ss_sp
);