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