Blob


1 #include "threadimpl.h"
3 void
4 makecontext(ucontext_t *ucp, void (*func)(void), int argc, ...)
5 {
6 int n;
7 int *sp;
9 sp = (int*)ucp->uc_stack.ss_sp+ucp->uc_stack.ss_size/4;
10 sp -= argc;
11 /*
12 * Stack pointer at call instruction (before return address
13 * gets pushed) must be 16-byte aligned.
14 */
15 if((uintptr)sp%4)
16 abort();
17 while((uintptr)sp%16)
18 sp--;
19 memmove(sp, &argc+1, argc*sizeof(int));
20 *--sp = 0; /* return address */
21 ucp->uc_mcontext.mc_eip = (long)func;
22 ucp->uc_mcontext.mc_esp = (int)sp;
23 }
25 int
26 swapcontext(ucontext_t *oucp, ucontext_t *ucp)
27 {
28 if(getcontext(oucp) == 0)
29 setcontext(ucp);
30 return 0;
31 }