xref: /freebsd-src/contrib/llvm-project/compiler-rt/lib/scudo/standalone/wrappers_cpp.cpp (revision 5ffd83dbcc34f10e07f6d3e968ae6365869615f4)
168d75effSDimitry Andric //===-- wrappers_cpp.cpp ----------------------------------------*- C++ -*-===//
268d75effSDimitry Andric //
368d75effSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
468d75effSDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
568d75effSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
668d75effSDimitry Andric //
768d75effSDimitry Andric //===----------------------------------------------------------------------===//
868d75effSDimitry Andric 
968d75effSDimitry Andric #include "platform.h"
1068d75effSDimitry Andric 
1168d75effSDimitry Andric // Skip this compilation unit if compiled as part of Bionic.
1268d75effSDimitry Andric #if !SCUDO_ANDROID || !_BIONIC
1368d75effSDimitry Andric 
1468d75effSDimitry Andric #include "allocator_config.h"
1568d75effSDimitry Andric 
1668d75effSDimitry Andric #include <stdint.h>
1768d75effSDimitry Andric 
18480093f4SDimitry Andric extern "C" void malloc_postinit();
19*5ffd83dbSDimitry Andric extern HIDDEN scudo::Allocator<scudo::Config, malloc_postinit> Allocator;
2068d75effSDimitry Andric 
2168d75effSDimitry Andric namespace std {
2268d75effSDimitry Andric struct nothrow_t {};
2368d75effSDimitry Andric enum class align_val_t : size_t {};
2468d75effSDimitry Andric } // namespace std
2568d75effSDimitry Andric 
2668d75effSDimitry Andric INTERFACE WEAK void *operator new(size_t size) {
27*5ffd83dbSDimitry Andric   return Allocator.allocate(size, scudo::Chunk::Origin::New);
2868d75effSDimitry Andric }
2968d75effSDimitry Andric INTERFACE WEAK void *operator new[](size_t size) {
30*5ffd83dbSDimitry Andric   return Allocator.allocate(size, scudo::Chunk::Origin::NewArray);
3168d75effSDimitry Andric }
3268d75effSDimitry Andric INTERFACE WEAK void *operator new(size_t size,
3368d75effSDimitry Andric                                   std::nothrow_t const &) NOEXCEPT {
34*5ffd83dbSDimitry Andric   return Allocator.allocate(size, scudo::Chunk::Origin::New);
3568d75effSDimitry Andric }
3668d75effSDimitry Andric INTERFACE WEAK void *operator new[](size_t size,
3768d75effSDimitry Andric                                     std::nothrow_t const &) NOEXCEPT {
38*5ffd83dbSDimitry Andric   return Allocator.allocate(size, scudo::Chunk::Origin::NewArray);
3968d75effSDimitry Andric }
4068d75effSDimitry Andric INTERFACE WEAK void *operator new(size_t size, std::align_val_t align) {
41*5ffd83dbSDimitry Andric   return Allocator.allocate(size, scudo::Chunk::Origin::New,
4268d75effSDimitry Andric                             static_cast<scudo::uptr>(align));
4368d75effSDimitry Andric }
4468d75effSDimitry Andric INTERFACE WEAK void *operator new[](size_t size, std::align_val_t align) {
45*5ffd83dbSDimitry Andric   return Allocator.allocate(size, scudo::Chunk::Origin::NewArray,
4668d75effSDimitry Andric                             static_cast<scudo::uptr>(align));
4768d75effSDimitry Andric }
4868d75effSDimitry Andric INTERFACE WEAK void *operator new(size_t size, std::align_val_t align,
4968d75effSDimitry Andric                                   std::nothrow_t const &) NOEXCEPT {
50*5ffd83dbSDimitry Andric   return Allocator.allocate(size, scudo::Chunk::Origin::New,
5168d75effSDimitry Andric                             static_cast<scudo::uptr>(align));
5268d75effSDimitry Andric }
5368d75effSDimitry Andric INTERFACE WEAK void *operator new[](size_t size, std::align_val_t align,
5468d75effSDimitry Andric                                     std::nothrow_t const &) NOEXCEPT {
55*5ffd83dbSDimitry Andric   return Allocator.allocate(size, scudo::Chunk::Origin::NewArray,
5668d75effSDimitry Andric                             static_cast<scudo::uptr>(align));
5768d75effSDimitry Andric }
5868d75effSDimitry Andric 
5968d75effSDimitry Andric INTERFACE WEAK void operator delete(void *ptr)NOEXCEPT {
60*5ffd83dbSDimitry Andric   Allocator.deallocate(ptr, scudo::Chunk::Origin::New);
6168d75effSDimitry Andric }
6268d75effSDimitry Andric INTERFACE WEAK void operator delete[](void *ptr) NOEXCEPT {
63*5ffd83dbSDimitry Andric   Allocator.deallocate(ptr, scudo::Chunk::Origin::NewArray);
6468d75effSDimitry Andric }
6568d75effSDimitry Andric INTERFACE WEAK void operator delete(void *ptr, std::nothrow_t const &)NOEXCEPT {
66*5ffd83dbSDimitry Andric   Allocator.deallocate(ptr, scudo::Chunk::Origin::New);
6768d75effSDimitry Andric }
6868d75effSDimitry Andric INTERFACE WEAK void operator delete[](void *ptr,
6968d75effSDimitry Andric                                       std::nothrow_t const &) NOEXCEPT {
70*5ffd83dbSDimitry Andric   Allocator.deallocate(ptr, scudo::Chunk::Origin::NewArray);
7168d75effSDimitry Andric }
7268d75effSDimitry Andric INTERFACE WEAK void operator delete(void *ptr, size_t size)NOEXCEPT {
73*5ffd83dbSDimitry Andric   Allocator.deallocate(ptr, scudo::Chunk::Origin::New, size);
7468d75effSDimitry Andric }
7568d75effSDimitry Andric INTERFACE WEAK void operator delete[](void *ptr, size_t size) NOEXCEPT {
76*5ffd83dbSDimitry Andric   Allocator.deallocate(ptr, scudo::Chunk::Origin::NewArray, size);
7768d75effSDimitry Andric }
7868d75effSDimitry Andric INTERFACE WEAK void operator delete(void *ptr, std::align_val_t align)NOEXCEPT {
79*5ffd83dbSDimitry Andric   Allocator.deallocate(ptr, scudo::Chunk::Origin::New, 0,
8068d75effSDimitry Andric                        static_cast<scudo::uptr>(align));
8168d75effSDimitry Andric }
8268d75effSDimitry Andric INTERFACE WEAK void operator delete[](void *ptr,
8368d75effSDimitry Andric                                       std::align_val_t align) NOEXCEPT {
84*5ffd83dbSDimitry Andric   Allocator.deallocate(ptr, scudo::Chunk::Origin::NewArray, 0,
8568d75effSDimitry Andric                        static_cast<scudo::uptr>(align));
8668d75effSDimitry Andric }
8768d75effSDimitry Andric INTERFACE WEAK void operator delete(void *ptr, std::align_val_t align,
8868d75effSDimitry Andric                                     std::nothrow_t const &)NOEXCEPT {
89*5ffd83dbSDimitry Andric   Allocator.deallocate(ptr, scudo::Chunk::Origin::New, 0,
9068d75effSDimitry Andric                        static_cast<scudo::uptr>(align));
9168d75effSDimitry Andric }
9268d75effSDimitry Andric INTERFACE WEAK void operator delete[](void *ptr, std::align_val_t align,
9368d75effSDimitry Andric                                       std::nothrow_t const &) NOEXCEPT {
94*5ffd83dbSDimitry Andric   Allocator.deallocate(ptr, scudo::Chunk::Origin::NewArray, 0,
9568d75effSDimitry Andric                        static_cast<scudo::uptr>(align));
9668d75effSDimitry Andric }
9768d75effSDimitry Andric INTERFACE WEAK void operator delete(void *ptr, size_t size,
9868d75effSDimitry Andric                                     std::align_val_t align)NOEXCEPT {
99*5ffd83dbSDimitry Andric   Allocator.deallocate(ptr, scudo::Chunk::Origin::New, size,
10068d75effSDimitry Andric                        static_cast<scudo::uptr>(align));
10168d75effSDimitry Andric }
10268d75effSDimitry Andric INTERFACE WEAK void operator delete[](void *ptr, size_t size,
10368d75effSDimitry Andric                                       std::align_val_t align) NOEXCEPT {
104*5ffd83dbSDimitry Andric   Allocator.deallocate(ptr, scudo::Chunk::Origin::NewArray, size,
10568d75effSDimitry Andric                        static_cast<scudo::uptr>(align));
10668d75effSDimitry Andric }
10768d75effSDimitry Andric 
10868d75effSDimitry Andric #endif // !SCUDO_ANDROID || !_BIONIC
109