]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/libsupc++/eh_throw.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / libsupc++ / eh_throw.cc
CommitLineData
52a11cbf 1// -*- C++ -*- Exception handling routines for throwing.
5624e564 2// Copyright (C) 2001-2015 Free Software Foundation, Inc.
52a11cbf 3//
cbecceb9 4// This file is part of GCC.
52a11cbf 5//
cbecceb9 6// GCC is free software; you can redistribute it and/or modify
52a11cbf 7// it under the terms of the GNU General Public License as published by
748086b7 8// the Free Software Foundation; either version 3, or (at your option)
52a11cbf
RH
9// any later version.
10//
cbecceb9 11// GCC is distributed in the hope that it will be useful,
52a11cbf
RH
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15//
748086b7
JJ
16// Under Section 7 of GPL version 3, you are granted additional
17// permissions described in the GCC Runtime Library Exception, version
18// 3.1, as published by the Free Software Foundation.
52a11cbf 19
748086b7
JJ
20// You should have received a copy of the GNU General Public License and
21// a copy of the GCC Runtime Library Exception along with this program;
22// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23// <http://www.gnu.org/licenses/>.
52a11cbf 24
52a11cbf
RH
25#include <bits/c++config.h>
26#include "unwind-cxx.h"
27
52a11cbf
RH
28using namespace __cxxabiv1;
29
30
31static void
32__gxx_exception_cleanup (_Unwind_Reason_Code code, _Unwind_Exception *exc)
33{
30a333ce 34 // This cleanup is set only for primaries.
c4bca01b
JJ
35 __cxa_refcounted_exception *header
36 = __get_refcounted_exception_header_from_ue (exc);
52a11cbf 37
30a333ce 38 // We only want to be called through _Unwind_DeleteException.
cb94b155 39 // _Unwind_DeleteException in the HP-UX IA64 libunwind library
30a333ce 40 // returns _URC_NO_REASON and not _URC_FOREIGN_EXCEPTION_CAUGHT
cb94b155
SE
41 // like the GCC _Unwind_DeleteException function does.
42 if (code != _URC_FOREIGN_EXCEPTION_CAUGHT && code != _URC_NO_REASON)
c4bca01b 43 __terminate (header->exc.terminateHandler);
52a11cbf 44
a152e96f 45#if ATOMIC_INT_LOCK_FREE > 1
75cee7c6 46 if (__atomic_sub_fetch (&header->referenceCount, 1, __ATOMIC_ACQ_REL) == 0)
30a333ce
PC
47 {
48#endif
c4bca01b
JJ
49 if (header->exc.exceptionDestructor)
50 header->exc.exceptionDestructor (header + 1);
52a11cbf 51
30a333ce 52 __cxa_free_exception (header + 1);
a152e96f 53#if ATOMIC_INT_LOCK_FREE > 1
30a333ce
PC
54 }
55#endif
52a11cbf
RH
56}
57
58
59extern "C" void
f5c48b80 60__cxxabiv1::__cxa_throw (void *obj, std::type_info *tinfo,
2ecb85c8 61 void (_GLIBCXX_CDTOR_CALLABI *dest) (void *))
52a11cbf 62{
83c214a8
TT
63 PROBE2 (throw, obj, tinfo);
64
ccc2e73c
JM
65 __cxa_eh_globals *globals = __cxa_get_globals ();
66 globals->uncaughtExceptions += 1;
67
30a333ce 68 // Definitely a primary.
c4bca01b
JJ
69 __cxa_refcounted_exception *header
70 = __get_refcounted_exception_header_from_obj (obj);
30a333ce 71 header->referenceCount = 1;
c4bca01b
JJ
72 header->exc.exceptionType = tinfo;
73 header->exc.exceptionDestructor = dest;
7e20f4b0
JW
74 header->exc.unexpectedHandler = std::get_unexpected ();
75 header->exc.terminateHandler = std::get_terminate ();
c4bca01b
JJ
76 __GXX_INIT_PRIMARY_EXCEPTION_CLASS(header->exc.unwindHeader.exception_class);
77 header->exc.unwindHeader.exception_cleanup = __gxx_exception_cleanup;
52a11cbf 78
3d7c150e 79#ifdef _GLIBCXX_SJLJ_EXCEPTIONS
c4bca01b 80 _Unwind_SjLj_RaiseException (&header->exc.unwindHeader);
52a11cbf 81#else
c4bca01b 82 _Unwind_RaiseException (&header->exc.unwindHeader);
52a11cbf
RH
83#endif
84
85 // Some sort of unwinding error. Note that terminate is a handler.
c4bca01b 86 __cxa_begin_catch (&header->exc.unwindHeader);
52a11cbf
RH
87 std::terminate ();
88}
89
90extern "C" void
723acbd5 91__cxxabiv1::__cxa_rethrow ()
52a11cbf
RH
92{
93 __cxa_eh_globals *globals = __cxa_get_globals ();
94 __cxa_exception *header = globals->caughtExceptions;
95
39609077
RH
96 globals->uncaughtExceptions += 1;
97
52a11cbf
RH
98 // Watch for luser rethrowing with no active exception.
99 if (header)
100 {
101 // Tell __cxa_end_catch this is a rethrow.
617a1b71 102 if (!__is_gxx_exception_class(header->unwindHeader.exception_class))
a944ceb9
RH
103 globals->caughtExceptions = 0;
104 else
83c214a8
TT
105 {
106 header->handlerCount = -header->handlerCount;
107 // Only notify probe for C++ exceptions.
108 PROBE2 (rethrow, __get_object_from_ambiguous_exception(header),
109 header->exceptionType);
110 }
52a11cbf 111
3d7c150e 112#ifdef _GLIBCXX_SJLJ_EXCEPTIONS
a944ceb9 113 _Unwind_SjLj_Resume_or_Rethrow (&header->unwindHeader);
ed0d100f 114#else
1dcca6f3 115#if defined(_LIBUNWIND_STD_ABI)
ed0d100f 116 _Unwind_RaiseException (&header->unwindHeader);
52a11cbf 117#else
a944ceb9 118 _Unwind_Resume_or_Rethrow (&header->unwindHeader);
ed0d100f 119#endif
52a11cbf
RH
120#endif
121
122 // Some sort of unwinding error. Note that terminate is a handler.
123 __cxa_begin_catch (&header->unwindHeader);
124 }
125 std::terminate ();
126}