annotate libstdc++-v3/libsupc++/eh_throw.cc @ 118:fd00160c1b76

ifdef TARGET_64BIT
author mir3636
date Tue, 27 Feb 2018 15:01:35 +0900
parents 04ced10e8804
children 84e7813d76e9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 // -*- C++ -*- Exception handling routines for throwing.
kono
parents:
diff changeset
2 // Copyright (C) 2001-2017 Free Software Foundation, Inc.
kono
parents:
diff changeset
3 //
kono
parents:
diff changeset
4 // This file is part of GCC.
kono
parents:
diff changeset
5 //
kono
parents:
diff changeset
6 // GCC is free software; you can redistribute it and/or modify
kono
parents:
diff changeset
7 // it under the terms of the GNU General Public License as published by
kono
parents:
diff changeset
8 // the Free Software Foundation; either version 3, or (at your option)
kono
parents:
diff changeset
9 // any later version.
kono
parents:
diff changeset
10 //
kono
parents:
diff changeset
11 // GCC is distributed in the hope that it will be useful,
kono
parents:
diff changeset
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
kono
parents:
diff changeset
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
kono
parents:
diff changeset
14 // GNU General Public License for more details.
kono
parents:
diff changeset
15 //
kono
parents:
diff changeset
16 // Under Section 7 of GPL version 3, you are granted additional
kono
parents:
diff changeset
17 // permissions described in the GCC Runtime Library Exception, version
kono
parents:
diff changeset
18 // 3.1, as published by the Free Software Foundation.
kono
parents:
diff changeset
19
kono
parents:
diff changeset
20 // You should have received a copy of the GNU General Public License and
kono
parents:
diff changeset
21 // a copy of the GCC Runtime Library Exception along with this program;
kono
parents:
diff changeset
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
kono
parents:
diff changeset
23 // <http://www.gnu.org/licenses/>.
kono
parents:
diff changeset
24
kono
parents:
diff changeset
25 #include <bits/c++config.h>
kono
parents:
diff changeset
26 #include "unwind-cxx.h"
kono
parents:
diff changeset
27 #include "eh_atomics.h"
kono
parents:
diff changeset
28
kono
parents:
diff changeset
29 using namespace __cxxabiv1;
kono
parents:
diff changeset
30
kono
parents:
diff changeset
31
kono
parents:
diff changeset
32 static void
kono
parents:
diff changeset
33 __gxx_exception_cleanup (_Unwind_Reason_Code code, _Unwind_Exception *exc)
kono
parents:
diff changeset
34 {
kono
parents:
diff changeset
35 // This cleanup is set only for primaries.
kono
parents:
diff changeset
36 __cxa_refcounted_exception *header
kono
parents:
diff changeset
37 = __get_refcounted_exception_header_from_ue (exc);
kono
parents:
diff changeset
38
kono
parents:
diff changeset
39 // We only want to be called through _Unwind_DeleteException.
kono
parents:
diff changeset
40 // _Unwind_DeleteException in the HP-UX IA64 libunwind library
kono
parents:
diff changeset
41 // returns _URC_NO_REASON and not _URC_FOREIGN_EXCEPTION_CAUGHT
kono
parents:
diff changeset
42 // like the GCC _Unwind_DeleteException function does.
kono
parents:
diff changeset
43 if (code != _URC_FOREIGN_EXCEPTION_CAUGHT && code != _URC_NO_REASON)
kono
parents:
diff changeset
44 __terminate (header->exc.terminateHandler);
kono
parents:
diff changeset
45
kono
parents:
diff changeset
46 if (__gnu_cxx::__eh_atomic_dec (&header->referenceCount))
kono
parents:
diff changeset
47 {
kono
parents:
diff changeset
48 if (header->exc.exceptionDestructor)
kono
parents:
diff changeset
49 header->exc.exceptionDestructor (header + 1);
kono
parents:
diff changeset
50
kono
parents:
diff changeset
51 __cxa_free_exception (header + 1);
kono
parents:
diff changeset
52 }
kono
parents:
diff changeset
53 }
kono
parents:
diff changeset
54
kono
parents:
diff changeset
55 extern "C" __cxa_refcounted_exception*
kono
parents:
diff changeset
56 __cxxabiv1::__cxa_init_primary_exception(void *obj, std::type_info *tinfo,
kono
parents:
diff changeset
57 void (_GLIBCXX_CDTOR_CALLABI *dest) (void *))
kono
parents:
diff changeset
58 {
kono
parents:
diff changeset
59 __cxa_refcounted_exception *header
kono
parents:
diff changeset
60 = __get_refcounted_exception_header_from_obj (obj);
kono
parents:
diff changeset
61 header->referenceCount = 0;
kono
parents:
diff changeset
62 header->exc.exceptionType = tinfo;
kono
parents:
diff changeset
63 header->exc.exceptionDestructor = dest;
kono
parents:
diff changeset
64 header->exc.unexpectedHandler = std::get_unexpected ();
kono
parents:
diff changeset
65 header->exc.terminateHandler = std::get_terminate ();
kono
parents:
diff changeset
66 __GXX_INIT_PRIMARY_EXCEPTION_CLASS(header->exc.unwindHeader.exception_class);
kono
parents:
diff changeset
67 header->exc.unwindHeader.exception_cleanup = __gxx_exception_cleanup;
kono
parents:
diff changeset
68
kono
parents:
diff changeset
69 return header;
kono
parents:
diff changeset
70 }
kono
parents:
diff changeset
71
kono
parents:
diff changeset
72 extern "C" void
kono
parents:
diff changeset
73 __cxxabiv1::__cxa_throw (void *obj, std::type_info *tinfo,
kono
parents:
diff changeset
74 void (_GLIBCXX_CDTOR_CALLABI *dest) (void *))
kono
parents:
diff changeset
75 {
kono
parents:
diff changeset
76 PROBE2 (throw, obj, tinfo);
kono
parents:
diff changeset
77
kono
parents:
diff changeset
78 __cxa_eh_globals *globals = __cxa_get_globals ();
kono
parents:
diff changeset
79 globals->uncaughtExceptions += 1;
kono
parents:
diff changeset
80 // Definitely a primary.
kono
parents:
diff changeset
81 __cxa_refcounted_exception *header =
kono
parents:
diff changeset
82 __cxa_init_primary_exception(obj, tinfo, dest);
kono
parents:
diff changeset
83 header->referenceCount = 1;
kono
parents:
diff changeset
84
kono
parents:
diff changeset
85 #ifdef __USING_SJLJ_EXCEPTIONS__
kono
parents:
diff changeset
86 _Unwind_SjLj_RaiseException (&header->exc.unwindHeader);
kono
parents:
diff changeset
87 #else
kono
parents:
diff changeset
88 _Unwind_RaiseException (&header->exc.unwindHeader);
kono
parents:
diff changeset
89 #endif
kono
parents:
diff changeset
90
kono
parents:
diff changeset
91 // Some sort of unwinding error. Note that terminate is a handler.
kono
parents:
diff changeset
92 __cxa_begin_catch (&header->exc.unwindHeader);
kono
parents:
diff changeset
93 std::terminate ();
kono
parents:
diff changeset
94 }
kono
parents:
diff changeset
95
kono
parents:
diff changeset
96 extern "C" void
kono
parents:
diff changeset
97 __cxxabiv1::__cxa_rethrow ()
kono
parents:
diff changeset
98 {
kono
parents:
diff changeset
99 __cxa_eh_globals *globals = __cxa_get_globals ();
kono
parents:
diff changeset
100 __cxa_exception *header = globals->caughtExceptions;
kono
parents:
diff changeset
101
kono
parents:
diff changeset
102 globals->uncaughtExceptions += 1;
kono
parents:
diff changeset
103
kono
parents:
diff changeset
104 // Watch for luser rethrowing with no active exception.
kono
parents:
diff changeset
105 if (header)
kono
parents:
diff changeset
106 {
kono
parents:
diff changeset
107 // Tell __cxa_end_catch this is a rethrow.
kono
parents:
diff changeset
108 if (!__is_gxx_exception_class(header->unwindHeader.exception_class))
kono
parents:
diff changeset
109 globals->caughtExceptions = 0;
kono
parents:
diff changeset
110 else
kono
parents:
diff changeset
111 {
kono
parents:
diff changeset
112 header->handlerCount = -header->handlerCount;
kono
parents:
diff changeset
113 // Only notify probe for C++ exceptions.
kono
parents:
diff changeset
114 PROBE2 (rethrow, __get_object_from_ambiguous_exception(header),
kono
parents:
diff changeset
115 header->exceptionType);
kono
parents:
diff changeset
116 }
kono
parents:
diff changeset
117
kono
parents:
diff changeset
118 #ifdef __USING_SJLJ_EXCEPTIONS__
kono
parents:
diff changeset
119 _Unwind_SjLj_Resume_or_Rethrow (&header->unwindHeader);
kono
parents:
diff changeset
120 #else
kono
parents:
diff changeset
121 #if defined(_LIBUNWIND_STD_ABI)
kono
parents:
diff changeset
122 _Unwind_RaiseException (&header->unwindHeader);
kono
parents:
diff changeset
123 #else
kono
parents:
diff changeset
124 _Unwind_Resume_or_Rethrow (&header->unwindHeader);
kono
parents:
diff changeset
125 #endif
kono
parents:
diff changeset
126 #endif
kono
parents:
diff changeset
127
kono
parents:
diff changeset
128 // Some sort of unwinding error. Note that terminate is a handler.
kono
parents:
diff changeset
129 __cxa_begin_catch (&header->unwindHeader);
kono
parents:
diff changeset
130 }
kono
parents:
diff changeset
131 std::terminate ();
kono
parents:
diff changeset
132 }