| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: pthread.c,v 1.128 2012/03/08 16:40:45 joerg Exp $ */ | | 1 | /* $NetBSD: pthread.c,v 1.129 2012/03/09 12:06:44 drochner 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.128 2012/03/08 16:40:45 joerg Exp $"); | | 33 | __RCSID("$NetBSD: pthread.c,v 1.129 2012/03/09 12:06:44 drochner 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> |
| @@ -330,27 +330,27 @@ pthread__newstack(pthread_t newthread, c | | | @@ -330,27 +330,27 @@ pthread__newstack(pthread_t newthread, c |
330 | stacksize = 0; | | 330 | stacksize = 0; |
331 | } | | 331 | } |
332 | if (stacksize == 0) | | 332 | if (stacksize == 0) |
333 | stacksize = pthread__stacksize; | | 333 | stacksize = pthread__stacksize; |
334 | | | 334 | |
335 | if (stackbase == NULL) { | | 335 | if (stackbase == NULL) { |
336 | stackbase = mmap(NULL, stacksize, | | 336 | stackbase = mmap(NULL, stacksize, |
337 | PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, -1, (off_t)0); | | 337 | PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, -1, (off_t)0); |
338 | if (stackbase == MAP_FAILED) | | 338 | if (stackbase == MAP_FAILED) |
339 | return ENOMEM; | | 339 | return ENOMEM; |
340 | mapped_stack = true; | | 340 | mapped_stack = true; |
341 | } | | 341 | } |
342 | newthread->pt_stack.ss_size = pthread__stacksize - pthread__pagesize; | | 342 | newthread->pt_stack.ss_size = pthread__stacksize - pthread__pagesize; |
343 | newthread->pt_stack.ss_sp = stackbase; | | 343 | newthread->pt_stack.ss_sp = stackbase; |
344 | #ifdef __MACHINE_STACK_GROWS_UP | | 344 | #ifdef __MACHINE_STACK_GROWS_UP |
345 | redzone = (char *)stackbase + newthread->pt_stack.ss_size; | | 345 | redzone = (char *)stackbase + newthread->pt_stack.ss_size; |
346 | #else | | 346 | #else |
347 | redzone = (char *)stackbase; | | 347 | redzone = (char *)stackbase; |
348 | #endif | | 348 | #endif |
349 | if (mprotect(redzone, pthread__pagesize, PROT_NONE) == -1) { | | 349 | if (mprotect(redzone, pthread__pagesize, PROT_NONE) == -1) { |
350 | if (mapped_stack) | | 350 | if (mapped_stack) |
351 | munmap(stackbase, pthread__stacksize); | | 351 | munmap(stackbase, pthread__stacksize); |
352 | return EPERM; | | 352 | return EPERM; |
353 | } | | 353 | } |
354 | return 0; | | 354 | return 0; |
355 | } | | 355 | } |
356 | | | 356 | |
| @@ -1250,27 +1250,27 @@ pthread__initmain(pthread_t *newt) | | | @@ -1250,27 +1250,27 @@ pthread__initmain(pthread_t *newt) |
1250 | char *value; | | 1250 | char *value; |
1251 | | | 1251 | |
1252 | pthread__initmainstack(); | | 1252 | pthread__initmainstack(); |
1253 | | | 1253 | |
1254 | value = pthread__getenv("PTHREAD_STACKSIZE"); | | 1254 | value = pthread__getenv("PTHREAD_STACKSIZE"); |
1255 | if (value != NULL) { | | 1255 | if (value != NULL) { |
1256 | pthread__stacksize = atoi(value) * 1024; | | 1256 | pthread__stacksize = atoi(value) * 1024; |
1257 | if (pthread__stacksize > pthread__main.pt_stack.ss_size) | | 1257 | if (pthread__stacksize > pthread__main.pt_stack.ss_size) |
1258 | pthread__stacksize = pthread__main.pt_stack.ss_size; | | 1258 | pthread__stacksize = pthread__main.pt_stack.ss_size; |
1259 | } | | 1259 | } |
1260 | if (pthread__stacksize == 0) | | 1260 | if (pthread__stacksize == 0) |
1261 | pthread__stacksize = pthread__main.pt_stack.ss_size; | | 1261 | pthread__stacksize = pthread__main.pt_stack.ss_size; |
1262 | pthread__stacksize += pthread__pagesize - 1; | | 1262 | pthread__stacksize += pthread__pagesize - 1; |
1263 | pthread__stacksize &= ~pthread__pagesize; | | 1263 | pthread__stacksize &= ~(pthread__pagesize - 1); |
1264 | if (pthread__stacksize < 4 * pthread__pagesize) | | 1264 | if (pthread__stacksize < 4 * pthread__pagesize) |
1265 | errx(1, "Stacksize limit is too low, minimum %zd kbyte.", | | 1265 | errx(1, "Stacksize limit is too low, minimum %zd kbyte.", |
1266 | 4 * pthread__pagesize / 1024); | | 1266 | 4 * pthread__pagesize / 1024); |
1267 | | | 1267 | |
1268 | *newt = &pthread__main; | | 1268 | *newt = &pthread__main; |
1269 | #if defined(__HAVE_TLS_VARIANT_I) || defined(__HAVE_TLS_VARIANT_II) | | 1269 | #if defined(__HAVE_TLS_VARIANT_I) || defined(__HAVE_TLS_VARIANT_II) |
1270 | # ifdef __HAVE___LWP_GETTCB_FAST | | 1270 | # ifdef __HAVE___LWP_GETTCB_FAST |
1271 | pthread__main.pt_tls = __lwp_gettcb_fast(); | | 1271 | pthread__main.pt_tls = __lwp_gettcb_fast(); |
1272 | # else | | 1272 | # else |
1273 | pthread__main.pt_tls = _lwp_getprivate(); | | 1273 | pthread__main.pt_tls = _lwp_getprivate(); |
1274 | # endif | | 1274 | # endif |
1275 | pthread__main.pt_tls->tcb_pthread = &pthread__main; | | 1275 | pthread__main.pt_tls->tcb_pthread = &pthread__main; |
1276 | #endif | | 1276 | #endif |