Bug 1232907 - Enable ExecutableAllocator randomization on Windows XP. r=jandem
authorChris Peterson <cpeterson@mozilla.com>
Mon, 07 Dec 2015 22:56:52 -0500
changeset 276677 d1de47ef53a2eb93a8e0f9e9800fbf0a1bc04b04
parent 276676 1adf7961d21753a0033328d79a813d6d70f9da73
child 276678 6db8fd96938ee038670b434dbd41ce00ead78b0c
push id69269
push usercpeterson@mozilla.com
push dateThu, 17 Dec 2015 08:03:07 +0000
treeherdermozilla-inbound@d1de47ef53a2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjandem
bugs1232907
milestone46.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1232907 - Enable ExecutableAllocator randomization on Windows XP. r=jandem
js/src/jit/ExecutableAllocatorWin.cpp
--- a/js/src/jit/ExecutableAllocatorWin.cpp
+++ b/js/src/jit/ExecutableAllocatorWin.cpp
@@ -72,32 +72,16 @@ ExecutableAllocator::computeRandomAlloca
         js::GenerateXorShift128PlusSeed(seed);
         randomNumberGenerator.emplace(seed[0], seed[1]);
     }
 
     uint64_t rand = randomNumberGenerator.ref().next();
     return (void*) (base | (rand & mask));
 }
 
-static bool
-RandomizeIsBrokenImpl()
-{
-    // We disable everything before Vista, for now.
-    return !mozilla::IsVistaOrLater();
-}
-
-static bool
-RandomizeIsBroken()
-{
-    // Use the compiler's intrinsic guards for |static type value = expr| to avoid some potential
-    // races if runtimes are created from multiple threads.
-    static int result = RandomizeIsBrokenImpl();
-    return !!result;
-}
-
 #ifdef JS_CPU_X64
 static js::JitExceptionHandler sJitExceptionHandler;
 
 JS_FRIEND_API(void)
 js::SetJitExceptionHandler(JitExceptionHandler handler)
 {
     MOZ_ASSERT(!sJitExceptionHandler);
     sJitExceptionHandler = handler;
@@ -231,25 +215,21 @@ js::jit::DeallocateExecutableMemory(void
 #endif
 
     VirtualFree(addr, 0, MEM_RELEASE);
 }
 
 ExecutablePool::Allocation
 ExecutableAllocator::systemAlloc(size_t n)
 {
-    void* allocation = nullptr;
-    if (!RandomizeIsBroken()) {
-        void* randomAddress = computeRandomAllocationAddress();
-        allocation = AllocateExecutableMemory(randomAddress, n, initialProtectionFlags(Executable),
-                                              "js-jit-code", pageSize);
-    }
+    void* randomAddress = computeRandomAllocationAddress();
+    unsigned flags = initialProtectionFlags(Executable);
+    void* allocation = AllocateExecutableMemory(randomAddress, n, flags, "js-jit-code", pageSize);
     if (!allocation) {
-        allocation = AllocateExecutableMemory(nullptr, n, initialProtectionFlags(Executable),
-                                              "js-jit-code", pageSize);
+        allocation = AllocateExecutableMemory(nullptr, n, flags, "js-jit-code", pageSize);
     }
     ExecutablePool::Allocation alloc = { reinterpret_cast<char*>(allocation), n };
     return alloc;
 }
 
 void
 ExecutableAllocator::systemRelease(const ExecutablePool::Allocation& alloc)
 {