[Clang][SME2] Enable multi-vector loads & stores for SME2 (#75821)
[llvm-project.git] / compiler-rt / lib / scudo / standalone / wrappers_cpp.cpp
blob098d4f71acc4afc9e4f2d146c4e75ccd14c3d07c
1 //===-- wrappers_cpp.cpp ----------------------------------------*- C++ -*-===//
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 //===----------------------------------------------------------------------===//
9 #include "platform.h"
11 // Skip this compilation unit if compiled as part of Bionic.
12 #if !SCUDO_ANDROID || !_BIONIC
14 #include "allocator_config.h"
15 #include "internal_defs.h"
16 #include "platform.h"
17 #include "scudo/interface.h"
18 #include "wrappers_c.h"
20 #include <stdint.h>
22 namespace std {
23 struct nothrow_t {};
24 enum class align_val_t : size_t {};
25 } // namespace std
27 static void reportAllocation(void *ptr, size_t size) {
28 if (SCUDO_ENABLE_HOOKS)
29 if (__scudo_allocate_hook && ptr)
30 __scudo_allocate_hook(ptr, size);
32 static void reportDeallocation(void *ptr) {
33 if (SCUDO_ENABLE_HOOKS)
34 if (__scudo_deallocate_hook)
35 __scudo_deallocate_hook(ptr);
38 INTERFACE WEAK void *operator new(size_t size) {
39 void *Ptr = Allocator.allocate(size, scudo::Chunk::Origin::New);
40 reportAllocation(Ptr, size);
41 return Ptr;
43 INTERFACE WEAK void *operator new[](size_t size) {
44 void *Ptr = Allocator.allocate(size, scudo::Chunk::Origin::NewArray);
45 reportAllocation(Ptr, size);
46 return Ptr;
48 INTERFACE WEAK void *operator new(size_t size,
49 std::nothrow_t const &) NOEXCEPT {
50 void *Ptr = Allocator.allocate(size, scudo::Chunk::Origin::New);
51 reportAllocation(Ptr, size);
52 return Ptr;
54 INTERFACE WEAK void *operator new[](size_t size,
55 std::nothrow_t const &) NOEXCEPT {
56 void *Ptr = Allocator.allocate(size, scudo::Chunk::Origin::NewArray);
57 reportAllocation(Ptr, size);
58 return Ptr;
60 INTERFACE WEAK void *operator new(size_t size, std::align_val_t align) {
61 void *Ptr = Allocator.allocate(size, scudo::Chunk::Origin::New,
62 static_cast<scudo::uptr>(align));
63 reportAllocation(Ptr, size);
64 return Ptr;
66 INTERFACE WEAK void *operator new[](size_t size, std::align_val_t align) {
67 void *Ptr = Allocator.allocate(size, scudo::Chunk::Origin::NewArray,
68 static_cast<scudo::uptr>(align));
69 reportAllocation(Ptr, size);
70 return Ptr;
72 INTERFACE WEAK void *operator new(size_t size, std::align_val_t align,
73 std::nothrow_t const &) NOEXCEPT {
74 void *Ptr = Allocator.allocate(size, scudo::Chunk::Origin::New,
75 static_cast<scudo::uptr>(align));
76 reportAllocation(Ptr, size);
77 return Ptr;
79 INTERFACE WEAK void *operator new[](size_t size, std::align_val_t align,
80 std::nothrow_t const &) NOEXCEPT {
81 void *Ptr = Allocator.allocate(size, scudo::Chunk::Origin::NewArray,
82 static_cast<scudo::uptr>(align));
83 reportAllocation(Ptr, size);
84 return Ptr;
87 INTERFACE WEAK void operator delete(void *ptr) NOEXCEPT {
88 reportDeallocation(ptr);
89 Allocator.deallocate(ptr, scudo::Chunk::Origin::New);
91 INTERFACE WEAK void operator delete[](void *ptr) NOEXCEPT {
92 reportDeallocation(ptr);
93 Allocator.deallocate(ptr, scudo::Chunk::Origin::NewArray);
95 INTERFACE WEAK void operator delete(void *ptr,
96 std::nothrow_t const &) NOEXCEPT {
97 reportDeallocation(ptr);
98 Allocator.deallocate(ptr, scudo::Chunk::Origin::New);
100 INTERFACE WEAK void operator delete[](void *ptr,
101 std::nothrow_t const &) NOEXCEPT {
102 reportDeallocation(ptr);
103 Allocator.deallocate(ptr, scudo::Chunk::Origin::NewArray);
105 INTERFACE WEAK void operator delete(void *ptr, size_t size) NOEXCEPT {
106 reportDeallocation(ptr);
107 Allocator.deallocate(ptr, scudo::Chunk::Origin::New, size);
109 INTERFACE WEAK void operator delete[](void *ptr, size_t size) NOEXCEPT {
110 reportDeallocation(ptr);
111 Allocator.deallocate(ptr, scudo::Chunk::Origin::NewArray, size);
113 INTERFACE WEAK void operator delete(void *ptr,
114 std::align_val_t align) NOEXCEPT {
115 reportDeallocation(ptr);
116 Allocator.deallocate(ptr, scudo::Chunk::Origin::New, 0,
117 static_cast<scudo::uptr>(align));
119 INTERFACE WEAK void operator delete[](void *ptr,
120 std::align_val_t align) NOEXCEPT {
121 reportDeallocation(ptr);
122 Allocator.deallocate(ptr, scudo::Chunk::Origin::NewArray, 0,
123 static_cast<scudo::uptr>(align));
125 INTERFACE WEAK void operator delete(void *ptr, std::align_val_t align,
126 std::nothrow_t const &) NOEXCEPT {
127 reportDeallocation(ptr);
128 Allocator.deallocate(ptr, scudo::Chunk::Origin::New, 0,
129 static_cast<scudo::uptr>(align));
131 INTERFACE WEAK void operator delete[](void *ptr, std::align_val_t align,
132 std::nothrow_t const &) NOEXCEPT {
133 reportDeallocation(ptr);
134 Allocator.deallocate(ptr, scudo::Chunk::Origin::NewArray, 0,
135 static_cast<scudo::uptr>(align));
137 INTERFACE WEAK void operator delete(void *ptr, size_t size,
138 std::align_val_t align) NOEXCEPT {
139 reportDeallocation(ptr);
140 Allocator.deallocate(ptr, scudo::Chunk::Origin::New, size,
141 static_cast<scudo::uptr>(align));
143 INTERFACE WEAK void operator delete[](void *ptr, size_t size,
144 std::align_val_t align) NOEXCEPT {
145 reportDeallocation(ptr);
146 Allocator.deallocate(ptr, scudo::Chunk::Origin::NewArray, size,
147 static_cast<scudo::uptr>(align));
150 #endif // !SCUDO_ANDROID || !_BIONIC