annotate libcxxabi/src/cxa_exception.h @ 236:c4bab56944e8 llvm-original

LLVM 16
author kono
date Wed, 09 Nov 2022 17:45:10 +0900
parents 79ff65ed7e25
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
236
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
1 //===----------------------------------------------------------------------===//
150
anatofuz
parents:
diff changeset
2 //
anatofuz
parents:
diff changeset
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
anatofuz
parents:
diff changeset
4 // See https://llvm.org/LICENSE.txt for license information.
anatofuz
parents:
diff changeset
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
anatofuz
parents:
diff changeset
6 //
anatofuz
parents:
diff changeset
7 //
anatofuz
parents:
diff changeset
8 // This file implements the "Exception Handling APIs"
anatofuz
parents:
diff changeset
9 // https://itanium-cxx-abi.github.io/cxx-abi/abi-eh.html
anatofuz
parents:
diff changeset
10 //
anatofuz
parents:
diff changeset
11 //===----------------------------------------------------------------------===//
anatofuz
parents:
diff changeset
12
anatofuz
parents:
diff changeset
13 #ifndef _CXA_EXCEPTION_H
anatofuz
parents:
diff changeset
14 #define _CXA_EXCEPTION_H
anatofuz
parents:
diff changeset
15
anatofuz
parents:
diff changeset
16 #include <exception> // for std::unexpected_handler and std::terminate_handler
anatofuz
parents:
diff changeset
17 #include "cxxabi.h"
anatofuz
parents:
diff changeset
18 #include "unwind.h"
anatofuz
parents:
diff changeset
19
anatofuz
parents:
diff changeset
20 namespace __cxxabiv1 {
anatofuz
parents:
diff changeset
21
anatofuz
parents:
diff changeset
22 static const uint64_t kOurExceptionClass = 0x434C4E47432B2B00; // CLNGC++\0
anatofuz
parents:
diff changeset
23 static const uint64_t kOurDependentExceptionClass = 0x434C4E47432B2B01; // CLNGC++\1
anatofuz
parents:
diff changeset
24 static const uint64_t get_vendor_and_language = 0xFFFFFFFFFFFFFF00; // mask for CLNGC++
anatofuz
parents:
diff changeset
25
anatofuz
parents:
diff changeset
26 _LIBCXXABI_HIDDEN uint64_t __getExceptionClass (const _Unwind_Exception*);
anatofuz
parents:
diff changeset
27 _LIBCXXABI_HIDDEN void __setExceptionClass ( _Unwind_Exception*, uint64_t);
anatofuz
parents:
diff changeset
28 _LIBCXXABI_HIDDEN bool __isOurExceptionClass(const _Unwind_Exception*);
anatofuz
parents:
diff changeset
29
anatofuz
parents:
diff changeset
30 struct _LIBCXXABI_HIDDEN __cxa_exception {
anatofuz
parents:
diff changeset
31 #if defined(__LP64__) || defined(_WIN64) || defined(_LIBCXXABI_ARM_EHABI)
anatofuz
parents:
diff changeset
32 // Now _Unwind_Exception is marked with __attribute__((aligned)),
anatofuz
parents:
diff changeset
33 // which implies __cxa_exception is also aligned. Insert padding
anatofuz
parents:
diff changeset
34 // in the beginning of the struct, rather than before unwindHeader.
anatofuz
parents:
diff changeset
35 void *reserve;
anatofuz
parents:
diff changeset
36
236
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
37 // This is a new field to support C++11 exception_ptr.
150
anatofuz
parents:
diff changeset
38 // For binary compatibility it is at the start of this
anatofuz
parents:
diff changeset
39 // struct which is prepended to the object thrown in
anatofuz
parents:
diff changeset
40 // __cxa_allocate_exception.
anatofuz
parents:
diff changeset
41 size_t referenceCount;
anatofuz
parents:
diff changeset
42 #endif
anatofuz
parents:
diff changeset
43
anatofuz
parents:
diff changeset
44 // Manage the exception object itself.
anatofuz
parents:
diff changeset
45 std::type_info *exceptionType;
236
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
46 void (_LIBCXXABI_DTOR_FUNC *exceptionDestructor)(void *);
150
anatofuz
parents:
diff changeset
47 std::unexpected_handler unexpectedHandler;
anatofuz
parents:
diff changeset
48 std::terminate_handler terminateHandler;
anatofuz
parents:
diff changeset
49
anatofuz
parents:
diff changeset
50 __cxa_exception *nextException;
anatofuz
parents:
diff changeset
51
anatofuz
parents:
diff changeset
52 int handlerCount;
anatofuz
parents:
diff changeset
53
anatofuz
parents:
diff changeset
54 #if defined(_LIBCXXABI_ARM_EHABI)
anatofuz
parents:
diff changeset
55 __cxa_exception* nextPropagatingException;
anatofuz
parents:
diff changeset
56 int propagationCount;
anatofuz
parents:
diff changeset
57 #else
anatofuz
parents:
diff changeset
58 int handlerSwitchValue;
anatofuz
parents:
diff changeset
59 const unsigned char *actionRecord;
anatofuz
parents:
diff changeset
60 const unsigned char *languageSpecificData;
anatofuz
parents:
diff changeset
61 void *catchTemp;
anatofuz
parents:
diff changeset
62 void *adjustedPtr;
anatofuz
parents:
diff changeset
63 #endif
anatofuz
parents:
diff changeset
64
anatofuz
parents:
diff changeset
65 #if !defined(__LP64__) && !defined(_WIN64) && !defined(_LIBCXXABI_ARM_EHABI)
236
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
66 // This is a new field to support C++11 exception_ptr.
150
anatofuz
parents:
diff changeset
67 // For binary compatibility it is placed where the compiler
236
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
68 // previously added padding to 64-bit align unwindHeader.
150
anatofuz
parents:
diff changeset
69 size_t referenceCount;
anatofuz
parents:
diff changeset
70 #endif
anatofuz
parents:
diff changeset
71 _Unwind_Exception unwindHeader;
anatofuz
parents:
diff changeset
72 };
anatofuz
parents:
diff changeset
73
anatofuz
parents:
diff changeset
74 // http://sourcery.mentor.com/archives/cxx-abi-dev/msg01924.html
anatofuz
parents:
diff changeset
75 // The layout of this structure MUST match the layout of __cxa_exception, with
anatofuz
parents:
diff changeset
76 // primaryException instead of referenceCount.
anatofuz
parents:
diff changeset
77 struct _LIBCXXABI_HIDDEN __cxa_dependent_exception {
anatofuz
parents:
diff changeset
78 #if defined(__LP64__) || defined(_WIN64) || defined(_LIBCXXABI_ARM_EHABI)
anatofuz
parents:
diff changeset
79 void* reserve; // padding.
anatofuz
parents:
diff changeset
80 void* primaryException;
anatofuz
parents:
diff changeset
81 #endif
anatofuz
parents:
diff changeset
82
anatofuz
parents:
diff changeset
83 std::type_info *exceptionType;
236
c4bab56944e8 LLVM 16
kono
parents: 221
diff changeset
84 void (_LIBCXXABI_DTOR_FUNC *exceptionDestructor)(void *);
150
anatofuz
parents:
diff changeset
85 std::unexpected_handler unexpectedHandler;
anatofuz
parents:
diff changeset
86 std::terminate_handler terminateHandler;
anatofuz
parents:
diff changeset
87
anatofuz
parents:
diff changeset
88 __cxa_exception *nextException;
anatofuz
parents:
diff changeset
89
anatofuz
parents:
diff changeset
90 int handlerCount;
anatofuz
parents:
diff changeset
91
anatofuz
parents:
diff changeset
92 #if defined(_LIBCXXABI_ARM_EHABI)
anatofuz
parents:
diff changeset
93 __cxa_exception* nextPropagatingException;
anatofuz
parents:
diff changeset
94 int propagationCount;
anatofuz
parents:
diff changeset
95 #else
anatofuz
parents:
diff changeset
96 int handlerSwitchValue;
anatofuz
parents:
diff changeset
97 const unsigned char *actionRecord;
anatofuz
parents:
diff changeset
98 const unsigned char *languageSpecificData;
anatofuz
parents:
diff changeset
99 void * catchTemp;
anatofuz
parents:
diff changeset
100 void *adjustedPtr;
anatofuz
parents:
diff changeset
101 #endif
anatofuz
parents:
diff changeset
102
anatofuz
parents:
diff changeset
103 #if !defined(__LP64__) && !defined(_WIN64) && !defined(_LIBCXXABI_ARM_EHABI)
anatofuz
parents:
diff changeset
104 void* primaryException;
anatofuz
parents:
diff changeset
105 #endif
anatofuz
parents:
diff changeset
106 _Unwind_Exception unwindHeader;
anatofuz
parents:
diff changeset
107 };
anatofuz
parents:
diff changeset
108
anatofuz
parents:
diff changeset
109 // Verify the negative offsets of different fields.
anatofuz
parents:
diff changeset
110 static_assert(sizeof(_Unwind_Exception) +
anatofuz
parents:
diff changeset
111 offsetof(__cxa_exception, unwindHeader) ==
anatofuz
parents:
diff changeset
112 sizeof(__cxa_exception),
anatofuz
parents:
diff changeset
113 "unwindHeader has wrong negative offsets");
anatofuz
parents:
diff changeset
114 static_assert(sizeof(_Unwind_Exception) +
anatofuz
parents:
diff changeset
115 offsetof(__cxa_dependent_exception, unwindHeader) ==
anatofuz
parents:
diff changeset
116 sizeof(__cxa_dependent_exception),
anatofuz
parents:
diff changeset
117 "unwindHeader has wrong negative offsets");
anatofuz
parents:
diff changeset
118
anatofuz
parents:
diff changeset
119 #if defined(_LIBCXXABI_ARM_EHABI)
anatofuz
parents:
diff changeset
120 static_assert(offsetof(__cxa_exception, propagationCount) +
anatofuz
parents:
diff changeset
121 sizeof(_Unwind_Exception) + sizeof(void*) ==
anatofuz
parents:
diff changeset
122 sizeof(__cxa_exception),
anatofuz
parents:
diff changeset
123 "propagationCount has wrong negative offset");
anatofuz
parents:
diff changeset
124 static_assert(offsetof(__cxa_dependent_exception, propagationCount) +
anatofuz
parents:
diff changeset
125 sizeof(_Unwind_Exception) + sizeof(void*) ==
anatofuz
parents:
diff changeset
126 sizeof(__cxa_dependent_exception),
anatofuz
parents:
diff changeset
127 "propagationCount has wrong negative offset");
anatofuz
parents:
diff changeset
128 #elif defined(__LP64__) || defined(_WIN64)
anatofuz
parents:
diff changeset
129 static_assert(offsetof(__cxa_exception, adjustedPtr) +
anatofuz
parents:
diff changeset
130 sizeof(_Unwind_Exception) + sizeof(void*) ==
anatofuz
parents:
diff changeset
131 sizeof(__cxa_exception),
anatofuz
parents:
diff changeset
132 "adjustedPtr has wrong negative offset");
anatofuz
parents:
diff changeset
133 static_assert(offsetof(__cxa_dependent_exception, adjustedPtr) +
anatofuz
parents:
diff changeset
134 sizeof(_Unwind_Exception) + sizeof(void*) ==
anatofuz
parents:
diff changeset
135 sizeof(__cxa_dependent_exception),
anatofuz
parents:
diff changeset
136 "adjustedPtr has wrong negative offset");
anatofuz
parents:
diff changeset
137 #else
anatofuz
parents:
diff changeset
138 static_assert(offsetof(__cxa_exception, referenceCount) +
anatofuz
parents:
diff changeset
139 sizeof(_Unwind_Exception) + sizeof(void*) ==
anatofuz
parents:
diff changeset
140 sizeof(__cxa_exception),
anatofuz
parents:
diff changeset
141 "referenceCount has wrong negative offset");
anatofuz
parents:
diff changeset
142 static_assert(offsetof(__cxa_dependent_exception, primaryException) +
anatofuz
parents:
diff changeset
143 sizeof(_Unwind_Exception) + sizeof(void*) ==
anatofuz
parents:
diff changeset
144 sizeof(__cxa_dependent_exception),
anatofuz
parents:
diff changeset
145 "primaryException has wrong negative offset");
anatofuz
parents:
diff changeset
146 #endif
anatofuz
parents:
diff changeset
147
anatofuz
parents:
diff changeset
148 struct _LIBCXXABI_HIDDEN __cxa_eh_globals {
anatofuz
parents:
diff changeset
149 __cxa_exception * caughtExceptions;
anatofuz
parents:
diff changeset
150 unsigned int uncaughtExceptions;
anatofuz
parents:
diff changeset
151 #if defined(_LIBCXXABI_ARM_EHABI)
anatofuz
parents:
diff changeset
152 __cxa_exception* propagatingExceptions;
anatofuz
parents:
diff changeset
153 #endif
anatofuz
parents:
diff changeset
154 };
anatofuz
parents:
diff changeset
155
anatofuz
parents:
diff changeset
156 extern "C" _LIBCXXABI_FUNC_VIS __cxa_eh_globals * __cxa_get_globals ();
anatofuz
parents:
diff changeset
157 extern "C" _LIBCXXABI_FUNC_VIS __cxa_eh_globals * __cxa_get_globals_fast ();
anatofuz
parents:
diff changeset
158
anatofuz
parents:
diff changeset
159 extern "C" _LIBCXXABI_FUNC_VIS void * __cxa_allocate_dependent_exception ();
anatofuz
parents:
diff changeset
160 extern "C" _LIBCXXABI_FUNC_VIS void __cxa_free_dependent_exception (void * dependent_exception);
anatofuz
parents:
diff changeset
161
anatofuz
parents:
diff changeset
162 } // namespace __cxxabiv1
anatofuz
parents:
diff changeset
163
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
164 #endif // _CXA_EXCEPTION_H