author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 17 Sep 2010 08:37:04 +0300 | |
changeset 266 | 0008ccd16016 |
parent 0 | a41df078684a |
permissions | -rw-r--r-- |
0 | 1 |
/* The C++ exceptions runtime support |
2 |
* |
|
3 |
* Copyright 2002-2005 ARM Limited. All rights reserved. |
|
4 |
* |
|
5 |
* Your rights to use this code are set out in the accompanying licence |
|
6 |
* text file LICENCE.txt (ARM contract number LEC-ELA-00080 v1.0). |
|
7 |
*/ |
|
8 |
||
266
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
9 |
/* Portions copyright Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies). */ |
0 | 10 |
|
11 |
/* |
|
12 |
* RCS $Revision: 92950 $ |
|
13 |
* Checkin $Date: 2005-10-12 11:08:47 +0100 (Wed, 12 Oct 2005) $ |
|
14 |
* Revising $Author: achapman $ |
|
15 |
*/ |
|
16 |
||
17 |
/* This source file is compiled automatically by ARM's make system into |
|
18 |
* multiple object files. The source regions constituting object file |
|
19 |
* xxx.o are delimited by ifdef xxx_c / endif directives. |
|
20 |
* |
|
21 |
* The source regions currently marked are: |
|
22 |
* arm_exceptions_globs_c |
|
23 |
* arm_exceptions_mem_c |
|
24 |
* arm_exceptions_uncaught_c |
|
25 |
* arm_exceptions_terminate_c |
|
26 |
* arm_exceptions_setterminate_c |
|
27 |
* arm_exceptions_unexpected_c |
|
28 |
* arm_exceptions_setunexpected_c |
|
29 |
* arm_exceptions_support_c |
|
30 |
* arm_exceptions_callterm_c |
|
31 |
* arm_exceptions_callunex_c |
|
32 |
* arm_exceptions_currenttype_c |
|
33 |
* arm_exceptions_alloc_c |
|
34 |
* arm_exceptions_free_c |
|
35 |
* arm_exceptions_throw_c |
|
36 |
* arm_exceptions_rethrow_c |
|
37 |
* arm_exceptions_foreign_c |
|
38 |
* arm_exceptions_cleanup_c |
|
39 |
* arm_exceptions_getexceptionptr_c |
|
40 |
* arm_exceptions_begincatch_c |
|
41 |
* arm_exceptions_endcatch_c |
|
42 |
* arm_exceptions_bad_typeid_c |
|
43 |
* arm_exceptions_bad_cast_c |
|
44 |
*/ |
|
45 |
||
46 |
#include <string.h> |
|
47 |
||
48 |
// Environment: |
|
49 |
#include "unwind_env.h" |
|
50 |
// Language-independent unwinder declarations: |
|
51 |
#include "unwinder.h" |
|
52 |
||
53 |
#ifdef __EPOC32__ |
|
54 |
/* Symbian specific support */ |
|
55 |
#include "symbian_support.h" |
|
56 |
#endif |
|
57 |
||
58 |
#include <new> |
|
59 |
||
60 |
/* Barrier cache: */ |
|
61 |
/* Requirement imposed by C++ semantics module - pointer to match object in slot 0: */ |
|
62 |
#define BARRIER_HANDLEROBJECT (0) |
|
63 |
/* Requirement imposed by C++ semantics module - function exception spec info */ |
|
64 |
#define BARRIER_FNSPECCOUNT (1) |
|
65 |
#define BARRIER_FNSPECBASE (2) |
|
66 |
#define BARRIER_FNSPECSTRIDE (3) |
|
67 |
#define BARRIER_FNSPECARRAY (4) |
|
68 |
||
69 |
/* By default, none of these routines are unwindable: */ |
|
70 |
#pragma noexceptions_unwind |
|
71 |
||
72 |
/* For brevity: */ |
|
73 |
||
74 |
typedef _Unwind_Control_Block UCB; |
|
75 |
||
76 |
using std::terminate_handler; |
|
77 |
using std::unexpected_handler; |
|
78 |
using std::terminate; |
|
79 |
using std::unexpected; |
|
80 |
using std::type_info; |
|
81 |
||
82 |
/* Redeclare these interface routines as weak, so using them does not |
|
83 |
* pull in the unwind library. We only want the unwind library if |
|
84 |
* someone throws (or raises an exception from some other language). |
|
85 |
*/ |
|
86 |
WEAKDECL NORETURNDECL void _Unwind_Resume(UCB *); |
|
87 |
WEAKDECL void _Unwind_Complete(UCB *); |
|
88 |
||
89 |
/* Diagnostics: |
|
90 |
* Define DEBUG to get extra interfaces which assist debugging this functionality. |
|
91 |
* Define CPP_DIAGNOSTICS for printed diagnostics. |
|
92 |
*/ |
|
93 |
#ifdef DEBUG |
|
94 |
#define CPP_DIAGNOSTICS |
|
95 |
#endif |
|
96 |
||
97 |
#ifdef CPP_DIAGNOSTICS |
|
98 |
#ifndef __EPOC32__ |
|
99 |
extern "C" int printf(const char *, ...); |
|
100 |
#endif |
|
101 |
#endif |
|
102 |
||
103 |
/* --------- "Exceptions_class" string for our implementation: --------- */ |
|
104 |
||
105 |
#define EXCEPTIONS_CLASS_SIZE 8 |
|
106 |
#define ARMCPP_EXCEPTIONS_CLASS "ARM\0C++\0" |
|
107 |
||
108 |
||
109 |
/* --------- Exception control object: --------- */ |
|
110 |
||
111 |
// Type __cxa_exception is the combined C++ housekeeping (LEO) and UCB. |
|
112 |
// It will be followed by the user exception object, hence must ensure |
|
113 |
// the latter is aligned on an 8 byte boundary. |
|
114 |
||
115 |
#ifndef __EPOC32__ |
|
116 |
struct __cxa_exception { |
|
117 |
const type_info *exceptionType; // RTTI object describing the type of the exception |
|
118 |
void *(*exceptionDestructor)(void *); // Destructor for the exception object (may be NULL) |
|
119 |
unexpected_handler unexpectedHandler; // Handler in force after evaluating throw expr |
|
120 |
terminate_handler terminateHandler; // Handler in force after evaluating throw expr |
|
121 |
__cxa_exception *nextCaughtException; // Chain of "currently caught" c++ exception objects |
|
122 |
uint32_t handlerCount; // Count of how many handlers this EO is "caught" in |
|
123 |
__cxa_exception *nextPropagatingException; // Chain of objects saved over cleanup |
|
124 |
uint32_t propagationCount; // Count of live propagations (throws) of this EO |
|
125 |
UCB ucb; // Forces alignment of next item to 8-byte boundary |
|
126 |
}; |
|
127 |
#endif |
|
128 |
||
129 |
||
130 |
/* --------- Control "globals": --------- */ |
|
131 |
||
132 |
// We do this by putting all the thread-specific "globals" into a single |
|
133 |
// area of store, which we allocate space for dynamically. |
|
134 |
// We don't define a constructor for this; see comments with __cxa_get_globals. |
|
135 |
||
136 |
#ifndef __EPOC32__ |
|
137 |
typedef void (*handler)(void); |
|
138 |
||
139 |
struct __cxa_eh_globals { |
|
140 |
uint32_t uncaughtExceptions; // counter |
|
141 |
unexpected_handler unexpectedHandler; // per-thread handler |
|
142 |
terminate_handler terminateHandler; // per-thread handler |
|
143 |
bool implementation_ever_called_terminate; // true if it ever did |
|
144 |
handler call_hook; // transient field to tell terminate/unexpected which hook to call |
|
145 |
__cxa_exception *caughtExceptions; // chain of "caught" exceptions |
|
146 |
__cxa_exception *propagatingExceptions; // chain of "propagating" (in cleanup) exceptions |
|
147 |
void *emergency_buffer; // emergency buffer for when rest of heap full |
|
148 |
}; |
|
149 |
#endif |
|
150 |
||
151 |
||
152 |
/* ---------- Entry points: ---------- */ |
|
153 |
||
154 |
/* There is a little type-delicacy required here as __cxa_throw takes a |
|
155 |
* function pointer. Setting aside the problem of not being able to form |
|
156 |
* a pointer to a destructor in C++, if we simply say extern "C" here |
|
157 |
* then the function pointer will also have C linkage and will be a |
|
158 |
* pointer to a C function. This causes problems when __cxa_throw is |
|
159 |
* defined (unless we repeat the extern "C" at the definition site) because |
|
160 |
* the fnptr in the definition gets C++ linkage, hence that __cxa_throw has |
|
161 |
* a different signature to the declared one, and so the function we wanted |
|
162 |
* doesn't get defined at all. |
|
163 |
* Maybe it should just take a void * but this seems more honest. |
|
164 |
*/ |
|
165 |
||
166 |
typedef void *(*cppdtorptr)(void *); |
|
167 |
||
168 |
extern "C" { |
|
169 |
||
170 |
// Protocol routines called directly from application code |
|
171 |
||
172 |
IMPORT_C void *__cxa_allocate_exception(size_t size); |
|
173 |
IMPORT_C void __cxa_free_exception(void *); |
|
174 |
WEAKDECL void __cxa_throw(void *, const type_info *, cppdtorptr); |
|
175 |
IMPORT_C void __cxa_rethrow(void); |
|
176 |
IMPORT_C void *__cxa_get_exception_ptr(UCB *); |
|
177 |
void *__cxa_begin_catch(UCB *); |
|
178 |
IMPORT_C void __cxa_end_catch(void); |
|
179 |
IMPORT_C void __cxa_end_cleanup(void); |
|
180 |
IMPORT_C const type_info *__cxa_current_exception_type(void); |
|
181 |
||
182 |
// Protocol routines usually called only by the personality routine(s). |
|
183 |
||
184 |
IMPORT_C void __cxa_call_terminate(UCB *); |
|
185 |
IMPORT_C void __cxa_call_unexpected(UCB *); |
|
186 |
IMPORT_C bool __cxa_begin_cleanup(UCB *); |
|
187 |
typedef enum { |
|
188 |
ctm_failed = 0, |
|
189 |
ctm_succeeded = 1, |
|
190 |
ctm_succeeded_with_ptr_to_base = 2 |
|
191 |
} __cxa_type_match_result; |
|
192 |
IMPORT_C __cxa_type_match_result __cxa_type_match(UCB *, const std::type_info *, |
|
193 |
bool is_reference_type, void **); |
|
194 |
||
195 |
// Auxilliary routines |
|
196 |
||
197 |
__cxa_eh_globals *__cxa_get_globals(void); |
|
198 |
IMPORT_C void __cxa_bad_typeid(void); |
|
199 |
IMPORT_C void __cxa_bad_cast(void); |
|
200 |
||
201 |
// Emergency memory buffer management routines |
|
202 |
||
203 |
void *__ARM_exceptions_buffer_init(void); |
|
204 |
void *__ARM_exceptions_buffer_allocate(void *, size_t); |
|
205 |
void *__ARM_exceptions_buffer_free(void *, void *); |
|
206 |
} |
|
207 |
||
208 |
||
209 |
// Support routines |
|
210 |
||
211 |
#define NAMES __ARM |
|
212 |
namespace NAMES { |
|
213 |
void default_unexpected_handler(void); |
|
214 |
void call_terminate_handler(UCB *); |
|
215 |
void eh_catch_semantics(UCB *); |
|
216 |
bool is_foreign_exception(UCB *); |
|
217 |
bool same_exceptions_class(const void *, const void *); |
|
218 |
__cxa_exception *get_foreign_intermediary(__cxa_exception *, UCB *); |
|
219 |
} |
|
220 |
||
221 |
// Macro: convert ucb pointer to __cxa_exception pointer |
|
222 |
||
223 |
#define ucbp_to_ep(UCB_P) ((__cxa_exception *)((char *)(UCB_P) - offsetof(__cxa_exception, ucb))) |
|
224 |
||
225 |
||
226 |
#ifdef arm_exceptions_globs_c |
|
227 |
||
228 |
/* --------- Allocating and retrieving "globals": --------- */ |
|
229 |
||
230 |
// The exception-handling globals should be allocated per-thread. |
|
231 |
// This is done here assuming the existance of a zero-initialised void* |
|
232 |
// pointer location obtainable by the macro EH_GLOBALS. |
|
233 |
||
234 |
// Default terminate handler: |
|
235 |
||
236 |
#ifndef __EPOC32__ |
|
237 |
static void __default_terminate_handler(void) { |
|
238 |
abort(); |
|
239 |
} |
|
240 |
#endif |
|
241 |
||
242 |
// If std::unexpected() is in the image, include a default handler for it: |
|
243 |
namespace NAMES { WEAKDECL void default_unexpected_handler(void); } |
|
244 |
||
245 |
// ARM's toolchain documentation states that if symbol |
|
246 |
// __ARM_exceptions_buffer_required is present we should allocate |
|
247 |
// an emergency buffer. |
|
248 |
// As we aren't allowed static data in ARM library builds, reference the |
|
249 |
// symbol by declaring it a function. This causes an additional problem when |
|
250 |
// ARM libraries are built position-independent, namely that an absent |
|
251 |
// function doesn't compare address-equal to NULL. So we have to get the |
|
252 |
// "addresses" from two different compilation units and compare those. |
|
253 |
// This is a known defect, to be fixed in the compiler. |
|
254 |
extern "C" WEAKDECL void __ARM_exceptions_buffer_required(void); |
|
255 |
extern void (*(__ARM_exceptions_buffer_required_address(void)))(void); |
|
256 |
||
257 |
// The address comparison function only needs to be used when we are building |
|
258 |
// position-independent. In other cases, comparing the address to NULL is more |
|
259 |
// efficient. |
|
260 |
#if 0 |
|
261 |
# define ARM_EXCEPTIONS_BUFFER_NOT_REQUIRED() (&__ARM_exceptions_buffer_required != __ARM_exceptions_buffer_required_address()) |
|
262 |
#else |
|
263 |
# define ARM_EXCEPTIONS_BUFFER_NOT_REQUIRED() (&__ARM_exceptions_buffer_required == NULL) |
|
264 |
#endif |
|
265 |
||
266 |
// __cxa_eh_globals returns the per-thread memory. There are several complications, |
|
267 |
// all of which relate to not touching the exceptions system while trying to |
|
268 |
// initialise it: |
|
269 |
// 1) We can't obtain memory by calling new or nothrow new as both of these use |
|
270 |
// exceptions internally, so we must use malloc |
|
271 |
// 2) We choose not to initialise the memory via placement new and a constructor, |
|
272 |
// since placement new is declared with an empty function exception specification, |
|
273 |
// which causes more of the exceptions system to always be pulled in. |
|
274 |
// 3) We can't call terminate, as terminate looks in the memory we are trying to |
|
275 |
// allocate. |
|
276 |
||
277 |
EXPORT_C __cxa_eh_globals *__cxa_get_globals(void) |
|
278 |
{ |
|
279 |
__cxa_eh_globals *this_thread_globals = (__cxa_eh_globals *)(EH_GLOBALS); |
|
280 |
||
281 |
#ifndef __EPOC32__ |
|
282 |
/* The Symbian implementation allocates the required space on the threads stack |
|
283 |
at thread creation and sets up thread local storage to point to the globals |
|
284 |
which are also initialised |
|
285 |
*/ |
|
286 |
if (this_thread_globals == NULL) { |
|
287 |
||
288 |
// First call |
|
289 |
// Obtain some memory: this is thread-safe provided malloc is. |
|
290 |
this_thread_globals = (__cxa_eh_globals *)malloc(sizeof(__cxa_eh_globals)); |
|
291 |
if (this_thread_globals == NULL) abort(); // NOT terminate(), which calls this fn |
|
292 |
||
293 |
// Save the pointer in the specially-provided location |
|
294 |
EH_GLOBALS = this_thread_globals; |
|
295 |
||
296 |
// Finally initialise the memory by hand |
|
297 |
this_thread_globals->uncaughtExceptions = 0; |
|
298 |
this_thread_globals->unexpectedHandler = NAMES::default_unexpected_handler; |
|
299 |
this_thread_globals->terminateHandler = __default_terminate_handler; |
|
300 |
this_thread_globals->implementation_ever_called_terminate = false; |
|
301 |
this_thread_globals->call_hook = NULL; |
|
302 |
this_thread_globals->caughtExceptions = NULL; |
|
303 |
this_thread_globals->propagatingExceptions = NULL; |
|
304 |
if (ARM_EXCEPTIONS_BUFFER_NOT_REQUIRED()) |
|
305 |
this_thread_globals->emergency_buffer = NULL; |
|
306 |
else |
|
307 |
this_thread_globals->emergency_buffer = __ARM_exceptions_buffer_init(); |
|
308 |
} |
|
309 |
#endif |
|
310 |
return this_thread_globals; |
|
311 |
} |
|
312 |
||
313 |
||
314 |
#endif /* arm_exceptions_globs_c */ |
|
315 |
#ifdef arm_exceptions_mem_c |
|
316 |
||
317 |
/* --------- Emergency memory: --------- */ |
|
318 |
||
319 |
// It is possible to reserve memory for throwing bad_alloc when the heap |
|
320 |
// is otherwise full. The ARM implementation provides hooks to do this. |
|
321 |
// The default implementation reserves just enough space for a bad_alloc |
|
322 |
// object, so if memory is later exhausted bad_alloc can still be thrown. |
|
323 |
// Note there is no guarantee or requirement that the exception being |
|
324 |
// thrown is actually bad_alloc. |
|
325 |
||
326 |
// A usage flag and enough space for a bad_alloc exception control object |
|
327 |
#ifndef __EPOC32__ |
|
328 |
struct emergency_eco { |
|
329 |
__cxa_exception ep; |
|
330 |
std::bad_alloc b; |
|
331 |
}; |
|
332 |
||
333 |
struct emergency_buffer { |
|
334 |
bool inuse; |
|
335 |
struct emergency_eco eco; |
|
336 |
}; |
|
337 |
||
338 |
#endif |
|
339 |
||
340 |
#ifndef __EPOC32__ |
|
341 |
// The SymbianOS implementation allocates this space at thread creation |
|
342 |
||
343 |
// Initialiser |
|
344 |
void* __ARM_exceptions_buffer_init(void) |
|
345 |
{ |
|
346 |
emergency_buffer *buffer = (emergency_buffer *)malloc(sizeof(emergency_buffer)); |
|
347 |
if (buffer == NULL) return NULL; |
|
348 |
buffer->inuse = false; |
|
349 |
return buffer; |
|
350 |
} |
|
351 |
#endif |
|
352 |
||
353 |
// Allocator |
|
354 |
void *__ARM_exceptions_buffer_allocate(void *buffer, size_t size) |
|
355 |
{ |
|
356 |
emergency_buffer *b = (emergency_buffer *)buffer; |
|
266
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
357 |
|
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
358 |
#ifndef __EPOC32__ |
0 | 359 |
if (size > sizeof(emergency_eco) || b == NULL || b->inuse) return NULL; |
360 |
b->inuse = true; |
|
361 |
return &b->eco; |
|
266
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
362 |
#else |
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
363 |
ASSERT(b); |
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
364 |
|
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
365 |
if (size > sizeof(emergency_eco) || b->inuse) { |
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
366 |
// The first buffer isn't usable; try the second one instead, if it exists. |
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
367 |
if (b->em_buf2_p) |
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
368 |
return b->em_buf2_p->Alloc(size); |
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
369 |
else |
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
370 |
return NULL; |
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
371 |
} |
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
372 |
else { |
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
373 |
b->inuse = true; |
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
374 |
return &b->eco; |
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
375 |
} |
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
376 |
#endif |
0 | 377 |
} |
378 |
||
379 |
// Deallocator: Must return non-NULL if and only if it recognises |
|
380 |
// and releases the supplied object |
|
381 |
void *__ARM_exceptions_buffer_free(void *buffer, void *addr) |
|
382 |
{ |
|
383 |
emergency_buffer *b = (emergency_buffer *)buffer; |
|
266
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
384 |
|
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
385 |
#ifndef __EPOC32__ |
0 | 386 |
if (b == NULL || addr != &b->eco) return NULL; |
387 |
b->inuse = false; |
|
388 |
return b; |
|
266
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
389 |
#else |
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
390 |
ASSERT(b); |
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
391 |
|
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
392 |
if (addr != &b->eco) { |
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
393 |
// The object wasn't from the first buffer; see if it is from the second one. |
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
394 |
if (b->em_buf2_p) |
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
395 |
return b->em_buf2_p->Free(addr); |
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
396 |
else |
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
397 |
return NULL; |
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
398 |
} |
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
399 |
else { |
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
400 |
b->inuse = false; |
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
401 |
return b; |
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
402 |
} |
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
403 |
#endif |
0 | 404 |
} |
405 |
||
406 |
# if 0 |
|
407 |
// Hook activation support - see comments earlier |
|
408 |
extern "C" WEAKDECL void __ARM_exceptions_buffer_required(void); |
|
409 |
void (*(__ARM_exceptions_buffer_required_address(void)))(void) |
|
410 |
{ |
|
411 |
return &__ARM_exceptions_buffer_required; |
|
412 |
} |
|
413 |
# endif |
|
414 |
||
415 |
||
416 |
#endif /* arm_exceptions_mem_c */ |
|
417 |
#ifdef arm_exceptions_uncaught_c |
|
418 |
||
419 |
/* ---- uncaught_exception() ---- */ |
|
420 |
||
421 |
/* The EDG (and I think our) interpretation is that if the implementation |
|
422 |
* ever called terminate(), uncaught_exception() should return true. |
|
423 |
*/ |
|
424 |
#if __ARMCC_VERSION < 220000 |
|
425 |
bool std::uncaught_exception(void) |
|
426 |
#else |
|
427 |
EXPORT_C bool std::uncaught_exception(void) |
|
428 |
#endif |
|
429 |
{ |
|
430 |
__cxa_eh_globals *g = __cxa_get_globals(); |
|
431 |
return g->implementation_ever_called_terminate || g->uncaughtExceptions; |
|
432 |
} |
|
433 |
||
434 |
||
435 |
#endif /* arm_exceptions_uncaught_c */ |
|
436 |
#ifdef arm_exceptions_terminate_c |
|
437 |
||
438 |
/* ---- terminate() etc ---- */ |
|
439 |
||
440 |
/* The behaviour of terminate() must differ between calls by the |
|
441 |
* implementation and calls by the application. This is achieved by having the |
|
442 |
* implementation set call_hook immediately before the call to terminate(). |
|
443 |
* The hook called by terminate() should terminate the program without |
|
444 |
* returning to the caller. There is no requirement for terminate() itself to |
|
445 |
* intercept throws. |
|
446 |
*/ |
|
447 |
||
448 |
EXPORT_C void std::terminate(void) |
|
449 |
{ |
|
450 |
__cxa_eh_globals *g = __cxa_get_globals(); |
|
451 |
||
452 |
if (g->call_hook != NULL) { |
|
453 |
// Clear then call hook fn we were passed |
|
454 |
handler call_hook = g->call_hook; |
|
455 |
g->call_hook = NULL; |
|
456 |
call_hook(); |
|
457 |
} else { |
|
458 |
// Call global hook fn |
|
459 |
g->terminateHandler(); |
|
460 |
} |
|
461 |
// If hook fn returns: |
|
462 |
abort(); |
|
463 |
} |
|
464 |
||
465 |
||
466 |
#endif /* arm_exceptions_terminate_c */ |
|
467 |
#ifdef arm_exceptions_setterminate_c |
|
468 |
||
469 |
EXPORT_C terminate_handler std::set_terminate(terminate_handler h) throw() |
|
470 |
{ |
|
471 |
__cxa_eh_globals *g = __cxa_get_globals(); |
|
472 |
terminate_handler old = g->terminateHandler; |
|
473 |
g->terminateHandler = h; |
|
474 |
return old; |
|
475 |
} |
|
476 |
||
477 |
||
478 |
#endif /* arm_exceptions_setterminate_c */ |
|
479 |
#ifdef arm_exceptions_unexpected_c |
|
480 |
||
481 |
/* ---- unexpected() etc ---- */ |
|
482 |
/* Comments as per terminate() */ |
|
483 |
||
484 |
void NAMES::default_unexpected_handler(void) { |
|
485 |
terminate(); |
|
486 |
} |
|
487 |
||
488 |
#pragma exceptions_unwind |
|
489 |
||
490 |
EXPORT_C void std::unexpected(void) |
|
491 |
{ |
|
492 |
__cxa_eh_globals *g = __cxa_get_globals(); |
|
493 |
||
494 |
if (g->call_hook != NULL) { |
|
495 |
// Clear then call hook fn we were passed |
|
496 |
handler call_hook = g->call_hook; |
|
497 |
g->call_hook = NULL; |
|
498 |
call_hook(); |
|
499 |
} else { |
|
500 |
// Call global hook fn |
|
501 |
g->unexpectedHandler(); |
|
502 |
} |
|
503 |
||
504 |
// If hook fn returns: |
|
505 |
abort(); |
|
506 |
} |
|
507 |
||
508 |
||
509 |
#endif /* arm_exceptions_unexpected_c */ |
|
510 |
#ifdef arm_exceptions_setunexpected_c |
|
511 |
||
512 |
EXPORT_C unexpected_handler std::set_unexpected(unexpected_handler h) throw() |
|
513 |
{ |
|
514 |
__cxa_eh_globals *g = __cxa_get_globals(); |
|
515 |
unexpected_handler old = g->unexpectedHandler; |
|
516 |
g->unexpectedHandler = h; |
|
517 |
return old; |
|
518 |
} |
|
519 |
||
520 |
||
521 |
#endif /* arm_exceptions_setunexpected_c */ |
|
522 |
#ifdef arm_exceptions_support_c |
|
523 |
||
524 |
/* ---------- Helper functions: ---------- */ |
|
525 |
||
526 |
/* Two routines to determine whether two exceptions objects share a layout. |
|
527 |
* This is determined by checking whether the UCB exception_class members |
|
528 |
* are identical. |
|
529 |
* In principle we could use memcmp to perform this check (the code is |
|
530 |
* given below) but the check is quite frequent and so that is costly. |
|
531 |
* Therefore for efficiency we make use of the fact that the UCB is |
|
532 |
* word aligned, that the exception_class member is consequently |
|
533 |
* word aligned within it, and that we know the size of the member. |
|
534 |
* We take care elsewhere to only ever call the routines with pointers |
|
535 |
* to word-aligned addresses. |
|
536 |
*/ |
|
537 |
||
538 |
#if 0 |
|
539 |
||
540 |
// Straightforward versions |
|
541 |
||
542 |
bool NAMES::same_exceptions_class(const void *ec1, const void *ec2) |
|
543 |
{ |
|
544 |
return memcmp(ec1, ec2, EXCEPTIONS_CLASS_SIZE) == 0; // identical |
|
545 |
} |
|
546 |
||
547 |
// One of our exception objects, or not? |
|
548 |
||
549 |
bool NAMES::is_foreign_exception(UCB *ucbp) |
|
550 |
{ |
|
551 |
return !NAMES::same_exceptions_class(&ucbp->exception_class, ARMCPP_EXCEPTIONS_CLASS); |
|
552 |
} |
|
553 |
||
554 |
#else |
|
555 |
||
556 |
// Faster versions |
|
557 |
||
558 |
bool NAMES::same_exceptions_class(const void *ec1, const void *ec2) |
|
559 |
{ |
|
560 |
uint32_t *ip1 = (uint32_t *)ec1; |
|
561 |
uint32_t *ip2 = (uint32_t *)ec2; |
|
562 |
return ip1[0] == ip2[0] && ip1[1] == ip2[1]; |
|
563 |
} |
|
564 |
||
565 |
// One of our exception objects, or not? |
|
566 |
||
567 |
bool NAMES::is_foreign_exception(UCB *ucbp) |
|
568 |
{ |
|
569 |
// Need a word-aligned copy of the string |
|
570 |
static const union { |
|
571 |
const char s[EXCEPTIONS_CLASS_SIZE+1]; int dummy; |
|
572 |
} is_foreign_exception_static = {ARMCPP_EXCEPTIONS_CLASS}; |
|
573 |
return !NAMES::same_exceptions_class(&ucbp->exception_class, &is_foreign_exception_static.s); |
|
574 |
} |
|
575 |
||
576 |
#endif |
|
577 |
||
578 |
||
579 |
#endif /* arm_exceptions_support_c */ |
|
580 |
#ifdef arm_exceptions_callterm_c |
|
581 |
||
582 |
/* When the implementation wants to call terminate(), do the following: |
|
583 |
* Mark the object as "caught" so it can be rethrown. |
|
584 |
* Set the hook function for terminate() to call; |
|
585 |
* Mark the fact that terminate() has been called by the implementation; |
|
586 |
* We have to be careful - the implementation might encounter an error while |
|
587 |
* unwinding a foreign exception, and also it is possible this might be |
|
588 |
* called after failing to obtain a ucb. |
|
589 |
*/ |
|
590 |
||
591 |
void NAMES::call_terminate_handler(UCB *ucbp) |
|
592 |
{ |
|
593 |
__cxa_eh_globals *g = __cxa_get_globals(); |
|
594 |
||
595 |
if (ucbp == NULL) { |
|
596 |
// Call global hook |
|
597 |
g->call_hook = g->terminateHandler; |
|
598 |
} else { |
|
599 |
// Extract the hook to call |
|
600 |
if (NAMES::is_foreign_exception(ucbp)) { |
|
601 |
// Someone else's |
|
602 |
g->call_hook = g->terminateHandler; // best we can do under the circumstances |
|
603 |
} else { |
|
604 |
// One of ours |
|
605 |
__cxa_exception *ep = ucbp_to_ep(ucbp); |
|
606 |
g->call_hook = ep->terminateHandler; // the one in force at the point of throw |
|
607 |
} |
|
608 |
} |
|
609 |
||
610 |
g->implementation_ever_called_terminate = true; |
|
611 |
terminate(); |
|
612 |
// never returns |
|
613 |
} |
|
614 |
||
615 |
||
616 |
EXPORT_C void __cxa_call_terminate(UCB *ucbp) |
|
617 |
{ |
|
618 |
if (ucbp != NULL) // Record entry to (implicit) handler |
|
619 |
__cxa_begin_catch(ucbp); |
|
620 |
||
621 |
NAMES::call_terminate_handler(ucbp); |
|
622 |
// never returns |
|
623 |
} |
|
624 |
||
625 |
||
626 |
#endif /* arm_exceptions_callterm_c */ |
|
627 |
#ifdef arm_exceptions_callunex_c |
|
628 |
||
629 |
/* When the implementation wants to call unexpected(), do the following: |
|
630 |
* Mark the object as "caught" so it can be rethrown. |
|
631 |
* Set the hook function for unexpected() to call; |
|
632 |
* Call unexpected and trap any throw to make sure it is acceptable. |
|
633 |
* We have to be careful - the implementation might encounter an error while |
|
634 |
* unwinding a foreign exception. |
|
635 |
*/ |
|
636 |
||
637 |
#pragma exceptions_unwind |
|
638 |
||
639 |
EXPORT_C void __cxa_call_unexpected(UCB *ucbp) |
|
640 |
{ |
|
641 |
||
642 |
// Extract data we will need from the barrier cache before |
|
643 |
// anyone has a chance to overwrite it |
|
644 |
||
645 |
uint32_t rtti_count = ucbp->barrier_cache.bitpattern[BARRIER_FNSPECCOUNT]; |
|
646 |
uint32_t base = ucbp->barrier_cache.bitpattern[BARRIER_FNSPECBASE]; |
|
647 |
uint32_t stride = ucbp->barrier_cache.bitpattern[BARRIER_FNSPECSTRIDE]; |
|
648 |
uint32_t rtti_offset_array_addr = ucbp->barrier_cache.bitpattern[BARRIER_FNSPECARRAY]; |
|
649 |
||
650 |
// Also get the globals here and the eop |
|
651 |
||
652 |
__cxa_eh_globals *g = __cxa_get_globals(); |
|
653 |
__cxa_exception *ep = ucbp_to_ep(ucbp); |
|
654 |
||
655 |
#ifdef ARM_EXCEPTIONS_ENABLED |
|
656 |
try { |
|
657 |
#endif |
|
658 |
||
659 |
// Record entry to (implicit) handler |
|
660 |
||
661 |
__cxa_begin_catch(ucbp); |
|
662 |
||
663 |
// Now extract the hook to call |
|
664 |
||
665 |
if (NAMES::is_foreign_exception(ucbp)) { |
|
666 |
// Someone else's |
|
667 |
g->call_hook = g->unexpectedHandler; // best we can do under the circumstances |
|
668 |
} else { |
|
669 |
// One of ours |
|
670 |
g->call_hook = ep->unexpectedHandler; // the one in force at the point of throw |
|
671 |
} |
|
672 |
unexpected(); // never returns normally, but might throw something |
|
673 |
||
674 |
#ifdef ARM_EXCEPTIONS_ENABLED |
|
675 |
} catch (...) { |
|
676 |
||
677 |
// Unexpected() threw. This requires some delicacy. |
|
678 |
// There are 2 possibilities: |
|
679 |
// i) rethrow of the same object |
|
680 |
// ii) throw of a new object |
|
681 |
// Unexpected() is an implicit handler, and we manually called |
|
682 |
// __cxa_begin_catch on the ingoing object. We need to call |
|
683 |
// __cxa_end_catch on that object and, if the object is no longer |
|
684 |
// being handled (possible in case ii), this will cause its destruction. |
|
685 |
// The wrinkle is that in case ii the object is not on top of the catch |
|
686 |
// stack because we just caught something else. |
|
687 |
||
688 |
// Get hold of what was thrown (which we just caught). |
|
689 |
||
690 |
__cxa_exception *epnew = g->caughtExceptions; |
|
691 |
||
692 |
// Call __cxa_end_catch on the original object, taking care with the catch chain |
|
693 |
||
694 |
if (epnew == ep) { |
|
695 |
// rethrow - easy & safe - object is at top of chain and handlercount > 1 |
|
696 |
__cxa_end_catch(); |
|
697 |
} else { |
|
698 |
// not rethrow - unchain the top (new) object, clean up the next one, |
|
699 |
// and put the top object back |
|
700 |
||
701 |
// unchain |
|
702 |
g->caughtExceptions = epnew->nextCaughtException; |
|
703 |
// assert g->caughtExceptions == ep now |
|
704 |
// Decrement its handlercount (this might call a dtor if the count goes to 0, |
|
705 |
// and the dtor might throw - if it does, just give up) |
|
706 |
try { |
|
707 |
__cxa_end_catch(); |
|
708 |
} catch(...) { |
|
709 |
terminate(); |
|
710 |
} |
|
711 |
// Chain back in |
|
712 |
epnew->nextCaughtException = g->caughtExceptions; |
|
713 |
g->caughtExceptions = epnew; |
|
714 |
} |
|
715 |
||
716 |
// See whether what was thrown is permitted, and in passing |
|
717 |
// see if std::bad_exception is permitted |
|
718 |
||
719 |
bool bad_exception_permitted = false; |
|
720 |
uint32_t i; |
|
721 |
for (i = 0; i < rtti_count; i++) { |
|
722 |
void *matched_object; |
|
723 |
type_info *fnspec; |
|
724 |
if (EHABI_V2(ucbp)) |
|
725 |
fnspec = (type_info *)__ARM_resolve_target2((void *)rtti_offset_array_addr); |
|
726 |
else |
|
727 |
fnspec = (type_info *)(*(uint32_t *)rtti_offset_array_addr + base); |
|
728 |
if (__cxa_type_match(&(epnew->ucb), fnspec, false, &matched_object)) { |
|
729 |
#ifdef CPP_DIAGNOSTICS |
|
730 |
printf("__cxa_call_unexpected: fnspec matched\n"); |
|
731 |
#endif |
|
732 |
throw; // got a match - propagate it |
|
733 |
} |
|
734 |
if (typeid(std::bad_exception) == *fnspec) |
|
735 |
bad_exception_permitted = true; |
|
736 |
rtti_offset_array_addr += stride; |
|
737 |
} |
|
738 |
||
739 |
// There was no match... |
|
740 |
if (bad_exception_permitted) throw std::bad_exception(); // transmute |
|
741 |
||
742 |
// Otherwise call epnew's terminate handler |
|
743 |
NAMES::call_terminate_handler(&epnew->ucb); |
|
744 |
} |
|
745 |
#endif |
|
746 |
} |
|
747 |
||
748 |
||
749 |
#endif /* arm_exceptions_callunex_c */ |
|
750 |
#ifdef arm_exceptions_currenttype_c |
|
751 |
||
752 |
/* Yield the type of the currently handled exception, or null if none or the |
|
753 |
* object is foreign. |
|
754 |
*/ |
|
755 |
||
756 |
EXPORT_C const type_info *__cxa_current_exception_type(void) |
|
757 |
{ |
|
758 |
__cxa_eh_globals *g = __cxa_get_globals(); |
|
759 |
__cxa_exception *ep = g->caughtExceptions; |
|
760 |
if (ep == NULL || NAMES::is_foreign_exception(&ep->ucb)) return NULL; |
|
761 |
return ep->exceptionType; |
|
762 |
} |
|
763 |
||
764 |
||
765 |
#endif /* arm_exceptions_currenttype_c */ |
|
766 |
#ifdef arm_exceptions_alloc_c |
|
767 |
||
768 |
/* Allocate store for controlling an exception propagation */ |
|
769 |
||
770 |
EXPORT_C void *__cxa_allocate_exception(size_t size) |
|
771 |
{ |
|
772 |
__cxa_eh_globals *g = __cxa_get_globals(); |
|
773 |
||
774 |
// Allocate store for a __cxa_exception header and the EO. |
|
775 |
// Allocated store should be thread-safe and persistent, and must do |
|
776 |
// something sensible if the allocation fails |
|
777 |
||
778 |
size_t total_size = size + sizeof(__cxa_exception); |
|
779 |
// coverity[alloc_fn] |
|
780 |
__cxa_exception *ep = (__cxa_exception *)malloc(total_size); |
|
781 |
if (ep == NULL) { |
|
782 |
// Try the emergency memory pool |
|
783 |
SYMBIAN_EH_SUPPORT_PRINTF("Trying emergency buffer: size %d\n", total_size); |
|
784 |
ep = (__cxa_exception *)__ARM_exceptions_buffer_allocate(g->emergency_buffer, total_size); |
|
785 |
||
786 |
if (ep == NULL) { |
|
787 |
SYMBIAN_EH_SUPPORT_PRINTF("Emergency buffer allocation failed. Terminating\n"); |
|
788 |
NAMES::call_terminate_handler(NULL); |
|
789 |
} |
|
790 |
} |
|
791 |
||
792 |
UCB *ucbp = &ep->ucb; |
|
793 |
||
794 |
// Initialise the UCB |
|
795 |
||
796 |
memcpy(ucbp->exception_class, ARMCPP_EXCEPTIONS_CLASS, EXCEPTIONS_CLASS_SIZE); |
|
797 |
ucbp->exception_cleanup = NULL; /* initialise properly before throwing */ |
|
798 |
ucbp->unwinder_cache.reserved1 = 0; /* required to do this */ |
|
799 |
||
800 |
// Initialise parts of the LEO, in case copy-construction of the EO results |
|
801 |
// in a need to call terminate (via __cxa_call_terminate) |
|
802 |
||
803 |
ep->handlerCount = 0; // Not in any handlers |
|
804 |
ep->nextCaughtException = NULL; // Not in any handlers |
|
805 |
ep->nextPropagatingException = NULL; // Not saved over cleanup |
|
806 |
ep->propagationCount = 0; // Not propagating |
|
807 |
ep->terminateHandler = g->terminateHandler; // Cache current terminate handler |
|
808 |
ep->unexpectedHandler = g->unexpectedHandler; // Cache current unexpected handler |
|
809 |
||
810 |
// Return pointer to the EO |
|
811 |
// coverity[memory_leak] |
|
812 |
return ep + 1; |
|
813 |
} |
|
814 |
||
815 |
||
816 |
#endif /* arm_exceptions_alloc_c */ |
|
817 |
#ifdef arm_exceptions_free_c |
|
818 |
||
819 |
/* Free store allocated by __cxa_allocate_exception */ |
|
820 |
||
821 |
EXPORT_C void __cxa_free_exception(void *eop) |
|
822 |
{ |
|
823 |
__cxa_eh_globals *g = __cxa_get_globals(); |
|
824 |
char *ep = (char *)eop - sizeof(__cxa_exception); |
|
825 |
if (__ARM_exceptions_buffer_free(g->emergency_buffer, ep)) return; |
|
826 |
free(ep); |
|
827 |
} |
|
828 |
||
829 |
||
830 |
#endif /* arm_exceptions_free_c */ |
|
831 |
#ifdef arm_exceptions_throw_c |
|
832 |
||
833 |
/* This routine is called when a foreign runtime catches one of our exception |
|
834 |
* objects and then exits its catch by a means other than rethrow. |
|
835 |
* We should clean it up as if we had caught it ourselves. |
|
836 |
*/ |
|
837 |
||
838 |
static void external_exception_termination(_Unwind_Reason_Code c, UCB *ucbp) |
|
839 |
{ |
|
840 |
NAMES::eh_catch_semantics(ucbp); |
|
841 |
__cxa_end_catch(); |
|
842 |
} |
|
843 |
||
844 |
||
845 |
/* Initiate a throw */ |
|
846 |
||
847 |
#pragma push |
|
848 |
#pragma exceptions_unwind |
|
849 |
||
850 |
EXPORT_C void __cxa_throw(void *eop, const type_info *t, cppdtorptr d) |
|
851 |
{ |
|
852 |
__cxa_exception *ep = (__cxa_exception *)((char *)eop - sizeof(__cxa_exception)); |
|
853 |
UCB *ucbp = &ep->ucb; |
|
854 |
||
855 |
// Initialise the remaining LEO and UCB fields not done by __cxa_allocate_exception |
|
856 |
||
857 |
ucbp->exception_cleanup = external_exception_termination; |
|
858 |
ep->exceptionType = t; |
|
859 |
ep->exceptionDestructor = d; |
|
860 |
ep->propagationCount = 1; // Propagating by 1 throw |
|
861 |
||
862 |
// Increment the uncaught C++ exceptions count |
|
863 |
||
864 |
__cxa_eh_globals *g = __cxa_get_globals(); |
|
865 |
g->uncaughtExceptions++; |
|
866 |
||
867 |
// Tell debugger what's happening |
|
868 |
||
869 |
DEBUGGER_BOTTLENECK(ucbp, _UASUBSYS_CPP, _UAACT_STARTING, t); |
|
870 |
||
871 |
// Initiate unwinding - if we get control back, call C++ routine terminate() |
|
872 |
||
873 |
_Unwind_RaiseException(ucbp); |
|
874 |
||
875 |
#ifdef CPP_DIAGNOSTICS |
|
876 |
printf("__cxa_throw: throw failed\n"); |
|
877 |
#endif |
|
878 |
||
879 |
__cxa_call_terminate(ucbp); |
|
880 |
} |
|
881 |
||
882 |
#pragma pop |
|
883 |
||
884 |
/* ----- Type matching: ----- */ |
|
885 |
||
886 |
/* This is located here so that (in ARM's implementation) it is only retained in |
|
887 |
* an image if the application itself throws. |
|
888 |
*/ |
|
889 |
||
890 |
/* Type matching functions. |
|
891 |
* C++ DR126 says the matching rules for fnspecs are intended to be the same as |
|
892 |
* those for catch: |
|
893 |
* "A function is said to allow an exception of type E if its exception-specification |
|
894 |
* contains a type T for which a handler of type T would be a match (15.3 except.handle) |
|
895 |
* for an exception of type E." |
|
896 |
* Thus we have a single type matching rule. |
|
897 |
*/ |
|
898 |
||
899 |
/* Helper macros: */ |
|
900 |
||
901 |
#define CV_quals_of_pointee(P) (((const abi::__pbase_type_info *)(P))->__flags & \ |
|
902 |
(abi::__pbase_type_info::__const_mask | \ |
|
903 |
abi::__pbase_type_info::__volatile_mask)) |
|
904 |
||
905 |
#define is_const(QUALS) (((QUALS) & abi::__pbase_type_info::__const_mask) != 0) |
|
906 |
||
907 |
#define any_qualifier_missing(TEST_QUALS, REF_QUALS) ((~(TEST_QUALS) & (REF_QUALS)) != 0) |
|
908 |
||
909 |
/* A routine is required for derived class to base class conversion. |
|
910 |
* This is obtained via a macro definition DERIVED_TO_BASE_CONVERSION |
|
911 |
* in unwind_env.h. |
|
912 |
*/ |
|
913 |
||
914 |
/* External entry point: |
|
915 |
* Type check the c++ rtti object for compatibility against the type of |
|
916 |
* the object containing the ucb. Return a pointer to the matched object |
|
917 |
* (possibly a non-leftmost baseclass of the exception object) |
|
918 |
*/ |
|
919 |
EXPORT_C __cxa_type_match_result __cxa_type_match(UCB *ucbp, const type_info *match_type, |
|
920 |
bool is_reference_type, void **matched_objectpp) |
|
921 |
{ |
|
922 |
if (NAMES::is_foreign_exception(ucbp)) |
|
923 |
return ctm_failed; |
|
924 |
||
925 |
__cxa_exception *ep = ucbp_to_ep(ucbp); |
|
926 |
const type_info *throw_type = ep->exceptionType; |
|
927 |
bool previous_qualifiers_include_const = true; // for pointer qualification conversion |
|
928 |
unsigned int pointer_depth = 0; |
|
929 |
void *original_objectp = ep + 1; |
|
930 |
void *current_objectp = original_objectp; |
|
931 |
||
932 |
for (;;) { |
|
933 |
||
934 |
// Match if identical |
|
935 |
||
936 |
if (*throw_type == *match_type) { |
|
937 |
*matched_objectpp = original_objectp; |
|
938 |
#ifdef CPP_DIAGNOSTICS |
|
939 |
printf("__cxa_type_match: success\n"); |
|
940 |
#endif |
|
941 |
return ctm_succeeded; |
|
942 |
} |
|
943 |
||
944 |
// Fail if one is a pointer and the other isn't |
|
945 |
||
946 |
const type_info &type_throw_type = typeid(*throw_type); |
|
947 |
const type_info &type_match_type = typeid(*match_type); |
|
948 |
||
949 |
if ((type_throw_type == typeid(abi::__pointer_type_info) || |
|
950 |
type_match_type == typeid(abi::__pointer_type_info)) && |
|
951 |
type_throw_type != type_match_type) { |
|
952 |
#ifdef CPP_DIAGNOSTICS |
|
953 |
printf("__cxa_type_match: failed (mixed ptr/non-ptr)\n"); |
|
954 |
#endif |
|
955 |
return ctm_failed; |
|
956 |
} |
|
957 |
||
958 |
// Both are pointers or neither is |
|
959 |
if (type_throw_type == typeid(abi::__pointer_type_info)) { |
|
960 |
// Both are pointers |
|
961 |
#ifdef CPP_DIAGNOSTICS |
|
962 |
printf("__cxa_type_match: throwing a ptr\n"); |
|
963 |
#endif |
|
964 |
pointer_depth++; |
|
965 |
// Check match_type is at least as CV-qualified as throw_type |
|
966 |
unsigned int match_quals = CV_quals_of_pointee(match_type); |
|
967 |
unsigned int throw_quals = CV_quals_of_pointee(throw_type); |
|
968 |
if (any_qualifier_missing(match_quals, throw_quals)) { |
|
969 |
#ifdef CPP_DIAGNOSTICS |
|
970 |
printf("__cxa_type_match: failed (missing qualifiers)\n"); |
|
971 |
#endif |
|
972 |
return ctm_failed; |
|
973 |
} |
|
974 |
// If the match type has additional qualifiers not found in the |
|
975 |
// throw type, any previous qualifiers must have included const |
|
976 |
if (any_qualifier_missing(throw_quals, match_quals) && |
|
977 |
!previous_qualifiers_include_const) { |
|
978 |
#ifdef CPP_DIAGNOSTICS |
|
979 |
printf("__cxa_type_match: failed (not all qualifiers have const)\n"); |
|
980 |
#endif |
|
981 |
return ctm_failed; |
|
982 |
} |
|
983 |
if (!is_const(match_quals)) |
|
984 |
previous_qualifiers_include_const = false; |
|
985 |
throw_type = ((const abi::__pbase_type_info *)throw_type)->__pointee; |
|
986 |
match_type = ((const abi::__pbase_type_info *)match_type)->__pointee; |
|
987 |
if (current_objectp != NULL) |
|
988 |
current_objectp = *(void **)current_objectp; |
|
989 |
continue; |
|
990 |
} |
|
991 |
||
992 |
// Neither is a pointer now but qualification conversion has been done. |
|
993 |
// See if pointer conversion on the original was possible. |
|
994 |
// T* will match void* |
|
995 |
||
996 |
if (pointer_depth == 1 && *match_type == typeid(void)) { |
|
997 |
if (is_reference_type) { |
|
998 |
#ifdef CPP_DIAGNOSTICS |
|
999 |
printf("__cxa_type_match: failed (void *&)\n"); |
|
1000 |
#endif |
|
1001 |
return ctm_failed; |
|
1002 |
} else { |
|
1003 |
*matched_objectpp = original_objectp; |
|
1004 |
#ifdef CPP_DIAGNOSTICS |
|
1005 |
printf("__cxa_type_match: success (conversion to void *)\n"); |
|
1006 |
#endif |
|
1007 |
return ctm_succeeded; |
|
1008 |
} |
|
1009 |
} |
|
1010 |
||
1011 |
// Else if we have 2 (different) class types, a derived class is matched by a |
|
1012 |
// non-ambiguous public base class (perhaps not a leftmost one) and a |
|
1013 |
// pointer to a derived class is matched by a non-reference pointer to |
|
1014 |
// non-ambiguous public base class (perhaps not a leftmost one). |
|
1015 |
// __si_class_type_info and __vmi_class_type_info are classes with bases. |
|
1016 |
||
1017 |
void *matched_base_p; |
|
1018 |
||
1019 |
if ((pointer_depth == 0 || (pointer_depth == 1 && !is_reference_type)) && |
|
1020 |
(type_throw_type == typeid(abi::__si_class_type_info) || |
|
1021 |
type_throw_type == typeid(abi::__vmi_class_type_info))) { |
|
1022 |
if (DERIVED_TO_BASE_CONVERSION(current_objectp, &matched_base_p, |
|
1023 |
throw_type, match_type)) { |
|
1024 |
#ifdef CPP_DIAGNOSTICS |
|
1025 |
printf("__cxa_type_match: success (matched base 0x%x of 0x%x%s, thrown object 0x%x)\n", |
|
1026 |
matched_base_p, current_objectp, |
|
1027 |
pointer_depth == 0 ? "" : " via ptr", |
|
1028 |
original_objectp); |
|
1029 |
#endif |
|
1030 |
*matched_objectpp = matched_base_p; |
|
1031 |
return pointer_depth == 0 ? ctm_succeeded : ctm_succeeded_with_ptr_to_base; |
|
1032 |
} else { |
|
1033 |
#ifdef CPP_DIAGNOSTICS |
|
1034 |
printf("__cxa_type_match: failed (derived to base failed or ref to base pointer)\n"); |
|
1035 |
#endif |
|
1036 |
return ctm_failed; |
|
1037 |
} |
|
1038 |
} |
|
1039 |
||
1040 |
#ifdef CPP_DIAGNOSTICS |
|
1041 |
printf("__cxa_type_match: failed (types simply differ)\n"); |
|
1042 |
#endif |
|
1043 |
return ctm_failed; |
|
1044 |
} /* for */ |
|
1045 |
} |
|
1046 |
||
1047 |
||
1048 |
/* For debugging purposes: */ |
|
1049 |
#ifdef DEBUG |
|
1050 |
extern "C" bool debug__cxa_type_match(void *objptr, |
|
1051 |
const type_info *throw_type, |
|
1052 |
const type_info *catch_type, |
|
1053 |
void **matched_objectpp) |
|
1054 |
{ |
|
1055 |
/* Create enough of an exception object that the type-matcher can run, then |
|
1056 |
* check the type. Objptr is expected to be the result of a call to |
|
1057 |
* __cxa_allocate_exception, which has then been copy-constructed. |
|
1058 |
*/ |
|
1059 |
__cxa_exception *e = ((__cxa_exception *)objptr) - 1; |
|
1060 |
e->exceptionType = throw_type; |
|
1061 |
return __cxa_type_match(&e->ucb, catch_type, false, matched_objectpp); |
|
1062 |
} |
|
1063 |
#endif |
|
1064 |
||
1065 |
||
1066 |
#endif /* arm_exceptions_throw_c */ |
|
1067 |
#ifdef arm_exceptions_rethrow_c |
|
1068 |
||
1069 |
/* Redeclare _Unwind_RaiseException as weak (if WEAKDECL is defined |
|
1070 |
* appropriately) so the use from __cxa_rethrow does not on its own |
|
1071 |
* force the unwind library to be loaded. |
|
1072 |
*/ |
|
1073 |
||
1074 |
extern "C" WEAKDECL _Unwind_Reason_Code _Unwind_RaiseException(UCB *ucbp); |
|
1075 |
||
1076 |
#pragma exceptions_unwind |
|
1077 |
||
1078 |
EXPORT_C void __cxa_rethrow(void) |
|
1079 |
{ |
|
1080 |
// Recover the exception object - it is the most recent caught exception object |
|
1081 |
__cxa_eh_globals *g = __cxa_get_globals(); |
|
1082 |
__cxa_exception *ep = g->caughtExceptions; |
|
1083 |
bool foreign; |
|
1084 |
||
1085 |
// Must call terminate here if no such exception |
|
1086 |
if (ep == NULL) NAMES::call_terminate_handler(NULL); |
|
1087 |
||
1088 |
UCB *ucbp = &ep->ucb; |
|
1089 |
||
1090 |
// Mark the object as being propagated by throw, preventing multiple |
|
1091 |
// propagation and also permitting __cxa_end_catch to do the right |
|
1092 |
// thing when it is called from the handler's cleanup. |
|
1093 |
||
1094 |
ep->propagationCount++; |
|
1095 |
||
1096 |
// Now reraise, taking care with foreign exceptions |
|
1097 |
||
1098 |
foreign = NAMES::is_foreign_exception(ucbp); |
|
1099 |
if (foreign) { |
|
1100 |
// Indirect through the intermediate object to the foreign ucb |
|
1101 |
ucbp = (UCB *)ep->exceptionType; |
|
1102 |
} else { |
|
1103 |
// Increment the uncaught C++ exceptions count |
|
1104 |
g->uncaughtExceptions++; |
|
1105 |
} |
|
1106 |
||
1107 |
// Tell debugger what's happening |
|
1108 |
||
1109 |
DEBUGGER_BOTTLENECK(ucbp, _UASUBSYS_CPP, _UAACT_STARTING, foreign ? NULL : ep->exceptionType); |
|
1110 |
||
1111 |
// Initiate unwinding - if we get control back, call C++ routine terminate() |
|
1112 |
||
1113 |
_Unwind_RaiseException(ucbp); |
|
1114 |
||
1115 |
#ifdef CPP_DIAGNOSTICS |
|
1116 |
printf("__cxa_rethrow: throw failed\n"); |
|
1117 |
#endif |
|
1118 |
||
1119 |
__cxa_call_terminate(ucbp); |
|
1120 |
} |
|
1121 |
||
1122 |
#endif /* arm_exceptions_rethrow_c */ |
|
1123 |
#ifdef arm_exceptions_foreign_c |
|
1124 |
||
1125 |
/* During catch and cleanup, foreign exception objects are dealt with using |
|
1126 |
* an intermediate __cxa_exception block in the appropriate exceptions |
|
1127 |
* chain. This block has the same exception_class as the real foreign |
|
1128 |
* ucb, and points to the real ucb via the intermediate block's exceptionType |
|
1129 |
* field. This helper function checks whether it has been passed such an |
|
1130 |
* intermediate block and sets one up if not. Only call it when the UCB |
|
1131 |
* is known to belong to a foreign exception. |
|
1132 |
*/ |
|
1133 |
||
1134 |
__cxa_exception *NAMES::get_foreign_intermediary(__cxa_exception *head_ep, UCB *ucbp) |
|
1135 |
{ |
|
1136 |
if (head_ep != NULL) { |
|
1137 |
UCB *head_ucbp = &head_ep->ucb; |
|
1138 |
if (NAMES::same_exceptions_class(&head_ucbp->exception_class, &ucbp->exception_class) && |
|
1139 |
(UCB *)head_ep->exceptionType == ucbp) |
|
1140 |
return head_ep; |
|
1141 |
} |
|
1142 |
||
1143 |
// Create an intermediate block. Only initialise as much as necessary |
|
1144 |
__cxa_exception *ep = ((__cxa_exception *)__cxa_allocate_exception(0)) - 1; |
|
1145 |
UCB *new_ucbp = &ep->ucb; |
|
1146 |
memcpy(new_ucbp->exception_class, ucbp->exception_class, EXCEPTIONS_CLASS_SIZE); |
|
1147 |
ep->propagationCount = 0; // Not propagating |
|
1148 |
ep->handlerCount = 0; // Not handled |
|
1149 |
ep->nextCaughtException = NULL; // Not in chain |
|
1150 |
ep->exceptionType = (const type_info *)ucbp; // The foreign UCB |
|
1151 |
return ep; |
|
1152 |
} |
|
1153 |
||
1154 |
||
1155 |
#endif /* arm_exceptions_foreign_c */ |
|
1156 |
#ifdef arm_exceptions_cleanup_c |
|
1157 |
||
1158 |
EXPORT_C bool __cxa_begin_cleanup(UCB *ucbp) |
|
1159 |
{ |
|
1160 |
// Indicate that a cleanup is about to start. |
|
1161 |
// Save the exception pointer over the cleanup for recovery later, using a chain. |
|
1162 |
// If we allowed the exception to be rethrown in a cleanup, then |
|
1163 |
// the object might appear multiple times at the head of this chain, |
|
1164 |
// and the propagationCount could be used to track this - at this point, |
|
1165 |
// the object is logically in the chain propagationCount-1 times, and |
|
1166 |
// physically 0 or 1 times. Thus if propagationCount == 1 we should insert |
|
1167 |
// it physically. A similar rule is used for physical removal in |
|
1168 |
//__cxa_end_cleanup. |
|
1169 |
// Foreign exceptions are handled via an intermediate __cxa_exception object |
|
1170 |
// in a similar way as __cxa_begin_catch. |
|
1171 |
||
1172 |
__cxa_eh_globals *g = __cxa_get_globals(); |
|
1173 |
__cxa_exception *ep; |
|
1174 |
||
1175 |
if (NAMES::is_foreign_exception(ucbp)) { |
|
1176 |
// coverity[alloc_fn] coverity[var_assign] |
|
1177 |
ep = NAMES::get_foreign_intermediary(g->propagatingExceptions, ucbp); |
|
1178 |
ep->propagationCount++; // Indicate one (or one additional) propagation |
|
1179 |
} else { |
|
1180 |
ep = ucbp_to_ep(ucbp); |
|
1181 |
} |
|
1182 |
||
1183 |
if (ep->propagationCount == 1) { |
|
1184 |
// Insert into chain |
|
1185 |
ep->nextPropagatingException = g->propagatingExceptions; |
|
1186 |
g->propagatingExceptions = ep; |
|
1187 |
} |
|
1188 |
// coverity[leaked_storage] |
|
1189 |
return true; |
|
1190 |
} |
|
1191 |
||
1192 |
||
1193 |
// Helper function for __cxa_end_cleanup |
|
1194 |
||
1195 |
extern "C" UCB * __ARM_cxa_end_cleanup(void) |
|
1196 |
{ |
|
1197 |
// Recover and return the currently propagating exception (from the |
|
1198 |
// head of the propagatingExceptions chain). |
|
1199 |
// propagationCount at this moment is a logical count of how many times the |
|
1200 |
// item is in the chain so physically unchain it when this count is 1. |
|
1201 |
// Foreign exceptions use an intermediary. |
|
1202 |
||
1203 |
__cxa_eh_globals *g = __cxa_get_globals(); |
|
1204 |
__cxa_exception *ep = g->propagatingExceptions; |
|
1205 |
||
1206 |
if (ep == NULL) terminate(); |
|
1207 |
||
1208 |
UCB *ucbp = &ep->ucb; |
|
1209 |
if (NAMES::is_foreign_exception(ucbp)) { |
|
1210 |
// Get the foreign ucb |
|
1211 |
ucbp = (UCB *)ep->exceptionType; |
|
1212 |
if (ep->propagationCount == 1) { |
|
1213 |
// Free the intermediate ucb (see description in __cxa_begin_catch) |
|
1214 |
void *eop = (void *)(ep + 1); |
|
1215 |
g->propagatingExceptions = ep->nextPropagatingException; |
|
1216 |
__cxa_free_exception(eop); |
|
1217 |
} else { |
|
1218 |
ep->propagationCount--; |
|
1219 |
} |
|
1220 |
} else { |
|
1221 |
// Not foreign |
|
1222 |
if (ep->propagationCount == 1) { // logically in chain once - so unchain |
|
1223 |
g->propagatingExceptions = ep->nextPropagatingException; |
|
1224 |
} |
|
1225 |
} |
|
1226 |
return ucbp; |
|
1227 |
} |
|
1228 |
||
1229 |
// __cxa_end_cleanup is called at the end of a cleanup fragment. |
|
1230 |
// It must do the C++ housekeeping, then call _Unwind_Resume, but it must |
|
1231 |
// damage no significant registers in the process. |
|
1232 |
||
1233 |
EXPORT_C __asm void __cxa_end_cleanup(void) { |
|
1234 |
extern __ARM_cxa_end_cleanup; |
|
1235 |
extern _Unwind_Resume WEAKASMDECL; |
|
1236 |
||
1237 |
#ifdef __thumb |
|
1238 |
preserve8; // This is preserve8 (ARM assembler heuristics are inadequate) |
|
1239 |
push {r1-r7}; |
|
1240 |
mov r2, r8; |
|
1241 |
mov r3, r9; |
|
1242 |
mov r4, r10; |
|
1243 |
mov r5, r11; |
|
1244 |
push {r1-r5}; |
|
1245 |
bl __ARM_cxa_end_cleanup; // returns UCB address in r0 |
|
1246 |
pop {r1-r5}; |
|
1247 |
mov r8, r2; |
|
1248 |
mov r9, r3; |
|
1249 |
mov r10, r4; |
|
1250 |
mov r11, r5; |
|
1251 |
pop {r1-r7}; |
|
1252 |
bl _Unwind_Resume; // won't return |
|
1253 |
#else |
|
1254 |
stmfd r13!, {r1-r12} |
|
1255 |
bl __ARM_cxa_end_cleanup; // returns UCB address in r0 |
|
1256 |
ldmia r13!, {r1-r12}; |
|
1257 |
b _Unwind_Resume; // won't return |
|
1258 |
#endif |
|
1259 |
} |
|
1260 |
||
1261 |
||
1262 |
#endif /* arm_exceptions_cleanup_c */ |
|
1263 |
#ifdef arm_exceptions_catchsemantics_c |
|
1264 |
||
1265 |
/* Update date structures as if catching an object. |
|
1266 |
* Call this from __cxa_begin_catch when actually catching an object, |
|
1267 |
* and from external_exception_termination when called by a foreign runtime |
|
1268 |
* after one of our objects was caught. |
|
1269 |
*/ |
|
1270 |
||
1271 |
void NAMES::eh_catch_semantics(UCB *ucbp) |
|
1272 |
{ |
|
1273 |
__cxa_eh_globals *g = __cxa_get_globals(); |
|
1274 |
__cxa_exception *ep; |
|
1275 |
||
1276 |
if (NAMES::is_foreign_exception(ucbp)) { |
|
1277 |
// Foreign exception. Get the associated intermediary block or |
|
1278 |
// make one if there isn't one already. |
|
1279 |
// In the case of a rethrow, the foreign object may already be on |
|
1280 |
// the handled exceptions chain (it will be first). |
|
1281 |
// coverity[alloc_fn] coverity[var_assign] |
|
1282 |
ep = NAMES::get_foreign_intermediary(g->caughtExceptions, ucbp); |
|
1283 |
} else { |
|
1284 |
// Not foreign |
|
1285 |
ep = ucbp_to_ep(ucbp); |
|
1286 |
// Decrement the propagation count |
|
1287 |
ep->propagationCount--; |
|
1288 |
// Decrement the total uncaught C++ exceptions count |
|
1289 |
g->uncaughtExceptions--; |
|
1290 |
} |
|
1291 |
||
1292 |
// Common code for our EO's, and foreign ones where we work on the intermediate EO |
|
1293 |
||
1294 |
// Increment the handler count for this exception object |
|
1295 |
ep->handlerCount++; |
|
1296 |
||
1297 |
// Push the ep onto the "handled exceptions" chain if it is not already there. |
|
1298 |
// (If catching a rethrow, it may already be there) |
|
1299 |
||
1300 |
if (ep->nextCaughtException == NULL) { |
|
1301 |
ep->nextCaughtException = g->caughtExceptions; |
|
1302 |
g->caughtExceptions = ep; |
|
1303 |
} |
|
1304 |
// coverity[leaked_storage] |
|
1305 |
} |
|
1306 |
||
1307 |
||
1308 |
#endif /* arm_exceptions_catchsemantics_c */ |
|
1309 |
#ifdef arm_exceptions_getexceptionptr_c |
|
1310 |
||
1311 |
EXPORT_C void *__cxa_get_exception_ptr(UCB *ucbp) |
|
1312 |
{ |
|
1313 |
return (void *)ucbp->barrier_cache.bitpattern[BARRIER_HANDLEROBJECT]; // The matched object, if any |
|
1314 |
} |
|
1315 |
||
1316 |
||
1317 |
#endif /* arm_exceptions_getexceptionptr_c */ |
|
1318 |
#ifdef arm_exceptions_begincatch_c |
|
1319 |
||
1320 |
void *__cxa_begin_catch(UCB *ucbp) |
|
1321 |
{ |
|
1322 |
void *match = (void *)ucbp->barrier_cache.bitpattern[BARRIER_HANDLEROBJECT]; // The matched object, if any |
|
1323 |
||
1324 |
// Update the data structures |
|
1325 |
||
1326 |
NAMES::eh_catch_semantics(ucbp); |
|
1327 |
||
1328 |
// Tell the unwinder the exception propagation has finished, |
|
1329 |
// and return the object pointer |
|
1330 |
||
1331 |
_Unwind_Complete(ucbp); |
|
1332 |
return match; |
|
1333 |
} |
|
1334 |
||
1335 |
||
1336 |
#endif /* arm_exceptions_begincatch_c */ |
|
1337 |
#ifdef arm_exceptions_endcatch_c |
|
1338 |
||
1339 |
#pragma exceptions_unwind |
|
1340 |
||
1341 |
EXPORT_C void __cxa_end_catch(void) |
|
1342 |
{ |
|
1343 |
// Recover the exception object - it is the most recent caught exception object |
|
1344 |
__cxa_eh_globals *g = __cxa_get_globals(); |
|
1345 |
__cxa_exception *ep = g->caughtExceptions; |
|
1346 |
||
1347 |
if (ep == NULL) terminate(); |
|
1348 |
||
1349 |
// Rethrow in progress? |
|
1350 |
||
1351 |
bool object_being_rethrown = ep->propagationCount != 0; |
|
1352 |
||
1353 |
// Decrement the handler count for this exception object |
|
1354 |
ep->handlerCount--; |
|
1355 |
||
1356 |
// Unstack the object if it is no longer being handled anywhere. |
|
1357 |
// Destroy and free the object if it is no longer alive - |
|
1358 |
// it is dead if its handler count becomes 0, unless it is |
|
1359 |
// about to be rethrown. |
|
1360 |
// If the dtor throws, allow its exception to propagate. |
|
1361 |
// Do different things if it is a foreign exception object. |
|
1362 |
||
1363 |
if (ep->handlerCount == 0) { |
|
1364 |
void *eop = (void *)(ep + 1); |
|
1365 |
UCB *ucbp = &ep->ucb; |
|
1366 |
bool foreign = NAMES::is_foreign_exception(ucbp); |
|
1367 |
||
1368 |
// Unstack it from the caught exceptions stack - it is guaranteed to be top item. |
|
1369 |
g->caughtExceptions = ep->nextCaughtException; |
|
1370 |
||
1371 |
if (foreign) { |
|
1372 |
// Get the foreign ucb and free the intermediate ucb (see description in __cxa_begin_catch) |
|
1373 |
ucbp = (UCB *)ep->exceptionType; |
|
1374 |
__cxa_free_exception(eop); |
|
1375 |
} else { |
|
1376 |
ep->nextCaughtException = NULL; // So __cxa_begin_catch knows it isn't in the chain |
|
1377 |
} |
|
1378 |
||
1379 |
// Now destroy the exception object if it's no longer needed |
|
1380 |
if (!object_being_rethrown) { |
|
1381 |
if (foreign) { |
|
1382 |
||
1383 |
// Notify the foreign language, if it so requested |
|
1384 |
if (ucbp->exception_cleanup != NULL) |
|
1385 |
(ucbp->exception_cleanup)(_URC_FOREIGN_EXCEPTION_CAUGHT, ucbp); |
|
1386 |
||
1387 |
} else { |
|
1388 |
||
1389 |
// One of our objects: do C++-specific semantics |
|
1390 |
||
1391 |
if (ep->exceptionDestructor != NULL) { |
|
1392 |
// Run the dtor. If it throws, free the memory anyway and |
|
1393 |
// propagate the new exception. |
|
1394 |
#ifdef ARM_EXCEPTIONS_ENABLED |
|
1395 |
try { |
|
1396 |
(ep->exceptionDestructor)(eop); |
|
1397 |
} catch(...) { |
|
1398 |
// Free the memory and reraise |
|
1399 |
__cxa_free_exception(eop); |
|
1400 |
throw; |
|
1401 |
} |
|
1402 |
#else |
|
1403 |
(ep->exceptionDestructor)(eop); |
|
1404 |
#endif |
|
1405 |
} |
|
1406 |
// Dtor (if there was one) didn't throw. Free the memory. |
|
1407 |
__cxa_free_exception(eop); |
|
1408 |
} // !foreign |
|
1409 |
} // !object_being_rethrown |
|
1410 |
} // ep->handlerCount == 0 |
|
1411 |
} |
|
1412 |
||
1413 |
||
1414 |
#endif /* arm_exceptions_endcatch_c */ |
|
1415 |
#ifdef arm_exceptions_bad_typeid_c |
|
1416 |
||
1417 |
#pragma exceptions_unwind |
|
1418 |
||
1419 |
EXPORT_C void __cxa_bad_typeid(void) |
|
1420 |
{ |
|
1421 |
throw std::bad_typeid(); |
|
1422 |
} |
|
1423 |
||
1424 |
||
1425 |
#endif /* arm_exceptions_bad_typeid_c */ |
|
1426 |
#ifdef arm_exceptions_bad_cast_c |
|
1427 |
||
1428 |
#pragma exceptions_unwind |
|
1429 |
||
1430 |
EXPORT_C void __cxa_bad_cast(void) |
|
1431 |
{ |
|
1432 |
throw std::bad_cast(); |
|
1433 |
} |
|
1434 |
||
1435 |
||
1436 |
#endif /* arm_exceptions_bad_cast_c */ |