2012-04-26 03:48:48 +00:00
|
|
|
/* Copyright (C) 2003-2012 Free Software Foundation, Inc.
|
2003-07-22 23:56:53 +00:00
|
|
|
This file is part of the GNU C Library.
|
|
|
|
Contributed by Jakub Jelinek <jakub@redhat.com>.
|
|
|
|
|
|
|
|
The GNU C Library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Lesser General Public License as
|
|
|
|
published by the Free Software Foundation; either version 2.1 of the
|
|
|
|
License, or (at your option) any later version.
|
|
|
|
|
|
|
|
The GNU C Library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
2012-02-09 23:18:22 +00:00
|
|
|
License along with the GNU C Library; see the file COPYING.LIB. If
|
|
|
|
not, see <http://www.gnu.org/licenses/>. */
|
2003-07-22 23:56:53 +00:00
|
|
|
|
|
|
|
#include <dlfcn.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unwind.h>
|
|
|
|
#include <pthreadP.h>
|
2009-01-29 20:52:36 +00:00
|
|
|
#include <sysdep.h>
|
2012-04-26 03:48:48 +00:00
|
|
|
#include <gnu/lib-names.h>
|
2003-07-22 23:56:53 +00:00
|
|
|
|
2009-01-29 20:38:04 +00:00
|
|
|
static void *libgcc_s_handle;
|
2006-05-09 15:19:13 +00:00
|
|
|
static void (*libgcc_s_resume) (struct _Unwind_Exception *exc);
|
|
|
|
static _Unwind_Reason_Code (*libgcc_s_personality)
|
2003-07-22 23:56:53 +00:00
|
|
|
(int, _Unwind_Action, _Unwind_Exception_Class, struct _Unwind_Exception *,
|
|
|
|
struct _Unwind_Context *);
|
2006-05-09 15:19:13 +00:00
|
|
|
static _Unwind_Reason_Code (*libgcc_s_forcedunwind)
|
2003-07-22 23:56:53 +00:00
|
|
|
(struct _Unwind_Exception *, _Unwind_Stop_Fn, void *);
|
2006-05-09 15:19:13 +00:00
|
|
|
static _Unwind_Word (*libgcc_s_getcfa) (struct _Unwind_Context *);
|
2003-07-22 23:56:53 +00:00
|
|
|
|
|
|
|
void
|
2006-05-10 00:03:41 +00:00
|
|
|
__attribute_noinline__
|
2003-07-22 23:56:53 +00:00
|
|
|
pthread_cancel_init (void)
|
|
|
|
{
|
2009-01-29 20:52:36 +00:00
|
|
|
void *resume;
|
|
|
|
void *personality;
|
|
|
|
void *forcedunwind;
|
|
|
|
void *getcfa;
|
2003-07-22 23:56:53 +00:00
|
|
|
void *handle;
|
|
|
|
|
2009-01-29 20:38:04 +00:00
|
|
|
if (__builtin_expect (libgcc_s_handle != NULL, 1))
|
2006-05-09 15:19:13 +00:00
|
|
|
{
|
|
|
|
/* Force gcc to reload all values. */
|
|
|
|
asm volatile ("" ::: "memory");
|
|
|
|
return;
|
|
|
|
}
|
2003-07-22 23:56:53 +00:00
|
|
|
|
2009-11-03 22:52:01 +00:00
|
|
|
handle = __libc_dlopen (LIBGCC_S_SO);
|
2003-07-22 23:56:53 +00:00
|
|
|
|
|
|
|
if (handle == NULL
|
|
|
|
|| (resume = __libc_dlsym (handle, "_Unwind_Resume")) == NULL
|
|
|
|
|| (personality = __libc_dlsym (handle, "__gcc_personality_v0")) == NULL
|
|
|
|
|| (forcedunwind = __libc_dlsym (handle, "_Unwind_ForcedUnwind"))
|
|
|
|
== NULL
|
2003-09-04 05:57:06 +00:00
|
|
|
|| (getcfa = __libc_dlsym (handle, "_Unwind_GetCFA")) == NULL
|
|
|
|
#ifdef ARCH_CANCEL_INIT
|
|
|
|
|| ARCH_CANCEL_INIT (handle)
|
|
|
|
#endif
|
|
|
|
)
|
2009-11-03 22:52:01 +00:00
|
|
|
__libc_fatal (LIBGCC_S_SO " must be installed for pthread_cancel to work\n");
|
2003-07-22 23:56:53 +00:00
|
|
|
|
2009-01-29 20:52:36 +00:00
|
|
|
PTR_MANGLE (resume);
|
2003-07-22 23:56:53 +00:00
|
|
|
libgcc_s_resume = resume;
|
2009-01-29 20:52:36 +00:00
|
|
|
PTR_MANGLE (personality);
|
2003-07-22 23:56:53 +00:00
|
|
|
libgcc_s_personality = personality;
|
2009-01-29 20:52:36 +00:00
|
|
|
PTR_MANGLE (forcedunwind);
|
2003-07-22 23:56:53 +00:00
|
|
|
libgcc_s_forcedunwind = forcedunwind;
|
2009-01-29 20:52:36 +00:00
|
|
|
PTR_MANGLE (getcfa);
|
2009-01-29 20:38:04 +00:00
|
|
|
libgcc_s_getcfa = getcfa;
|
|
|
|
/* Make sure libgcc_s_handle is written last. Otherwise,
|
2005-11-16 23:32:52 +00:00
|
|
|
pthread_cancel_init might return early even when the pointer the
|
|
|
|
caller is interested in is not initialized yet. */
|
|
|
|
atomic_write_barrier ();
|
2009-01-29 20:38:04 +00:00
|
|
|
libgcc_s_handle = handle;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
__libc_freeres_fn_section
|
|
|
|
__unwind_freeres (void)
|
|
|
|
{
|
|
|
|
void *handle = libgcc_s_handle;
|
|
|
|
if (handle != NULL)
|
|
|
|
{
|
|
|
|
libgcc_s_handle = NULL;
|
|
|
|
__libc_dlclose (handle);
|
|
|
|
}
|
2003-07-22 23:56:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_Unwind_Resume (struct _Unwind_Exception *exc)
|
|
|
|
{
|
2009-01-29 20:52:36 +00:00
|
|
|
if (__builtin_expect (libgcc_s_handle == NULL, 0))
|
2006-05-09 15:19:13 +00:00
|
|
|
pthread_cancel_init ();
|
2011-07-23 03:48:22 +00:00
|
|
|
else
|
|
|
|
atomic_read_barrier ();
|
2006-05-09 15:19:13 +00:00
|
|
|
|
2009-01-29 20:52:36 +00:00
|
|
|
void (*resume) (struct _Unwind_Exception *exc) = libgcc_s_resume;
|
|
|
|
PTR_DEMANGLE (resume);
|
|
|
|
resume (exc);
|
2003-07-22 23:56:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_Unwind_Reason_Code
|
|
|
|
__gcc_personality_v0 (int version, _Unwind_Action actions,
|
|
|
|
_Unwind_Exception_Class exception_class,
|
2011-07-23 03:48:22 +00:00
|
|
|
struct _Unwind_Exception *ue_header,
|
|
|
|
struct _Unwind_Context *context)
|
2003-07-22 23:56:53 +00:00
|
|
|
{
|
2009-01-29 20:52:36 +00:00
|
|
|
if (__builtin_expect (libgcc_s_handle == NULL, 0))
|
2006-05-09 15:19:13 +00:00
|
|
|
pthread_cancel_init ();
|
2011-07-23 03:48:22 +00:00
|
|
|
else
|
|
|
|
atomic_read_barrier ();
|
2006-05-09 15:19:13 +00:00
|
|
|
|
2009-01-29 20:52:36 +00:00
|
|
|
_Unwind_Reason_Code (*personality)
|
|
|
|
(int, _Unwind_Action, _Unwind_Exception_Class, struct _Unwind_Exception *,
|
|
|
|
struct _Unwind_Context *) = libgcc_s_personality;
|
|
|
|
PTR_DEMANGLE (personality);
|
|
|
|
return personality (version, actions, exception_class, ue_header, context);
|
2003-07-22 23:56:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_Unwind_Reason_Code
|
|
|
|
_Unwind_ForcedUnwind (struct _Unwind_Exception *exc, _Unwind_Stop_Fn stop,
|
|
|
|
void *stop_argument)
|
|
|
|
{
|
2009-01-29 20:52:36 +00:00
|
|
|
if (__builtin_expect (libgcc_s_handle == NULL, 0))
|
2006-05-09 15:19:13 +00:00
|
|
|
pthread_cancel_init ();
|
2011-07-23 03:48:22 +00:00
|
|
|
else
|
|
|
|
atomic_read_barrier ();
|
2006-05-09 15:19:13 +00:00
|
|
|
|
2009-01-29 20:52:36 +00:00
|
|
|
_Unwind_Reason_Code (*forcedunwind)
|
|
|
|
(struct _Unwind_Exception *, _Unwind_Stop_Fn, void *)
|
|
|
|
= libgcc_s_forcedunwind;
|
|
|
|
PTR_DEMANGLE (forcedunwind);
|
|
|
|
return forcedunwind (exc, stop, stop_argument);
|
2003-07-22 23:56:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_Unwind_Word
|
|
|
|
_Unwind_GetCFA (struct _Unwind_Context *context)
|
|
|
|
{
|
2009-01-29 20:52:36 +00:00
|
|
|
if (__builtin_expect (libgcc_s_handle == NULL, 0))
|
2006-05-09 15:19:13 +00:00
|
|
|
pthread_cancel_init ();
|
2011-07-23 03:48:22 +00:00
|
|
|
else
|
|
|
|
atomic_read_barrier ();
|
2006-05-09 15:19:13 +00:00
|
|
|
|
2009-01-29 20:52:36 +00:00
|
|
|
_Unwind_Word (*getcfa) (struct _Unwind_Context *) = libgcc_s_getcfa;
|
|
|
|
PTR_DEMANGLE (getcfa);
|
|
|
|
return getcfa (context);
|
2003-07-22 23:56:53 +00:00
|
|
|
}
|