Commit 9eba0cb2 authored by andersca@apple.com's avatar andersca@apple.com
Browse files

Move RemoteMemoryReader into FastMalloc.cpp

https://bugs.webkit.org/show_bug.cgi?id=115985

Reviewed by Andreas Kling.

RemoteMemoryReader is only used in FastMalloc.cpp, and even had one of its member functions
implemented there, so move the entire class template there and remove MallocZoneSupport.h.

* GNUmakefile.list.am:
* WTF.pro:
* WTF.vcproj/WTF.vcproj:
* WTF.vcxproj/WTF.vcxproj:
* WTF.vcxproj/WTF.vcxproj.filters:
* WTF.xcodeproj/project.pbxproj:
* wtf/CMakeLists.txt:
* wtf/FastMalloc.cpp:
(WTF):
(PageHeapAllocator):
(WTF::TCMalloc_ThreadCache::CreateCacheIfNecessary):
* wtf/MallocZoneSupport.h: Removed.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@149963 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 20e062bd
2013-05-12 Anders Carlsson <andersca@apple.com>
Move RemoteMemoryReader into FastMalloc.cpp
https://bugs.webkit.org/show_bug.cgi?id=115985
Reviewed by Andreas Kling.
RemoteMemoryReader is only used in FastMalloc.cpp, and even had one of its member functions
implemented there, so move the entire class template there and remove MallocZoneSupport.h.
* GNUmakefile.list.am:
* WTF.pro:
* WTF.vcproj/WTF.vcproj:
* WTF.vcxproj/WTF.vcxproj:
* WTF.vcxproj/WTF.vcxproj.filters:
* WTF.xcodeproj/project.pbxproj:
* wtf/CMakeLists.txt:
* wtf/FastMalloc.cpp:
(WTF):
(PageHeapAllocator):
(WTF::TCMalloc_ThreadCache::CreateCacheIfNecessary):
* wtf/MallocZoneSupport.h: Removed.
2013-05-10 Laszlo Gombos <l.gombos@samsung.com>
 
Remove USE(OS_RANDOMNESS)
......
......@@ -83,7 +83,6 @@ wtf_sources += \
Source/WTF/wtf/MD5.h \
Source/WTF/wtf/MainThread.cpp \
Source/WTF/wtf/MainThread.h \
Source/WTF/wtf/MallocZoneSupport.h \
Source/WTF/wtf/MathExtras.h \
Source/WTF/wtf/MediaTime.h \
Source/WTF/wtf/MediaTime.cpp \
......
......@@ -85,7 +85,6 @@ HEADERS += \
ListHashSet.h \
Locker.h \
MainThread.h \
MallocZoneSupport.h \
MathExtras.h \
MD5.h \
MediaTime.h \
......
......@@ -902,10 +902,6 @@
RelativePath="..\wtf\MainThread.h"
>
</File>
<File
RelativePath="..\wtf\MallocZoneSupport.h"
>
</File>
<File
RelativePath="..\wtf\MathExtras.h"
>
......
......@@ -161,7 +161,6 @@
<ClInclude Include="..\wtf\ListHashSet.h" />
<ClInclude Include="..\wtf\Locker.h" />
<ClInclude Include="..\wtf\MainThread.h" />
<ClInclude Include="..\wtf\MallocZoneSupport.h" />
<ClInclude Include="..\wtf\MathExtras.h" />
<ClInclude Include="..\wtf\MD5.h" />
<ClInclude Include="..\wtf\MediaTime.h" />
......
......@@ -486,9 +486,6 @@
<ClInclude Include="..\wtf\MainThread.h">
<Filter>wtf</Filter>
</ClInclude>
<ClInclude Include="..\wtf\MallocZoneSupport.h">
<Filter>wtf</Filter>
</ClInclude>
<ClInclude Include="..\wtf\MathExtras.h">
<Filter>wtf</Filter>
</ClInclude>
......
......@@ -142,7 +142,6 @@
A8A473E4151A825B004123FF /* MainThreadMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = A8A472C5151A825A004123FF /* MainThreadMac.mm */; };
A8A473E5151A825B004123FF /* MainThread.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A8A472C6151A825A004123FF /* MainThread.cpp */; };
A8A473E6151A825B004123FF /* MainThread.h in Headers */ = {isa = PBXBuildFile; fileRef = A8A472C7151A825B004123FF /* MainThread.h */; };
A8A473E7151A825B004123FF /* MallocZoneSupport.h in Headers */ = {isa = PBXBuildFile; fileRef = A8A472C8151A825B004123FF /* MallocZoneSupport.h */; };
A8A473E8151A825B004123FF /* MathExtras.h in Headers */ = {isa = PBXBuildFile; fileRef = A8A472C9151A825B004123FF /* MathExtras.h */; };
A8A473E9151A825B004123FF /* MD5.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A8A472CA151A825B004123FF /* MD5.cpp */; };
A8A473EA151A825B004123FF /* MD5.h in Headers */ = {isa = PBXBuildFile; fileRef = A8A472CB151A825B004123FF /* MD5.h */; };
......@@ -416,7 +415,6 @@
A8A472C5151A825A004123FF /* MainThreadMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MainThreadMac.mm; sourceTree = "<group>"; };
A8A472C6151A825A004123FF /* MainThread.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MainThread.cpp; sourceTree = "<group>"; };
A8A472C7151A825B004123FF /* MainThread.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MainThread.h; sourceTree = "<group>"; };
A8A472C8151A825B004123FF /* MallocZoneSupport.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MallocZoneSupport.h; sourceTree = "<group>"; };
A8A472C9151A825B004123FF /* MathExtras.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MathExtras.h; sourceTree = "<group>"; };
A8A472CA151A825B004123FF /* MD5.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MD5.cpp; sourceTree = "<group>"; };
A8A472CB151A825B004123FF /* MD5.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MD5.h; sourceTree = "<group>"; };
......@@ -688,7 +686,6 @@
A8A472C3151A825A004123FF /* Locker.h */,
A8A472C6151A825A004123FF /* MainThread.cpp */,
A8A472C7151A825B004123FF /* MainThread.h */,
A8A472C8151A825B004123FF /* MallocZoneSupport.h */,
A8A472C9151A825B004123FF /* MathExtras.h */,
A8A472CA151A825B004123FF /* MD5.cpp */,
A8A472CB151A825B004123FF /* MD5.h */,
......@@ -999,7 +996,6 @@
A8A473E1151A825B004123FF /* ListHashSet.h in Headers */,
A8A473E3151A825B004123FF /* Locker.h in Headers */,
A8A473E6151A825B004123FF /* MainThread.h in Headers */,
A8A473E7151A825B004123FF /* MallocZoneSupport.h in Headers */,
A8A473E8151A825B004123FF /* MathExtras.h in Headers */,
A8A473EA151A825B004123FF /* MD5.h in Headers */,
CD5497AD15857D0300B5BC30 /* MediaTime.h in Headers */,
......
......@@ -45,7 +45,6 @@ set(WTF_HEADERS
Locker.h
MD5.h
MainThread.h
MallocZoneSupport.h
MathExtras.h
MediaTime.h
MessageQueue.h
......
......@@ -90,6 +90,10 @@
#include <wtf/StdLibExtras.h>
#include <wtf/UnusedParam.h>
#if OS(DARWIN)
#include <malloc/malloc.h>
#endif
#ifndef NO_TCMALLOC_SAMPLES
#ifdef WTF_CHANGES
#define NO_TCMALLOC_SAMPLES
......@@ -231,9 +235,7 @@ TryMallocReturnValue tryFastZeroedMalloc(size_t n)
#if FORCE_SYSTEM_MALLOC
#if OS(DARWIN)
#include <malloc/malloc.h>
#elif OS(WINDOWS)
#if OS(WINDOWS)
#include <malloc.h>
#endif
......@@ -452,7 +454,6 @@ extern "C" WTF_EXPORT_PRIVATE const int jscore_fastmalloc_introspection = 0;
#ifdef WTF_CHANGES
#if OS(DARWIN)
#include "MallocZoneSupport.h"
#include <wtf/HashSet.h>
#include <wtf/Vector.h>
#endif
......@@ -1059,6 +1060,10 @@ static void* MetaDataAlloc(size_t bytes) {
return result;
}
#if defined(WTF_CHANGES) && OS(DARWIN)
class RemoteMemoryReader;
#endif
template <class T>
class PageHeapAllocator {
private:
......@@ -1131,12 +1136,8 @@ class PageHeapAllocator {
int inuse() const { return inuse_; }
#if defined(WTF_CHANGES) && OS(DARWIN)
template <class Recorder>
void recordAdministrativeRegions(Recorder& recorder, const RemoteMemoryReader& reader)
{
for (HardenedSLL adminAllocation = allocated_regions_; adminAllocation; adminAllocation.setValue(reader.nextEntryInHardenedLinkedList(reinterpret_cast<void**>(adminAllocation.value()), entropy_)))
recorder.recordRegion(reinterpret_cast<vm_address_t>(adminAllocation.value()), kAllocIncrement);
}
template <typename Recorder>
void recordAdministrativeRegions(Recorder&, const RemoteMemoryReader&);
#endif
};
......@@ -4681,17 +4682,50 @@ size_t fastMallocSize(const void* ptr)
}
#if OS(DARWIN)
class RemoteMemoryReader {
task_t m_task;
memory_reader_t* m_reader;
public:
RemoteMemoryReader(task_t task, memory_reader_t* reader)
: m_task(task)
, m_reader(reader)
{ }
void* operator()(vm_address_t address, size_t size) const
{
void* output;
kern_return_t err = (*m_reader)(m_task, address, size, static_cast<void**>(&output));
if (err)
output = 0;
return output;
}
template <typename T>
T* operator()(T* address, size_t size = sizeof(T)) const
{
return static_cast<T*>((*this)(reinterpret_cast<vm_address_t>(address), size));
}
template <typename T>
T* nextEntryInHardenedLinkedList(T** remoteAddress, uintptr_t entropy) const
{
T** localAddress = (*this)(remoteAddress);
if (!localAddress)
return 0;
T* hardenedNext = *localAddress;
if (!hardenedNext || hardenedNext == (void*)entropy)
return 0;
return XOR_MASK_PTR_WITH_KEY(hardenedNext, remoteAddress, entropy);
}
};
template <typename T>
T* RemoteMemoryReader::nextEntryInHardenedLinkedList(T** remoteAddress, uintptr_t entropy) const
template <typename Recorder>
void PageHeapAllocator<T>::recordAdministrativeRegions(Recorder& recorder, const RemoteMemoryReader& reader)
{
T** localAddress = (*this)(remoteAddress);
if (!localAddress)
return 0;
T* hardenedNext = *localAddress;
if (!hardenedNext || hardenedNext == (void*)entropy)
return 0;
return XOR_MASK_PTR_WITH_KEY(hardenedNext, remoteAddress, entropy);
for (HardenedSLL adminAllocation = allocated_regions_; adminAllocation; adminAllocation.setValue(reader.nextEntryInHardenedLinkedList(reinterpret_cast<void**>(adminAllocation.value()), entropy_)))
recorder.recordRegion(reinterpret_cast<vm_address_t>(adminAllocation.value()), kAllocIncrement);
}
class FreeObjectFinder {
......
/*
* Copyright (C) 2007 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef MallocZoneSupport_h
#define MallocZoneSupport_h
#include <malloc/malloc.h>
namespace WTF {
class RemoteMemoryReader {
task_t m_task;
memory_reader_t* m_reader;
public:
RemoteMemoryReader(task_t task, memory_reader_t* reader)
: m_task(task)
, m_reader(reader)
{ }
void* operator()(vm_address_t address, size_t size) const
{
void* output;
kern_return_t err = (*m_reader)(m_task, address, size, static_cast<void**>(&output));
if (err)
output = 0;
return output;
}
template <typename T>
T* operator()(T* address, size_t size=sizeof(T)) const
{
return static_cast<T*>((*this)(reinterpret_cast<vm_address_t>(address), size));
}
template <typename T>
T* nextEntryInHardenedLinkedList(T** address, uintptr_t entropy) const;
};
} // namespace WTF
#endif // MallocZoneSupport_h
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment