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
operator new(size_t size)26 INTERFACE WEAK void *operator new(size_t size) {
27 return Allocator.allocate(size, scudo::Chunk::Origin::New);
28 }
operator new[](size_t size)29 INTERFACE WEAK void *operator new[](size_t size) {
30 return Allocator.allocate(size, scudo::Chunk::Origin::NewArray);
31 }
operator new(size_t size,std::nothrow_t const &)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 }
operator new[](size_t size,std::nothrow_t const &)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 }
operator new(size_t size,std::align_val_t align)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 }
operator new[](size_t size,std::align_val_t align)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 }
operator new(size_t size,std::align_val_t align,std::nothrow_t const &)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 }
operator new[](size_t size,std::align_val_t align,std::nothrow_t const &)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
operator delete(void * ptr)59 INTERFACE WEAK void operator delete(void *ptr)NOEXCEPT {
60 Allocator.deallocate(ptr, scudo::Chunk::Origin::New);
61 }
operator delete[](void * ptr)62 INTERFACE WEAK void operator delete[](void *ptr) NOEXCEPT {
63 Allocator.deallocate(ptr, scudo::Chunk::Origin::NewArray);
64 }
operator delete(void * ptr,std::nothrow_t const &)65 INTERFACE WEAK void operator delete(void *ptr, std::nothrow_t const &)NOEXCEPT {
66 Allocator.deallocate(ptr, scudo::Chunk::Origin::New);
67 }
operator delete[](void * ptr,std::nothrow_t const &)68 INTERFACE WEAK void operator delete[](void *ptr,
69 std::nothrow_t const &) NOEXCEPT {
70 Allocator.deallocate(ptr, scudo::Chunk::Origin::NewArray);
71 }
operator delete(void * ptr,size_t size)72 INTERFACE WEAK void operator delete(void *ptr, size_t size)NOEXCEPT {
73 Allocator.deallocate(ptr, scudo::Chunk::Origin::New, size);
74 }
operator delete[](void * ptr,size_t size)75 INTERFACE WEAK void operator delete[](void *ptr, size_t size) NOEXCEPT {
76 Allocator.deallocate(ptr, scudo::Chunk::Origin::NewArray, size);
77 }
operator delete(void * ptr,std::align_val_t align)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 }
operator delete[](void * ptr,std::align_val_t align)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 }
operator delete(void * ptr,std::align_val_t align,std::nothrow_t const &)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 }
operator delete[](void * ptr,std::align_val_t align,std::nothrow_t const &)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 }
operator delete(void * ptr,size_t size,std::align_val_t align)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 }
operator delete[](void * ptr,size_t size,std::align_val_t align)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