+2016-04-25 Geoffrey Garen <ggaren@apple.com>
+
+ bmalloc: vm allocations should plant guard pages
+ https://bugs.webkit.org/show_bug.cgi?id=156937
+
+ Rolling back in r199936 with a fix for the memory regression.
+
2016-04-23 Gavin Barraclough <barraclough@apple.com>
bmalloc: vm allocations should plant guard pages
SmallPage* page();
Object operator+(size_t);
+ Object operator-(size_t);
bool operator<=(const Object&);
private:
return Object(m_chunk, m_offset + offset);
}
+inline Object Object::operator-(size_t offset)
+{
+ return Object(m_chunk, m_offset - offset);
+}
+
inline bool Object::operator<=(const Object& other)
{
BASSERT(m_chunk == other.m_chunk);
namespace bmalloc {
-XLargeRange VMHeap::tryAllocateLargeChunk(std::lock_guard<StaticMutex>& lock, size_t alignment, size_t size)
+XLargeRange VMHeap::tryAllocateLargeChunk(std::lock_guard<StaticMutex>&, size_t alignment, size_t size)
{
// We allocate VM in aligned multiples to increase the chances that
// the OS will provide contiguous ranges that we can merge.
if (!memory)
return XLargeRange();
- Chunk* chunk = new (memory) Chunk(lock);
+ Chunk* chunk = static_cast<Chunk*>(memory);
#if BOS(DARWIN)
m_zone.addChunk(chunk);
void VMHeap::allocateSmallChunk(std::lock_guard<StaticMutex>& lock, size_t pageClass)
{
- Chunk* chunk =
- new (vmAllocate(chunkSize, chunkSize)) Chunk(lock);
-
-#if BOS(DARWIN)
- m_zone.addChunk(chunk);
-#endif
-
size_t pageSize = bmalloc::pageSize(pageClass);
size_t smallPageCount = pageSize / smallPageSize;
// aligned allocation requests at equal and smaller powers of two.
size_t metadataSize = divideRoundingUp(sizeof(Chunk), pageSize) * pageSize;
+ void* memory = vmAllocate(chunkSize, chunkSize);
+ Chunk* chunk = static_cast<Chunk*>(memory);
+
Object begin(chunk, metadataSize);
Object end(chunk, chunkSize);
+ // Establish guard pages before writing to Chunk memory to work around
+ // an edge case in the Darwin VM system (<rdar://problem/25910098>).
+ vmRevokePermissions(begin.begin(), pageSize);
+ vmRevokePermissions(end.begin() - pageSize, pageSize);
+
+ begin = begin + pageSize;
+ end = end - pageSize;
+
+ new (chunk) Chunk(lock);
+
+#if BOS(DARWIN)
+ m_zone.addChunk(chunk);
+#endif
+
for (Object it = begin; it + pageSize <= end; it = it + pageSize) {
SmallPage* page = it.page();
- new (page) SmallPage;
for (size_t i = 0; i < smallPageCount; ++i)
page[i].setSlide(i);