2020-01-01 00:14:33 +00:00
|
|
|
/* Copyright (C) 2003-2020 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
|
Prefer https to http for gnu.org and fsf.org URLs
Also, change sources.redhat.com to sourceware.org.
This patch was automatically generated by running the following shell
script, which uses GNU sed, and which avoids modifying files imported
from upstream:
sed -ri '
s,(http|ftp)(://(.*\.)?(gnu|fsf|sourceware)\.org($|[^.]|\.[^a-z])),https\2,g
s,(http|ftp)(://(.*\.)?)sources\.redhat\.com($|[^.]|\.[^a-z]),https\2sourceware.org\4,g
' \
$(find $(git ls-files) -prune -type f \
! -name '*.po' \
! -name 'ChangeLog*' \
! -path COPYING ! -path COPYING.LIB \
! -path manual/fdl-1.3.texi ! -path manual/lgpl-2.1.texi \
! -path manual/texinfo.tex ! -path scripts/config.guess \
! -path scripts/config.sub ! -path scripts/install-sh \
! -path scripts/mkinstalldirs ! -path scripts/move-if-change \
! -path INSTALL ! -path locale/programs/charmap-kw.h \
! -path po/libc.pot ! -path sysdeps/gnu/errlist.c \
! '(' -name configure \
-execdir test -f configure.ac -o -f configure.in ';' ')' \
! '(' -name preconfigure \
-execdir test -f preconfigure.ac ';' ')' \
-print)
and then by running 'make dist-prepare' to regenerate files built
from the altered files, and then executing the following to cleanup:
chmod a+x sysdeps/unix/sysv/linux/riscv/configure
# Omit irrelevant whitespace and comment-only changes,
# perhaps from a slightly-different Autoconf version.
git checkout -f \
sysdeps/csky/configure \
sysdeps/hppa/configure \
sysdeps/riscv/configure \
sysdeps/unix/sysv/linux/csky/configure
# Omit changes that caused a pre-commit check to fail like this:
# remote: *** error: sysdeps/powerpc/powerpc64/ppc-mcount.S: trailing lines
git checkout -f \
sysdeps/powerpc/powerpc64/ppc-mcount.S \
sysdeps/unix/sysv/linux/s390/s390-64/syscall.S
# Omit change that caused a pre-commit check to fail like this:
# remote: *** error: sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S: last line does not end in newline
git checkout -f sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S
2019-09-07 05:40:42 +00:00
|
|
|
not, see <https://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>
|
2015-01-05 22:01:49 +00:00
|
|
|
#include <unwind-resume.h>
|
2003-07-22 23:56:53 +00:00
|
|
|
|
2009-01-29 20:38:04 +00:00
|
|
|
static void *libgcc_s_handle;
|
2015-01-05 22:01:49 +00:00
|
|
|
void (*__libgcc_s_resume) (struct _Unwind_Exception *exc)
|
|
|
|
attribute_hidden __attribute__ ((noreturn));
|
|
|
|
static _Unwind_Reason_Code (*libgcc_s_personality) PERSONALITY_PROTO;
|
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;
|
|
|
|
|
2014-02-10 13:45:42 +00:00
|
|
|
if (__glibc_likely (libgcc_s_handle != NULL))
|
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
|
|
|
|
2018-04-26 13:41:43 +00:00
|
|
|
/* See include/dlfcn.h. Use of __libc_dlopen requires RTLD_NOW. */
|
|
|
|
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);
|
2015-01-05 22:01:49 +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;
|
|
|
|
}
|
|
|
|
|
2018-06-22 13:28:47 +00:00
|
|
|
/* Register for cleanup in libpthread.so. */
|
2009-01-29 20:38:04 +00:00
|
|
|
void
|
2018-06-22 13:28:47 +00:00
|
|
|
__nptl_unwind_freeres (void)
|
2009-01-29 20:38:04 +00:00
|
|
|
{
|
|
|
|
void *handle = libgcc_s_handle;
|
|
|
|
if (handle != NULL)
|
|
|
|
{
|
|
|
|
libgcc_s_handle = NULL;
|
|
|
|
__libc_dlclose (handle);
|
|
|
|
}
|
2003-07-22 23:56:53 +00:00
|
|
|
}
|
|
|
|
|
2015-01-05 22:01:49 +00:00
|
|
|
#if !HAVE_ARCH_UNWIND_RESUME
|
2003-07-22 23:56:53 +00:00
|
|
|
void
|
|
|
|
_Unwind_Resume (struct _Unwind_Exception *exc)
|
|
|
|
{
|
2014-02-10 13:45:42 +00:00
|
|
|
if (__glibc_unlikely (libgcc_s_handle == NULL))
|
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
|
|
|
|
2015-01-05 22:01:49 +00:00
|
|
|
void (*resume) (struct _Unwind_Exception *exc) = __libgcc_s_resume;
|
2009-01-29 20:52:36 +00:00
|
|
|
PTR_DEMANGLE (resume);
|
|
|
|
resume (exc);
|
2003-07-22 23:56:53 +00:00
|
|
|
}
|
2015-01-05 22:01:49 +00:00
|
|
|
#endif
|
2003-07-22 23:56:53 +00:00
|
|
|
|
|
|
|
_Unwind_Reason_Code
|
2015-01-05 22:01:49 +00:00
|
|
|
__gcc_personality_v0 PERSONALITY_PROTO
|
2003-07-22 23:56:53 +00:00
|
|
|
{
|
2014-02-10 13:45:42 +00:00
|
|
|
if (__glibc_unlikely (libgcc_s_handle == NULL))
|
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
|
|
|
|
2015-01-05 22:01:49 +00:00
|
|
|
__typeof (libgcc_s_personality) personality = libgcc_s_personality;
|
2009-01-29 20:52:36 +00:00
|
|
|
PTR_DEMANGLE (personality);
|
2015-01-05 22:01:49 +00:00
|
|
|
return (*personality) PERSONALITY_ARGS;
|
2003-07-22 23:56:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_Unwind_Reason_Code
|
|
|
|
_Unwind_ForcedUnwind (struct _Unwind_Exception *exc, _Unwind_Stop_Fn stop,
|
|
|
|
void *stop_argument)
|
|
|
|
{
|
2014-02-10 13:45:42 +00:00
|
|
|
if (__glibc_unlikely (libgcc_s_handle == NULL))
|
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)
|
|
|
|
{
|
2014-02-10 13:45:42 +00:00
|
|
|
if (__glibc_unlikely (libgcc_s_handle == NULL))
|
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
|
|
|
}
|