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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/process/memory_mac.mm
diff --git a/base/process/memory_mac.mm b/base/process/memory_mac.mm
index 155004dc0a43e257a4918d79b9e9b7aca4a96182..4b5a3ce9c8cb60834b8ab52ab594fa4585481585 100644
--- a/base/process/memory_mac.mm
+++ b/base/process/memory_mac.mm
@@ -5,10 +5,18 @@
#include "base/process/memory.h"
#include "base/allocator/allocator_interception_mac.h"
+#include "base/allocator/allocator_shim.h"
+#include "base/allocator/features.h"
#include "build/build_config.h"
namespace base {
+namespace {
+void oom_killer_new() {
+ TerminateBecauseOutOfMemory(0);
+}
+} // namespace
+
void EnableTerminationOnHeapCorruption() {
#if !ARCH_CPU_64_BITS
DLOG(WARNING) << "EnableTerminationOnHeapCorruption only works on 64-bit";
@@ -24,6 +32,17 @@ bool UncheckedCalloc(size_t num_items, size_t size, void** result) {
}
void EnableTerminationOnOutOfMemory() {
+ // Step 1: Enable OOM killer on C++ failures.
+ std::set_new_handler(oom_killer_new);
+
+// Step 2: Enable OOM killer on C-malloc failures for the default zone (if we
+// have a shim).
+#if BUILDFLAG(USE_EXPERIMENTAL_ALLOCATOR_SHIM)
+ allocator::SetCallNewHandlerOnMallocFailure(true);
+#endif
+
+ // Step 3: Enable OOM killer on all other malloc zones (or just "all" without
+ // "other" if shim is disabled).
allocator::InterceptAllocationsMac();
}
« 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