]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/libsupc++/cxxabi-internal.h
re PR other/28145 (C++ (throw() and catch(...) {/* fall through */ } ) and pthread...
[thirdparty/gcc.git] / libstdc++-v3 / libsupc++ / cxxabi-internal.h
1 // new abi support -*- C++ -*-
2
3 // Copyright (C) 2000, 2002, 2003, 2004, 2006 Free Software Foundation, Inc.
4 //
5 // This file is part of GCC.
6 //
7 // GCC is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation; either version 2, or (at your option)
10 // any later version.
11 //
12 // GCC is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with GCC; see the file COPYING. If not, write to
19 // the Free Software Foundation, 51 Franklin Street, Fifth Floor,
20 // Boston, MA 02110-1301, USA.
21
22 // As a special exception, you may use this file as part of a free software
23 // library without restriction. Specifically, if other files instantiate
24 // templates or use macros or inline functions from this file, or you compile
25 // this file and link it with other files to produce an executable, this
26 // file does not by itself cause the resulting executable to be covered by
27 // the GNU General Public License. This exception does not however
28 // invalidate any other reasons why the executable file might be covered by
29 // the GNU General Public License.
30
31 // Written by Nathan Sidwell, Codesourcery LLC, <nathan@codesourcery.com>
32
33 /* This file declares the new abi entry points into the runtime. It is not
34 normally necessary for user programs to include this header, or use the
35 entry points directly. However, this header is available should that be
36 needed.
37
38 Some of the entry points are intended for both C and C++, thus this header
39 is includable from both C and C++. Though the C++ specific parts are not
40 available in C, naturally enough. */
41
42 /** @file cxxabi.h
43 * The header provides an interface to the C++ ABI.
44 */
45
46 #ifndef _CXXABI_INTERNAL_H
47 #define _CXXABI_INTERNAL_H 1
48
49 #pragma GCC visibility push(default)
50
51 #include <stddef.h>
52 #include <bits/cxxabi_tweaks.h>
53
54 #ifdef __cplusplus
55 namespace __cxxabiv1
56 {
57 extern "C"
58 {
59 #endif
60
61 typedef __cxa_cdtor_return_type (*__cxa_cdtor_type)(void *);
62
63 // Allocate array.
64 void*
65 __cxa_vec_new(size_t __element_count, size_t __element_size,
66 size_t __padding_size, __cxa_cdtor_type constructor,
67 __cxa_cdtor_type destructor);
68
69 void*
70 __cxa_vec_new2(size_t __element_count, size_t __element_size,
71 size_t __padding_size, __cxa_cdtor_type constructor,
72 __cxa_cdtor_type destructor, void *(*__alloc) (size_t),
73 void (*__dealloc) (void*));
74
75 void*
76 __cxa_vec_new3(size_t __element_count, size_t __element_size,
77 size_t __padding_size, __cxa_cdtor_type constructor,
78 __cxa_cdtor_type destructor, void *(*__alloc) (size_t),
79 void (*__dealloc) (void*, size_t));
80
81 // Construct array.
82 __cxa_vec_ctor_return_type
83 __cxa_vec_ctor(void* __array_address, size_t __element_count,
84 size_t __element_size, __cxa_cdtor_type constructor,
85 __cxa_cdtor_type destructor);
86
87 __cxa_vec_ctor_return_type
88 __cxa_vec_cctor(void* dest_array, void* src_array, size_t element_count,
89 size_t element_size,
90 __cxa_cdtor_return_type (*constructor) (void*, void*),
91 __cxa_cdtor_type destructor);
92
93 // Destruct array.
94 void
95 __cxa_vec_dtor(void* __array_address, size_t __element_count,
96 size_t __element_size, __cxa_cdtor_type destructor);
97
98 void
99 __cxa_vec_cleanup(void* __array_address, size_t __element_count,
100 size_t __element_size, __cxa_cdtor_type destructor);
101
102 // Destruct and release array.
103 void
104 __cxa_vec_delete(void* __array_address, size_t __element_size,
105 size_t __padding_size, __cxa_cdtor_type destructor);
106
107 void
108 __cxa_vec_delete2(void* __array_address, size_t __element_size,
109 size_t __padding_size, __cxa_cdtor_type destructor,
110 void (*__dealloc) (void*));
111
112 void
113 __cxa_vec_delete3(void* __array_address, size_t __element_size,
114 size_t __padding_size, __cxa_cdtor_type destructor,
115 void (*__dealloc) (void*, size_t));
116
117 int
118 __cxa_guard_acquire(__guard*);
119
120 void
121 __cxa_guard_release(__guard*);
122
123 void
124 __cxa_guard_abort(__guard*);
125
126 // Pure virtual functions.
127 void
128 __cxa_pure_virtual(void);
129
130 // Exception handling.
131 void
132 __cxa_bad_cast();
133
134 void
135 __cxa_bad_typeid();
136
137 // DSO destruction.
138 int
139 __cxa_atexit(void (*)(void*), void*, void*)
140 #ifdef __cplusplus
141 throw ()
142 #endif
143 ;
144
145 int
146 __cxa_finalize(void*);
147
148 // Demangling routines.
149 char*
150 __cxa_demangle(const char* __mangled_name, char* __output_buffer,
151 size_t* __length, int* __status);
152 #ifdef __cplusplus
153 }
154 } // namespace __cxxabiv1
155 #endif
156
157 #ifdef __cplusplus
158
159 #include <typeinfo>
160
161 namespace __cxxabiv1
162 {
163 // Type information for int, float etc.
164 class __fundamental_type_info : public std::type_info
165 {
166 public:
167 explicit
168 __fundamental_type_info(const char* __n) : std::type_info(__n) { }
169
170 virtual
171 ~__fundamental_type_info();
172 };
173
174 // Type information for array objects.
175 class __array_type_info : public std::type_info
176 {
177 public:
178 explicit
179 __array_type_info(const char* __n) : std::type_info(__n) { }
180
181 virtual
182 ~__array_type_info();
183 };
184
185 // Type information for functions (both member and non-member).
186 class __function_type_info : public std::type_info
187 {
188 public:
189 explicit
190 __function_type_info(const char* __n) : std::type_info(__n) { }
191
192 virtual
193 ~__function_type_info();
194
195 protected:
196 // Implementation defined member function.
197 virtual bool
198 __is_function_p() const;
199 };
200
201 // Type information for enumerations.
202 class __enum_type_info : public std::type_info
203 {
204 public:
205 explicit
206 __enum_type_info(const char* __n) : std::type_info(__n) { }
207
208 virtual
209 ~__enum_type_info();
210 };
211
212 // Common type information for simple pointers and pointers to member.
213 class __pbase_type_info : public std::type_info
214 {
215 public:
216 unsigned int __flags; // Qualification of the target object.
217 const std::type_info* __pointee; // Type of pointed to object.
218
219 explicit
220 __pbase_type_info(const char* __n, int __quals,
221 const std::type_info* __type)
222 : std::type_info(__n), __flags(__quals), __pointee(__type)
223 { }
224
225 virtual
226 ~__pbase_type_info();
227
228 // Implementation defined type.
229 enum __masks
230 {
231 __const_mask = 0x1,
232 __volatile_mask = 0x2,
233 __restrict_mask = 0x4,
234 __incomplete_mask = 0x8,
235 __incomplete_class_mask = 0x10
236 };
237
238 protected:
239 __pbase_type_info(const __pbase_type_info&);
240
241 __pbase_type_info&
242 operator=(const __pbase_type_info&);
243
244 // Implementation defined member functions.
245 virtual bool
246 __do_catch(const std::type_info* __thr_type, void** __thr_obj,
247 unsigned int __outer) const;
248
249 inline virtual bool
250 __pointer_catch(const __pbase_type_info* __thr_type, void** __thr_obj,
251 unsigned __outer) const;
252 };
253
254 // Type information for simple pointers.
255 class __pointer_type_info : public __pbase_type_info
256 {
257 public:
258 explicit
259 __pointer_type_info(const char* __n, int __quals,
260 const std::type_info* __type)
261 : __pbase_type_info (__n, __quals, __type) { }
262
263
264 virtual
265 ~__pointer_type_info();
266
267 protected:
268 // Implementation defined member functions.
269 virtual bool
270 __is_pointer_p() const;
271
272 virtual bool
273 __pointer_catch(const __pbase_type_info* __thr_type, void** __thr_obj,
274 unsigned __outer) const;
275 };
276
277 class __class_type_info;
278
279 // Type information for a pointer to member variable.
280 class __pointer_to_member_type_info : public __pbase_type_info
281 {
282 public:
283 __class_type_info* __context; // Class of the member.
284
285 explicit
286 __pointer_to_member_type_info(const char* __n, int __quals,
287 const std::type_info* __type,
288 __class_type_info* __klass)
289 : __pbase_type_info(__n, __quals, __type), __context(__klass) { }
290
291 virtual
292 ~__pointer_to_member_type_info();
293
294 protected:
295 __pointer_to_member_type_info(const __pointer_to_member_type_info&);
296
297 __pointer_to_member_type_info&
298 operator=(const __pointer_to_member_type_info&);
299
300 // Implementation defined member function.
301 virtual bool
302 __pointer_catch(const __pbase_type_info* __thr_type, void** __thr_obj,
303 unsigned __outer) const;
304 };
305
306 // Helper class for __vmi_class_type.
307 class __base_class_type_info
308 {
309 public:
310 const __class_type_info* __base_type; // Base class type.
311 long __offset_flags; // Offset and info.
312
313 enum __offset_flags_masks
314 {
315 __virtual_mask = 0x1,
316 __public_mask = 0x2,
317 __hwm_bit = 2,
318 __offset_shift = 8 // Bits to shift offset.
319 };
320
321 // Implementation defined member functions.
322 bool
323 __is_virtual_p() const
324 { return __offset_flags & __virtual_mask; }
325
326 bool
327 __is_public_p() const
328 { return __offset_flags & __public_mask; }
329
330 ptrdiff_t
331 __offset() const
332 {
333 // This shift, being of a signed type, is implementation
334 // defined. GCC implements such shifts as arithmetic, which is
335 // what we want.
336 return static_cast<ptrdiff_t>(__offset_flags) >> __offset_shift;
337 }
338 };
339
340 // Type information for a class.
341 class __class_type_info : public std::type_info
342 {
343 public:
344 explicit
345 __class_type_info (const char *__n) : type_info(__n) { }
346
347 virtual
348 ~__class_type_info ();
349
350 // Implementation defined types.
351 // The type sub_kind tells us about how a base object is contained
352 // within a derived object. We often do this lazily, hence the
353 // UNKNOWN value. At other times we may use NOT_CONTAINED to mean
354 // not publicly contained.
355 enum __sub_kind
356 {
357 // We have no idea.
358 __unknown = 0,
359
360 // Not contained within us (in some circumstances this might
361 // mean not contained publicly)
362 __not_contained,
363
364 // Contained ambiguously.
365 __contained_ambig,
366
367 // Via a virtual path.
368 __contained_virtual_mask = __base_class_type_info::__virtual_mask,
369
370 // Via a public path.
371 __contained_public_mask = __base_class_type_info::__public_mask,
372
373 // Contained within us.
374 __contained_mask = 1 << __base_class_type_info::__hwm_bit,
375
376 __contained_private = __contained_mask,
377 __contained_public = __contained_mask | __contained_public_mask
378 };
379
380 struct __upcast_result;
381 struct __dyncast_result;
382
383 protected:
384 // Implementation defined member functions.
385 virtual bool
386 __do_upcast(const __class_type_info* __dst_type, void**__obj_ptr) const;
387
388 virtual bool
389 __do_catch(const type_info* __thr_type, void** __thr_obj,
390 unsigned __outer) const;
391
392 public:
393 // Helper for upcast. See if DST is us, or one of our bases.
394 // Return false if not found, true if found.
395 virtual bool
396 __do_upcast(const __class_type_info* __dst, const void* __obj,
397 __upcast_result& __restrict __result) const;
398
399 // Indicate whether SRC_PTR of type SRC_TYPE is contained publicly
400 // within OBJ_PTR. OBJ_PTR points to a base object of our type,
401 // which is the destination type. SRC2DST indicates how SRC
402 // objects might be contained within this type. If SRC_PTR is one
403 // of our SRC_TYPE bases, indicate the virtuality. Returns
404 // not_contained for non containment or private containment.
405 inline __sub_kind
406 __find_public_src(ptrdiff_t __src2dst, const void* __obj_ptr,
407 const __class_type_info* __src_type,
408 const void* __src_ptr) const;
409
410 // Helper for dynamic cast. ACCESS_PATH gives the access from the
411 // most derived object to this base. DST_TYPE indicates the
412 // desired type we want. OBJ_PTR points to a base of our type
413 // within the complete object. SRC_TYPE indicates the static type
414 // started from and SRC_PTR points to that base within the most
415 // derived object. Fill in RESULT with what we find. Return true
416 // if we have located an ambiguous match.
417 virtual bool
418 __do_dyncast(ptrdiff_t __src2dst, __sub_kind __access_path,
419 const __class_type_info* __dst_type, const void* __obj_ptr,
420 const __class_type_info* __src_type, const void* __src_ptr,
421 __dyncast_result& __result) const;
422
423 // Helper for find_public_subobj. SRC2DST indicates how SRC_TYPE
424 // bases are inherited by the type started from -- which is not
425 // necessarily the current type. The current type will be a base
426 // of the destination type. OBJ_PTR points to the current base.
427 virtual __sub_kind
428 __do_find_public_src(ptrdiff_t __src2dst, const void* __obj_ptr,
429 const __class_type_info* __src_type,
430 const void* __src_ptr) const;
431 };
432
433 // Type information for a class with a single non-virtual base.
434 class __si_class_type_info : public __class_type_info
435 {
436 public:
437 const __class_type_info* __base_type;
438
439 explicit
440 __si_class_type_info(const char *__n, const __class_type_info *__base)
441 : __class_type_info(__n), __base_type(__base) { }
442
443 virtual
444 ~__si_class_type_info();
445
446 protected:
447 __si_class_type_info(const __si_class_type_info&);
448
449 __si_class_type_info&
450 operator=(const __si_class_type_info&);
451
452 // Implementation defined member functions.
453 virtual bool
454 __do_dyncast(ptrdiff_t __src2dst, __sub_kind __access_path,
455 const __class_type_info* __dst_type, const void* __obj_ptr,
456 const __class_type_info* __src_type, const void* __src_ptr,
457 __dyncast_result& __result) const;
458
459 virtual __sub_kind
460 __do_find_public_src(ptrdiff_t __src2dst, const void* __obj_ptr,
461 const __class_type_info* __src_type,
462 const void* __sub_ptr) const;
463
464 virtual bool
465 __do_upcast(const __class_type_info*__dst, const void*__obj,
466 __upcast_result& __restrict __result) const;
467 };
468
469 // Type information for a class with multiple and/or virtual bases.
470 class __vmi_class_type_info : public __class_type_info
471 {
472 public:
473 unsigned int __flags; // Details about the class hierarchy.
474 unsigned int __base_count; // Number of direct bases.
475
476 // The array of bases uses the trailing array struct hack so this
477 // class is not constructable with a normal constructor. It is
478 // internally generated by the compiler.
479 __base_class_type_info __base_info[1]; // Array of bases.
480
481 explicit
482 __vmi_class_type_info(const char* __n, int ___flags)
483 : __class_type_info(__n), __flags(___flags), __base_count(0) { }
484
485 virtual
486 ~__vmi_class_type_info();
487
488 // Implementation defined types.
489 enum __flags_masks
490 {
491 __non_diamond_repeat_mask = 0x1, // Distinct instance of repeated base.
492 __diamond_shaped_mask = 0x2, // Diamond shaped multiple inheritance.
493 __flags_unknown_mask = 0x10
494 };
495
496 protected:
497 // Implementation defined member functions.
498 virtual bool
499 __do_dyncast(ptrdiff_t __src2dst, __sub_kind __access_path,
500 const __class_type_info* __dst_type, const void* __obj_ptr,
501 const __class_type_info* __src_type, const void* __src_ptr,
502 __dyncast_result& __result) const;
503
504 virtual __sub_kind
505 __do_find_public_src(ptrdiff_t __src2dst, const void* __obj_ptr,
506 const __class_type_info* __src_type,
507 const void* __src_ptr) const;
508
509 virtual bool
510 __do_upcast(const __class_type_info* __dst, const void* __obj,
511 __upcast_result& __restrict __result) const;
512 };
513
514 // Dynamic cast runtime.
515 // src2dst has the following possible values
516 // >-1: src_type is a unique public non-virtual base of dst_type
517 // dst_ptr + src2dst == src_ptr
518 // -1: unspecified relationship
519 // -2: src_type is not a public base of dst_type
520 // -3: src_type is a multiple public non-virtual base of dst_type
521 extern "C" void*
522 __dynamic_cast(const void* __src_ptr, // Starting object.
523 const __class_type_info* __src_type, // Static type of object.
524 const __class_type_info* __dst_type, // Desired target type.
525 ptrdiff_t __src2dst); // How src and dst are related.
526
527
528 // Returns the type_info for the currently handled exception [15.3/8], or
529 // null if there is none.
530 extern "C" std::type_info*
531 __cxa_current_exception_type();
532
533 // A magic placeholder class that can be caught by reference
534 // to recognize forced unwinding.
535 class __forced_unwind
536 {
537 virtual ~__forced_unwind() throw();
538 virtual void __pure() = 0; // prevent catch by value
539 };
540
541 // A magic placeholder class that can be caught by reference
542 // to recognize foreign exceptions.
543 class __foreign_exception
544 {
545 virtual ~__foreign_exception() throw();
546 virtual void __pure() = 0; // prevent catch by value
547 };
548
549 } // namespace __cxxabiv1
550
551 #endif // __cplusplus
552
553 #pragma GCC visibility pop
554
555 #endif // __CXXABI_INTERNAL_H