diff options
Diffstat (limited to 'src/libthread/386.c')
-rw-r--r-- | src/libthread/386.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/libthread/386.c b/src/libthread/386.c index 2f391bff..3fbf0afe 100644 --- a/src/libthread/386.c +++ b/src/libthread/386.c @@ -1,8 +1,23 @@ #include "threadimpl.h" +/* + * To use this you need some patches to Valgrind that + * let it help out with detecting stack overflow. + */ +#define USEVALGRIND 0 +#ifdef USEVALGRIND +#include <valgrind/memcheck.h> +#endif static void launcher386(void (*f)(void *arg), void *arg) { + Proc *p; + Thread *t; + + p = _threadgetproc(); + t = p->thread; + _threadstacklimit(t->stk); + (*f)(arg); threadexits(nil); } @@ -19,3 +34,24 @@ _threadinitstack(Thread *t, void (*f)(void*), void *arg) t->sched.sp = (ulong)tos - 8; /* old PC and new PC */ } +void +_threadinswitch(int enter) +{ + USED(enter); +#ifdef USEVALGRIND + if(enter) + VALGRIND_SET_STACK_LIMIT(0, 0, 1); + else + VALGRIND_SET_STACK_LIMIT(0, 0, 0); +#endif +} + +void +_threadstacklimit(void *addr) +{ + USED(addr); + +#ifdef USEVALGRIND + VALGRIND_SET_STACK_LIMIT(1, addr, 0); +#endif +} |