diff options
Diffstat (limited to 'chromium/third_party/WebKit/Source/wtf/PageAllocator.cpp')
-rw-r--r-- | chromium/third_party/WebKit/Source/wtf/PageAllocator.cpp | 43 |
1 files changed, 35 insertions, 8 deletions
diff --git a/chromium/third_party/WebKit/Source/wtf/PageAllocator.cpp b/chromium/third_party/WebKit/Source/wtf/PageAllocator.cpp index 00e65f044d8..a34408858d0 100644 --- a/chromium/third_party/WebKit/Source/wtf/PageAllocator.cpp +++ b/chromium/third_party/WebKit/Source/wtf/PageAllocator.cpp @@ -73,9 +73,9 @@ static void* systemAllocPages(void* addr, size_t len) ret = VirtualAlloc(0, len, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); #else ret = mmap(addr, len, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); - RELEASE_ASSERT(ret != MAP_FAILED); + if (ret == MAP_FAILED) + ret = 0; #endif - RELEASE_ASSERT(ret); return ret; } @@ -170,7 +170,11 @@ static void* getRandomPageBase() // Linux and OS X support the full 47-bit user space of x64 processors. random &= 0x3fffffffffffUL; #endif -#else // !CPU(X86_64) +#elif CPU(ARM64) + // ARM64 on Linux has 39-bit user space. + random &= 0x3fffffffffUL; + random += 0x1000000000UL; +#else // !CPU(X86_64) && !CPU(ARM64) // This is a good range on Windows, Linux and Mac. // Allocates in the 0.5-1.5GB region. random &= 0x3fffffff; @@ -182,7 +186,6 @@ static void* getRandomPageBase() void* allocPages(void* addr, size_t len, size_t align) { - RELEASE_ASSERT(len < INT_MAX - align); ASSERT(len >= kPageAllocationGranularity); ASSERT(!(len & kPageAllocationGranularityOffsetMask)); ASSERT(align >= kPageAllocationGranularity); @@ -201,7 +204,7 @@ void* allocPages(void* addr, size_t len, size_t align) // address and length are suitable. Just try it. void* ret = systemAllocPages(addr, len); // If the alignment is to our liking, we're done. - if (!(reinterpret_cast<uintptr_t>(ret) & alignOffsetMask)) + if (!ret || !(reinterpret_cast<uintptr_t>(ret) & alignOffsetMask)) return ret; // Annoying. Unmap and map a larger range to be sure to succeed on the @@ -209,12 +212,15 @@ void* allocPages(void* addr, size_t len, size_t align) freePages(ret, len); size_t tryLen = len + (align - kPageAllocationGranularity); + RELEASE_ASSERT(tryLen > len); // We loop to cater for the unlikely case where another thread maps on top // of the aligned location we choose. int count = 0; while (count++ < 100) { ret = systemAllocPages(addr, tryLen); + if (!ret) + return 0; // We can now try and trim out a subset of the mapping. addr = reinterpret_cast<void*>((reinterpret_cast<uintptr_t>(ret) + alignOffsetMask) & alignBaseMask); @@ -228,7 +234,7 @@ void* allocPages(void* addr, size_t len, size_t align) // broken mmap() that ignores address hints for valid, unused addresses. freePages(ret, tryLen); ret = systemAllocPages(addr, len); - if (ret == addr) + if (ret == addr || !ret) return ret; // Unlikely race / collision. Do the simple thing and just start again. @@ -265,6 +271,18 @@ void setSystemPagesInaccessible(void* addr, size_t len) #endif } +void setSystemPagesAccessible(void* addr, size_t len) +{ + ASSERT(!(len & kSystemPageOffsetMask)); +#if OS(POSIX) + int ret = mprotect(addr, len, PROT_READ | PROT_WRITE); + RELEASE_ASSERT(!ret); +#else + void* ret = VirtualAlloc(addr, len, MEM_COMMIT, PAGE_READWRITE); + RELEASE_ASSERT(ret); +#endif +} + void decommitSystemPages(void* addr, size_t len) { ASSERT(!(len & kSystemPageOffsetMask)); @@ -272,8 +290,17 @@ void decommitSystemPages(void* addr, size_t len) int ret = madvise(addr, len, MADV_FREE); RELEASE_ASSERT(!ret); #else - void* ret = VirtualAlloc(addr, len, MEM_RESET, PAGE_READWRITE); - RELEASE_ASSERT(ret); + setSystemPagesInaccessible(addr, len); +#endif +} + +void recommitSystemPages(void* addr, size_t len) +{ + ASSERT(!(len & kSystemPageOffsetMask)); +#if OS(POSIX) + (void) addr; +#else + setSystemPagesAccessible(addr, len); #endif } |