| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 // This file contains all the logic necessary to intercept allocations on | 5 // This file contains all the logic necessary to intercept allocations on |
| 6 // macOS. "malloc zones" are an abstraction that allows the process to intercept | 6 // macOS. "malloc zones" are an abstraction that allows the process to intercept |
| 7 // all malloc-related functions. There is no good mechanism [short of | 7 // all malloc-related functions. There is no good mechanism [short of |
| 8 // interposition] to determine new malloc zones are added, so there's no clean | 8 // interposition] to determine new malloc zones are added, so there's no clean |
| 9 // mechanism to intercept all malloc zones. This file contains logic to | 9 // mechanism to intercept all malloc zones. This file contains logic to |
| 10 // intercept the default and purgeable zones, which always exist. A cursory | 10 // intercept the default and purgeable zones, which always exist. A cursory |
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 | 363 |
| 364 void StoreFunctionsForDefaultZone(MallocZoneFunctions* functions) { | 364 void StoreFunctionsForDefaultZone(MallocZoneFunctions* functions) { |
| 365 ChromeMallocZone* default_zone = reinterpret_cast<ChromeMallocZone*>( | 365 ChromeMallocZone* default_zone = reinterpret_cast<ChromeMallocZone*>( |
| 366 malloc_default_zone()); | 366 malloc_default_zone()); |
| 367 StoreZoneFunctions(default_zone, functions); | 367 StoreZoneFunctions(default_zone, functions); |
| 368 } | 368 } |
| 369 | 369 |
| 370 void ReplaceFunctionsForDefaultZone(const MallocZoneFunctions* functions) { | 370 void ReplaceFunctionsForDefaultZone(const MallocZoneFunctions* functions) { |
| 371 CHECK(!g_replaced_default_zone); | 371 CHECK(!g_replaced_default_zone); |
| 372 g_replaced_default_zone = true; | 372 g_replaced_default_zone = true; |
| 373 #if !defined(ADDRESS_SANITIZER) |
| 373 StoreFunctionsForDefaultZone(&g_old_zone); | 374 StoreFunctionsForDefaultZone(&g_old_zone); |
| 375 #endif |
| 374 ChromeMallocZone* default_zone = reinterpret_cast<ChromeMallocZone*>( | 376 ChromeMallocZone* default_zone = reinterpret_cast<ChromeMallocZone*>( |
| 375 malloc_default_zone()); | 377 malloc_default_zone()); |
| 376 ReplaceZoneFunctions(default_zone, functions); | 378 ReplaceZoneFunctions(default_zone, functions); |
| 377 } | 379 } |
| 378 | 380 |
| 379 void InterceptAllocationsMac() { | 381 void InterceptAllocationsMac() { |
| 380 if (g_oom_killer_enabled) | 382 if (g_oom_killer_enabled) |
| 381 return; | 383 return; |
| 382 | 384 |
| 383 g_oom_killer_enabled = true; | 385 g_oom_killer_enabled = true; |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 500 g_old_allocWithZone = | 502 g_old_allocWithZone = |
| 501 reinterpret_cast<allocWithZone_t>(method_getImplementation(orig_method)); | 503 reinterpret_cast<allocWithZone_t>(method_getImplementation(orig_method)); |
| 502 CHECK(g_old_allocWithZone) | 504 CHECK(g_old_allocWithZone) |
| 503 << "Failed to get allocWithZone allocation function."; | 505 << "Failed to get allocWithZone allocation function."; |
| 504 method_setImplementation(orig_method, | 506 method_setImplementation(orig_method, |
| 505 reinterpret_cast<IMP>(oom_killer_allocWithZone)); | 507 reinterpret_cast<IMP>(oom_killer_allocWithZone)); |
| 506 } | 508 } |
| 507 | 509 |
| 508 } // namespace allocator | 510 } // namespace allocator |
| 509 } // namespace base | 511 } // namespace base |
| OLD | NEW |