Blob


1 #include "ucontext.c"
3 #ifdef OLD
5 #include "threadimpl.h"
6 /*
7 * To use this you need some patches to Valgrind that
8 * let it help out with detecting stack overflow.
9 */
10 #ifdef USEVALGRIND
11 #include <valgrind/memcheck.h>
12 #endif
14 static void
15 launcher386(void (*f)(void *arg), void *arg)
16 {
17 Proc *p;
18 Thread *t;
20 p = _threadgetproc();
21 t = p->thread;
22 _threadstacklimit(t->stk, t->stk+t->stksize);
24 (*f)(arg);
25 threadexits(nil);
26 }
28 void
29 _threadinitstack(Thread *t, void (*f)(void*), void *arg)
30 {
31 ulong *tos;
33 tos = (ulong*)&t->stk[t->stksize&~7];
34 *--tos = (ulong)arg;
35 *--tos = (ulong)f;
36 t->sched.pc = (ulong)launcher386;
37 t->sched.sp = (ulong)tos - 8; /* old PC and new PC */
38 }
40 void
41 _threadinswitch(int enter)
42 {
43 USED(enter);
44 #ifdef USEVALGRIND
45 if(enter)
46 VALGRIND_SET_STACK_LIMIT(0, 0, 0);
47 else
48 VALGRIND_SET_STACK_LIMIT(0, 0, 1);
49 #endif
50 }
52 void
53 _threadstacklimit(void *bottom, void *top)
54 {
55 USED(bottom);
56 USED(top);
58 #ifdef USEVALGRIND
59 VALGRIND_SET_STACK_LIMIT(1, bottom, top);
60 #endif
61 }
62 #endif