xref: /freebsd-src/contrib/llvm-project/compiler-rt/lib/scudo/standalone/wrappers_cpp.cpp (revision 81ad626541db97eb356e2c1d4a20eb2a26a766ab)
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"
15*81ad6265SDimitry Andric #include "wrappers_c.h"
1668d75effSDimitry Andric 
1768d75effSDimitry Andric #include <stdint.h>
1868d75effSDimitry Andric 
1968d75effSDimitry Andric namespace std {
2068d75effSDimitry Andric struct nothrow_t {};
2168d75effSDimitry Andric enum class align_val_t : size_t {};
2268d75effSDimitry Andric } // namespace std
2368d75effSDimitry Andric 
2468d75effSDimitry Andric INTERFACE WEAK void *operator new(size_t size) {
255ffd83dbSDimitry Andric   return Allocator.allocate(size, scudo::Chunk::Origin::New);
2668d75effSDimitry Andric }
2768d75effSDimitry Andric INTERFACE WEAK void *operator new[](size_t size) {
285ffd83dbSDimitry Andric   return Allocator.allocate(size, scudo::Chunk::Origin::NewArray);
2968d75effSDimitry Andric }
3068d75effSDimitry Andric INTERFACE WEAK void *operator new(size_t size,
3168d75effSDimitry Andric                                   std::nothrow_t const &) NOEXCEPT {
325ffd83dbSDimitry Andric   return Allocator.allocate(size, scudo::Chunk::Origin::New);
3368d75effSDimitry Andric }
3468d75effSDimitry Andric INTERFACE WEAK void *operator new[](size_t size,
3568d75effSDimitry Andric                                     std::nothrow_t const &) NOEXCEPT {
365ffd83dbSDimitry Andric   return Allocator.allocate(size, scudo::Chunk::Origin::NewArray);
3768d75effSDimitry Andric }
3868d75effSDimitry Andric INTERFACE WEAK void *operator new(size_t size, std::align_val_t align) {
395ffd83dbSDimitry Andric   return Allocator.allocate(size, scudo::Chunk::Origin::New,
4068d75effSDimitry Andric                             static_cast<scudo::uptr>(align));
4168d75effSDimitry Andric }
4268d75effSDimitry Andric INTERFACE WEAK void *operator new[](size_t size, std::align_val_t align) {
435ffd83dbSDimitry Andric   return Allocator.allocate(size, scudo::Chunk::Origin::NewArray,
4468d75effSDimitry Andric                             static_cast<scudo::uptr>(align));
4568d75effSDimitry Andric }
4668d75effSDimitry Andric INTERFACE WEAK void *operator new(size_t size, std::align_val_t align,
4768d75effSDimitry Andric                                   std::nothrow_t const &) NOEXCEPT {
485ffd83dbSDimitry Andric   return Allocator.allocate(size, scudo::Chunk::Origin::New,
4968d75effSDimitry Andric                             static_cast<scudo::uptr>(align));
5068d75effSDimitry Andric }
5168d75effSDimitry Andric INTERFACE WEAK void *operator new[](size_t size, std::align_val_t align,
5268d75effSDimitry Andric                                     std::nothrow_t const &) NOEXCEPT {
535ffd83dbSDimitry Andric   return Allocator.allocate(size, scudo::Chunk::Origin::NewArray,
5468d75effSDimitry Andric                             static_cast<scudo::uptr>(align));
5568d75effSDimitry Andric }
5668d75effSDimitry Andric 
5768d75effSDimitry Andric INTERFACE WEAK void operator delete(void *ptr) NOEXCEPT {
585ffd83dbSDimitry Andric   Allocator.deallocate(ptr, scudo::Chunk::Origin::New);
5968d75effSDimitry Andric }
6068d75effSDimitry Andric INTERFACE WEAK void operator delete[](void *ptr) NOEXCEPT {
615ffd83dbSDimitry Andric   Allocator.deallocate(ptr, scudo::Chunk::Origin::NewArray);
6268d75effSDimitry Andric }
63*81ad6265SDimitry Andric INTERFACE WEAK void operator delete(void *ptr,
64*81ad6265SDimitry Andric                                     std::nothrow_t const &) NOEXCEPT {
655ffd83dbSDimitry Andric   Allocator.deallocate(ptr, scudo::Chunk::Origin::New);
6668d75effSDimitry Andric }
6768d75effSDimitry Andric INTERFACE WEAK void operator delete[](void *ptr,
6868d75effSDimitry Andric                                       std::nothrow_t const &) NOEXCEPT {
695ffd83dbSDimitry Andric   Allocator.deallocate(ptr, scudo::Chunk::Origin::NewArray);
7068d75effSDimitry Andric }
7168d75effSDimitry Andric INTERFACE WEAK void operator delete(void *ptr, size_t size) NOEXCEPT {
725ffd83dbSDimitry Andric   Allocator.deallocate(ptr, scudo::Chunk::Origin::New, size);
7368d75effSDimitry Andric }
7468d75effSDimitry Andric INTERFACE WEAK void operator delete[](void *ptr, size_t size) NOEXCEPT {
755ffd83dbSDimitry Andric   Allocator.deallocate(ptr, scudo::Chunk::Origin::NewArray, size);
7668d75effSDimitry Andric }
77*81ad6265SDimitry Andric INTERFACE WEAK void operator delete(void *ptr,
78*81ad6265SDimitry Andric                                     std::align_val_t align) NOEXCEPT {
795ffd83dbSDimitry 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 {
845ffd83dbSDimitry 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 {
895ffd83dbSDimitry 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 {
945ffd83dbSDimitry 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 {
995ffd83dbSDimitry 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 {
1045ffd83dbSDimitry 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