bump product version to 6.3.0.0.beta1
[LibreOffice.git] / bridges / source / cpp_uno / gcc3_ios / unwind-cxx.h
blob9a700445c12ad7b75848cb379dccd3929c79fd1e
1 // -*- C++ -*- Exception handling and frame unwind runtime interface routines.
2 // Copyright (C) 2001 Free Software Foundation, Inc.
3 //
4 // This file is part of GCC.
5 //
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)
9 // any later version.
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 "@@@".
33 #ifndef _UNWIND_CXX_H
34 #define _UNWIND_CXX_H 1
36 // Level 2: C++ ABI
38 #include <typeinfo>
39 #include <exception>
41 #include <stddef.h>
42 #include "unwind.h"
45 typedef unsigned _Unwind_Word __attribute__((__mode__(__word__)));
46 typedef signed _Unwind_Sword __attribute__((__mode__(__word__)));
47 typedef unsigned _Unwind_Word __attribute__((__mode__(__word__)));
48 typedef unsigned _Unwind_Ptr __attribute__((__mode__(__pointer__)));
49 typedef unsigned _Unwind_Exception_Class __attribute__((__mode__(__DI__)));
50 typedef unsigned _Unwind_Internal_Ptr __attribute__((__mode__(__pointer__)));
52 #pragma GCC visibility push(default)
54 namespace __cxxabiv1
57 // A C++ exception object consists of a header, which is a wrapper around
58 // an unwind object header with additional C++ specific information,
59 // followed by the exception object itself.
61 struct __cxa_exception
63 #if __LP64__
64 // This is a new field to support C++ 0x exception_ptr.
65 // For binary compatibility it is at the start of this
66 // struct which is prepended to the object thrown in
67 // __cxa_allocate_exception.
68 size_t referenceCount;
69 #endif
70 // Manage the exception object itself.
71 std::type_info *exceptionType;
72 void (*exceptionDestructor)(void *);
74 // The C++ standard has entertaining rules wrt calling set_terminate
75 // and set_unexpected in the middle of the exception cleanup process.
76 void (*unexpectedHandler)(); // std::unexpected_handler dropped from C++17
77 std::terminate_handler terminateHandler;
79 // The caught exception stack threads through here.
80 __cxa_exception *nextException;
82 // How many nested handlers have caught this exception. A negated
83 // value is a signal that this object has been rethrown.
84 int handlerCount;
86 #ifdef __ARM_EABI_UNWINDER__
87 // Stack of exceptions in cleanups.
88 __cxa_exception* nextPropagatingException;
90 // The number of active cleanup handlers for this exception.
91 int propagationCount;
92 #else
93 // Cache parsed handler data from the personality routine Phase 1
94 // for Phase 2 and __cxa_call_unexpected.
95 int handlerSwitchValue;
96 const unsigned char *actionRecord;
97 const unsigned char *languageSpecificData;
98 _Unwind_Ptr catchTemp;
99 void *adjustedPtr;
100 #endif
101 #if !__LP64__
102 // This is a new field to support C++ 0x exception_ptr.
103 // For binary compatibility it is placed where the compiler
104 // previously adding padded to 64-bit align unwindHeader.
105 size_t referenceCount;
106 #endif
108 // The generic exception header. Must be last.
109 _Unwind_Exception unwindHeader;
112 // Each thread in a C++ program has access to a __cxa_eh_globals object.
113 struct __cxa_eh_globals
115 __cxa_exception *caughtExceptions;
116 unsigned int uncaughtExceptions;
117 #ifdef __ARM_EABI_UNWINDER__
118 __cxa_exception* propagatingExceptions;
119 #endif
123 // The __cxa_eh_globals for the current thread can be obtained by using
124 // either of the following functions. The "fast" version assumes at least
125 // one prior call of __cxa_get_globals has been made from the current
126 // thread, so no initialization is necessary.
127 extern "C" __cxa_eh_globals *__cxa_get_globals () throw();
128 extern "C" __cxa_eh_globals *__cxa_get_globals_fast () throw();
130 // Allocate memory for the exception plus the thrown object.
131 extern "C" void *__cxa_allocate_exception(size_t thrown_size) throw();
133 // Free the space allocated for the exception.
134 extern "C" void __cxa_free_exception(void *thrown_exception) throw();
136 #pragma GCC visibility push(hidden)
137 extern "C" void *__cxa_allocate_dependent_exception() throw();
138 extern "C" void __cxa_free_dependent_exception(void *thrown_exception) throw();
139 #pragma GCC visibility pop
141 // Throw the exception.
142 extern "C" void __cxa_throw (void *thrown_exception,
143 std::type_info *tinfo,
144 void (*dest) (void *))
145 __attribute__((noreturn));
147 // Used to implement exception handlers.
148 extern "C" void *__cxa_get_exception_ptr (void *) throw();
149 extern "C" void *__cxa_begin_catch (void *) throw();
150 extern "C" void __cxa_end_catch ();
151 extern "C" void __cxa_rethrow () __attribute__((noreturn));
153 // These facilitate code generation for recurring situations.
154 extern "C" void __cxa_bad_cast ();
155 extern "C" void __cxa_bad_typeid ();
157 // @@@ These are not directly specified by the IA-64 C++ ABI.
159 // Handles re-checking the exception specification if unexpectedHandler
160 // throws, and if bad_exception needs to be thrown. Called from the
161 // compiler.
162 extern "C" void __cxa_call_unexpected (void *) __attribute__((noreturn));
163 extern "C" void __cxa_call_terminate (void*) __attribute__((noreturn));
165 #ifdef __ARM_EABI_UNWINDER__
166 // Arm EABI specified routines.
167 typedef enum {
168 ctm_failed = 0,
169 ctm_succeeded = 1,
170 ctm_succeeded_with_ptr_to_base = 2
171 } __cxa_type_match_result;
172 extern "C" bool __cxa_type_match(_Unwind_Exception*, const std::type_info*,
173 bool, void**);
174 extern "C" void __cxa_begin_cleanup (_Unwind_Exception*);
175 extern "C" void __cxa_end_cleanup (void);
176 #endif
178 // These are explicitly GNU C++ specific.
180 // Acquire the C++ exception header from the C++ object.
181 static inline __cxa_exception *
182 __get_exception_header_from_obj (void *ptr)
184 return reinterpret_cast<__cxa_exception *>(ptr) - 1;
187 // Acquire the C++ exception header from the generic exception header.
188 static inline __cxa_exception *
189 __get_exception_header_from_ue (_Unwind_Exception *exc)
191 return reinterpret_cast<__cxa_exception *>(exc + 1) - 1;
194 #ifdef __ARM_EABI_UNWINDER__
195 static inline bool
196 __is_gxx_exception_class(_Unwind_Exception_Class c)
198 // TODO: Take advantage of the fact that c will always be word aligned.
199 return c[0] == 'G'
200 && c[1] == 'N'
201 && c[2] == 'U'
202 && c[3] == 'C'
203 && c[4] == 'C'
204 && c[5] == '+'
205 && c[6] == '+';
208 static inline void
209 __GXX_INIT_EXCEPTION_CLASS(_Unwind_Exception_Class c)
211 c[0] = 'G';
212 c[1] = 'N';
213 c[2] = 'U';
214 c[3] = 'C';
215 c[4] = 'C';
216 c[5] = '+';
217 c[6] = '+';
218 c[7] = '\0';
221 static inline void*
222 __gxx_caught_object(_Unwind_Exception* eo)
224 return (void*)eo->barrier_cache.bitpattern[0];
226 #else // !__ARM_EABI_UNWINDER__
227 // This is the exception class we report -- "GNUCC++\0".
228 const _Unwind_Exception_Class __gxx_exception_class
229 = ((((((((_Unwind_Exception_Class) 'G'
230 << 8 | (_Unwind_Exception_Class) 'N')
231 << 8 | (_Unwind_Exception_Class) 'U')
232 << 8 | (_Unwind_Exception_Class) 'C')
233 << 8 | (_Unwind_Exception_Class) 'C')
234 << 8 | (_Unwind_Exception_Class) '+')
235 << 8 | (_Unwind_Exception_Class) '+')
236 << 8 | (_Unwind_Exception_Class) '\0');
238 static inline bool
239 __is_gxx_exception_class(_Unwind_Exception_Class c)
241 return (c & ((_Unwind_Exception_Class)~0 << 8)) == __gxx_exception_class;
244 #define __GXX_INIT_EXCEPTION_CLASS(c) c = __gxx_exception_class
246 // GNU C++ personality routine, Version 0.
247 extern "C" _Unwind_Reason_Code __gxx_personality_v0
248 (int, _Unwind_Action, _Unwind_Exception_Class,
249 struct _Unwind_Exception *, struct _Unwind_Context *);
251 // GNU C++ sjlj personality routine, Version 0.
252 extern "C" _Unwind_Reason_Code __gxx_personality_sj0
253 (int, _Unwind_Action, _Unwind_Exception_Class,
254 struct _Unwind_Exception *, struct _Unwind_Context *);
256 static inline void*
257 __gxx_caught_object(_Unwind_Exception* eo)
259 __cxa_exception* header = __get_exception_header_from_ue (eo);
260 return header->adjustedPtr;
262 #endif // !__ARM_EABI_UNWINDER__
264 } /* namespace __cxxabiv1 */
266 #pragma GCC visibility pop
268 #endif // _UNWIND_CXX_H