Chromium Code Reviews| Index: base/process_util_mac.mm |
| diff --git a/base/process_util_mac.mm b/base/process_util_mac.mm |
| index 39eabac079097a0ca2434f05d57846a7fdee41dc..66c30fe33715ffdf2ff8f5607223a5ee82e90b04 100644 |
| --- a/base/process_util_mac.mm |
| +++ b/base/process_util_mac.mm |
| @@ -1,4 +1,4 @@ |
| -// Copyright (c) 2008 The Chromium Authors. All rights reserved. |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| @@ -622,7 +622,34 @@ void oom_killer_new() { |
| // === Core Foundation CFAllocators === |
| -typedef ChromeCFAllocator* ChromeCFAllocatorRef; |
| +bool CanGetContextForCFAllocator(long darwin_version) { |
| + // TODO(avi):remove at final release; http://crbug.com/74589 |
|
Mark Mentovai
2011/03/17 23:10:46
Space after colon.
Avi (use Gerrit)
2011/03/18 13:18:35
Done.
|
| + if (darwin_version == 11) { |
| + NSLog(@"Unsure about the internals of CFAllocator but going to patch them " |
|
Mark Mentovai
2011/03/17 23:18:51
Thinking about this again…
Saying “if a crash hap
Avi (use Gerrit)
2011/03/18 13:18:35
Good point; slight rewording. WDYT?
|
| + "anyway. If a crash happens, this is almost certainly why; please " |
| + "file a bug at http://new.crbug.com/ ."); |
| + } |
| + return darwin_version == 9 || |
| + darwin_version == 10 || |
| + darwin_version == 11; |
| +} |
| + |
| +CFAllocatorContext* ContextForCFAllocator(CFAllocatorRef allocator, |
| + long darwin_version) { |
| + if (darwin_version == 9 || darwin_version == 10) { |
| + ChromeCFAllocator9and10* our_allocator = |
| + const_cast<ChromeCFAllocator9and10*>( |
| + reinterpret_cast<const ChromeCFAllocator9and10*>(allocator)); |
| + return &our_allocator->_context; |
| + } else if (darwin_version == 11) { |
| + ChromeCFAllocator11* our_allocator = |
| + const_cast<ChromeCFAllocator11*>( |
| + reinterpret_cast<const ChromeCFAllocator11*>(allocator)); |
| + return &our_allocator->_context; |
| + } else { |
| + return NULL; |
| + } |
| +} |
| CFAllocatorAllocateCallBack g_old_cfallocator_system_default; |
| CFAllocatorAllocateCallBack g_old_cfallocator_malloc; |
| @@ -833,29 +860,30 @@ void EnableTerminationOnOutOfMemory() { |
| << "Old allocators unexpectedly non-null"; |
| bool cf_allocator_internals_known = |
| - darwin_version == 9 || darwin_version == 10; |
| + CanGetContextForCFAllocator(darwin_version); |
| if (cf_allocator_internals_known) { |
| - ChromeCFAllocatorRef allocator = const_cast<ChromeCFAllocatorRef>( |
| - reinterpret_cast<const ChromeCFAllocator*>(kCFAllocatorSystemDefault)); |
| - g_old_cfallocator_system_default = allocator->_context.allocate; |
| + CFAllocatorContext* context = |
| + ContextForCFAllocator(kCFAllocatorSystemDefault, darwin_version); |
| + CHECK(context) << "Failed to get context for kCFAllocatorSystemDefault."; |
| + g_old_cfallocator_system_default = context->allocate; |
| CHECK(g_old_cfallocator_system_default) |
| << "Failed to get kCFAllocatorSystemDefault allocation function."; |
| - allocator->_context.allocate = oom_killer_cfallocator_system_default; |
| + context->allocate = oom_killer_cfallocator_system_default; |
| - allocator = const_cast<ChromeCFAllocatorRef>( |
| - reinterpret_cast<const ChromeCFAllocator*>(kCFAllocatorMalloc)); |
| - g_old_cfallocator_malloc = allocator->_context.allocate; |
| + context = ContextForCFAllocator(kCFAllocatorMalloc, darwin_version); |
| + CHECK(context) << "Failed to get context for kCFAllocatorMalloc."; |
| + g_old_cfallocator_malloc = context->allocate; |
| CHECK(g_old_cfallocator_malloc) |
| << "Failed to get kCFAllocatorMalloc allocation function."; |
| - allocator->_context.allocate = oom_killer_cfallocator_malloc; |
| + context->allocate = oom_killer_cfallocator_malloc; |
| - allocator = const_cast<ChromeCFAllocatorRef>( |
| - reinterpret_cast<const ChromeCFAllocator*>(kCFAllocatorMallocZone)); |
| - g_old_cfallocator_malloc_zone = allocator->_context.allocate; |
| + context = ContextForCFAllocator(kCFAllocatorMallocZone, darwin_version); |
| + CHECK(context) << "Failed to get context for kCFAllocatorMallocZone."; |
| + g_old_cfallocator_malloc_zone = context->allocate; |
| CHECK(g_old_cfallocator_malloc_zone) |
| << "Failed to get kCFAllocatorMallocZone allocation function."; |
| - allocator->_context.allocate = oom_killer_cfallocator_malloc_zone; |
| + context->allocate = oom_killer_cfallocator_malloc_zone; |
| } else { |
| NSLog(@"Internals of CFAllocator not known; out-of-memory failures via " |
| "CFAllocator will not result in termination. http://crbug.com/45650"); |