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 memmove(sp, &argc+1, argc*sizeof(int));
11 *--sp = 0; /* return address */
12 ucp->uc_mcontext.mc_eip = (long)func;
13 ucp->uc_mcontext.mc_esp = (int)sp;
14 }
16 extern int getmcontext(mcontext_t*);
17 extern int setmcontext(mcontext_t*);
19 int
20 getcontext(ucontext_t *uc)
21 {
22 return getmcontext(&uc->uc_mcontext);
23 }
25 void
26 setcontext(ucontext_t *uc)
27 {
28 setmcontext(&uc->uc_mcontext);
29 }
31 int
32 swapcontext(ucontext_t *oucp, ucontext_t *ucp)
33 {
34 if(getcontext(oucp) == 0)
35 setcontext(ucp);
36 return 0;
37 }