Blame SOURCES/glibc-rh771342.patch

b9ba6d
2011-06-30  Ulrich Drepper  <drepper@gmail.com>
b9ba6d
b9ba6d
	* nptl-init.c (__nptl_set_robust): New function.
b9ba6d
	(pthread_functions): Add reference.
b9ba6d
	* npthreadP.h: Declare __nptl_set_robust.
b9ba6d
	* sysdeps/pthread/pthread-functions.h (pthread_functions): Add
b9ba6d
	ptr_set_robust member.
b9ba6d
	* sysdeps/unix/sysv/linux/fork.c: Call set_robust_list syscall in
b9ba6d
	child if threads are used.
b9ba6d
b9ba6d
diff -Nrup a/nptl/nptl-init.c b/nptl/nptl-init.c
b9ba6d
--- a/nptl/nptl-init.c	2011-12-20 00:29:54.645538691 -0700
b9ba6d
+++ b/nptl/nptl-init.c	2012-01-03 10:18:38.977513783 -0700
b9ba6d
@@ -69,6 +69,13 @@ extern void __libc_setup_tls (size_t tcb
b9ba6d
 #endif
b9ba6d
 
b9ba6d
 #ifdef SHARED
b9ba6d
+static
b9ba6d
+#else
b9ba6d
+extern
b9ba6d
+#endif
b9ba6d
+void __nptl_set_robust (struct pthread *);
b9ba6d
+
b9ba6d
+#ifdef SHARED
b9ba6d
 static void nptl_freeres (void);
b9ba6d
 
b9ba6d
 
b9ba6d
@@ -131,13 +138,25 @@ static const struct pthread_functions pt
b9ba6d
     .ptr__nptl_deallocate_tsd = __nptl_deallocate_tsd,
b9ba6d
     .ptr__nptl_setxid = __nptl_setxid,
b9ba6d
     /* For now only the stack cache needs to be freed.  */
b9ba6d
-    .ptr_freeres = nptl_freeres
b9ba6d
+    .ptr_freeres = nptl_freeres,
b9ba6d
+    .ptr_set_robust = __nptl_set_robust
b9ba6d
   };
b9ba6d
 # define ptr_pthread_functions &pthread_functions
b9ba6d
 #else
b9ba6d
 # define ptr_pthread_functions NULL
b9ba6d
 #endif
b9ba6d
 
b9ba6d
+#ifdef SHARED
b9ba6d
+static
b9ba6d
+#endif
b9ba6d
+void
b9ba6d
+__nptl_set_robust (struct pthread *self)
b9ba6d
+{
b9ba6d
+  INTERNAL_SYSCALL_DECL (err);
b9ba6d
+  INTERNAL_SYSCALL (set_robust_list, err, 2, &self->robust_head,
b9ba6d
+                   sizeof (struct robust_list_head));
b9ba6d
+}
b9ba6d
+
b9ba6d
 
b9ba6d
 #ifdef SHARED
b9ba6d
 /* This function is called indirectly from the freeres code in libc.  */
b9ba6d
diff -Nrup a/nptl/pthreadP.h b/nptl/pthreadP.h
b9ba6d
--- a/nptl/pthreadP.h	2010-05-04 05:27:23.000000000 -0600
b9ba6d
+++ b/nptl/pthreadP.h	2012-01-03 10:12:35.599269269 -0700
b9ba6d
@@ -555,17 +555,20 @@ extern void __pthread_cleanup_pop_restor
b9ba6d
 
b9ba6d
 /* Old cleanup interfaces, still used in libc.so.  */
b9ba6d
 extern void _pthread_cleanup_push (struct _pthread_cleanup_buffer *buffer,
b9ba6d
-                                   void (*routine) (void *), void *arg);
b9ba6d
+				   void (*routine) (void *), void *arg);
b9ba6d
 extern void _pthread_cleanup_pop (struct _pthread_cleanup_buffer *buffer,
b9ba6d
-                                  int execute);
b9ba6d
+				  int execute);
b9ba6d
 extern void _pthread_cleanup_push_defer (struct _pthread_cleanup_buffer *buffer,
b9ba6d
-                                         void (*routine) (void *), void *arg);
b9ba6d
+					 void (*routine) (void *), void *arg);
b9ba6d
 extern void _pthread_cleanup_pop_restore (struct _pthread_cleanup_buffer *buffer,
b9ba6d
-                                          int execute);
b9ba6d
+					  int execute);
b9ba6d
 
b9ba6d
 extern void __nptl_deallocate_tsd (void) attribute_hidden;
b9ba6d
 
b9ba6d
 extern int __nptl_setxid (struct xid_command *cmdp) attribute_hidden;
b9ba6d
+#ifndef SHARED
b9ba6d
+extern void __nptl_set_robust (struct pthread *self);
b9ba6d
+#endif
b9ba6d
 
b9ba6d
 extern void __free_stacks (size_t limit) attribute_hidden;
b9ba6d
 
b9ba6d
diff -Nrup a/nptl/sysdeps/pthread/pthread-functions.h b/nptl/sysdeps/pthread/pthread-functions.h
b9ba6d
--- a/nptl/sysdeps/pthread/pthread-functions.h	2010-05-04 05:27:23.000000000 -0600
b9ba6d
+++ b/nptl/sysdeps/pthread/pthread-functions.h	2012-01-03 10:12:35.639269301 -0700
b9ba6d
@@ -97,6 +97,7 @@ struct pthread_functions
b9ba6d
   void (*ptr__nptl_deallocate_tsd) (void);
b9ba6d
   int (*ptr__nptl_setxid) (struct xid_command *);
b9ba6d
   void (*ptr_freeres) (void);
b9ba6d
+  void (*ptr_set_robust) (struct pthread *);
b9ba6d
 };
b9ba6d
 
b9ba6d
 /* Variable in libc.so.  */
b9ba6d
diff -Nrup a/nptl/sysdeps/unix/sysv/linux/fork.c b/nptl/sysdeps/unix/sysv/linux/fork.c
b9ba6d
--- a/nptl/sysdeps/unix/sysv/linux/fork.c	2010-05-04 05:27:23.000000000 -0600
b9ba6d
+++ b/nptl/sysdeps/unix/sysv/linux/fork.c	2012-01-03 10:12:35.649269309 -0700
b9ba6d
@@ -29,6 +29,7 @@
b9ba6d
 #include <ldsodefs.h>
b9ba6d
 #include <bits/stdio-lock.h>
b9ba6d
 #include <atomic.h>
b9ba6d
+#include <pthreadP.h>
b9ba6d
 
b9ba6d
 
b9ba6d
 unsigned long int *__fork_generation_pointer;
b9ba6d
@@ -86,8 +87,8 @@ __libc_fork (void)
b9ba6d
 	 just go away.  The unloading code works in the order of the
b9ba6d
 	 list.
b9ba6d
 
b9ba6d
-         While executing the registered handlers we are building a
b9ba6d
-         list of all the entries so that we can go backward later on.  */
b9ba6d
+	 While executing the registered handlers we are building a
b9ba6d
+	 list of all the entries so that we can go backward later on.  */
b9ba6d
       while (1)
b9ba6d
 	{
b9ba6d
 	  /* Execute the handler if there is one.  */
b9ba6d
@@ -154,6 +155,24 @@ __libc_fork (void)
b9ba6d
       GL(dl_cpuclock_offset) = now;
b9ba6d
 #endif
b9ba6d
 
b9ba6d
+#ifdef __NR_set_robust_list
b9ba6d
+      /* Initialize the robust mutex list which has been reset during
b9ba6d
+	 the fork.  We do not check for errors since if it fails here
b9ba6d
+	 it failed at process start as well and noone could have used
b9ba6d
+	 robust mutexes.  We also do not have to set
b9ba6d
+	 self->robust_head.futex_offset since we inherit the correct
b9ba6d
+	 value from the parent.  */
b9ba6d
+# ifdef SHARED
b9ba6d
+      if (__libc_pthread_functions.ptr_set_robust != NULL)
b9ba6d
+	PTHFCT_CALL (ptr_set_robust, (self));
b9ba6d
+# else
b9ba6d
+      extern __typeof (__nptl_set_robust) __nptl_set_robust
b9ba6d
+	__attribute__((weak));
b9ba6d
+      if (__builtin_expect (__nptl_set_robust != NULL, 0))
b9ba6d
+	__nptl_set_robust (self);
b9ba6d
+# endif
b9ba6d
+#endif
b9ba6d
+
b9ba6d
       /* Reset the file list.  These are recursive mutexes.  */
b9ba6d
       fresetlockfiles ();
b9ba6d
 
b9ba6d
@@ -170,10 +189,10 @@ __libc_fork (void)
b9ba6d
 	    allp->handler->child_handler ();
b9ba6d
 
b9ba6d
 	  /* Note that we do not have to wake any possible waiter.
b9ba6d
- 	     This is the only thread in the new process.  The count
b9ba6d
- 	     may have been bumped up by other threads doing a fork.
b9ba6d
- 	     We reset it to 1, to avoid waiting for non-existing
b9ba6d
- 	     thread(s) to release the count.  */
b9ba6d
+	     This is the only thread in the new process.  The count
b9ba6d
+	     may have been bumped up by other threads doing a fork.
b9ba6d
+	     We reset it to 1, to avoid waiting for non-existing
b9ba6d
+	     thread(s) to release the count.  */
b9ba6d
 	  allp->handler->refcntr = 1;
b9ba6d
 
b9ba6d
 	  /* XXX We could at this point look through the object pool