Howard Hinnant | 987afbe | 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" |
Jonathan Roelofs | c5f7e6f | 2014-02-12 04:49:09 +0000 | [diff] [blame] | 10 | // http://mentorembedded.github.io/cxx-abi/abi-eh.html |
Howard Hinnant | 987afbe | 2011-12-06 18:01:47 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Howard Hinnant | 4ac72dd | 2012-03-19 16:20:34 +0000 | [diff] [blame] | 14 | #ifndef _CXA_EXCEPTION_H |
| 15 | #define _CXA_EXCEPTION_H |
| 16 | |
Marshall Clow | 1df50ca | 2011-07-20 14:53:53 +0000 | [diff] [blame] | 17 | #include <exception> // for std::unexpected_handler and std::terminate_handler |
Mehdi Amini | 5a40358 | 2017-04-04 05:38:38 +0000 | [diff] [blame] | 18 | #include "cxxabi.h" |
Marshall Clow | 1df50ca | 2011-07-20 14:53:53 +0000 | [diff] [blame] | 19 | #include "unwind.h" |
| 20 | |
| 21 | namespace __cxxabiv1 { |
| 22 | |
Howard Hinnant | 6830b2a | 2012-01-24 18:15:20 +0000 | [diff] [blame] | 23 | static const uint64_t kOurExceptionClass = 0x434C4E47432B2B00; // CLNGC++\0 |
| 24 | static const uint64_t kOurDependentExceptionClass = 0x434C4E47432B2B01; // CLNGC++\1 |
Dan Albert | b98c20c | 2015-02-05 23:48:06 +0000 | [diff] [blame] | 25 | static const uint64_t get_vendor_and_language = 0xFFFFFFFFFFFFFF00; // mask for CLNGC++ |
| 26 | |
Shoaib Meenai | fe989a9 | 2017-03-01 03:55:57 +0000 | [diff] [blame] | 27 | struct _LIBCXXABI_HIDDEN __cxa_exception { |
Ranjeet Singh | ef6e672 | 2017-03-01 11:42:01 +0000 | [diff] [blame] | 28 | #if defined(__LP64__) || defined(_LIBCXXABI_ARM_EHABI) |
Marshall Clow | 1df50ca | 2011-07-20 14:53:53 +0000 | [diff] [blame] | 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. |
Logan Chien | aacc1c7 | 2014-04-12 11:56:41 +0000 | [diff] [blame] | 33 | size_t referenceCount; |
Marshall Clow | 1df50ca | 2011-07-20 14:53:53 +0000 | [diff] [blame] | 34 | #endif |
Dan Albert | b98c20c | 2015-02-05 23:48:06 +0000 | [diff] [blame] | 35 | |
Marshall Clow | 1df50ca | 2011-07-20 14:53:53 +0000 | [diff] [blame] | 36 | // Manage the exception object itself. |
Logan Chien | aacc1c7 | 2014-04-12 11:56:41 +0000 | [diff] [blame] | 37 | std::type_info *exceptionType; |
Dan Albert | b98c20c | 2015-02-05 23:48:06 +0000 | [diff] [blame] | 38 | void (*exceptionDestructor)(void *); |
Logan Chien | aacc1c7 | 2014-04-12 11:56:41 +0000 | [diff] [blame] | 39 | std::unexpected_handler unexpectedHandler; |
| 40 | std::terminate_handler terminateHandler; |
| 41 | |
| 42 | __cxa_exception *nextException; |
| 43 | |
| 44 | int handlerCount; |
| 45 | |
Ranjeet Singh | ef6e672 | 2017-03-01 11:42:01 +0000 | [diff] [blame] | 46 | #if defined(_LIBCXXABI_ARM_EHABI) |
Logan Chien | aacc1c7 | 2014-04-12 11:56:41 +0000 | [diff] [blame] | 47 | __cxa_exception* nextPropagatingException; |
| 48 | int propagationCount; |
Marshall Clow | 1df50ca | 2011-07-20 14:53:53 +0000 | [diff] [blame] | 49 | #else |
Logan Chien | aacc1c7 | 2014-04-12 11:56:41 +0000 | [diff] [blame] | 50 | int handlerSwitchValue; |
| 51 | const unsigned char *actionRecord; |
| 52 | const unsigned char *languageSpecificData; |
| 53 | void *catchTemp; |
| 54 | void *adjustedPtr; |
Marshall Clow | 1df50ca | 2011-07-20 14:53:53 +0000 | [diff] [blame] | 55 | #endif |
| 56 | |
Ranjeet Singh | ef6e672 | 2017-03-01 11:42:01 +0000 | [diff] [blame] | 57 | #if !defined(__LP64__) && !defined(_LIBCXXABI_ARM_EHABI) |
Marshall Clow | 1df50ca | 2011-07-20 14:53:53 +0000 | [diff] [blame] | 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. |
Logan Chien | aacc1c7 | 2014-04-12 11:56:41 +0000 | [diff] [blame] | 61 | size_t referenceCount; |
Marshall Clow | 1df50ca | 2011-07-20 14:53:53 +0000 | [diff] [blame] | 62 | #endif |
Logan Chien | aacc1c7 | 2014-04-12 11:56:41 +0000 | [diff] [blame] | 63 | |
| 64 | _Unwind_Exception unwindHeader; |
| 65 | }; |
Howard Hinnant | 6ccae15 | 2011-12-08 19:35:18 +0000 | [diff] [blame] | 66 | |
| 67 | // http://sourcery.mentor.com/archives/cxx-abi-dev/msg01924.html |
Nico Weber | ae54387 | 2014-06-25 23:52:07 +0000 | [diff] [blame] | 68 | // The layout of this structure MUST match the layout of __cxa_exception, with |
| 69 | // primaryException instead of referenceCount. |
Shoaib Meenai | fe989a9 | 2017-03-01 03:55:57 +0000 | [diff] [blame] | 70 | struct _LIBCXXABI_HIDDEN __cxa_dependent_exception { |
Ranjeet Singh | ef6e672 | 2017-03-01 11:42:01 +0000 | [diff] [blame] | 71 | #if defined(__LP64__) || defined(_LIBCXXABI_ARM_EHABI) |
Logan Chien | aacc1c7 | 2014-04-12 11:56:41 +0000 | [diff] [blame] | 72 | void* primaryException; |
Marshall Clow | 1df50ca | 2011-07-20 14:53:53 +0000 | [diff] [blame] | 73 | #endif |
Dan Albert | b98c20c | 2015-02-05 23:48:06 +0000 | [diff] [blame] | 74 | |
Logan Chien | aacc1c7 | 2014-04-12 11:56:41 +0000 | [diff] [blame] | 75 | std::type_info *exceptionType; |
Dan Albert | b98c20c | 2015-02-05 23:48:06 +0000 | [diff] [blame] | 76 | void (*exceptionDestructor)(void *); |
Logan Chien | aacc1c7 | 2014-04-12 11:56:41 +0000 | [diff] [blame] | 77 | std::unexpected_handler unexpectedHandler; |
| 78 | std::terminate_handler terminateHandler; |
| 79 | |
| 80 | __cxa_exception *nextException; |
| 81 | |
| 82 | int handlerCount; |
Dan Albert | b98c20c | 2015-02-05 23:48:06 +0000 | [diff] [blame] | 83 | |
Ranjeet Singh | ef6e672 | 2017-03-01 11:42:01 +0000 | [diff] [blame] | 84 | #if defined(_LIBCXXABI_ARM_EHABI) |
Logan Chien | aacc1c7 | 2014-04-12 11:56:41 +0000 | [diff] [blame] | 85 | __cxa_exception* nextPropagatingException; |
| 86 | int propagationCount; |
Marshall Clow | 1df50ca | 2011-07-20 14:53:53 +0000 | [diff] [blame] | 87 | #else |
Logan Chien | aacc1c7 | 2014-04-12 11:56:41 +0000 | [diff] [blame] | 88 | int handlerSwitchValue; |
| 89 | const unsigned char *actionRecord; |
| 90 | const unsigned char *languageSpecificData; |
| 91 | void * catchTemp; |
| 92 | void *adjustedPtr; |
Marshall Clow | 1df50ca | 2011-07-20 14:53:53 +0000 | [diff] [blame] | 93 | #endif |
Dan Albert | b98c20c | 2015-02-05 23:48:06 +0000 | [diff] [blame] | 94 | |
Ranjeet Singh | ef6e672 | 2017-03-01 11:42:01 +0000 | [diff] [blame] | 95 | #if !defined(__LP64__) && !defined(_LIBCXXABI_ARM_EHABI) |
Logan Chien | aacc1c7 | 2014-04-12 11:56:41 +0000 | [diff] [blame] | 96 | void* primaryException; |
Marshall Clow | 1df50ca | 2011-07-20 14:53:53 +0000 | [diff] [blame] | 97 | #endif |
Logan Chien | aacc1c7 | 2014-04-12 11:56:41 +0000 | [diff] [blame] | 98 | |
| 99 | _Unwind_Exception unwindHeader; |
| 100 | }; |
| 101 | |
Shoaib Meenai | fe989a9 | 2017-03-01 03:55:57 +0000 | [diff] [blame] | 102 | struct _LIBCXXABI_HIDDEN __cxa_eh_globals { |
Logan Chien | aacc1c7 | 2014-04-12 11:56:41 +0000 | [diff] [blame] | 103 | __cxa_exception * caughtExceptions; |
| 104 | unsigned int uncaughtExceptions; |
Ranjeet Singh | ef6e672 | 2017-03-01 11:42:01 +0000 | [diff] [blame] | 105 | #if defined(_LIBCXXABI_ARM_EHABI) |
Logan Chien | aacc1c7 | 2014-04-12 11:56:41 +0000 | [diff] [blame] | 106 | __cxa_exception* propagatingExceptions; |
Marshall Clow | 1df50ca | 2011-07-20 14:53:53 +0000 | [diff] [blame] | 107 | #endif |
Logan Chien | aacc1c7 | 2014-04-12 11:56:41 +0000 | [diff] [blame] | 108 | }; |
Marshall Clow | 1df50ca | 2011-07-20 14:53:53 +0000 | [diff] [blame] | 109 | |
Shoaib Meenai | fe989a9 | 2017-03-01 03:55:57 +0000 | [diff] [blame] | 110 | extern "C" _LIBCXXABI_FUNC_VIS __cxa_eh_globals * __cxa_get_globals (); |
| 111 | extern "C" _LIBCXXABI_FUNC_VIS __cxa_eh_globals * __cxa_get_globals_fast (); |
Howard Hinnant | eaa65af | 2012-02-02 20:47:28 +0000 | [diff] [blame] | 112 | |
Shoaib Meenai | fe989a9 | 2017-03-01 03:55:57 +0000 | [diff] [blame] | 113 | extern "C" _LIBCXXABI_FUNC_VIS void * __cxa_allocate_dependent_exception (); |
| 114 | extern "C" _LIBCXXABI_FUNC_VIS void __cxa_free_dependent_exception (void * dependent_exception); |
Logan Chien | aacc1c7 | 2014-04-12 11:56:41 +0000 | [diff] [blame] | 115 | |
| 116 | } // namespace __cxxabiv1 |
Howard Hinnant | 4ac72dd | 2012-03-19 16:20:34 +0000 | [diff] [blame] | 117 | |
| 118 | #endif // _CXA_EXCEPTION_H |