2 * Copyright 2012 David Chisnall. All rights reserved.
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to
6 * deal in the Software without restriction, including without limitation the
7 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8 * sell copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be
12 * included in all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 * The cxxabi.h header provides a set of public definitions for types and
33 * functions defined by the Itanium C++ ABI specification. For reference, see
34 * the ABI specification here:
36 * http://sourcery.mentor.com/public/cxx-abi/abi.html
38 * All deviations from this specification, unless otherwise noted, are
43 namespace __cxxabiv1
{
47 * Function type to call when an unexpected exception is encountered.
49 typedef void (*unexpected_handler
)();
51 * Function type to call when an unrecoverable condition is encountered.
53 typedef void (*terminate_handler
)();
57 * Structure used as a header on thrown exceptions. This is the same layout as
58 * defined by the Itanium ABI spec, so should be interoperable with any other
59 * implementation of this spec, such as GNU libsupc++.
61 * This structure is allocated when an exception is thrown. Unwinding happens
62 * in two phases, the first looks for a handler and the second installs the
63 * context. This structure stores a cache of the handler location between
64 * phase 1 and phase 2. Unfortunately, cleanup information is not cached, so
65 * must be looked up in both phases. This happens for two reasons. The first
66 * is that we don't know how many frames containing cleanups there will be, and
67 * we should avoid dynamic allocation during unwinding (the exception may be
68 * reporting that we've run out of memory). The second is that finding
69 * cleanups is much cheaper than finding handlers, because we don't have to
70 * look at the type table at all.
72 * Note: Several fields of this structure have not-very-informative names.
73 * These are taken from the ABI spec and have not been changed to make it
74 * easier for people referring to to the spec while reading this code.
76 struct __cxa_exception
80 * Reference count. Used to support the C++11 exception_ptr class. This
81 * is prepended to the structure in 64-bit mode and squeezed in to the
82 * padding left before the 64-bit aligned _Unwind_Exception at the end in
85 * Note that it is safe to extend this structure at the beginning, rather
86 * than the end, because the public API for creating it returns the address
87 * of the end (where the exception object can be stored).
89 uintptr_t referenceCount
;
91 /** Type info for the thrown object. */
92 std::type_info
*exceptionType
;
93 /** Destructor for the object, if one exists. */
94 void (*exceptionDestructor
) (void *);
95 /** Handler called when an exception specification is violated. */
96 unexpected_handler unexpectedHandler
;
97 /** Hander called to terminate. */
98 terminate_handler terminateHandler
;
100 * Next exception in the list. If an exception is thrown inside a catch
101 * block and caught in a nested catch, this points to the exception that
102 * will be handled after the inner catch block completes.
104 __cxa_exception
*nextException
;
106 * The number of handlers that currently have references to this
107 * exception. The top (non-sign) bit of this is used as a flag to indicate
108 * that the exception is being rethrown, so should not be deleted when its
109 * handler count reaches 0 (which it doesn't with the top bit set).
114 * The ARM EH ABI requires the unwind library to keep track of exceptions
115 * during cleanups. These support nesting, so we need to keep a list of
118 _Unwind_Exception
*nextCleanup
;
120 * The number of cleanups that are currently being run on this exception.
125 * The selector value to be returned when installing the catch handler.
126 * Used at the call site to determine which catch() block should execute.
127 * This is found in phase 1 of unwinding then installed in phase 2.
129 int handlerSwitchValue
;
131 * The action record for the catch. This is cached during phase 1
134 const char *actionRecord
;
136 * Pointer to the language-specific data area (LSDA) for the handler
137 * frame. This is unused in this implementation, but set for ABI
138 * compatibility in case we want to mix code in very weird ways.
140 const char *languageSpecificData
;
141 /** The cached landing pad for the catch handler.*/
144 * The pointer that will be returned as the pointer to the object. When
145 * throwing a class and catching a virtual superclass (for example), we
146 * need to adjust the thrown pointer to make it all work correctly.
151 * Reference count. Used to support the C++11 exception_ptr class. This
152 * is prepended to the structure in 64-bit mode and squeezed in to the
153 * padding left before the 64-bit aligned _Unwind_Exception at the end in
156 * Note that it is safe to extend this structure at the beginning, rather
157 * than the end, because the public API for creating it returns the address
158 * of the end (where the exception object can be stored)
160 uintptr_t referenceCount
;
162 /** The language-agnostic part of the exception header. */
163 _Unwind_Exception unwindHeader
;
167 * ABI-specified globals structure. Returned by the __cxa_get_globals()
168 * function and its fast variant. This is a per-thread structure - every
169 * thread will have one lazily allocated.
171 * This structure is defined by the ABI, so may be used outside of this
174 struct __cxa_eh_globals
177 * A linked list of exceptions that are currently caught. There may be
178 * several of these in nested catch() blocks.
180 __cxa_exception
*caughtExceptions
;
182 * The number of uncaught exceptions.
184 unsigned int uncaughtExceptions
;
187 * ABI function returning the __cxa_eh_globals structure.
189 __cxa_eh_globals
*__cxa_get_globals(void);
191 * Version of __cxa_get_globals() assuming that __cxa_get_globals() has already
192 * been called at least once by this thread.
194 __cxa_eh_globals
*__cxa_get_globals_fast(void);
196 std::type_info
* __cxa_current_exception_type();
199 * Throws an exception returned by __cxa_current_primary_exception(). This
200 * exception may have been caught in another thread.
202 void __cxa_rethrow_primary_exception(void* thrown_exception
);
204 * Returns the current exception in a form that can be stored in an
205 * exception_ptr object and then rethrown by a call to
206 * __cxa_rethrow_primary_exception().
208 void *__cxa_current_primary_exception(void);
210 * Increments the reference count of an exception. Called when an
211 * exception_ptr is copied.
213 void __cxa_increment_exception_refcount(void* thrown_exception
);
215 * Decrements the reference count of an exception. Called when an
216 * exception_ptr is deleted.
218 void __cxa_decrement_exception_refcount(void* thrown_exception
);
220 * Demangles a C++ symbol or type name. The buffer, if non-NULL, must be
221 * allocated with malloc() and must be *n bytes or more long. This function
222 * may call realloc() on the value pointed to by buf, and will return the
223 * length of the string via *n.
225 * The value pointed to by status is set to one of the following:
228 * -1: memory allocation failure
229 * -2: invalid mangled name
230 * -3: invalid arguments
232 char* __cxa_demangle(const char* mangled_name
,
240 namespace abi
= __cxxabiv1
;
242 #endif /* __cplusplus */
243 #endif /* __CXXABI_H_ */