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

Unified Diff: base/allocator/malloc_zone_functions_mac.cc

Issue 2727463002: mac: Several minor fixes to allocator shim. (Closed)
Patch Set: Treat MallocZoneFunctions as POD. 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
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..6a7a4f75d5f6754e6fd793fbb75fe5e5be980a03 100644
--- a/base/allocator/malloc_zone_functions_mac.cc
+++ b/base/allocator/malloc_zone_functions_mac.cc
@@ -10,11 +10,11 @@
namespace base {
namespace allocator {
-MallocZoneFunctions* g_malloc_zones = nullptr;
-MallocZoneFunctions::MallocZoneFunctions() {}
+MallocZoneFunctions g_malloc_zones[kMaxZoneCount];
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 +51,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 +67,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 +83,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) {

Powered by Google App Engine
This is Rietveld 408576698