Blob


1 #include "threadimpl.h"
3 #include "BSD.c"
5 /*
6 * FreeBSD 4 and earlier needs the context functions.
7 */
8 void
9 makecontext(ucontext_t *ucp, void (*func)(void), int argc, ...)
10 {
11 int *sp;
13 sp = (int*)ucp->uc_stack.ss_sp+ucp->uc_stack.ss_size/4;
14 sp -= argc;
15 memmove(sp, &argc+1, argc*sizeof(int));
16 *--sp = 0; /* return address */
17 ucp->uc_mcontext.mc_eip = (long)func;
18 ucp->uc_mcontext.mc_esp = (int)sp;
19 }
21 extern int getmcontext(mcontext_t*);
22 extern int setmcontext(mcontext_t*);
24 int
25 getcontext(ucontext_t *uc)
26 {
27 return getmcontext(&uc->uc_mcontext);
28 }
30 void
31 setcontext(ucontext_t *uc)
32 {
33 setmcontext(&uc->uc_mcontext);
34 }
36 int
37 swapcontext(ucontext_t *oucp, ucontext_t *ucp)
38 {
39 if(getcontext(oucp) == 0)
40 setcontext(ucp);
41 return 0;
42 }