Howard Hinnant | 987afbe | 2011-12-06 18:01:47 +0000 | [diff] [blame] | 1 | //===------------------------- cxa_exception.hpp --------------------------===// |
| 2 | // |
Chandler Carruth | 57b08b0 | 2019-01-19 10:56:40 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Howard Hinnant | 987afbe | 2011-12-06 18:01:47 +0000 | [diff] [blame] | 6 | // |
| 7 | // |
| 8 | // This file implements the "Exception Handling APIs" |
Louis Dionne | 2b0da3d | 2019-04-11 16:37:07 +0000 | [diff] [blame^] | 9 | // https://itanium-cxx-abi.github.io/cxx-abi/abi-eh.html |
Howard Hinnant | 987afbe | 2011-12-06 18:01:47 +0000 | [diff] [blame] | 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
Howard Hinnant | 4ac72dd | 2012-03-19 16:20:34 +0000 | [diff] [blame] | 13 | #ifndef _CXA_EXCEPTION_H |
| 14 | #define _CXA_EXCEPTION_H |
| 15 | |
Marshall Clow | 1df50ca | 2011-07-20 14:53:53 +0000 | [diff] [blame] | 16 | #include <exception> // for std::unexpected_handler and std::terminate_handler |
Mehdi Amini | 5a40358 | 2017-04-04 05:38:38 +0000 | [diff] [blame] | 17 | #include "cxxabi.h" |
Marshall Clow | 1df50ca | 2011-07-20 14:53:53 +0000 | [diff] [blame] | 18 | #include "unwind.h" |
| 19 | |
| 20 | namespace __cxxabiv1 { |
| 21 | |
Howard Hinnant | 6830b2a | 2012-01-24 18:15:20 +0000 | [diff] [blame] | 22 | static const uint64_t kOurExceptionClass = 0x434C4E47432B2B00; // CLNGC++\0 |
| 23 | static const uint64_t kOurDependentExceptionClass = 0x434C4E47432B2B01; // CLNGC++\1 |
Dan Albert | b98c20c | 2015-02-05 23:48:06 +0000 | [diff] [blame] | 24 | static const uint64_t get_vendor_and_language = 0xFFFFFFFFFFFFFF00; // mask for CLNGC++ |
| 25 | |
Marshall Clow | 611a55a | 2018-10-10 16:18:37 +0000 | [diff] [blame] | 26 | uint64_t __getExceptionClass (const _Unwind_Exception*); |
| 27 | void __setExceptionClass ( _Unwind_Exception*, uint64_t); |
| 28 | bool __isOurExceptionClass(const _Unwind_Exception*); |
| 29 | |
Shoaib Meenai | fe989a9 | 2017-03-01 03:55:57 +0000 | [diff] [blame] | 30 | struct _LIBCXXABI_HIDDEN __cxa_exception { |
Ranjeet Singh | ef6e672 | 2017-03-01 11:42:01 +0000 | [diff] [blame] | 31 | #if defined(__LP64__) || defined(_LIBCXXABI_ARM_EHABI) |
Marshall Clow | 1df50ca | 2011-07-20 14:53:53 +0000 | [diff] [blame] | 32 | // This is a new field to support C++ 0x exception_ptr. |
| 33 | // For binary compatibility it is at the start of this |
| 34 | // struct which is prepended to the object thrown in |
| 35 | // __cxa_allocate_exception. |
Logan Chien | aacc1c7 | 2014-04-12 11:56:41 +0000 | [diff] [blame] | 36 | size_t referenceCount; |
Marshall Clow | 1df50ca | 2011-07-20 14:53:53 +0000 | [diff] [blame] | 37 | #endif |
Dan Albert | b98c20c | 2015-02-05 23:48:06 +0000 | [diff] [blame] | 38 | |
Marshall Clow | 1df50ca | 2011-07-20 14:53:53 +0000 | [diff] [blame] | 39 | // Manage the exception object itself. |
Logan Chien | aacc1c7 | 2014-04-12 11:56:41 +0000 | [diff] [blame] | 40 | std::type_info *exceptionType; |
Dan Albert | b98c20c | 2015-02-05 23:48:06 +0000 | [diff] [blame] | 41 | void (*exceptionDestructor)(void *); |
Logan Chien | aacc1c7 | 2014-04-12 11:56:41 +0000 | [diff] [blame] | 42 | std::unexpected_handler unexpectedHandler; |
| 43 | std::terminate_handler terminateHandler; |
| 44 | |
| 45 | __cxa_exception *nextException; |
| 46 | |
| 47 | int handlerCount; |
| 48 | |
Ranjeet Singh | ef6e672 | 2017-03-01 11:42:01 +0000 | [diff] [blame] | 49 | #if defined(_LIBCXXABI_ARM_EHABI) |
Logan Chien | aacc1c7 | 2014-04-12 11:56:41 +0000 | [diff] [blame] | 50 | __cxa_exception* nextPropagatingException; |
| 51 | int propagationCount; |
Marshall Clow | 1df50ca | 2011-07-20 14:53:53 +0000 | [diff] [blame] | 52 | #else |
Logan Chien | aacc1c7 | 2014-04-12 11:56:41 +0000 | [diff] [blame] | 53 | int handlerSwitchValue; |
| 54 | const unsigned char *actionRecord; |
| 55 | const unsigned char *languageSpecificData; |
| 56 | void *catchTemp; |
| 57 | void *adjustedPtr; |
Marshall Clow | 1df50ca | 2011-07-20 14:53:53 +0000 | [diff] [blame] | 58 | #endif |
| 59 | |
Ranjeet Singh | ef6e672 | 2017-03-01 11:42:01 +0000 | [diff] [blame] | 60 | #if !defined(__LP64__) && !defined(_LIBCXXABI_ARM_EHABI) |
Marshall Clow | 1df50ca | 2011-07-20 14:53:53 +0000 | [diff] [blame] | 61 | // This is a new field to support C++ 0x exception_ptr. |
| 62 | // For binary compatibility it is placed where the compiler |
| 63 | // previously adding padded to 64-bit align unwindHeader. |
Logan Chien | aacc1c7 | 2014-04-12 11:56:41 +0000 | [diff] [blame] | 64 | size_t referenceCount; |
Marshall Clow | 1df50ca | 2011-07-20 14:53:53 +0000 | [diff] [blame] | 65 | #endif |
Akira Hatanaka | c57477b2 | 2017-05-13 06:28:17 +0000 | [diff] [blame] | 66 | _Unwind_Exception unwindHeader; |
Logan Chien | aacc1c7 | 2014-04-12 11:56:41 +0000 | [diff] [blame] | 67 | }; |
Howard Hinnant | 6ccae15 | 2011-12-08 19:35:18 +0000 | [diff] [blame] | 68 | |
| 69 | // http://sourcery.mentor.com/archives/cxx-abi-dev/msg01924.html |
Nico Weber | ae54387 | 2014-06-25 23:52:07 +0000 | [diff] [blame] | 70 | // The layout of this structure MUST match the layout of __cxa_exception, with |
| 71 | // primaryException instead of referenceCount. |
Shoaib Meenai | fe989a9 | 2017-03-01 03:55:57 +0000 | [diff] [blame] | 72 | struct _LIBCXXABI_HIDDEN __cxa_dependent_exception { |
Ranjeet Singh | ef6e672 | 2017-03-01 11:42:01 +0000 | [diff] [blame] | 73 | #if defined(__LP64__) || defined(_LIBCXXABI_ARM_EHABI) |
Logan Chien | aacc1c7 | 2014-04-12 11:56:41 +0000 | [diff] [blame] | 74 | void* primaryException; |
Marshall Clow | 1df50ca | 2011-07-20 14:53:53 +0000 | [diff] [blame] | 75 | #endif |
Dan Albert | b98c20c | 2015-02-05 23:48:06 +0000 | [diff] [blame] | 76 | |
Logan Chien | aacc1c7 | 2014-04-12 11:56:41 +0000 | [diff] [blame] | 77 | std::type_info *exceptionType; |
Dan Albert | b98c20c | 2015-02-05 23:48:06 +0000 | [diff] [blame] | 78 | void (*exceptionDestructor)(void *); |
Logan Chien | aacc1c7 | 2014-04-12 11:56:41 +0000 | [diff] [blame] | 79 | std::unexpected_handler unexpectedHandler; |
| 80 | std::terminate_handler terminateHandler; |
| 81 | |
| 82 | __cxa_exception *nextException; |
| 83 | |
| 84 | int handlerCount; |
Dan Albert | b98c20c | 2015-02-05 23:48:06 +0000 | [diff] [blame] | 85 | |
Ranjeet Singh | ef6e672 | 2017-03-01 11:42:01 +0000 | [diff] [blame] | 86 | #if defined(_LIBCXXABI_ARM_EHABI) |
Logan Chien | aacc1c7 | 2014-04-12 11:56:41 +0000 | [diff] [blame] | 87 | __cxa_exception* nextPropagatingException; |
| 88 | int propagationCount; |
Marshall Clow | 1df50ca | 2011-07-20 14:53:53 +0000 | [diff] [blame] | 89 | #else |
Logan Chien | aacc1c7 | 2014-04-12 11:56:41 +0000 | [diff] [blame] | 90 | int handlerSwitchValue; |
| 91 | const unsigned char *actionRecord; |
| 92 | const unsigned char *languageSpecificData; |
| 93 | void * catchTemp; |
| 94 | void *adjustedPtr; |
Marshall Clow | 1df50ca | 2011-07-20 14:53:53 +0000 | [diff] [blame] | 95 | #endif |
Dan Albert | b98c20c | 2015-02-05 23:48:06 +0000 | [diff] [blame] | 96 | |
Ranjeet Singh | ef6e672 | 2017-03-01 11:42:01 +0000 | [diff] [blame] | 97 | #if !defined(__LP64__) && !defined(_LIBCXXABI_ARM_EHABI) |
Logan Chien | aacc1c7 | 2014-04-12 11:56:41 +0000 | [diff] [blame] | 98 | void* primaryException; |
Marshall Clow | 1df50ca | 2011-07-20 14:53:53 +0000 | [diff] [blame] | 99 | #endif |
Akira Hatanaka | c57477b2 | 2017-05-13 06:28:17 +0000 | [diff] [blame] | 100 | _Unwind_Exception unwindHeader; |
Logan Chien | aacc1c7 | 2014-04-12 11:56:41 +0000 | [diff] [blame] | 101 | }; |
| 102 | |
Shoaib Meenai | fe989a9 | 2017-03-01 03:55:57 +0000 | [diff] [blame] | 103 | struct _LIBCXXABI_HIDDEN __cxa_eh_globals { |
Logan Chien | aacc1c7 | 2014-04-12 11:56:41 +0000 | [diff] [blame] | 104 | __cxa_exception * caughtExceptions; |
| 105 | unsigned int uncaughtExceptions; |
Ranjeet Singh | ef6e672 | 2017-03-01 11:42:01 +0000 | [diff] [blame] | 106 | #if defined(_LIBCXXABI_ARM_EHABI) |
Logan Chien | aacc1c7 | 2014-04-12 11:56:41 +0000 | [diff] [blame] | 107 | __cxa_exception* propagatingExceptions; |
Marshall Clow | 1df50ca | 2011-07-20 14:53:53 +0000 | [diff] [blame] | 108 | #endif |
Logan Chien | aacc1c7 | 2014-04-12 11:56:41 +0000 | [diff] [blame] | 109 | }; |
Marshall Clow | 1df50ca | 2011-07-20 14:53:53 +0000 | [diff] [blame] | 110 | |
Shoaib Meenai | fe989a9 | 2017-03-01 03:55:57 +0000 | [diff] [blame] | 111 | extern "C" _LIBCXXABI_FUNC_VIS __cxa_eh_globals * __cxa_get_globals (); |
| 112 | extern "C" _LIBCXXABI_FUNC_VIS __cxa_eh_globals * __cxa_get_globals_fast (); |
Howard Hinnant | eaa65af | 2012-02-02 20:47:28 +0000 | [diff] [blame] | 113 | |
Shoaib Meenai | fe989a9 | 2017-03-01 03:55:57 +0000 | [diff] [blame] | 114 | extern "C" _LIBCXXABI_FUNC_VIS void * __cxa_allocate_dependent_exception (); |
| 115 | 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] | 116 | |
| 117 | } // namespace __cxxabiv1 |
Howard Hinnant | 4ac72dd | 2012-03-19 16:20:34 +0000 | [diff] [blame] | 118 | |
| 119 | #endif // _CXA_EXCEPTION_H |