Howard Hinnant | b9f2cc8 | 2011-12-06 18:01:47 +0000 | [diff] [blame] | 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://www.codesourcery.com/public/cxx-abi/abi-eh.html |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Howard Hinnant | 0f80bb7 | 2012-03-19 16:20:34 +0000 | [diff] [blame] | 14 | #ifndef _CXA_EXCEPTION_H |
| 15 | #define _CXA_EXCEPTION_H |
| 16 | |
Marshall Clow | 61b898e | 2011-07-20 14:53:53 +0000 | [diff] [blame] | 17 | #include <exception> // for std::unexpected_handler and std::terminate_handler |
| 18 | #include <cxxabi.h> |
| 19 | #include "unwind.h" |
| 20 | |
| 21 | namespace __cxxabiv1 { |
| 22 | |
Howard Hinnant | 0240685 | 2012-02-02 20:47:28 +0000 | [diff] [blame] | 23 | #pragma GCC visibility push(hidden) |
| 24 | |
Howard Hinnant | 2a70c10 | 2012-01-24 18:15:20 +0000 | [diff] [blame] | 25 | static const uint64_t kOurExceptionClass = 0x434C4E47432B2B00; // CLNGC++\0 |
| 26 | static const uint64_t kOurDependentExceptionClass = 0x434C4E47432B2B01; // CLNGC++\1 |
Howard Hinnant | 7ab185e | 2012-02-01 18:15:15 +0000 | [diff] [blame] | 27 | static const uint64_t get_vendor_and_language = 0xFFFFFFFFFFFFFF00; // mask for CLNGC++ |
Howard Hinnant | 2a70c10 | 2012-01-24 18:15:20 +0000 | [diff] [blame] | 28 | |
Marshall Clow | 61b898e | 2011-07-20 14:53:53 +0000 | [diff] [blame] | 29 | struct __cxa_exception { |
| 30 | #if __LP64__ |
| 31 | // This is a new field to support C++ 0x exception_ptr. |
| 32 | // For binary compatibility it is at the start of this |
| 33 | // struct which is prepended to the object thrown in |
| 34 | // __cxa_allocate_exception. |
| 35 | size_t referenceCount; |
| 36 | #endif |
| 37 | |
| 38 | // Manage the exception object itself. |
| 39 | std::type_info *exceptionType; |
| 40 | void (*exceptionDestructor)(void *); |
| 41 | std::unexpected_handler unexpectedHandler; |
| 42 | std::terminate_handler terminateHandler; |
| 43 | |
| 44 | __cxa_exception *nextException; |
| 45 | |
| 46 | int handlerCount; |
| 47 | |
| 48 | #ifdef __ARM_EABI_UNWINDER__ |
| 49 | __cxa_exception* nextPropagatingException; |
| 50 | int propagationCount; |
| 51 | #else |
| 52 | int handlerSwitchValue; |
| 53 | const unsigned char *actionRecord; |
| 54 | const unsigned char *languageSpecificData; |
| 55 | void *catchTemp; |
| 56 | void *adjustedPtr; |
| 57 | #endif |
| 58 | |
| 59 | #if !__LP64__ |
| 60 | // This is a new field to support C++ 0x exception_ptr. |
| 61 | // For binary compatibility it is placed where the compiler |
| 62 | // previously adding padded to 64-bit align unwindHeader. |
| 63 | size_t referenceCount; |
| 64 | #endif |
| 65 | |
| 66 | _Unwind_Exception unwindHeader; |
| 67 | }; |
Howard Hinnant | 6eb54ad | 2011-12-08 19:35:18 +0000 | [diff] [blame] | 68 | |
| 69 | // http://sourcery.mentor.com/archives/cxx-abi-dev/msg01924.html |
Marshall Clow | 61b898e | 2011-07-20 14:53:53 +0000 | [diff] [blame] | 70 | |
| 71 | struct __cxa_dependent_exception { |
| 72 | #if __LP64__ |
| 73 | void* primaryException; |
| 74 | #endif |
| 75 | |
Marshall Clow | 61b898e | 2011-07-20 14:53:53 +0000 | [diff] [blame] | 76 | std::type_info *exceptionType; |
| 77 | void (*exceptionDestructor)(void *); |
Marshall Clow | 61b898e | 2011-07-20 14:53:53 +0000 | [diff] [blame] | 78 | std::unexpected_handler unexpectedHandler; |
| 79 | std::terminate_handler terminateHandler; |
| 80 | |
| 81 | __cxa_exception *nextException; |
| 82 | |
| 83 | int handlerCount; |
| 84 | |
| 85 | #ifdef __ARM_EABI_UNWINDER__ |
| 86 | __cxa_exception* nextPropagatingException; |
| 87 | int propagationCount; |
| 88 | #else |
| 89 | int handlerSwitchValue; |
| 90 | const unsigned char *actionRecord; |
| 91 | const unsigned char *languageSpecificData; |
| 92 | void * catchTemp; |
| 93 | void *adjustedPtr; |
| 94 | #endif |
| 95 | |
| 96 | #if !__LP64__ |
| 97 | void* primaryException; |
| 98 | #endif |
| 99 | |
| 100 | _Unwind_Exception unwindHeader; |
| 101 | }; |
| 102 | |
| 103 | struct __cxa_eh_globals { |
| 104 | __cxa_exception * caughtExceptions; |
| 105 | unsigned int uncaughtExceptions; |
| 106 | #ifdef __ARM_EABI_UNWINDER__ |
| 107 | __cxa_exception* propagatingExceptions; |
| 108 | #endif |
| 109 | }; |
| 110 | |
Howard Hinnant | 0240685 | 2012-02-02 20:47:28 +0000 | [diff] [blame] | 111 | #pragma GCC visibility pop |
| 112 | #pragma GCC visibility push(default) |
| 113 | |
Howard Hinnant | 7da9b96 | 2012-01-30 16:07:00 +0000 | [diff] [blame] | 114 | extern "C" __cxa_eh_globals * __cxa_get_globals (); |
| 115 | extern "C" __cxa_eh_globals * __cxa_get_globals_fast (); |
Marshall Clow | 61b898e | 2011-07-20 14:53:53 +0000 | [diff] [blame] | 116 | |
Howard Hinnant | 7da9b96 | 2012-01-30 16:07:00 +0000 | [diff] [blame] | 117 | extern "C" void * __cxa_allocate_dependent_exception (); |
| 118 | extern "C" void __cxa_free_dependent_exception (void * dependent_exception); |
Marshall Clow | 61b898e | 2011-07-20 14:53:53 +0000 | [diff] [blame] | 119 | |
Howard Hinnant | 0240685 | 2012-02-02 20:47:28 +0000 | [diff] [blame] | 120 | #pragma GCC visibility pop |
Dave Zarzycki | 74ecc63 | 2012-02-22 05:25:00 +0000 | [diff] [blame] | 121 | } |
Howard Hinnant | 0f80bb7 | 2012-03-19 16:20:34 +0000 | [diff] [blame] | 122 | |
| 123 | #endif // _CXA_EXCEPTION_H |