+2012-03-19 Yong Li <yoli@rim.com>
+
+ [BlackBerry] Implement OSAllocator::commit/decommit in the correct way
+ https://bugs.webkit.org/show_bug.cgi?id=77013
+
+ We should use mmap(PROT_NONE, MAP_LAZY) instead of posix_madvise() to
+ implement memory decommitting for QNX.
+
+ Reviewed by Rob Buis.
+
+ * wtf/OSAllocatorPosix.cpp:
+ (WTF::OSAllocator::reserveUncommitted):
+ (WTF::OSAllocator::commit):
+ (WTF::OSAllocator::decommit):
+
2012-03-19 Gavin Barraclough <barraclough@apple.com>
Unreviewed - revent a couple of files accidentally committed.
void* OSAllocator::reserveUncommitted(size_t bytes, Usage usage, bool writable, bool executable, bool includesGuardPages)
{
- void* result = reserveAndCommit(bytes, usage, writable, executable, includesGuardPages);
#if OS(QNX)
- posix_madvise(result, bytes, POSIX_MADV_DONTNEED);
-#elif OS(LINUX)
+ // Reserve memory with PROT_NONE and MAP_LAZY so it isn't committed now.
+ void* result = mmap(0, bytes, PROT_NONE, MAP_LAZY | MAP_PRIVATE | MAP_ANON, -1, 0);
+ if (result == MAP_FAILED)
+ CRASH();
+#else // OS(QNX)
+
+ void* result = reserveAndCommit(bytes, usage, writable, executable, includesGuardPages);
+#if OS(LINUX)
madvise(result, bytes, MADV_DONTNEED);
#elif 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) { }
#endif
+
+#endif // OS(QNX)
+
return result;
}
return result;
}
-void OSAllocator::commit(void* address, size_t bytes, bool, bool)
+void OSAllocator::commit(void* address, size_t bytes, bool writable, bool executable)
{
#if OS(QNX)
- posix_madvise(address, bytes, POSIX_MADV_WILLNEED);
+ int protection = PROT_READ;
+ if (writable)
+ protection |= PROT_WRITE;
+ if (executable)
+ protection |= PROT_EXEC;
+ if (MAP_FAILED == mmap(address, bytes, protection, MAP_FIXED | MAP_PRIVATE | MAP_ANON, -1, 0))
+ CRASH();
#elif OS(LINUX)
+ UNUSED_PARAM(writable);
+ UNUSED_PARAM(executable);
madvise(address, bytes, MADV_WILLNEED);
#elif HAVE(MADV_FREE_REUSE)
+ UNUSED_PARAM(writable);
+ UNUSED_PARAM(executable);
while (madvise(address, bytes, MADV_FREE_REUSE) == -1 && errno == EAGAIN) { }
#else
// Non-MADV_FREE_REUSE reservations automatically commit on demand.
UNUSED_PARAM(address);
UNUSED_PARAM(bytes);
+ UNUSED_PARAM(writable);
+ UNUSED_PARAM(executable);
#endif
}
void OSAllocator::decommit(void* address, size_t bytes)
{
#if OS(QNX)
- posix_madvise(address, bytes, POSIX_MADV_DONTNEED);
+ // Use PROT_NONE and MAP_LAZY to decommit the pages.
+ mmap(address, bytes, PROT_NONE, MAP_FIXED | MAP_LAZY | MAP_PRIVATE | MAP_ANON, -1, 0);
#elif OS(LINUX)
madvise(address, bytes, MADV_DONTNEED);
#elif HAVE(MADV_FREE_REUSE)