2020-01-01 08:14:33 +08:00
|
|
|
/* Copyright (C) 2003-2020 Free Software Foundation, Inc.
|
2003-04-12 08:58:26 +08:00
|
|
|
This file is part of the GNU C Library.
|
|
|
|
Contributed by Ulrich Drepper <drepper@redhat.com>
|
|
|
|
and Richard Henderson <rth@redhat.com>, 2003.
|
|
|
|
|
|
|
|
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-10 07:18:22 +08:00
|
|
|
License along with the GNU C Library; if not, see
|
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 13:40:42 +08:00
|
|
|
<https://www.gnu.org/licenses/>. */
|
2003-04-12 08:58:26 +08:00
|
|
|
|
|
|
|
#include <setjmp.h>
|
2014-11-21 05:58:03 +08:00
|
|
|
#include <stdio.h>
|
2003-04-12 08:58:26 +08:00
|
|
|
#include <stdlib.h>
|
2003-08-01 03:26:38 +08:00
|
|
|
#include <string.h>
|
2003-05-17 01:40:49 +08:00
|
|
|
#include <unistd.h>
|
2003-04-12 08:58:26 +08:00
|
|
|
#include "pthreadP.h"
|
2020-10-31 05:38:31 +08:00
|
|
|
#include <libc-diag.h>
|
2005-12-22 06:54:00 +08:00
|
|
|
#include <jmpbuf-unwind.h>
|
2003-04-12 08:58:26 +08:00
|
|
|
|
2003-11-06 12:29:42 +08:00
|
|
|
#ifdef _STACK_GROWS_DOWN
|
2003-12-19 09:37:13 +08:00
|
|
|
# define FRAME_LEFT(frame, other, adj) \
|
|
|
|
((uintptr_t) frame - adj >= (uintptr_t) other - adj)
|
2003-11-06 12:29:42 +08:00
|
|
|
#elif _STACK_GROWS_UP
|
2003-12-19 09:37:13 +08:00
|
|
|
# define FRAME_LEFT(frame, other, adj) \
|
|
|
|
((uintptr_t) frame - adj <= (uintptr_t) other - adj)
|
2003-11-06 12:29:42 +08:00
|
|
|
#else
|
|
|
|
# error "Define either _STACK_GROWS_DOWN or _STACK_GROWS_UP"
|
|
|
|
#endif
|
|
|
|
|
2003-04-12 08:58:26 +08:00
|
|
|
static _Unwind_Reason_Code
|
|
|
|
unwind_stop (int version, _Unwind_Action actions,
|
|
|
|
_Unwind_Exception_Class exc_class,
|
|
|
|
struct _Unwind_Exception *exc_obj,
|
|
|
|
struct _Unwind_Context *context, void *stop_parameter)
|
|
|
|
{
|
|
|
|
struct pthread_unwind_buf *buf = stop_parameter;
|
2003-11-06 12:29:42 +08:00
|
|
|
struct pthread *self = THREAD_SELF;
|
|
|
|
struct _pthread_cleanup_buffer *curp = THREAD_GETMEM (self, cleanup);
|
|
|
|
int do_longjump = 0;
|
2004-09-03 06:47:23 +08:00
|
|
|
|
2003-12-19 09:37:13 +08:00
|
|
|
/* Adjust all pointers used in comparisons, so that top of thread's
|
|
|
|
stack is at the top of address space. Without that, things break
|
|
|
|
if stack is allocated above the main stack. */
|
|
|
|
uintptr_t adj = (uintptr_t) self->stackblock + self->stackblock_size;
|
2003-04-12 08:58:26 +08:00
|
|
|
|
|
|
|
/* Do longjmp if we're at "end of stack", aka "end of unwind data".
|
|
|
|
We assume there are only C frame without unwind data in between
|
|
|
|
here and the jmp_buf target. Otherwise simply note that the CFA
|
|
|
|
of a function is NOT within it's stack frame; it's the SP of the
|
|
|
|
previous frame. */
|
|
|
|
if ((actions & _UA_END_OF_STACK)
|
2003-12-19 09:37:13 +08:00
|
|
|
|| ! _JMPBUF_CFA_UNWINDS_ADJ (buf->cancel_jmp_buf[0].jmp_buf, context,
|
|
|
|
adj))
|
2003-11-06 12:29:42 +08:00
|
|
|
do_longjump = 1;
|
|
|
|
|
2014-02-10 21:45:42 +08:00
|
|
|
if (__glibc_unlikely (curp != NULL))
|
2003-11-06 12:29:42 +08:00
|
|
|
{
|
|
|
|
/* Handle the compatibility stuff. Execute all handlers
|
|
|
|
registered with the old method which would be unwound by this
|
|
|
|
step. */
|
|
|
|
struct _pthread_cleanup_buffer *oldp = buf->priv.data.cleanup;
|
2012-03-20 04:34:44 +08:00
|
|
|
void *cfa = (void *) (_Unwind_Ptr) _Unwind_GetCFA (context);
|
2003-11-06 12:29:42 +08:00
|
|
|
|
2003-12-19 09:37:13 +08:00
|
|
|
if (curp != oldp && (do_longjump || FRAME_LEFT (cfa, curp, adj)))
|
2003-11-06 12:29:42 +08:00
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
|
|
|
/* Pointer to the next element. */
|
|
|
|
struct _pthread_cleanup_buffer *nextp = curp->__prev;
|
|
|
|
|
|
|
|
/* Call the handler. */
|
|
|
|
curp->__routine (curp->__arg);
|
|
|
|
|
|
|
|
/* To the next. */
|
|
|
|
curp = nextp;
|
|
|
|
}
|
2003-12-19 09:37:13 +08:00
|
|
|
while (curp != oldp
|
|
|
|
&& (do_longjump || FRAME_LEFT (cfa, curp, adj)));
|
2003-11-06 12:29:42 +08:00
|
|
|
|
|
|
|
/* Mark the current element as handled. */
|
|
|
|
THREAD_SETMEM (self, cleanup, curp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-31 05:38:31 +08:00
|
|
|
DIAG_PUSH_NEEDS_COMMENT;
|
|
|
|
#if __GNUC_PREREQ (7, 0)
|
|
|
|
/* This call results in a -Wstringop-overflow warning because struct
|
|
|
|
pthread_unwind_buf is smaller than jmp_buf. setjmp and longjmp
|
|
|
|
do not use anything beyond the common prefix (they never access
|
|
|
|
the saved signal mask), so that is a false positive. */
|
|
|
|
DIAG_IGNORE_NEEDS_COMMENT (11, "-Wstringop-overflow=");
|
|
|
|
#endif
|
2003-11-06 12:29:42 +08:00
|
|
|
if (do_longjump)
|
2004-09-03 06:47:23 +08:00
|
|
|
__libc_unwind_longjmp ((struct __jmp_buf_tag *) buf->cancel_jmp_buf, 1);
|
2020-10-31 05:38:31 +08:00
|
|
|
DIAG_POP_NEEDS_COMMENT;
|
2003-04-12 08:58:26 +08:00
|
|
|
|
|
|
|
return _URC_NO_REASON;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
unwind_cleanup (_Unwind_Reason_Code reason, struct _Unwind_Exception *exc)
|
|
|
|
{
|
2003-05-09 11:00:52 +08:00
|
|
|
/* When we get here a C++ catch block didn't rethrow the object. We
|
|
|
|
cannot handle this case and therefore abort. */
|
2014-11-21 05:58:03 +08:00
|
|
|
__libc_fatal ("FATAL: exception not rethrown\n");
|
2003-04-12 08:58:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
__cleanup_fct_attribute __attribute ((noreturn))
|
|
|
|
__pthread_unwind (__pthread_unwind_buf_t *buf)
|
|
|
|
{
|
|
|
|
struct pthread_unwind_buf *ibuf = (struct pthread_unwind_buf *) buf;
|
|
|
|
struct pthread *self = THREAD_SELF;
|
|
|
|
|
2003-11-06 12:29:42 +08:00
|
|
|
/* This is not a catchable exception, so don't provide any details about
|
|
|
|
the exception type. We do need to initialize the field though. */
|
|
|
|
THREAD_SETMEM (self, exc.exception_class, 0);
|
2012-11-27 08:42:38 +08:00
|
|
|
THREAD_SETMEM (self, exc.exception_cleanup, &unwind_cleanup);
|
2003-11-06 12:29:42 +08:00
|
|
|
|
|
|
|
_Unwind_ForcedUnwind (&self->exc, unwind_stop, ibuf);
|
2003-04-12 08:58:26 +08:00
|
|
|
/* NOTREACHED */
|
|
|
|
|
|
|
|
/* We better do not get here. */
|
|
|
|
abort ();
|
|
|
|
}
|
2003-07-03 15:37:59 +08:00
|
|
|
hidden_def (__pthread_unwind)
|
2003-04-12 08:58:26 +08:00
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
__cleanup_fct_attribute __attribute ((noreturn))
|
|
|
|
__pthread_unwind_next (__pthread_unwind_buf_t *buf)
|
|
|
|
{
|
|
|
|
struct pthread_unwind_buf *ibuf = (struct pthread_unwind_buf *) buf;
|
|
|
|
|
2003-05-31 15:50:12 +08:00
|
|
|
__pthread_unwind ((__pthread_unwind_buf_t *) ibuf->priv.data.prev);
|
2003-04-12 08:58:26 +08:00
|
|
|
}
|
2003-07-09 05:08:13 +08:00
|
|
|
hidden_def (__pthread_unwind_next)
|