From 1d572eba9748f815486258b2e87d831e5bdee038 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Fri, 27 Oct 2017 09:03:55 +0200 Subject: posix: Fix pthread_create() with user stack In case the user provides a stack with address and size, then do not alter the stack size. Close #3211. --- cpukit/posix/src/pthreadcreate.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'cpukit/posix/src/pthreadcreate.c') diff --git a/cpukit/posix/src/pthreadcreate.c b/cpukit/posix/src/pthreadcreate.c index 2315b7f5ee..5a8cf2d7fb 100644 --- a/cpukit/posix/src/pthreadcreate.c +++ b/cpukit/posix/src/pthreadcreate.c @@ -77,6 +77,7 @@ int pthread_create( const POSIX_API_Control *executing_api; int schedpolicy = SCHED_RR; struct sched_param schedparam; + size_t stacksize; Objects_Name name; int error; ISR_lock_Context lock_context; @@ -96,8 +97,15 @@ int pthread_create( * NOTE: If the user provides the stack we will let it drop below * twice the minimum. */ - if ( the_attr->stackaddr && !_Stack_Is_enough(the_attr->stacksize) ) - return EINVAL; + if ( the_attr->stackaddr != NULL ) { + if ( !_Stack_Is_enough(the_attr->stacksize) ) { + return EINVAL; + } + + stacksize = the_attr->stacksize; + } else { + stacksize = _POSIX_Threads_Ensure_minimum_stack( the_attr->stacksize ); + } #if 0 int cputime_clock_allowed; /* see time.h */ @@ -200,7 +208,7 @@ int pthread_create( the_thread, scheduler, the_attr->stackaddr, - _POSIX_Threads_Ensure_minimum_stack(the_attr->stacksize), + stacksize, is_fp, core_normal_prio, true, /* preemptible */ -- cgit v1.2.3