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

Unified Diff: base/allocator/malloc_zone_functions_mac.cc

Issue 2727463002: mac: Several minor fixes to allocator shim. (Closed)
Patch Set: more compile error. 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
« no previous file with comments | « base/allocator/malloc_zone_functions_mac.h ('k') | base/allocator/malloc_zone_functions_mac_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/allocator/malloc_zone_functions_mac.cc
diff --git a/base/allocator/malloc_zone_functions_mac.cc b/base/allocator/malloc_zone_functions_mac.cc
index e64719da9e63fa485e2a3a6aca2aa7644e458fba..9a4149603089839fa0a10f2230795d6934edab34 100644
--- a/base/allocator/malloc_zone_functions_mac.cc
+++ b/base/allocator/malloc_zone_functions_mac.cc
@@ -10,11 +10,13 @@
namespace base {
namespace allocator {
-MallocZoneFunctions* g_malloc_zones = nullptr;
-MallocZoneFunctions::MallocZoneFunctions() {}
+MallocZoneFunctions g_malloc_zones[kMaxZoneCount];
+static_assert(std::is_pod<MallocZoneFunctions>::value,
+ "MallocZoneFunctions must be POD");
void StoreZoneFunctions(const ChromeMallocZone* zone,
MallocZoneFunctions* functions) {
+ memset(functions, 0, sizeof(MallocZoneFunctions));
functions->malloc = zone->malloc;
functions->calloc = zone->calloc;
functions->valloc = zone->valloc;
@@ -51,10 +53,6 @@ base::Lock& GetLock() {
void EnsureMallocZonesInitializedLocked() {
GetLock().AssertAcquired();
- if (!g_malloc_zones) {
- g_malloc_zones = reinterpret_cast<base::allocator::MallocZoneFunctions*>(
- calloc(kMaxZoneCount, sizeof(MallocZoneFunctions)));
- }
}
int g_zone_count = 0;
@@ -71,14 +69,14 @@ bool IsMallocZoneAlreadyStoredLocked(ChromeMallocZone* zone) {
} // namespace
-void StoreMallocZone(ChromeMallocZone* zone) {
+bool StoreMallocZone(ChromeMallocZone* zone) {
base::AutoLock l(GetLock());
EnsureMallocZonesInitializedLocked();
if (IsMallocZoneAlreadyStoredLocked(zone))
- return;
+ return false;
if (g_zone_count == kMaxZoneCount)
- return;
+ return false;
StoreZoneFunctions(zone, &g_malloc_zones[g_zone_count]);
++g_zone_count;
@@ -87,6 +85,7 @@ void StoreMallocZone(ChromeMallocZone* zone) {
// reads these values is triggered after this function returns. so we want to
// guarantee that they are committed at this stage"
base::subtle::MemoryBarrier();
+ return true;
}
bool IsMallocZoneAlreadyStored(ChromeMallocZone* zone) {
@@ -94,6 +93,11 @@ bool IsMallocZoneAlreadyStored(ChromeMallocZone* zone) {
return IsMallocZoneAlreadyStoredLocked(zone);
}
+bool DoesMallocZoneNeedReplacing(ChromeMallocZone* zone,
+ const MallocZoneFunctions* functions) {
+ return IsMallocZoneAlreadyStored(zone) && zone->malloc != functions->malloc;
+}
+
int GetMallocZoneCountForTesting() {
base::AutoLock l(GetLock());
return g_zone_count;
« no previous file with comments | « base/allocator/malloc_zone_functions_mac.h ('k') | base/allocator/malloc_zone_functions_mac_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698