Blame SOURCES/glibc-rh771342.patch

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