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 struct _LIBCXXABI_HIDDEN __cxa_exception {
     28 #if defined(__LP64__) || defined(_LIBCXXABI_ARM_EHABI)
     29     // This is a new field to support C++ 0x exception_ptr.
     30     // For binary compatibility it is at the start of this
     31     // struct which is prepended to the object thrown in
     32     // __cxa_allocate_exception.
     33     size_t referenceCount;
     34 #endif
     35 
     36     //  Manage the exception object itself.
     37     std::type_info *exceptionType;
     38     void (*exceptionDestructor)(void *);
     39     std::unexpected_handler unexpectedHandler;
     40     std::terminate_handler  terminateHandler;
     41 
     42     __cxa_exception *nextException;
     43 
     44     int handlerCount;
     45 
     46 #if defined(_LIBCXXABI_ARM_EHABI)
     47     __cxa_exception* nextPropagatingException;
     48     int propagationCount;
     49 #else
     50     int handlerSwitchValue;
     51     const unsigned char *actionRecord;
     52     const unsigned char *languageSpecificData;
     53     void *catchTemp;
     54     void *adjustedPtr;
     55 #endif
     56 
     57 #if !defined(__LP64__) && !defined(_LIBCXXABI_ARM_EHABI)
     58     // This is a new field to support C++ 0x exception_ptr.
     59     // For binary compatibility it is placed where the compiler
     60     // previously adding padded to 64-bit align unwindHeader.
     61     size_t referenceCount;
     62 #endif
     63     _Unwind_Exception unwindHeader;
     64 };
     65 
     66 // http://sourcery.mentor.com/archives/cxx-abi-dev/msg01924.html
     67 // The layout of this structure MUST match the layout of __cxa_exception, with
     68 // primaryException instead of referenceCount.
     69 struct _LIBCXXABI_HIDDEN __cxa_dependent_exception {
     70 #if defined(__LP64__) || defined(_LIBCXXABI_ARM_EHABI)
     71     void* primaryException;
     72 #endif
     73 
     74     std::type_info *exceptionType;
     75     void (*exceptionDestructor)(void *);
     76     std::unexpected_handler unexpectedHandler;
     77     std::terminate_handler terminateHandler;
     78 
     79     __cxa_exception *nextException;
     80 
     81     int handlerCount;
     82 
     83 #if defined(_LIBCXXABI_ARM_EHABI)
     84     __cxa_exception* nextPropagatingException;
     85     int propagationCount;
     86 #else
     87     int handlerSwitchValue;
     88     const unsigned char *actionRecord;
     89     const unsigned char *languageSpecificData;
     90     void * catchTemp;
     91     void *adjustedPtr;
     92 #endif
     93 
     94 #if !defined(__LP64__) && !defined(_LIBCXXABI_ARM_EHABI)
     95     void* primaryException;
     96 #endif
     97     _Unwind_Exception unwindHeader;
     98 };
     99 
    100 struct _LIBCXXABI_HIDDEN __cxa_eh_globals {
    101     __cxa_exception *   caughtExceptions;
    102     unsigned int        uncaughtExceptions;
    103 #if defined(_LIBCXXABI_ARM_EHABI)
    104     __cxa_exception* propagatingExceptions;
    105 #endif
    106 };
    107 
    108 extern "C" _LIBCXXABI_FUNC_VIS __cxa_eh_globals * __cxa_get_globals      ();
    109 extern "C" _LIBCXXABI_FUNC_VIS __cxa_eh_globals * __cxa_get_globals_fast ();
    110 
    111 extern "C" _LIBCXXABI_FUNC_VIS void * __cxa_allocate_dependent_exception ();
    112 extern "C" _LIBCXXABI_FUNC_VIS void __cxa_free_dependent_exception (void * dependent_exception);
    113 
    114 }  // namespace __cxxabiv1
    115 
    116 #endif  // _CXA_EXCEPTION_H
    117