xref: /aosp_15_r20/external/libcxxabi/src/cxa_exception.hpp (revision c05d8e5dc3e10f6ce4317e8bc22cc4a25f55fa94)
1*c05d8e5dSAndroid Build Coastguard Worker //===------------------------- cxa_exception.hpp --------------------------===//
2*c05d8e5dSAndroid Build Coastguard Worker //
3*c05d8e5dSAndroid Build Coastguard Worker //                     The LLVM Compiler Infrastructure
4*c05d8e5dSAndroid Build Coastguard Worker //
5*c05d8e5dSAndroid Build Coastguard Worker // This file is dual licensed under the MIT and the University of Illinois Open
6*c05d8e5dSAndroid Build Coastguard Worker // Source Licenses. See LICENSE.TXT for details.
7*c05d8e5dSAndroid Build Coastguard Worker //
8*c05d8e5dSAndroid Build Coastguard Worker //
9*c05d8e5dSAndroid Build Coastguard Worker //  This file implements the "Exception Handling APIs"
10*c05d8e5dSAndroid Build Coastguard Worker //  http://mentorembedded.github.io/cxx-abi/abi-eh.html
11*c05d8e5dSAndroid Build Coastguard Worker //
12*c05d8e5dSAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
13*c05d8e5dSAndroid Build Coastguard Worker 
14*c05d8e5dSAndroid Build Coastguard Worker #ifndef _CXA_EXCEPTION_H
15*c05d8e5dSAndroid Build Coastguard Worker #define _CXA_EXCEPTION_H
16*c05d8e5dSAndroid Build Coastguard Worker 
17*c05d8e5dSAndroid Build Coastguard Worker #include <exception> // for std::unexpected_handler and std::terminate_handler
18*c05d8e5dSAndroid Build Coastguard Worker #include "cxxabi.h"
19*c05d8e5dSAndroid Build Coastguard Worker #include "unwind.h"
20*c05d8e5dSAndroid Build Coastguard Worker 
21*c05d8e5dSAndroid Build Coastguard Worker namespace __cxxabiv1 {
22*c05d8e5dSAndroid Build Coastguard Worker 
23*c05d8e5dSAndroid Build Coastguard Worker static const uint64_t kOurExceptionClass          = 0x434C4E47432B2B00; // CLNGC++\0
24*c05d8e5dSAndroid Build Coastguard Worker static const uint64_t kOurDependentExceptionClass = 0x434C4E47432B2B01; // CLNGC++\1
25*c05d8e5dSAndroid Build Coastguard Worker static const uint64_t get_vendor_and_language     = 0xFFFFFFFFFFFFFF00; // mask for CLNGC++
26*c05d8e5dSAndroid Build Coastguard Worker 
27*c05d8e5dSAndroid Build Coastguard Worker uint64_t __getExceptionClass  (const _Unwind_Exception*);
28*c05d8e5dSAndroid Build Coastguard Worker void     __setExceptionClass  (      _Unwind_Exception*, uint64_t);
29*c05d8e5dSAndroid Build Coastguard Worker bool     __isOurExceptionClass(const _Unwind_Exception*);
30*c05d8e5dSAndroid Build Coastguard Worker 
31*c05d8e5dSAndroid Build Coastguard Worker struct _LIBCXXABI_HIDDEN __cxa_exception {
32*c05d8e5dSAndroid Build Coastguard Worker #if defined(__LP64__) || defined(_LIBCXXABI_ARM_EHABI)
33*c05d8e5dSAndroid Build Coastguard Worker     // This is a new field to support C++ 0x exception_ptr.
34*c05d8e5dSAndroid Build Coastguard Worker     // For binary compatibility it is at the start of this
35*c05d8e5dSAndroid Build Coastguard Worker     // struct which is prepended to the object thrown in
36*c05d8e5dSAndroid Build Coastguard Worker     // __cxa_allocate_exception.
37*c05d8e5dSAndroid Build Coastguard Worker     size_t referenceCount;
38*c05d8e5dSAndroid Build Coastguard Worker #endif
39*c05d8e5dSAndroid Build Coastguard Worker 
40*c05d8e5dSAndroid Build Coastguard Worker     //  Manage the exception object itself.
41*c05d8e5dSAndroid Build Coastguard Worker     std::type_info *exceptionType;
42*c05d8e5dSAndroid Build Coastguard Worker     void (*exceptionDestructor)(void *);
43*c05d8e5dSAndroid Build Coastguard Worker     std::unexpected_handler unexpectedHandler;
44*c05d8e5dSAndroid Build Coastguard Worker     std::terminate_handler  terminateHandler;
45*c05d8e5dSAndroid Build Coastguard Worker 
46*c05d8e5dSAndroid Build Coastguard Worker     __cxa_exception *nextException;
47*c05d8e5dSAndroid Build Coastguard Worker 
48*c05d8e5dSAndroid Build Coastguard Worker     int handlerCount;
49*c05d8e5dSAndroid Build Coastguard Worker 
50*c05d8e5dSAndroid Build Coastguard Worker #if defined(_LIBCXXABI_ARM_EHABI)
51*c05d8e5dSAndroid Build Coastguard Worker     __cxa_exception* nextPropagatingException;
52*c05d8e5dSAndroid Build Coastguard Worker     int propagationCount;
53*c05d8e5dSAndroid Build Coastguard Worker #else
54*c05d8e5dSAndroid Build Coastguard Worker     int handlerSwitchValue;
55*c05d8e5dSAndroid Build Coastguard Worker     const unsigned char *actionRecord;
56*c05d8e5dSAndroid Build Coastguard Worker     const unsigned char *languageSpecificData;
57*c05d8e5dSAndroid Build Coastguard Worker     void *catchTemp;
58*c05d8e5dSAndroid Build Coastguard Worker     void *adjustedPtr;
59*c05d8e5dSAndroid Build Coastguard Worker #endif
60*c05d8e5dSAndroid Build Coastguard Worker 
61*c05d8e5dSAndroid Build Coastguard Worker #if !defined(__LP64__) && !defined(_LIBCXXABI_ARM_EHABI)
62*c05d8e5dSAndroid Build Coastguard Worker     // This is a new field to support C++ 0x exception_ptr.
63*c05d8e5dSAndroid Build Coastguard Worker     // For binary compatibility it is placed where the compiler
64*c05d8e5dSAndroid Build Coastguard Worker     // previously adding padded to 64-bit align unwindHeader.
65*c05d8e5dSAndroid Build Coastguard Worker     size_t referenceCount;
66*c05d8e5dSAndroid Build Coastguard Worker #endif
67*c05d8e5dSAndroid Build Coastguard Worker     _Unwind_Exception unwindHeader;
68*c05d8e5dSAndroid Build Coastguard Worker };
69*c05d8e5dSAndroid Build Coastguard Worker 
70*c05d8e5dSAndroid Build Coastguard Worker // http://sourcery.mentor.com/archives/cxx-abi-dev/msg01924.html
71*c05d8e5dSAndroid Build Coastguard Worker // The layout of this structure MUST match the layout of __cxa_exception, with
72*c05d8e5dSAndroid Build Coastguard Worker // primaryException instead of referenceCount.
73*c05d8e5dSAndroid Build Coastguard Worker struct _LIBCXXABI_HIDDEN __cxa_dependent_exception {
74*c05d8e5dSAndroid Build Coastguard Worker #if defined(__LP64__) || defined(_LIBCXXABI_ARM_EHABI)
75*c05d8e5dSAndroid Build Coastguard Worker     void* primaryException;
76*c05d8e5dSAndroid Build Coastguard Worker #endif
77*c05d8e5dSAndroid Build Coastguard Worker 
78*c05d8e5dSAndroid Build Coastguard Worker     std::type_info *exceptionType;
79*c05d8e5dSAndroid Build Coastguard Worker     void (*exceptionDestructor)(void *);
80*c05d8e5dSAndroid Build Coastguard Worker     std::unexpected_handler unexpectedHandler;
81*c05d8e5dSAndroid Build Coastguard Worker     std::terminate_handler terminateHandler;
82*c05d8e5dSAndroid Build Coastguard Worker 
83*c05d8e5dSAndroid Build Coastguard Worker     __cxa_exception *nextException;
84*c05d8e5dSAndroid Build Coastguard Worker 
85*c05d8e5dSAndroid Build Coastguard Worker     int handlerCount;
86*c05d8e5dSAndroid Build Coastguard Worker 
87*c05d8e5dSAndroid Build Coastguard Worker #if defined(_LIBCXXABI_ARM_EHABI)
88*c05d8e5dSAndroid Build Coastguard Worker     __cxa_exception* nextPropagatingException;
89*c05d8e5dSAndroid Build Coastguard Worker     int propagationCount;
90*c05d8e5dSAndroid Build Coastguard Worker #else
91*c05d8e5dSAndroid Build Coastguard Worker     int handlerSwitchValue;
92*c05d8e5dSAndroid Build Coastguard Worker     const unsigned char *actionRecord;
93*c05d8e5dSAndroid Build Coastguard Worker     const unsigned char *languageSpecificData;
94*c05d8e5dSAndroid Build Coastguard Worker     void * catchTemp;
95*c05d8e5dSAndroid Build Coastguard Worker     void *adjustedPtr;
96*c05d8e5dSAndroid Build Coastguard Worker #endif
97*c05d8e5dSAndroid Build Coastguard Worker 
98*c05d8e5dSAndroid Build Coastguard Worker #if !defined(__LP64__) && !defined(_LIBCXXABI_ARM_EHABI)
99*c05d8e5dSAndroid Build Coastguard Worker     void* primaryException;
100*c05d8e5dSAndroid Build Coastguard Worker #endif
101*c05d8e5dSAndroid Build Coastguard Worker     _Unwind_Exception unwindHeader;
102*c05d8e5dSAndroid Build Coastguard Worker };
103*c05d8e5dSAndroid Build Coastguard Worker 
104*c05d8e5dSAndroid Build Coastguard Worker struct _LIBCXXABI_HIDDEN __cxa_eh_globals {
105*c05d8e5dSAndroid Build Coastguard Worker     __cxa_exception *   caughtExceptions;
106*c05d8e5dSAndroid Build Coastguard Worker     unsigned int        uncaughtExceptions;
107*c05d8e5dSAndroid Build Coastguard Worker #if defined(_LIBCXXABI_ARM_EHABI)
108*c05d8e5dSAndroid Build Coastguard Worker     __cxa_exception* propagatingExceptions;
109*c05d8e5dSAndroid Build Coastguard Worker #endif
110*c05d8e5dSAndroid Build Coastguard Worker };
111*c05d8e5dSAndroid Build Coastguard Worker 
112*c05d8e5dSAndroid Build Coastguard Worker extern "C" _LIBCXXABI_FUNC_VIS __cxa_eh_globals * __cxa_get_globals      ();
113*c05d8e5dSAndroid Build Coastguard Worker extern "C" _LIBCXXABI_FUNC_VIS __cxa_eh_globals * __cxa_get_globals_fast ();
114*c05d8e5dSAndroid Build Coastguard Worker 
115*c05d8e5dSAndroid Build Coastguard Worker extern "C" _LIBCXXABI_FUNC_VIS void * __cxa_allocate_dependent_exception ();
116*c05d8e5dSAndroid Build Coastguard Worker extern "C" _LIBCXXABI_FUNC_VIS void __cxa_free_dependent_exception (void * dependent_exception);
117*c05d8e5dSAndroid Build Coastguard Worker 
118*c05d8e5dSAndroid Build Coastguard Worker }  // namespace __cxxabiv1
119*c05d8e5dSAndroid Build Coastguard Worker 
120*c05d8e5dSAndroid Build Coastguard Worker #endif  // _CXA_EXCEPTION_H
121