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