]>
Commit | Line | Data |
---|---|---|
52a11cbf | 1 | // -*- C++ -*- Exception handling routines for throwing. |
405feeb8 | 2 | // Copyright (C) 2001-2013 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 | ||
58 | ||
59 | extern "C" void | |
f5c48b80 | 60 | __cxxabiv1::__cxa_throw (void *obj, std::type_info *tinfo, |
2ecb85c8 | 61 | void (_GLIBCXX_CDTOR_CALLABI *dest) (void *)) |
52a11cbf | 62 | { |
30a333ce | 63 | // Definitely a primary. |
c4bca01b JJ |
64 | __cxa_refcounted_exception *header |
65 | = __get_refcounted_exception_header_from_obj (obj); | |
30a333ce | 66 | header->referenceCount = 1; |
c4bca01b JJ |
67 | header->exc.exceptionType = tinfo; |
68 | header->exc.exceptionDestructor = dest; | |
69 | header->exc.unexpectedHandler = __unexpected_handler; | |
70 | header->exc.terminateHandler = __terminate_handler; | |
71 | __GXX_INIT_PRIMARY_EXCEPTION_CLASS(header->exc.unwindHeader.exception_class); | |
72 | header->exc.unwindHeader.exception_cleanup = __gxx_exception_cleanup; | |
52a11cbf | 73 | |
3d7c150e | 74 | #ifdef _GLIBCXX_SJLJ_EXCEPTIONS |
c4bca01b | 75 | _Unwind_SjLj_RaiseException (&header->exc.unwindHeader); |
52a11cbf | 76 | #else |
c4bca01b | 77 | _Unwind_RaiseException (&header->exc.unwindHeader); |
52a11cbf RH |
78 | #endif |
79 | ||
80 | // Some sort of unwinding error. Note that terminate is a handler. | |
c4bca01b | 81 | __cxa_begin_catch (&header->exc.unwindHeader); |
52a11cbf RH |
82 | std::terminate (); |
83 | } | |
84 | ||
85 | extern "C" void | |
723acbd5 | 86 | __cxxabiv1::__cxa_rethrow () |
52a11cbf RH |
87 | { |
88 | __cxa_eh_globals *globals = __cxa_get_globals (); | |
89 | __cxa_exception *header = globals->caughtExceptions; | |
90 | ||
39609077 RH |
91 | globals->uncaughtExceptions += 1; |
92 | ||
52a11cbf RH |
93 | // Watch for luser rethrowing with no active exception. |
94 | if (header) | |
95 | { | |
96 | // Tell __cxa_end_catch this is a rethrow. | |
617a1b71 | 97 | if (!__is_gxx_exception_class(header->unwindHeader.exception_class)) |
a944ceb9 RH |
98 | globals->caughtExceptions = 0; |
99 | else | |
100 | header->handlerCount = -header->handlerCount; | |
52a11cbf | 101 | |
3d7c150e | 102 | #ifdef _GLIBCXX_SJLJ_EXCEPTIONS |
a944ceb9 | 103 | _Unwind_SjLj_Resume_or_Rethrow (&header->unwindHeader); |
ed0d100f | 104 | #else |
1dcca6f3 | 105 | #if defined(_LIBUNWIND_STD_ABI) |
ed0d100f | 106 | _Unwind_RaiseException (&header->unwindHeader); |
52a11cbf | 107 | #else |
a944ceb9 | 108 | _Unwind_Resume_or_Rethrow (&header->unwindHeader); |
ed0d100f | 109 | #endif |
52a11cbf RH |
110 | #endif |
111 | ||
112 | // Some sort of unwinding error. Note that terminate is a handler. | |
113 | __cxa_begin_catch (&header->unwindHeader); | |
114 | } | |
115 | std::terminate (); | |
116 | } |