1 // Copyright 2016 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifdef BASE_ALLOCATOR_ALLOCATOR_SHIM_OVERRIDE_CPP_SYMBOLS_H_ 6 #error This header is meant to be included only once by allocator_shim.cc 7 #endif 8 #define BASE_ALLOCATOR_ALLOCATOR_SHIM_OVERRIDE_CPP_SYMBOLS_H_ 9 10 // Preempt the default new/delete C++ symbols so they call the shim entry 11 // points. This file is strongly inspired by tcmalloc's 12 // libc_override_redefine.h. 13 14 #include <new> 15 16 #include "base/allocator/allocator_shim_internals.h" 17 new(size_t size)18SHIM_ALWAYS_EXPORT void* operator new(size_t size) { 19 return ShimCppNew(size); 20 } 21 delete(void * p)22SHIM_ALWAYS_EXPORT void operator delete(void* p) __THROW { 23 ShimCppDelete(p); 24 } 25 26 SHIM_ALWAYS_EXPORT void* operator new[](size_t size) { 27 return ShimCppNew(size); 28 } 29 30 SHIM_ALWAYS_EXPORT void operator delete[](void* p) __THROW { 31 ShimCppDelete(p); 32 } 33 new(size_t size,const std::nothrow_t &)34SHIM_ALWAYS_EXPORT void* operator new(size_t size, 35 const std::nothrow_t&) __THROW { 36 return ShimCppNew(size); 37 } 38 39 SHIM_ALWAYS_EXPORT void* operator new[](size_t size, 40 const std::nothrow_t&) __THROW { 41 return ShimCppNew(size); 42 } 43 delete(void * p,const std::nothrow_t &)44SHIM_ALWAYS_EXPORT void operator delete(void* p, const std::nothrow_t&) __THROW { 45 ShimCppDelete(p); 46 } 47 48 SHIM_ALWAYS_EXPORT void operator delete[](void* p, 49 const std::nothrow_t&) __THROW { 50 ShimCppDelete(p); 51 } 52 delete(void * p,size_t)53SHIM_ALWAYS_EXPORT void operator delete(void* p, size_t) __THROW { 54 ShimCppDelete(p); 55 } 56 57 SHIM_ALWAYS_EXPORT void operator delete[](void* p, size_t) __THROW { 58 ShimCppDelete(p); 59 } 60