summaryrefslogtreecommitdiffstats
path: root/JavaScriptCore/wtf/PageAllocation.cpp
diff options
context:
space:
mode:
authorBen Murdoch <benm@google.com>2010-08-11 14:44:44 +0100
committerBen Murdoch <benm@google.com>2010-08-12 19:15:41 +0100
commitdd8bb3de4f353a81954234999f1fea748aee2ea9 (patch)
tree729b52bf09294f0d6c67cd5ea80aee1b727b7bd8 /JavaScriptCore/wtf/PageAllocation.cpp
parentf3d41ba51d86bf719c7a65ab5297aea3c17e2d98 (diff)
downloadexternal_webkit-dd8bb3de4f353a81954234999f1fea748aee2ea9.zip
external_webkit-dd8bb3de4f353a81954234999f1fea748aee2ea9.tar.gz
external_webkit-dd8bb3de4f353a81954234999f1fea748aee2ea9.tar.bz2
Merge WebKit at r65072 : Initial merge by git.
Change-Id: Ibcf418498376b2660aacb7f8d46ea7085ef91585
Diffstat (limited to 'JavaScriptCore/wtf/PageAllocation.cpp')
-rw-r--r--JavaScriptCore/wtf/PageAllocation.cpp197
1 files changed, 7 insertions, 190 deletions
diff --git a/JavaScriptCore/wtf/PageAllocation.cpp b/JavaScriptCore/wtf/PageAllocation.cpp
index 4cf2ea9..f3fe997 100644
--- a/JavaScriptCore/wtf/PageAllocation.cpp
+++ b/JavaScriptCore/wtf/PageAllocation.cpp
@@ -26,206 +26,23 @@
#include "config.h"
#include "PageAllocation.h"
-
-#if HAVE(ERRNO_H)
-#include <errno.h>
-#endif
-
-#if HAVE(MMAP)
-#include <sys/mman.h>
-#include <unistd.h>
-#endif
-
-#if OS(WINDOWS)
-#include "windows.h"
-#endif
-
-#if OS(SYMBIAN)
-#include <e32hal.h>
-#endif
+#include "PageReservation.h"
namespace WTF {
-#if HAVE(MMAP)
+size_t PageAllocation::s_pageSize = 0;
-bool PageAllocation::commit(void* start, size_t size, bool, bool) const
-{
-#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;
-}
+#ifndef NDEBUG
-void PageAllocation::decommit(void* start, size_t size) const
+int PageAllocation::lastError()
{
-#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) { }
+#if OS(WINCE)
+ return GetLastError();
#else
- UNUSED_PARAM(start);
- UNUSED_PARAM(size);
+ return errno;
#endif
}
-PageAllocation PageAllocation::allocate(size_t size, Usage usage, bool writable, bool executable)
-{
- return allocateAt(0, false, size, usage, writable, executable);
-}
-
-PageAllocation PageAllocation::reserve(size_t size, Usage usage, bool writable, bool executable)
-{
- return reserveAt(0, false, size, usage, writable, executable);
-}
-
-PageAllocation PageAllocation::allocateAt(void* address, bool fixed, size_t size, Usage usage, bool writable, bool executable)
-{
- int flags = MAP_PRIVATE | MAP_ANON;
- if (fixed)
- flags |= MAP_FIXED;
-
- int protection = PROT_READ;
- if (writable)
- protection |= PROT_WRITE;
- if (executable)
- protection |= PROT_EXEC;
-
- void* base = mmap(address, size, protection, flags, usage, 0);
- if (base == MAP_FAILED)
- base = 0;
-
- return PageAllocation(base, size);
-}
-
-PageAllocation PageAllocation::reserveAt(void* address, bool fixed, size_t size, Usage usage, bool writable, bool executable)
-{
- PageAllocation result = allocateAt(address, fixed, size, usage, writable, executable);
- if (!!result)
- result.decommit(result.base(), size);
- return result;
-}
-
-void PageAllocation::deallocate()
-{
- int result = munmap(m_base, m_size);
- ASSERT_UNUSED(result, !result);
- m_base = 0;
-}
-
-size_t PageAllocation::pagesize()
-{
- static size_t size = 0;
- if (!size)
- size = getpagesize();
- return size;
-}
-
-#elif HAVE(VIRTUALALLOC)
-
-static DWORD protection(bool writable, bool executable)
-{
- if (executable)
- return writable ?PAGE_EXECUTE_READWRITE : PAGE_EXECUTE_READ;
- return writable ?PAGE_READWRITE : PAGE_READONLY;
-}
-
-bool PageAllocation::commit(void* start, size_t size, bool writable, bool executable) const
-{
- return VirtualAlloc(start, size, MEM_COMMIT, protection(writable, executable)) == start;
-}
-
-void PageAllocation::decommit(void* start, size_t size) const
-{
- VirtualFree(start, size, MEM_DECOMMIT);
-}
-
-PageAllocation PageAllocation::allocate(size_t size, Usage, bool writable, bool executable)
-{
- return PageAllocation(VirtualAlloc(0, size, MEM_COMMIT | MEM_RESERVE, protection(writable, executable)), size);
-}
-
-PageAllocation PageAllocation::reserve(size_t size, Usage usage, bool writable, bool executable)
-{
- return PageAllocation(VirtualAlloc(0, size, MEM_RESERVE, protection(writable, executable)), size);
-}
-
-void PageAllocation::deallocate()
-{
- VirtualFree(m_base, 0, MEM_RELEASE);
- m_base = 0;
-}
-
-size_t PageAllocation::pagesize()
-{
- static size_t size = 0;
- if (!size) {
- SYSTEM_INFO system_info;
- GetSystemInfo(&system_info);
- size = system_info.dwPageSize;
- }
- return size;
-}
-
-#elif OS(SYMBIAN)
-
-bool PageAllocation::commit(void* start, size_t size, bool writable, bool executable) const
-{
- if (m_chunk) {
- intptr_t offset = reinterpret_cast<intptr_t>(base()) - reinterpret_cast<intptr_t>(start);
- m_chunk->Commit(offset, size);
- }
- return true;
-}
-
-void PageAllocation::decommit(void* start, size_t size) const
-{
- if (m_chunk) {
- intptr_t offset = reinterpret_cast<intptr_t>(base()) - reinterpret_cast<intptr_t>(start);
- m_chunk->Decommit(offset, size);
- }
-}
-
-PageAllocation PageAllocation::allocate(size_t size, Usage usage, bool writable, bool executable)
-{
- if (!executable)
- return PageAllocation(fastMalloc(size), size, 0);
- RChunk* rchunk = new RChunk();
- TInt errorCode = rchunk->CreateLocalCode(size, size);
- return PageAllocation(rchunk->Base(), size, rchunk);
-}
-
-PageAllocation PageAllocation::reserve(size_t size, Usage usage, bool writable, bool executable)
-{
- if (!executable)
- return PageAllocation(fastMalloc(size), size, 0);
- RChunk* rchunk = new RChunk();
- TInt errorCode = rchunk->CreateLocalCode(0, size);
- return PageAllocation(rchunk->Base(), size, rchunk);
-}
-
-void PageAllocation::deallocate()
-{
- if (m_chunk) {
- m_chunk->Close();
- delete m_chunk;
- } else
- fastFree(m_base);
- m_base = 0;
-}
-
-size_t PageAllocation::pagesize()
-{
- static TInt page_size = 0;
- if (!page_size)
- UserHal::PageSizeInBytes(page_size);
- return page_size;
-}
-
#endif
}