olga / rpms / glibc

Forked from rpms/glibc 5 years ago
Clone

Blame SOURCES/glibc-rh1527904-3.patch

00db10
commit 630f4cc3aa019ede55976ea561f1a7af2f068639
00db10
Author: Szabolcs Nagy <szabolcs.nagy@arm.com>
00db10
Date:   Wed Dec 6 13:05:50 2017 +0000
00db10
00db10
    [BZ #22637] Fix stack guard size accounting
00db10
    
00db10
    Previously if user requested S stack and G guard when creating a
00db10
    thread, the total mapping was S and the actual available stack was
00db10
    S - G - static_tls, which is not what the user requested.
00db10
    
00db10
    This patch fixes the guard size accounting by pretending the user
00db10
    requested S+G stack.  This way all later logic works out except
00db10
    when reporting the user requested stack size (pthread_getattr_np)
00db10
    or when computing the minimal stack size (__pthread_get_minstack).
00db10
    
00db10
    Normally this will increase thread stack allocations by one page.
00db10
    TLS accounting is not affected, that will require a separate fix.
00db10
    
00db10
            [BZ #22637]
00db10
            * nptl/descr.h (stackblock, stackblock_size): Update comments.
00db10
            * nptl/allocatestack.c (allocate_stack): Add guardsize to stacksize.
00db10
            * nptl/nptl-init.c (__pthread_get_minstack): Remove guardsize from
00db10
            stacksize.
00db10
            * nptl/pthread_getattr_np.c (pthread_getattr_np): Likewise.
00db10
00db10
Index: glibc-2.17-c758a686/nptl/allocatestack.c
00db10
===================================================================
00db10
--- glibc-2.17-c758a686.orig/nptl/allocatestack.c
00db10
+++ glibc-2.17-c758a686/nptl/allocatestack.c
00db10
@@ -470,6 +470,10 @@ allocate_stack (const struct pthread_att
00db10
       /* Make sure the size of the stack is enough for the guard and
00db10
 	 eventually the thread descriptor.  */
00db10
       guardsize = (attr->guardsize + pagesize_m1) & ~pagesize_m1;
00db10
+      if (guardsize < attr->guardsize || size + guardsize < guardsize)
00db10
+	/* Arithmetic overflow.  */
00db10
+	return EINVAL;
00db10
+      size += guardsize;
00db10
       if (__builtin_expect (size < ((guardsize + __static_tls_size
00db10
 				     + MINIMAL_REST_STACK + pagesize_m1)
00db10
 				    & ~pagesize_m1),
00db10
Index: glibc-2.17-c758a686/nptl/descr.h
00db10
===================================================================
00db10
--- glibc-2.17-c758a686.orig/nptl/descr.h
00db10
+++ glibc-2.17-c758a686/nptl/descr.h
00db10
@@ -366,9 +366,9 @@ struct pthread
00db10
   struct _Unwind_Exception exc;
00db10
 #endif
00db10
 
00db10
-  /* If nonzero pointer to area allocated for the stack and its
00db10
-     size.  */
00db10
+  /* If nonzero, pointer to the area allocated for the stack and guard. */
00db10
   void *stackblock;
00db10
+  /* Size of the stackblock area including the guard.  */
00db10
   size_t stackblock_size;
00db10
   /* Size of the included guard area.  */
00db10
   size_t guardsize;
00db10
Index: glibc-2.17-c758a686/nptl/nptl-init.c
00db10
===================================================================
00db10
--- glibc-2.17-c758a686.orig/nptl/nptl-init.c
00db10
+++ glibc-2.17-c758a686/nptl/nptl-init.c
00db10
@@ -500,8 +500,5 @@ strong_alias (__pthread_initialize_minim
00db10
 size_t
00db10
 __pthread_get_minstack (const pthread_attr_t *attr)
00db10
 {
00db10
-  struct pthread_attr *iattr = (struct pthread_attr *) attr;
00db10
-
00db10
-  return (GLRO(dl_pagesize) + __static_tls_size + PTHREAD_STACK_MIN
00db10
-	  + iattr->guardsize);
00db10
+  return GLRO(dl_pagesize) + __static_tls_size + PTHREAD_STACK_MIN;
00db10
 }
00db10
Index: glibc-2.17-c758a686/nptl/pthread_getattr_np.c
00db10
===================================================================
00db10
--- glibc-2.17-c758a686.orig/nptl/pthread_getattr_np.c
00db10
+++ glibc-2.17-c758a686/nptl/pthread_getattr_np.c
00db10
@@ -59,8 +59,11 @@ pthread_getattr_np (thread_id, attr)
00db10
   /* The sizes are subject to alignment.  */
00db10
   if (__builtin_expect (thread->stackblock != NULL, 1))
00db10
     {
00db10
-      iattr->stacksize = thread->stackblock_size;
00db10
-      iattr->stackaddr = (char *) thread->stackblock + iattr->stacksize;
00db10
+      /* The stack size reported to the user should not include the
00db10
+	 guard size.  */
00db10
+      iattr->stacksize = thread->stackblock_size - thread->guardsize;
00db10
+      iattr->stackaddr = (char *) thread->stackblock
00db10
+       			 + thread->stackblock_size;
00db10
     }
00db10
   else
00db10
     {