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