plan9port/src/libthread/386.c

58 lines
967 B
C
Raw Normal View History

2003-09-30 17:47:42 +00:00
#include "threadimpl.h"
/*
* To use this you need some patches to Valgrind that
* let it help out with detecting stack overflow.
*/
#ifdef USEVALGRIND
#include <valgrind/memcheck.h>
#endif
2003-09-30 17:47:42 +00:00
static void
launcher386(void (*f)(void *arg), void *arg)
{
Proc *p;
Thread *t;
p = _threadgetproc();
t = p->thread;
2004-05-11 17:51:27 +00:00
_threadstacklimit(t->stk, t->stk+t->stksize);
2003-09-30 17:47:42 +00:00
(*f)(arg);
threadexits(nil);
}
void
_threadinitstack(Thread *t, void (*f)(void*), void *arg)
{
ulong *tos;
tos = (ulong*)&t->stk[t->stksize&~7];
*--tos = (ulong)arg;
*--tos = (ulong)f;
t->sched.pc = (ulong)launcher386;
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, 0);
2004-05-11 17:51:27 +00:00
else
VALGRIND_SET_STACK_LIMIT(0, 0, 1);
#endif
}
void
2004-05-11 17:51:27 +00:00
_threadstacklimit(void *bottom, void *top)
{
2004-05-11 17:51:27 +00:00
USED(bottom);
USED(top);
#ifdef USEVALGRIND
2004-05-11 17:51:27 +00:00
VALGRIND_SET_STACK_LIMIT(1, bottom, top);
#endif
}