LibreOffice Module bridges (master) 1
unwind-cxx.h
Go to the documentation of this file.
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.
10//
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.
15//
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.
20
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.
29
30// This is derived from the C++ ABI for IA-64. Where we diverge
31// for cross-architecture compatibility are noted with "@@@".
32
33#ifndef _UNWIND_CXX_H
34#define _UNWIND_CXX_H 1
35
36// Level 2: C++ ABI
37
38#include <typeinfo>
39#include <exception>
40
41#include <stddef.h>
42#include "unwind.h"
43
44
45typedef unsigned _Unwind_Word __attribute__((__mode__(__word__)));
46typedef signed _Unwind_Sword __attribute__((__mode__(__word__)));
47typedef unsigned _Unwind_Word __attribute__((__mode__(__word__)));
48typedef unsigned _Unwind_Ptr __attribute__((__mode__(__pointer__)));
49#if !defined __IPHONE_16_4 || __IPHONE_OS_VERSION_MAX_ALLOWED < __IPHONE_16_4
50typedef unsigned _Unwind_Exception_Class __attribute__((__mode__(__DI__)));
51#endif
52typedef unsigned _Unwind_Internal_Ptr __attribute__((__mode__(__pointer__)));
53
54#pragma GCC visibility push(default)
55
56namespace __cxxabiv1
57{
58
59// A C++ exception object consists of a header, which is a wrapper around
60// an unwind object header with additional C++ specific information,
61// followed by the exception object itself.
62
64{
65#if __LP64__
66#if 0
67 // This is a new field added with LLVM 10
68 // <https://github.com/llvm/llvm-project/commit/674ec1eb16678b8addc02a4b0534ab383d22fa77>
69 // "[libcxxabi] Insert padding in __cxa_exception struct for compatibility". The HACK in
70 // fillUnoException (bridges/source/cpp_uno/gcc3_macosx_x86-64/except.cxx) tries to find out at
71 // runtime whether a __cxa_exception has this member. Once we can be sure that we only run
72 // against new libcxxabi that has this member, we can drop the "#if 0" here and drop the hack
73 // in fillUnoException.
74
75 // Now _Unwind_Exception is marked with __attribute__((aligned)),
76 // which implies __cxa_exception is also aligned. Insert padding
77 // in the beginning of the struct, rather than before unwindHeader.
78 void *reserve;
79#endif
80
81 // This is a new field to support C++ 0x exception_ptr.
82 // For binary compatibility it is at the start of this
83 // struct which is prepended to the object thrown in
84 // __cxa_allocate_exception.
85 size_t referenceCount;
86#endif
87 // Manage the exception object itself.
88 std::type_info *exceptionType;
89 void (*exceptionDestructor)(void *);
90
91 // The C++ standard has entertaining rules wrt calling set_terminate
92 // and set_unexpected in the middle of the exception cleanup process.
93 void (*unexpectedHandler)(); // std::unexpected_handler dropped from C++17
94 std::terminate_handler terminateHandler;
95
96 // The caught exception stack threads through here.
98
99 // How many nested handlers have caught this exception. A negated
100 // value is a signal that this object has been rethrown.
102
103#ifdef __ARM_EABI_UNWINDER__
104 // Stack of exceptions in cleanups.
105 __cxa_exception* nextPropagatingException;
106
107 // The number of active cleanup handlers for this exception.
108 int propagationCount;
109#else
110 // Cache parsed handler data from the personality routine Phase 1
111 // for Phase 2 and __cxa_call_unexpected.
113 const unsigned char *actionRecord;
114 const unsigned char *languageSpecificData;
115 _Unwind_Ptr catchTemp;
117#endif
118#if !__LP64__
119 // This is a new field to support C++ 0x exception_ptr.
120 // For binary compatibility it is placed where the compiler
121 // previously adding padded to 64-bit align unwindHeader.
123#endif
124
125 // The generic exception header. Must be last.
126 _Unwind_Exception unwindHeader;
127};
128
129// Each thread in a C++ program has access to a __cxa_eh_globals object.
131{
133 unsigned int uncaughtExceptions;
134#ifdef __ARM_EABI_UNWINDER__
135 __cxa_exception* propagatingExceptions;
136#endif
137};
138
139
140// The __cxa_eh_globals for the current thread can be obtained by using
141// either of the following functions. The "fast" version assumes at least
142// one prior call of __cxa_get_globals has been made from the current
143// thread, so no initialization is necessary.
144extern "C" __cxa_eh_globals *__cxa_get_globals () throw();
146
147// Allocate memory for the exception plus the thrown object.
148extern "C" void *__cxa_allocate_exception(size_t thrown_size) throw();
149
150// Free the space allocated for the exception.
151extern "C" void __cxa_free_exception(void *thrown_exception) throw();
152
153#pragma GCC visibility push(hidden)
154extern "C" void *__cxa_allocate_dependent_exception() throw();
155extern "C" void __cxa_free_dependent_exception(void *thrown_exception) throw();
156#pragma GCC visibility pop
157
158// Throw the exception.
159extern "C" void __cxa_throw (void *thrown_exception,
160 std::type_info *tinfo,
161 void (*dest) (void *))
162 __attribute__((noreturn));
163
164// Used to implement exception handlers.
165extern "C" void *__cxa_get_exception_ptr (void *) throw();
166extern "C" void *__cxa_begin_catch (void *) throw();
167extern "C" void __cxa_end_catch ();
168extern "C" void __cxa_rethrow () __attribute__((noreturn));
169
170// These facilitate code generation for recurring situations.
171extern "C" void __cxa_bad_cast ();
172extern "C" void __cxa_bad_typeid ();
173
174// @@@ These are not directly specified by the IA-64 C++ ABI.
175
176// Handles re-checking the exception specification if unexpectedHandler
177// throws, and if bad_exception needs to be thrown. Called from the
178// compiler.
179extern "C" void __cxa_call_unexpected (void *) __attribute__((noreturn));
180extern "C" void __cxa_call_terminate (void*) __attribute__((noreturn));
181
182#ifdef __ARM_EABI_UNWINDER__
183// Arm EABI specified routines.
184typedef enum {
185 ctm_failed = 0,
186 ctm_succeeded = 1,
187 ctm_succeeded_with_ptr_to_base = 2
188} __cxa_type_match_result;
189extern "C" bool __cxa_type_match(_Unwind_Exception*, const std::type_info*,
190 bool, void**);
191extern "C" void __cxa_begin_cleanup (_Unwind_Exception*);
192extern "C" void __cxa_end_cleanup (void);
193#endif
194
195// These are explicitly GNU C++ specific.
196
197// Acquire the C++ exception header from the C++ object.
198static inline __cxa_exception *
200{
201 return reinterpret_cast<__cxa_exception *>(ptr) - 1;
202}
203
204// Acquire the C++ exception header from the generic exception header.
205static inline __cxa_exception *
206__get_exception_header_from_ue (_Unwind_Exception *exc)
207{
208 return reinterpret_cast<__cxa_exception *>(exc + 1) - 1;
209}
210
211#ifdef __ARM_EABI_UNWINDER__
212static inline bool
213__is_gxx_exception_class(_Unwind_Exception_Class c)
214{
215 // TODO: Take advantage of the fact that c will always be word aligned.
216 return c[0] == 'G'
217 && c[1] == 'N'
218 && c[2] == 'U'
219 && c[3] == 'C'
220 && c[4] == 'C'
221 && c[5] == '+'
222 && c[6] == '+';
223}
224
225static inline void
226__GXX_INIT_EXCEPTION_CLASS(_Unwind_Exception_Class c)
227{
228 c[0] = 'G';
229 c[1] = 'N';
230 c[2] = 'U';
231 c[3] = 'C';
232 c[4] = 'C';
233 c[5] = '+';
234 c[6] = '+';
235 c[7] = '\0';
236}
237
238static inline void*
239__gxx_caught_object(_Unwind_Exception* eo)
240{
241 return (void*)eo->barrier_cache.bitpattern[0];
242}
243#else // !__ARM_EABI_UNWINDER__
244// This is the exception class we report -- "GNUCC++\0".
245const _Unwind_Exception_Class __gxx_exception_class
246= ((((((((_Unwind_Exception_Class) 'G'
247 << 8 | (_Unwind_Exception_Class) 'N')
248 << 8 | (_Unwind_Exception_Class) 'U')
249 << 8 | (_Unwind_Exception_Class) 'C')
250 << 8 | (_Unwind_Exception_Class) 'C')
251 << 8 | (_Unwind_Exception_Class) '+')
252 << 8 | (_Unwind_Exception_Class) '+')
253 << 8 | (_Unwind_Exception_Class) '\0');
254
255static inline bool
256__is_gxx_exception_class(_Unwind_Exception_Class c)
257{
258 return (c & ((_Unwind_Exception_Class)~0 << 8)) == __gxx_exception_class;
259}
260
261#define __GXX_INIT_EXCEPTION_CLASS(c) c = __gxx_exception_class
262
263// GNU C++ personality routine, Version 0.
265 (int, _Unwind_Action, _Unwind_Exception_Class,
266 struct _Unwind_Exception *, struct _Unwind_Context *);
267
268// GNU C++ sjlj personality routine, Version 0.
270 (int, _Unwind_Action, _Unwind_Exception_Class,
271 struct _Unwind_Exception *, struct _Unwind_Context *);
272
273static inline void*
274__gxx_caught_object(_Unwind_Exception* eo)
275{
277 return header->adjustedPtr;
278}
279#endif // !__ARM_EABI_UNWINDER__
280
281} /* namespace __cxxabiv1 */
282
283#pragma GCC visibility pop
284
285#endif // _UNWIND_CXX_H
constexpr sal_Int8 header[]
void __cxa_rethrow() __attribute__((noreturn))
_Unwind_Reason_Code __gxx_personality_sj0(int, _Unwind_Action, _Unwind_Exception_Class, struct _Unwind_Exception *, struct _Unwind_Context *)
void __cxa_call_terminate(void *) __attribute__((noreturn))
void __cxa_throw(void *thrown_exception, std::type_info *tinfo, void(*dest)(void *)) __attribute__((noreturn))
__cxa_eh_globals * __cxa_get_globals()
static bool __is_gxx_exception_class(_Unwind_Exception_Class c)
Definition: unwind-cxx.h:256
void * __cxa_allocate_dependent_exception()
void __cxa_end_catch()
void __cxa_call_unexpected(void *) __attribute__((noreturn))
void * __cxa_allocate_exception(size_t thrown_size)
const _Unwind_Exception_Class __gxx_exception_class
Definition: unwind-cxx.h:246
static __cxa_exception * __get_exception_header_from_obj(void *ptr)
Definition: unwind-cxx.h:199
static __cxa_exception * __get_exception_header_from_ue(_Unwind_Exception *exc)
Definition: unwind-cxx.h:206
__cxa_eh_globals * __cxa_get_globals_fast()
static void * __gxx_caught_object(_Unwind_Exception *eo)
Definition: unwind-cxx.h:274
void __cxa_bad_typeid()
void __cxa_bad_cast()
void __cxa_free_exception(void *thrown_exception)
void __cxa_free_dependent_exception(void *thrown_exception)
void * __cxa_get_exception_ptr(void *)
_Unwind_Reason_Code __gxx_personality_v0(int, _Unwind_Action, _Unwind_Exception_Class, struct _Unwind_Exception *, struct _Unwind_Context *)
void * __cxa_begin_catch(void *)
unsigned int uncaughtExceptions
Definition: unwind-cxx.h:133
__cxa_exception * caughtExceptions
Definition: unwind-cxx.h:132
const unsigned char * languageSpecificData
Definition: unwind-cxx.h:114
void(* exceptionDestructor)(void *)
Definition: unwind-cxx.h:89
__cxa_exception * nextException
Definition: unwind-cxx.h:97
const unsigned char * actionRecord
Definition: unwind-cxx.h:113
std::terminate_handler terminateHandler
Definition: unwind-cxx.h:94
std::type_info * exceptionType
Definition: unwind-cxx.h:88
_Unwind_Exception unwindHeader
Definition: unwind-cxx.h:126
#define __GXX_INIT_EXCEPTION_CLASS(c)
Definition: unwind-cxx.h:261
unsigned _Unwind_Word __attribute__((__mode__(__word__)))
Definition: unwind-cxx.h:45