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 #include "base/allocator/allocator_shim.h" | 5 #include "base/allocator/allocator_shim.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 | 8 |
9 #include <new> | 9 #include <new> |
10 | 10 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 subtle::NoBarrier_Load(&g_chain_head) | 83 subtle::NoBarrier_Load(&g_chain_head) |
84 #endif | 84 #endif |
85 ); | 85 ); |
86 } | 86 } |
87 | 87 |
88 } // namespace | 88 } // namespace |
89 | 89 |
90 namespace base { | 90 namespace base { |
91 namespace allocator { | 91 namespace allocator { |
92 | 92 |
| 93 #if defined(OS_MACOSX) |
| 94 bool g_is_mac_shim_layer_initialized = false; |
| 95 #endif |
| 96 |
93 void SetCallNewHandlerOnMallocFailure(bool value) { | 97 void SetCallNewHandlerOnMallocFailure(bool value) { |
94 g_call_new_handler_on_malloc_failure = value; | 98 g_call_new_handler_on_malloc_failure = value; |
95 } | 99 } |
96 | 100 |
97 void* UncheckedAlloc(size_t size) { | 101 void* UncheckedAlloc(size_t size) { |
98 const allocator::AllocatorDispatch* const chain_head = GetChainHead(); | 102 const allocator::AllocatorDispatch* const chain_head = GetChainHead(); |
99 return chain_head->alloc_function(chain_head, size); | 103 return chain_head->alloc_function(chain_head, size); |
100 } | 104 } |
101 | 105 |
102 void InsertAllocatorDispatch(AllocatorDispatch* dispatch) { | 106 void InsertAllocatorDispatch(AllocatorDispatch* dispatch) { |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 namespace base { | 302 namespace base { |
299 namespace allocator { | 303 namespace allocator { |
300 void InitializeAllocatorShim() { | 304 void InitializeAllocatorShim() { |
301 // Prepares the default dispatch. After the intercepted malloc calls have | 305 // Prepares the default dispatch. After the intercepted malloc calls have |
302 // traversed the shim this will route them to the default malloc zone. | 306 // traversed the shim this will route them to the default malloc zone. |
303 InitializeDefaultDispatchToMacAllocator(); | 307 InitializeDefaultDispatchToMacAllocator(); |
304 | 308 |
305 // This replaces the default malloc zone, causing calls to malloc & friends | 309 // This replaces the default malloc zone, causing calls to malloc & friends |
306 // from the codebase to be routed to ShimMalloc() above. | 310 // from the codebase to be routed to ShimMalloc() above. |
307 OverrideMacSymbols(); | 311 OverrideMacSymbols(); |
| 312 |
| 313 g_is_mac_shim_layer_initialized = true; |
308 } | 314 } |
309 } // namespace allocator | 315 } // namespace allocator |
310 } // namespace base | 316 } // namespace base |
311 #endif | 317 #endif |
312 | 318 |
313 // Cross-checks. | 319 // Cross-checks. |
314 | 320 |
315 #if defined(MEMORY_TOOL_REPLACES_ALLOCATOR) | 321 #if defined(MEMORY_TOOL_REPLACES_ALLOCATOR) |
316 #error The allocator shim should not be compiled when building for memory tools. | 322 #error The allocator shim should not be compiled when building for memory tools. |
317 #endif | 323 #endif |
318 | 324 |
319 #if (defined(__GNUC__) && defined(__EXCEPTIONS)) || \ | 325 #if (defined(__GNUC__) && defined(__EXCEPTIONS)) || \ |
320 (defined(_HAS_EXCEPTIONS) && _HAS_EXCEPTIONS) | 326 (defined(_HAS_EXCEPTIONS) && _HAS_EXCEPTIONS) |
321 #error This code cannot be used when exceptions are turned on. | 327 #error This code cannot be used when exceptions are turned on. |
322 #endif | 328 #endif |
OLD | NEW |