local-stack-grows-up
authorGNU Libc Maintainers <debian-glibc@lists.debian.org>
Mon, 16 Jan 2017 17:43:37 +0000 (17:43 +0000)
committerAurelien Jarno <aurel32@debian.org>
Mon, 16 Jan 2017 17:43:37 +0000 (17:43 +0000)
Gbp-Pq: Topic hppa
Gbp-Pq: Name local-stack-grows-up.diff

nptl/allocatestack.c

index 6b42b11d5a77848a15a557efddddf2205d95c2ca..f8d989d0d293c0ed10809eebab94271bb4c9e24f 100644 (file)
@@ -691,9 +691,13 @@ allocate_stack (const struct pthread_attr *attr, struct pthread **pdp,
                        prot) != 0)
            goto mprot_error;
 #elif _STACK_GROWS_UP
-         if (mprotect ((char *) pd - pd->guardsize,
-                       pd->guardsize - guardsize, prot) != 0)
-           goto mprot_error;
+         char *new_guard = (char *) (((uintptr_t) pd - guardsize) & ~pagesize_m1);
+         char *old_guard = (char *) (((uintptr_t) pd - pd->guardsize) & ~pagesize_m1);
+         /* The guard size difference might be > 0, but once rounded
+            to the nearest page the size difference might be zero.  */
+         if (old_guard - new_guard > 0)
+           if (mprotect (old_guard, new_guard - old_guard, prot) != 0)
+             goto mprot_error;
 #endif
 
          pd->guardsize = guardsize;