From 0a08973fdfd081e959b3c42f8f95d27badb46423 Mon Sep 17 00:00:00 2001 From: Adhemerval Zanella Date: Thu, 5 Jan 2012 21:36:23 -0500 Subject: [PATCH] Fix for AIO stack size (backported from 'master' branch) --- nptl/Versions | 2 +- nptl/nptl-init.c | 12 +++++++++++- nptl/pthreadP.h | 1 + nptl/sysdeps/unix/sysv/linux/aio_misc.h | 6 +++--- nptl/sysdeps/unix/sysv/linux/timer_routines.c | 2 +- 5 files changed, 17 insertions(+), 6 deletions(-) diff --git a/nptl/Versions b/nptl/Versions index f74941fa92b..333d4fa0ebc 100644 --- a/nptl/Versions +++ b/nptl/Versions @@ -254,6 +254,6 @@ libpthread { GLIBC_PRIVATE { __pthread_initialize_minimal; __pthread_clock_gettime; __pthread_clock_settime; - __pthread_unwind; + __pthread_unwind; __pthread_get_minstack; } } diff --git a/nptl/nptl-init.c b/nptl/nptl-init.c index 851bab2bf19..628e7d7e70c 100644 --- a/nptl/nptl-init.c +++ b/nptl/nptl-init.c @@ -408,7 +408,7 @@ __pthread_initialize_minimal_internal (void) /* Make sure it meets the minimum size that allocate_stack (allocatestack.c) will demand, which depends on the page size. */ - const uintptr_t pagesz = __sysconf (_SC_PAGESIZE); + const uintptr_t pagesz = GLRO(dl_pagesize); const size_t minstack = pagesz + __static_tls_size + MINIMAL_REST_STACK; if (limit.rlim_cur < minstack) limit.rlim_cur = minstack; @@ -450,3 +450,13 @@ __pthread_initialize_minimal_internal (void) } strong_alias (__pthread_initialize_minimal_internal, __pthread_initialize_minimal) + + +size_t +__pthread_get_minstack (const pthread_attr_t *attr) +{ + struct pthread_attr *iattr = (struct pthread_attr *) attr; + + return (GLRO(dl_pagesize) + __static_tls_size + PTHREAD_STACK_MIN + + iattr->guardsize); +} diff --git a/nptl/pthreadP.h b/nptl/pthreadP.h index 43ca44c8296..eb553a08fe3 100644 --- a/nptl/pthreadP.h +++ b/nptl/pthreadP.h @@ -397,6 +397,7 @@ weak_function; extern void __pthread_init_static_tls (struct link_map *) attribute_hidden; +extern size_t __pthread_get_minstack (const pthread_attr_t *attr); /* Namespace save aliases. */ extern int __pthread_getschedparam (pthread_t thread_id, int *policy, diff --git a/nptl/sysdeps/unix/sysv/linux/aio_misc.h b/nptl/sysdeps/unix/sysv/linux/aio_misc.h index 2bf7c17aed9..3910b13268f 100644 --- a/nptl/sysdeps/unix/sysv/linux/aio_misc.h +++ b/nptl/sysdeps/unix/sysv/linux/aio_misc.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2004, 2006 Free Software Foundation, Inc. +/* Copyright (C) 2004, 2006, 2011 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Jakub Jelinek , 2004. @@ -46,8 +46,8 @@ __aio_create_helper_thread (pthread_t *threadp, void *(*tf) (void *), pthread_attr_init (&attr); pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED); - /* Don't set the stacksize to PTHREAD_STACK_MIN. Let it default, otherwise - the stack may be too small if TLS is in use. */ + /* The helper thread needs only very little resources. */ + (void) pthread_attr_setstacksize (&attr, __pthread_get_minstack (&attr)); /* Block all signals in the helper thread. To do this thoroughly we temporarily have to block all signals here. */ diff --git a/nptl/sysdeps/unix/sysv/linux/timer_routines.c b/nptl/sysdeps/unix/sysv/linux/timer_routines.c index b159316fb20..d75f45bc4e9 100644 --- a/nptl/sysdeps/unix/sysv/linux/timer_routines.c +++ b/nptl/sysdeps/unix/sysv/linux/timer_routines.c @@ -165,7 +165,7 @@ __start_helper_thread (void) and should go away automatically when canceled. */ pthread_attr_t attr; (void) pthread_attr_init (&attr); - (void) pthread_attr_setstacksize (&attr, PTHREAD_STACK_MIN); + (void) pthread_attr_setstacksize (&attr, __pthread_get_minstack (&attr)); /* Block all signals in the helper thread but SIGSETXID. To do this thoroughly we temporarily have to block all signals here. The -- 2.47.2