| author | |
| committer | |
| log | 42da1d385de8559710e04b5a05234f2dd8bb347e |
| tree | 8f354c4dd008700e8ebfd367b25842addb25ae1a |
| parent | 54b67c20259f697f1e0c4532a5ee7e5d3f01eb1e |
11 files changed, 404 insertions(+), 132 deletions(-)
lib/libcxxabi/include/__cxxabi_config.h+8| ... | ... | @@ -76,4 +76,12 @@ |
| 76 | 76 | # define _LIBCXXABI_GUARD_ABI_ARM |
| 77 | 77 | #endif |
| 78 | 78 | |
| 79 | #if defined(_LIBCXXABI_COMPILER_CLANG) | |
| 80 | # if !__has_feature(cxx_exceptions) | |
| 81 | # define _LIBCXXABI_NO_EXCEPTIONS | |
| 82 | # endif | |
| 83 | #elif defined(_LIBCXXABI_COMPILER_GCC) && !__EXCEPTIONS | |
| 84 | # define _LIBCXXABI_NO_EXCEPTIONS | |
| 85 | #endif | |
| 86 | ||
| 79 | 87 | #endif // ____CXXABI_CONFIG_H |
lib/libcxxabi/src/abort_message.cpp+34-32| ... | ... | @@ -12,52 +12,54 @@ |
| 12 | 12 | #include "abort_message.h" |
| 13 | 13 | |
| 14 | 14 | #ifdef __BIONIC__ |
| 15 | #include <android/api-level.h> | |
| 16 | #if __ANDROID_API__ >= 21 | |
| 17 | #include <syslog.h> | |
| 18 | extern "C" void android_set_abort_message(const char* msg); | |
| 19 | #else | |
| 20 | #include <assert.h> | |
| 21 | #endif // __ANDROID_API__ >= 21 | |
| 15 | # include <android/api-level.h> | |
| 16 | # if __ANDROID_API__ >= 21 | |
| 17 | # include <syslog.h> | |
| 18 | extern "C" void android_set_abort_message(const char* msg); | |
| 19 | # else | |
| 20 | # include <assert.h> | |
| 21 | # endif // __ANDROID_API__ >= 21 | |
| 22 | 22 | #endif // __BIONIC__ |
| 23 | 23 | |
| 24 | #ifdef __APPLE__ | |
| 25 | # if defined(__has_include) && __has_include(<CrashReporterClient.h>) | |
| 26 | # define HAVE_CRASHREPORTERCLIENT_H | |
| 27 | # include <CrashReporterClient.h> | |
| 28 | # endif | |
| 24 | #if defined(__APPLE__) && __has_include(<CrashReporterClient.h>) | |
| 25 | # include <CrashReporterClient.h> | |
| 26 | # define _LIBCXXABI_USE_CRASHREPORTER_CLIENT | |
| 29 | 27 | #endif |
| 30 | 28 | |
| 31 | 29 | void abort_message(const char* format, ...) |
| 32 | 30 | { |
| 33 | // write message to stderr | |
| 31 | // Write message to stderr. We do this before formatting into a | |
| 32 | // variable-size buffer so that we still get some information if | |
| 33 | // formatting into the variable-sized buffer fails. | |
| 34 | 34 | #if !defined(NDEBUG) || !defined(LIBCXXABI_BAREMETAL) |
| 35 | #ifdef __APPLE__ | |
| 36 | fprintf(stderr, "libc++abi.dylib: "); | |
| 35 | { | |
| 36 | fprintf(stderr, "libc++abi: "); | |
| 37 | va_list list; | |
| 38 | va_start(list, format); | |
| 39 | vfprintf(stderr, format, list); | |
| 40 | va_end(list); | |
| 41 | fprintf(stderr, "\n"); | |
| 42 | } | |
| 37 | 43 | #endif |
| 44 | ||
| 45 | // Format the arguments into an allocated buffer. We leak the buffer on | |
| 46 | // purpose, since we're about to abort() anyway. | |
| 47 | #if defined(_LIBCXXABI_USE_CRASHREPORTER_CLIENT) | |
| 48 | char* buffer; | |
| 38 | 49 | va_list list; |
| 39 | 50 | va_start(list, format); |
| 40 | vfprintf(stderr, format, list); | |
| 51 | vasprintf(&buffer, format, list); | |
| 41 | 52 | va_end(list); |
| 42 | fprintf(stderr, "\n"); | |
| 43 | #endif | |
| 44 | 53 | |
| 45 | #if defined(__APPLE__) && defined(HAVE_CRASHREPORTERCLIENT_H) | |
| 46 | // record message in crash report | |
| 47 | char* buffer; | |
| 48 | va_list list2; | |
| 49 | va_start(list2, format); | |
| 50 | vasprintf(&buffer, format, list2); | |
| 51 | va_end(list2); | |
| 52 | 54 | CRSetCrashLogMessage(buffer); |
| 53 | 55 | #elif defined(__BIONIC__) |
| 54 | 56 | char* buffer; |
| 55 | va_list list2; | |
| 56 | va_start(list2, format); | |
| 57 | vasprintf(&buffer, format, list2); | |
| 58 | va_end(list2); | |
| 57 | va_list list; | |
| 58 | va_start(list, format); | |
| 59 | vasprintf(&buffer, format, list); | |
| 60 | va_end(list); | |
| 59 | 61 | |
| 60 | #if __ANDROID_API__ >= 21 | |
| 62 | # if __ANDROID_API__ >= 21 | |
| 61 | 63 | // Show error in tombstone. |
| 62 | 64 | android_set_abort_message(buffer); |
| 63 | 65 | |
| ... | ... | @@ -65,12 +67,12 @@ void abort_message(const char* format, ...) |
| 65 | 67 | openlog("libc++abi", 0, 0); |
| 66 | 68 | syslog(LOG_CRIT, "%s", buffer); |
| 67 | 69 | closelog(); |
| 68 | #else | |
| 70 | # else | |
| 69 | 71 | // The good error reporting wasn't available in Android until L. Since we're |
| 70 | 72 | // about to abort anyway, just call __assert2, which will log _somewhere_ |
| 71 | 73 | // (tombstone and/or logcat) in older releases. |
| 72 | 74 | __assert2(__FILE__, __LINE__, __func__, buffer); |
| 73 | #endif // __ANDROID_API__ >= 21 | |
| 75 | # endif // __ANDROID_API__ >= 21 | |
| 74 | 76 | #endif // __BIONIC__ |
| 75 | 77 | |
| 76 | 78 | abort(); |
lib/libcxxabi/src/abort_message.h+1-10| ... | ... | @@ -11,16 +11,7 @@ |
| 11 | 11 | |
| 12 | 12 | #include "cxxabi.h" |
| 13 | 13 | |
| 14 | #ifdef __cplusplus | |
| 15 | extern "C" { | |
| 16 | #endif | |
| 17 | ||
| 18 | _LIBCXXABI_HIDDEN _LIBCXXABI_NORETURN void | |
| 14 | extern "C" _LIBCXXABI_HIDDEN _LIBCXXABI_NORETURN void | |
| 19 | 15 | abort_message(const char *format, ...) __attribute__((format(printf, 1, 2))); |
| 20 | 16 | |
| 21 | #ifdef __cplusplus | |
| 22 | } | |
| 23 | 17 | #endif |
| 24 | ||
| 25 | #endif | |
| 26 |
lib/libcxxabi/src/cxa_guard_impl.h+27-2| ... | ... | @@ -40,7 +40,6 @@ |
| 40 | 40 | #include "__cxxabi_config.h" |
| 41 | 41 | #include "include/atomic_support.h" |
| 42 | 42 | #include <unistd.h> |
| 43 | #include <sys/types.h> | |
| 44 | 43 | #if defined(__has_include) |
| 45 | 44 | # if __has_include(<sys/syscall.h>) |
| 46 | 45 | # include <sys/syscall.h> |
| ... | ... | @@ -108,6 +107,32 @@ struct LazyValue { |
| 108 | 107 | bool is_init = false; |
| 109 | 108 | }; |
| 110 | 109 | |
| 110 | template <class IntType> | |
| 111 | class AtomicInt { | |
| 112 | public: | |
| 113 | using MemoryOrder = std::__libcpp_atomic_order; | |
| 114 | ||
| 115 | explicit AtomicInt(IntType *b) : b(b) {} | |
| 116 | AtomicInt(AtomicInt const&) = delete; | |
| 117 | AtomicInt& operator=(AtomicInt const&) = delete; | |
| 118 | ||
| 119 | IntType load(MemoryOrder ord) { | |
| 120 | return std::__libcpp_atomic_load(b, ord); | |
| 121 | } | |
| 122 | void store(IntType val, MemoryOrder ord) { | |
| 123 | std::__libcpp_atomic_store(b, val, ord); | |
| 124 | } | |
| 125 | IntType exchange(IntType new_val, MemoryOrder ord) { | |
| 126 | return std::__libcpp_atomic_exchange(b, new_val, ord); | |
| 127 | } | |
| 128 | bool compare_exchange(IntType *expected, IntType desired, MemoryOrder ord_success, MemoryOrder ord_failure) { | |
| 129 | return std::__libcpp_atomic_compare_exchange(b, expected, desired, ord_success, ord_failure); | |
| 130 | } | |
| 131 | ||
| 132 | private: | |
| 133 | IntType *b; | |
| 134 | }; | |
| 135 | ||
| 111 | 136 | //===----------------------------------------------------------------------===// |
| 112 | 137 | // PlatformGetThreadID |
| 113 | 138 | //===----------------------------------------------------------------------===// |
| ... | ... | @@ -195,7 +220,7 @@ public: |
| 195 | 220 | public: |
| 196 | 221 | /// base_address - the address of the original guard object. |
| 197 | 222 | void* const base_address; |
| 198 | /// The address of the guord byte at offset 0. | |
| 223 | /// The address of the guard byte at offset 0. | |
| 199 | 224 | uint8_t* const guard_byte_address; |
| 200 | 225 | /// The address of the byte used by the implementation during initialization. |
| 201 | 226 | uint8_t* const init_byte_address; |
lib/libcxxabi/src/cxa_handlers.h+1-1| ... | ... | @@ -12,7 +12,7 @@ |
| 12 | 12 | #ifndef _CXA_HANDLERS_H |
| 13 | 13 | #define _CXA_HANDLERS_H |
| 14 | 14 | |
| 15 | #include <__cxxabi_config.h> | |
| 15 | #include "__cxxabi_config.h" | |
| 16 | 16 | |
| 17 | 17 | #include <exception> |
| 18 | 18 |
lib/libcxxabi/src/cxa_unexpected.cpp deleted-22| ... | ... | @@ -1,22 +0,0 @@ |
| 1 | //===------------------------- cxa_unexpected.cpp -------------------------===// | |
| 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 | #include <exception> | |
| 10 | #include "cxxabi.h" | |
| 11 | #include "cxa_exception.h" | |
| 12 | ||
| 13 | namespace __cxxabiv1 | |
| 14 | { | |
| 15 | ||
| 16 | extern "C" | |
| 17 | { | |
| 18 | ||
| 19 | } | |
| 20 | ||
| 21 | } // namespace __cxxabiv1 | |
| 22 |
lib/libcxxabi/src/cxa_vector.cpp+6-6| ... | ... | @@ -24,9 +24,9 @@ |
| 24 | 24 | |
| 25 | 25 | namespace __cxxabiv1 { |
| 26 | 26 | |
| 27 | #if 0 | |
| 28 | #pragma mark --Helper routines and classes -- | |
| 29 | #endif | |
| 27 | // | |
| 28 | // Helper routines and classes | |
| 29 | // | |
| 30 | 30 | |
| 31 | 31 | namespace { |
| 32 | 32 | inline static size_t __get_element_count ( void *p ) { |
| ... | ... | @@ -111,9 +111,9 @@ namespace { |
| 111 | 111 | }; |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | #if 0 | |
| 115 | #pragma mark --Externally visible routines-- | |
| 116 | #endif | |
| 114 | // | |
| 115 | // Externally visible routines | |
| 116 | // | |
| 117 | 117 | |
| 118 | 118 | namespace { |
| 119 | 119 | _LIBCXXABI_NORETURN |
lib/libcxxabi/src/demangle/ItaniumDemangle.h+38-9| ... | ... | @@ -98,7 +98,7 @@ |
| 98 | 98 | X(BoolExpr) \ |
| 99 | 99 | X(StringLiteral) \ |
| 100 | 100 | X(LambdaExpr) \ |
| 101 | X(IntegerCastExpr) \ | |
| 101 | X(EnumLiteral) \ | |
| 102 | 102 | X(IntegerLiteral) \ |
| 103 | 103 | X(FloatLiteral) \ |
| 104 | 104 | X(DoubleLiteral) \ |
| ... | ... | @@ -2036,22 +2036,26 @@ public: |
| 2036 | 2036 | } |
| 2037 | 2037 | }; |
| 2038 | 2038 | |
| 2039 | class IntegerCastExpr : public Node { | |
| 2039 | class EnumLiteral : public Node { | |
| 2040 | 2040 | // ty(integer) |
| 2041 | 2041 | const Node *Ty; |
| 2042 | 2042 | StringView Integer; |
| 2043 | 2043 | |
| 2044 | 2044 | public: |
| 2045 | IntegerCastExpr(const Node *Ty_, StringView Integer_) | |
| 2046 | : Node(KIntegerCastExpr), Ty(Ty_), Integer(Integer_) {} | |
| 2045 | EnumLiteral(const Node *Ty_, StringView Integer_) | |
| 2046 | : Node(KEnumLiteral), Ty(Ty_), Integer(Integer_) {} | |
| 2047 | 2047 | |
| 2048 | 2048 | template<typename Fn> void match(Fn F) const { F(Ty, Integer); } |
| 2049 | 2049 | |
| 2050 | 2050 | void printLeft(OutputStream &S) const override { |
| 2051 | S += "("; | |
| 2051 | S << "("; | |
| 2052 | 2052 | Ty->print(S); |
| 2053 | S += ")"; | |
| 2054 | S += Integer; | |
| 2053 | S << ")"; | |
| 2054 | ||
| 2055 | if (Integer[0] == 'n') | |
| 2056 | S << "-" << Integer.dropFront(1); | |
| 2057 | else | |
| 2058 | S << Integer; | |
| 2055 | 2059 | } |
| 2056 | 2060 | }; |
| 2057 | 2061 | |
| ... | ... | @@ -4064,8 +4068,11 @@ Qualifiers AbstractManglingParser<Alloc, Derived>::parseCVQualifiers() { |
| 4064 | 4068 | // ::= fp <top-level CV-Qualifiers> <parameter-2 non-negative number> _ # L == 0, second and later parameters |
| 4065 | 4069 | // ::= fL <L-1 non-negative number> p <top-level CV-Qualifiers> _ # L > 0, first parameter |
| 4066 | 4070 | // ::= fL <L-1 non-negative number> p <top-level CV-Qualifiers> <parameter-2 non-negative number> _ # L > 0, second and later parameters |
| 4071 | // ::= fpT # 'this' expression (not part of standard?) | |
| 4067 | 4072 | template <typename Derived, typename Alloc> |
| 4068 | 4073 | Node *AbstractManglingParser<Derived, Alloc>::parseFunctionParam() { |
| 4074 | if (consumeIf("fpT")) | |
| 4075 | return make<NameType>("this"); | |
| 4069 | 4076 | if (consumeIf("fp")) { |
| 4070 | 4077 | parseCVQualifiers(); |
| 4071 | 4078 | StringView Num = parseNumber(); |
| ... | ... | @@ -4225,7 +4232,13 @@ Node *AbstractManglingParser<Derived, Alloc>::parseExprPrimary() { |
| 4225 | 4232 | return getDerived().template parseFloatingLiteral<double>(); |
| 4226 | 4233 | case 'e': |
| 4227 | 4234 | ++First; |
| 4235 | #if defined(__powerpc__) || defined(__s390__) | |
| 4236 | // Handle cases where long doubles encoded with e have the same size | |
| 4237 | // and representation as doubles. | |
| 4238 | return getDerived().template parseFloatingLiteral<double>(); | |
| 4239 | #else | |
| 4228 | 4240 | return getDerived().template parseFloatingLiteral<long double>(); |
| 4241 | #endif | |
| 4229 | 4242 | case '_': |
| 4230 | 4243 | if (consumeIf("_Z")) { |
| 4231 | 4244 | Node *R = getDerived().parseEncoding(); |
| ... | ... | @@ -4264,12 +4277,12 @@ Node *AbstractManglingParser<Derived, Alloc>::parseExprPrimary() { |
| 4264 | 4277 | Node *T = getDerived().parseType(); |
| 4265 | 4278 | if (T == nullptr) |
| 4266 | 4279 | return nullptr; |
| 4267 | StringView N = parseNumber(); | |
| 4280 | StringView N = parseNumber(/*AllowNegative=*/true); | |
| 4268 | 4281 | if (N.empty()) |
| 4269 | 4282 | return nullptr; |
| 4270 | 4283 | if (!consumeIf('E')) |
| 4271 | 4284 | return nullptr; |
| 4272 | return make<IntegerCastExpr>(T, N); | |
| 4285 | return make<EnumLiteral>(T, N); | |
| 4273 | 4286 | } |
| 4274 | 4287 | } |
| 4275 | 4288 | } |
| ... | ... | @@ -5083,6 +5096,22 @@ Node *AbstractManglingParser<Derived, Alloc>::parseSpecialName() { |
| 5083 | 5096 | // ::= <special-name> |
| 5084 | 5097 | template <typename Derived, typename Alloc> |
| 5085 | 5098 | Node *AbstractManglingParser<Derived, Alloc>::parseEncoding() { |
| 5099 | // The template parameters of an encoding are unrelated to those of the | |
| 5100 | // enclosing context. | |
| 5101 | class SaveTemplateParams { | |
| 5102 | AbstractManglingParser *Parser; | |
| 5103 | decltype(TemplateParams) OldParams; | |
| 5104 | ||
| 5105 | public: | |
| 5106 | SaveTemplateParams(AbstractManglingParser *Parser) : Parser(Parser) { | |
| 5107 | OldParams = std::move(Parser->TemplateParams); | |
| 5108 | Parser->TemplateParams.clear(); | |
| 5109 | } | |
| 5110 | ~SaveTemplateParams() { | |
| 5111 | Parser->TemplateParams = std::move(OldParams); | |
| 5112 | } | |
| 5113 | } SaveTemplateParams(this); | |
| 5114 | ||
| 5086 | 5115 | if (look() == 'G' || look() == 'T') |
| 5087 | 5116 | return getDerived().parseSpecialName(); |
| 5088 | 5117 |
lib/libcxxabi/src/include/atomic_support.h-30| ... | ... | @@ -177,34 +177,4 @@ bool __libcpp_atomic_compare_exchange(_ValueType* __val, |
| 177 | 177 | |
| 178 | 178 | _LIBCPP_END_NAMESPACE_STD |
| 179 | 179 | |
| 180 | namespace { | |
| 181 | ||
| 182 | template <class IntType> | |
| 183 | class AtomicInt { | |
| 184 | public: | |
| 185 | using MemoryOrder = std::__libcpp_atomic_order; | |
| 186 | ||
| 187 | explicit AtomicInt(IntType *b) : b(b) {} | |
| 188 | AtomicInt(AtomicInt const&) = delete; | |
| 189 | AtomicInt& operator=(AtomicInt const&) = delete; | |
| 190 | ||
| 191 | IntType load(MemoryOrder ord) { | |
| 192 | return std::__libcpp_atomic_load(b, ord); | |
| 193 | } | |
| 194 | void store(IntType val, MemoryOrder ord) { | |
| 195 | std::__libcpp_atomic_store(b, val, ord); | |
| 196 | } | |
| 197 | IntType exchange(IntType new_val, MemoryOrder ord) { | |
| 198 | return std::__libcpp_atomic_exchange(b, new_val, ord); | |
| 199 | } | |
| 200 | bool compare_exchange(IntType *expected, IntType desired, MemoryOrder ord_success, MemoryOrder ord_failure) { | |
| 201 | return std::__libcpp_atomic_compare_exchange(b, expected, desired, ord_success, ord_failure); | |
| 202 | } | |
| 203 | ||
| 204 | private: | |
| 205 | IntType *b; | |
| 206 | }; | |
| 207 | ||
| 208 | } // end namespace | |
| 209 | ||
| 210 | 180 | #endif // ATOMIC_SUPPORT_H |
lib/libcxxabi/src/private_typeinfo.cpp+27-20| ... | ... | @@ -8,11 +8,11 @@ |
| 8 | 8 | |
| 9 | 9 | #include "private_typeinfo.h" |
| 10 | 10 | |
| 11 | // The flag _LIBCXX_DYNAMIC_FALLBACK is used to make dynamic_cast more | |
| 12 | // forgiving when type_info's mistakenly have hidden visibility and thus | |
| 13 | // multiple type_infos can exist for a single type. | |
| 11 | // The flag _LIBCXXABI_FORGIVING_DYNAMIC_CAST is used to make dynamic_cast | |
| 12 | // more forgiving when type_info's mistakenly have hidden visibility and | |
| 13 | // thus multiple type_infos can exist for a single type. | |
| 14 | 14 | // |
| 15 | // When _LIBCXX_DYNAMIC_FALLBACK is defined, and only in the case where | |
| 15 | // When _LIBCXXABI_FORGIVING_DYNAMIC_CAST is defined, and only in the case where | |
| 16 | 16 | // there is a detected inconsistency in the type_info hierarchy during a |
| 17 | 17 | // dynamic_cast, then the equality operation will fall back to using strcmp |
| 18 | 18 | // on type_info names to determine type_info equality. |
| ... | ... | @@ -23,7 +23,7 @@ |
| 23 | 23 | // algorithm and an inconsistency is still detected, dynamic_cast will call |
| 24 | 24 | // abort with an appropriate message. |
| 25 | 25 | // |
| 26 | // The current implementation of _LIBCXX_DYNAMIC_FALLBACK requires a | |
| 26 | // The current implementation of _LIBCXXABI_FORGIVING_DYNAMIC_CAST requires a | |
| 27 | 27 | // printf-like function called syslog: |
| 28 | 28 | // |
| 29 | 29 | // void syslog(int facility_priority, const char* format, ...); |
| ... | ... | @@ -31,21 +31,22 @@ |
| 31 | 31 | // If you want this functionality but your platform doesn't have syslog, |
| 32 | 32 | // just implement it in terms of fprintf(stderr, ...). |
| 33 | 33 | // |
| 34 | // _LIBCXX_DYNAMIC_FALLBACK is currently off by default. | |
| 34 | // _LIBCXXABI_FORGIVING_DYNAMIC_CAST is currently off by default. | |
| 35 | 35 | |
| 36 | 36 | // On Windows, typeids are different between DLLs and EXEs, so comparing |
| 37 | 37 | // type_info* will work for typeids from the same compiled file but fail |
| 38 | 38 | // for typeids from a DLL and an executable. Among other things, exceptions |
| 39 | 39 | // are not caught by handlers since can_catch() returns false. |
| 40 | 40 | // |
| 41 | // Defining _LIBCXX_DYNAMIC_FALLBACK does not help since can_catch() calls | |
| 41 | // Defining _LIBCXXABI_FORGIVING_DYNAMIC_CAST does not help since can_catch() calls | |
| 42 | 42 | // is_equal() with use_strcmp=false so the string names are not compared. |
| 43 | 43 | |
| 44 | 44 | #include <string.h> |
| 45 | 45 | |
| 46 | #ifdef _LIBCXX_DYNAMIC_FALLBACK | |
| 46 | #ifdef _LIBCXXABI_FORGIVING_DYNAMIC_CAST | |
| 47 | 47 | #include "abort_message.h" |
| 48 | 48 | #include <sys/syslog.h> |
| 49 | #include <atomic> | |
| 49 | 50 | #endif |
| 50 | 51 | |
| 51 | 52 | static inline |
| ... | ... | @@ -633,22 +634,25 @@ __dynamic_cast(const void *static_ptr, const __class_type_info *static_type, |
| 633 | 634 | info.number_of_dst_type = 1; |
| 634 | 635 | // Do the search |
| 635 | 636 | dynamic_type->search_above_dst(&info, dynamic_ptr, dynamic_ptr, public_path, false); |
| 636 | #ifdef _LIBCXX_DYNAMIC_FALLBACK | |
| 637 | #ifdef _LIBCXXABI_FORGIVING_DYNAMIC_CAST | |
| 637 | 638 | // The following if should always be false because we should definitely |
| 638 | 639 | // find (static_ptr, static_type), either on a public or private path |
| 639 | 640 | if (info.path_dst_ptr_to_static_ptr == unknown) |
| 640 | 641 | { |
| 641 | 642 | // We get here only if there is some kind of visibility problem |
| 642 | 643 | // in client code. |
| 643 | syslog(LOG_ERR, "dynamic_cast error 1: Both of the following type_info's " | |
| 644 | "should have public visibility. At least one of them is hidden. %s" | |
| 645 | ", %s.\n", static_type->name(), dynamic_type->name()); | |
| 644 | static std::atomic<size_t> error_count(0); | |
| 645 | size_t error_count_snapshot = error_count.fetch_add(1, std::memory_order_relaxed); | |
| 646 | if ((error_count_snapshot & (error_count_snapshot-1)) == 0) | |
| 647 | syslog(LOG_ERR, "dynamic_cast error 1: Both of the following type_info's " | |
| 648 | "should have public visibility. At least one of them is hidden. %s" | |
| 649 | ", %s.\n", static_type->name(), dynamic_type->name()); | |
| 646 | 650 | // Redo the search comparing type_info's using strcmp |
| 647 | 651 | info = {dst_type, static_ptr, static_type, src2dst_offset, 0}; |
| 648 | 652 | info.number_of_dst_type = 1; |
| 649 | 653 | dynamic_type->search_above_dst(&info, dynamic_ptr, dynamic_ptr, public_path, true); |
| 650 | 654 | } |
| 651 | #endif // _LIBCXX_DYNAMIC_FALLBACK | |
| 655 | #endif // _LIBCXXABI_FORGIVING_DYNAMIC_CAST | |
| 652 | 656 | // Query the search. |
| 653 | 657 | if (info.path_dst_ptr_to_static_ptr == public_path) |
| 654 | 658 | dst_ptr = dynamic_ptr; |
| ... | ... | @@ -657,22 +661,25 @@ __dynamic_cast(const void *static_ptr, const __class_type_info *static_type, |
| 657 | 661 | { |
| 658 | 662 | // Not using giant short cut. Do the search |
| 659 | 663 | dynamic_type->search_below_dst(&info, dynamic_ptr, public_path, false); |
| 660 | #ifdef _LIBCXX_DYNAMIC_FALLBACK | |
| 664 | #ifdef _LIBCXXABI_FORGIVING_DYNAMIC_CAST | |
| 661 | 665 | // The following if should always be false because we should definitely |
| 662 | 666 | // find (static_ptr, static_type), either on a public or private path |
| 663 | 667 | if (info.path_dst_ptr_to_static_ptr == unknown && |
| 664 | 668 | info.path_dynamic_ptr_to_static_ptr == unknown) |
| 665 | 669 | { |
| 666 | syslog(LOG_ERR, "dynamic_cast error 2: One or more of the following type_info's " | |
| 667 | "has hidden visibility or is defined in more than one translation " | |
| 668 | "unit. They should all have public visibility. " | |
| 669 | "%s, %s, %s.\n", static_type->name(), dynamic_type->name(), | |
| 670 | dst_type->name()); | |
| 670 | static std::atomic<size_t> error_count(0); | |
| 671 | size_t error_count_snapshot = error_count.fetch_add(1, std::memory_order_relaxed); | |
| 672 | if ((error_count_snapshot & (error_count_snapshot-1)) == 0) | |
| 673 | syslog(LOG_ERR, "dynamic_cast error 2: One or more of the following type_info's " | |
| 674 | "has hidden visibility or is defined in more than one translation " | |
| 675 | "unit. They should all have public visibility. " | |
| 676 | "%s, %s, %s.\n", static_type->name(), dynamic_type->name(), | |
| 677 | dst_type->name()); | |
| 671 | 678 | // Redo the search comparing type_info's using strcmp |
| 672 | 679 | info = {dst_type, static_ptr, static_type, src2dst_offset, 0}; |
| 673 | 680 | dynamic_type->search_below_dst(&info, dynamic_ptr, public_path, true); |
| 674 | 681 | } |
| 675 | #endif // _LIBCXX_DYNAMIC_FALLBACK | |
| 682 | #endif // _LIBCXXABI_FORGIVING_DYNAMIC_CAST | |
| 676 | 683 | // Query the search. |
| 677 | 684 | switch (info.number_to_static_ptr) |
| 678 | 685 | { |
lib/libcxxabi/src/stdlib_new_delete.cpp created+262| ... | ... | @@ -0,0 +1,262 @@ |
| 1 | //===--------------------- stdlib_new_delete.cpp --------------------------===// | |
| 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 | // This file implements the new and delete operators. | |
| 9 | //===----------------------------------------------------------------------===// | |
| 10 | ||
| 11 | #define _LIBCPP_BUILDING_LIBRARY | |
| 12 | #include "__cxxabi_config.h" | |
| 13 | #include <new> | |
| 14 | #include <cstdlib> | |
| 15 | ||
| 16 | #if !defined(_THROW_BAD_ALLOC) || !defined(_NOEXCEPT) || !defined(_LIBCXXABI_WEAK) | |
| 17 | #error The _THROW_BAD_ALLOC, _NOEXCEPT, and _LIBCXXABI_WEAK libc++ macros must \ | |
| 18 | already be defined by libc++. | |
| 19 | #endif | |
| 20 | // Implement all new and delete operators as weak definitions | |
| 21 | // in this shared library, so that they can be overridden by programs | |
| 22 | // that define non-weak copies of the functions. | |
| 23 | ||
| 24 | _LIBCXXABI_WEAK | |
| 25 | void * | |
| 26 | operator new(std::size_t size) _THROW_BAD_ALLOC | |
| 27 | { | |
| 28 | if (size == 0) | |
| 29 | size = 1; | |
| 30 | void* p; | |
| 31 | while ((p = ::malloc(size)) == 0) | |
| 32 | { | |
| 33 | // If malloc fails and there is a new_handler, | |
| 34 | // call it to try free up memory. | |
| 35 | std::new_handler nh = std::get_new_handler(); | |
| 36 | if (nh) | |
| 37 | nh(); | |
| 38 | else | |
| 39 | #ifndef _LIBCXXABI_NO_EXCEPTIONS | |
| 40 | throw std::bad_alloc(); | |
| 41 | #else | |
| 42 | break; | |
| 43 | #endif | |
| 44 | } | |
| 45 | return p; | |
| 46 | } | |
| 47 | ||
| 48 | _LIBCXXABI_WEAK | |
| 49 | void* | |
| 50 | operator new(size_t size, const std::nothrow_t&) _NOEXCEPT | |
| 51 | { | |
| 52 | void* p = 0; | |
| 53 | #ifndef _LIBCXXABI_NO_EXCEPTIONS | |
| 54 | try | |
| 55 | { | |
| 56 | #endif // _LIBCXXABI_NO_EXCEPTIONS | |
| 57 | p = ::operator new(size); | |
| 58 | #ifndef _LIBCXXABI_NO_EXCEPTIONS | |
| 59 | } | |
| 60 | catch (...) | |
| 61 | { | |
| 62 | } | |
| 63 | #endif // _LIBCXXABI_NO_EXCEPTIONS | |
| 64 | return p; | |
| 65 | } | |
| 66 | ||
| 67 | _LIBCXXABI_WEAK | |
| 68 | void* | |
| 69 | operator new[](size_t size) _THROW_BAD_ALLOC | |
| 70 | { | |
| 71 | return ::operator new(size); | |
| 72 | } | |
| 73 | ||
| 74 | _LIBCXXABI_WEAK | |
| 75 | void* | |
| 76 | operator new[](size_t size, const std::nothrow_t&) _NOEXCEPT | |
| 77 | { | |
| 78 | void* p = 0; | |
| 79 | #ifndef _LIBCXXABI_NO_EXCEPTIONS | |
| 80 | try | |
| 81 | { | |
| 82 | #endif // _LIBCXXABI_NO_EXCEPTIONS | |
| 83 | p = ::operator new[](size); | |
| 84 | #ifndef _LIBCXXABI_NO_EXCEPTIONS | |
| 85 | } | |
| 86 | catch (...) | |
| 87 | { | |
| 88 | } | |
| 89 | #endif // _LIBCXXABI_NO_EXCEPTIONS | |
| 90 | return p; | |
| 91 | } | |
| 92 | ||
| 93 | _LIBCXXABI_WEAK | |
| 94 | void | |
| 95 | operator delete(void* ptr) _NOEXCEPT | |
| 96 | { | |
| 97 | if (ptr) | |
| 98 | ::free(ptr); | |
| 99 | } | |
| 100 | ||
| 101 | _LIBCXXABI_WEAK | |
| 102 | void | |
| 103 | operator delete(void* ptr, const std::nothrow_t&) _NOEXCEPT | |
| 104 | { | |
| 105 | ::operator delete(ptr); | |
| 106 | } | |
| 107 | ||
| 108 | _LIBCXXABI_WEAK | |
| 109 | void | |
| 110 | operator delete(void* ptr, size_t) _NOEXCEPT | |
| 111 | { | |
| 112 | ::operator delete(ptr); | |
| 113 | } | |
| 114 | ||
| 115 | _LIBCXXABI_WEAK | |
| 116 | void | |
| 117 | operator delete[] (void* ptr) _NOEXCEPT | |
| 118 | { | |
| 119 | ::operator delete(ptr); | |
| 120 | } | |
| 121 | ||
| 122 | _LIBCXXABI_WEAK | |
| 123 | void | |
| 124 | operator delete[] (void* ptr, const std::nothrow_t&) _NOEXCEPT | |
| 125 | { | |
| 126 | ::operator delete[](ptr); | |
| 127 | } | |
| 128 | ||
| 129 | _LIBCXXABI_WEAK | |
| 130 | void | |
| 131 | operator delete[] (void* ptr, size_t) _NOEXCEPT | |
| 132 | { | |
| 133 | ::operator delete[](ptr); | |
| 134 | } | |
| 135 | ||
| 136 | #if !defined(_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION) | |
| 137 | ||
| 138 | _LIBCXXABI_WEAK | |
| 139 | void * | |
| 140 | operator new(std::size_t size, std::align_val_t alignment) _THROW_BAD_ALLOC | |
| 141 | { | |
| 142 | if (size == 0) | |
| 143 | size = 1; | |
| 144 | if (static_cast<size_t>(alignment) < sizeof(void*)) | |
| 145 | alignment = std::align_val_t(sizeof(void*)); | |
| 146 | void* p; | |
| 147 | #if defined(_LIBCPP_WIN32API) | |
| 148 | while ((p = _aligned_malloc(size, static_cast<size_t>(alignment))) == nullptr) | |
| 149 | #else | |
| 150 | while (::posix_memalign(&p, static_cast<size_t>(alignment), size) != 0) | |
| 151 | #endif | |
| 152 | { | |
| 153 | // If posix_memalign fails and there is a new_handler, | |
| 154 | // call it to try free up memory. | |
| 155 | std::new_handler nh = std::get_new_handler(); | |
| 156 | if (nh) | |
| 157 | nh(); | |
| 158 | else { | |
| 159 | #ifndef _LIBCXXABI_NO_EXCEPTIONS | |
| 160 | throw std::bad_alloc(); | |
| 161 | #else | |
| 162 | p = nullptr; // posix_memalign doesn't initialize 'p' on failure | |
| 163 | break; | |
| 164 | #endif | |
| 165 | } | |
| 166 | } | |
| 167 | return p; | |
| 168 | } | |
| 169 | ||
| 170 | _LIBCXXABI_WEAK | |
| 171 | void* | |
| 172 | operator new(size_t size, std::align_val_t alignment, const std::nothrow_t&) _NOEXCEPT | |
| 173 | { | |
| 174 | void* p = 0; | |
| 175 | #ifndef _LIBCXXABI_NO_EXCEPTIONS | |
| 176 | try | |
| 177 | { | |
| 178 | #endif // _LIBCXXABI_NO_EXCEPTIONS | |
| 179 | p = ::operator new(size, alignment); | |
| 180 | #ifndef _LIBCXXABI_NO_EXCEPTIONS | |
| 181 | } | |
| 182 | catch (...) | |
| 183 | { | |
| 184 | } | |
| 185 | #endif // _LIBCXXABI_NO_EXCEPTIONS | |
| 186 | return p; | |
| 187 | } | |
| 188 | ||
| 189 | _LIBCXXABI_WEAK | |
| 190 | void* | |
| 191 | operator new[](size_t size, std::align_val_t alignment) _THROW_BAD_ALLOC | |
| 192 | { | |
| 193 | return ::operator new(size, alignment); | |
| 194 | } | |
| 195 | ||
| 196 | _LIBCXXABI_WEAK | |
| 197 | void* | |
| 198 | operator new[](size_t size, std::align_val_t alignment, const std::nothrow_t&) _NOEXCEPT | |
| 199 | { | |
| 200 | void* p = 0; | |
| 201 | #ifndef _LIBCXXABI_NO_EXCEPTIONS | |
| 202 | try | |
| 203 | { | |
| 204 | #endif // _LIBCXXABI_NO_EXCEPTIONS | |
| 205 | p = ::operator new[](size, alignment); | |
| 206 | #ifndef _LIBCXXABI_NO_EXCEPTIONS | |
| 207 | } | |
| 208 | catch (...) | |
| 209 | { | |
| 210 | } | |
| 211 | #endif // _LIBCXXABI_NO_EXCEPTIONS | |
| 212 | return p; | |
| 213 | } | |
| 214 | ||
| 215 | _LIBCXXABI_WEAK | |
| 216 | void | |
| 217 | operator delete(void* ptr, std::align_val_t) _NOEXCEPT | |
| 218 | { | |
| 219 | if (ptr) | |
| 220 | #if defined(_LIBCPP_WIN32API) | |
| 221 | ::_aligned_free(ptr); | |
| 222 | #else | |
| 223 | ::free(ptr); | |
| 224 | #endif | |
| 225 | } | |
| 226 | ||
| 227 | _LIBCXXABI_WEAK | |
| 228 | void | |
| 229 | operator delete(void* ptr, std::align_val_t alignment, const std::nothrow_t&) _NOEXCEPT | |
| 230 | { | |
| 231 | ::operator delete(ptr, alignment); | |
| 232 | } | |
| 233 | ||
| 234 | _LIBCXXABI_WEAK | |
| 235 | void | |
| 236 | operator delete(void* ptr, size_t, std::align_val_t alignment) _NOEXCEPT | |
| 237 | { | |
| 238 | ::operator delete(ptr, alignment); | |
| 239 | } | |
| 240 | ||
| 241 | _LIBCXXABI_WEAK | |
| 242 | void | |
| 243 | operator delete[] (void* ptr, std::align_val_t alignment) _NOEXCEPT | |
| 244 | { | |
| 245 | ::operator delete(ptr, alignment); | |
| 246 | } | |
| 247 | ||
| 248 | _LIBCXXABI_WEAK | |
| 249 | void | |
| 250 | operator delete[] (void* ptr, std::align_val_t alignment, const std::nothrow_t&) _NOEXCEPT | |
| 251 | { | |
| 252 | ::operator delete[](ptr, alignment); | |
| 253 | } | |
| 254 | ||
| 255 | _LIBCXXABI_WEAK | |
| 256 | void | |
| 257 | operator delete[] (void* ptr, size_t, std::align_val_t alignment) _NOEXCEPT | |
| 258 | { | |
| 259 | ::operator delete[](ptr, alignment); | |
| 260 | } | |
| 261 | ||
| 262 | #endif // !_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION |