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 __CXXABI_H
10#define __CXXABI_H
11
12/*
13 * This header provides the interface to the C++ ABI as defined at:
14 *       https://itanium-cxx-abi.github.io/cxx-abi/
15 */
16
17#include <stddef.h>
18#include <stdint.h>
19
20#include <__cxxabi_config.h>
21
22#define _LIBCPPABI_VERSION 15000
23#define _LIBCXXABI_NORETURN  __attribute__((noreturn))
24#define _LIBCXXABI_ALWAYS_COLD __attribute__((cold))
25
26#ifdef __cplusplus
27
28namespace std {
29#if defined(_WIN32)
30class _LIBCXXABI_TYPE_VIS type_info; // forward declaration
31#else
32class type_info; // forward declaration
33#endif
34}
35
36
37// runtime routines use C calling conventions, but are in __cxxabiv1 namespace
38namespace __cxxabiv1 {
39extern "C"  {
40
41// 2.4.2 Allocating the Exception Object
42extern _LIBCXXABI_FUNC_VIS void *
43__cxa_allocate_exception(size_t thrown_size) throw();
44extern _LIBCXXABI_FUNC_VIS void
45__cxa_free_exception(void *thrown_exception) throw();
46
47// 2.4.3 Throwing the Exception Object
48extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_NORETURN void
49__cxa_throw(void *thrown_exception, std::type_info *tinfo,
50            void (_LIBCXXABI_DTOR_FUNC *dest)(void *));
51
52// 2.5.3 Exception Handlers
53extern _LIBCXXABI_FUNC_VIS void *
54__cxa_get_exception_ptr(void *exceptionObject) throw();
55extern _LIBCXXABI_FUNC_VIS void *
56__cxa_begin_catch(void *exceptionObject) throw();
57extern _LIBCXXABI_FUNC_VIS void __cxa_end_catch();
58#if defined(_LIBCXXABI_ARM_EHABI)
59extern _LIBCXXABI_FUNC_VIS bool
60__cxa_begin_cleanup(void *exceptionObject) throw();
61extern _LIBCXXABI_FUNC_VIS void __cxa_end_cleanup();
62#endif
63extern _LIBCXXABI_FUNC_VIS std::type_info *__cxa_current_exception_type();
64
65// 2.5.4 Rethrowing Exceptions
66extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_NORETURN void __cxa_rethrow();
67
68// 2.6 Auxiliary Runtime APIs
69extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_NORETURN void __cxa_bad_cast(void);
70extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_NORETURN void __cxa_bad_typeid(void);
71extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_NORETURN void
72__cxa_throw_bad_array_new_length(void);
73
74// 3.2.6 Pure Virtual Function API
75extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_NORETURN void __cxa_pure_virtual(void);
76
77// 3.2.7 Deleted Virtual Function API
78extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_NORETURN void __cxa_deleted_virtual(void);
79
80// 3.3.2 One-time Construction API
81#if defined(_LIBCXXABI_GUARD_ABI_ARM)
82extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_ALWAYS_COLD int __cxa_guard_acquire(uint32_t *);
83extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_ALWAYS_COLD void __cxa_guard_release(uint32_t *);
84extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_ALWAYS_COLD void __cxa_guard_abort(uint32_t *);
85#else
86extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_ALWAYS_COLD int __cxa_guard_acquire(uint64_t *);
87extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_ALWAYS_COLD void __cxa_guard_release(uint64_t *);
88extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_ALWAYS_COLD void __cxa_guard_abort(uint64_t *);
89#endif
90
91// 3.3.3 Array Construction and Destruction API
92extern _LIBCXXABI_FUNC_VIS void *
93__cxa_vec_new(size_t element_count, size_t element_size, size_t padding_size,
94              void (*constructor)(void *), void (*destructor)(void *));
95
96extern _LIBCXXABI_FUNC_VIS void *
97__cxa_vec_new2(size_t element_count, size_t element_size, size_t padding_size,
98               void (*constructor)(void *), void (*destructor)(void *),
99               void *(*alloc)(size_t), void (*dealloc)(void *));
100
101extern _LIBCXXABI_FUNC_VIS void *
102__cxa_vec_new3(size_t element_count, size_t element_size, size_t padding_size,
103               void (*constructor)(void *), void (*destructor)(void *),
104               void *(*alloc)(size_t), void (*dealloc)(void *, size_t));
105
106extern _LIBCXXABI_FUNC_VIS void
107__cxa_vec_ctor(void *array_address, size_t element_count, size_t element_size,
108               void (*constructor)(void *), void (*destructor)(void *));
109
110extern _LIBCXXABI_FUNC_VIS void __cxa_vec_dtor(void *array_address,
111                                               size_t element_count,
112                                               size_t element_size,
113                                               void (*destructor)(void *));
114
115extern _LIBCXXABI_FUNC_VIS void __cxa_vec_cleanup(void *array_address,
116                                                  size_t element_count,
117                                                  size_t element_size,
118                                                  void (*destructor)(void *));
119
120extern _LIBCXXABI_FUNC_VIS void __cxa_vec_delete(void *array_address,
121                                                 size_t element_size,
122                                                 size_t padding_size,
123                                                 void (*destructor)(void *));
124
125extern _LIBCXXABI_FUNC_VIS void
126__cxa_vec_delete2(void *array_address, size_t element_size, size_t padding_size,
127                  void (*destructor)(void *), void (*dealloc)(void *));
128
129extern _LIBCXXABI_FUNC_VIS void
130__cxa_vec_delete3(void *__array_address, size_t element_size,
131                  size_t padding_size, void (*destructor)(void *),
132                  void (*dealloc)(void *, size_t));
133
134extern _LIBCXXABI_FUNC_VIS void
135__cxa_vec_cctor(void *dest_array, void *src_array, size_t element_count,
136                size_t element_size, void (*constructor)(void *, void *),
137                void (*destructor)(void *));
138
139// 3.3.5.3 Runtime API
140// These functions are part of the C++ ABI, but they are not defined in libc++abi:
141//    int __cxa_atexit(void (*)(void *), void *, void *);
142//    void __cxa_finalize(void *);
143
144// 3.4 Demangler API
145extern _LIBCXXABI_FUNC_VIS char *__cxa_demangle(const char *mangled_name,
146                                                char *output_buffer,
147                                                size_t *length, int *status);
148
149// Apple additions to support C++ 0x exception_ptr class
150// These are primitives to wrap a smart pointer around an exception object
151extern _LIBCXXABI_FUNC_VIS void *__cxa_current_primary_exception() throw();
152extern _LIBCXXABI_FUNC_VIS void
153__cxa_rethrow_primary_exception(void *primary_exception);
154extern _LIBCXXABI_FUNC_VIS void
155__cxa_increment_exception_refcount(void *primary_exception) throw();
156extern _LIBCXXABI_FUNC_VIS void
157__cxa_decrement_exception_refcount(void *primary_exception) throw();
158
159// Apple extension to support std::uncaught_exception()
160extern _LIBCXXABI_FUNC_VIS bool __cxa_uncaught_exception() throw();
161extern _LIBCXXABI_FUNC_VIS unsigned int __cxa_uncaught_exceptions() throw();
162
163#if defined(__linux__) || defined(__Fuchsia__)
164// Linux and Fuchsia TLS support. Not yet an official part of the Itanium ABI.
165// https://sourceware.org/glibc/wiki/Destructor%20support%20for%20thread_local%20variables
166extern _LIBCXXABI_FUNC_VIS int __cxa_thread_atexit(void (*)(void *), void *,
167                                                   void *) throw();
168#endif
169
170} // extern "C"
171} // namespace __cxxabiv1
172
173namespace abi = __cxxabiv1;
174
175#endif // __cplusplus
176
177#endif // __CXXABI_H
178