blob: 72235e9c98209528d179fdccc0fc57f1107ae538 [file] [log] [blame]
Dynamic Tools Team517193e2019-09-11 14:48:41 +00001//===-- 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
18extern scudo::Allocator<scudo::Config> *AllocatorPtr;
19
20namespace std {
21struct nothrow_t {};
22enum class align_val_t : size_t {};
23} // namespace std
24
25INTERFACE WEAK void *operator new(size_t size) {
26 return AllocatorPtr->allocate(size, scudo::Chunk::Origin::New);
27}
28INTERFACE WEAK void *operator new[](size_t size) {
29 return AllocatorPtr->allocate(size, scudo::Chunk::Origin::NewArray);
30}
31INTERFACE WEAK void *operator new(size_t size,
32 std::nothrow_t const &) NOEXCEPT {
33 return AllocatorPtr->allocate(size, scudo::Chunk::Origin::New);
34}
35INTERFACE WEAK void *operator new[](size_t size,
36 std::nothrow_t const &) NOEXCEPT {
37 return AllocatorPtr->allocate(size, scudo::Chunk::Origin::NewArray);
38}
39INTERFACE WEAK void *operator new(size_t size, std::align_val_t align) {
40 return AllocatorPtr->allocate(size, scudo::Chunk::Origin::New,
41 static_cast<scudo::uptr>(align));
42}
43INTERFACE WEAK void *operator new[](size_t size, std::align_val_t align) {
44 return AllocatorPtr->allocate(size, scudo::Chunk::Origin::NewArray,
45 static_cast<scudo::uptr>(align));
46}
47INTERFACE WEAK void *operator new(size_t size, std::align_val_t align,
48 std::nothrow_t const &) NOEXCEPT {
49 return AllocatorPtr->allocate(size, scudo::Chunk::Origin::New,
50 static_cast<scudo::uptr>(align));
51}
52INTERFACE WEAK void *operator new[](size_t size, std::align_val_t align,
53 std::nothrow_t const &) NOEXCEPT {
54 return AllocatorPtr->allocate(size, scudo::Chunk::Origin::NewArray,
55 static_cast<scudo::uptr>(align));
56}
57
58INTERFACE WEAK void operator delete(void *ptr)NOEXCEPT {
59 AllocatorPtr->deallocate(ptr, scudo::Chunk::Origin::New);
60}
61INTERFACE WEAK void operator delete[](void *ptr) NOEXCEPT {
62 AllocatorPtr->deallocate(ptr, scudo::Chunk::Origin::NewArray);
63}
64INTERFACE WEAK void operator delete(void *ptr, std::nothrow_t const &)NOEXCEPT {
65 AllocatorPtr->deallocate(ptr, scudo::Chunk::Origin::New);
66}
67INTERFACE WEAK void operator delete[](void *ptr,
68 std::nothrow_t const &) NOEXCEPT {
69 AllocatorPtr->deallocate(ptr, scudo::Chunk::Origin::NewArray);
70}
71INTERFACE WEAK void operator delete(void *ptr, size_t size)NOEXCEPT {
72 AllocatorPtr->deallocate(ptr, scudo::Chunk::Origin::New, size);
73}
74INTERFACE WEAK void operator delete[](void *ptr, size_t size) NOEXCEPT {
75 AllocatorPtr->deallocate(ptr, scudo::Chunk::Origin::NewArray, size);
76}
77INTERFACE WEAK void operator delete(void *ptr, std::align_val_t align)NOEXCEPT {
78 AllocatorPtr->deallocate(ptr, scudo::Chunk::Origin::New, 0,
79 static_cast<scudo::uptr>(align));
80}
81INTERFACE WEAK void operator delete[](void *ptr,
82 std::align_val_t align) NOEXCEPT {
83 AllocatorPtr->deallocate(ptr, scudo::Chunk::Origin::NewArray, 0,
84 static_cast<scudo::uptr>(align));
85}
86INTERFACE WEAK void operator delete(void *ptr, std::align_val_t align,
87 std::nothrow_t const &)NOEXCEPT {
88 AllocatorPtr->deallocate(ptr, scudo::Chunk::Origin::New, 0,
89 static_cast<scudo::uptr>(align));
90}
91INTERFACE WEAK void operator delete[](void *ptr, std::align_val_t align,
92 std::nothrow_t const &) NOEXCEPT {
93 AllocatorPtr->deallocate(ptr, scudo::Chunk::Origin::NewArray, 0,
94 static_cast<scudo::uptr>(align));
95}
96INTERFACE WEAK void operator delete(void *ptr, size_t size,
97 std::align_val_t align)NOEXCEPT {
98 AllocatorPtr->deallocate(ptr, scudo::Chunk::Origin::New, size,
99 static_cast<scudo::uptr>(align));
100}
101INTERFACE WEAK void operator delete[](void *ptr, size_t size,
102 std::align_val_t align) NOEXCEPT {
103 AllocatorPtr->deallocate(ptr, scudo::Chunk::Origin::NewArray, size,
104 static_cast<scudo::uptr>(align));
105}
106
107#endif // !SCUDO_ANDROID || !_BIONIC