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 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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::IsOSLaterThanElCapitan_DontCallThis(); |
252 } | 252 } |
253 | 253 |
254 CFAllocatorContext* ContextForCFAllocator(CFAllocatorRef allocator) { | 254 CFAllocatorContext* ContextForCFAllocator(CFAllocatorRef allocator) { |
255 if (base::mac::IsOSSnowLeopard()) { | 255 if (base::mac::IsOSLion() || base::mac::IsOSMountainLion() || |
256 ChromeCFAllocatorLeopards* our_allocator = | 256 base::mac::IsOSMavericks() || base::mac::IsOSYosemite() || |
257 const_cast<ChromeCFAllocatorLeopards*>( | 257 base::mac::IsOSElCapitan()) { |
258 reinterpret_cast<const ChromeCFAllocatorLeopards*>(allocator)); | |
259 return &our_allocator->_context; | |
260 } else if (base::mac::IsOSLion() || | |
261 base::mac::IsOSMountainLion() || | |
262 base::mac::IsOSMavericks() || | |
263 base::mac::IsOSYosemite() || | |
264 base::mac::IsOSElCapitan()) { | |
265 ChromeCFAllocatorLions* our_allocator = | 258 ChromeCFAllocatorLions* our_allocator = |
266 const_cast<ChromeCFAllocatorLions*>( | 259 const_cast<ChromeCFAllocatorLions*>( |
267 reinterpret_cast<const ChromeCFAllocatorLions*>(allocator)); | 260 reinterpret_cast<const ChromeCFAllocatorLions*>(allocator)); |
268 return &our_allocator->_context; | 261 return &our_allocator->_context; |
269 } else { | 262 } else { |
270 return NULL; | 263 return NULL; |
271 } | 264 } |
272 } | 265 } |
273 | 266 |
274 CFAllocatorAllocateCallBack g_old_cfallocator_system_default; | 267 CFAllocatorAllocateCallBack g_old_cfallocator_system_default; |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
555 @selector(allocWithZone:)); | 548 @selector(allocWithZone:)); |
556 g_old_allocWithZone = reinterpret_cast<allocWithZone_t>( | 549 g_old_allocWithZone = reinterpret_cast<allocWithZone_t>( |
557 method_getImplementation(orig_method)); | 550 method_getImplementation(orig_method)); |
558 CHECK(g_old_allocWithZone) | 551 CHECK(g_old_allocWithZone) |
559 << "Failed to get allocWithZone allocation function."; | 552 << "Failed to get allocWithZone allocation function."; |
560 method_setImplementation(orig_method, | 553 method_setImplementation(orig_method, |
561 reinterpret_cast<IMP>(oom_killer_allocWithZone)); | 554 reinterpret_cast<IMP>(oom_killer_allocWithZone)); |
562 } | 555 } |
563 | 556 |
564 } // namespace base | 557 } // namespace base |
OLD | NEW |