Thu Mar 8 16:33:46 2012 UTC ()
Fix the stack base pointer for the initial thread on !HPPA.
AT_STACKBASE is pointing to the start of the stack, which is the
upper limit on platforms where the stack grows down.


(joerg)
diff -r1.126 -r1.127 src/lib/libpthread/pthread.c

cvs diff -r1.126 -r1.127 src/lib/libpthread/pthread.c (expand / switch to unified diff)

--- src/lib/libpthread/pthread.c 2012/03/02 18:06:05 1.126
+++ src/lib/libpthread/pthread.c 2012/03/08 16:33:45 1.127
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: pthread.c,v 1.126 2012/03/02 18:06:05 joerg Exp $ */ 1/* $NetBSD: pthread.c,v 1.127 2012/03/08 16:33:45 joerg Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2001, 2002, 2003, 2006, 2007, 2008 The NetBSD Foundation, Inc. 4 * Copyright (c) 2001, 2002, 2003, 2006, 2007, 2008 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Nathan J. Williams and Andrew Doran. 8 * by Nathan J. Williams and Andrew Doran.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -20,27 +20,27 @@ @@ -20,27 +20,27 @@
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33__RCSID("$NetBSD: pthread.c,v 1.126 2012/03/02 18:06:05 joerg Exp $"); 33__RCSID("$NetBSD: pthread.c,v 1.127 2012/03/08 16:33:45 joerg Exp $");
34 34
35#define __EXPOSE_STACK 1 35#define __EXPOSE_STACK 1
36 36
37#include <sys/param.h> 37#include <sys/param.h>
38#include <sys/exec_elf.h> 38#include <sys/exec_elf.h>
39#include <sys/mman.h> 39#include <sys/mman.h>
40#include <sys/sysctl.h> 40#include <sys/sysctl.h>
41#include <sys/lwpctl.h> 41#include <sys/lwpctl.h>
42#include <sys/tls.h> 42#include <sys/tls.h>
43 43
44#include <assert.h> 44#include <assert.h>
45#include <dlfcn.h> 45#include <dlfcn.h>
46#include <err.h> 46#include <err.h>
@@ -1192,36 +1192,43 @@ pthread__unpark_all(pthread_queue_t *que @@ -1192,36 +1192,43 @@ pthread__unpark_all(pthread_queue_t *que
1192 } 1192 }
1193 self->pt_nwaiters = nwaiters; 1193 self->pt_nwaiters = nwaiters;
1194 PTQ_INIT(queue); 1194 PTQ_INIT(queue);
1195 pthread__mutex_deferwake(self, interlock); 1195 pthread__mutex_deferwake(self, interlock);
1196} 1196}
1197 1197
1198#undef OOPS 1198#undef OOPS
1199 1199
1200static void 1200static void
1201pthread__initmainstack(void) 1201pthread__initmainstack(void)
1202{ 1202{
1203 struct rlimit slimit; 1203 struct rlimit slimit;
1204 const AuxInfo *aux; 1204 const AuxInfo *aux;
 1205 size_t size;
1205 1206
1206 _DIAGASSERT(_dlauxinfo() != NULL); 1207 _DIAGASSERT(_dlauxinfo() != NULL);
1207 1208
1208 if (getrlimit(RLIMIT_STACK, &slimit) == -1) 1209 if (getrlimit(RLIMIT_STACK, &slimit) == -1)
1209 err(1, "Couldn't get stack resource consumption limits"); 1210 err(1, "Couldn't get stack resource consumption limits");
1210 pthread__main.pt_stack.ss_size = slimit.rlim_cur; 1211 size = slimit.rlim_cur;
 1212 pthread__main.pt_stack.ss_size = size;
1211 1213
1212 for (aux = _dlauxinfo(); aux->a_type != AT_NULL; ++aux) { 1214 for (aux = _dlauxinfo(); aux->a_type != AT_NULL; ++aux) {
1213 if (aux->a_type == AT_STACKBASE) { 1215 if (aux->a_type == AT_STACKBASE) {
1214 pthread__main.pt_stack.ss_sp = (void *)aux->a_v; 1216 pthread__main.pt_stack.ss_sp = (void *)aux->a_v;
 1217#ifdef __MACHINE_STACK_GROWS_UP
 1218 pthread__main.pt_stack.ss_sp = (void *)aux->a_v;
 1219#else
 1220 pthread__main.pt_stack.ss_sp = (char *)aux->a_v - size;
 1221#endif
1215 break; 1222 break;
1216 } 1223 }
1217 } 1224 }
1218} 1225}
1219 1226
1220/* 1227/*
1221 * Set up the slightly special stack for the "initial" thread, which 1228 * Set up the slightly special stack for the "initial" thread, which
1222 * runs on the normal system stack, and thus gets slightly different 1229 * runs on the normal system stack, and thus gets slightly different
1223 * treatment. 1230 * treatment.
1224 */ 1231 */
1225static void 1232static void
1226pthread__initmain(pthread_t *newt) 1233pthread__initmain(pthread_t *newt)
1227{ 1234{