libthread: use mmap to allocate OpenBSD stacks
Should fix faults on OpenBSD. Fixes #218. Fixes #226.
This commit is contained in:
parent
4ae529dbfe
commit
8c573cab68
6 changed files with 61 additions and 8 deletions
|
|
@ -109,7 +109,7 @@ threadalloc(void (*fn)(void*), void *arg, uint stack)
|
|||
ulong z;
|
||||
|
||||
/* allocate the task and stack together */
|
||||
t = malloc(sizeof *t+stack);
|
||||
t = malloc(sizeof *t);
|
||||
if(t == nil)
|
||||
sysfatal("threadalloc malloc: %r");
|
||||
memset(t, 0, sizeof *t);
|
||||
|
|
@ -122,7 +122,9 @@ threadalloc(void (*fn)(void*), void *arg, uint stack)
|
|||
/* do a reasonable initialization */
|
||||
if(stack == 0)
|
||||
return t;
|
||||
t->stk = (uchar*)(t+1);
|
||||
t->stk = _threadstkalloc(stack);
|
||||
if(t->stk == nil)
|
||||
sysfatal("threadalloc malloc stack: %r");
|
||||
t->stksize = stack;
|
||||
memset(&t->context.uc, 0, sizeof t->context.uc);
|
||||
sigemptyset(&zero);
|
||||
|
|
@ -353,6 +355,7 @@ Top:
|
|||
delthreadinproc(p, t);
|
||||
p->nthread--;
|
||||
/*print("nthread %d\n", p->nthread); */
|
||||
_threadstkfree(t->stk, t->stksize);
|
||||
free(t);
|
||||
}
|
||||
|
||||
|
|
@ -509,6 +512,8 @@ needstack(int n)
|
|||
_Thread *t;
|
||||
|
||||
t = proc()->thread;
|
||||
if(t->stk == nil)
|
||||
return;
|
||||
|
||||
if((char*)&t <= (char*)t->stk
|
||||
|| (char*)&t - (char*)t->stk < 256+n){
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue