[rtems commit] posix: Fix pthread_create() with user stack

Sebastian Huber sebh at rtems.org
Sat Oct 28 11:14:11 UTC 2017


Module:    rtems
Branch:    master
Commit:    1d572eba9748f815486258b2e87d831e5bdee038
Changeset: http://git.rtems.org/rtems/commit/?id=1d572eba9748f815486258b2e87d831e5bdee038

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Fri Oct 27 09:03:55 2017 +0200

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

diff --git a/cpukit/posix/src/pthreadcreate.c b/cpukit/posix/src/pthreadcreate.c
index 2315b7f..5a8cf2d 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 */



More information about the vc mailing list