OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_util.h" | 5 #include "base/process_util.h" |
6 | 6 |
7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
8 #include <crt_externs.h> | 8 #include <crt_externs.h> |
9 #include <dlfcn.h> | 9 #include <dlfcn.h> |
10 #include <errno.h> | 10 #include <errno.h> |
(...skipping 752 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
763 | 763 |
764 // === C++ operator new === | 764 // === C++ operator new === |
765 | 765 |
766 void oom_killer_new() { | 766 void oom_killer_new() { |
767 debug::BreakDebugger(); | 767 debug::BreakDebugger(); |
768 } | 768 } |
769 | 769 |
770 // === Core Foundation CFAllocators === | 770 // === Core Foundation CFAllocators === |
771 | 771 |
772 bool CanGetContextForCFAllocator() { | 772 bool CanGetContextForCFAllocator() { |
773 // TODO(avi): remove at final release; http://crbug.com/117476 | |
774 if (base::mac::IsOSMountainLion()) { | |
775 NSLog(@"Unsure about the internals of CFAllocator but going to patch them " | |
776 "anyway. If there is a crash inside of CFAllocatorAllocate, please " | |
777 "report it at http://crbug.com/117476 . If there is a crash and it " | |
778 "is NOT inside of CFAllocatorAllocate, it is NOT RELATED. DO NOT " | |
779 "REPORT IT THERE but rather FILE A NEW BUG."); | |
780 } | |
781 return !base::mac:: | 773 return !base::mac:: |
782 IsOSDangerouslyLaterThanMountainLionForUseByCFAllocatorReplacement(); | 774 IsOSDangerouslyLaterThanMountainLionForUseByCFAllocatorReplacement(); |
Mark Mentovai
2012/08/07 16:43:03
We’re gonna need to remember to do something with
Avi (use Gerrit)
2012/08/07 16:54:54
I plan on doing all of the same work; digging up t
| |
783 } | 775 } |
784 | 776 |
785 CFAllocatorContext* ContextForCFAllocator(CFAllocatorRef allocator) { | 777 CFAllocatorContext* ContextForCFAllocator(CFAllocatorRef allocator) { |
786 if (base::mac::IsOSLeopard() || base::mac::IsOSSnowLeopard()) { | 778 if (base::mac::IsOSLeopard() || base::mac::IsOSSnowLeopard()) { |
787 ChromeCFAllocatorLeopards* our_allocator = | 779 ChromeCFAllocatorLeopards* our_allocator = |
788 const_cast<ChromeCFAllocatorLeopards*>( | 780 const_cast<ChromeCFAllocatorLeopards*>( |
789 reinterpret_cast<const ChromeCFAllocatorLeopards*>(allocator)); | 781 reinterpret_cast<const ChromeCFAllocatorLeopards*>(allocator)); |
790 return &our_allocator->_context; | 782 return &our_allocator->_context; |
791 } else if (base::mac::IsOSLion() || base::mac::IsOSMountainLion()) { | 783 } else if (base::mac::IsOSLion() || base::mac::IsOSMountainLion()) { |
792 ChromeCFAllocatorLions* our_allocator = | 784 ChromeCFAllocatorLions* our_allocator = |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1024 << "Failed to get kCFAllocatorMalloc allocation function."; | 1016 << "Failed to get kCFAllocatorMalloc allocation function."; |
1025 context->allocate = oom_killer_cfallocator_malloc; | 1017 context->allocate = oom_killer_cfallocator_malloc; |
1026 | 1018 |
1027 context = ContextForCFAllocator(kCFAllocatorMallocZone); | 1019 context = ContextForCFAllocator(kCFAllocatorMallocZone); |
1028 CHECK(context) << "Failed to get context for kCFAllocatorMallocZone."; | 1020 CHECK(context) << "Failed to get context for kCFAllocatorMallocZone."; |
1029 g_old_cfallocator_malloc_zone = context->allocate; | 1021 g_old_cfallocator_malloc_zone = context->allocate; |
1030 CHECK(g_old_cfallocator_malloc_zone) | 1022 CHECK(g_old_cfallocator_malloc_zone) |
1031 << "Failed to get kCFAllocatorMallocZone allocation function."; | 1023 << "Failed to get kCFAllocatorMallocZone allocation function."; |
1032 context->allocate = oom_killer_cfallocator_malloc_zone; | 1024 context->allocate = oom_killer_cfallocator_malloc_zone; |
1033 } else { | 1025 } else { |
1034 NSLog(@"Internals of CFAllocator not known; out-of-memory failures via " | 1026 NSLog(@"Internals of CFAllocator not known; out-of-memory failures via " |
Mark Mentovai
2012/08/07 17:01:08
OK, so when 10.next starts running, people will se
Avi (use Gerrit)
2012/08/07 17:10:08
a. Yes, I'm OK with this message. The amount of ti
| |
1035 "CFAllocator will not result in termination. http://crbug.com/45650"); | 1027 "CFAllocator will not result in termination. http://crbug.com/45650"); |
1036 } | 1028 } |
1037 #endif | 1029 #endif |
1038 | 1030 |
1039 // === Cocoa NSObject allocation === | 1031 // === Cocoa NSObject allocation === |
1040 | 1032 |
1041 // Note that both +[NSObject new] and +[NSObject alloc] call through to | 1033 // Note that both +[NSObject new] and +[NSObject alloc] call through to |
1042 // +[NSObject allocWithZone:]. | 1034 // +[NSObject allocWithZone:]. |
1043 | 1035 |
1044 CHECK(!g_old_allocWithZone) | 1036 CHECK(!g_old_allocWithZone) |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1217 } | 1209 } |
1218 } | 1210 } |
1219 | 1211 |
1220 } // namespace | 1212 } // namespace |
1221 | 1213 |
1222 void EnsureProcessTerminated(ProcessHandle process) { | 1214 void EnsureProcessTerminated(ProcessHandle process) { |
1223 WaitForChildToDie(process, kWaitBeforeKillSeconds); | 1215 WaitForChildToDie(process, kWaitBeforeKillSeconds); |
1224 } | 1216 } |
1225 | 1217 |
1226 } // namespace base | 1218 } // namespace base |
OLD | NEW |