Index: base/allocator/partition_allocator/address_space_randomization.cc |
diff --git a/third_party/WebKit/Source/wtf/allocator/AddressSpaceRandomization.cpp b/base/allocator/partition_allocator/address_space_randomization.cc |
similarity index 84% |
rename from third_party/WebKit/Source/wtf/allocator/AddressSpaceRandomization.cpp |
rename to base/allocator/partition_allocator/address_space_randomization.cc |
index 4fca2678ef82e6648d6ae80a33e9fb47dc2fb4dc..cd902a4837910dfbf937e7c4b4dad55e7702ca24 100644 |
--- a/third_party/WebKit/Source/wtf/allocator/AddressSpaceRandomization.cpp |
+++ b/base/allocator/partition_allocator/address_space_randomization.cc |
@@ -2,26 +2,27 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#include "wtf/allocator/AddressSpaceRandomization.h" |
+#include "base/allocator/partition_allocator/address_space_randomization.h" |
-#include "wtf/SpinLock.h" |
-#include "wtf/allocator/PageAllocator.h" |
+#include "base/allocator/partition_allocator/page_allocator.h" |
+#include "base/synchronization/spin_lock.h" |
+#include "build/build_config.h" |
-#if OS(WIN) |
+#if defined(OS_WIN) |
#include <windows.h> |
#else |
#include <sys/time.h> |
#include <unistd.h> |
#endif |
-namespace WTF { |
+namespace base { |
namespace { |
// This is the same PRNG as used by tcmalloc for mapping address randomness; |
// see http://burtleburtle.net/bob/rand/smallprng.html |
struct ranctx { |
- SpinLock lock; |
+ subtle::SpinLock lock; |
bool initialized; |
uint32_t a; |
uint32_t b; |
@@ -43,14 +44,14 @@ uint32_t ranvalInternal(ranctx* x) { |
#undef rot |
uint32_t ranval(ranctx* x) { |
- SpinLock::Guard guard(x->lock); |
+ subtle::SpinLock::Guard guard(x->lock); |
if (UNLIKELY(!x->initialized)) { |
x->initialized = true; |
char c; |
uint32_t seed = static_cast<uint32_t>(reinterpret_cast<uintptr_t>(&c)); |
uint32_t pid; |
uint32_t usec; |
-#if OS(WIN) |
+#if defined(OS_WIN) |
pid = GetCurrentProcessId(); |
SYSTEMTIME st; |
GetSystemTime(&st); |
@@ -83,12 +84,12 @@ static struct ranctx s_ranctx; |
void* getRandomPageBase() { |
uintptr_t random; |
random = static_cast<uintptr_t>(ranval(&s_ranctx)); |
-#if CPU(X86_64) |
+#if defined(ARCH_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) |
+#if defined(OS_WIN) |
// 64-bit Windows has a bizarrely small 8TB user address space. |
// Allocates in the 1-5TB region. |
// TODO(cevans): I think Win 8.1 has 47-bits like Linux. |
@@ -102,12 +103,12 @@ void* getRandomPageBase() { |
// Linux and OS X support the full 47-bit user space of x64 processors. |
random &= 0x3fffffffffffUL; |
#endif |
-#elif CPU(ARM64) |
+#elif defined(ARCH_CPU_ARM64) |
// ARM64 on Linux has 39-bit user space. |
random &= 0x3fffffffffUL; |
random += 0x1000000000UL; |
-#else // !CPU(X86_64) && !CPU(ARM64) |
-#if OS(WIN) |
+#else // !defined(ARCH_CPU_X86_64) && !defined(ARCH_CPU_ARM64) |
+#if defined(OS_WIN) |
// On win32 host systems the randomization plus huge alignment causes |
// excessive fragmentation. Plus most of these systems lack ASLR, so the |
// randomization isn't buying anything. In that case we just skip it. |
@@ -117,14 +118,14 @@ void* getRandomPageBase() { |
isWow64 = FALSE; |
if (!isWow64) |
return nullptr; |
-#endif // OS(WIN) |
+#endif // defined(OS_WIN) |
// 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) |
+#endif // defined(ARCH_CPU_X86_64) |
random &= kPageAllocationGranularityBaseMask; |
return reinterpret_cast<void*>(random); |
} |
-} // namespace WTF |
+} // namespace base |