| 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 230000 |
| 23 | #define _LIBCXXABI_ALWAYS_COLD __attribute__((cold)) |
| 24 | |
| 25 | #ifdef __cplusplus |
| 26 | |
| 27 | namespace std { |
| 28 | #if defined(_WIN32) |
| 29 | class _LIBCXXABI_TYPE_VIS type_info; // forward declaration |
| 30 | #else |
| 31 | class type_info; // forward declaration |
| 32 | #endif |
| 33 | } // namespace std |
| 34 | |
| 35 | |
| 36 | // runtime routines use C calling conventions, but are in __cxxabiv1 namespace |
| 37 | namespace __cxxabiv1 { |
| 38 | |
| 39 | struct __cxa_exception; |
| 40 | |
| 41 | extern "C" { |
| 42 | |
| 43 | // 2.4.2 Allocating the Exception Object |
| 44 | extern _LIBCXXABI_FUNC_VIS void * |
| 45 | __cxa_allocate_exception(size_t thrown_size) _LIBCXXABI_NOEXCEPT; |
| 46 | extern _LIBCXXABI_FUNC_VIS void |
| 47 | __cxa_free_exception(void *thrown_exception) _LIBCXXABI_NOEXCEPT; |
| 48 | // This function is an LLVM extension, which mirrors the same extension in libsupc++ and libcxxrt |
| 49 | extern _LIBCXXABI_FUNC_VIS __cxa_exception* |
| 50 | #ifdef __wasm__ |
| 51 | // In Wasm, a destructor returns its argument |
| 52 | __cxa_init_primary_exception(void* object, std::type_info* tinfo, void*(_LIBCXXABI_DTOR_FUNC* dest)(void*)) _LIBCXXABI_NOEXCEPT; |
| 53 | #else |
| 54 | __cxa_init_primary_exception(void* object, std::type_info* tinfo, void(_LIBCXXABI_DTOR_FUNC* dest)(void*)) _LIBCXXABI_NOEXCEPT; |
| 55 | #endif |
| 56 | |
| 57 | // 2.4.3 Throwing the Exception Object |
| 58 | [[__noreturn__]] extern _LIBCXXABI_FUNC_VIS void |
| 59 | __cxa_throw(void *thrown_exception, std::type_info *tinfo, |
| 60 | #ifdef __wasm__ |
| 61 | void *(_LIBCXXABI_DTOR_FUNC *dest)(void *)); |
| 62 | #else |
| 63 | void (_LIBCXXABI_DTOR_FUNC *dest)(void *)); |
| 64 | #endif |
| 65 | |
| 66 | // 2.5.3 Exception Handlers |
| 67 | extern _LIBCXXABI_FUNC_VIS void * |
| 68 | __cxa_get_exception_ptr(void *exceptionObject) _LIBCXXABI_NOEXCEPT; |
| 69 | extern _LIBCXXABI_FUNC_VIS void * |
| 70 | __cxa_begin_catch(void *exceptionObject) _LIBCXXABI_NOEXCEPT; |
| 71 | extern _LIBCXXABI_FUNC_VIS void __cxa_end_catch(); |
| 72 | #if defined(_LIBCXXABI_ARM_EHABI) |
| 73 | extern _LIBCXXABI_FUNC_VIS bool |
| 74 | __cxa_begin_cleanup(void *exceptionObject) _LIBCXXABI_NOEXCEPT; |
| 75 | extern _LIBCXXABI_FUNC_VIS void __cxa_end_cleanup(); |
| 76 | #endif |
| 77 | extern _LIBCXXABI_FUNC_VIS std::type_info *__cxa_current_exception_type(); |
| 78 | |
| 79 | // GNU extension |
| 80 | // Calls `terminate` with the current exception being caught. This function is used by GCC when a `noexcept` function |
| 81 | // throws an exception inside a try/catch block and doesn't catch it. |
| 82 | [[__noreturn__]] extern _LIBCXXABI_FUNC_VIS void __cxa_call_terminate(void*) _LIBCXXABI_NOEXCEPT; |
| 83 | |
| 84 | // 2.5.4 Rethrowing Exceptions |
| 85 | [[__noreturn__]] extern _LIBCXXABI_FUNC_VIS void __cxa_rethrow(); |
| 86 | |
| 87 | // 2.6 Auxiliary Runtime APIs |
| 88 | [[__noreturn__]] extern _LIBCXXABI_FUNC_VIS void __cxa_bad_cast(void); |
| 89 | [[__noreturn__]] extern _LIBCXXABI_FUNC_VIS void __cxa_bad_typeid(void); |
| 90 | [[__noreturn__]] extern _LIBCXXABI_FUNC_VIS void |
| 91 | __cxa_throw_bad_array_new_length(void); |
| 92 | |
| 93 | // 3.2.6 Pure Virtual Function API |
| 94 | [[__noreturn__]] extern _LIBCXXABI_FUNC_VIS void __cxa_pure_virtual(void); |
| 95 | |
| 96 | // 3.2.7 Deleted Virtual Function API |
| 97 | [[__noreturn__]] extern _LIBCXXABI_FUNC_VIS void __cxa_deleted_virtual(void); |
| 98 | |
| 99 | // 3.3.2 One-time Construction API |
| 100 | #if defined(_LIBCXXABI_GUARD_ABI_ARM) |
| 101 | extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_ALWAYS_COLD int __cxa_guard_acquire(uint32_t *); |
| 102 | extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_ALWAYS_COLD void __cxa_guard_release(uint32_t *); |
| 103 | extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_ALWAYS_COLD void __cxa_guard_abort(uint32_t *); |
| 104 | #else |
| 105 | extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_ALWAYS_COLD int __cxa_guard_acquire(uint64_t *); |
| 106 | extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_ALWAYS_COLD void __cxa_guard_release(uint64_t *); |
| 107 | extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_ALWAYS_COLD void __cxa_guard_abort(uint64_t *); |
| 108 | #endif |
| 109 | |
| 110 | // 3.3.3 Array Construction and Destruction API |
| 111 | extern _LIBCXXABI_FUNC_VIS void * |
| 112 | __cxa_vec_new(size_t element_count, size_t element_size, size_t padding_size, |
| 113 | void (*constructor)(void *), void (*destructor)(void *)); |
| 114 | |
| 115 | extern _LIBCXXABI_FUNC_VIS void * |
| 116 | __cxa_vec_new2(size_t element_count, size_t element_size, size_t padding_size, |
| 117 | void (*constructor)(void *), void (*destructor)(void *), |
| 118 | void *(*alloc)(size_t), void (*dealloc)(void *)); |
| 119 | |
| 120 | extern _LIBCXXABI_FUNC_VIS void * |
| 121 | __cxa_vec_new3(size_t element_count, size_t element_size, size_t padding_size, |
| 122 | void (*constructor)(void *), void (*destructor)(void *), |
| 123 | void *(*alloc)(size_t), void (*dealloc)(void *, size_t)); |
| 124 | |
| 125 | extern _LIBCXXABI_FUNC_VIS void |
| 126 | __cxa_vec_ctor(void *array_address, size_t element_count, size_t element_size, |
| 127 | void (*constructor)(void *), void (*destructor)(void *)); |
| 128 | |
| 129 | extern _LIBCXXABI_FUNC_VIS void __cxa_vec_dtor(void *array_address, |
| 130 | size_t element_count, |
| 131 | size_t element_size, |
| 132 | void (*destructor)(void *)); |
| 133 | |
| 134 | extern _LIBCXXABI_FUNC_VIS void __cxa_vec_cleanup(void *array_address, |
| 135 | size_t element_count, |
| 136 | size_t element_size, |
| 137 | void (*destructor)(void *)); |
| 138 | |
| 139 | extern _LIBCXXABI_FUNC_VIS void __cxa_vec_delete(void *array_address, |
| 140 | size_t element_size, |
| 141 | size_t padding_size, |
| 142 | void (*destructor)(void *)); |
| 143 | |
| 144 | extern _LIBCXXABI_FUNC_VIS void |
| 145 | __cxa_vec_delete2(void *array_address, size_t element_size, size_t padding_size, |
| 146 | void (*destructor)(void *), void (*dealloc)(void *)); |
| 147 | |
| 148 | extern _LIBCXXABI_FUNC_VIS void |
| 149 | __cxa_vec_delete3(void *__array_address, size_t element_size, |
| 150 | size_t padding_size, void (*destructor)(void *), |
| 151 | void (*dealloc)(void *, size_t)); |
| 152 | |
| 153 | extern _LIBCXXABI_FUNC_VIS void |
| 154 | __cxa_vec_cctor(void *dest_array, void *src_array, size_t element_count, |
| 155 | size_t element_size, void (*constructor)(void *, void *), |
| 156 | void (*destructor)(void *)); |
| 157 | |
| 158 | // 3.3.5.3 Runtime API |
| 159 | // These functions are part of the C++ ABI, but they are not defined in libc++abi: |
| 160 | // int __cxa_atexit(void (*)(void *), void *, void *); |
| 161 | // void __cxa_finalize(void *); |
| 162 | |
| 163 | // 3.4 Demangler API |
| 164 | extern _LIBCXXABI_FUNC_VIS char *__cxa_demangle(const char *mangled_name, |
| 165 | char *output_buffer, |
| 166 | size_t *length, int *status); |
| 167 | |
| 168 | // Apple additions to support C++ 0x exception_ptr class |
| 169 | // These are primitives to wrap a smart pointer around an exception object |
| 170 | extern _LIBCXXABI_FUNC_VIS void *__cxa_current_primary_exception() _LIBCXXABI_NOEXCEPT; |
| 171 | extern _LIBCXXABI_FUNC_VIS void |
| 172 | __cxa_rethrow_primary_exception(void *primary_exception); |
| 173 | extern _LIBCXXABI_FUNC_VIS void |
| 174 | __cxa_increment_exception_refcount(void *primary_exception) _LIBCXXABI_NOEXCEPT; |
| 175 | extern _LIBCXXABI_FUNC_VIS void |
| 176 | __cxa_decrement_exception_refcount(void *primary_exception) _LIBCXXABI_NOEXCEPT; |
| 177 | |
| 178 | // Apple extension to support std::uncaught_exception() |
| 179 | extern _LIBCXXABI_FUNC_VIS bool __cxa_uncaught_exception() _LIBCXXABI_NOEXCEPT; |
| 180 | extern _LIBCXXABI_FUNC_VIS unsigned int __cxa_uncaught_exceptions() _LIBCXXABI_NOEXCEPT; |
| 181 | |
| 182 | #if defined(__linux__) || defined(__Fuchsia__) |
| 183 | // Linux and Fuchsia TLS support. Not yet an official part of the Itanium ABI. |
| 184 | // https://sourceware.org/glibc/wiki/Destructor%20support%20for%20thread_local%20variables |
| 185 | extern _LIBCXXABI_FUNC_VIS int __cxa_thread_atexit(void (*)(void *), void *, |
| 186 | void *) _LIBCXXABI_NOEXCEPT; |
| 187 | #endif |
| 188 | |
| 189 | } // extern "C" |
| 190 | } // namespace __cxxabiv1 |
| 191 | |
| 192 | namespace abi = __cxxabiv1; |
| 193 | |
| 194 | #endif // __cplusplus |
| 195 | |
| 196 | #endif // __CXXABI_H |
| 197 | |