in pthread__initmain(), don't reuse the part of the initial stack that

is occupied by the argv and environment (and MD stuff like the page-table
mapping on x86).  fixes PR 26392.
This commit is contained in:
chs 2004-07-25 23:22:43 +00:00
parent ff5b999530
commit 503ca60040

View File

@ -1,4 +1,4 @@
/* $NetBSD: pthread_stack.c,v 1.14 2004/07/20 01:51:49 chs Exp $ */
/* $NetBSD: pthread_stack.c,v 1.15 2004/07/25 23:22:43 chs Exp $ */
/*-
* Copyright (c) 2001 The NetBSD Foundation, Inc.
@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: pthread_stack.c,v 1.14 2004/07/20 01:51:49 chs Exp $");
__RCSID("$NetBSD: pthread_stack.c,v 1.15 2004/07/25 23:22:43 chs Exp $");
#define __EXPOSE_STACK 1
#include <sys/param.h>
@ -107,6 +107,7 @@ void
pthread__initmain(pthread_t *newt)
{
void *base;
size_t size;
#ifndef PT_FIXEDSTACKSIZE_LG
struct rlimit slimit;
@ -139,18 +140,26 @@ pthread__initmain(pthread_t *newt)
pthread_stacksize = (1 << pthread_stacksize_lg);
pthread_stackmask = pthread_stacksize - 1;
/*
* XXX The "initial" thread stack can be smaller than
* requested because we don't control the end of the stack.
* On i386 the stack usually ends at 0xbfc00000 and for
* requested sizes >=8MB, we get a 4MB smaller stack.
*/
#endif /* PT_FIXEDSTACKSIZE_LG */
/*
* The "initial" thread stack can be smaller than requested
* because we don't control the end of the stack.
* For example, on i386 the stack usually ends at 0xbfc00000,
* so for requested sizes >=8MB, we get a 4MB smaller stack.
* Also, we don't want to clobber the argv, environment, etc.
* Just trim off the part of the stack that we can't use.
*/
#ifdef __MACHINE_STACK_GROWS_UP
/* XXX this case isn't right */
base = (void *) (pthread__sp() & ~PT_STACKMASK);
size = PT_STACKSIZE;
#else
base = (void *) (pthread__sp() & ~PT_STACKMASK);
size = ((char *)pthread__sp() - (char *)base) & ~(pagesize - 1);
#endif
*newt = pthread__stackid_setup(base, PT_STACKSIZE);
*newt = pthread__stackid_setup(base, size);
}
static pthread_t
@ -172,7 +181,7 @@ pthread__stackid_setup(void *base, size_t size)
*/
redaddr = STACK_SHRINK(STACK_MAX(base, size), pagesize);
t->pt_stack.ss_size = PT_STACKSIZE - 2 * pagesize;
t->pt_stack.ss_size = size - 2 * pagesize;
#ifdef __MACHINE_STACK_GROWS_UP
t->pt_stack.ss_sp = (char *)base + pagesize;
sp = t->pt_stack.ss_sp;