1//===------------------------- cxa_exception.h ----------------------------===// 2// 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 6// 7// 8// This file implements the "Exception Handling APIs" 9// https://itanium-cxx-abi.github.io/cxx-abi/abi-eh.html 10// 11//===----------------------------------------------------------------------===// 12 13#ifndef _CXA_EXCEPTION_H 14#define _CXA_EXCEPTION_H 15 16#include <exception> // for std::unexpected_handler and std::terminate_handler 17#include "cxxabi.h" 18#include "unwind.h" 19 20namespace __cxxabiv1 { 21 22static const uint64_t kOurExceptionClass = 0x434C4E47432B2B00; // CLNGC++\0 23static const uint64_t kOurDependentExceptionClass = 0x434C4E47432B2B01; // CLNGC++\1 24static const uint64_t get_vendor_and_language = 0xFFFFFFFFFFFFFF00; // mask for CLNGC++ 25 26uint64_t __getExceptionClass (const _Unwind_Exception*); 27void __setExceptionClass ( _Unwind_Exception*, uint64_t); 28bool __isOurExceptionClass(const _Unwind_Exception*); 29 30struct _LIBCXXABI_HIDDEN __cxa_exception { 31#if defined(__LP64__) || defined(_LIBCXXABI_ARM_EHABI) 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. 36 size_t referenceCount; 37#endif 38 39 // Manage the exception object itself. 40 std::type_info *exceptionType; 41 void (*exceptionDestructor)(void *); 42 std::unexpected_handler unexpectedHandler; 43 std::terminate_handler terminateHandler; 44 45 __cxa_exception *nextException; 46 47 int handlerCount; 48 49#if defined(_LIBCXXABI_ARM_EHABI) 50 __cxa_exception* nextPropagatingException; 51 int propagationCount; 52#else 53 int handlerSwitchValue; 54 const unsigned char *actionRecord; 55 const unsigned char *languageSpecificData; 56 void *catchTemp; 57 void *adjustedPtr; 58#endif 59 60#if !defined(__LP64__) && !defined(_LIBCXXABI_ARM_EHABI) 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. 64 size_t referenceCount; 65#endif 66 _Unwind_Exception unwindHeader; 67}; 68 69// http://sourcery.mentor.com/archives/cxx-abi-dev/msg01924.html 70// The layout of this structure MUST match the layout of __cxa_exception, with 71// primaryException instead of referenceCount. 72struct _LIBCXXABI_HIDDEN __cxa_dependent_exception { 73#if defined(__LP64__) || defined(_LIBCXXABI_ARM_EHABI) 74 void* primaryException; 75#endif 76 77 std::type_info *exceptionType; 78 void (*exceptionDestructor)(void *); 79 std::unexpected_handler unexpectedHandler; 80 std::terminate_handler terminateHandler; 81 82 __cxa_exception *nextException; 83 84 int handlerCount; 85 86#if defined(_LIBCXXABI_ARM_EHABI) 87 __cxa_exception* nextPropagatingException; 88 int propagationCount; 89#else 90 int handlerSwitchValue; 91 const unsigned char *actionRecord; 92 const unsigned char *languageSpecificData; 93 void * catchTemp; 94 void *adjustedPtr; 95#endif 96 97#if !defined(__LP64__) && !defined(_LIBCXXABI_ARM_EHABI) 98 void* primaryException; 99#endif 100 _Unwind_Exception unwindHeader; 101}; 102 103struct _LIBCXXABI_HIDDEN __cxa_eh_globals { 104 __cxa_exception * caughtExceptions; 105 unsigned int uncaughtExceptions; 106#if defined(_LIBCXXABI_ARM_EHABI) 107 __cxa_exception* propagatingExceptions; 108#endif 109}; 110 111extern "C" _LIBCXXABI_FUNC_VIS __cxa_eh_globals * __cxa_get_globals (); 112extern "C" _LIBCXXABI_FUNC_VIS __cxa_eh_globals * __cxa_get_globals_fast (); 113 114extern "C" _LIBCXXABI_FUNC_VIS void * __cxa_allocate_dependent_exception (); 115extern "C" _LIBCXXABI_FUNC_VIS void __cxa_free_dependent_exception (void * dependent_exception); 116 117} // namespace __cxxabiv1 118 119#endif // _CXA_EXCEPTION_H 120