xref: /freebsd/contrib/llvm-project/compiler-rt/lib/scudo/standalone/wrappers_cpp.cpp (revision 3078531de10dcae44b253a35125c949ff4235284)
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 //===----------------------------------------------------------------------===//
8 
9 #include "platform.h"
10 
11 // Skip this compilation unit if compiled as part of Bionic.
12 #if !SCUDO_ANDROID || !_BIONIC
13 
14 #include "allocator_config.h"
15 
16 #include <stdint.h>
17 
18 extern "C" void malloc_postinit();
19 extern HIDDEN scudo::Allocator<scudo::Config, malloc_postinit> Allocator;
20 
21 namespace std {
22 struct nothrow_t {};
23 enum class align_val_t : size_t {};
24 } // namespace std
25 
26 INTERFACE WEAK void *operator new(size_t size) {
27   return Allocator.allocate(size, scudo::Chunk::Origin::New);
28 }
29 INTERFACE WEAK void *operator new[](size_t size) {
30   return Allocator.allocate(size, scudo::Chunk::Origin::NewArray);
31 }
32 INTERFACE WEAK void *operator new(size_t size,
33                                   std::nothrow_t const &) NOEXCEPT {
34   return Allocator.allocate(size, scudo::Chunk::Origin::New);
35 }
36 INTERFACE WEAK void *operator new[](size_t size,
37                                     std::nothrow_t const &) NOEXCEPT {
38   return Allocator.allocate(size, scudo::Chunk::Origin::NewArray);
39 }
40 INTERFACE WEAK void *operator new(size_t size, std::align_val_t align) {
41   return Allocator.allocate(size, scudo::Chunk::Origin::New,
42                             static_cast<scudo::uptr>(align));
43 }
44 INTERFACE WEAK void *operator new[](size_t size, std::align_val_t align) {
45   return Allocator.allocate(size, scudo::Chunk::Origin::NewArray,
46                             static_cast<scudo::uptr>(align));
47 }
48 INTERFACE WEAK void *operator new(size_t size, std::align_val_t align,
49                                   std::nothrow_t const &) NOEXCEPT {
50   return Allocator.allocate(size, scudo::Chunk::Origin::New,
51                             static_cast<scudo::uptr>(align));
52 }
53 INTERFACE WEAK void *operator new[](size_t size, std::align_val_t align,
54                                     std::nothrow_t const &) NOEXCEPT {
55   return Allocator.allocate(size, scudo::Chunk::Origin::NewArray,
56                             static_cast<scudo::uptr>(align));
57 }
58 
59 INTERFACE WEAK void operator delete(void *ptr)NOEXCEPT {
60   Allocator.deallocate(ptr, scudo::Chunk::Origin::New);
61 }
62 INTERFACE WEAK void operator delete[](void *ptr) NOEXCEPT {
63   Allocator.deallocate(ptr, scudo::Chunk::Origin::NewArray);
64 }
65 INTERFACE WEAK void operator delete(void *ptr, std::nothrow_t const &)NOEXCEPT {
66   Allocator.deallocate(ptr, scudo::Chunk::Origin::New);
67 }
68 INTERFACE WEAK void operator delete[](void *ptr,
69                                       std::nothrow_t const &) NOEXCEPT {
70   Allocator.deallocate(ptr, scudo::Chunk::Origin::NewArray);
71 }
72 INTERFACE WEAK void operator delete(void *ptr, size_t size)NOEXCEPT {
73   Allocator.deallocate(ptr, scudo::Chunk::Origin::New, size);
74 }
75 INTERFACE WEAK void operator delete[](void *ptr, size_t size) NOEXCEPT {
76   Allocator.deallocate(ptr, scudo::Chunk::Origin::NewArray, size);
77 }
78 INTERFACE WEAK void operator delete(void *ptr, std::align_val_t align)NOEXCEPT {
79   Allocator.deallocate(ptr, scudo::Chunk::Origin::New, 0,
80                        static_cast<scudo::uptr>(align));
81 }
82 INTERFACE WEAK void operator delete[](void *ptr,
83                                       std::align_val_t align) NOEXCEPT {
84   Allocator.deallocate(ptr, scudo::Chunk::Origin::NewArray, 0,
85                        static_cast<scudo::uptr>(align));
86 }
87 INTERFACE WEAK void operator delete(void *ptr, std::align_val_t align,
88                                     std::nothrow_t const &)NOEXCEPT {
89   Allocator.deallocate(ptr, scudo::Chunk::Origin::New, 0,
90                        static_cast<scudo::uptr>(align));
91 }
92 INTERFACE WEAK void operator delete[](void *ptr, std::align_val_t align,
93                                       std::nothrow_t const &) NOEXCEPT {
94   Allocator.deallocate(ptr, scudo::Chunk::Origin::NewArray, 0,
95                        static_cast<scudo::uptr>(align));
96 }
97 INTERFACE WEAK void operator delete(void *ptr, size_t size,
98                                     std::align_val_t align)NOEXCEPT {
99   Allocator.deallocate(ptr, scudo::Chunk::Origin::New, size,
100                        static_cast<scudo::uptr>(align));
101 }
102 INTERFACE WEAK void operator delete[](void *ptr, size_t size,
103                                       std::align_val_t align) NOEXCEPT {
104   Allocator.deallocate(ptr, scudo::Chunk::Origin::NewArray, size,
105                        static_cast<scudo::uptr>(align));
106 }
107 
108 #endif // !SCUDO_ANDROID || !_BIONIC
109