Home | History | Annotate | Download | only in src
      1 //===------------------------- cxa_exception.hpp --------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is dual licensed under the MIT and the University of Illinois Open
      6 // Source Licenses. See LICENSE.TXT for details.
      7 //
      8 //
      9 //  This file implements the "Exception Handling APIs"
     10 //  http://mentorembedded.github.io/cxx-abi/abi-eh.html
     11 //
     12 //===----------------------------------------------------------------------===//
     13 
     14 #ifndef _CXA_EXCEPTION_H
     15 #define _CXA_EXCEPTION_H
     16 
     17 #include <exception> // for std::unexpected_handler and std::terminate_handler
     18 #include "cxxabi.h"
     19 #include "unwind.h"
     20 
     21 namespace __cxxabiv1 {
     22 
     23 static const uint64_t kOurExceptionClass          = 0x434C4E47432B2B00; // CLNGC++\0
     24 static const uint64_t kOurDependentExceptionClass = 0x434C4E47432B2B01; // CLNGC++\1
     25 static const uint64_t get_vendor_and_language     = 0xFFFFFFFFFFFFFF00; // mask for CLNGC++
     26 
     27 uint64_t __getExceptionClass  (const _Unwind_Exception*);
     28 void     __setExceptionClass  (      _Unwind_Exception*, uint64_t);
     29 bool     __isOurExceptionClass(const _Unwind_Exception*);
     30 
     31 struct _LIBCXXABI_HIDDEN __cxa_exception {
     32 #if defined(__LP64__) || defined(_LIBCXXABI_ARM_EHABI)
     33     // This is a new field to support C++ 0x exception_ptr.
     34     // For binary compatibility it is at the start of this
     35     // struct which is prepended to the object thrown in
     36     // __cxa_allocate_exception.
     37     size_t referenceCount;
     38 #endif
     39 
     40     //  Manage the exception object itself.
     41     std::type_info *exceptionType;
     42     void (*exceptionDestructor)(void *);
     43     std::unexpected_handler unexpectedHandler;
     44     std::terminate_handler  terminateHandler;
     45 
     46     __cxa_exception *nextException;
     47 
     48     int handlerCount;
     49 
     50 #if defined(_LIBCXXABI_ARM_EHABI)
     51     __cxa_exception* nextPropagatingException;
     52     int propagationCount;
     53 #else
     54     int handlerSwitchValue;
     55     const unsigned char *actionRecord;
     56     const unsigned char *languageSpecificData;
     57     void *catchTemp;
     58     void *adjustedPtr;
     59 #endif
     60 
     61 #if !defined(__LP64__) && !defined(_LIBCXXABI_ARM_EHABI)
     62     // This is a new field to support C++ 0x exception_ptr.
     63     // For binary compatibility it is placed where the compiler
     64     // previously adding padded to 64-bit align unwindHeader.
     65     size_t referenceCount;
     66 #endif
     67     _Unwind_Exception unwindHeader;
     68 };
     69 
     70 // http://sourcery.mentor.com/archives/cxx-abi-dev/msg01924.html
     71 // The layout of this structure MUST match the layout of __cxa_exception, with
     72 // primaryException instead of referenceCount.
     73 struct _LIBCXXABI_HIDDEN __cxa_dependent_exception {
     74 #if defined(__LP64__) || defined(_LIBCXXABI_ARM_EHABI)
     75     void* primaryException;
     76 #endif
     77 
     78     std::type_info *exceptionType;
     79     void (*exceptionDestructor)(void *);
     80     std::unexpected_handler unexpectedHandler;
     81     std::terminate_handler terminateHandler;
     82 
     83     __cxa_exception *nextException;
     84 
     85     int handlerCount;
     86 
     87 #if defined(_LIBCXXABI_ARM_EHABI)
     88     __cxa_exception* nextPropagatingException;
     89     int propagationCount;
     90 #else
     91     int handlerSwitchValue;
     92     const unsigned char *actionRecord;
     93     const unsigned char *languageSpecificData;
     94     void * catchTemp;
     95     void *adjustedPtr;
     96 #endif
     97 
     98 #if !defined(__LP64__) && !defined(_LIBCXXABI_ARM_EHABI)
     99     void* primaryException;
    100 #endif
    101     _Unwind_Exception unwindHeader;
    102 };
    103 
    104 struct _LIBCXXABI_HIDDEN __cxa_eh_globals {
    105     __cxa_exception *   caughtExceptions;
    106     unsigned int        uncaughtExceptions;
    107 #if defined(_LIBCXXABI_ARM_EHABI)
    108     __cxa_exception* propagatingExceptions;
    109 #endif
    110 };
    111 
    112 extern "C" _LIBCXXABI_FUNC_VIS __cxa_eh_globals * __cxa_get_globals      ();
    113 extern "C" _LIBCXXABI_FUNC_VIS __cxa_eh_globals * __cxa_get_globals_fast ();
    114 
    115 extern "C" _LIBCXXABI_FUNC_VIS void * __cxa_allocate_dependent_exception ();
    116 extern "C" _LIBCXXABI_FUNC_VIS void __cxa_free_dependent_exception (void * dependent_exception);
    117 
    118 }  // namespace __cxxabiv1
    119 
    120 #endif  // _CXA_EXCEPTION_H
    121