12745e
diff -pruN glibc-2.17-c758a686/include/libc-internal.h glibc-2.17-c758a686/include/libc-internal.h
29e444
--- glibc-2.17-c758a686/include/libc-internal.h	2012-12-25 08:32:13.000000000 +0530
12745e
+++ glibc-2.17-c758a686/include/libc-internal.h	2013-07-30 11:26:37.947943710 +0530
29e444
@@ -50,4 +50,24 @@ extern void __init_misc (int, char **, c
29e444
 /* Cast an integer or a pointer VAL to integer with proper type.  */
29e444
 # define cast_to_integer(val) ((__integer_if_pointer_type (val)) (val))
29e444
 
29e444
+/* Align a value by rounding down to closest size.
29e444
+   e.g. Using size of 4096, we get this behavior:
29e444
+	{4095, 4096, 4097} = {0, 4096, 4096}.  */
29e444
+#define ALIGN_DOWN(base, size)	((base) & -((__typeof__ (base)) (size)))
29e444
+
29e444
+/* Align a value by rounding up to closest size.
29e444
+   e.g. Using size of 4096, we get this behavior:
29e444
+	{4095, 4096, 4097} = {4096, 4096, 8192}.
29e444
+
29e444
+  Note: The size argument has side effects (expanded multiple times).  */
29e444
+#define ALIGN_UP(base, size)	ALIGN_DOWN ((base) + (size) - 1, (size))
29e444
+
29e444
+/* Same as ALIGN_DOWN(), but automatically casts when base is a pointer.  */
29e444
+#define PTR_ALIGN_DOWN(base, size) \
29e444
+  ((__typeof__ (base)) ALIGN_DOWN ((uintptr_t) (base), (size)))
29e444
+
29e444
+/* Same as ALIGN_UP(), but automatically casts when base is a pointer.  */
29e444
+#define PTR_ALIGN_UP(base, size) \
29e444
+  ((__typeof__ (base)) ALIGN_UP ((uintptr_t) (base), (size)))
29e444
+
29e444
 #endif /* _LIBC_INTERNAL  */
12745e
diff -pruN glibc-2.17-c758a686/nptl/allocatestack.c glibc-2.17-c758a686/nptl/allocatestack.c
29e444
--- glibc-2.17-c758a686/nptl/allocatestack.c	2012-12-25 08:32:13.000000000 +0530
12745e
+++ glibc-2.17-c758a686/nptl/allocatestack.c	2013-07-30 11:26:38.012943707 +0530
29e444
@@ -355,7 +355,7 @@ allocate_stack (const struct pthread_att
29e444
 
29e444
   /* Get the stack size from the attribute if it is set.  Otherwise we
29e444
      use the default we determined at start time.  */
29e444
-  size = attr->stacksize ?: __default_stacksize;
29e444
+  size = attr->stacksize ?: __default_pthread_attr.stacksize;
29e444
 
29e444
   /* Get memory for the stack.  */
29e444
   if (__builtin_expect (attr->flags & ATTR_FLAG_STACKADDR, 0))
12745e
diff -pruN glibc-2.17-c758a686/nptl/nptl-init.c glibc-2.17-c758a686/nptl/nptl-init.c
29e444
--- glibc-2.17-c758a686/nptl/nptl-init.c	2013-07-30 11:45:16.902904743 +0530
12745e
+++ glibc-2.17-c758a686/nptl/nptl-init.c	2013-07-30 11:44:59.538905347 +0530
29e444
@@ -423,7 +423,8 @@ __pthread_initialize_minimal_internal (v
29e444
 
29e444
   /* Round the resource limit up to page size.  */
29e444
   limit.rlim_cur = (limit.rlim_cur + pagesz - 1) & -pagesz;
29e444
-  __default_stacksize = limit.rlim_cur;
29e444
+  __default_pthread_attr.stacksize = limit.rlim_cur;
29e444
+  __default_pthread_attr.guardsize = GLRO (dl_pagesize);
29e444
 
29e444
 #ifdef SHARED
29e444
   /* Transfer the old value from the dynamic linker's internal location.  */
12745e
diff -pruN glibc-2.17-c758a686/nptl/pthread_attr_getstacksize.c glibc-2.17-c758a686/nptl/pthread_attr_getstacksize.c
29e444
--- glibc-2.17-c758a686/nptl/pthread_attr_getstacksize.c	2012-12-25 08:32:13.000000000 +0530
12745e
+++ glibc-2.17-c758a686/nptl/pthread_attr_getstacksize.c	2013-07-30 11:26:39.650943650 +0530
29e444
@@ -32,7 +32,7 @@ __pthread_attr_getstacksize (attr, stack
29e444
 
29e444
   /* If the user has not set a stack size we return what the system
29e444
      will use as the default.  */
29e444
-  *stacksize = iattr->stacksize ?: __default_stacksize;
29e444
+  *stacksize = iattr->stacksize ?: __default_pthread_attr.stacksize;
29e444
 
29e444
   return 0;
29e444
 }
12745e
diff -pruN glibc-2.17-c758a686/nptl/pthread_barrier_init.c glibc-2.17-c758a686/nptl/pthread_barrier_init.c
29e444
--- glibc-2.17-c758a686/nptl/pthread_barrier_init.c	2012-12-25 08:32:13.000000000 +0530
12745e
+++ glibc-2.17-c758a686/nptl/pthread_barrier_init.c	2013-07-30 11:26:40.206943631 +0530
29e444
@@ -22,7 +22,7 @@
29e444
 #include <kernel-features.h>
29e444
 
29e444
 
29e444
-static const struct pthread_barrierattr default_attr =
29e444
+static const struct pthread_barrierattr default_barrierattr =
29e444
   {
29e444
     .pshared = PTHREAD_PROCESS_PRIVATE
29e444
   };
29e444
@@ -42,7 +42,7 @@ pthread_barrier_init (barrier, attr, cou
29e444
   const struct pthread_barrierattr *iattr
29e444
     = (attr != NULL
29e444
        ? iattr = (struct pthread_barrierattr *) attr
29e444
-       : &default_attr);
29e444
+       : &default_barrierattr);
29e444
 
29e444
   if (iattr->pshared != PTHREAD_PROCESS_PRIVATE
29e444
       && __builtin_expect (iattr->pshared != PTHREAD_PROCESS_SHARED, 0))
12745e
diff -pruN glibc-2.17-c758a686/nptl/pthread_create.c glibc-2.17-c758a686/nptl/pthread_create.c
29e444
--- glibc-2.17-c758a686/nptl/pthread_create.c	2012-12-25 08:32:13.000000000 +0530
12745e
+++ glibc-2.17-c758a686/nptl/pthread_create.c	2013-07-30 11:26:40.774943611 +0530
29e444
@@ -432,15 +432,6 @@ start_thread (void *arg)
29e444
 }
29e444
 
29e444
 
29e444
-/* Default thread attributes for the case when the user does not
29e444
-   provide any.  */
29e444
-static const struct pthread_attr default_attr =
29e444
-  {
29e444
-    /* Just some value > 0 which gets rounded to the nearest page size.  */
29e444
-    .guardsize = 1,
29e444
-  };
29e444
-
29e444
-
29e444
 int
29e444
 __pthread_create_2_1 (newthread, attr, start_routine, arg)
29e444
      pthread_t *newthread;
29e444
@@ -454,7 +445,7 @@ __pthread_create_2_1 (newthread, attr, s
29e444
   if (iattr == NULL)
29e444
     /* Is this the best idea?  On NUMA machines this could mean
29e444
        accessing far-away memory.  */
29e444
-    iattr = &default_attr;
29e444
+    iattr = &__default_pthread_attr;
29e444
 
29e444
   struct pthread *pd = NULL;
29e444
   int err = ALLOCATE_STACK (iattr, &pd;;
12745e
diff -pruN glibc-2.17-c758a686/nptl/pthread_mutex_init.c glibc-2.17-c758a686/nptl/pthread_mutex_init.c
29e444
--- glibc-2.17-c758a686/nptl/pthread_mutex_init.c	2012-12-25 08:32:13.000000000 +0530
12745e
+++ glibc-2.17-c758a686/nptl/pthread_mutex_init.c	2013-07-30 11:26:42.079943566 +0530
29e444
@@ -24,7 +24,7 @@
29e444
 
29e444
 #include <stap-probe.h>
29e444
 
29e444
-static const struct pthread_mutexattr default_attr =
29e444
+static const struct pthread_mutexattr default_mutexattr =
29e444
   {
29e444
     /* Default is a normal mutex, not shared between processes.  */
29e444
     .mutexkind = PTHREAD_MUTEX_NORMAL
29e444
@@ -45,7 +45,8 @@ __pthread_mutex_init (mutex, mutexattr)
29e444
 
29e444
   assert (sizeof (pthread_mutex_t) <= __SIZEOF_PTHREAD_MUTEX_T);
29e444
 
29e444
-  imutexattr = (const struct pthread_mutexattr *) mutexattr ?: &default_attr;
29e444
+  imutexattr = ((const struct pthread_mutexattr *) mutexattr
29e444
+		?: &default_mutexattr);
29e444
 
29e444
   /* Sanity checks.  */
29e444
   switch (__builtin_expect (imutexattr->mutexkind
12745e
diff -pruN glibc-2.17-c758a686/nptl/pthreadP.h glibc-2.17-c758a686/nptl/pthreadP.h
29e444
--- glibc-2.17-c758a686/nptl/pthreadP.h	2012-12-25 08:32:13.000000000 +0530
12745e
+++ glibc-2.17-c758a686/nptl/pthreadP.h	2013-07-30 11:26:43.095943530 +0530
29e444
@@ -147,8 +147,8 @@ enum
29e444
 /* Internal variables.  */
29e444
 
29e444
 
29e444
-/* Default stack size.  */
29e444
-extern size_t __default_stacksize attribute_hidden;
29e444
+/* Default pthread attributes.  */
29e444
+extern struct pthread_attr __default_pthread_attr attribute_hidden;
29e444
 
29e444
 /* Size and alignment of static TLS block.  */
29e444
 extern size_t __static_tls_size attribute_hidden;
12745e
diff -pruN glibc-2.17-c758a686/nptl/pthread_rwlock_init.c glibc-2.17-c758a686/nptl/pthread_rwlock_init.c
29e444
--- glibc-2.17-c758a686/nptl/pthread_rwlock_init.c	2012-12-25 08:32:13.000000000 +0530
12745e
+++ glibc-2.17-c758a686/nptl/pthread_rwlock_init.c	2013-07-30 11:26:43.745943508 +0530
29e444
@@ -21,7 +21,7 @@
29e444
 #include <kernel-features.h>
29e444
 
29e444
 
29e444
-static const struct pthread_rwlockattr default_attr =
29e444
+static const struct pthread_rwlockattr default_rwlockattr =
29e444
   {
29e444
     .lockkind = PTHREAD_RWLOCK_DEFAULT_NP,
29e444
     .pshared = PTHREAD_PROCESS_PRIVATE
29e444
@@ -35,7 +35,7 @@ __pthread_rwlock_init (rwlock, attr)
29e444
 {
29e444
   const struct pthread_rwlockattr *iattr;
29e444
 
29e444
-  iattr = ((const struct pthread_rwlockattr *) attr) ?: &default_attr;
29e444
+  iattr = ((const struct pthread_rwlockattr *) attr) ?: &default_rwlockattr;
29e444
 
29e444
   memset (rwlock, '\0', sizeof (*rwlock));
29e444
 
12745e
diff -pruN glibc-2.17-c758a686/nptl/vars.c glibc-2.17-c758a686/nptl/vars.c
29e444
--- glibc-2.17-c758a686/nptl/vars.c	2012-12-25 08:32:13.000000000 +0530
12745e
+++ glibc-2.17-c758a686/nptl/vars.c	2013-07-30 11:26:43.763943507 +0530
29e444
@@ -20,13 +20,9 @@
29e444
 #include <tls.h>
29e444
 #include <unistd.h>
29e444
 
29e444
-/* Default stack size.  */
29e444
-size_t __default_stacksize attribute_hidden
29e444
-#ifdef SHARED
29e444
-;
29e444
-#else
29e444
-  = PTHREAD_STACK_MIN;
29e444
-#endif
29e444
+/* Default thread attributes for the case when the user does not
29e444
+   provide any.  */
29e444
+struct pthread_attr __default_pthread_attr attribute_hidden;
29e444
 
29e444
 /* Flag whether the machine is SMP or not.  */
29e444
 int __is_smp attribute_hidden;