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