rsc | 31cf0ab | 2004-12-28 03:50:11 +0000 | [diff] [blame] | 1 | #include "threadimpl.h" |
| 2 | |
rsc | cea1000 | 2005-05-01 18:38:12 +0000 | [diff] [blame] | 3 | #include "BSD.c" |
rsc | 1d2533d | 2004-12-28 22:36:24 +0000 | [diff] [blame] | 4 | |
rsc | d54ead7 | 2004-12-28 04:20:39 +0000 | [diff] [blame] | 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; |
| 12 | |
| 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 | } |
| 20 | |
rsc | d54ead7 | 2004-12-28 04:20:39 +0000 | [diff] [blame] | 21 | int |
| 22 | swapcontext(ucontext_t *oucp, ucontext_t *ucp) |
| 23 | { |
| 24 | if(getcontext(oucp) == 0) |
| 25 | setcontext(ucp); |
| 26 | return 0; |
| 27 | } |
| 28 | |
rsc | b20b42b | 2005-08-10 18:48:31 +0000 | [diff] [blame] | 29 | void |
| 30 | _pthreadinit(void) |
| 31 | { |
| 32 | __isthreaded = 1; |
| 33 | signal(SIGUSR2, sigusr2handler); |
| 34 | } |