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

Side by Side Diff: base/process_util_mac.mm

Issue 10908245: unchecked_malloc() for Skia on OSX. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: -> unchecked_malloc Created 8 years, 3 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
OLDNEW
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>
11 #include <mach/mach.h> 11 #include <mach/mach.h>
12 #include <mach/mach_init.h> 12 #include <mach/mach_init.h>
13 #include <mach/mach_vm.h> 13 #include <mach/mach_vm.h>
14 #include <mach/shared_region.h> 14 #include <mach/shared_region.h>
15 #include <mach/task.h> 15 #include <mach/task.h>
16 #include <mach-o/dyld.h>
17 #include <mach-o/nlist.h> 16 #include <mach-o/nlist.h>
18 #include <malloc/malloc.h> 17 #include <malloc/malloc.h>
19 #import <objc/runtime.h> 18 #import <objc/runtime.h>
20 #include <signal.h> 19 #include <signal.h>
21 #include <spawn.h> 20 #include <spawn.h>
22 #include <sys/event.h> 21 #include <sys/event.h>
23 #include <sys/mman.h> 22 #include <sys/mman.h>
24 #include <sys/sysctl.h> 23 #include <sys/sysctl.h>
25 #include <sys/types.h> 24 #include <sys/types.h>
26 #include <sys/wait.h> 25 #include <sys/wait.h>
27 26
28 #include <new> 27 #include <new>
29 #include <string> 28 #include <string>
30 29
31 #include "base/debug/debugger.h" 30 #include "base/debug/debugger.h"
32 #include "base/eintr_wrapper.h" 31 #include "base/eintr_wrapper.h"
33 #include "base/file_util.h" 32 #include "base/file_util.h"
34 #include "base/hash_tables.h" 33 #include "base/hash_tables.h"
35 #include "base/logging.h" 34 #include "base/logging.h"
36 #include "base/mac/mac_util.h" 35 #include "base/mac/mac_util.h"
37 #include "base/string_util.h" 36 #include "base/string_util.h"
38 #include "base/sys_info.h" 37 #include "base/sys_info.h"
39 #include "base/sys_string_conversions.h"
40 #include "base/time.h"
41 #include "third_party/apple_apsl/CFBase.h" 38 #include "third_party/apple_apsl/CFBase.h"
42 #include "third_party/apple_apsl/malloc.h" 39 #include "third_party/apple_apsl/malloc.h"
43 #include "third_party/mach_override/mach_override.h" 40 #include "third_party/mach_override/mach_override.h"
44 41
45 namespace base { 42 namespace base {
46 43
47 void RestoreDefaultExceptionHandler() { 44 void RestoreDefaultExceptionHandler() {
48 // This function is tailored to remove the Breakpad exception handler. 45 // This function is tailored to remove the Breakpad exception handler.
49 // exception_mask matches s_exception_mask in 46 // exception_mask matches s_exception_mask in
50 // breakpad/src/client/mac/handler/exception_handler.cc 47 // breakpad/src/client/mac/handler/exception_handler.cc
(...skipping 778 matching lines...) Expand 10 before | Expand all | Expand 10 after
829 id oom_killer_allocWithZone(id self, SEL _cmd, NSZone* zone) 826 id oom_killer_allocWithZone(id self, SEL _cmd, NSZone* zone)
830 { 827 {
831 id result = g_old_allocWithZone(self, _cmd, zone); 828 id result = g_old_allocWithZone(self, _cmd, zone);
832 if (!result) 829 if (!result)
833 debug::BreakDebugger(); 830 debug::BreakDebugger();
834 return result; 831 return result;
835 } 832 }
836 833
837 } // namespace 834 } // namespace
838 835
839 malloc_zone_t* GetPurgeableZone() { 836 void* unchecked_malloc(size_t size) {
Mark Mentovai 2012/09/17 18:28:11 Good cleanup.
840 // malloc_default_purgeable_zone only exists on >= 10.6. Use dlsym to grab it 837 if (g_old_malloc)
841 // at runtime because it may not be present in the SDK used for compilation. 838 return g_old_malloc(malloc_default_zone(), size);
842 typedef malloc_zone_t* (*malloc_default_purgeable_zone_t)(void); 839 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;
849 } 840 }
850 841
851 void EnableTerminationOnOutOfMemory() { 842 void EnableTerminationOnOutOfMemory() {
852 if (g_oom_killer_enabled) 843 if (g_oom_killer_enabled)
853 return; 844 return;
854 845
855 g_oom_killer_enabled = true; 846 g_oom_killer_enabled = true;
856 847
857 // === C malloc/calloc/valloc/realloc/posix_memalign === 848 // === C malloc/calloc/valloc/realloc/posix_memalign ===
858 849
(...skipping 14 matching lines...) Expand all
873 #if !defined(ADDRESS_SANITIZER) 864 #if !defined(ADDRESS_SANITIZER)
874 // Don't do anything special on OOM for the malloc zones replaced by 865 // Don't do anything special on OOM for the malloc zones replaced by
875 // AddressSanitizer, as modifying or protecting them may not work correctly. 866 // AddressSanitizer, as modifying or protecting them may not work correctly.
876 867
877 // See http://trac.webkit.org/changeset/53362/trunk/Tools/DumpRenderTree/mac 868 // See http://trac.webkit.org/changeset/53362/trunk/Tools/DumpRenderTree/mac
878 bool zone_allocators_protected = base::mac::IsOSLionOrLater(); 869 bool zone_allocators_protected = base::mac::IsOSLionOrLater();
879 870
880 ChromeMallocZone* default_zone = 871 ChromeMallocZone* default_zone =
881 reinterpret_cast<ChromeMallocZone*>(malloc_default_zone()); 872 reinterpret_cast<ChromeMallocZone*>(malloc_default_zone());
882 ChromeMallocZone* purgeable_zone = 873 ChromeMallocZone* purgeable_zone =
883 reinterpret_cast<ChromeMallocZone*>(GetPurgeableZone()); 874 reinterpret_cast<ChromeMallocZone*>(malloc_default_purgeable_zone());
884 875
885 vm_address_t page_start_default = 0; 876 vm_address_t page_start_default = 0;
886 vm_address_t page_start_purgeable = 0; 877 vm_address_t page_start_purgeable = 0;
887 vm_size_t len_default = 0; 878 vm_size_t len_default = 0;
888 vm_size_t len_purgeable = 0; 879 vm_size_t len_purgeable = 0;
889 if (zone_allocators_protected) { 880 if (zone_allocators_protected) {
890 page_start_default = reinterpret_cast<vm_address_t>(default_zone) & 881 page_start_default = reinterpret_cast<vm_address_t>(default_zone) &
891 static_cast<vm_size_t>(~(getpagesize() - 1)); 882 static_cast<vm_size_t>(~(getpagesize() - 1));
892 len_default = reinterpret_cast<vm_address_t>(default_zone) - 883 len_default = reinterpret_cast<vm_address_t>(default_zone) -
893 page_start_default + sizeof(ChromeMallocZone); 884 page_start_default + sizeof(ChromeMallocZone);
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
1209 } 1200 }
1210 } 1201 }
1211 1202
1212 } // namespace 1203 } // namespace
1213 1204
1214 void EnsureProcessTerminated(ProcessHandle process) { 1205 void EnsureProcessTerminated(ProcessHandle process) {
1215 WaitForChildToDie(process, kWaitBeforeKillSeconds); 1206 WaitForChildToDie(process, kWaitBeforeKillSeconds);
1216 } 1207 }
1217 1208
1218 } // namespace base 1209 } // namespace base
OLDNEW
« base/process_util.h ('K') | « base/process_util.h ('k') | base/process_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698