| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/process/memory.h" | 5 #include "base/process/memory.h" |
| 6 | 6 |
| 7 #include <CoreFoundation/CoreFoundation.h> | 7 #include <CoreFoundation/CoreFoundation.h> |
| 8 #include <errno.h> | 8 #include <errno.h> |
| 9 #include <mach/mach.h> | 9 #include <mach/mach.h> |
| 10 #include <mach/mach_vm.h> | 10 #include <mach/mach_vm.h> |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 | 241 |
| 242 void oom_killer_new() { | 242 void oom_killer_new() { |
| 243 TerminateBecauseOutOfMemory(0); | 243 TerminateBecauseOutOfMemory(0); |
| 244 } | 244 } |
| 245 | 245 |
| 246 #if !defined(ADDRESS_SANITIZER) | 246 #if !defined(ADDRESS_SANITIZER) |
| 247 | 247 |
| 248 // === Core Foundation CFAllocators === | 248 // === Core Foundation CFAllocators === |
| 249 | 249 |
| 250 bool CanGetContextForCFAllocator() { | 250 bool CanGetContextForCFAllocator() { |
| 251 return !base::mac::IsOSLaterThanElCapitan_DontCallThis(); | 251 return !base::mac::IsOSLaterThanSierra_DontCallThis(); |
| 252 } | 252 } |
| 253 | 253 |
| 254 CFAllocatorContext* ContextForCFAllocator(CFAllocatorRef allocator) { | 254 CFAllocatorContext* ContextForCFAllocator(CFAllocatorRef allocator) { |
| 255 if (base::mac::IsOSMavericks() || base::mac::IsOSYosemite() || | 255 ChromeCFAllocatorLions* our_allocator = |
| 256 base::mac::IsOSElCapitan()) { | 256 const_cast<ChromeCFAllocatorLions*>( |
| 257 ChromeCFAllocatorLions* our_allocator = | 257 reinterpret_cast<const ChromeCFAllocatorLions*>(allocator)); |
| 258 const_cast<ChromeCFAllocatorLions*>( | 258 return &our_allocator->_context; |
| 259 reinterpret_cast<const ChromeCFAllocatorLions*>(allocator)); | |
| 260 return &our_allocator->_context; | |
| 261 } else { | |
| 262 return NULL; | |
| 263 } | |
| 264 } | 259 } |
| 265 | 260 |
| 266 CFAllocatorAllocateCallBack g_old_cfallocator_system_default; | 261 CFAllocatorAllocateCallBack g_old_cfallocator_system_default; |
| 267 CFAllocatorAllocateCallBack g_old_cfallocator_malloc; | 262 CFAllocatorAllocateCallBack g_old_cfallocator_malloc; |
| 268 CFAllocatorAllocateCallBack g_old_cfallocator_malloc_zone; | 263 CFAllocatorAllocateCallBack g_old_cfallocator_malloc_zone; |
| 269 | 264 |
| 270 void* oom_killer_cfallocator_system_default(CFIndex alloc_size, | 265 void* oom_killer_cfallocator_system_default(CFIndex alloc_size, |
| 271 CFOptionFlags hint, | 266 CFOptionFlags hint, |
| 272 void* info) { | 267 void* info) { |
| 273 void* result = g_old_cfallocator_system_default(alloc_size, hint, info); | 268 void* result = g_old_cfallocator_system_default(alloc_size, hint, info); |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 547 @selector(allocWithZone:)); | 542 @selector(allocWithZone:)); |
| 548 g_old_allocWithZone = reinterpret_cast<allocWithZone_t>( | 543 g_old_allocWithZone = reinterpret_cast<allocWithZone_t>( |
| 549 method_getImplementation(orig_method)); | 544 method_getImplementation(orig_method)); |
| 550 CHECK(g_old_allocWithZone) | 545 CHECK(g_old_allocWithZone) |
| 551 << "Failed to get allocWithZone allocation function."; | 546 << "Failed to get allocWithZone allocation function."; |
| 552 method_setImplementation(orig_method, | 547 method_setImplementation(orig_method, |
| 553 reinterpret_cast<IMP>(oom_killer_allocWithZone)); | 548 reinterpret_cast<IMP>(oom_killer_allocWithZone)); |
| 554 } | 549 } |
| 555 | 550 |
| 556 } // namespace base | 551 } // namespace base |
| OLD | NEW |