summaryrefslogtreecommitdiffstats
path: root/base/process_util_mac.mm
diff options
context:
space:
mode:
authoravi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-01 16:35:22 +0000
committeravi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-01 16:35:22 +0000
commit39b011a438415a19ce78df050af9dbca3f9ec204 (patch)
tree79a222889346b1051de4243b37cd8edb0395e310 /base/process_util_mac.mm
parent71f1fc95107fb420699ebbabc15ff4b79ff9c305 (diff)
downloadchromium_src-39b011a438415a19ce78df050af9dbca3f9ec204.zip
chromium_src-39b011a438415a19ce78df050af9dbca3f9ec204.tar.gz
chromium_src-39b011a438415a19ce78df050af9dbca3f9ec204.tar.bz2
Revert 51371 - Catch OOMs in purgeable memory.
BUG=http://crbug.com/47980 TEST=unit tested Review URL: http://codereview.chromium.org/2859036 TBR=avi@chromium.org Review URL: http://codereview.chromium.org/2883014 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@51373 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/process_util_mac.mm')
-rw-r--r--base/process_util_mac.mm127
1 files changed, 7 insertions, 120 deletions
diff --git a/base/process_util_mac.mm b/base/process_util_mac.mm
index c9543db..457e69b 100644
--- a/base/process_util_mac.mm
+++ b/base/process_util_mac.mm
@@ -7,7 +7,6 @@
#import <Cocoa/Cocoa.h>
#include <crt_externs.h>
-#include <dlfcn.h>
#include <mach/mach.h>
#include <mach/mach_init.h>
#include <mach/task.h>
@@ -406,12 +405,6 @@ valloc_type g_old_valloc;
realloc_type g_old_realloc;
memalign_type g_old_memalign;
-malloc_type g_old_malloc_purgeable;
-calloc_type g_old_calloc_purgeable;
-valloc_type g_old_valloc_purgeable;
-realloc_type g_old_realloc_purgeable;
-memalign_type g_old_memalign_purgeable;
-
void* oom_killer_malloc(struct _malloc_zone_t* zone,
size_t size) {
void* result = g_old_malloc(zone, size);
@@ -460,54 +453,6 @@ void* oom_killer_memalign(struct _malloc_zone_t* zone,
return result;
}
-void* oom_killer_malloc_purgeable(struct _malloc_zone_t* zone,
- size_t size) {
- void* result = g_old_malloc_purgeable(zone, size);
- if (!result && size)
- DebugUtil::BreakDebugger();
- return result;
-}
-
-void* oom_killer_calloc_purgeable(struct _malloc_zone_t* zone,
- size_t num_items,
- size_t size) {
- void* result = g_old_calloc_purgeable(zone, num_items, size);
- if (!result && num_items && size)
- DebugUtil::BreakDebugger();
- return result;
-}
-
-void* oom_killer_valloc_purgeable(struct _malloc_zone_t* zone,
- size_t size) {
- void* result = g_old_valloc_purgeable(zone, size);
- if (!result && size)
- DebugUtil::BreakDebugger();
- return result;
-}
-
-void* oom_killer_realloc_purgeable(struct _malloc_zone_t* zone,
- void* ptr,
- size_t size) {
- void* result = g_old_realloc_purgeable(zone, ptr, size);
- if (!result && size)
- DebugUtil::BreakDebugger();
- return result;
-}
-
-void* oom_killer_memalign_purgeable(struct _malloc_zone_t* zone,
- size_t alignment,
- size_t size) {
- void* result = g_old_memalign_purgeable(zone, alignment, size);
- // Only die if posix_memalign would have returned ENOMEM, since there are
- // other reasons why NULL might be returned (see
- // http://opensource.apple.com/source/Libc/Libc-583/gen/malloc.c ).
- if (!result && size && alignment >= sizeof(void*)
- && (alignment & (alignment - 1)) == 0) {
- DebugUtil::BreakDebugger();
- }
- return result;
-}
-
// === C++ operator new ===
void oom_killer_new() {
@@ -595,16 +540,6 @@ id oom_killer_allocWithZone(id self, SEL _cmd, NSZone* zone)
} // namespace
-malloc_zone_t* GetPurgeableZone() {
- // malloc_default_purgeable_zone only exists on >= 10.6. Use dlsym to grab it
- // at runtime because it may not be present in the SDK used for compilation.
- typedef malloc_zone_t* (*malloc_default_purgeable_zone_t)(void);
- malloc_default_purgeable_zone_t malloc_purgeable_zone =
- reinterpret_cast<malloc_default_purgeable_zone_t>(
- dlsym(RTLD_DEFAULT, "malloc_default_purgeable_zone"));
- return malloc_purgeable_zone();
-}
-
void EnableTerminationOnOutOfMemory() {
if (g_oom_killer_enabled)
return;
@@ -628,43 +563,23 @@ void EnableTerminationOnOutOfMemory() {
CHECK(!g_old_malloc && !g_old_calloc && !g_old_valloc && !g_old_realloc &&
!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";
-
// See http://trac.webkit.org/changeset/53362/trunk/WebKitTools/DumpRenderTree/mac
bool zone_allocators_protected =
((os_major == 10 && os_minor > 6) || os_major > 10);
ChromeMallocZone* default_zone =
reinterpret_cast<ChromeMallocZone*>(malloc_default_zone());
- ChromeMallocZone* purgeable_zone =
- reinterpret_cast<ChromeMallocZone*>(GetPurgeableZone());
- vm_address_t page_start_default = NULL;
- vm_address_t page_start_purgeable = NULL;
- vm_size_t len_default = 0;
- vm_size_t len_purgeable = 0;
+ vm_address_t page_start = NULL;
+ vm_size_t len = 0;
if (zone_allocators_protected) {
- page_start_default = reinterpret_cast<vm_address_t>(default_zone) &
+ page_start = reinterpret_cast<vm_address_t>(default_zone) &
static_cast<vm_size_t>(~(getpagesize() - 1));
- len_default = reinterpret_cast<vm_address_t>(default_zone) -
- page_start_default + sizeof(ChromeMallocZone);
- mprotect(reinterpret_cast<void*>(page_start_default), len_default,
- PROT_READ | PROT_WRITE);
-
- if (purgeable_zone) {
- page_start_purgeable = reinterpret_cast<vm_address_t>(purgeable_zone) &
- static_cast<vm_size_t>(~(getpagesize() - 1));
- len_purgeable = reinterpret_cast<vm_address_t>(purgeable_zone) -
- page_start_purgeable + sizeof(ChromeMallocZone);
- mprotect(reinterpret_cast<void*>(page_start_purgeable), len_purgeable,
- PROT_READ | PROT_WRITE);
- }
+ len = reinterpret_cast<vm_address_t>(default_zone) -
+ page_start + sizeof(malloc_zone_t);
+ mprotect(reinterpret_cast<void*>(page_start), len, PROT_READ | PROT_WRITE);
}
- // Default zone
-
g_old_malloc = default_zone->malloc;
g_old_calloc = default_zone->calloc;
g_old_valloc = default_zone->valloc;
@@ -683,36 +598,8 @@ void EnableTerminationOnOutOfMemory() {
default_zone->memalign = oom_killer_memalign;
}
- // Purgeable zone (if it exists)
-
- if (purgeable_zone) {
- g_old_malloc_purgeable = purgeable_zone->malloc;
- g_old_calloc_purgeable = purgeable_zone->calloc;
- g_old_valloc_purgeable = purgeable_zone->valloc;
- g_old_realloc_purgeable = purgeable_zone->realloc;
- CHECK(g_old_malloc_purgeable && g_old_calloc_purgeable &&
- g_old_valloc_purgeable && g_old_realloc_purgeable)
- << "Failed to get system allocation functions.";
-
- purgeable_zone->malloc = oom_killer_malloc_purgeable;
- purgeable_zone->calloc = oom_killer_calloc_purgeable;
- purgeable_zone->valloc = oom_killer_valloc_purgeable;
- purgeable_zone->realloc = oom_killer_realloc_purgeable;
-
- if (purgeable_zone->version >= 5) {
- g_old_memalign_purgeable = purgeable_zone->memalign;
- if (g_old_memalign_purgeable)
- purgeable_zone->memalign = oom_killer_memalign_purgeable;
- }
- }
-
if (zone_allocators_protected) {
- mprotect(reinterpret_cast<void*>(page_start_default), len_default,
- PROT_READ);
- if (purgeable_zone) {
- mprotect(reinterpret_cast<void*>(page_start_purgeable), len_purgeable,
- PROT_READ);
- }
+ mprotect(reinterpret_cast<void*>(page_start), len, PROT_READ);
}
// === C malloc_zone_batch_malloc ===