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

Unified Diff: base/allocator/allocator_interception_mac.mm

Issue 2713553002: mac: Periodically shim new malloc zones immediately after startup. (Closed)
Patch Set: Comments from primiano. Created 3 years, 9 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
Index: base/allocator/allocator_interception_mac.mm
diff --git a/base/allocator/allocator_interception_mac.mm b/base/allocator/allocator_interception_mac.mm
index 70c40c45c2055ce7212d89872d49575120145364..6a72e232bf07fbdf6ee35c85a42cd2efed111b36 100644
--- a/base/allocator/allocator_interception_mac.mm
+++ b/base/allocator/allocator_interception_mac.mm
@@ -29,11 +29,15 @@
#include "base/allocator/features.h"
#include "base/allocator/malloc_zone_functions_mac.h"
+#include "base/base_switches.h"
+#include "base/bind.h"
+#include "base/command_line.h"
Primiano Tucci (use gerrit) 2017/04/03 08:03:24 nit: you don't need command-line and base_switches
#include "base/logging.h"
#include "base/mac/mac_util.h"
#include "base/mac/mach_logging.h"
#include "base/process/memory.h"
#include "base/scoped_clear_errno.h"
+#include "base/threading/sequenced_task_runner_handle.h"
#include "build/build_config.h"
#include "third_party/apple_apsl/CFBase.h"
@@ -524,5 +528,36 @@ void UninterceptMallocZonesForTesting() {
ClearAllMallocZonesForTesting();
}
+namespace {
+
+void ShimNewMallocZones(base::Time end_time, base::TimeDelta delay) {
+ StoreFunctionsForAllZones();
+
+ // Use the functions for the default zone as a template to replace those
+ // new zones.
+ ChromeMallocZone* default_zone =
+ reinterpret_cast<ChromeMallocZone*>(malloc_default_zone());
+ DCHECK(IsMallocZoneAlreadyStored(default_zone));
+
+ MallocZoneFunctions new_functions;
+ StoreZoneFunctions(default_zone, &new_functions);
+ ReplaceFunctionsForStoredZones(&new_functions);
+
+ if (base::Time::Now() > end_time)
+ return;
+
+ base::TimeDelta next_delay = delay * 2;
+ SequencedTaskRunnerHandle::Get()->PostDelayedTask(
+ FROM_HERE, base::Bind(&ShimNewMallocZones, end_time, next_delay), delay);
+}
+
+} // namespace
+
+void PeriodicallyShimNewMallocZones() {
+ base::Time end_time = base::Time::Now() + base::TimeDelta::FromMinutes(1);
+ base::TimeDelta initial_delay = base::TimeDelta::FromSeconds(1);
+ ShimNewMallocZones(end_time, initial_delay);
+}
+
} // namespace allocator
} // namespace base

Powered by Google App Engine
This is Rietveld 408576698