From 503ca60040d628482e4c376502bb4be8509992e9 Mon Sep 17 00:00:00 2001 From: chs Date: Sun, 25 Jul 2004 23:22:43 +0000 Subject: 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. --- lib/libpthread/pthread_stack.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) (limited to 'lib/libpthread/pthread_stack.c') diff --git a/lib/libpthread/pthread_stack.c b/lib/libpthread/pthread_stack.c index 745d1a3e7fa..1fdee283f21 100644 --- a/lib/libpthread/pthread_stack.c +++ b/lib/libpthread/pthread_stack.c @@ -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 -__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 @@ -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; +#endif /* PT_FIXEDSTACKSIZE_LG */ /* - * 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. + * 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. */ -#endif /* PT_FIXEDSTACKSIZE_LG */ - +#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; -- cgit