1 41b3e8b9 2020-01-20 rsc #include "threadimpl.h"
4 41b3e8b9 2020-01-20 rsc makecontext(ucontext_t *uc, void (*fn)(void), int argc, ...)
10 41b3e8b9 2020-01-20 rsc sysfatal("libthread: makecontext misused");
11 41b3e8b9 2020-01-20 rsc va_start(arg, argc);
12 41b3e8b9 2020-01-20 rsc uc->mc.di = va_arg(arg, uint);
13 41b3e8b9 2020-01-20 rsc uc->mc.si = va_arg(arg, uint);
16 41b3e8b9 2020-01-20 rsc sp = USPALIGN(uc, 16);
17 41b3e8b9 2020-01-20 rsc *--sp = 0; // fn's return address
18 41b3e8b9 2020-01-20 rsc *--sp = (uintptr)fn; // return address of setcontext
19 41b3e8b9 2020-01-20 rsc uc->mc.sp = (uintptr)sp;
23 41b3e8b9 2020-01-20 rsc swapcontext(ucontext_t *oucp, ucontext_t *ucp)
25 41b3e8b9 2020-01-20 rsc if(getcontext(oucp) == 0)
26 41b3e8b9 2020-01-20 rsc setcontext(ucp);