Changeset 199936 in webkit


Ignore:
Timestamp:
Apr 22, 2016 4:56:53 PM (8 years ago)
Author:
ggaren@apple.com
Message:

bmalloc: vm allocations should plant guard pages
https://bugs.webkit.org/show_bug.cgi?id=156937

Reviewed by Michael Saboff.

  • bmalloc/Object.h:

(bmalloc::Object::operator-): Added a - helper.

  • bmalloc/VMAllocate.h:

(bmalloc::vmRevokePermissions): Added a helper to revoke permissions on
a VM region. We use this for guard pages.

  • bmalloc/VMHeap.cpp:

(bmalloc::VMHeap::allocateSmallChunk): Add guard pages to the start and
end of the chunk.

Note that we don't guard large chunks becuase we need to be able to merge
them. Otherwise, we will run out of virtual addresses.

Location:
trunk/Source/bmalloc
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/bmalloc/ChangeLog

    r199934 r199936  
     12016-04-22  Geoffrey Garen  <ggaren@apple.com>
     2
     3        bmalloc: vm allocations should plant guard pages
     4        https://bugs.webkit.org/show_bug.cgi?id=156937
     5
     6        Reviewed by Michael Saboff.
     7
     8        * bmalloc/Object.h:
     9        (bmalloc::Object::operator-): Added a - helper.
     10
     11        * bmalloc/VMAllocate.h:
     12        (bmalloc::vmRevokePermissions): Added a helper to revoke permissions on
     13        a VM region. We use this for guard pages.
     14
     15        * bmalloc/VMHeap.cpp:
     16        (bmalloc::VMHeap::allocateSmallChunk): Add guard pages to the start and
     17        end of the chunk.
     18
     19        Note that we don't guard large chunks becuase we need to be able to merge
     20        them. Otherwise, we will run out of virtual addresses.
     21
    1222016-04-22  Geoffrey Garen  <ggaren@apple.com>
    223
  • trunk/Source/bmalloc/bmalloc/Object.h

    r199746 r199936  
    5353   
    5454    Object operator+(size_t);
     55    Object operator-(size_t);
    5556    bool operator<=(const Object&);
    5657
     
    6566}
    6667
     68inline Object Object::operator-(size_t offset)
     69{
     70    return Object(m_chunk, m_offset - offset);
     71}
     72
    6773inline bool Object::operator<=(const Object& other)
    6874{
  • trunk/Source/bmalloc/bmalloc/VMAllocate.h

    r199759 r199936  
    138138}
    139139
     140inline void vmRevokePermissions(void* p, size_t vmSize)
     141{
     142    vmValidate(p, vmSize);
     143    mprotect(p, vmSize, PROT_NONE);
     144}
     145
    140146// Allocates vmSize bytes at a specified power-of-two alignment.
    141147// Use this function to create maskable memory regions.
  • trunk/Source/bmalloc/bmalloc/VMHeap.cpp

    r199759 r199936  
    7676    Object end(chunk, chunkSize);
    7777
     78    vmRevokePermissions(begin.begin(), pageSize);
     79    vmRevokePermissions(end.begin() - pageSize, pageSize);
     80
     81    begin = begin + pageSize;
     82    end = end - pageSize;
     83
    7884    for (Object it = begin; it + pageSize <= end; it = it + pageSize) {
    7985        SmallPage* page = it.page();
Note: See TracChangeset for help on using the changeset viewer.