| Index: base/process/memory_mac.mm
|
| diff --git a/base/process/memory_mac.mm b/base/process/memory_mac.mm
|
| index 4c1b12043e60b64fbc861102cb542e4943c6c0dc..112a80298606c3006eac009f9fa3fb50dd294d32 100644
|
| --- a/base/process/memory_mac.mm
|
| +++ b/base/process/memory_mac.mm
|
| @@ -364,12 +364,14 @@ void EnableTerminationOnOutOfMemory() {
|
| // Don't do anything special on OOM for the malloc zones replaced by
|
| // AddressSanitizer, as modifying or protecting them may not work correctly.
|
|
|
| + // Old allocators unexpectedly non-null
|
| CHECK(!g_old_malloc && !g_old_calloc && !g_old_valloc && !g_old_realloc &&
|
| - !g_old_memalign) << "Old allocators unexpectedly non-null";
|
| + !g_old_memalign);
|
|
|
| + // Old allocators unexpectedly non-null
|
| CHECK(!g_old_malloc_purgeable && !g_old_calloc_purgeable &&
|
| !g_old_valloc_purgeable && !g_old_realloc_purgeable &&
|
| - !g_old_memalign_purgeable) << "Old allocators unexpectedly non-null";
|
| + !g_old_memalign_purgeable);
|
|
|
| ChromeMallocZone* default_zone =
|
| reinterpret_cast<ChromeMallocZone*>(malloc_default_zone());
|
| @@ -401,9 +403,9 @@ void EnableTerminationOnOutOfMemory() {
|
| g_old_valloc = default_zone->valloc;
|
| g_old_free = default_zone->free;
|
| g_old_realloc = default_zone->realloc;
|
| + // Failed to get system allocation functions.
|
| CHECK(g_old_malloc && g_old_calloc && g_old_valloc && g_old_free &&
|
| - g_old_realloc)
|
| - << "Failed to get system allocation functions.";
|
| + g_old_realloc);
|
|
|
| default_zone->malloc = oom_killer_malloc;
|
| default_zone->calloc = oom_killer_calloc;
|
| @@ -425,10 +427,10 @@ void EnableTerminationOnOutOfMemory() {
|
| g_old_valloc_purgeable = purgeable_zone->valloc;
|
| g_old_free_purgeable = purgeable_zone->free;
|
| g_old_realloc_purgeable = purgeable_zone->realloc;
|
| + // Failed to get system allocation functions.
|
| CHECK(g_old_malloc_purgeable && g_old_calloc_purgeable &&
|
| g_old_valloc_purgeable && g_old_free_purgeable &&
|
| - g_old_realloc_purgeable)
|
| - << "Failed to get system allocation functions.";
|
| + g_old_realloc_purgeable);
|
|
|
| purgeable_zone->malloc = oom_killer_malloc_purgeable;
|
| purgeable_zone->calloc = oom_killer_calloc_purgeable;
|
| @@ -495,33 +497,36 @@ void EnableTerminationOnOutOfMemory() {
|
| // This will not catch allocation done by custom allocators, but will catch
|
| // all allocation done by system-provided ones.
|
|
|
| + // Old allocators unexpectedly non-null
|
| CHECK(!g_old_cfallocator_system_default && !g_old_cfallocator_malloc &&
|
| - !g_old_cfallocator_malloc_zone)
|
| - << "Old allocators unexpectedly non-null";
|
| + !g_old_cfallocator_malloc_zone);
|
|
|
| bool cf_allocator_internals_known = CanGetContextForCFAllocator();
|
|
|
| if (cf_allocator_internals_known) {
|
| CFAllocatorContext* context =
|
| ContextForCFAllocator(kCFAllocatorSystemDefault);
|
| - CHECK(context) << "Failed to get context for kCFAllocatorSystemDefault.";
|
| + // Failed to get context for kCFAllocatorSystemDefault.
|
| + CHECK(context);
|
| g_old_cfallocator_system_default = context->allocate;
|
| - CHECK(g_old_cfallocator_system_default)
|
| - << "Failed to get kCFAllocatorSystemDefault allocation function.";
|
| + // Failed to get kCFAllocatorSystemDefault allocation function.
|
| + CHECK(g_old_cfallocator_system_default);
|
| context->allocate = oom_killer_cfallocator_system_default;
|
|
|
| context = ContextForCFAllocator(kCFAllocatorMalloc);
|
| - CHECK(context) << "Failed to get context for kCFAllocatorMalloc.";
|
| + // Failed to get context for kCFAllocatorMalloc.
|
| + CHECK(context);
|
| g_old_cfallocator_malloc = context->allocate;
|
| - CHECK(g_old_cfallocator_malloc)
|
| - << "Failed to get kCFAllocatorMalloc allocation function.";
|
| + // Failed to get kCFAllocatorMalloc allocation function.
|
| + CHECK(g_old_cfallocator_malloc);
|
| context->allocate = oom_killer_cfallocator_malloc;
|
|
|
| context = ContextForCFAllocator(kCFAllocatorMallocZone);
|
| - CHECK(context) << "Failed to get context for kCFAllocatorMallocZone.";
|
| + // Failed to get context for kCFAllocatorMallocZone.
|
| + CHECK(context);
|
| g_old_cfallocator_malloc_zone = context->allocate;
|
| - CHECK(g_old_cfallocator_malloc_zone)
|
| - << "Failed to get kCFAllocatorMallocZone allocation function.";
|
| + // Failed to get kCFAllocatorMallocZone allocation function.
|
| + CHECK(g_old_cfallocator_malloc_zone);
|
| context->allocate = oom_killer_cfallocator_malloc_zone;
|
| } else {
|
| DLOG(WARNING) << "Internals of CFAllocator not known; out-of-memory "
|
| @@ -535,16 +540,16 @@ void EnableTerminationOnOutOfMemory() {
|
| // Note that both +[NSObject new] and +[NSObject alloc] call through to
|
| // +[NSObject allocWithZone:].
|
|
|
| - CHECK(!g_old_allocWithZone)
|
| - << "Old allocator unexpectedly non-null";
|
| + // Old allocator unexpectedly non-null
|
| + CHECK(!g_old_allocWithZone);
|
|
|
| Class nsobject_class = [NSObject class];
|
| Method orig_method = class_getClassMethod(nsobject_class,
|
| @selector(allocWithZone:));
|
| g_old_allocWithZone = reinterpret_cast<allocWithZone_t>(
|
| method_getImplementation(orig_method));
|
| - CHECK(g_old_allocWithZone)
|
| - << "Failed to get allocWithZone allocation function.";
|
| + // Failed to get allocWithZone allocation function.
|
| + CHECK(g_old_allocWithZone);
|
| method_setImplementation(orig_method,
|
| reinterpret_cast<IMP>(oom_killer_allocWithZone));
|
| }
|
|
|