diff options
| author | chs <chs@NetBSD.org> | 2004-08-17 14:16:00 +0000 |
|---|---|---|
| committer | chs <chs@NetBSD.org> | 2004-08-17 14:16:00 +0000 |
| commit | c6736a59b3a47ac959fc1995b1c869a436c4d74b (patch) | |
| tree | b2fd95ae5f3e75a2cf2b0c06494519283db0a715 /lib/libpthread/pthread_stack.c | |
| parent | f56858739a73f6cb1e5ecc9a1bf68dc429923369 (diff) | |
redo the fix for PR 26392 differently: instead of changing the stack bounds
for the initial stack, just change the initial thread's pt_uc to point to
the opposite end of the stack (away from the argv, environment, etc).
Diffstat (limited to 'lib/libpthread/pthread_stack.c')
| -rw-r--r-- | lib/libpthread/pthread_stack.c | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/lib/libpthread/pthread_stack.c b/lib/libpthread/pthread_stack.c index 1fdee283f21..29c21a80a4d 100644 --- a/lib/libpthread/pthread_stack.c +++ b/lib/libpthread/pthread_stack.c @@ -1,4 +1,4 @@ -/* $NetBSD: pthread_stack.c,v 1.15 2004/07/25 23:22:43 chs Exp $ */ +/* $NetBSD: pthread_stack.c,v 1.16 2004/08/17 14:16:00 chs Exp $ */ /*- * Copyright (c) 2001 The NetBSD Foundation, Inc. @@ -37,7 +37,7 @@ */ #include <sys/cdefs.h> -__RCSID("$NetBSD: pthread_stack.c,v 1.15 2004/07/25 23:22:43 chs Exp $"); +__RCSID("$NetBSD: pthread_stack.c,v 1.16 2004/08/17 14:16:00 chs Exp $"); #define __EXPOSE_STACK 1 #include <sys/param.h> @@ -106,6 +106,7 @@ pthread__stackalloc(pthread_t *newt) void pthread__initmain(pthread_t *newt) { + pthread_t t; void *base; size_t size; @@ -142,24 +143,28 @@ pthread__initmain(pthread_t *newt) pthread_stackmask = pthread_stacksize - 1; #endif /* PT_FIXEDSTACKSIZE_LG */ + base = (void *)(pthread__sp() & ~PT_STACKMASK); + size = PT_STACKSIZE; + + t = pthread__stackid_setup(base, size); + /* - * The "initial" thread stack can be smaller than requested + * The "safe" area chosen below isn't safe for the initial thread stack * 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. + * so for requested sizes >=8MB, the last 4MB of stack isn't available. * Also, we don't want to clobber the argv, environment, etc. - * Just trim off the part of the stack that we can't use. + * Reset the initial pt_uc pointer to be safe for the initial thread. */ + #ifdef __MACHINE_STACK_GROWS_UP - /* XXX this case isn't right */ - base = (void *) (pthread__sp() & ~PT_STACKMASK); - size = PT_STACKSIZE; + t->pt_uc = (ucontext_t *) + ((char *)t->pt_stack.ss_sp + t->pt_stack.ss_size - + sizeof (ucontext_t)); #else - base = (void *) (pthread__sp() & ~PT_STACKMASK); - size = ((char *)pthread__sp() - (char *)base) & ~(pagesize - 1); + t->pt_uc = (ucontext_t *)t->pt_stack.ss_sp; #endif - - *newt = pthread__stackid_setup(base, size); + *newt = t; } static pthread_t |
