author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Mon, 04 Oct 2010 02:35:35 +0300 | |
changeset 281 | 13fbfa31d2ba |
parent 266 | 0008ccd16016 |
permissions | -rw-r--r-- |
266
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1 |
// Copyright (c) 2004-2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 2 |
// All rights reserved. |
3 |
// This component and the accompanying materials are made available |
|
4 |
// under the terms of the License "ARM EABI LICENCE.txt" |
|
5 |
// which accompanies this distribution, and is available |
|
6 |
// in kernel/eka/compsupp. |
|
7 |
// |
|
8 |
// Initial Contributors: |
|
9 |
// Nokia Corporation - initial contribution. |
|
10 |
// |
|
11 |
// Contributors: |
|
12 |
// |
|
13 |
// Description: |
|
14 |
// e32/compsupp/symaehabi/symbian_support.h |
|
15 |
// |
|
16 |
// |
|
17 |
||
18 |
||
19 |
#ifndef SYMBIAN_SUPPORT_H |
|
20 |
#define SYMBIAN_SUPPORT_H |
|
21 |
||
22 |
#include <e32def_private.h> |
|
23 |
||
24 |
#ifdef __cplusplus |
|
25 |
typedef _Unwind_Control_Block UCB; |
|
26 |
||
27 |
using std::terminate_handler; |
|
28 |
using std::unexpected_handler; |
|
29 |
using std::terminate; |
|
30 |
using std::unexpected; |
|
31 |
using std::type_info; |
|
32 |
||
33 |
/* --------- Exception control object: --------- */ |
|
34 |
||
35 |
// Type __cxa_exception is the combined C++ housekeeping (LEO) and UCB. |
|
36 |
// It will be followed by the user exception object, hence must ensure |
|
37 |
// the latter is aligned on an 8 byte boundary. |
|
38 |
||
39 |
struct __cxa_exception { |
|
40 |
const type_info *exceptionType; // RTTI object describing the type of the exception |
|
41 |
void *(*exceptionDestructor)(void *); // Destructor for the exception object (may be NULL) |
|
42 |
unexpected_handler unexpectedHandler; // Handler in force after evaluating throw expr |
|
43 |
terminate_handler terminateHandler; // Handler in force after evaluating throw expr |
|
44 |
__cxa_exception *nextCaughtException; // Chain of "currently caught" c++ exception objects |
|
45 |
uint32_t handlerCount; // Count of how many handlers this EO is "caught" in |
|
46 |
__cxa_exception *nextPropagatingException; // Chain of objects saved over cleanup |
|
47 |
uint32_t propagationCount; // Count of live propagations (throws) of this EO |
|
48 |
UCB ucb; // Forces alignment of next item to 8-byte boundary |
|
49 |
}; |
|
50 |
||
51 |
||
52 |
// Exceptions global support |
|
53 |
typedef void (*handler)(void); |
|
54 |
||
55 |
struct __cxa_eh_globals { |
|
56 |
uint32_t uncaughtExceptions; // counter |
|
57 |
unexpected_handler unexpectedHandler; // per-thread handler |
|
58 |
terminate_handler terminateHandler; // per-thread handler |
|
59 |
bool implementation_ever_called_terminate; // true if it ever did |
|
60 |
handler call_hook; // transient field to tell terminate/unexpected which hook to call |
|
61 |
__cxa_exception *caughtExceptions; // chain of "caught" exceptions |
|
62 |
__cxa_exception *propagatingExceptions; // chain of "propagating" (in cleanup) exceptions |
|
63 |
void *emergency_buffer; // emergency buffer for when rest of heap full |
|
64 |
}; |
|
65 |
||
66 |
// emergency storage reserve primarily for throwing OOM exceptions |
|
67 |
struct emergency_eco { |
|
68 |
__cxa_exception ep; |
|
69 |
XLeaveException aUserLeaveException; |
|
70 |
}; |
|
71 |
||
266
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
72 |
|
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
73 |
|
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
74 |
#include "emergency_buffer.h" |
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
75 |
|
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
76 |
struct emergency_eco2 : emergency_eco { |
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
77 |
// The secondary emergency buffer might as well support slightly bigger objects. |
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
78 |
int spacer[6]; |
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
79 |
}; |
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
80 |
|
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
81 |
typedef TEmergencyBuffer<emergency_eco2, 2> TEmergencyBuffer2; |
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
82 |
|
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
83 |
|
0 | 84 |
struct emergency_buffer { |
85 |
bool inuse; |
|
266
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
86 |
|
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
87 |
TEmergencyBuffer2* em_buf2_p; // offset = 4, size = 4. |
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
88 |
|
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
89 |
// This field has always been forced to an 8-byte alignment, so the fact that |
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
90 |
// em_buf2_p has been added shouldn't break compatibility with existing binaries. |
0 | 91 |
struct emergency_eco eco; |
92 |
}; |
|
93 |
||
94 |
||
95 |
class TCppRTExceptionsGlobals |
|
96 |
{ |
|
97 |
public: |
|
98 |
IMPORT_C TCppRTExceptionsGlobals(); |
|
266
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
99 |
public: |
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
100 |
IMPORT_C void Init2ndEmergencyBuffer(); |
0008ccd16016
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
101 |
IMPORT_C void Kill2ndEmergencyBuffer(); |
0 | 102 |
private: |
103 |
__cxa_eh_globals thread_globals; |
|
104 |
emergency_buffer buffer; |
|
105 |
}; |
|
106 |
||
107 |
#endif |
|
108 |
||
109 |
// Support for finding ROM resident ExIdx tables |
|
110 |
#define GET_ROM_EST(u) ((TRomExceptionSearchTable *)((u)->unwinder_cache.reserved4)) |
|
111 |
#define SET_ROM_EST(u,e) ((TRomExceptionSearchTable *)((u)->unwinder_cache.reserved4=(uint32_t)e)) |
|
112 |
#define GET_EXCEPTION_DESCRIPTOR(u) ((TExceptionDescriptor *)((u)->unwinder_cache.reserved5)) |
|
113 |
#define SET_EXCEPTION_DESCRIPTOR(u,e) ((TExceptionDescriptor *)((u)->unwinder_cache.reserved5=(uint32_t)e)) |
|
114 |
||
115 |
// Support for checking which version of EHABI is in play |
|
116 |
#define EHABI_MASK 0xfffffffc |
|
117 |
// Checks if image implements V2 of EHABI |
|
118 |
#define EHABI_V2(u) ((GET_EXCEPTION_DESCRIPTOR(u)->iROSegmentBase) & 1) |
|
119 |
#define GET_RO_BASE(u) (((u)->iROSegmentBase) & EHABI_MASK) |
|
120 |
#define ADDRESS_IN_EXCEPTION_DESCRIPTOR_RANGE(addr, aEDp) (((addr) >= GET_RO_BASE(aEDp)) && ((addr) < (aEDp)->iROSegmentLimit)) |
|
121 |
#define GET_EST_FENCEPOST(aESTp) ((aESTp)->iEntries[(aESTp)->iNumEntries]) |
|
122 |
#define ADDRESS_IN_ROM_EST(addr, aESTp) (((addr) >= (aESTp)->iEntries[0]) && ((addr) < GET_EST_FENCEPOST((aESTp)))) |
|
123 |
||
124 |
||
125 |
// Non __EPOC32__ versions defined in unwinder.c |
|
126 |
#define EIT_base(u) \ |
|
127 |
((const __EIT_entry *)((GET_EXCEPTION_DESCRIPTOR(u))->iExIdxBase)) |
|
128 |
#define EIT_limit(u) \ |
|
129 |
((const __EIT_entry *)((GET_EXCEPTION_DESCRIPTOR(u))->iExIdxLimit)) |
|
130 |
||
131 |
||
132 |
#ifdef __cplusplus |
|
133 |
extern "C" { |
|
134 |
#endif |
|
135 |
||
136 |
typedef unsigned int size_t; |
|
137 |
IMPORT_C void abort(void); |
|
138 |
int typenameeq(const char * n1, const char * n2); |
|
139 |
||
140 |
#define malloc User::Alloc |
|
141 |
#define free User::Free |
|
142 |
||
143 |
||
144 |
#ifdef _DEBUG |
|
145 |
// uncomment this for diagnostic output in UDEB build |
|
146 |
//#define _DEBUG_SYMBIAN_EH_SUPPORT |
|
147 |
#endif |
|
148 |
||
149 |
#ifdef _DEBUG_SYMBIAN_EH_SUPPORT |
|
150 |
#define VRS_DIAGNOSTICS |
|
151 |
#define UNWIND_ACTIVITY_DIAGNOSTICS |
|
152 |
#define PR_DIAGNOSTICS |
|
153 |
#define PRINTED_DIAGNOSTICS |
|
154 |
#define CPP_DIAGNOSTICS |
|
155 |
#endif |
|
156 |
#define printf DebugPrintf |
|
157 |
extern void DebugPrintf(const char *, ...); |
|
158 |
||
159 |
#ifdef _DEBUG_SYMBIAN_EH_SUPPORT |
|
160 |
#define SYMBIAN_EH_SUPPORT_PRINTF DebugPrintf |
|
161 |
#else |
|
162 |
#define SYMBIAN_EH_SUPPORT_PRINTF (void) |
|
163 |
#pragma diag_suppress 174 |
|
164 |
#endif |
|
165 |
||
166 |
void InitialiseSymbianSpecificUnwinderCache(uint32_t addr, _Unwind_Control_Block * ucbp); |
|
167 |
TExceptionDescriptor * ReLoadExceptionDescriptor(uint32_t addr,_Unwind_Control_Block * ucbp); |
|
168 |
||
169 |
/* Functions used to convert between segment-relative offsets |
|
170 |
* and absolute addresses. These are only used in unwinder.c and must be |
|
171 |
* compilable by a C compiler. |
|
172 |
*/ |
|
173 |
||
174 |
static __inline void ValidateExceptionDescriptor(uint32_t addr, _Unwind_Control_Block * ucbp) |
|
175 |
{ |
|
176 |
// On entry assume ROM exception search table and exception descriptor for current frame cached in ucbp |
|
177 |
||
178 |
// see if addr is in current exception descriptor range |
|
179 |
TExceptionDescriptor * aEDp = GET_EXCEPTION_DESCRIPTOR(ucbp); |
|
180 |
if (!ADDRESS_IN_EXCEPTION_DESCRIPTOR_RANGE(addr, aEDp)) { |
|
181 |
aEDp = ReLoadExceptionDescriptor(addr, ucbp); |
|
182 |
// If there's no valid exception descriptor abort. |
|
183 |
if (!aEDp) { |
|
184 |
#ifdef _DEBUG |
|
185 |
DebugPrintf("EH ERROR: no exception descriptor for address 0x%08x\n", addr); |
|
186 |
DEBUGGER_BOTTLENECK(ucbp, _UASUBSYS_UNWINDER, _UAACT_ENDING, _UAARG_ENDING_UNWINDER_LOOKUPFAILED); |
|
187 |
#endif |
|
188 |
abort(); |
|
189 |
} |
|
190 |
} |
|
191 |
} |
|
192 |
||
193 |
static __inline uint32_t addr_to_ER_RO_offset(uint32_t addr, _Unwind_Control_Block * ucbp) |
|
194 |
{ |
|
195 |
TExceptionDescriptor * aEDp = GET_EXCEPTION_DESCRIPTOR(ucbp); |
|
196 |
// assume ucbp has the correct exception descriptor for this offset |
|
197 |
return addr - GET_RO_BASE(aEDp); |
|
198 |
} |
|
199 |
||
200 |
static __inline uint32_t ER_RO_offset_to_addr(uint32_t offset, _Unwind_Control_Block * ucbp) |
|
201 |
{ |
|
202 |
TExceptionDescriptor * aEDp = GET_EXCEPTION_DESCRIPTOR(ucbp); |
|
203 |
// assume ucbp has the correct exception descriptor for this offset |
|
204 |
return offset + GET_RO_BASE(aEDp); |
|
205 |
} |
|
206 |
||
207 |
// This must be the same as the version in unwinder.c. However its structure is |
|
208 |
// governed by the EHABI and so it shouldn't change anytime soon. |
|
209 |
typedef struct __EIT_entry { |
|
210 |
uint32_t fnoffset; /* Place-relative */ |
|
211 |
uint32_t content; |
|
212 |
} __EIT_entry; |
|
213 |
||
214 |
// The Symbian unwinder uses these specific search functions rather than the generic bsearch |
|
215 |
// to find entries in the exception index table |
|
216 |
const __EIT_entry *SearchEITV1(uint32_t return_address_offset, const __EIT_entry *base, unsigned int nelems); |
|
217 |
__EIT_entry *SearchEITV2(uint32_t return_address, const __EIT_entry *base, unsigned int nelems); |
|
218 |
||
219 |
||
220 |
#ifdef __cplusplus |
|
221 |
} |
|
222 |
#endif |
|
223 |
||
224 |
#endif // SYMBIAN_SUPPORT_H |
|
225 |