[PATCH] posix: Fix pthread_create() with user stack

Sebastian Huber sebastian.huber at embedded-brains.de
Fri Oct 27 07:03:55 UTC 2017


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(-)

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 */
-- 
2.12.3



More information about the devel mailing list