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 #include "wrappers_c.h"
16 
17 #include <stdint.h>
18 
19 namespace std {
20 struct nothrow_t {};
21 enum class align_val_t : size_t {};
22 } // namespace std
23 
24 INTERFACE WEAK void *operator new(size_t size) {
25   return Allocator.allocate(size, scudo::Chunk::Origin::New);
26 }
27 INTERFACE WEAK void *operator new[](size_t size) {
28   return Allocator.allocate(size, scudo::Chunk::Origin::NewArray);
29 }
30 INTERFACE WEAK void *operator new(size_t size,
31                                   std::nothrow_t const &) NOEXCEPT {
32   return Allocator.allocate(size, scudo::Chunk::Origin::New);
33 }
34 INTERFACE WEAK void *operator new[](size_t size,
35                                     std::nothrow_t const &) NOEXCEPT {
36   return Allocator.allocate(size, scudo::Chunk::Origin::NewArray);
37 }
38 INTERFACE WEAK void *operator new(size_t size, std::align_val_t align) {
39   return Allocator.allocate(size, scudo::Chunk::Origin::New,
40                             static_cast<scudo::uptr>(align));
41 }
42 INTERFACE WEAK void *operator new[](size_t size, std::align_val_t align) {
43   return Allocator.allocate(size, scudo::Chunk::Origin::NewArray,
44                             static_cast<scudo::uptr>(align));
45 }
46 INTERFACE WEAK void *operator new(size_t size, std::align_val_t align,
47                                   std::nothrow_t const &) NOEXCEPT {
48   return Allocator.allocate(size, scudo::Chunk::Origin::New,
49                             static_cast<scudo::uptr>(align));
50 }
51 INTERFACE WEAK void *operator new[](size_t size, std::align_val_t align,
52                                     std::nothrow_t const &) NOEXCEPT {
53   return Allocator.allocate(size, scudo::Chunk::Origin::NewArray,
54                             static_cast<scudo::uptr>(align));
55 }
56 
57 INTERFACE WEAK void operator delete(void *ptr) NOEXCEPT {
58   Allocator.deallocate(ptr, scudo::Chunk::Origin::New);
59 }
60 INTERFACE WEAK void operator delete[](void *ptr) NOEXCEPT {
61   Allocator.deallocate(ptr, scudo::Chunk::Origin::NewArray);
62 }
63 INTERFACE WEAK void operator delete(void *ptr,
64                                     std::nothrow_t const &) NOEXCEPT {
65   Allocator.deallocate(ptr, scudo::Chunk::Origin::New);
66 }
67 INTERFACE WEAK void operator delete[](void *ptr,
68                                       std::nothrow_t const &) NOEXCEPT {
69   Allocator.deallocate(ptr, scudo::Chunk::Origin::NewArray);
70 }
71 INTERFACE WEAK void operator delete(void *ptr, size_t size) NOEXCEPT {
72   Allocator.deallocate(ptr, scudo::Chunk::Origin::New, size);
73 }
74 INTERFACE WEAK void operator delete[](void *ptr, size_t size) NOEXCEPT {
75   Allocator.deallocate(ptr, scudo::Chunk::Origin::NewArray, size);
76 }
77 INTERFACE WEAK void operator delete(void *ptr,
78                                     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