| 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 |
| 11 #include "base/atomicops.h" | 11 #include "base/atomicops.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/process/process_metrics.h" | 14 #include "base/process/process_metrics.h" |
| 15 #include "base/threading/platform_thread.h" | 15 #include "base/threading/platform_thread.h" |
| 16 #include "build/build_config.h" | 16 #include "build/build_config.h" |
| 17 | 17 |
| 18 #if !defined(OS_WIN) | 18 #if !defined(OS_WIN) |
| 19 #include <unistd.h> | 19 #include <unistd.h> |
| 20 #else | 20 #else |
| 21 #include "base/allocator/winheap_stubs_win.h" | 21 #include "base/allocator/winheap_stubs_win.h" |
| 22 #endif | 22 #endif |
| 23 | 23 |
| 24 #if defined(OS_MACOSX) | 24 #if defined(OS_MACOSX) |
| 25 #include <malloc/malloc.h> | 25 #include <malloc/malloc.h> |
| 26 |
| 27 #include "base/allocator/allocator_interception_mac.h" |
| 26 #endif | 28 #endif |
| 27 | 29 |
| 28 // No calls to malloc / new in this file. They would would cause re-entrancy of | 30 // No calls to malloc / new in this file. They would would cause re-entrancy of |
| 29 // the shim, which is hard to deal with. Keep this code as simple as possible | 31 // the shim, which is hard to deal with. Keep this code as simple as possible |
| 30 // and don't use any external C++ object here, not even //base ones. Even if | 32 // and don't use any external C++ object here, not even //base ones. Even if |
| 31 // they are safe to use today, in future they might be refactored. | 33 // they are safe to use today, in future they might be refactored. |
| 32 | 34 |
| 33 namespace { | 35 namespace { |
| 34 | 36 |
| 35 using namespace base; | 37 using namespace base; |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 #endif | 321 #endif |
| 320 | 322 |
| 321 #if defined(OS_MACOSX) | 323 #if defined(OS_MACOSX) |
| 322 namespace base { | 324 namespace base { |
| 323 namespace allocator { | 325 namespace allocator { |
| 324 void InitializeAllocatorShim() { | 326 void InitializeAllocatorShim() { |
| 325 // Prepares the default dispatch. After the intercepted malloc calls have | 327 // Prepares the default dispatch. After the intercepted malloc calls have |
| 326 // traversed the shim this will route them to the default malloc zone. | 328 // traversed the shim this will route them to the default malloc zone. |
| 327 InitializeDefaultDispatchToMacAllocator(); | 329 InitializeDefaultDispatchToMacAllocator(); |
| 328 | 330 |
| 331 MallocZoneFunctions functions = MallocZoneFunctionsToReplaceDefault(); |
| 332 |
| 329 // This replaces the default malloc zone, causing calls to malloc & friends | 333 // This replaces the default malloc zone, causing calls to malloc & friends |
| 330 // from the codebase to be routed to ShimMalloc() above. | 334 // from the codebase to be routed to ShimMalloc() above. |
| 331 OverrideMacSymbols(); | 335 base::allocator::ReplaceFunctionsForStoredZones(&functions); |
| 332 } | 336 } |
| 333 } // namespace allocator | 337 } // namespace allocator |
| 334 } // namespace base | 338 } // namespace base |
| 335 #endif | 339 #endif |
| 336 | 340 |
| 337 // Cross-checks. | 341 // Cross-checks. |
| 338 | 342 |
| 339 #if defined(MEMORY_TOOL_REPLACES_ALLOCATOR) | 343 #if defined(MEMORY_TOOL_REPLACES_ALLOCATOR) |
| 340 #error The allocator shim should not be compiled when building for memory tools. | 344 #error The allocator shim should not be compiled when building for memory tools. |
| 341 #endif | 345 #endif |
| 342 | 346 |
| 343 #if (defined(__GNUC__) && defined(__EXCEPTIONS)) || \ | 347 #if (defined(__GNUC__) && defined(__EXCEPTIONS)) || \ |
| 344 (defined(_HAS_EXCEPTIONS) && _HAS_EXCEPTIONS) | 348 (defined(_HAS_EXCEPTIONS) && _HAS_EXCEPTIONS) |
| 345 #error This code cannot be used when exceptions are turned on. | 349 #error This code cannot be used when exceptions are turned on. |
| 346 #endif | 350 #endif |
| OLD | NEW |