[SCM] WebKit Debian packaging branch, debian/experimental, updated. upstream/1.3.3-10851-g50815da

ggaren at apple.com ggaren at apple.com
Wed Dec 22 18:14:25 UTC 2010


The following commit has been merged in the debian/experimental branch:
commit 05fad6601e9c06287b63d9743794e448f0e5a123
Author: ggaren at apple.com <ggaren at apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Thu Dec 9 01:30:18 2010 +0000

    Migrated OS-specific allocation code from PageReservation and PageAllocation to OSAllocator
    https://bugs.webkit.org/show_bug.cgi?id=50653
    
    Reviewed by Sam Weinig.
    
    * JavaScriptCore.exp: Updated for new function signature.
    
    * interpreter/RegisterFile.h:
    (JSC::RegisterFile::RegisterFile):
    (JSC::RegisterFile::grow):
    * jit/ExecutableAllocatorFixedVMPool.cpp:
    (JSC::FixedVMPoolAllocator::reuse):
    (JSC::FixedVMPoolAllocator::FixedVMPoolAllocator): Removed checkAllocatedOkay.
    OSAllocator is now the central location for verifying that allocation succeeds.
    This allowed me to remove some complicating cross-platform cruft.
    
    * runtime/AlignedMemoryAllocator.h:
    (JSC::::allocate): Updated for code motion.
    
    * wtf/OSAllocator.h: Added Usage, writable, and executable parameters, to
    support VM features required by clients of PageAllocation and PageReservation.
    
    * wtf/OSAllocatorPosix.cpp:
    (WTF::OSAllocator::reserve):
    (WTF::OSAllocator::reserveAndCommit):
    (WTF::OSAllocator::commit): Moved PageAllocation support for randomizing
    executable memory here.
    
    * wtf/OSAllocatorSymbian.cpp:
    (WTF::OSAllocator::reserve):
    (WTF::OSAllocator::reserveAndCommit):
    (WTF::OSAllocator::commit): Updated for new function signatures.
    
    * wtf/OSAllocatorWin.cpp:
    (WTF::protection):
    (WTF::OSAllocator::reserve):
    (WTF::OSAllocator::reserveAndCommit):
    (WTF::OSAllocator::commit):
    (WTF::OSAllocator::release): Updated for new function signatures. Moved
    some protection-related and WINCE-related code from PageAllocation here.
    
    * wtf/PageAllocation.cpp: Nixed cross-platform lastError abstraction, since
    it was only used by checkAllocatedOkay, which is now gone.
    
    * wtf/PageAllocation.h:
    (WTF::PageAllocation::allocate):
    (WTF::PageAllocation::allocateAligned):
    (WTF::PageAllocation::deallocate):
    (WTF::PageAllocation::isPowerOfTwo):
    (WTF::PageAllocation::systemAllocateAligned): Removed system* functions,
    and replaced calls to them with calls to OSAllocator.
    
    * wtf/PageReservation.h:
    (WTF::PageReservation::commit):
    (WTF::PageReservation::decommit):
    (WTF::PageReservation::reserve):
    (WTF::PageReservation::deallocate):
    (WTF::PageReservation::PageReservation): Ditto. Added m_writable and
    m_executable because these flags are now required when committing memory.
    
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@73570 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/JavaScriptCore/ChangeLog b/JavaScriptCore/ChangeLog
index cda9ff6..8964fc5 100644
--- a/JavaScriptCore/ChangeLog
+++ b/JavaScriptCore/ChangeLog
@@ -1,3 +1,65 @@
+2010-12-07  Geoffrey Garen  <ggaren at apple.com>
+
+        Reviewed by Sam Weinig.
+
+        Migrated OS-specific allocation code from PageReservation and PageAllocation to OSAllocator
+        https://bugs.webkit.org/show_bug.cgi?id=50653
+
+        * JavaScriptCore.exp: Updated for new function signature.
+
+        * interpreter/RegisterFile.h:
+        (JSC::RegisterFile::RegisterFile):
+        (JSC::RegisterFile::grow):
+        * jit/ExecutableAllocatorFixedVMPool.cpp:
+        (JSC::FixedVMPoolAllocator::reuse):
+        (JSC::FixedVMPoolAllocator::FixedVMPoolAllocator): Removed checkAllocatedOkay.
+        OSAllocator is now the central location for verifying that allocation succeeds.
+        This allowed me to remove some complicating cross-platform cruft.
+
+        * runtime/AlignedMemoryAllocator.h:
+        (JSC::::allocate): Updated for code motion.
+
+        * wtf/OSAllocator.h: Added Usage, writable, and executable parameters, to
+        support VM features required by clients of PageAllocation and PageReservation.
+
+        * wtf/OSAllocatorPosix.cpp:
+        (WTF::OSAllocator::reserve):
+        (WTF::OSAllocator::reserveAndCommit):
+        (WTF::OSAllocator::commit): Moved PageAllocation support for randomizing
+        executable memory here.
+
+        * wtf/OSAllocatorSymbian.cpp:
+        (WTF::OSAllocator::reserve):
+        (WTF::OSAllocator::reserveAndCommit):
+        (WTF::OSAllocator::commit): Updated for new function signatures.
+
+        * wtf/OSAllocatorWin.cpp:
+        (WTF::protection):
+        (WTF::OSAllocator::reserve):
+        (WTF::OSAllocator::reserveAndCommit):
+        (WTF::OSAllocator::commit):
+        (WTF::OSAllocator::release): Updated for new function signatures. Moved
+        some protection-related and WINCE-related code from PageAllocation here.
+
+        * wtf/PageAllocation.cpp: Nixed cross-platform lastError abstraction, since
+        it was only used by checkAllocatedOkay, which is now gone.
+
+        * wtf/PageAllocation.h:
+        (WTF::PageAllocation::allocate):
+        (WTF::PageAllocation::allocateAligned):
+        (WTF::PageAllocation::deallocate):
+        (WTF::PageAllocation::isPowerOfTwo):
+        (WTF::PageAllocation::systemAllocateAligned): Removed system* functions,
+        and replaced calls to them with calls to OSAllocator.
+
+        * wtf/PageReservation.h:
+        (WTF::PageReservation::commit):
+        (WTF::PageReservation::decommit):
+        (WTF::PageReservation::reserve):
+        (WTF::PageReservation::deallocate):
+        (WTF::PageReservation::PageReservation): Ditto. Added m_writable and
+        m_executable because these flags are now required when committing memory.
+
 2010-12-08  Chris Rogers  <crogers at google.com>
 
         Reviewed by Kenneth Russell.
diff --git a/JavaScriptCore/JavaScriptCore.exp b/JavaScriptCore/JavaScriptCore.exp
index e4a92c5..f310f80 100644
--- a/JavaScriptCore/JavaScriptCore.exp
+++ b/JavaScriptCore/JavaScriptCore.exp
@@ -359,7 +359,7 @@ __ZN3WTF10StringImplD1Ev
 __ZN3WTF10fastCallocEmm
 __ZN3WTF10fastMallocEm
 __ZN3WTF10fastStrDupEPKc
-__ZN3WTF11OSAllocator16reserveAndCommitEm
+__ZN3WTF11OSAllocator16reserveAndCommitEmNS0_5UsageEbb
 __ZN3WTF11OSAllocator7releaseEPvm
 __ZN3WTF11commentAtomE
 __ZN3WTF11currentTimeEv
diff --git a/JavaScriptCore/interpreter/RegisterFile.h b/JavaScriptCore/interpreter/RegisterFile.h
index d9f6a2b..b29e9b2 100644
--- a/JavaScriptCore/interpreter/RegisterFile.h
+++ b/JavaScriptCore/interpreter/RegisterFile.h
@@ -138,7 +138,6 @@ namespace JSC {
         static void initializeThreading();
 
     private:
-        void checkAllocatedOkay(bool okay);
         void releaseExcessCapacity();
         void addToCommittedByteCount(long);
         size_t m_numGlobals;
@@ -164,11 +163,10 @@ namespace JSC {
         ASSERT(capacity && PageAllocation::isPageAligned(capacity));
 
         size_t bufferLength = (capacity + maxGlobals) * sizeof(Register);
-        m_reservation = PageReservation::reserve(roundUpAllocationSize(bufferLength, commitSize), PageAllocation::JSVMStackPages);
+        m_reservation = PageReservation::reserve(roundUpAllocationSize(bufferLength, commitSize), OSAllocator::JSVMStackPages);
         void* base = m_reservation.base();
-        checkAllocatedOkay(base);
         size_t committedSize = roundUpAllocationSize(maxGlobals * sizeof(Register), commitSize);
-        checkAllocatedOkay(m_reservation.commit(base, committedSize));
+        m_reservation.commit(base, committedSize);
         addToCommittedByteCount(static_cast<long>(committedSize));
         m_commitEnd = reinterpret_cast_ptr<Register*>(reinterpret_cast<char*>(base) + committedSize);
         m_start = static_cast<Register*>(base) + maxGlobals;
@@ -196,7 +194,7 @@ namespace JSC {
 
         if (newEnd > m_commitEnd) {
             size_t size = roundUpAllocationSize(reinterpret_cast<char*>(newEnd) - reinterpret_cast<char*>(m_commitEnd), commitSize);
-            checkAllocatedOkay(m_reservation.commit(m_commitEnd, size));
+            m_reservation.commit(m_commitEnd, size);
             addToCommittedByteCount(static_cast<long>(size));
             m_commitEnd = reinterpret_cast_ptr<Register*>(reinterpret_cast<char*>(m_commitEnd) + size);
         }
@@ -208,16 +206,6 @@ namespace JSC {
         return true;
     }
 
-    inline void RegisterFile::checkAllocatedOkay(bool okay)
-    {
-        if (!okay) {
-#ifndef NDEBUG
-            fprintf(stderr, "Could not allocate register file: %d\n", PageReservation::lastError());
-#endif
-            CRASH();
-        }
-    }
-
 } // namespace JSC
 
 #endif // RegisterFile_h
diff --git a/JavaScriptCore/jit/ExecutableAllocatorFixedVMPool.cpp b/JavaScriptCore/jit/ExecutableAllocatorFixedVMPool.cpp
index 37320cf..b79df77 100644
--- a/JavaScriptCore/jit/ExecutableAllocatorFixedVMPool.cpp
+++ b/JavaScriptCore/jit/ExecutableAllocatorFixedVMPool.cpp
@@ -133,8 +133,7 @@ class FixedVMPoolAllocator
 
     void reuse(void* position, size_t size)
     {
-        bool okay = m_allocation.commit(position, size);
-        ASSERT_UNUSED(okay, okay);
+        m_allocation.commit(position, size);
         addToCommittedByteCount(static_cast<long>(size));
     }
 
@@ -279,7 +278,7 @@ public:
         : m_commonSize(commonSize)
         , m_countFreedSinceLastCoalesce(0)
     {
-        m_allocation = PageReservation::reserve(totalHeapSize, PageAllocation::JSJITCodePages, EXECUTABLE_POOL_WRITABLE, true);
+        m_allocation = PageReservation::reserve(totalHeapSize, OSAllocator::JSJITCodePages, EXECUTABLE_POOL_WRITABLE, true);
 
         if (!!m_allocation)
             m_freeList.insert(new FreeListEntry(m_allocation.base(), m_allocation.size()));
diff --git a/JavaScriptCore/runtime/AlignedMemoryAllocator.h b/JavaScriptCore/runtime/AlignedMemoryAllocator.h
index e682eb3..c5dd4a3 100644
--- a/JavaScriptCore/runtime/AlignedMemoryAllocator.h
+++ b/JavaScriptCore/runtime/AlignedMemoryAllocator.h
@@ -76,7 +76,7 @@ inline void AlignedMemoryAllocator<blockSize>::destroy()
 template<size_t blockSize>
 inline AlignedMemory<blockSize> AlignedMemoryAllocator<blockSize>::allocate()
 {
-    return AlignedMemory<blockSize>(PageAllocation::allocateAligned(blockSize, PageAllocation::JSGCHeapPages));
+    return AlignedMemory<blockSize>(PageAllocation::allocateAligned(blockSize, OSAllocator::JSGCHeapPages));
 }
 
 template<size_t blockSize>
diff --git a/JavaScriptCore/wtf/OSAllocator.h b/JavaScriptCore/wtf/OSAllocator.h
index 9d80714..3c8173b 100644
--- a/JavaScriptCore/wtf/OSAllocator.h
+++ b/JavaScriptCore/wtf/OSAllocator.h
@@ -26,14 +26,24 @@
 #ifndef OSAllocator_h
 #define OSAllocator_h
 
+#include <wtf/VMTags.h>
+
 namespace WTF {
 
 class OSAllocator {
 public:
-    static void* reserve(size_t);
-    static void* reserveAndCommit(size_t);
-
-    static void commit(void*, size_t);
+    enum Usage {
+        UnknownUsage = -1,
+        FastMallocPages = VM_TAG_FOR_TCMALLOC_MEMORY,
+        JSGCHeapPages = VM_TAG_FOR_COLLECTOR_MEMORY,
+        JSVMStackPages = VM_TAG_FOR_REGISTERFILE_MEMORY,
+        JSJITCodePages = VM_TAG_FOR_EXECUTABLEALLOCATOR_MEMORY,
+    };
+
+    static void* reserve(size_t, Usage = UnknownUsage, bool writable = true, bool executable = false);
+    static void* reserveAndCommit(size_t, Usage = UnknownUsage, bool writable = true, bool executable = false);
+
+    static void commit(void*, size_t, bool writable, bool executable);
     static void decommit(void*, size_t);
 
     static void release(void*, size_t);
diff --git a/JavaScriptCore/wtf/OSAllocatorPosix.cpp b/JavaScriptCore/wtf/OSAllocatorPosix.cpp
index c1c3bb6..28ca291 100644
--- a/JavaScriptCore/wtf/OSAllocatorPosix.cpp
+++ b/JavaScriptCore/wtf/OSAllocatorPosix.cpp
@@ -33,11 +33,9 @@
 
 namespace WTF {
 
-void* OSAllocator::reserve(size_t bytes)
+void* OSAllocator::reserve(size_t bytes, Usage usage, bool writable, bool executable)
 {
-    void* result = mmap(0, bytes, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0);
-    if (result == MAP_FAILED)
-        CRASH();
+    void* result = reserveAndCommit(bytes, usage, writable, executable);
 #if HAVE(MADV_FREE_REUSE)
     // To support the "reserve then commit" model, we have to initially decommit.
     while (madvise(result, bytes, MADV_FREE_REUSABLE) == -1 && errno == EAGAIN) { }
@@ -45,16 +43,50 @@ void* OSAllocator::reserve(size_t bytes)
     return result;
 }
 
-void* OSAllocator::reserveAndCommit(size_t bytes)
+void* OSAllocator::reserveAndCommit(size_t bytes, Usage usage, bool writable, bool executable)
 {
     // All POSIX reservations start out logically committed.
-    void* result = mmap(0, bytes, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0);
+    int protection = PROT_READ;
+    if (writable)
+        protection |= PROT_WRITE;
+    if (executable)
+        protection |= PROT_EXEC;
+
+    int flags = MAP_PRIVATE | MAP_ANON;
+
+#if OS(DARWIN) && !defined(BUILDING_ON_TIGER)
+    int fd = usage;
+#else
+    int fd = -1;
+#endif
+
+    void* result = 0;
+#if (OS(DARWIN) && CPU(X86_64))
+    if (executable) {
+        // Cook up an address to allocate at, using the following recipe:
+        //   17 bits of zero, stay in userspace kids.
+        //   26 bits of randomness for ASLR.
+        //   21 bits of zero, at least stay aligned within one level of the pagetables.
+        //
+        // But! - as a temporary workaround for some plugin problems (rdar://problem/6812854),
+        // for now instead of 2^26 bits of ASLR lets stick with 25 bits of randomization plus
+        // 2^24, which should put up somewhere in the middle of userspace (in the address range
+        // 0x200000000000 .. 0x5fffffffffff).
+        intptr_t randomLocation = 0;
+        randomLocation = arc4random() & ((1 << 25) - 1);
+        randomLocation += (1 << 24);
+        randomLocation <<= 21;
+        result = reinterpret_cast<void*>(randomLocation);
+    }
+#endif
+
+    result = mmap(result, bytes, protection, flags, fd, 0);
     if (result == MAP_FAILED)
         CRASH();
     return result;
 }
 
-void OSAllocator::commit(void* address, size_t bytes)
+void OSAllocator::commit(void* address, size_t bytes, bool, bool)
 {
 #if HAVE(MADV_FREE_REUSE)
     while (madvise(address, bytes, MADV_FREE_REUSE) == -1 && errno == EAGAIN) { }
diff --git a/JavaScriptCore/wtf/OSAllocatorSymbian.cpp b/JavaScriptCore/wtf/OSAllocatorSymbian.cpp
index 445b77a..6329850 100644
--- a/JavaScriptCore/wtf/OSAllocatorSymbian.cpp
+++ b/JavaScriptCore/wtf/OSAllocatorSymbian.cpp
@@ -30,17 +30,17 @@
 
 namespace WTF {
 
-void* OSAllocator::reserve(size_t bytes)
+void* OSAllocator::reserve(size_t, Usage, bool, bool)
 {
     return fastMalloc(bytes);
 }
 
-void* OSAllocator::reserveAndCommit(size_t bytes)
+void* OSAllocator::reserveAndCommit(size_t bytes, Usage, bool, bool)
 {
     return reserve(bytes);
 }
 
-void OSAllocator::commit(void*, size_t)
+void OSAllocator::commit(void*, size_t, Usage, bool, bool)
 {
 }
 
diff --git a/JavaScriptCore/wtf/OSAllocatorWin.cpp b/JavaScriptCore/wtf/OSAllocatorWin.cpp
index 904331f..fc62fb7 100644
--- a/JavaScriptCore/wtf/OSAllocatorWin.cpp
+++ b/JavaScriptCore/wtf/OSAllocatorWin.cpp
@@ -31,25 +31,32 @@
 
 namespace WTF {
 
-void* OSAllocator::reserve(size_t bytes)
+static inline DWORD protection(bool writable, bool executable)
 {
-    void* result = VirtualAlloc(0, bytes, MEM_RESERVE, PAGE_READWRITE);
+    return executable ?
+        (writable ? PAGE_EXECUTE_READWRITE : PAGE_EXECUTE_READ) :
+        (writable ? PAGE_READWRITE : PAGE_READONLY);
+}
+
+void* OSAllocator::reserve(size_t bytes, Usage, bool writable, bool executable)
+{
+    void* result = VirtualAlloc(0, bytes, MEM_RESERVE, protection(writable, executable));
     if (!result)
         CRASH();
     return result;
 }
 
-void* OSAllocator::reserveAndCommit(size_t bytes)
+void* OSAllocator::reserveAndCommit(size_t bytes, Usage, bool writable, bool executable)
 {
-    void* result = VirtualAlloc(0, bytes, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
+    void* result = VirtualAlloc(0, bytes, MEM_RESERVE | MEM_COMMIT, protection(writable, executable));
     if (!result)
         CRASH();
     return result;
 }
 
-void OSAllocator::commit(void* address, size_t bytes)
+void OSAllocator::commit(void* address, size_t bytes, bool writable, bool executable)
 {
-    void* result = VirtualAlloc(address, bytes, MEM_COMMIT, PAGE_READWRITE);
+    void* result = VirtualAlloc(address, bytes, MEM_COMMIT, protection(writable, executable));
     if (!result)
         CRASH();
 }
@@ -63,6 +70,9 @@ void OSAllocator::decommit(void* address, size_t bytes)
 
 void OSAllocator::release(void* address, size_t bytes)
 {
+#if OS(WINCE)
+    decommit(address, bytes);
+#endif
     // According to http://msdn.microsoft.com/en-us/library/aa366892(VS.85).aspx,
     // dwSize must be 0 if dwFreeType is MEM_RELEASE.
     bool result = VirtualFree(address, 0, MEM_RELEASE);
diff --git a/JavaScriptCore/wtf/PageAllocation.cpp b/JavaScriptCore/wtf/PageAllocation.cpp
index f3fe997..01cfbc1 100644
--- a/JavaScriptCore/wtf/PageAllocation.cpp
+++ b/JavaScriptCore/wtf/PageAllocation.cpp
@@ -32,17 +32,4 @@ namespace WTF {
 
 size_t PageAllocation::s_pageSize = 0;
 
-#ifndef NDEBUG
-
-int PageAllocation::lastError()
-{
-#if OS(WINCE)
-    return GetLastError();
-#else
-    return errno;
-#endif
-}
-
-#endif
-
 }
diff --git a/JavaScriptCore/wtf/PageAllocation.h b/JavaScriptCore/wtf/PageAllocation.h
index 5a28e40..3585b33 100644
--- a/JavaScriptCore/wtf/PageAllocation.h
+++ b/JavaScriptCore/wtf/PageAllocation.h
@@ -27,6 +27,7 @@
 #define PageAllocation_h
 
 #include <wtf/Assertions.h>
+#include <wtf/OSAllocator.h>
 #include <wtf/UnusedParam.h>
 #include <wtf/VMTags.h>
 #include <algorithm>
@@ -82,14 +83,6 @@ namespace WTF {
 */
 class PageAllocation {
 public:
-    enum Usage {
-        UnknownUsage = -1,
-        FastMallocPages = VM_TAG_FOR_TCMALLOC_MEMORY,
-        JSGCHeapPages = VM_TAG_FOR_COLLECTOR_MEMORY,
-        JSVMStackPages = VM_TAG_FOR_REGISTERFILE_MEMORY,
-        JSJITCodePages = VM_TAG_FOR_EXECUTABLEALLOCATOR_MEMORY,
-    };
-
     PageAllocation()
         : m_base(0)
         , m_size(0)
@@ -103,14 +96,14 @@ public:
     void* base() const { return m_base; }
     size_t size() const { return m_size; }
 
-    static PageAllocation allocate(size_t size, Usage usage = UnknownUsage, bool writable = true, bool executable = false)
+    static PageAllocation allocate(size_t size, OSAllocator::Usage usage = OSAllocator::UnknownUsage, bool writable = true, bool executable = false)
     {
         ASSERT(isPageAligned(size));
-        return systemAllocate(size, usage, writable, executable);
+        return PageAllocation(OSAllocator::reserveAndCommit(size, usage, writable, executable), size);
     }
 
 #if HAVE(PAGE_ALLOCATE_ALIGNED)
-    static PageAllocation allocateAligned(size_t size, Usage usage = UnknownUsage)
+    static PageAllocation allocateAligned(size_t size, OSAllocator::Usage usage = OSAllocator::UnknownUsage)
     {
         ASSERT(isPageAligned(size));
         ASSERT(isPowerOfTwo(size));
@@ -121,7 +114,9 @@ public:
     void deallocate()
     {
         ASSERT(m_base);
-        systemDeallocate(true);
+        void* tmp = 0;
+        std::swap(tmp, m_base);
+        OSAllocator::release(tmp, m_size);
     }
 
     static size_t pageSize()
@@ -136,7 +131,6 @@ public:
     static bool isPageAligned(void* address) { return !(reinterpret_cast<intptr_t>(address) & (pageSize() - 1)); }
     static bool isPageAligned(size_t size) { return !(size & (pageSize() - 1)); }
     static bool isPowerOfTwo(size_t size) { return !(size & (size - 1)); }
-    static int lastError();
 #endif
 
 protected:
@@ -155,13 +149,9 @@ protected:
     }
 #endif
 
-    static PageAllocation systemAllocate(size_t, Usage, bool, bool);
 #if HAVE(PAGE_ALLOCATE_ALIGNED)
-    static PageAllocation systemAllocateAligned(size_t, Usage);
+    static PageAllocation systemAllocateAligned(size_t, OSAllocator::Usage);
 #endif
-    // systemDeallocate takes a parameter indicating whether memory is currently committed
-    // (this should always be true for PageAllocation, false for PageReservation).
-    void systemDeallocate(bool committed);
     static size_t systemPageSize();
 
     void* m_base;
@@ -177,49 +167,7 @@ protected:
 #if HAVE(MMAP)
 
 
-inline PageAllocation PageAllocation::systemAllocate(size_t size, Usage usage, bool writable, bool executable)
-{
-    int protection = PROT_READ;
-    if (writable)
-        protection |= PROT_WRITE;
-    if (executable)
-        protection |= PROT_EXEC;
-
-    int flags = MAP_PRIVATE | MAP_ANON;
-
-#if OS(DARWIN) && !defined(BUILDING_ON_TIGER)
-    int fd = usage;
-#else
-    int fd = -1;
-#endif
-
-    void* base = 0;
-#if (OS(DARWIN) && CPU(X86_64))
-    if (executable) {
-        // Cook up an address to allocate at, using the following recipe:
-        //   17 bits of zero, stay in userspace kids.
-        //   26 bits of randomness for ASLR.
-        //   21 bits of zero, at least stay aligned within one level of the pagetables.
-        //
-        // But! - as a temporary workaround for some plugin problems (rdar://problem/6812854),
-        // for now instead of 2^26 bits of ASLR lets stick with 25 bits of randomization plus
-        // 2^24, which should put up somewhere in the middle of userspace (in the address range
-        // 0x200000000000 .. 0x5fffffffffff).
-        intptr_t randomLocation = 0;
-        randomLocation = arc4random() & ((1 << 25) - 1);
-        randomLocation += (1 << 24);
-        randomLocation <<= 21;
-        base = reinterpret_cast<void*>(randomLocation);
-    }
-#endif
-
-    base = mmap(base, size, protection, flags, fd, 0);
-    if (base == MAP_FAILED)
-        base = 0;
-    return PageAllocation(base, size);
-}
-
-inline PageAllocation PageAllocation::systemAllocateAligned(size_t size, Usage usage)
+inline PageAllocation PageAllocation::systemAllocateAligned(size_t size, OSAllocator::Usage usage)
 {
 #if OS(DARWIN)
     vm_address_t address = 0;
@@ -262,15 +210,6 @@ inline PageAllocation PageAllocation::systemAllocateAligned(size_t size, Usage u
 #endif
 }
 
-inline void PageAllocation::systemDeallocate(bool)
-{
-    void* tmp = 0;
-    std::swap(tmp, m_base);
-
-    int result = munmap(tmp, m_size);
-    ASSERT_UNUSED(result, !result);
-}
-
 inline size_t PageAllocation::systemPageSize()
 {
     return getpagesize();
@@ -280,16 +219,8 @@ inline size_t PageAllocation::systemPageSize()
 #elif HAVE(VIRTUALALLOC)
 
 
-inline PageAllocation PageAllocation::systemAllocate(size_t size, Usage, bool writable, bool executable)
-{
-    DWORD protection = executable ?
-        (writable ? PAGE_EXECUTE_READWRITE : PAGE_EXECUTE_READ) :
-        (writable ? PAGE_READWRITE : PAGE_READONLY);
-    return PageAllocation(VirtualAlloc(0, size, MEM_COMMIT | MEM_RESERVE, protection), size);
-}
-
 #if HAVE(ALIGNED_MALLOC)
-inline PageAllocation PageAllocation::systemAllocateAligned(size_t size, Usage usage)
+inline PageAllocation PageAllocation::systemAllocateAligned(size_t size, OSAllocator::Usage usage)
 {
 #if COMPILER(MINGW) && !COMPILER(MINGW64)
     void* address = __mingw_aligned_malloc(size, size);
@@ -301,20 +232,6 @@ inline PageAllocation PageAllocation::systemAllocateAligned(size_t size, Usage u
 }
 #endif
 
-inline void PageAllocation::systemDeallocate(bool committed)
-{
-    void* tmp = 0;
-    std::swap(tmp, m_base);
-
-#if OS(WINCE)
-    if (committed)
-        VirtualFree(tmp, m_size, MEM_DECOMMIT);
-#else
-    UNUSED_PARAM(committed);
-#endif
-    VirtualFree(tmp, 0, MEM_RELEASE); 
-}
-
 inline size_t PageAllocation::systemPageSize()
 {
     static size_t size = 0;
@@ -328,25 +245,6 @@ inline size_t PageAllocation::systemPageSize()
 #elif OS(SYMBIAN)
 
 
-inline PageAllocation PageAllocation::systemAllocate(size_t size, Usage usage, bool writable, bool executable)
-{
-    RChunk* rchunk = new RChunk();
-    if (executable)
-        rchunk->CreateLocalCode(size, size);
-    else
-        rchunk->CreateLocal(size, size);
-    return PageAllocation(rchunk->Base(), size, rchunk);
-}
-
-inline void PageAllocation::systemDeallocate(bool)
-{
-    void* tmp = 0;
-    std::swap(tmp, m_base);
-
-    m_chunk->Close();
-    delete m_chunk;
-}
-
 inline size_t PageAllocation::systemPageSize()
 {
     static TInt page_size = 0;
diff --git a/JavaScriptCore/wtf/PageReservation.h b/JavaScriptCore/wtf/PageReservation.h
index 28f06bb..ae06efc 100644
--- a/JavaScriptCore/wtf/PageReservation.h
+++ b/JavaScriptCore/wtf/PageReservation.h
@@ -52,9 +52,6 @@ namespace WTF {
     Memory protection should not be changed on decommitted memory, and if protection
     is changed on memory while it is committed it should be returned to the orignal
     protection before decommit is called.
-
-    Note: Inherits from PageAllocation privately to prevent clients accidentally
-    calling PageAllocation::deallocate on a PageReservation.
 */
 class PageReservation : private PageAllocation {
 public:
@@ -66,19 +63,18 @@ public:
     using PageAllocation::base;
     using PageAllocation::size;
 
-    bool commit(void* start, size_t size)
+    void commit(void* start, size_t size)
     {
         ASSERT(m_base);
         ASSERT(isPageAligned(start));
         ASSERT(isPageAligned(size));
 
-        bool commited = systemCommit(start, size);
 #ifndef NDEBUG
-        if (commited)
-            m_committed += size;
+        m_committed += size;
 #endif
-        return commited;
+        OSAllocator::commit(start, size, m_writable, m_executable);
     }
+
     void decommit(void* start, size_t size)
     {
         ASSERT(m_base);
@@ -88,149 +84,44 @@ public:
 #ifndef NDEBUG
         m_committed -= size;
 #endif
-        systemDecommit(start, size);
+        OSAllocator::decommit(start, size);
     }
 
-    static PageReservation reserve(size_t size, Usage usage = UnknownUsage, bool writable = true, bool executable = false)
+    static PageReservation reserve(size_t size, OSAllocator::Usage usage = OSAllocator::UnknownUsage, bool writable = true, bool executable = false)
     {
         ASSERT(isPageAligned(size));
-        return systemReserve(size, usage, writable, executable);
+        return PageReservation(OSAllocator::reserve(size, usage, writable, executable), size, writable, executable);
     }
 
     void deallocate()
     {
-        ASSERT(m_base);
         ASSERT(!m_committed);
-        systemDeallocate(false);
+        PageAllocation::deallocate();
     }
 
-#ifndef NDEBUG
-    using PageAllocation::lastError;
-#endif
-
 private:
 #if OS(SYMBIAN)
     PageReservation(void* base, size_t size, RChunk* chunk)
         : PageAllocation(base, size, chunk)
 #else
-    PageReservation(void* base, size_t size)
+    PageReservation(void* base, size_t size, bool writable, bool executable)
         : PageAllocation(base, size)
 #endif
 #ifndef NDEBUG
         , m_committed(0)
 #endif
+        , m_writable(writable)
+        , m_executable(executable)
     {
     }
 
-    bool systemCommit(void*, size_t);
-    void systemDecommit(void*, size_t);
-    static PageReservation systemReserve(size_t, Usage, bool, bool);
-
-#if HAVE(VIRTUALALLOC)
-    DWORD m_protection;
-#endif
 #ifndef NDEBUG
     size_t m_committed;
 #endif
+    bool m_writable;
+    bool m_executable;
 };
 
-
-#if HAVE(MMAP)
-
-
-inline bool PageReservation::systemCommit(void* start, size_t size)
-{
-#if HAVE(MADV_FREE_REUSE)
-    while (madvise(start, size, MADV_FREE_REUSE) == -1 && errno == EAGAIN) { }
-#else
-    UNUSED_PARAM(start);
-    UNUSED_PARAM(size);
-#endif
-    return true;
-}
-
-inline void PageReservation::systemDecommit(void* start, size_t size)
-{
-#if HAVE(MADV_FREE_REUSE)
-    while (madvise(start, size, MADV_FREE_REUSABLE) == -1 && errno == EAGAIN) { }
-#elif HAVE(MADV_FREE)
-    while (madvise(start, size, MADV_FREE) == -1 && errno == EAGAIN) { }
-#elif HAVE(MADV_DONTNEED)
-    while (madvise(start, size, MADV_DONTNEED) == -1 && errno == EAGAIN) { }
-#else
-    UNUSED_PARAM(start);
-    UNUSED_PARAM(size);
-#endif
-}
-
-inline PageReservation PageReservation::systemReserve(size_t size, Usage usage, bool writable, bool executable)
-{
-    void* base = systemAllocate(size, usage, writable, executable).base();
-#if HAVE(MADV_FREE_REUSE)
-    // When using MADV_FREE_REUSE we keep all decommitted memory marked as REUSABLE.
-    // We call REUSE on commit, and REUSABLE on decommit.
-    if (base)
-        while (madvise(base, size, MADV_FREE_REUSABLE) == -1 && errno == EAGAIN) { }
-#endif
-    return PageReservation(base, size);
-}
-
-
-#elif HAVE(VIRTUALALLOC)
-
-
-inline bool PageReservation::systemCommit(void* start, size_t size)
-{
-    return VirtualAlloc(start, size, MEM_COMMIT, m_protection) == start;
-}
-
-inline void PageReservation::systemDecommit(void* start, size_t size)
-{
-    VirtualFree(start, size, MEM_DECOMMIT);
-}
-
-inline PageReservation PageReservation::systemReserve(size_t size, Usage usage, bool writable, bool executable)
-{
-    // Record the protection for use during commit.
-    DWORD protection = executable ?
-        (writable ? PAGE_EXECUTE_READWRITE : PAGE_EXECUTE_READ) :
-        (writable ? PAGE_READWRITE : PAGE_READONLY);
-    PageReservation reservation(VirtualAlloc(0, size, MEM_RESERVE, protection), size);
-    reservation.m_protection = protection;
-    return reservation;
-}
-
-
-#elif OS(SYMBIAN)
-
-
-inline bool PageReservation::systemCommit(void* start, size_t size)
-{
-    intptr_t offset = reinterpret_cast<intptr_t>(start) - reinterpret_cast<intptr_t>(m_base);
-    m_chunk->Commit(offset, size);
-    return true;
-}
-
-inline void PageReservation::systemDecommit(void* start, size_t size)
-{
-    intptr_t offset = reinterpret_cast<intptr_t>(start) - reinterpret_cast<intptr_t>(m_base);
-    m_chunk->Decommit(offset, size);
-}
-
-inline PageReservation PageReservation::systemReserve(size_t size, Usage usage, bool writable, bool executable)
-{
-    RChunk* rchunk = new RChunk();
-    if (executable)
-        rchunk->CreateLocalCode(0, size);
-    else
-        rchunk->CreateDisconnectedLocal(0, 0, size);
-    return PageReservation(rchunk->Base(), size, rchunk);
-}
-
-
-#endif
-
-
 }
 
 using WTF::PageReservation;

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list