]>
Commit | Line | Data |
---|---|---|
52a11cbf | 1 | // -*- C++ -*- Exception handling routines for throwing. |
818ab71a | 2 | // Copyright (C) 2001-2016 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 |
28 | using namespace __cxxabiv1; |
29 | ||
30 | ||
31 | static 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 | ||
27abac26 GN |
58 | extern "C" __cxa_refcounted_exception* |
59 | __cxxabiv1::__cxa_init_primary_exception(void *obj, std::type_info *tinfo, | |
60 | void (_GLIBCXX_CDTOR_CALLABI *dest) (void *)) | |
61 | { | |
62 | __cxa_refcounted_exception *header | |
63 | = __get_refcounted_exception_header_from_obj (obj); | |
64 | header->referenceCount = 0; | |
65 | header->exc.exceptionType = tinfo; | |
66 | header->exc.exceptionDestructor = dest; | |
67 | header->exc.unexpectedHandler = std::get_unexpected (); | |
68 | header->exc.terminateHandler = std::get_terminate (); | |
69 | __GXX_INIT_PRIMARY_EXCEPTION_CLASS(header->exc.unwindHeader.exception_class); | |
70 | header->exc.unwindHeader.exception_cleanup = __gxx_exception_cleanup; | |
71 | ||
72 | return header; | |
73 | } | |
52a11cbf RH |
74 | |
75 | extern "C" void | |
f5c48b80 | 76 | __cxxabiv1::__cxa_throw (void *obj, std::type_info *tinfo, |
2ecb85c8 | 77 | void (_GLIBCXX_CDTOR_CALLABI *dest) (void *)) |
52a11cbf | 78 | { |
83c214a8 TT |
79 | PROBE2 (throw, obj, tinfo); |
80 | ||
ccc2e73c JM |
81 | __cxa_eh_globals *globals = __cxa_get_globals (); |
82 | globals->uncaughtExceptions += 1; | |
30a333ce | 83 | // Definitely a primary. |
27abac26 GN |
84 | __cxa_refcounted_exception *header = |
85 | __cxa_init_primary_exception(obj, tinfo, dest); | |
30a333ce | 86 | header->referenceCount = 1; |
52a11cbf | 87 | |
9b92a9f3 | 88 | #ifdef __USING_SJLJ_EXCEPTIONS__ |
c4bca01b | 89 | _Unwind_SjLj_RaiseException (&header->exc.unwindHeader); |
52a11cbf | 90 | #else |
c4bca01b | 91 | _Unwind_RaiseException (&header->exc.unwindHeader); |
52a11cbf RH |
92 | #endif |
93 | ||
94 | // Some sort of unwinding error. Note that terminate is a handler. | |
c4bca01b | 95 | __cxa_begin_catch (&header->exc.unwindHeader); |
52a11cbf RH |
96 | std::terminate (); |
97 | } | |
98 | ||
99 | extern "C" void | |
723acbd5 | 100 | __cxxabiv1::__cxa_rethrow () |
52a11cbf RH |
101 | { |
102 | __cxa_eh_globals *globals = __cxa_get_globals (); | |
103 | __cxa_exception *header = globals->caughtExceptions; | |
104 | ||
39609077 RH |
105 | globals->uncaughtExceptions += 1; |
106 | ||
52a11cbf RH |
107 | // Watch for luser rethrowing with no active exception. |
108 | if (header) | |
109 | { | |
110 | // Tell __cxa_end_catch this is a rethrow. | |
617a1b71 | 111 | if (!__is_gxx_exception_class(header->unwindHeader.exception_class)) |
a944ceb9 RH |
112 | globals->caughtExceptions = 0; |
113 | else | |
83c214a8 TT |
114 | { |
115 | header->handlerCount = -header->handlerCount; | |
116 | // Only notify probe for C++ exceptions. | |
117 | PROBE2 (rethrow, __get_object_from_ambiguous_exception(header), | |
118 | header->exceptionType); | |
119 | } | |
52a11cbf | 120 | |
9b92a9f3 | 121 | #ifdef __USING_SJLJ_EXCEPTIONS__ |
a944ceb9 | 122 | _Unwind_SjLj_Resume_or_Rethrow (&header->unwindHeader); |
ed0d100f | 123 | #else |
1dcca6f3 | 124 | #if defined(_LIBUNWIND_STD_ABI) |
ed0d100f | 125 | _Unwind_RaiseException (&header->unwindHeader); |
52a11cbf | 126 | #else |
a944ceb9 | 127 | _Unwind_Resume_or_Rethrow (&header->unwindHeader); |
ed0d100f | 128 | #endif |
52a11cbf RH |
129 | #endif |
130 | ||
131 | // Some sort of unwinding error. Note that terminate is a handler. | |
132 | __cxa_begin_catch (&header->unwindHeader); | |
133 | } | |
134 | std::terminate (); | |
135 | } |