Blob


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