Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(93)

Side by Side Diff: base/process_util_mac.mm

Issue 6711017: Update OOM killer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address feedback Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | third_party/apple_apsl/CFBase.h » ('j') | third_party/apple_apsl/CFBase.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 5
6 #include "base/process_util.h" 6 #include "base/process_util.h"
7 7
8 #import <Cocoa/Cocoa.h> 8 #import <Cocoa/Cocoa.h>
9 #include <crt_externs.h> 9 #include <crt_externs.h>
10 #include <dlfcn.h> 10 #include <dlfcn.h>
11 #include <mach/mach.h> 11 #include <mach/mach.h>
(...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after
615 } 615 }
616 616
617 // === C++ operator new === 617 // === C++ operator new ===
618 618
619 void oom_killer_new() { 619 void oom_killer_new() {
620 debug::BreakDebugger(); 620 debug::BreakDebugger();
621 } 621 }
622 622
623 // === Core Foundation CFAllocators === 623 // === Core Foundation CFAllocators ===
624 624
625 typedef ChromeCFAllocator* ChromeCFAllocatorRef; 625 bool CanGetContextForCFAllocator(long darwin_version) {
626 // 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.
627 if (darwin_version == 11) {
628 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?
629 "anyway. If a crash happens, this is almost certainly why; please "
630 "file a bug at http://new.crbug.com/ .");
631 }
632 return darwin_version == 9 ||
633 darwin_version == 10 ||
634 darwin_version == 11;
635 }
636
637 CFAllocatorContext* ContextForCFAllocator(CFAllocatorRef allocator,
638 long darwin_version) {
639 if (darwin_version == 9 || darwin_version == 10) {
640 ChromeCFAllocator9and10* our_allocator =
641 const_cast<ChromeCFAllocator9and10*>(
642 reinterpret_cast<const ChromeCFAllocator9and10*>(allocator));
643 return &our_allocator->_context;
644 } else if (darwin_version == 11) {
645 ChromeCFAllocator11* our_allocator =
646 const_cast<ChromeCFAllocator11*>(
647 reinterpret_cast<const ChromeCFAllocator11*>(allocator));
648 return &our_allocator->_context;
649 } else {
650 return NULL;
651 }
652 }
626 653
627 CFAllocatorAllocateCallBack g_old_cfallocator_system_default; 654 CFAllocatorAllocateCallBack g_old_cfallocator_system_default;
628 CFAllocatorAllocateCallBack g_old_cfallocator_malloc; 655 CFAllocatorAllocateCallBack g_old_cfallocator_malloc;
629 CFAllocatorAllocateCallBack g_old_cfallocator_malloc_zone; 656 CFAllocatorAllocateCallBack g_old_cfallocator_malloc_zone;
630 657
631 void* oom_killer_cfallocator_system_default(CFIndex alloc_size, 658 void* oom_killer_cfallocator_system_default(CFIndex alloc_size,
632 CFOptionFlags hint, 659 CFOptionFlags hint,
633 void* info) { 660 void* info) {
634 void* result = g_old_cfallocator_system_default(alloc_size, hint, info); 661 void* result = g_old_cfallocator_system_default(alloc_size, hint, info);
635 if (!result) 662 if (!result)
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
826 // === Core Foundation CFAllocators === 853 // === Core Foundation CFAllocators ===
827 854
828 // This will not catch allocation done by custom allocators, but will catch 855 // This will not catch allocation done by custom allocators, but will catch
829 // all allocation done by system-provided ones. 856 // all allocation done by system-provided ones.
830 857
831 CHECK(!g_old_cfallocator_system_default && !g_old_cfallocator_malloc && 858 CHECK(!g_old_cfallocator_system_default && !g_old_cfallocator_malloc &&
832 !g_old_cfallocator_malloc_zone) 859 !g_old_cfallocator_malloc_zone)
833 << "Old allocators unexpectedly non-null"; 860 << "Old allocators unexpectedly non-null";
834 861
835 bool cf_allocator_internals_known = 862 bool cf_allocator_internals_known =
836 darwin_version == 9 || darwin_version == 10; 863 CanGetContextForCFAllocator(darwin_version);
837 864
838 if (cf_allocator_internals_known) { 865 if (cf_allocator_internals_known) {
839 ChromeCFAllocatorRef allocator = const_cast<ChromeCFAllocatorRef>( 866 CFAllocatorContext* context =
840 reinterpret_cast<const ChromeCFAllocator*>(kCFAllocatorSystemDefault)); 867 ContextForCFAllocator(kCFAllocatorSystemDefault, darwin_version);
841 g_old_cfallocator_system_default = allocator->_context.allocate; 868 CHECK(context) << "Failed to get context for kCFAllocatorSystemDefault.";
869 g_old_cfallocator_system_default = context->allocate;
842 CHECK(g_old_cfallocator_system_default) 870 CHECK(g_old_cfallocator_system_default)
843 << "Failed to get kCFAllocatorSystemDefault allocation function."; 871 << "Failed to get kCFAllocatorSystemDefault allocation function.";
844 allocator->_context.allocate = oom_killer_cfallocator_system_default; 872 context->allocate = oom_killer_cfallocator_system_default;
845 873
846 allocator = const_cast<ChromeCFAllocatorRef>( 874 context = ContextForCFAllocator(kCFAllocatorMalloc, darwin_version);
847 reinterpret_cast<const ChromeCFAllocator*>(kCFAllocatorMalloc)); 875 CHECK(context) << "Failed to get context for kCFAllocatorMalloc.";
848 g_old_cfallocator_malloc = allocator->_context.allocate; 876 g_old_cfallocator_malloc = context->allocate;
849 CHECK(g_old_cfallocator_malloc) 877 CHECK(g_old_cfallocator_malloc)
850 << "Failed to get kCFAllocatorMalloc allocation function."; 878 << "Failed to get kCFAllocatorMalloc allocation function.";
851 allocator->_context.allocate = oom_killer_cfallocator_malloc; 879 context->allocate = oom_killer_cfallocator_malloc;
852 880
853 allocator = const_cast<ChromeCFAllocatorRef>( 881 context = ContextForCFAllocator(kCFAllocatorMallocZone, darwin_version);
854 reinterpret_cast<const ChromeCFAllocator*>(kCFAllocatorMallocZone)); 882 CHECK(context) << "Failed to get context for kCFAllocatorMallocZone.";
855 g_old_cfallocator_malloc_zone = allocator->_context.allocate; 883 g_old_cfallocator_malloc_zone = context->allocate;
856 CHECK(g_old_cfallocator_malloc_zone) 884 CHECK(g_old_cfallocator_malloc_zone)
857 << "Failed to get kCFAllocatorMallocZone allocation function."; 885 << "Failed to get kCFAllocatorMallocZone allocation function.";
858 allocator->_context.allocate = oom_killer_cfallocator_malloc_zone; 886 context->allocate = oom_killer_cfallocator_malloc_zone;
859 } else { 887 } else {
860 NSLog(@"Internals of CFAllocator not known; out-of-memory failures via " 888 NSLog(@"Internals of CFAllocator not known; out-of-memory failures via "
861 "CFAllocator will not result in termination. http://crbug.com/45650"); 889 "CFAllocator will not result in termination. http://crbug.com/45650");
862 } 890 }
863 891
864 // === Cocoa NSObject allocation === 892 // === Cocoa NSObject allocation ===
865 893
866 // Note that both +[NSObject new] and +[NSObject alloc] call through to 894 // Note that both +[NSObject new] and +[NSObject alloc] call through to
867 // +[NSObject allocWithZone:]. 895 // +[NSObject allocWithZone:].
868 896
(...skipping 18 matching lines...) Expand all
887 if (sysctl(mib, 4, &info, &length, NULL, 0) < 0) { 915 if (sysctl(mib, 4, &info, &length, NULL, 0) < 0) {
888 PLOG(ERROR) << "sysctl"; 916 PLOG(ERROR) << "sysctl";
889 return -1; 917 return -1;
890 } 918 }
891 if (length == 0) 919 if (length == 0)
892 return -1; 920 return -1;
893 return info.kp_eproc.e_ppid; 921 return info.kp_eproc.e_ppid;
894 } 922 }
895 923
896 } // namespace base 924 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | third_party/apple_apsl/CFBase.h » ('j') | third_party/apple_apsl/CFBase.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698