Changeset 86906 in webkit


Ignore:
Timestamp:
May 19, 2011 4:46:16 PM (13 years ago)
Author:
oliver@apple.com
Message:

2011-05-19 Oliver Hunt <oliver@apple.com>

Reviewed by Gavin Barraclough.

Add guard pages to each end of the memory region used by the fixedvm allocator
https://bugs.webkit.org/show_bug.cgi?id=61150

Add mechanism to notify the OSAllocator that pages at either end of an
allocation should be considered guard pages. Update PageReservation,
PageAllocation, etc to handle this.

  • JavaScriptCore.exp:
  • jit/ExecutableAllocatorFixedVMPool.cpp: (JSC::FixedVMPoolAllocator::FixedVMPoolAllocator):
  • wtf/OSAllocator.h:
  • wtf/OSAllocatorPosix.cpp: (WTF::OSAllocator::reserveUncommitted): (WTF::OSAllocator::reserveAndCommit):
  • wtf/PageAllocation.h: (WTF::PageAllocation::PageAllocation):
  • wtf/PageAllocationAligned.h: (WTF::PageAllocationAligned::PageAllocationAligned):
  • wtf/PageBlock.h: (WTF::PageBlock::PageBlock):
  • wtf/PageReservation.h: (WTF::PageReservation::reserve): (WTF::PageReservation::reserveWithGuardPages):

Add a new function to make a reservation that will add guard
pages to the ends of an allocation.

(WTF::PageReservation::PageReservation):

Location:
trunk/Source/JavaScriptCore
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r86883 r86906  
     12011-05-19  Oliver Hunt  <oliver@apple.com>
     2
     3        Reviewed by Gavin Barraclough.
     4
     5        Add guard pages to each end of the memory region used by the fixedvm allocator
     6        https://bugs.webkit.org/show_bug.cgi?id=61150
     7
     8        Add mechanism to notify the OSAllocator that pages at either end of an
     9        allocation should be considered guard pages.  Update PageReservation,
     10        PageAllocation, etc to handle this.
     11
     12        * JavaScriptCore.exp:
     13        * jit/ExecutableAllocatorFixedVMPool.cpp:
     14        (JSC::FixedVMPoolAllocator::FixedVMPoolAllocator):
     15        * wtf/OSAllocator.h:
     16        * wtf/OSAllocatorPosix.cpp:
     17        (WTF::OSAllocator::reserveUncommitted):
     18        (WTF::OSAllocator::reserveAndCommit):
     19        * wtf/PageAllocation.h:
     20        (WTF::PageAllocation::PageAllocation):
     21        * wtf/PageAllocationAligned.h:
     22        (WTF::PageAllocationAligned::PageAllocationAligned):
     23        * wtf/PageBlock.h:
     24        (WTF::PageBlock::PageBlock):
     25        * wtf/PageReservation.h:
     26        (WTF::PageReservation::reserve):
     27        (WTF::PageReservation::reserveWithGuardPages):
     28            Add a new function to make a reservation that will add guard
     29            pages to the ends of an allocation.
     30        (WTF::PageReservation::PageReservation):
     31
    1322011-05-19  Oliver Hunt  <oliver@apple.com>
    233
  • trunk/Source/JavaScriptCore/JavaScriptCore.exp

    r86837 r86906  
    376376__ZN3WTF10fastMallocEm
    377377__ZN3WTF10fastStrDupEPKc
    378 __ZN3WTF11OSAllocator16reserveAndCommitEmNS0_5UsageEbb
     378__ZN3WTF11OSAllocator16reserveAndCommitEmNS0_5UsageEbbb
    379379__ZN3WTF11OSAllocator18releaseDecommittedEPvm
    380380__ZN3WTF11commentAtomE
  • trunk/Source/JavaScriptCore/JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def

    r86850 r86906  
    286286    ?releaseStack@MarkStack@JSC@@CAXPAXI@Z
    287287    ?reportExtraMemoryCostSlowCase@Heap@JSC@@AAEXI@Z
    288     ?reserveAndCommit@OSAllocator@WTF@@SAPAXIW4Usage@12@_N1@Z
     288    ?reserveAndCommit@OSAllocator@WTF@@SAPAXIW4Usage@12@_N11@Z
    289289    ?reserveCapacity@StringBuilder@WTF@@QAEXI@Z
    290290    ?reset@ParserArena@JSC@@QAEXXZ
  • trunk/Source/JavaScriptCore/jit/ExecutableAllocatorFixedVMPool.cpp

    r77145 r86906  
    410410        ASSERT(PageTables1GB::size() == 1024 * 1024 * 1024);
    411411
    412         m_reservation = PageReservation::reserve(FixedVMPoolPageTables::size(), OSAllocator::JSJITCodePages, EXECUTABLE_POOL_WRITABLE, true);
     412        m_reservation = PageReservation::reserveWithGuardPages(FixedVMPoolPageTables::size(), OSAllocator::JSJITCodePages, EXECUTABLE_POOL_WRITABLE, true);
    413413#if !ENABLE(INTERPRETER)
    414414        if (!isValid())
  • trunk/Source/JavaScriptCore/wtf/OSAllocator.h

    r79126 r86906  
    4646    // releaseDecommitted should be called on a region of VM allocated by a single reservation,
    4747    // the memory must all currently be in a decommitted state.
    48     static void* reserveUncommitted(size_t, Usage = UnknownUsage, bool writable = true, bool executable = false);
     48    static void* reserveUncommitted(size_t, Usage = UnknownUsage, bool writable = true, bool executable = false, bool includesGuardPages = false);
    4949    static void releaseDecommitted(void*, size_t);
    5050
     
    5858    // decommitAndRelease should be called on a region of VM allocated by a single reservation,
    5959    // the memory must all currently be in a committed state.
    60     static void* reserveAndCommit(size_t, Usage = UnknownUsage, bool writable = true, bool executable = false);
     60    static void* reserveAndCommit(size_t, Usage = UnknownUsage, bool writable = true, bool executable = false, bool includesGuardPages = false);
    6161    static void decommitAndRelease(void* base, size_t size);
    6262
  • trunk/Source/JavaScriptCore/wtf/OSAllocatorPosix.cpp

    r85041 r86906  
    2727#include "OSAllocator.h"
    2828
     29#include "PageAllocation.h"
    2930#include <errno.h>
    3031#include <sys/mman.h>
     
    3435namespace WTF {
    3536
    36 void* OSAllocator::reserveUncommitted(size_t bytes, Usage usage, bool writable, bool executable)
     37void* OSAllocator::reserveUncommitted(size_t bytes, Usage usage, bool writable, bool executable, bool includesGuardPages)
    3738{
    38     void* result = reserveAndCommit(bytes, usage, writable, executable);
     39    void* result = reserveAndCommit(bytes, usage, writable, executable, includesGuardPages);
    3940#if HAVE(MADV_FREE_REUSE)
    4041    // To support the "reserve then commit" model, we have to initially decommit.
     
    4445}
    4546
    46 void* OSAllocator::reserveAndCommit(size_t bytes, Usage usage, bool writable, bool executable)
     47void* OSAllocator::reserveAndCommit(size_t bytes, Usage usage, bool writable, bool executable, bool includesGuardPages)
    4748{
    4849    // All POSIX reservations start out logically committed.
     
    6465#if (OS(DARWIN) && CPU(X86_64))
    6566    if (executable) {
     67        ASSERT(includesGuardPages);
    6668        // Cook up an address to allocate at, using the following recipe:
    6769        //   17 bits of zero, stay in userspace kids.
     
    8486    if (result == MAP_FAILED)
    8587        CRASH();
     88    if (includesGuardPages) {
     89        mprotect(result, pageSize(), PROT_NONE);
     90        mprotect(static_cast<char*>(result) + bytes - pageSize(), pageSize(), PROT_NONE);
     91    }
    8692    return result;
    8793}
  • trunk/Source/JavaScriptCore/wtf/OSAllocatorSymbian.cpp

    r79126 r86906  
    7575
    7676// Reserve memory and return the base address of the region
    77 void* OSAllocator::reserveUncommitted(size_t reservationSize, Usage usage, bool , bool executable)
     77void* OSAllocator::reserveUncommitted(size_t reservationSize, Usage usage, bool , bool executable, bool)
    7878{
    7979    void* base = 0;
     
    111111}
    112112   
    113 void* OSAllocator::reserveAndCommit(size_t bytes, Usage usage, bool writable, bool executable)
     113void* OSAllocator::reserveAndCommit(size_t bytes, Usage usage, bool writable, bool executable, bool)
    114114{
    115115    void* base = reserveUncommitted(bytes, usage, writable, executable);
  • trunk/Source/JavaScriptCore/wtf/PageAllocation.h

    r76409 r86906  
    118118private:
    119119    PageAllocation(void* base, size_t size)
    120         : PageBlock(base, size)
     120        : PageBlock(base, size, false)
    121121    {
    122122    }
  • trunk/Source/JavaScriptCore/wtf/PageAllocationAligned.h

    r74431 r86906  
    4949#if OS(DARWIN)
    5050    PageAllocationAligned(void* base, size_t size)
    51         : PageBlock(base, size)
     51        : PageBlock(base, size, false)
    5252    {
    5353    }
    5454#else
    5555    PageAllocationAligned(void* base, size_t size, void* reservationBase, size_t reservationSize)
    56         : PageBlock(base, size)
    57         , m_reservation(reservationBase, reservationSize)
     56        : PageBlock(base, size, false)
     57        , m_reservation(reservationBase, reservationSize, false)
    5858    {
    5959    }
  • trunk/Source/JavaScriptCore/wtf/PageBlock.h

    r74431 r86906  
    3838    PageBlock();
    3939    PageBlock(const PageBlock&);
    40     PageBlock(void*, size_t);
     40    PageBlock(void*, size_t, bool hasGuardPages);
    4141   
    4242    void* base() const { return m_base; }
     
    5252
    5353private:
     54    void* m_realBase;
    5455    void* m_base;
    5556    size_t m_size;
     
    5758
    5859inline PageBlock::PageBlock()
    59     : m_base(0)
     60    : m_realBase(0)
     61    , m_base(0)
    6062    , m_size(0)
    6163{
     
    6365
    6466inline PageBlock::PageBlock(const PageBlock& other)
    65     : m_base(other.m_base)
     67    : m_realBase(other.m_realBase)
     68    , m_base(other.m_base)
    6669    , m_size(other.m_size)
    6770{
    6871}
    6972
    70 inline PageBlock::PageBlock(void* base, size_t size)
    71     : m_base(base)
     73inline PageBlock::PageBlock(void* base, size_t size, bool hasGuardPages)
     74    : m_realBase(base)
     75    , m_base(static_cast<char*>(base) + (hasGuardPages ? pageSize() : 0))
    7276    , m_size(size)
    7377{
  • trunk/Source/JavaScriptCore/wtf/PageReservation.h

    r77145 r86906  
    105105    {
    106106        ASSERT(isPageAligned(size));
    107         return PageReservation(OSAllocator::reserveUncommitted(size, usage, writable, executable), size, writable, executable);
     107        return PageReservation(OSAllocator::reserveUncommitted(size, usage, writable, executable), size, writable, executable, false);
     108    }
     109   
     110    static PageReservation reserveWithGuardPages(size_t size, OSAllocator::Usage usage = OSAllocator::UnknownUsage, bool writable = true, bool executable = false)
     111    {
     112        ASSERT(isPageAligned(size));
     113        return PageReservation(OSAllocator::reserveUncommitted(size + pageSize() * 2, usage, writable, executable, true), size, writable, executable, true);
    108114    }
    109115
     
    124130
    125131private:
    126     PageReservation(void* base, size_t size, bool writable, bool executable)
    127         : PageBlock(base, size)
     132    PageReservation(void* base, size_t size, bool writable, bool executable, bool hasGuardPages)
     133        : PageBlock(base, size, hasGuardPages)
    128134        , m_committed(0)
    129135        , m_writable(writable)
Note: See TracChangeset for help on using the changeset viewer.