olga / rpms / glibc

Forked from rpms/glibc 5 years ago
Clone

Blame SOURCES/glibc-rh1527904-3.patch

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