1//===----------------------------------------------------------------------===//
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
9#ifndef __PRIVATE_TYPEINFO_H_
10#define __PRIVATE_TYPEINFO_H_
11
12#include "__cxxabi_config.h"
13
14#include <typeinfo>
15#include <stddef.h>
16
17namespace __cxxabiv1 {
18
19class _LIBCXXABI_TYPE_VIS __shim_type_info : public std::type_info {
20public:
21 _LIBCXXABI_HIDDEN ~__shim_type_info() override;
22
23 _LIBCXXABI_HIDDEN virtual void noop1() const;
24 _LIBCXXABI_HIDDEN virtual void noop2() const;
25 _LIBCXXABI_HIDDEN virtual bool can_catch(const __shim_type_info *thrown_type,
26 void *&adjustedPtr) const = 0;
27};
28
29class _LIBCXXABI_TYPE_VIS __fundamental_type_info final : public __shim_type_info {
30public:
31 _LIBCXXABI_HIDDEN ~__fundamental_type_info() final;
32 _LIBCXXABI_HIDDEN bool can_catch(const __shim_type_info*, void*&) const final;
33};
34
35class _LIBCXXABI_TYPE_VIS __array_type_info final : public __shim_type_info {
36public:
37 _LIBCXXABI_HIDDEN ~__array_type_info() final;
38 _LIBCXXABI_HIDDEN bool can_catch(const __shim_type_info*, void*&) const final;
39};
40
41class _LIBCXXABI_TYPE_VIS __function_type_info final : public __shim_type_info {
42public:
43 _LIBCXXABI_HIDDEN ~__function_type_info() final;
44 _LIBCXXABI_HIDDEN bool can_catch(const __shim_type_info*, void*&) const final;
45};
46
47class _LIBCXXABI_TYPE_VIS __enum_type_info final : public __shim_type_info {
48public:
49 _LIBCXXABI_HIDDEN ~__enum_type_info() final;
50 _LIBCXXABI_HIDDEN bool can_catch(const __shim_type_info*, void*&) const final;
51};
52
53enum
54{
55 unknown = 0,
56 public_path,
57 not_public_path,
58 yes,
59 no
60};
61
62class _LIBCXXABI_TYPE_VIS __class_type_info;
63
64struct catch_info {
65 const __class_type_info* static_type;
66
67 // pointer to a dst_type which has (static_ptr, static_type) above it
68 const void* dst_ptr_leading_to_static_ptr;
69 // pointer to a dst_type which does not have (static_ptr, static_type) above it
70 const void* dst_ptr_not_leading_to_static_ptr;
71
72 // The following three paths are either unknown, public_path or not_public_path.
73 // access of path from dst_ptr_leading_to_static_ptr to (static_ptr, static_type)
74 int path_dst_ptr_to_static_ptr;
75
76 // Number of dst_types below (static_ptr, static_type)
77 int number_to_static_ptr;
78
79 // Set whenever a search can be stopped
80 bool search_done;
81
82 // There is no object (seen when we throw a null pointer to object).
83 bool have_object;
84 // Virtual base
85 const void* vbase_cookie;
86};
87
88struct _LIBCXXABI_HIDDEN __dynamic_cast_info
89{
90// const data supplied to the search:
91
92 const __class_type_info* dst_type;
93 const void* static_ptr;
94 const __class_type_info* static_type;
95
96 // Data that represents the answer:
97
98 // pointer to a dst_type which has (static_ptr, static_type) above it
99 const void* dst_ptr_leading_to_static_ptr;
100 // pointer to a dst_type which does not have (static_ptr, static_type) above it
101 const void* dst_ptr_not_leading_to_static_ptr;
102
103 // The following three paths are either unknown, public_path or not_public_path.
104 // access of path from dst_ptr_leading_to_static_ptr to (static_ptr, static_type)
105 int path_dst_ptr_to_static_ptr;
106 // access of path from (dynamic_ptr, dynamic_type) to (static_ptr, static_type)
107 // when there is no dst_type along the path
108 int path_dynamic_ptr_to_static_ptr;
109 // access of path from (dynamic_ptr, dynamic_type) to dst_type
110 // (not used if there is a (static_ptr, static_type) above a dst_type).
111 int path_dynamic_ptr_to_dst_ptr;
112
113 // Number of dst_types below (static_ptr, static_type)
114 int number_to_static_ptr;
115 // Number of dst_types not below (static_ptr, static_type)
116 int number_to_dst_ptr;
117
118// Data that helps stop the search before the entire tree is searched:
119
120 // is_dst_type_derived_from_static_type is either unknown, yes or no.
121 int is_dst_type_derived_from_static_type;
122 // Number of dst_type in tree. If 0, then that means unknown.
123 int number_of_dst_type;
124 // communicates to a dst_type node that (static_ptr, static_type) was found
125 // above it.
126 bool found_our_static_ptr;
127 // communicates to a dst_type node that a static_type was found
128 // above it, but it wasn't (static_ptr, static_type)
129 bool found_any_static_type;
130 // Set whenever a search can be stopped
131 bool search_done;
132};
133
134// Has no base class
135class _LIBCXXABI_TYPE_VIS __class_type_info : public __shim_type_info {
136public:
137 _LIBCXXABI_HIDDEN ~__class_type_info() override;
138
139 _LIBCXXABI_HIDDEN void process_static_type_above_dst(__dynamic_cast_info *,
140 const void *,
141 const void *, int) const;
142 _LIBCXXABI_HIDDEN void process_static_type_below_dst(__dynamic_cast_info *,
143 const void *, int) const;
144 _LIBCXXABI_HIDDEN void process_found_base_class(catch_info*, void*, int) const;
145 _LIBCXXABI_HIDDEN virtual void search_above_dst(__dynamic_cast_info *,
146 const void *, const void *,
147 int, bool) const;
148 _LIBCXXABI_HIDDEN virtual void
149 search_below_dst(__dynamic_cast_info *, const void *, int, bool) const;
150 _LIBCXXABI_HIDDEN bool can_catch(const __shim_type_info*, void*&) const final;
151 _LIBCXXABI_HIDDEN virtual void has_unambiguous_public_base(catch_info*, void*, int) const;
152};
153
154// Has one non-virtual public base class at offset zero
155class _LIBCXXABI_TYPE_VIS __si_class_type_info final : public __class_type_info {
156public:
157 _LIBCXXABI_DISABLE_POINTER_FIELD_PROTECTION const __class_type_info* __base_type;
158
159 _LIBCXXABI_HIDDEN ~__si_class_type_info() final;
160
161 _LIBCXXABI_HIDDEN void search_above_dst(__dynamic_cast_info*, const void*, const void*, int, bool) const final;
162 _LIBCXXABI_HIDDEN void search_below_dst(__dynamic_cast_info*, const void*, int, bool) const final;
163 _LIBCXXABI_HIDDEN void has_unambiguous_public_base(catch_info*, void*, int) const final;
164};
165
166struct _LIBCXXABI_HIDDEN __base_class_type_info
167{
168public:
169 const __class_type_info* __base_type;
170 long __offset_flags;
171
172 enum __offset_flags_masks
173 {
174 __virtual_mask = 0x1,
175 __public_mask = 0x2, // base is public
176 __offset_shift = 8
177 };
178
179 void search_above_dst(__dynamic_cast_info*, const void*, const void*, int, bool) const;
180 void search_below_dst(__dynamic_cast_info*, const void*, int, bool) const;
181 void has_unambiguous_public_base(catch_info*, void*, int) const;
182};
183
184// Has one or more base classes
185class _LIBCXXABI_TYPE_VIS __vmi_class_type_info final : public __class_type_info {
186public:
187 unsigned int __flags;
188 unsigned int __base_count;
189 __base_class_type_info __base_info[1];
190
191 enum __flags_masks {
192 __non_diamond_repeat_mask = 0x1, // has two or more distinct base class
193 // objects of the same type
194 __diamond_shaped_mask = 0x2 // has base class object with two or
195 // more derived objects
196 };
197
198 _LIBCXXABI_HIDDEN ~__vmi_class_type_info() final;
199
200 _LIBCXXABI_HIDDEN void search_above_dst(__dynamic_cast_info*, const void*, const void*, int, bool) const final;
201 _LIBCXXABI_HIDDEN void search_below_dst(__dynamic_cast_info*, const void*, int, bool) const final;
202 _LIBCXXABI_HIDDEN void has_unambiguous_public_base(catch_info*, void*, int) const final;
203};
204
205class _LIBCXXABI_TYPE_VIS __pbase_type_info : public __shim_type_info {
206public:
207 unsigned int __flags;
208 _LIBCXXABI_DISABLE_POINTER_FIELD_PROTECTION const __shim_type_info* __pointee;
209
210 enum __masks {
211 __const_mask = 0x1,
212 __volatile_mask = 0x2,
213 __restrict_mask = 0x4,
214 __incomplete_mask = 0x8,
215 __incomplete_class_mask = 0x10,
216 __transaction_safe_mask = 0x20,
217 // This implements the following proposal from cxx-abi-dev (not yet part of
218 // the ABI document):
219 //
220 // http://sourcerytools.com/pipermail/cxx-abi-dev/2016-October/002986.html
221 //
222 // This is necessary for support of http://wg21.link/p0012, which permits
223 // throwing noexcept function and member function pointers and catching
224 // them as non-noexcept pointers.
225 __noexcept_mask = 0x40,
226
227 // Flags that cannot be removed by a standard conversion.
228 __no_remove_flags_mask = __const_mask | __volatile_mask | __restrict_mask,
229 // Flags that cannot be added by a standard conversion.
230 __no_add_flags_mask = __transaction_safe_mask | __noexcept_mask
231 };
232
233 _LIBCXXABI_HIDDEN ~__pbase_type_info() override;
234 _LIBCXXABI_HIDDEN bool can_catch(const __shim_type_info*, void*&) const override;
235};
236
237class _LIBCXXABI_TYPE_VIS __pointer_type_info final : public __pbase_type_info {
238public:
239 _LIBCXXABI_HIDDEN ~__pointer_type_info() final;
240 _LIBCXXABI_HIDDEN bool can_catch(const __shim_type_info*, void*&) const final;
241 _LIBCXXABI_HIDDEN bool can_catch_nested(const __shim_type_info*) const;
242};
243
244class _LIBCXXABI_TYPE_VIS __pointer_to_member_type_info final : public __pbase_type_info {
245public:
246 _LIBCXXABI_DISABLE_POINTER_FIELD_PROTECTION const __class_type_info* __context;
247
248 _LIBCXXABI_HIDDEN ~__pointer_to_member_type_info() final;
249 _LIBCXXABI_HIDDEN bool can_catch(const __shim_type_info*, void*&) const final;
250 _LIBCXXABI_HIDDEN bool can_catch_nested(const __shim_type_info*) const;
251};
252
253} // __cxxabiv1
254
255#endif // __PRIVATE_TYPEINFO_H_
256