authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-08-04 17:30:57-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-08-04 17:30:57-07:00
log42da1d385de8559710e04b5a05234f2dd8bb347e
tree8f354c4dd008700e8ebfd367b25842addb25ae1a
parent54b67c20259f697f1e0c4532a5ee7e5d3f01eb1e

libcxxabi: upgrade from llvm 10 to 11rc1


11 files changed, 404 insertions(+), 132 deletions(-)

lib/libcxxabi/include/__cxxabi_config.h+8
......@@ -76,4 +76,12 @@
7676# define _LIBCXXABI_GUARD_ABI_ARM
7777#endif
7878
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
7987#endif // ____CXXABI_CONFIG_H
lib/libcxxabi/src/abort_message.cpp+34-32
......@@ -12,52 +12,54 @@
1212#include "abort_message.h"
1313
1414#ifdef __BIONIC__
15#include <android/api-level.h>
16#if __ANDROID_API__ >= 21
17#include <syslog.h>
18extern "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
2222#endif // __BIONIC__
2323
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
2927#endif
3028
3129void abort_message(const char* format, ...)
3230{
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.
3434#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 }
3743#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;
3849 va_list list;
3950 va_start(list, format);
40 vfprintf(stderr, format, list);
51 vasprintf(&buffer, format, list);
4152 va_end(list);
42 fprintf(stderr, "\n");
43#endif
4453
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);
5254 CRSetCrashLogMessage(buffer);
5355#elif defined(__BIONIC__)
5456 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);
5961
60#if __ANDROID_API__ >= 21
62# if __ANDROID_API__ >= 21
6163 // Show error in tombstone.
6264 android_set_abort_message(buffer);
6365
......@@ -65,12 +67,12 @@ void abort_message(const char* format, ...)
6567 openlog("libc++abi", 0, 0);
6668 syslog(LOG_CRIT, "%s", buffer);
6769 closelog();
68#else
70# else
6971 // The good error reporting wasn't available in Android until L. Since we're
7072 // about to abort anyway, just call __assert2, which will log _somewhere_
7173 // (tombstone and/or logcat) in older releases.
7274 __assert2(__FILE__, __LINE__, __func__, buffer);
73#endif // __ANDROID_API__ >= 21
75# endif // __ANDROID_API__ >= 21
7476#endif // __BIONIC__
7577
7678 abort();
lib/libcxxabi/src/abort_message.h+1-10
......@@ -11,16 +11,7 @@
1111
1212#include "cxxabi.h"
1313
14#ifdef __cplusplus
15extern "C" {
16#endif
17
18_LIBCXXABI_HIDDEN _LIBCXXABI_NORETURN void
14extern "C" _LIBCXXABI_HIDDEN _LIBCXXABI_NORETURN void
1915abort_message(const char *format, ...) __attribute__((format(printf, 1, 2)));
2016
21#ifdef __cplusplus
22}
2317#endif
24
25#endif
26
lib/libcxxabi/src/cxa_guard_impl.h+27-2
......@@ -40,7 +40,6 @@
4040#include "__cxxabi_config.h"
4141#include "include/atomic_support.h"
4242#include <unistd.h>
43#include <sys/types.h>
4443#if defined(__has_include)
4544# if __has_include(<sys/syscall.h>)
4645# include <sys/syscall.h>
......@@ -108,6 +107,32 @@ struct LazyValue {
108107 bool is_init = false;
109108};
110109
110template <class IntType>
111class AtomicInt {
112public:
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
132private:
133 IntType *b;
134};
135
111136//===----------------------------------------------------------------------===//
112137// PlatformGetThreadID
113138//===----------------------------------------------------------------------===//
......@@ -195,7 +220,7 @@ public:
195220public:
196221 /// base_address - the address of the original guard object.
197222 void* const base_address;
198 /// The address of the guord byte at offset 0.
223 /// The address of the guard byte at offset 0.
199224 uint8_t* const guard_byte_address;
200225 /// The address of the byte used by the implementation during initialization.
201226 uint8_t* const init_byte_address;
lib/libcxxabi/src/cxa_handlers.h+1-1
......@@ -12,7 +12,7 @@
1212#ifndef _CXA_HANDLERS_H
1313#define _CXA_HANDLERS_H
1414
15#include <__cxxabi_config.h>
15#include "__cxxabi_config.h"
1616
1717#include <exception>
1818
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
13namespace __cxxabiv1
14{
15
16extern "C"
17{
18
19}
20
21} // namespace __cxxabiv1
22
lib/libcxxabi/src/cxa_vector.cpp+6-6
......@@ -24,9 +24,9 @@
2424
2525namespace __cxxabiv1 {
2626
27#if 0
28#pragma mark --Helper routines and classes --
29#endif
27//
28// Helper routines and classes
29//
3030
3131namespace {
3232 inline static size_t __get_element_count ( void *p ) {
......@@ -111,9 +111,9 @@ namespace {
111111 };
112112}
113113
114#if 0
115#pragma mark --Externally visible routines--
116#endif
114//
115// Externally visible routines
116//
117117
118118namespace {
119119_LIBCXXABI_NORETURN
lib/libcxxabi/src/demangle/ItaniumDemangle.h+38-9
......@@ -98,7 +98,7 @@
9898 X(BoolExpr) \
9999 X(StringLiteral) \
100100 X(LambdaExpr) \
101 X(IntegerCastExpr) \
101 X(EnumLiteral) \
102102 X(IntegerLiteral) \
103103 X(FloatLiteral) \
104104 X(DoubleLiteral) \
......@@ -2036,22 +2036,26 @@ public:
20362036 }
20372037};
20382038
2039class IntegerCastExpr : public Node {
2039class EnumLiteral : public Node {
20402040 // ty(integer)
20412041 const Node *Ty;
20422042 StringView Integer;
20432043
20442044public:
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_) {}
20472047
20482048 template<typename Fn> void match(Fn F) const { F(Ty, Integer); }
20492049
20502050 void printLeft(OutputStream &S) const override {
2051 S += "(";
2051 S << "(";
20522052 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;
20552059 }
20562060};
20572061
......@@ -4064,8 +4068,11 @@ Qualifiers AbstractManglingParser<Alloc, Derived>::parseCVQualifiers() {
40644068// ::= fp <top-level CV-Qualifiers> <parameter-2 non-negative number> _ # L == 0, second and later parameters
40654069// ::= fL <L-1 non-negative number> p <top-level CV-Qualifiers> _ # L > 0, first parameter
40664070// ::= 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?)
40674072template <typename Derived, typename Alloc>
40684073Node *AbstractManglingParser<Derived, Alloc>::parseFunctionParam() {
4074 if (consumeIf("fpT"))
4075 return make<NameType>("this");
40694076 if (consumeIf("fp")) {
40704077 parseCVQualifiers();
40714078 StringView Num = parseNumber();
......@@ -4225,7 +4232,13 @@ Node *AbstractManglingParser<Derived, Alloc>::parseExprPrimary() {
42254232 return getDerived().template parseFloatingLiteral<double>();
42264233 case 'e':
42274234 ++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
42284240 return getDerived().template parseFloatingLiteral<long double>();
4241#endif
42294242 case '_':
42304243 if (consumeIf("_Z")) {
42314244 Node *R = getDerived().parseEncoding();
......@@ -4264,12 +4277,12 @@ Node *AbstractManglingParser<Derived, Alloc>::parseExprPrimary() {
42644277 Node *T = getDerived().parseType();
42654278 if (T == nullptr)
42664279 return nullptr;
4267 StringView N = parseNumber();
4280 StringView N = parseNumber(/*AllowNegative=*/true);
42684281 if (N.empty())
42694282 return nullptr;
42704283 if (!consumeIf('E'))
42714284 return nullptr;
4272 return make<IntegerCastExpr>(T, N);
4285 return make<EnumLiteral>(T, N);
42734286 }
42744287 }
42754288}
......@@ -5083,6 +5096,22 @@ Node *AbstractManglingParser<Derived, Alloc>::parseSpecialName() {
50835096// ::= <special-name>
50845097template <typename Derived, typename Alloc>
50855098Node *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
50865115 if (look() == 'G' || look() == 'T')
50875116 return getDerived().parseSpecialName();
50885117
lib/libcxxabi/src/include/atomic_support.h-30
......@@ -177,34 +177,4 @@ bool __libcpp_atomic_compare_exchange(_ValueType* __val,
177177
178178_LIBCPP_END_NAMESPACE_STD
179179
180namespace {
181
182template <class IntType>
183class AtomicInt {
184public:
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
204private:
205 IntType *b;
206};
207
208} // end namespace
209
210180#endif // ATOMIC_SUPPORT_H
lib/libcxxabi/src/private_typeinfo.cpp+27-20
......@@ -8,11 +8,11 @@
88
99#include "private_typeinfo.h"
1010
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.
1414//
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
1616// there is a detected inconsistency in the type_info hierarchy during a
1717// dynamic_cast, then the equality operation will fall back to using strcmp
1818// on type_info names to determine type_info equality.
......@@ -23,7 +23,7 @@
2323// algorithm and an inconsistency is still detected, dynamic_cast will call
2424// abort with an appropriate message.
2525//
26// The current implementation of _LIBCXX_DYNAMIC_FALLBACK requires a
26// The current implementation of _LIBCXXABI_FORGIVING_DYNAMIC_CAST requires a
2727// printf-like function called syslog:
2828//
2929// void syslog(int facility_priority, const char* format, ...);
......@@ -31,21 +31,22 @@
3131// If you want this functionality but your platform doesn't have syslog,
3232// just implement it in terms of fprintf(stderr, ...).
3333//
34// _LIBCXX_DYNAMIC_FALLBACK is currently off by default.
34// _LIBCXXABI_FORGIVING_DYNAMIC_CAST is currently off by default.
3535
3636// On Windows, typeids are different between DLLs and EXEs, so comparing
3737// type_info* will work for typeids from the same compiled file but fail
3838// for typeids from a DLL and an executable. Among other things, exceptions
3939// are not caught by handlers since can_catch() returns false.
4040//
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
4242// is_equal() with use_strcmp=false so the string names are not compared.
4343
4444#include <string.h>
4545
46#ifdef _LIBCXX_DYNAMIC_FALLBACK
46#ifdef _LIBCXXABI_FORGIVING_DYNAMIC_CAST
4747#include "abort_message.h"
4848#include <sys/syslog.h>
49#include <atomic>
4950#endif
5051
5152static inline
......@@ -633,22 +634,25 @@ __dynamic_cast(const void *static_ptr, const __class_type_info *static_type,
633634 info.number_of_dst_type = 1;
634635 // Do the search
635636 dynamic_type->search_above_dst(&info, dynamic_ptr, dynamic_ptr, public_path, false);
636#ifdef _LIBCXX_DYNAMIC_FALLBACK
637#ifdef _LIBCXXABI_FORGIVING_DYNAMIC_CAST
637638 // The following if should always be false because we should definitely
638639 // find (static_ptr, static_type), either on a public or private path
639640 if (info.path_dst_ptr_to_static_ptr == unknown)
640641 {
641642 // We get here only if there is some kind of visibility problem
642643 // 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());
646650 // Redo the search comparing type_info's using strcmp
647651 info = {dst_type, static_ptr, static_type, src2dst_offset, 0};
648652 info.number_of_dst_type = 1;
649653 dynamic_type->search_above_dst(&info, dynamic_ptr, dynamic_ptr, public_path, true);
650654 }
651#endif // _LIBCXX_DYNAMIC_FALLBACK
655#endif // _LIBCXXABI_FORGIVING_DYNAMIC_CAST
652656 // Query the search.
653657 if (info.path_dst_ptr_to_static_ptr == public_path)
654658 dst_ptr = dynamic_ptr;
......@@ -657,22 +661,25 @@ __dynamic_cast(const void *static_ptr, const __class_type_info *static_type,
657661 {
658662 // Not using giant short cut. Do the search
659663 dynamic_type->search_below_dst(&info, dynamic_ptr, public_path, false);
660 #ifdef _LIBCXX_DYNAMIC_FALLBACK
664 #ifdef _LIBCXXABI_FORGIVING_DYNAMIC_CAST
661665 // The following if should always be false because we should definitely
662666 // find (static_ptr, static_type), either on a public or private path
663667 if (info.path_dst_ptr_to_static_ptr == unknown &&
664668 info.path_dynamic_ptr_to_static_ptr == unknown)
665669 {
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());
671678 // Redo the search comparing type_info's using strcmp
672679 info = {dst_type, static_ptr, static_type, src2dst_offset, 0};
673680 dynamic_type->search_below_dst(&info, dynamic_ptr, public_path, true);
674681 }
675#endif // _LIBCXX_DYNAMIC_FALLBACK
682#endif // _LIBCXXABI_FORGIVING_DYNAMIC_CAST
676683 // Query the search.
677684 switch (info.number_to_static_ptr)
678685 {
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
25void *
26operator 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
49void*
50operator 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
68void*
69operator new[](size_t size) _THROW_BAD_ALLOC
70{
71 return ::operator new(size);
72}
73
74_LIBCXXABI_WEAK
75void*
76operator 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
94void
95operator delete(void* ptr) _NOEXCEPT
96{
97 if (ptr)
98 ::free(ptr);
99}
100
101_LIBCXXABI_WEAK
102void
103operator delete(void* ptr, const std::nothrow_t&) _NOEXCEPT
104{
105 ::operator delete(ptr);
106}
107
108_LIBCXXABI_WEAK
109void
110operator delete(void* ptr, size_t) _NOEXCEPT
111{
112 ::operator delete(ptr);
113}
114
115_LIBCXXABI_WEAK
116void
117operator delete[] (void* ptr) _NOEXCEPT
118{
119 ::operator delete(ptr);
120}
121
122_LIBCXXABI_WEAK
123void
124operator delete[] (void* ptr, const std::nothrow_t&) _NOEXCEPT
125{
126 ::operator delete[](ptr);
127}
128
129_LIBCXXABI_WEAK
130void
131operator 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
139void *
140operator 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
171void*
172operator 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
190void*
191operator new[](size_t size, std::align_val_t alignment) _THROW_BAD_ALLOC
192{
193 return ::operator new(size, alignment);
194}
195
196_LIBCXXABI_WEAK
197void*
198operator 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
216void
217operator 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
228void
229operator delete(void* ptr, std::align_val_t alignment, const std::nothrow_t&) _NOEXCEPT
230{
231 ::operator delete(ptr, alignment);
232}
233
234_LIBCXXABI_WEAK
235void
236operator delete(void* ptr, size_t, std::align_val_t alignment) _NOEXCEPT
237{
238 ::operator delete(ptr, alignment);
239}
240
241_LIBCXXABI_WEAK
242void
243operator delete[] (void* ptr, std::align_val_t alignment) _NOEXCEPT
244{
245 ::operator delete(ptr, alignment);
246}
247
248_LIBCXXABI_WEAK
249void
250operator delete[] (void* ptr, std::align_val_t alignment, const std::nothrow_t&) _NOEXCEPT
251{
252 ::operator delete[](ptr, alignment);
253}
254
255_LIBCXXABI_WEAK
256void
257operator 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