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, std::nothrow_t const &)NOEXCEPT { 64 Allocator.deallocate(ptr, scudo::Chunk::Origin::New); 65 } 66 INTERFACE WEAK void operator delete[](void *ptr, 67 std::nothrow_t const &) NOEXCEPT { 68 Allocator.deallocate(ptr, scudo::Chunk::Origin::NewArray); 69 } 70 INTERFACE WEAK void operator delete(void *ptr, size_t size)NOEXCEPT { 71 Allocator.deallocate(ptr, scudo::Chunk::Origin::New, size); 72 } 73 INTERFACE WEAK void operator delete[](void *ptr, size_t size) NOEXCEPT { 74 Allocator.deallocate(ptr, scudo::Chunk::Origin::NewArray, size); 75 } 76 INTERFACE WEAK void operator delete(void *ptr, std::align_val_t align)NOEXCEPT { 77 Allocator.deallocate(ptr, scudo::Chunk::Origin::New, 0, 78 static_cast<scudo::uptr>(align)); 79 } 80 INTERFACE WEAK void operator delete[](void *ptr, 81 std::align_val_t align) NOEXCEPT { 82 Allocator.deallocate(ptr, scudo::Chunk::Origin::NewArray, 0, 83 static_cast<scudo::uptr>(align)); 84 } 85 INTERFACE WEAK void operator delete(void *ptr, std::align_val_t align, 86 std::nothrow_t const &)NOEXCEPT { 87 Allocator.deallocate(ptr, scudo::Chunk::Origin::New, 0, 88 static_cast<scudo::uptr>(align)); 89 } 90 INTERFACE WEAK void operator delete[](void *ptr, std::align_val_t align, 91 std::nothrow_t const &) NOEXCEPT { 92 Allocator.deallocate(ptr, scudo::Chunk::Origin::NewArray, 0, 93 static_cast<scudo::uptr>(align)); 94 } 95 INTERFACE WEAK void operator delete(void *ptr, size_t size, 96 std::align_val_t align)NOEXCEPT { 97 Allocator.deallocate(ptr, scudo::Chunk::Origin::New, size, 98 static_cast<scudo::uptr>(align)); 99 } 100 INTERFACE WEAK void operator delete[](void *ptr, size_t size, 101 std::align_val_t align) NOEXCEPT { 102 Allocator.deallocate(ptr, scudo::Chunk::Origin::NewArray, size, 103 static_cast<scudo::uptr>(align)); 104 } 105 106 #endif // !SCUDO_ANDROID || !_BIONIC 107