1 #include "threadimpl.h"
4 makecontext(ucontext_t *uc, void (*fn)(void), int argc, ...)
9 //fprint(2, "makecontext %d\n", argc);
11 sysfatal("libthread: makecontext misused");
13 uc->mc.di = va_arg(arg, uint);
14 uc->mc.si = va_arg(arg, uint);
15 //fprint(2, "%ux %ux\n", uc->mc.di, uc->mc.si);
18 sp = (uintptr*)((char*)uc->uc_stack.ss_sp+uc->uc_stack.ss_size);
20 * Stack pointer at call instruction (before return address
21 * gets pushed) must be 16-byte aligned.
25 while((uintptr)sp%16 != 0)
27 *--sp = 0; // fn's return address
28 *--sp = (uintptr)fn; // return address of setcontext
29 uc->mc.sp = (uintptr)sp;
33 swapcontext(ucontext_t *oucp, ucontext_t *ucp)
35 if(getcontext(oucp) == 0)