|
Packit Service |
82fcde |
/* Copyright (C) 2003-2018 Free Software Foundation, Inc.
|
|
Packit Service |
82fcde |
This file is part of the GNU C Library.
|
|
Packit Service |
82fcde |
Contributed by Jakub Jelinek <jakub@redhat.com>.
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
The GNU C Library is free software; you can redistribute it and/or
|
|
Packit Service |
82fcde |
modify it under the terms of the GNU Lesser General Public License as
|
|
Packit Service |
82fcde |
published by the Free Software Foundation; either version 2.1 of the
|
|
Packit Service |
82fcde |
License, or (at your option) any later version.
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
The GNU C Library is distributed in the hope that it will be useful,
|
|
Packit Service |
82fcde |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
82fcde |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
82fcde |
Lesser General Public License for more details.
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
You should have received a copy of the GNU Lesser General Public
|
|
Packit Service |
82fcde |
License along with the GNU C Library; see the file COPYING.LIB. If
|
|
Packit Service |
82fcde |
not, see <http://www.gnu.org/licenses/>. */
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
#include <dlfcn.h>
|
|
Packit Service |
82fcde |
#include <stdio.h>
|
|
Packit Service |
82fcde |
#include <unwind.h>
|
|
Packit Service |
82fcde |
#include <pthreadP.h>
|
|
Packit Service |
82fcde |
#include <sysdep.h>
|
|
Packit Service |
82fcde |
#include <gnu/lib-names.h>
|
|
Packit Service |
82fcde |
#include <unwind-resume.h>
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
static void *libgcc_s_handle;
|
|
Packit Service |
82fcde |
void (*__libgcc_s_resume) (struct _Unwind_Exception *exc)
|
|
Packit Service |
82fcde |
attribute_hidden __attribute__ ((noreturn));
|
|
Packit Service |
82fcde |
static _Unwind_Reason_Code (*libgcc_s_personality) PERSONALITY_PROTO;
|
|
Packit Service |
82fcde |
static _Unwind_Reason_Code (*libgcc_s_forcedunwind)
|
|
Packit Service |
82fcde |
(struct _Unwind_Exception *, _Unwind_Stop_Fn, void *);
|
|
Packit Service |
82fcde |
static _Unwind_Word (*libgcc_s_getcfa) (struct _Unwind_Context *);
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
void
|
|
Packit Service |
82fcde |
__attribute_noinline__
|
|
Packit Service |
82fcde |
pthread_cancel_init (void)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
void *resume;
|
|
Packit Service |
82fcde |
void *personality;
|
|
Packit Service |
82fcde |
void *forcedunwind;
|
|
Packit Service |
82fcde |
void *getcfa;
|
|
Packit Service |
82fcde |
void *handle;
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
if (__glibc_likely (libgcc_s_handle != NULL))
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
/* Force gcc to reload all values. */
|
|
Packit Service |
82fcde |
asm volatile ("" ::: "memory");
|
|
Packit Service |
82fcde |
return;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
/* See include/dlfcn.h. Use of __libc_dlopen requires RTLD_NOW. */
|
|
Packit Service |
82fcde |
handle = __libc_dlopen (LIBGCC_S_SO);
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
if (handle == NULL
|
|
Packit Service |
82fcde |
|| (resume = __libc_dlsym (handle, "_Unwind_Resume")) == NULL
|
|
Packit Service |
82fcde |
|| (personality = __libc_dlsym (handle, "__gcc_personality_v0")) == NULL
|
|
Packit Service |
82fcde |
|| (forcedunwind = __libc_dlsym (handle, "_Unwind_ForcedUnwind"))
|
|
Packit Service |
82fcde |
== NULL
|
|
Packit Service |
82fcde |
|| (getcfa = __libc_dlsym (handle, "_Unwind_GetCFA")) == NULL
|
|
Packit Service |
82fcde |
#ifdef ARCH_CANCEL_INIT
|
|
Packit Service |
82fcde |
|| ARCH_CANCEL_INIT (handle)
|
|
Packit Service |
82fcde |
#endif
|
|
Packit Service |
82fcde |
)
|
|
Packit Service |
82fcde |
__libc_fatal (LIBGCC_S_SO " must be installed for pthread_cancel to work\n");
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
PTR_MANGLE (resume);
|
|
Packit Service |
82fcde |
__libgcc_s_resume = resume;
|
|
Packit Service |
82fcde |
PTR_MANGLE (personality);
|
|
Packit Service |
82fcde |
libgcc_s_personality = personality;
|
|
Packit Service |
82fcde |
PTR_MANGLE (forcedunwind);
|
|
Packit Service |
82fcde |
libgcc_s_forcedunwind = forcedunwind;
|
|
Packit Service |
82fcde |
PTR_MANGLE (getcfa);
|
|
Packit Service |
82fcde |
libgcc_s_getcfa = getcfa;
|
|
Packit Service |
82fcde |
/* Make sure libgcc_s_handle is written last. Otherwise,
|
|
Packit Service |
82fcde |
pthread_cancel_init might return early even when the pointer the
|
|
Packit Service |
82fcde |
caller is interested in is not initialized yet. */
|
|
Packit Service |
82fcde |
atomic_write_barrier ();
|
|
Packit Service |
82fcde |
libgcc_s_handle = handle;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
/* Register for cleanup in libpthread.so. */
|
|
Packit Service |
82fcde |
void
|
|
Packit Service |
82fcde |
__nptl_unwind_freeres (void)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
void *handle = libgcc_s_handle;
|
|
Packit Service |
82fcde |
if (handle != NULL)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
libgcc_s_handle = NULL;
|
|
Packit Service |
82fcde |
__libc_dlclose (handle);
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
#if !HAVE_ARCH_UNWIND_RESUME
|
|
Packit Service |
82fcde |
void
|
|
Packit Service |
82fcde |
_Unwind_Resume (struct _Unwind_Exception *exc)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
if (__glibc_unlikely (libgcc_s_handle == NULL))
|
|
Packit Service |
82fcde |
pthread_cancel_init ();
|
|
Packit Service |
82fcde |
else
|
|
Packit Service |
82fcde |
atomic_read_barrier ();
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
void (*resume) (struct _Unwind_Exception *exc) = __libgcc_s_resume;
|
|
Packit Service |
82fcde |
PTR_DEMANGLE (resume);
|
|
Packit Service |
82fcde |
resume (exc);
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
#endif
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
_Unwind_Reason_Code
|
|
Packit Service |
82fcde |
__gcc_personality_v0 PERSONALITY_PROTO
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
if (__glibc_unlikely (libgcc_s_handle == NULL))
|
|
Packit Service |
82fcde |
pthread_cancel_init ();
|
|
Packit Service |
82fcde |
else
|
|
Packit Service |
82fcde |
atomic_read_barrier ();
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
__typeof (libgcc_s_personality) personality = libgcc_s_personality;
|
|
Packit Service |
82fcde |
PTR_DEMANGLE (personality);
|
|
Packit Service |
82fcde |
return (*personality) PERSONALITY_ARGS;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
_Unwind_Reason_Code
|
|
Packit Service |
82fcde |
_Unwind_ForcedUnwind (struct _Unwind_Exception *exc, _Unwind_Stop_Fn stop,
|
|
Packit Service |
82fcde |
void *stop_argument)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
if (__glibc_unlikely (libgcc_s_handle == NULL))
|
|
Packit Service |
82fcde |
pthread_cancel_init ();
|
|
Packit Service |
82fcde |
else
|
|
Packit Service |
82fcde |
atomic_read_barrier ();
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
_Unwind_Reason_Code (*forcedunwind)
|
|
Packit Service |
82fcde |
(struct _Unwind_Exception *, _Unwind_Stop_Fn, void *)
|
|
Packit Service |
82fcde |
= libgcc_s_forcedunwind;
|
|
Packit Service |
82fcde |
PTR_DEMANGLE (forcedunwind);
|
|
Packit Service |
82fcde |
return forcedunwind (exc, stop, stop_argument);
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
_Unwind_Word
|
|
Packit Service |
82fcde |
_Unwind_GetCFA (struct _Unwind_Context *context)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
if (__glibc_unlikely (libgcc_s_handle == NULL))
|
|
Packit Service |
82fcde |
pthread_cancel_init ();
|
|
Packit Service |
82fcde |
else
|
|
Packit Service |
82fcde |
atomic_read_barrier ();
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
_Unwind_Word (*getcfa) (struct _Unwind_Context *) = libgcc_s_getcfa;
|
|
Packit Service |
82fcde |
PTR_DEMANGLE (getcfa);
|
|
Packit Service |
82fcde |
return getcfa (context);
|
|
Packit Service |
82fcde |
}
|