From 58a36b39ff9968d203037db496cedd8acbb969c3 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Sun, 28 Sep 2014 23:34:10 +0200 Subject: Fetch stack size from rlimit * pthread/pt-create.c: Include (__pthread_create_internal): When `attr''s stacksize is 0, try to get the desired size from the RLIMIT_STACK rlimit before defaulting to PTHREAD_STACK_DEFAULT. * sysdeps/generic/pt-attr.c (__pthread_default_attr): Set stacksize to 0 instead of PTHREAD_STACK_DEFAULT. --- pthread/pt-create.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'pthread') diff --git a/pthread/pt-create.c b/pthread/pt-create.c index 78dd17e..386891e 100644 --- a/pthread/pt-create.c +++ b/pthread/pt-create.c @@ -24,6 +24,7 @@ #include #include +#include #include @@ -92,6 +93,7 @@ __pthread_create_internal (struct __pthread **thread, struct __pthread *pthread; const struct __pthread_attr *setup; sigset_t sigset; + size_t stacksize; /* Allocate a new thread structure. */ err = __pthread_alloc (&pthread); @@ -101,6 +103,17 @@ __pthread_create_internal (struct __pthread **thread, /* Use the default attributes if ATTR is NULL. */ setup = attr ? attr : &__pthread_default_attr; + stacksize = setup->stacksize; + if (!stacksize) + { + struct rlimit rlim; + getrlimit(RLIMIT_STACK, &rlim); + if (rlim.rlim_cur != RLIM_INFINITY) + stacksize = rlim.rlim_cur; + if (!stacksize) + stacksize = PTHREAD_STACK_DEFAULT; + } + /* Initialize the thread state. */ pthread->state = (setup->detachstate == PTHREAD_CREATE_DETACHED ? PTHREAD_DETACHED : PTHREAD_JOINABLE); @@ -120,7 +133,7 @@ __pthread_create_internal (struct __pthread **thread, err = __pthread_stack_alloc (&pthread->stackaddr, ((setup->guardsize + __vm_page_size-1) / __vm_page_size) * __vm_page_size - + setup->stacksize); + + stacksize); if (err) goto failed_stack_alloc; @@ -128,7 +141,7 @@ __pthread_create_internal (struct __pthread **thread, pthread->stack = 1; } - pthread->stacksize = setup->stacksize; + pthread->stacksize = stacksize; /* Allocate the kernel thread and other required resources. */ err = __pthread_thread_alloc (pthread); @@ -230,7 +243,7 @@ __pthread_create_internal (struct __pthread **thread, __pthread_stack_dealloc (pthread->stackaddr, ((setup->guardsize + __vm_page_size-1) / __vm_page_size) * __vm_page_size - + pthread->stacksize); + + stacksize); failed_stack_alloc: __pthread_dealloc (pthread); failed: -- cgit v1.2.3