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
19namespace std {
20struct nothrow_t {};
21enum class align_val_t : size_t {};
22} // namespace std
23
24INTERFACE WEAK void *operator new(size_t size) {
25  return Allocator.allocate(size, scudo::Chunk::Origin::New);
26}
27INTERFACE WEAK void *operator new[](size_t size) {
28  return Allocator.allocate(size, scudo::Chunk::Origin::NewArray);
29}
30INTERFACE WEAK void *operator new(size_t size,
31                                  std::nothrow_t const &) NOEXCEPT {
32  return Allocator.allocate(size, scudo::Chunk::Origin::New);
33}
34INTERFACE WEAK void *operator new[](size_t size,
35                                    std::nothrow_t const &) NOEXCEPT {
36  return Allocator.allocate(size, scudo::Chunk::Origin::NewArray);
37}
38INTERFACE 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}
42INTERFACE 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}
46INTERFACE 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}
51INTERFACE 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
57INTERFACE WEAK void operator delete(void *ptr) NOEXCEPT {
58  Allocator.deallocate(ptr, scudo::Chunk::Origin::New);
59}
60INTERFACE WEAK void operator delete[](void *ptr) NOEXCEPT {
61  Allocator.deallocate(ptr, scudo::Chunk::Origin::NewArray);
62}
63INTERFACE WEAK void operator delete(void *ptr,
64                                    std::nothrow_t const &) NOEXCEPT {
65  Allocator.deallocate(ptr, scudo::Chunk::Origin::New);
66}
67INTERFACE WEAK void operator delete[](void *ptr,
68                                      std::nothrow_t const &) NOEXCEPT {
69  Allocator.deallocate(ptr, scudo::Chunk::Origin::NewArray);
70}
71INTERFACE WEAK void operator delete(void *ptr, size_t size) NOEXCEPT {
72  Allocator.deallocate(ptr, scudo::Chunk::Origin::New, size);
73}
74INTERFACE WEAK void operator delete[](void *ptr, size_t size) NOEXCEPT {
75  Allocator.deallocate(ptr, scudo::Chunk::Origin::NewArray, size);
76}
77INTERFACE 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}
82INTERFACE 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}
87INTERFACE 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}
92INTERFACE 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}
97INTERFACE 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}
102INTERFACE 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