[haiku-commits] r41807 - haiku/branches/developer/bonefish/signals/src/system/kernel

  • From: ingo_weinhold@xxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Sun, 29 May 2011 15:09:35 +0200 (CEST)

Author: bonefish
Date: 2011-05-29 15:09:34 +0200 (Sun, 29 May 2011)
New Revision: 41807
Changeset: https://dev.haiku-os.org/changeset/41807

Modified:
   haiku/branches/developer/bonefish/signals/src/system/kernel/thread.cpp
Log:
thread_create_thread(): Be less lenient with the given user stack size. Fail,
if it doesn't meet our requirements, instead of just using the default value.


Modified: haiku/branches/developer/bonefish/signals/src/system/kernel/thread.cpp
===================================================================
--- haiku/branches/developer/bonefish/signals/src/system/kernel/thread.cpp      
2011-05-29 12:48:05 UTC (rev 41806)
+++ haiku/branches/developer/bonefish/signals/src/system/kernel/thread.cpp      
2011-05-29 13:09:34 UTC (rev 41807)
@@ -769,23 +769,28 @@
                size_t stackSize = attributes.stack_size;
 
                if (stackBase != NULL) {
-                       // A stack has been specified. It must be large enough 
to also hold
-                       // the TLS space. If not, just allocate the standard 
stack.
-                       if (stackSize <= TLS_SIZE) {
-                               stackBase = NULL;
-                               stackSize = 0;
-                       } else
-                               stackBase -= TLS_SIZE;
+                       // A stack has been specified. It must be large enough 
to hold the
+                       // TLS space at least.
+                       STATIC_ASSERT(TLS_SIZE < MIN_USER_STACK_SIZE);
+                       if (stackSize < MIN_USER_STACK_SIZE)
+                               return B_BAD_VALUE;
+
+                       stackBase -= TLS_SIZE;
                }
 
                if (stackBase == NULL) {
                        // no user-defined stack -- allocate one
                        stackBase = (uint8*)(addr_t)USER_STACK_REGION;
 
-                       if (stackSize == 0)
+                       if (stackSize == 0) {
                                stackSize = USER_STACK_SIZE;
-                       else
+                       } else {
+                               // Verify that the given stack size is large 
enough.
+                               if (stackSize < MIN_USER_STACK_SIZE - TLS_SIZE)
+                                       return B_BAD_VALUE;
+
                                stackSize = PAGE_ALIGN(stackSize);
+                       }
                        stackSize += USER_STACK_GUARD_PAGES * B_PAGE_SIZE;
 
                        snprintf(stack_name, B_OS_NAME_LENGTH, "%s_%ld_stack",


Other related posts: