Deleted Added
full compact
cxxabi.h (227972) cxxabi.h (232922)
1/*
2 * Copyright 2012 David Chisnall. All rights reserved.
3 *
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:
10 *
11 * The above copyright notice and this permission notice shall be
12 * included in all copies or substantial portions of the Software.
13 *
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.
21 */
22
1#ifndef __CXXABI_H_
2#define __CXXABI_H_
3#include <stdint.h>
4#include "unwind.h"
5namespace std
6{
7 class type_info;
8}
9/*
10 * The cxxabi.h header provides a set of public definitions for types and
11 * functions defined by the Itanium C++ ABI specification. For reference, see
12 * the ABI specification here:
13 *
14 * http://sourcery.mentor.com/public/cxx-abi/abi.html
15 *
16 * All deviations from this specification, unless otherwise noted, are
17 * accidental.
18 */
19
20#ifdef __cplusplus
21namespace __cxxabiv1 {
22extern "C" {
23#endif
24/**
25 * Function type to call when an unexpected exception is encountered.
26 */
27typedef void (*unexpected_handler)();
28/**
29 * Function type to call when an unrecoverable condition is encountered.
30 */
31typedef void (*terminate_handler)();
32
33
34/**
35 * Structure used as a header on thrown exceptions. This is the same layout as
36 * defined by the Itanium ABI spec, so should be interoperable with any other
37 * implementation of this spec, such as GNU libsupc++.
38 *
39 * This structure is allocated when an exception is thrown. Unwinding happens
40 * in two phases, the first looks for a handler and the second installs the
41 * context. This structure stores a cache of the handler location between
42 * phase 1 and phase 2. Unfortunately, cleanup information is not cached, so
43 * must be looked up in both phases. This happens for two reasons. The first
44 * is that we don't know how many frames containing cleanups there will be, and
45 * we should avoid dynamic allocation during unwinding (the exception may be
46 * reporting that we've run out of memory). The second is that finding
47 * cleanups is much cheaper than finding handlers, because we don't have to
48 * look at the type table at all.
49 *
50 * Note: Several fields of this structure have not-very-informative names.
51 * These are taken from the ABI spec and have not been changed to make it
52 * easier for people referring to to the spec while reading this code.
53 */
54struct __cxa_exception
55{
56#if __LP64__
57 /**
58 * Reference count. Used to support the C++11 exception_ptr class. This
59 * is prepended to the structure in 64-bit mode and squeezed in to the
60 * padding left before the 64-bit aligned _Unwind_Exception at the end in
61 * 32-bit mode.
62 *
63 * Note that it is safe to extend this structure at the beginning, rather
64 * than the end, because the public API for creating it returns the address
65 * of the end (where the exception object can be stored).
66 */
67 uintptr_t referenceCount;
68#endif
69 /** Type info for the thrown object. */
70 std::type_info *exceptionType;
71 /** Destructor for the object, if one exists. */
72 void (*exceptionDestructor) (void *);
73 /** Handler called when an exception specification is violated. */
74 unexpected_handler unexpectedHandler;
75 /** Hander called to terminate. */
76 terminate_handler terminateHandler;
77 /**
78 * Next exception in the list. If an exception is thrown inside a catch
79 * block and caught in a nested catch, this points to the exception that
80 * will be handled after the inner catch block completes.
81 */
82 __cxa_exception *nextException;
83 /**
84 * The number of handlers that currently have references to this
85 * exception. The top (non-sign) bit of this is used as a flag to indicate
86 * that the exception is being rethrown, so should not be deleted when its
87 * handler count reaches 0 (which it doesn't with the top bit set).
88 */
89 int handlerCount;
90#ifdef __arm__
91 /**
92 * The ARM EH ABI requires the unwind library to keep track of exceptions
93 * during cleanups. These support nesting, so we need to keep a list of
94 * them.
95 */
96 _Unwind_Exception *nextCleanup;
97 /**
98 * The number of cleanups that are currently being run on this exception.
99 */
100 int cleanupCount;
101#endif
102 /**
103 * The selector value to be returned when installing the catch handler.
104 * Used at the call site to determine which catch() block should execute.
105 * This is found in phase 1 of unwinding then installed in phase 2.
106 */
107 int handlerSwitchValue;
108 /**
109 * The action record for the catch. This is cached during phase 1
110 * unwinding.
111 */
112 const char *actionRecord;
113 /**
114 * Pointer to the language-specific data area (LSDA) for the handler
115 * frame. This is unused in this implementation, but set for ABI
116 * compatibility in case we want to mix code in very weird ways.
117 */
118 const char *languageSpecificData;
119 /** The cached landing pad for the catch handler.*/
120 void *catchTemp;
121 /**
122 * The pointer that will be returned as the pointer to the object. When
123 * throwing a class and catching a virtual superclass (for example), we
124 * need to adjust the thrown pointer to make it all work correctly.
125 */
126 void *adjustedPtr;
127#if !__LP64__
128 /**
129 * Reference count. Used to support the C++11 exception_ptr class. This
130 * is prepended to the structure in 64-bit mode and squeezed in to the
131 * padding left before the 64-bit aligned _Unwind_Exception at the end in
132 * 32-bit mode.
133 *
134 * Note that it is safe to extend this structure at the beginning, rather
135 * than the end, because the public API for creating it returns the address
136 * of the end (where the exception object can be stored)
137 */
138 uintptr_t referenceCount;
139#endif
140 /** The language-agnostic part of the exception header. */
141 _Unwind_Exception unwindHeader;
142};
143
144/**
145 * ABI-specified globals structure. Returned by the __cxa_get_globals()
146 * function and its fast variant. This is a per-thread structure - every
147 * thread will have one lazily allocated.
148 *
149 * This structure is defined by the ABI, so may be used outside of this
150 * library.
151 */
152struct __cxa_eh_globals
153{
154 /**
155 * A linked list of exceptions that are currently caught. There may be
156 * several of these in nested catch() blocks.
157 */
158 __cxa_exception *caughtExceptions;
159 /**
160 * The number of uncaught exceptions.
161 */
162 unsigned int uncaughtExceptions;
163};
164/**
165 * ABI function returning the __cxa_eh_globals structure.
166 */
167__cxa_eh_globals *__cxa_get_globals(void);
168/**
169 * Version of __cxa_get_globals() assuming that __cxa_get_globals() has already
170 * been called at least once by this thread.
171 */
172__cxa_eh_globals *__cxa_get_globals_fast(void);
173
174/**
175 * Throws an exception returned by __cxa_current_primary_exception(). This
176 * exception may have been caught in another thread.
177 */
178void __cxa_rethrow_primary_exception(void* thrown_exception);
179/**
180 * Returns the current exception in a form that can be stored in an
181 * exception_ptr object and then rethrown by a call to
182 * __cxa_rethrow_primary_exception().
183 */
184void *__cxa_current_primary_exception(void);
185/**
186 * Increments the reference count of an exception. Called when an
187 * exception_ptr is copied.
188 */
189void __cxa_increment_exception_refcount(void* thrown_exception);
190/**
191 * Decrements the reference count of an exception. Called when an
192 * exception_ptr is deleted.
193 */
194void __cxa_decrement_exception_refcount(void* thrown_exception);
195/**
196 * Demangles a C++ symbol or type name. The buffer, if non-NULL, must be
197 * allocated with malloc() and must be *n bytes or more long. This function
198 * may call realloc() on the value pointed to by buf, and will return the
199 * length of the string via *n.
200 *
201 * The value pointed to by status is set to one of the following:
202 *
203 * 0: success
204 * -1: memory allocation failure
205 * -2: invalid mangled name
206 * -3: invalid arguments
207 */
208char* __cxa_demangle(const char* mangled_name,
209 char* buf,
210 size_t* n,
211 int* status);
212#ifdef __cplusplus
213} // extern "C"
214} // namespace
215
216namespace abi = __cxxabiv1;
217
218#endif /* __cplusplus */
219#endif /* __CXXABI_H_ */
23#ifndef __CXXABI_H_
24#define __CXXABI_H_
25#include <stdint.h>
26#include "unwind.h"
27namespace std
28{
29 class type_info;
30}
31/*
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:
35 *
36 * http://sourcery.mentor.com/public/cxx-abi/abi.html
37 *
38 * All deviations from this specification, unless otherwise noted, are
39 * accidental.
40 */
41
42#ifdef __cplusplus
43namespace __cxxabiv1 {
44extern "C" {
45#endif
46/**
47 * Function type to call when an unexpected exception is encountered.
48 */
49typedef void (*unexpected_handler)();
50/**
51 * Function type to call when an unrecoverable condition is encountered.
52 */
53typedef void (*terminate_handler)();
54
55
56/**
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++.
60 *
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.
71 *
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.
75 */
76struct __cxa_exception
77{
78#if __LP64__
79 /**
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
83 * 32-bit mode.
84 *
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).
88 */
89 uintptr_t referenceCount;
90#endif
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;
99 /**
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.
103 */
104 __cxa_exception *nextException;
105 /**
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).
110 */
111 int handlerCount;
112#ifdef __arm__
113 /**
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
116 * them.
117 */
118 _Unwind_Exception *nextCleanup;
119 /**
120 * The number of cleanups that are currently being run on this exception.
121 */
122 int cleanupCount;
123#endif
124 /**
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.
128 */
129 int handlerSwitchValue;
130 /**
131 * The action record for the catch. This is cached during phase 1
132 * unwinding.
133 */
134 const char *actionRecord;
135 /**
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.
139 */
140 const char *languageSpecificData;
141 /** The cached landing pad for the catch handler.*/
142 void *catchTemp;
143 /**
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.
147 */
148 void *adjustedPtr;
149#if !__LP64__
150 /**
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
154 * 32-bit mode.
155 *
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)
159 */
160 uintptr_t referenceCount;
161#endif
162 /** The language-agnostic part of the exception header. */
163 _Unwind_Exception unwindHeader;
164};
165
166/**
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.
170 *
171 * This structure is defined by the ABI, so may be used outside of this
172 * library.
173 */
174struct __cxa_eh_globals
175{
176 /**
177 * A linked list of exceptions that are currently caught. There may be
178 * several of these in nested catch() blocks.
179 */
180 __cxa_exception *caughtExceptions;
181 /**
182 * The number of uncaught exceptions.
183 */
184 unsigned int uncaughtExceptions;
185};
186/**
187 * ABI function returning the __cxa_eh_globals structure.
188 */
189__cxa_eh_globals *__cxa_get_globals(void);
190/**
191 * Version of __cxa_get_globals() assuming that __cxa_get_globals() has already
192 * been called at least once by this thread.
193 */
194__cxa_eh_globals *__cxa_get_globals_fast(void);
195
196/**
197 * Throws an exception returned by __cxa_current_primary_exception(). This
198 * exception may have been caught in another thread.
199 */
200void __cxa_rethrow_primary_exception(void* thrown_exception);
201/**
202 * Returns the current exception in a form that can be stored in an
203 * exception_ptr object and then rethrown by a call to
204 * __cxa_rethrow_primary_exception().
205 */
206void *__cxa_current_primary_exception(void);
207/**
208 * Increments the reference count of an exception. Called when an
209 * exception_ptr is copied.
210 */
211void __cxa_increment_exception_refcount(void* thrown_exception);
212/**
213 * Decrements the reference count of an exception. Called when an
214 * exception_ptr is deleted.
215 */
216void __cxa_decrement_exception_refcount(void* thrown_exception);
217/**
218 * Demangles a C++ symbol or type name. The buffer, if non-NULL, must be
219 * allocated with malloc() and must be *n bytes or more long. This function
220 * may call realloc() on the value pointed to by buf, and will return the
221 * length of the string via *n.
222 *
223 * The value pointed to by status is set to one of the following:
224 *
225 * 0: success
226 * -1: memory allocation failure
227 * -2: invalid mangled name
228 * -3: invalid arguments
229 */
230char* __cxa_demangle(const char* mangled_name,
231 char* buf,
232 size_t* n,
233 int* status);
234#ifdef __cplusplus
235} // extern "C"
236} // namespace
237
238namespace abi = __cxxabiv1;
239
240#endif /* __cplusplus */
241#endif /* __CXXABI_H_ */