summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoravi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-18 16:39:45 +0000
committeravi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-18 16:39:45 +0000
commit21fcf83c508704a5bd11ed0467fc20b5e03f3acc (patch)
treea6935efc80b36322388f50d530f5e3b2e4d2e3e1
parentb5c4a9f98c001b01ab41c01c80871247255a2655 (diff)
downloadchromium_src-21fcf83c508704a5bd11ed0467fc20b5e03f3acc.zip
chromium_src-21fcf83c508704a5bd11ed0467fc20b5e03f3acc.tar.gz
chromium_src-21fcf83c508704a5bd11ed0467fc20b5e03f3acc.tar.bz2
Update OOM killer.
BUG=74589 TEST=unit tested Review URL: http://codereview.chromium.org/6711017 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@78702 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--base/process_util_mac.mm57
-rw-r--r--third_party/apple_apsl/CFBase.h29
-rw-r--r--third_party/apple_apsl/README.chromium4
3 files changed, 71 insertions, 19 deletions
diff --git a/base/process_util_mac.mm b/base/process_util_mac.mm
index 39eabac..e2df2ca 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,33 @@ 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
+ if (darwin_version == 11) {
+ NSLog(@"Unsure about the internals of CFAllocator but going to patch them "
+ "anyway. Watch out for crashes inside of CFAllocatorAllocate.");
+ }
+ 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 +859,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");
diff --git a/third_party/apple_apsl/CFBase.h b/third_party/apple_apsl/CFBase.h
index ae3e2fa..4c52e0e 100644
--- a/third_party/apple_apsl/CFBase.h
+++ b/third_party/apple_apsl/CFBase.h
@@ -30,9 +30,7 @@
#include "CFRuntime.h"
-struct ChromeCFAllocator {
-
-
+struct ChromeCFAllocator9and10 {
ChromeCFRuntimeBase _base;
#if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED
size_t (*size)(struct _malloc_zone_t *zone, const void *ptr); /* returns the size of a block or 0 if not in this zone; must be fast, especially for negative answers */
@@ -52,4 +50,29 @@ struct ChromeCFAllocator {
CFAllocatorContext _context;
};
+// TODO(avi): update upon source release; http://crbug.com/74589
+struct ChromeCFAllocator11 {
+ ChromeCFRuntimeBase _base;
+ // CFAllocator in Darwin 9 included a complete copy of _malloc_zone_t. The
+ // version in Darwin 10 had an abbreviated _malloc_zone_t that ended after the
+ // version/"reserved" field (see above). Darwin 11 appears to have a truncated
+ // _malloc_zone_t as well, but two fields larger than 9/10.
+ void* presumedSizeFunctionPtr;
+ void* presumedMallocFunctionPtr;
+ void* presumedCallocFunctionPtr;
+ void* presumedVallocFunctionPtr;
+ void* presumedFreeFunctionPtr;
+ void* presumedReallocFunctionPtr;
+ void* presumedDestroyFunctionPtr;
+ const char *zone_name;
+ void* presumedBatchMallocFunctionPtr;
+ void* presumedBatchFreeFunctionPtr;
+ void* presumedIntrospectStructPtr;
+ void* presumedReservedSlashVersion; // always 6 in CFAllocators
+ void* presumedMemalignFunctionPtr;
+ void* presumedFreeDefiniteSizeFunctionPtr;
+ CFAllocatorRef _allocator;
+ CFAllocatorContext _context;
+};
+
#endif // THIRD_PARTY_APPLE_APSL_CFBASE_H_
diff --git a/third_party/apple_apsl/README.chromium b/third_party/apple_apsl/README.chromium
index 44077b9..c64b81f 100644
--- a/third_party/apple_apsl/README.chromium
+++ b/third_party/apple_apsl/README.chromium
@@ -29,4 +29,6 @@ Modifications:
- Added an #include of the CFRuntime.h file.
- Removed everything but the definition of __CFAllocator.
- Modified the reference of CFRuntimeBase to ChromeCFRuntimeBase.
-- Renamed __CFAllocator to ChromeCFAllocator to avoid possible name conflicts.
+- Renamed __CFAllocator to ChromeCFAllocator9and10 to avoid possible name
+ conflicts.
+- Added a presumed definition of ChromeCFAllocator11.