author | Mike Kinghan <mikek@symbian.org> |
Thu, 25 Nov 2010 14:35:45 +0000 | |
branch | GCC_SURGE |
changeset 305 | 1ba12ef4ef89 |
parent 235 | cbd07013118c |
permissions | -rw-r--r-- |
0 | 1 |
/* unwind_env.h |
2 |
* |
|
3 |
* Copyright 2003-2005 ARM Limited. All rights reserved. |
|
4 |
*/ |
|
5 |
/* |
|
6 |
Licence |
|
7 |
||
8 |
1. Subject to the provisions of clause 2, ARM hereby grants to LICENSEE a |
|
9 |
perpetual, non-exclusive, nontransferable, royalty free, worldwide licence |
|
10 |
to use this Example Implementation of Exception Handling solely for the |
|
11 |
purpose of developing, having developed, manufacturing, having |
|
12 |
manufactured, offering to sell, selling, supplying or otherwise |
|
13 |
distributing products which comply with the Exception Handling ABI for the |
|
14 |
ARM Architecture specification. All other rights are reserved to ARM or its |
|
15 |
licensors. |
|
16 |
||
17 |
2. THIS EXAMPLE IMPLEMENTATION OF EXCEPTION HANDLING IS PROVIDED "AS IS" |
|
18 |
WITH NO WARRANTIES EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT LIMITED |
|
19 |
TO ANY WARRANTY OF SATISFACTORY QUALITY, MERCHANTABILITY, NONINFRINGEMENT |
|
20 |
OR FITNESS FOR A PARTICULAR PURPOSE. |
|
21 |
*/ |
|
22 |
||
23 |
/* Portions copyright Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). */ |
|
24 |
||
25 |
/* |
|
26 |
* RCS $Revision: 92949 $ |
|
27 |
* Checkin $Date: 2005-10-12 11:07:03 +0100 (Wed, 12 Oct 2005) $ |
|
28 |
* Revising $Author: achapman $ |
|
29 |
*/ |
|
30 |
||
31 |
/* Environment definition - abstractions and requirements - to aid |
|
32 |
* portability of the ARM exceptions code. |
|
33 |
*/ |
|
34 |
||
35 |
#ifndef UNWINDENV_H |
|
36 |
#define UNWINDENV_H |
|
37 |
||
38 |
/* ---------------------------------------------------------------------- */ |
|
39 |
||
40 |
/* Source language |
|
41 |
* |
|
42 |
* The compiler is expected to define preprocessor symbols as follows: |
|
43 |
* __cplusplus when compiling in C++ mode. |
|
44 |
* __thumb when compiling to Thumb code. |
|
45 |
* |
|
46 |
* Some use is made of embedded assembly language, introduced by __asm. |
|
47 |
* This is described in ARM's toolchain documentation. Some edits may be |
|
48 |
* required for other compilers. The compiler should define one or more of: |
|
49 |
* __TARGET_ARCH_4T __TARGET_ARCH_4TXM __TARGET_ARCH_5T __TARGET_ARCH_5TXM |
|
50 |
* __TARGET_ARCH_5TE __TARGET_ARCH_6 |
|
51 |
* so the correct assembly wrappers are generated for certain functions. |
|
52 |
* |
|
53 |
* __APCS_INTERWORK should be defined if ARM/Thumb interworking is required. |
|
54 |
* |
|
55 |
* For all the above symbols, if your compiler does not provide appropriate |
|
56 |
* definitions, add them here. |
|
57 |
* |
|
58 |
* Some source language extensions are also used. |
|
59 |
*/ |
|
60 |
||
61 |
/* ---------------------------------------------------------------------- */ |
|
62 |
||
63 |
/* Library structure |
|
64 |
* |
|
65 |
* ARM's private make system contains an automated facility for compiling |
|
66 |
* source files multiple times to create multiple object files. The source |
|
67 |
* regions intended to constitute object file xxx.o are delimited by |
|
68 |
* #ifdef xxx_c / #endif directives. The exact preprocessor symbols used |
|
69 |
* for this conditionalisation are described in a comment at the start of |
|
70 |
* each file. When porting to a different system, compilations must be |
|
71 |
* performed with these preprocessor symbols appropriately defined |
|
72 |
* (or remove the conditionalisation). |
|
73 |
* |
|
74 |
*/ |
|
75 |
#ifdef __EPOC32__ |
|
76 |
||
77 |
#define ARM_EXCEPTIONS_ENABLED |
|
78 |
||
79 |
// turn on the source regions in unwinder.c |
|
80 |
#define unwinder_c |
|
81 |
#define unwind_activity_c |
|
82 |
||
83 |
// turn on the source regions in unwind_pr.c |
|
84 |
#define pr0_c |
|
85 |
#define pr1_c |
|
86 |
#define pr2_c |
|
87 |
#define prcommon_c |
|
88 |
||
89 |
// turn on the source regions in cppsemantics.cpp |
|
90 |
#define arm_exceptions_globs_c |
|
91 |
#define arm_exceptions_mem_c |
|
92 |
#define arm_exceptions_uncaught_c |
|
93 |
#define arm_exceptions_terminate_c |
|
94 |
#define arm_exceptions_setterminate_c |
|
95 |
#define arm_exceptions_unexpected_c |
|
96 |
#define arm_exceptions_setunexpected_c |
|
97 |
#define arm_exceptions_support_c |
|
98 |
#define arm_exceptions_callterm_c |
|
99 |
#define arm_exceptions_callunex_c |
|
100 |
#define arm_exceptions_currenttype_c |
|
101 |
#define arm_exceptions_alloc_c |
|
102 |
#define arm_exceptions_free_c |
|
103 |
#define arm_exceptions_throw_c |
|
104 |
#define arm_exceptions_rethrow_c |
|
105 |
#define arm_exceptions_foreign_c |
|
106 |
#define arm_exceptions_cleanup_c |
|
107 |
#define arm_exceptions_getexceptionptr_c |
|
108 |
#define arm_exceptions_catchsemantics_c |
|
109 |
#define arm_exceptions_begincatch_c |
|
110 |
#define arm_exceptions_endcatch_c |
|
111 |
#define arm_exceptions_bad_typeid_c |
|
112 |
#define arm_exceptions_bad_cast_c |
|
113 |
#endif |
|
114 |
||
115 |
/* ARM declares (or redeclares) some routines as weak in order that |
|
116 |
* references to them are weak, so that the static linker will not load |
|
117 |
* unwanted code. This is achieved by decorating routine declarations |
|
118 |
* with appropriate language extensions. Note that compilers supporting |
|
119 |
* similar features but via a different syntax may require edits to |
|
120 |
* the library source. |
|
121 |
* |
|
122 |
* Define those decorations here (define as empty if not required): |
|
123 |
*/ |
|
124 |
||
125 |
#ifndef __EPOC32__ |
|
126 |
#define WEAKDECL __weak /* token in C and C++ */ |
|
127 |
#define WEAKASMDECL [WEAK] /* token in assembler */ |
|
128 |
#else |
|
129 |
// The symbian version needs all of these in the DLL, so don't make them weak |
|
130 |
#define WEAKDECL |
|
131 |
#define WEAKASMDECL |
|
132 |
#endif |
|
133 |
||
134 |
/* ---------------------------------------------------------------------- */ |
|
135 |
||
136 |
/* Source language support and language extensions */ |
|
137 |
||
138 |
/* It is possible to compile the C++ semantics code using a compiler |
|
139 |
* which does not support C++ exceptions; this was useful to ARM whilst |
|
140 |
* ARM's compiler was being developed, and the facility has not been |
|
141 |
* removed. C++ exceptions syntax is conditionalised by |
|
142 |
* #ifdef ARM_EXCEPTIONS_ENABLED / #endif. Define ARM_EXCEPTIONS_ENABLED |
|
143 |
* by some means here if you want a usable library: |
|
144 |
*/ |
|
145 |
||
146 |
#ifdef __cplusplus |
|
147 |
extern "C" { |
|
148 |
/* For conditionalisation, specifically on ARM_EXCEPTIONS_ENABLED */ |
|
149 |
#include "basics.h" |
|
150 |
} |
|
151 |
#endif |
|
152 |
||
153 |
/* The following definitions of syntax decoration may be empty if the |
|
154 |
* facility is not required. Note that compilers supporting similar |
|
155 |
* features but via a different syntax may require edits to the library |
|
156 |
* source. |
|
157 |
* |
|
158 |
* Define the decorations here (define as empty if not required): |
|
159 |
*/ |
|
160 |
||
161 |
/* If the compiler understands noreturn functions: */ |
|
162 |
#define NORETURNDECL __declspec(noreturn) |
|
163 |
/* Inlining when compiling C */ |
|
164 |
#define INLINE __inline |
|
235
cbd07013118c
1) Fix for bug 3392 - [GCCE] GCC definition for FORCEINLINE required for e32test build.
Mike Kinghan <mikek@symbian.org>
parents:
0
diff
changeset
|
165 |
#if defined(__ARMCC__) |
0 | 166 |
/* Stronger encouragement to inline */ |
167 |
#define FORCEINLINE __forceinline |
|
235
cbd07013118c
1) Fix for bug 3392 - [GCCE] GCC definition for FORCEINLINE required for e32test build.
Mike Kinghan <mikek@symbian.org>
parents:
0
diff
changeset
|
168 |
#elif defined(__GCCE__) |
cbd07013118c
1) Fix for bug 3392 - [GCCE] GCC definition for FORCEINLINE required for e32test build.
Mike Kinghan <mikek@symbian.org>
parents:
0
diff
changeset
|
169 |
#define FORCEINLINE __inline __attribute__ ((always_inline)) |
cbd07013118c
1) Fix for bug 3392 - [GCCE] GCC definition for FORCEINLINE required for e32test build.
Mike Kinghan <mikek@symbian.org>
parents:
0
diff
changeset
|
170 |
#else |
cbd07013118c
1) Fix for bug 3392 - [GCCE] GCC definition for FORCEINLINE required for e32test build.
Mike Kinghan <mikek@symbian.org>
parents:
0
diff
changeset
|
171 |
#error What compiler? |
cbd07013118c
1) Fix for bug 3392 - [GCCE] GCC definition for FORCEINLINE required for e32test build.
Mike Kinghan <mikek@symbian.org>
parents:
0
diff
changeset
|
172 |
#endif |
cbd07013118c
1) Fix for bug 3392 - [GCCE] GCC definition for FORCEINLINE required for e32test build.
Mike Kinghan <mikek@symbian.org>
parents:
0
diff
changeset
|
173 |
|
0 | 174 |
|
175 |
/* ---------------------------------------------------------------------- */ |
|
176 |
||
177 |
/* Types */ |
|
178 |
||
179 |
/* The implementation requires types uint8_t, uint16_t, uint32_t and |
|
180 |
* uint64_t to be defined as unsigned integers of the appropriate number |
|
181 |
* of bits. |
|
182 |
* |
|
183 |
* Do that here: |
|
184 |
*/ |
|
185 |
||
186 |
#ifndef __EPOC32__ |
|
187 |
#include <stdint.h> |
|
188 |
#else |
|
189 |
#include <e32def.h> |
|
190 |
typedef TUint8 uint8_t; |
|
191 |
typedef TUint16 uint16_t; |
|
192 |
typedef TInt32 int32_t; |
|
193 |
typedef TUint32 uint32_t; |
|
194 |
typedef Uint64 uint64_t; |
|
195 |
#endif |
|
196 |
||
197 |
/* The C++ semantics support requires definition of the RTTI object |
|
198 |
* layout. We use the same structures and names as the generic C++ |
|
199 |
* ABI for Itanium. |
|
200 |
* |
|
201 |
* Define those structures here: |
|
202 |
*/ |
|
203 |
||
204 |
#ifdef __cplusplus |
|
205 |
extern "C" { |
|
206 |
#include "cxxabi.h" |
|
207 |
} |
|
208 |
#endif |
|
209 |
||
210 |
/* ---------------------------------------------------------------------- */ |
|
211 |
||
212 |
/* External requirements */ |
|
213 |
||
214 |
/* The C++ exception-handling 'globals' should be allocated per-thread. |
|
215 |
* The Exceptions ABI does not specify how this happens, but it is |
|
216 |
* intended that the details are localised to __cxa_get_globals. |
|
217 |
* |
|
218 |
* In the ARM implementation of __cxa_get_globals, it is assumed that a |
|
219 |
* zero-initialised location in a known per-thread place is somehow |
|
220 |
* obtainable, and can be assigned (by __cxa_get_globals) a pointer to |
|
221 |
* the allocated globals data structure. The macro EH_GLOBALS should be |
|
222 |
* defined here to yield a suitable address of type void*. This is used |
|
223 |
* only in __cxa_get_globals. |
|
224 |
* |
|
225 |
* Define it here: |
|
226 |
*/ |
|
227 |
||
228 |
#ifdef __cplusplus |
|
229 |
#ifndef __EPOC32__ |
|
230 |
extern "C" { |
|
231 |
/* for __user_libspace() machinery */ |
|
232 |
#include <interns.h> |
|
233 |
#define EH_GLOBALS libspace.eh_globals |
|
234 |
} |
|
235 |
#else |
|
236 |
#include <e32std.h> |
|
237 |
#define EH_GLOBALS (Dll::Tls()) |
|
238 |
#endif |
|
239 |
#endif |
|
240 |
||
241 |
/* A routine is required for C++ derived class to base class conversion. |
|
242 |
* This is used once, in __cxa_type_match. It is likely that suitable |
|
243 |
* code exists as part of the RTTI support code. Therefore access it |
|
244 |
* via a macro: |
|
245 |
* DERIVED_TO_BASE_CONVERSION(PTR, P_NEW_PTR, CLASS_INFO, BASE_INFO) |
|
246 |
* Convert PTR from a pointer to a derived class (described by |
|
247 |
* CLASS_INFO) to a pointer to a base class (described by BASE_INFO) |
|
248 |
* and store the resulting pointer in P_NEW_PTR. Return true (or |
|
249 |
* non-zero) if the base class was found and the conversion was done, |
|
250 |
* otherwise return false (or zero). |
|
251 |
* |
|
252 |
* Define the macro here: |
|
253 |
*/ |
|
254 |
||
255 |
#ifdef __cplusplus |
|
256 |
/* In the ARM implementation, a suitable routine exists elsewhere in the |
|
257 |
* C++ runtime library, where it is part of the dynamic_cast mechanism. |
|
258 |
*/ |
|
259 |
#if !defined(__EPOC32__) || (__ARMCC_VERSION > 310000) |
|
260 |
extern "C" int __derived_to_base_conversion(void** p_ptr, void** p_new_ptr, |
|
261 |
const std::type_info * class_info, |
|
262 |
const std::type_info * base_info, |
|
263 |
char** access_flags, int use_access_flags); |
|
264 |
||
265 |
#define DERIVED_TO_BASE_CONVERSION(PTR, P_NEW_PTR, CLASS_INFO, BASE_INFO) \ |
|
266 |
__derived_to_base_conversion(&(PTR), (P_NEW_PTR), (CLASS_INFO), (BASE_INFO), NULL, 0) |
|
267 |
#else |
|
268 |
extern "C" TBool _DoDerivedToBaseConversion(const std::type_info* aDerivedType, |
|
269 |
const std::type_info* aBaseType, |
|
270 |
TAny** aDerivedObj, |
|
271 |
TAny** aBaseObj); |
|
272 |
||
273 |
#define DERIVED_TO_BASE_CONVERSION(PTR, P_NEW_PTR, CLASS_INFO, BASE_INFO) \ |
|
274 |
_DoDerivedToBaseConversion(CLASS_INFO, BASE_INFO, &(PTR), P_NEW_PTR) |
|
275 |
#endif |
|
276 |
||
277 |
#endif |
|
278 |
||
279 |
/* The effect of R_ARM_TARGET2 relocations is platform-specific. A |
|
280 |
* routine is required for handling references created via such |
|
281 |
* relocations. The routine takes the address of a location that was |
|
282 |
* relocated by R_ARM_TARGET2, and returns a pointer to the absolute |
|
283 |
* address of the referenced entity. |
|
284 |
*/ |
|
285 |
||
286 |
static FORCEINLINE void *__ARM_resolve_target2(void *p) |
|
287 |
{ |
|
288 |
#ifdef __APCS_FPIC |
|
289 |
/* SVr4: R_ARM_TARGET2 is equivalent to R_ARM_GOT_PREL (placerel32 indirect) */ |
|
290 |
return *(void **)(*(uint32_t *)p + (uint32_t)p); |
|
291 |
#else |
|
292 |
/* Bare metal: R_ARM_TARGET2 is equivalent to R_ARM_ABS32 */ |
|
293 |
return *(void **)p; |
|
294 |
#endif |
|
295 |
} |
|
296 |
||
297 |
/* ---------------------------------------------------------------------- */ |
|
298 |
||
299 |
/* Runtime debug support |
|
300 |
* |
|
301 |
* Here we define the interface to a "bottleneck function" to be called |
|
302 |
* by exception handling code at 'interesting' points during execution, |
|
303 |
* and breakpointable by a debugger. |
|
304 |
* |
|
305 |
* This is not part of the Exceptions ABI but is expected to be |
|
306 |
* standardised elsewhere, probably in a Debug ABI. |
|
307 |
* |
|
308 |
* If you don't want this, define DEBUGGER_BOTTLENECK as a dummy, e.g. |
|
309 |
* #define DEBUGGER_BOTTLENECK(UCBP,LANG,ACTIVITY,ARG) (void)0 |
|
310 |
*/ |
|
311 |
||
312 |
#ifdef __cplusplus |
|
313 |
extern "C" { |
|
314 |
#endif |
|
315 |
||
316 |
struct _Unwind_Control_Block; |
|
317 |
||
318 |
typedef enum { |
|
319 |
_UASUBSYS_CPP = 0x00, |
|
320 |
_UASUBSYS_UNWINDER = 0xff |
|
321 |
} _Unwind_Activity_subsystem; |
|
322 |
||
323 |
typedef enum { |
|
324 |
_UAACT_STARTING = 0x0, |
|
325 |
_UAACT_ENDING = 0x1, |
|
326 |
_UAACT_BARRIERFOUND = 0x2, |
|
327 |
_UAACT_PADENTRY = 0x3, |
|
328 |
_UAACT_CPP_TYPEINFO = 0x80 |
|
329 |
} _Unwind_Activity_activity; |
|
330 |
||
331 |
typedef enum { |
|
332 |
_UAARG_ENDING_UNSPECIFIED = 0x0, |
|
333 |
_UAARG_ENDING_TABLECORRUPT = 0x1, |
|
334 |
_UAARG_ENDING_NOUNWIND = 0x2, |
|
335 |
_UAARG_ENDING_VRSFAILED = 0x3, |
|
336 |
/* C++ only: */ |
|
337 |
_UAARG_ENDING_CPP_BADOPCODE = 0x4, |
|
338 |
/* Unwinder only: */ |
|
339 |
_UAARG_ENDING_UNWINDER_LOOKUPFAILED = 0x4, |
|
340 |
_UAARG_ENDING_UNWINDER_BUFFERFAILED = 0x5 |
|
341 |
} _Unwind_Activity_arg; |
|
342 |
||
343 |
void _Unwind_Activity(struct _Unwind_Control_Block *ucbp, uint32_t reason, uint32_t arg); |
|
344 |
#define DEBUGGER_BOTTLENECK(UCBP,LANG,ACTIVITY,ARG) \ |
|
345 |
_Unwind_Activity((UCBP),((((uint32_t)(LANG))<<24)|ACTIVITY),(uint32_t)(ARG)) |
|
346 |
||
347 |
#ifdef __cplusplus |
|
348 |
} |
|
349 |
#endif |
|
350 |
||
351 |
||
352 |
/* ---------------------------------------------------------------------- */ |
|
353 |
||
354 |
/* Printed diagnostics |
|
355 |
* |
|
356 |
* These may be useful for debugging purposes during development, provided |
|
357 |
* the execution environment supports diagnostics via printf. |
|
358 |
* |
|
359 |
* #define PR_DIAGNOSTICS for printed diagnostics from the personality routine. |
|
360 |
* #define VRS_DIAGNOSTICS for printed diagnostics about VRS operations. |
|
361 |
* #define UNWIND_ACTIVITY_DIAGNOSTICS for printed information from _Unwind_Activity. |
|
362 |
* #define CPP_DIAGNOSTICS for printed diagnostics from the C++ semantics routines. |
|
363 |
*/ |
|
364 |
||
365 |
/* ---------------------------------------------------------------------- |
|
366 |
* Abstractions added for SymbianOS. A process is contructed from multiple |
|
367 |
* executables each with their own RO segment and exception data structures. |
|
368 |
* SymbianOS caches pointers to two data structures in the UCB which it then |
|
369 |
* uses to speed up the retrieval of certain information including values returned |
|
370 |
* by the functions below. |
|
371 |
* ---------------------------------------------------------------------- */ |
|
372 |
#ifndef __EPOC32__ |
|
373 |
#define ADDR_TO_ER_RO_OFFSET(addr, ucbp) addr_to_ER_RO_offset(addr) |
|
374 |
#define ER_RO_OFFSET_TO_ADDR(addr, ucbp) ER_RO_offset_to_addr(addr) |
|
375 |
#else |
|
376 |
#define ADDR_TO_ER_RO_OFFSET(addr, ucbp) addr_to_ER_RO_offset(addr, ucbp) |
|
377 |
#define ER_RO_OFFSET_TO_ADDR(addr, ucbp) ER_RO_offset_to_addr(addr, ucbp) |
|
378 |
#endif |
|
379 |
||
380 |
||
381 |
#endif /* defined UNWINDENV_H */ |
|
382 |
||
383 |
||
384 |
||
385 |
||
386 |
||
387 |
||
388 |
||
389 |