olga / rpms / glibc

Forked from rpms/glibc 5 years ago
Clone

Blame SOURCES/glibc-rh1103874.patch

00db10
diff -pruN glibc-2.17-c758a686/nptl/sysdeps/pthread/unwind-forcedunwind.c glibc-2.17-c758a686/nptl/sysdeps/pthread/unwind-forcedunwind.c
00db10
--- glibc-2.17-c758a686/nptl/sysdeps/pthread/unwind-forcedunwind.c	2010-05-04 16:57:23.000000000 +0530
00db10
+++ glibc-2.17-c758a686/nptl/sysdeps/pthread/unwind-forcedunwind.c	2014-06-02 23:00:02.901013275 +0530
00db10
@@ -45,8 +45,10 @@ pthread_cancel_init (void)
00db10
 
00db10
   if (__builtin_expect (libgcc_s_handle != NULL, 1))
00db10
     {
00db10
-      /* Force gcc to reload all values.  */
00db10
-      asm volatile ("" ::: "memory");
00db10
+      /* Order reads so as to prevent speculation of loads
00db10
+	 of libgcc_s_{resume,personality,forcedunwind,getcfa}
00db10
+	 to points prior to the write barrier.  */
00db10
+      atomic_read_barrier ();
00db10
       return;
00db10
     }
00db10
 
00db10
@@ -72,9 +74,14 @@ pthread_cancel_init (void)
00db10
   libgcc_s_forcedunwind = forcedunwind;
00db10
   PTR_MANGLE (getcfa);
00db10
   libgcc_s_getcfa = getcfa;
00db10
-  /* Make sure libgcc_s_handle is written last.  Otherwise,
00db10
-     pthread_cancel_init might return early even when the pointer the
00db10
-     caller is interested in is not initialized yet.  */
00db10
+  /* At the point at which any thread writes the handle
00db10
+     to libgcc_s_handle, the initialization is complete.
00db10
+     The writing of libgcc_s_handle is atomic. All other
00db10
+     threads reading libgcc_s_handle do so atomically. Any
00db10
+     thread that does not execute this function must issue
00db10
+     a read barrier to ensure that all of the above has
00db10
+     actually completed and that the values of the
00db10
+     function pointers are correct.   */
00db10
   atomic_write_barrier ();
00db10
   libgcc_s_handle = handle;
00db10
 }
00db10
@@ -91,13 +98,19 @@ __unwind_freeres (void)
00db10
     }
00db10
 }
00db10
 
00db10
-void
00db10
-_Unwind_Resume (struct _Unwind_Exception *exc)
00db10
+static __always_inline void
00db10
+_maybe_pthread_cancel_init (void)
00db10
 {
00db10
   if (__builtin_expect (libgcc_s_handle == NULL, 0))
00db10
     pthread_cancel_init ();
00db10
   else
00db10
     atomic_read_barrier ();
00db10
+}
00db10
+
00db10
+void
00db10
+_Unwind_Resume (struct _Unwind_Exception *exc)
00db10
+{
00db10
+  _maybe_pthread_cancel_init ();
00db10
 
00db10
   void (*resume) (struct _Unwind_Exception *exc) = libgcc_s_resume;
00db10
   PTR_DEMANGLE (resume);
00db10
@@ -108,10 +123,7 @@ __gcc_personality_v0 (int version, _Unwi
00db10
 		      struct _Unwind_Exception *ue_header,
00db10
 		      struct _Unwind_Context *context)
00db10
 {
00db10
-  if (__builtin_expect (libgcc_s_handle == NULL, 0))
00db10
-    pthread_cancel_init ();
00db10
-  else
00db10
-    atomic_read_barrier ();
00db10
+  _maybe_pthread_cancel_init ();
00db10
 
00db10
   _Unwind_Reason_Code (*personality)
00db10
     (int, _Unwind_Action, _Unwind_Exception_Class, struct _Unwind_Exception *,
00db10
@@ -122,10 +136,7 @@ _Unwind_Reason_Code
00db10
 _Unwind_ForcedUnwind (struct _Unwind_Exception *exc, _Unwind_Stop_Fn stop,
00db10
 		      void *stop_argument)
00db10
 {
00db10
-  if (__builtin_expect (libgcc_s_handle == NULL, 0))
00db10
-    pthread_cancel_init ();
00db10
-  else
00db10
-    atomic_read_barrier ();
00db10
+  _maybe_pthread_cancel_init ();
00db10
 
00db10
   _Unwind_Reason_Code (*forcedunwind)
00db10
     (struct _Unwind_Exception *, _Unwind_Stop_Fn, void *)
00db10
@@ -135,10 +148,7 @@ _Unwind_ForcedUnwind (struct _Unwind_Exc
00db10
 _Unwind_Word
00db10
 _Unwind_GetCFA (struct _Unwind_Context *context)
00db10
 {
00db10
-  if (__builtin_expect (libgcc_s_handle == NULL, 0))
00db10
-    pthread_cancel_init ();
00db10
-  else
00db10
-    atomic_read_barrier ();
00db10
+  _maybe_pthread_cancel_init ();
00db10
 
00db10
   _Unwind_Word (*getcfa) (struct _Unwind_Context *) = libgcc_s_getcfa;
00db10
   PTR_DEMANGLE (getcfa);
00db10
diff -pruN glibc-2.17-c758a686/sysdeps/gnu/unwind-resume.c glibc-2.17-c758a686/sysdeps/gnu/unwind-resume.c
00db10
--- glibc-2.17-c758a686/sysdeps/gnu/unwind-resume.c	2010-05-04 16:57:23.000000000 +0530
00db10
+++ glibc-2.17-c758a686/sysdeps/gnu/unwind-resume.c	2014-06-02 23:02:26.812007078 +0530
00db10
@@ -20,8 +20,11 @@
00db10
 #include <dlfcn.h>
00db10
 #include <stdio.h>
00db10
 #include <unwind.h>
00db10
+#include <pthreadP.h>
00db10
+#include <sysdep.h>
00db10
 #include <gnu/lib-names.h>
00db10
 
00db10
+static void *libgcc_s_handle;
00db10
 static void (*libgcc_s_resume) (struct _Unwind_Exception *exc);
00db10
 static _Unwind_Reason_Code (*libgcc_s_personality)
00db10
   (int, _Unwind_Action, _Unwind_Exception_Class, struct _Unwind_Exception *,
00db10
@@ -42,13 +45,32 @@ init (void)
00db10
 
00db10
   libgcc_s_resume = resume;
00db10
   libgcc_s_personality = personality;
00db10
+  atomic_write_barrier ();
00db10
+  /* At the point at which any thread writes the handle
00db10
+     to libgcc_s_handle, the initialization is complete.
00db10
+     The writing of libgcc_s_handle is atomic. All other
00db10
+     threads reading libgcc_s_handle do so atomically. Any
00db10
+     thread that does not execute this function must issue
00db10
+     a read barrier to ensure that all of the above has
00db10
+     actually completed and that the values of the
00db10
+     function pointers are correct.   */
00db10
+  libgcc_s_handle = handle;
00db10
 }
00db10
 
00db10
+static __always_inline void
00db10
+_maybe_init (void)
00db10
+{
00db10
+  if (__builtin_expect (libgcc_s_handle == NULL, 0))
00db10
+    init ();
00db10
+  else
00db10
+    atomic_read_barrier ();
00db10
+}
00db10
+
00db10
+
00db10
 void
00db10
 _Unwind_Resume (struct _Unwind_Exception *exc)
00db10
 {
00db10
-  if (__builtin_expect (libgcc_s_resume == NULL, 0))
00db10
-    init ();
00db10
+  _maybe_init ();
00db10
   libgcc_s_resume (exc);
00db10
 }
00db10
 
00db10
@@ -58,8 +80,7 @@ __gcc_personality_v0 (int version, _Unwi
00db10
                       struct _Unwind_Exception *ue_header,
00db10
                       struct _Unwind_Context *context)
00db10
 {
00db10
-  if (__builtin_expect (libgcc_s_personality == NULL, 0))
00db10
-    init ();
00db10
+  _maybe_init ();
00db10
   return libgcc_s_personality (version, actions, exception_class,
00db10
 			       ue_header, context);
00db10
 }