Chromium Code Reviews| 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 818 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 829 id oom_killer_allocWithZone(id self, SEL _cmd, NSZone* zone) | 829 id oom_killer_allocWithZone(id self, SEL _cmd, NSZone* zone) |
| 830 { | 830 { |
| 831 id result = g_old_allocWithZone(self, _cmd, zone); | 831 id result = g_old_allocWithZone(self, _cmd, zone); |
| 832 if (!result) | 832 if (!result) |
| 833 debug::BreakDebugger(); | 833 debug::BreakDebugger(); |
| 834 return result; | 834 return result; |
| 835 } | 835 } |
| 836 | 836 |
| 837 } // namespace | 837 } // namespace |
| 838 | 838 |
| 839 malloc_zone_t* GetPurgeableZone() { | 839 void* oom_safe_malloc(size_t size) { |
| 840 // malloc_default_purgeable_zone only exists on >= 10.6. Use dlsym to grab it | 840 if (g_old_malloc) |
| 841 // at runtime because it may not be present in the SDK used for compilation. | 841 return g_old_malloc(malloc_default_zone(), size); |
| 842 typedef malloc_zone_t* (*malloc_default_purgeable_zone_t)(void); | 842 return malloc(size); |
| 843 malloc_default_purgeable_zone_t malloc_purgeable_zone = | |
| 844 reinterpret_cast<malloc_default_purgeable_zone_t>( | |
| 845 dlsym(RTLD_DEFAULT, "malloc_default_purgeable_zone")); | |
| 846 if (malloc_purgeable_zone) | |
| 847 return malloc_purgeable_zone(); | |
| 848 return NULL; | |
|
Avi (use Gerrit)
2012/09/13 19:45:54
Thanks for removing this.
Scott Hess - ex-Googler
2012/09/13 20:04:00
Oops, added about this to the CL description.
| |
| 849 } | 843 } |
| 850 | 844 |
| 851 void EnableTerminationOnOutOfMemory() { | 845 void EnableTerminationOnOutOfMemory() { |
| 852 if (g_oom_killer_enabled) | 846 if (g_oom_killer_enabled) |
| 853 return; | 847 return; |
| 854 | 848 |
| 855 g_oom_killer_enabled = true; | 849 g_oom_killer_enabled = true; |
| 856 | 850 |
| 857 // === C malloc/calloc/valloc/realloc/posix_memalign === | 851 // === C malloc/calloc/valloc/realloc/posix_memalign === |
| 858 | 852 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 873 #if !defined(ADDRESS_SANITIZER) | 867 #if !defined(ADDRESS_SANITIZER) |
| 874 // Don't do anything special on OOM for the malloc zones replaced by | 868 // Don't do anything special on OOM for the malloc zones replaced by |
| 875 // AddressSanitizer, as modifying or protecting them may not work correctly. | 869 // AddressSanitizer, as modifying or protecting them may not work correctly. |
| 876 | 870 |
| 877 // See http://trac.webkit.org/changeset/53362/trunk/Tools/DumpRenderTree/mac | 871 // See http://trac.webkit.org/changeset/53362/trunk/Tools/DumpRenderTree/mac |
| 878 bool zone_allocators_protected = base::mac::IsOSLionOrLater(); | 872 bool zone_allocators_protected = base::mac::IsOSLionOrLater(); |
| 879 | 873 |
| 880 ChromeMallocZone* default_zone = | 874 ChromeMallocZone* default_zone = |
| 881 reinterpret_cast<ChromeMallocZone*>(malloc_default_zone()); | 875 reinterpret_cast<ChromeMallocZone*>(malloc_default_zone()); |
| 882 ChromeMallocZone* purgeable_zone = | 876 ChromeMallocZone* purgeable_zone = |
| 883 reinterpret_cast<ChromeMallocZone*>(GetPurgeableZone()); | 877 reinterpret_cast<ChromeMallocZone*>(malloc_default_purgeable_zone()); |
| 884 | 878 |
| 885 vm_address_t page_start_default = 0; | 879 vm_address_t page_start_default = 0; |
| 886 vm_address_t page_start_purgeable = 0; | 880 vm_address_t page_start_purgeable = 0; |
| 887 vm_size_t len_default = 0; | 881 vm_size_t len_default = 0; |
| 888 vm_size_t len_purgeable = 0; | 882 vm_size_t len_purgeable = 0; |
| 889 if (zone_allocators_protected) { | 883 if (zone_allocators_protected) { |
| 890 page_start_default = reinterpret_cast<vm_address_t>(default_zone) & | 884 page_start_default = reinterpret_cast<vm_address_t>(default_zone) & |
| 891 static_cast<vm_size_t>(~(getpagesize() - 1)); | 885 static_cast<vm_size_t>(~(getpagesize() - 1)); |
| 892 len_default = reinterpret_cast<vm_address_t>(default_zone) - | 886 len_default = reinterpret_cast<vm_address_t>(default_zone) - |
| 893 page_start_default + sizeof(ChromeMallocZone); | 887 page_start_default + sizeof(ChromeMallocZone); |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1209 } | 1203 } |
| 1210 } | 1204 } |
| 1211 | 1205 |
| 1212 } // namespace | 1206 } // namespace |
| 1213 | 1207 |
| 1214 void EnsureProcessTerminated(ProcessHandle process) { | 1208 void EnsureProcessTerminated(ProcessHandle process) { |
| 1215 WaitForChildToDie(process, kWaitBeforeKillSeconds); | 1209 WaitForChildToDie(process, kWaitBeforeKillSeconds); |
| 1216 } | 1210 } |
| 1217 | 1211 |
| 1218 } // namespace base | 1212 } // namespace base |
| OLD | NEW |