1 // -*- C++ -*- Exception handling and frame unwind runtime interface routines.
2 // Copyright (C) 2001 Free Software Foundation, Inc.
4 // This file is part of GCC.
6 // GCC is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2, or (at your option)
11 // GCC is distributed in the hope that it will be useful,
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.
16 // You should have received a copy of the GNU General Public License
17 // along with GCC; see the file COPYING. If not, write to
18 // the Free Software Foundation, 51 Franklin Street, Fifth Floor,
19 // Boston, MA 02110-1301, USA.
21 // As a special exception, you may use this file as part of a free software
22 // library without restriction. Specifically, if other files instantiate
23 // templates or use macros or inline functions from this file, or you compile
24 // this file and link it with other files to produce an executable, this
25 // file does not by itself cause the resulting executable to be covered by
26 // the GNU General Public License. This exception does not however
27 // invalidate any other reasons why the executable file might be covered by
28 // the GNU General Public License.
30 // This is derived from the C++ ABI for IA-64. Where we diverge
31 // for cross-architecture compatibility are noted with "@@@".
34 #define _UNWIND_CXX_H 1
43 #pragma GCC visibility push(default)
48 // A C++ exception object consists of a header, which is a wrapper around
49 // an unwind object header with additional C++ specific information,
50 // followed by the exception object itself.
52 struct __cxa_exception
54 // Manage the exception object itself.
55 std::type_info
*exceptionType
;
56 void (*exceptionDestructor
)(void *);
58 // The C++ standard has entertaining rules wrt calling set_terminate
59 // and set_unexpected in the middle of the exception cleanup process.
60 std::unexpected_handler unexpectedHandler
;
61 std::terminate_handler terminateHandler
;
63 // The caught exception stack threads through here.
64 __cxa_exception
*nextException
;
66 // How many nested handlers have caught this exception. A negated
67 // value is a signal that this object has been rethrown.
70 #ifdef __ARM_EABI_UNWINDER__
71 // Stack of exceptions in cleanups.
72 __cxa_exception
* nextPropagatingException
;
74 // The nuber of active cleanup handlers for this exception.
77 // Cache parsed handler data from the personality routine Phase 1
78 // for Phase 2 and __cxa_call_unexpected.
79 int handlerSwitchValue
;
80 const unsigned char *actionRecord
;
81 const unsigned char *languageSpecificData
;
82 _Unwind_Ptr catchTemp
;
86 // The generic exception header. Must be last.
87 _Unwind_Exception unwindHeader
;
90 // Each thread in a C++ program has access to a __cxa_eh_globals object.
91 struct __cxa_eh_globals
93 __cxa_exception
*caughtExceptions
;
94 unsigned int uncaughtExceptions
;
95 #ifdef __ARM_EABI_UNWINDER__
96 __cxa_exception
* propagatingExceptions
;
101 // The __cxa_eh_globals for the current thread can be obtained by using
102 // either of the following functions. The "fast" version assumes at least
103 // one prior call of __cxa_get_globals has been made from the current
104 // thread, so no initialization is necessary.
105 extern "C" __cxa_eh_globals
*__cxa_get_globals () throw();
106 extern "C" __cxa_eh_globals
*__cxa_get_globals_fast () throw();
108 // Allocate memory for the exception plus the thown object.
109 extern "C" void *__cxa_allocate_exception(std::size_t thrown_size
) throw();
111 // Free the space allocated for the exception.
112 extern "C" void __cxa_free_exception(void *thrown_exception
) throw();
114 // Throw the exception.
115 extern "C" void __cxa_throw (void *thrown_exception
,
116 std::type_info
*tinfo
,
117 void (*dest
) (void *))
118 __attribute__((noreturn
));
120 // Used to implement exception handlers.
121 extern "C" void *__cxa_get_exception_ptr (void *) throw();
122 extern "C" void *__cxa_begin_catch (void *) throw();
123 extern "C" void __cxa_end_catch ();
124 extern "C" void __cxa_rethrow () __attribute__((noreturn
));
126 // These facilitate code generation for recurring situations.
127 extern "C" void __cxa_bad_cast ();
128 extern "C" void __cxa_bad_typeid ();
130 // @@@ These are not directly specified by the IA-64 C++ ABI.
132 // Handles re-checking the exception specification if unexpectedHandler
133 // throws, and if bad_exception needs to be thrown. Called from the
135 extern "C" void __cxa_call_unexpected (void *) __attribute__((noreturn
));
136 extern "C" void __cxa_call_terminate (void*) __attribute__((noreturn
));
138 #ifdef __ARM_EABI_UNWINDER__
139 // Arm EABI specified routines.
143 ctm_succeeded_with_ptr_to_base
= 2
144 } __cxa_type_match_result
;
145 extern "C" bool __cxa_type_match(_Unwind_Exception
*, const std::type_info
*,
147 extern "C" void __cxa_begin_cleanup (_Unwind_Exception
*);
148 extern "C" void __cxa_end_cleanup (void);
151 // Invokes given handler, dying appropriately if the user handler was
152 // so inconsiderate as to return.
153 extern void __terminate(std::terminate_handler
) __attribute__((noreturn
));
154 extern void __unexpected(std::unexpected_handler
) __attribute__((noreturn
));
156 // The current installed user handlers.
157 extern std::terminate_handler __terminate_handler
;
158 extern std::unexpected_handler __unexpected_handler
;
160 // These are explicitly GNU C++ specific.
162 // Acquire the C++ exception header from the C++ object.
163 static inline __cxa_exception
*
164 __get_exception_header_from_obj (void *ptr
)
166 return reinterpret_cast<__cxa_exception
*>(ptr
) - 1;
169 // Acquire the C++ exception header from the generic exception header.
170 static inline __cxa_exception
*
171 __get_exception_header_from_ue (_Unwind_Exception
*exc
)
173 return reinterpret_cast<__cxa_exception
*>(exc
+ 1) - 1;
176 #ifdef __ARM_EABI_UNWINDER__
178 __is_gxx_exception_class(_Unwind_Exception_Class c
)
180 // TODO: Take advantage of the fact that c will always be word aligned.
192 __GXX_INIT_EXCEPTION_CLASS(_Unwind_Exception_Class c
)
205 __is_gxx_forced_unwind_class(_Unwind_Exception_Class c
)
218 __GXX_INIT_FORCED_UNWIND_CLASS(_Unwind_Exception_Class c
)
231 __gxx_caught_object(_Unwind_Exception
* eo
)
233 return (void*)eo
->barrier_cache
.bitpattern
[0];
235 #else // !__ARM_EABI_UNWINDER__
236 // This is the exception class we report -- "GNUCC++\0".
237 const _Unwind_Exception_Class __gxx_exception_class
238 = ((((((((_Unwind_Exception_Class
) 'G'
239 << 8 | (_Unwind_Exception_Class
) 'N')
240 << 8 | (_Unwind_Exception_Class
) 'U')
241 << 8 | (_Unwind_Exception_Class
) 'C')
242 << 8 | (_Unwind_Exception_Class
) 'C')
243 << 8 | (_Unwind_Exception_Class
) '+')
244 << 8 | (_Unwind_Exception_Class
) '+')
245 << 8 | (_Unwind_Exception_Class
) '\0');
248 __is_gxx_exception_class(_Unwind_Exception_Class c
)
250 return c
== __gxx_exception_class
;
253 #define __GXX_INIT_EXCEPTION_CLASS(c) c = __gxx_exception_class
255 // GNU C++ personality routine, Version 0.
256 extern "C" _Unwind_Reason_Code __gxx_personality_v0
257 (int, _Unwind_Action
, _Unwind_Exception_Class
,
258 struct _Unwind_Exception
*, struct _Unwind_Context
*);
260 // GNU C++ sjlj personality routine, Version 0.
261 extern "C" _Unwind_Reason_Code __gxx_personality_sj0
262 (int, _Unwind_Action
, _Unwind_Exception_Class
,
263 struct _Unwind_Exception
*, struct _Unwind_Context
*);
266 __gxx_caught_object(_Unwind_Exception
* eo
)
268 __cxa_exception
* header
= __get_exception_header_from_ue (eo
);
269 return header
->adjustedPtr
;
271 #endif // !__ARM_EABI_UNWINDER__
273 } /* namespace __cxxabiv1 */
275 #pragma GCC visibility pop
277 #endif // _UNWIND_CXX_H