From 3e2fc8a68b7767156e0e4961a979a7f132e7f6f5 Mon Sep 17 00:00:00 2001 From: "ggaren@apple.com" Date: Tue, 3 Mar 2015 21:58:02 +0000 Subject: [PATCH] bmalloc should implement malloc introspection (to stop false-positive leaks when MallocStackLogging is off) https://bugs.webkit.org/show_bug.cgi?id=141802 Reviewed by Andreas Kling. Rolling back in but disabled on iOS until I can debug why the iOS PLT crashes. * bmalloc/VMHeap.cpp: (bmalloc::VMHeap::grow): * bmalloc/VMHeap.h: * bmalloc/Zone.cpp: (bmalloc::Zone::size): (bmalloc::Zone::Zone): * bmalloc/Zone.h: git-svn-id: https://svn.webkit.org/repository/webkit/trunk@180954 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- Source/bmalloc/ChangeLog | 17 +++++++++++++++++ Source/bmalloc/bmalloc/VMHeap.cpp | 2 +- Source/bmalloc/bmalloc/VMHeap.h | 4 ++-- Source/bmalloc/bmalloc/Zone.cpp | 14 +++++++++++--- Source/bmalloc/bmalloc/Zone.h | 1 + 5 files changed, 32 insertions(+), 6 deletions(-) diff --git a/Source/bmalloc/ChangeLog b/Source/bmalloc/ChangeLog index db35f277d9a5..b07124499606 100644 --- a/Source/bmalloc/ChangeLog +++ b/Source/bmalloc/ChangeLog @@ -1,3 +1,20 @@ +2015-03-03 Geoffrey Garen + + bmalloc should implement malloc introspection (to stop false-positive leaks when MallocStackLogging is off) + https://bugs.webkit.org/show_bug.cgi?id=141802 + + Reviewed by Andreas Kling. + + Rolling back in but disabled on iOS until I can debug why the iOS PLT crashes. + + * bmalloc/VMHeap.cpp: + (bmalloc::VMHeap::grow): + * bmalloc/VMHeap.h: + * bmalloc/Zone.cpp: + (bmalloc::Zone::size): + (bmalloc::Zone::Zone): + * bmalloc/Zone.h: + 2015-03-03 Geoffrey Garen bmalloc: Miscellaneous cleanup diff --git a/Source/bmalloc/bmalloc/VMHeap.cpp b/Source/bmalloc/bmalloc/VMHeap.cpp index 26ffb1f19bc3..2aad2b11847c 100644 --- a/Source/bmalloc/bmalloc/VMHeap.cpp +++ b/Source/bmalloc/bmalloc/VMHeap.cpp @@ -40,7 +40,7 @@ VMHeap::VMHeap() void VMHeap::grow() { SuperChunk* superChunk = SuperChunk::create(); -#if BPLATFORM(DARWIN) +#if BOS(DARWIN) && !BPLATFORM(IOS) m_zone.addSuperChunk(superChunk); #endif diff --git a/Source/bmalloc/bmalloc/VMHeap.h b/Source/bmalloc/bmalloc/VMHeap.h index d581ab6596f6..9ddceab4c950 100644 --- a/Source/bmalloc/bmalloc/VMHeap.h +++ b/Source/bmalloc/bmalloc/VMHeap.h @@ -35,7 +35,7 @@ #include "SegregatedFreeList.h" #include "SmallChunk.h" #include "Vector.h" -#if BPLATFORM(DARWIN) +#if BOS(DARWIN) && !BPLATFORM(IOS) #include "Zone.h" #endif @@ -66,7 +66,7 @@ private: Vector m_smallPages; Vector m_mediumPages; SegregatedFreeList m_largeObjects; -#if BPLATFORM(DARWIN) +#if BOS(DARWIN) && !BPLATFORM(IOS) Zone m_zone; #endif }; diff --git a/Source/bmalloc/bmalloc/Zone.cpp b/Source/bmalloc/bmalloc/Zone.cpp index f2174ce8e2e0..9cfa71539918 100644 --- a/Source/bmalloc/bmalloc/Zone.cpp +++ b/Source/bmalloc/bmalloc/Zone.cpp @@ -42,6 +42,13 @@ template static void remoteRead(task_t task, memory_reader_t reader, memcpy(&result, tmp, sizeof(T)); } +// Support malloc_zone_from_ptr, which calls size() on each registered zone. +size_t Zone::size(malloc_zone_t*, const void*) +{ + // Our zone is not public API, so no pointer can belong to us. + return 0; +} + // This function runs inside the leaks process. kern_return_t Zone::enumerator(task_t task, void* context, unsigned type_mask, vm_address_t zone_address, memory_reader_t reader, vm_range_recorder_t recorder) { @@ -63,9 +70,10 @@ kern_return_t Zone::enumerator(task_t task, void* context, unsigned type_mask, v Zone::Zone() { - version = 4; - zone_name = "WebKit Malloc"; - introspect = &bmalloc::introspect; + malloc_zone_t::size = size; + malloc_zone_t::zone_name = "WebKit Malloc"; + malloc_zone_t::introspect = &bmalloc::introspect; + malloc_zone_t::version = 4; malloc_zone_register(this); } diff --git a/Source/bmalloc/bmalloc/Zone.h b/Source/bmalloc/bmalloc/Zone.h index b9fc228edeab..4fe496e8a7a8 100644 --- a/Source/bmalloc/bmalloc/Zone.h +++ b/Source/bmalloc/bmalloc/Zone.h @@ -38,6 +38,7 @@ public: // Enough capacity to track a 64GB heap, so probably enough for anything. static const size_t capacity = 2048; + static size_t size(malloc_zone_t*, const void*); static kern_return_t enumerator(task_t, void* context, unsigned type_mask, vm_address_t, memory_reader_t, vm_range_recorder_t); Zone(); -- 2.36.0