Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/libpthread Actually use the stack thread attributes when...
details: https://anonhg.NetBSD.org/src/rev/2d16fa21ee88
branches: trunk
changeset: 777872:2d16fa21ee88
user: joerg <joerg%NetBSD.org@localhost>
date: Thu Mar 08 16:40:45 2012 +0000
description:
Actually use the stack thread attributes when creating a new thread.
diffstat:
lib/libpthread/pthread.c | 33 ++++++++++++++++++++++++---------
1 files changed, 24 insertions(+), 9 deletions(-)
diffs (71 lines):
diff -r cd6bfbfe6d53 -r 2d16fa21ee88 lib/libpthread/pthread.c
--- a/lib/libpthread/pthread.c Thu Mar 08 16:40:37 2012 +0000
+++ b/lib/libpthread/pthread.c Thu Mar 08 16:40:45 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pthread.c,v 1.127 2012/03/08 16:33:45 joerg Exp $ */
+/* $NetBSD: pthread.c,v 1.128 2012/03/08 16:40:45 joerg Exp $ */
/*-
* Copyright (c) 2001, 2002, 2003, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: pthread.c,v 1.127 2012/03/08 16:33:45 joerg Exp $");
+__RCSID("$NetBSD: pthread.c,v 1.128 2012/03/08 16:40:45 joerg Exp $");
#define __EXPOSE_STACK 1
@@ -317,14 +317,28 @@
}
static int
-pthread__newstack(pthread_t newthread)
+pthread__newstack(pthread_t newthread, const pthread_attr_t *attr)
{
void *stackbase, *redzone;
+ size_t stacksize;
+ bool mapped_stack = false;
- stackbase = mmap(NULL, pthread__stacksize,
- PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, -1, (off_t)0);
- if (stackbase == MAP_FAILED)
- return ENOMEM;
+ if (attr != NULL) {
+ pthread_attr_getstack(attr, &stackbase, &stacksize);
+ } else {
+ stackbase = NULL;
+ stacksize = 0;
+ }
+ if (stacksize == 0)
+ stacksize = pthread__stacksize;
+
+ if (stackbase == NULL) {
+ stackbase = mmap(NULL, stacksize,
+ PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, -1, (off_t)0);
+ if (stackbase == MAP_FAILED)
+ return ENOMEM;
+ mapped_stack = true;
+ }
newthread->pt_stack.ss_size = pthread__stacksize - pthread__pagesize;
newthread->pt_stack.ss_sp = stackbase;
#ifdef __MACHINE_STACK_GROWS_UP
@@ -333,7 +347,8 @@
redzone = (char *)stackbase;
#endif
if (mprotect(redzone, pthread__pagesize, PROT_NONE) == -1) {
- munmap(stackbase, pthread__stacksize);
+ if (mapped_stack)
+ munmap(stackbase, pthread__stacksize);
return EPERM;
}
return 0;
@@ -411,7 +426,7 @@
return ENOMEM;
}
- if (pthread__newstack(newthread)) {
+ if (pthread__newstack(newthread, attr)) {
free(newthread);
free(name);
return ENOMEM;
Home |
Main Index |
Thread Index |
Old Index