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

Side by Side Diff: base/process/memory_mac.mm

Issue 2676093003: mac: Hook up allocator shim during app startup. (Closed)
Patch Set: Remove unused include. Created 3 years, 10 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
« no previous file with comments | « base/allocator/allocator_interception_mac.mm ('k') | base/process/memory_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/memory.h" 5 #include "base/process/memory.h"
6 6
7 #include "base/allocator/allocator_interception_mac.h" 7 #include "base/allocator/allocator_interception_mac.h"
8 #include "base/allocator/allocator_shim.h"
9 #include "base/allocator/features.h"
8 #include "build/build_config.h" 10 #include "build/build_config.h"
9 11
10 namespace base { 12 namespace base {
11 13
14 namespace {
15 void oom_killer_new() {
16 TerminateBecauseOutOfMemory(0);
17 }
18 } // namespace
19
12 void EnableTerminationOnHeapCorruption() { 20 void EnableTerminationOnHeapCorruption() {
13 #if !ARCH_CPU_64_BITS 21 #if !ARCH_CPU_64_BITS
14 DLOG(WARNING) << "EnableTerminationOnHeapCorruption only works on 64-bit"; 22 DLOG(WARNING) << "EnableTerminationOnHeapCorruption only works on 64-bit";
15 #endif 23 #endif
16 } 24 }
17 25
18 bool UncheckedMalloc(size_t size, void** result) { 26 bool UncheckedMalloc(size_t size, void** result) {
19 return allocator::UncheckedMallocMac(size, result); 27 return allocator::UncheckedMallocMac(size, result);
20 } 28 }
21 29
22 bool UncheckedCalloc(size_t num_items, size_t size, void** result) { 30 bool UncheckedCalloc(size_t num_items, size_t size, void** result) {
23 return allocator::UncheckedCallocMac(num_items, size, result); 31 return allocator::UncheckedCallocMac(num_items, size, result);
24 } 32 }
25 33
26 void EnableTerminationOnOutOfMemory() { 34 void EnableTerminationOnOutOfMemory() {
35 // Step 1: Enable OOM killer on C++ failures.
36 std::set_new_handler(oom_killer_new);
37
38 // Step 2: Enable OOM killer on C-malloc failures for the default zone (if we
39 // have a shim).
40 #if BUILDFLAG(USE_EXPERIMENTAL_ALLOCATOR_SHIM)
41 allocator::SetCallNewHandlerOnMallocFailure(true);
42 #endif
43
44 // Step 3: Enable OOM killer on all other malloc zones (or just "all" without
45 // "other" if shim is disabled).
27 allocator::InterceptAllocationsMac(); 46 allocator::InterceptAllocationsMac();
28 } 47 }
29 48
30 } // namespace base 49 } // namespace base
OLDNEW
« no previous file with comments | « base/allocator/allocator_interception_mac.mm ('k') | base/process/memory_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698