about summary refs log tree commit diff
path: root/nptl/pthread_create.c
diff options
context:
space:
mode:
authorCarlos O'Donell <carlos@systemhalted.org>2013-08-16 14:57:59 -0400
committerMike Frysinger <vapier@gentoo.org>2014-02-08 09:21:06 -0500
commita5760bbb50f3dbfd1e4051a54aae35060cdd639b (patch)
tree87050392c0d80ee6b56edf4e945e144c9521a62a /nptl/pthread_create.c
parent6a714e48586aa7f21d2eeef9195cee57c9ebaa60 (diff)
downloadglibc-a5760bbb50f3dbfd1e4051a54aae35060cdd639b.tar.gz
glibc-a5760bbb50f3dbfd1e4051a54aae35060cdd639b.tar.xz
glibc-a5760bbb50f3dbfd1e4051a54aae35060cdd639b.zip
nptl: support thread stacks that grow up
http://bugs.gentoo.org/301642
Diffstat (limited to 'nptl/pthread_create.c')
-rw-r--r--nptl/pthread_create.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/nptl/pthread_create.c b/nptl/pthread_create.c
index 9d7f52f57e..72945cb3f6 100644
--- a/nptl/pthread_create.c
+++ b/nptl/pthread_create.c
@@ -401,13 +401,26 @@ start_thread (void *arg)
 #ifdef _STACK_GROWS_DOWN
   char *sp = CURRENT_STACK_FRAME;
   size_t freesize = (sp - (char *) pd->stackblock) & ~pagesize_m1;
-#else
-# error "to do"
-#endif
   assert (freesize < pd->stackblock_size);
   if (freesize > PTHREAD_STACK_MIN)
     __madvise (pd->stackblock, freesize - PTHREAD_STACK_MIN, MADV_DONTNEED);
-
+#else
+  /* Page aligned start of memory to free (higher than or equal 
+     to current sp plus the minimum stack size).  */
+  void *freeblock = (void*)((size_t)(CURRENT_STACK_FRAME 
+				     + PTHREAD_STACK_MIN 
+				     + pagesize_m1) 
+				    & ~pagesize_m1);
+  char *free_end = (char *) (((uintptr_t) pd - pd->guardsize) & ~pagesize_m1);
+  /* Is there any space to free?  */
+  if (free_end > (char *)freeblock)
+    {
+      size_t freesize = (size_t)(free_end - (char *)freeblock);
+      assert (freesize < pd->stackblock_size);
+      __madvise (freeblock, freesize, MADV_DONTNEED);
+    }
+#endif
+ 
   /* If the thread is detached free the TCB.  */
   if (IS_DETACHED (pd))
     /* Free the TCB.  */