1*7c3d14c8STreehugger Robot //===-- scudo_new_delete.cpp ------------------------------------*- C++ -*-===//
2*7c3d14c8STreehugger Robot //
3*7c3d14c8STreehugger Robot // The LLVM Compiler Infrastructure
4*7c3d14c8STreehugger Robot //
5*7c3d14c8STreehugger Robot // This file is distributed under the University of Illinois Open Source
6*7c3d14c8STreehugger Robot // License. See LICENSE.TXT for details.
7*7c3d14c8STreehugger Robot //
8*7c3d14c8STreehugger Robot //===----------------------------------------------------------------------===//
9*7c3d14c8STreehugger Robot ///
10*7c3d14c8STreehugger Robot /// Interceptors for operators new and delete.
11*7c3d14c8STreehugger Robot ///
12*7c3d14c8STreehugger Robot //===----------------------------------------------------------------------===//
13*7c3d14c8STreehugger Robot
14*7c3d14c8STreehugger Robot #include "scudo_allocator.h"
15*7c3d14c8STreehugger Robot
16*7c3d14c8STreehugger Robot #include "interception/interception.h"
17*7c3d14c8STreehugger Robot
18*7c3d14c8STreehugger Robot #include <cstddef>
19*7c3d14c8STreehugger Robot
20*7c3d14c8STreehugger Robot using namespace __scudo;
21*7c3d14c8STreehugger Robot
22*7c3d14c8STreehugger Robot #define CXX_OPERATOR_ATTRIBUTE INTERCEPTOR_ATTRIBUTE
23*7c3d14c8STreehugger Robot
24*7c3d14c8STreehugger Robot // Fake std::nothrow_t to avoid including <new>.
25*7c3d14c8STreehugger Robot namespace std {
26*7c3d14c8STreehugger Robot struct nothrow_t {};
27*7c3d14c8STreehugger Robot } // namespace std
28*7c3d14c8STreehugger Robot
29*7c3d14c8STreehugger Robot CXX_OPERATOR_ATTRIBUTE
operator new(size_t size)30*7c3d14c8STreehugger Robot void *operator new(size_t size) {
31*7c3d14c8STreehugger Robot return scudoMalloc(size, FromNew);
32*7c3d14c8STreehugger Robot }
33*7c3d14c8STreehugger Robot CXX_OPERATOR_ATTRIBUTE
operator new[](size_t size)34*7c3d14c8STreehugger Robot void *operator new[](size_t size) {
35*7c3d14c8STreehugger Robot return scudoMalloc(size, FromNewArray);
36*7c3d14c8STreehugger Robot }
37*7c3d14c8STreehugger Robot CXX_OPERATOR_ATTRIBUTE
operator new(size_t size,std::nothrow_t const &)38*7c3d14c8STreehugger Robot void *operator new(size_t size, std::nothrow_t const&) {
39*7c3d14c8STreehugger Robot return scudoMalloc(size, FromNew);
40*7c3d14c8STreehugger Robot }
41*7c3d14c8STreehugger Robot CXX_OPERATOR_ATTRIBUTE
operator new[](size_t size,std::nothrow_t const &)42*7c3d14c8STreehugger Robot void *operator new[](size_t size, std::nothrow_t const&) {
43*7c3d14c8STreehugger Robot return scudoMalloc(size, FromNewArray);
44*7c3d14c8STreehugger Robot }
45*7c3d14c8STreehugger Robot
46*7c3d14c8STreehugger Robot CXX_OPERATOR_ATTRIBUTE
operator delete(void * ptr)47*7c3d14c8STreehugger Robot void operator delete(void *ptr) NOEXCEPT {
48*7c3d14c8STreehugger Robot return scudoFree(ptr, FromNew);
49*7c3d14c8STreehugger Robot }
50*7c3d14c8STreehugger Robot CXX_OPERATOR_ATTRIBUTE
operator delete[](void * ptr)51*7c3d14c8STreehugger Robot void operator delete[](void *ptr) NOEXCEPT {
52*7c3d14c8STreehugger Robot return scudoFree(ptr, FromNewArray);
53*7c3d14c8STreehugger Robot }
54*7c3d14c8STreehugger Robot CXX_OPERATOR_ATTRIBUTE
operator delete(void * ptr,std::nothrow_t const &)55*7c3d14c8STreehugger Robot void operator delete(void *ptr, std::nothrow_t const&) NOEXCEPT {
56*7c3d14c8STreehugger Robot return scudoFree(ptr, FromNew);
57*7c3d14c8STreehugger Robot }
58*7c3d14c8STreehugger Robot CXX_OPERATOR_ATTRIBUTE
operator delete[](void * ptr,std::nothrow_t const &)59*7c3d14c8STreehugger Robot void operator delete[](void *ptr, std::nothrow_t const&) NOEXCEPT {
60*7c3d14c8STreehugger Robot return scudoFree(ptr, FromNewArray);
61*7c3d14c8STreehugger Robot }
62*7c3d14c8STreehugger Robot CXX_OPERATOR_ATTRIBUTE
operator delete(void * ptr,size_t size)63*7c3d14c8STreehugger Robot void operator delete(void *ptr, size_t size) NOEXCEPT {
64*7c3d14c8STreehugger Robot scudoSizedFree(ptr, size, FromNew);
65*7c3d14c8STreehugger Robot }
66*7c3d14c8STreehugger Robot CXX_OPERATOR_ATTRIBUTE
operator delete[](void * ptr,size_t size)67*7c3d14c8STreehugger Robot void operator delete[](void *ptr, size_t size) NOEXCEPT {
68*7c3d14c8STreehugger Robot scudoSizedFree(ptr, size, FromNewArray);
69*7c3d14c8STreehugger Robot }
70