about summary refs log tree commit diff
path: root/nptl/pthread_getattr_np.c
diff options
context:
space:
mode:
authorCarlos O'Donell <carlos@systemhalted.org>2015-08-09 04:17:17 -0400
committerMike Frysinger <vapier@gentoo.org>2016-02-19 12:41:29 -0500
commitd615a47355699d29df01b28a120cef29c8a38091 (patch)
treea60b5cd1dddc6bb30e409601dad08f09a601993b /nptl/pthread_getattr_np.c
parent11fca9615fa7b98135d262066db5f4156dd72955 (diff)
downloadglibc-d615a47355699d29df01b28a120cef29c8a38091.tar.gz
glibc-d615a47355699d29df01b28a120cef29c8a38091.tar.xz
glibc-d615a47355699d29df01b28a120cef29c8a38091.zip
nptl: support thread stacks that grow up
Gentoo has been carrying this for all arches since 2.17.

URL: http://bugs.gentoo.org/301642
Diffstat (limited to 'nptl/pthread_getattr_np.c')
-rw-r--r--nptl/pthread_getattr_np.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/nptl/pthread_getattr_np.c b/nptl/pthread_getattr_np.c
index 8207cdca7b..fb906f0484 100644
--- a/nptl/pthread_getattr_np.c
+++ b/nptl/pthread_getattr_np.c
@@ -58,7 +58,11 @@ pthread_getattr_np (pthread_t thread_id, pthread_attr_t *attr)
   if (__glibc_likely (thread->stackblock != NULL))
     {
       iattr->stacksize = thread->stackblock_size;
+#if _STACK_GROWS_DOWN
       iattr->stackaddr = (char *) thread->stackblock + iattr->stacksize;
+#else
+      iattr->stackaddr = (char *) thread->stackblock;
+#endif
     }
   else
     {
@@ -103,7 +107,9 @@ pthread_getattr_np (pthread_t thread_id, pthread_attr_t *attr)
 
 	      char *line = NULL;
 	      size_t linelen = 0;
+#if _STACK_GROWS_DOWN
 	      uintptr_t last_to = 0;
+#endif
 
 	      while (! feof_unlocked (fp))
 		{
@@ -127,17 +133,24 @@ pthread_getattr_np (pthread_t thread_id, pthread_attr_t *attr)
 		         stack extension request.  */
 		      iattr->stacksize = (iattr->stacksize
 					  & -(intptr_t) GLRO(dl_pagesize));
-
+#if _STACK_GROWS_DOWN
 		      /* The limit might be too high.  */
 		      if ((size_t) iattr->stacksize
 			  > (size_t) iattr->stackaddr - last_to)
 			iattr->stacksize = (size_t) iattr->stackaddr - last_to;
-
+#else
+		      /* The limit might be too high.  */
+		      if ((size_t) iattr->stacksize
+			  > to - (size_t) iattr->stackaddr)
+			iattr->stacksize = to - (size_t) iattr->stackaddr;
+#endif
 		      /* We succeed and no need to look further.  */
 		      ret = 0;
 		      break;
 		    }
+#if _STACK_GROWS_DOWN
 		  last_to = to;
+#endif
 		}
 
 	      free (line);