Index: Source/wtf/PageAllocator.cpp |
diff --git a/Source/wtf/PageAllocator.cpp b/Source/wtf/PageAllocator.cpp |
index a34408858d0986e5bb2226119c4bc4a88cdd2ccf..182a76ce2b99e1b5bf9e122ba1c2a134b9c9003d 100644 |
--- a/Source/wtf/PageAllocator.cpp |
+++ b/Source/wtf/PageAllocator.cpp |
@@ -31,9 +31,8 @@ |
#include "config.h" |
#include "wtf/PageAllocator.h" |
+#include "wtf/AddressSpaceRandomization.h" |
#include "wtf/Assertions.h" |
-#include "wtf/ProcessID.h" |
-#include "wtf/SpinLock.h" |
#include <limits.h> |
@@ -102,88 +101,6 @@ static bool trimMapping(void* baseAddr, size_t baseLen, void* trimAddr, size_t t |
#endif |
} |
-// This is the same PRNG as used by tcmalloc for mapping address randomness; |
-// see http://burtleburtle.net/bob/rand/smallprng.html |
-struct ranctx { |
- int lock; |
- bool initialized; |
- uint32_t a; |
- uint32_t b; |
- uint32_t c; |
- uint32_t d; |
-}; |
- |
-#define rot(x, k) (((x) << (k)) | ((x) >> (32 - (k)))) |
- |
-uint32_t ranvalInternal(ranctx* x) |
-{ |
- uint32_t e = x->a - rot(x->b, 27); |
- x->a = x->b ^ rot(x->c, 17); |
- x->b = x->c + x->d; |
- x->c = x->d + e; |
- x->d = e + x->a; |
- return x->d; |
-} |
- |
-#undef rot |
- |
-uint32_t ranval(ranctx* x) |
-{ |
- spinLockLock(&x->lock); |
- if (UNLIKELY(!x->initialized)) { |
- x->initialized = true; |
- char c; |
- uint32_t seed = static_cast<uint32_t>(reinterpret_cast<uintptr_t>(&c)); |
- seed ^= static_cast<uint32_t>(getCurrentProcessID()); |
- x->a = 0xf1ea5eed; |
- x->b = x->c = x->d = seed; |
- for (int i = 0; i < 20; ++i) { |
- (void) ranvalInternal(x); |
- } |
- } |
- uint32_t ret = ranvalInternal(x); |
- spinLockUnlock(&x->lock); |
- return ret; |
-} |
- |
-static struct ranctx s_ranctx; |
- |
-// This internal function calculates a random preferred mapping address. |
-// It is used when the client of allocPages() passes null as the address. |
-// In calculating an address, we balance good ASLR against not fragmenting the |
-// address space too badly. |
-static void* getRandomPageBase() |
-{ |
- uintptr_t random; |
- random = static_cast<uintptr_t>(ranval(&s_ranctx)); |
-#if CPU(X86_64) |
- random <<= 32UL; |
- random |= static_cast<uintptr_t>(ranval(&s_ranctx)); |
- // This address mask gives a low liklihood of address space collisions. |
- // We handle the situation gracefully if there is a collision. |
-#if OS(WIN) |
- // 64-bit Windows has a bizarrely small 8TB user address space. |
- // Allocates in the 1-5TB region. |
- random &= 0x3ffffffffffUL; |
- random += 0x10000000000UL; |
-#else |
- // Linux and OS X support the full 47-bit user space of x64 processors. |
- random &= 0x3fffffffffffUL; |
-#endif |
-#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; |
- random += 0x20000000; |
-#endif // CPU(X86_64) |
- random &= kPageAllocationGranularityBaseMask; |
- return reinterpret_cast<void*>(random); |
-} |
- |
void* allocPages(void* addr, size_t len, size_t align) |
{ |
ASSERT(len >= kPageAllocationGranularity); |