OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "config.h" | 5 #include "config.h" |
6 #include "wtf/AddressSpaceRandomization.h" | 6 #include "wtf/AddressSpaceRandomization.h" |
7 | 7 |
8 #include "wtf/PageAllocator.h" | 8 #include "wtf/PageAllocator.h" |
9 #include "wtf/SpinLock.h" | 9 #include "wtf/SpinLock.h" |
10 | 10 |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 random += 0x10000000000UL; | 101 random += 0x10000000000UL; |
102 #else | 102 #else |
103 // Linux and OS X support the full 47-bit user space of x64 processors. | 103 // Linux and OS X support the full 47-bit user space of x64 processors. |
104 random &= 0x3fffffffffffUL; | 104 random &= 0x3fffffffffffUL; |
105 #endif | 105 #endif |
106 #elif CPU(ARM64) | 106 #elif CPU(ARM64) |
107 // ARM64 on Linux has 39-bit user space. | 107 // ARM64 on Linux has 39-bit user space. |
108 random &= 0x3fffffffffUL; | 108 random &= 0x3fffffffffUL; |
109 random += 0x1000000000UL; | 109 random += 0x1000000000UL; |
110 #else // !CPU(X86_64) && !CPU(ARM64) | 110 #else // !CPU(X86_64) && !CPU(ARM64) |
| 111 #if OS(WIN) |
| 112 // On win32 host systems the randomization plus huge alignment causes |
| 113 // excessive fragmentation. Plus most of these systems lack ASLR, so the |
| 114 // randomization isn't buying anything. In that case we just skip it. |
| 115 // TODO(jschuh): Just dump the randomization when HE-ASLR is present. |
| 116 static BOOL isWow64 = -1; |
| 117 if (isWow64 == -1 && !IsWow64Process(GetCurrentProcess(), &isWow64)) |
| 118 isWow64 = FALSE; |
| 119 if (!isWow64) |
| 120 return nullptr; |
| 121 #endif // OS(WIN) |
111 // This is a good range on Windows, Linux and Mac. | 122 // This is a good range on Windows, Linux and Mac. |
112 // Allocates in the 0.5-1.5GB region. | 123 // Allocates in the 0.5-1.5GB region. |
113 random &= 0x3fffffff; | 124 random &= 0x3fffffff; |
114 random += 0x20000000; | 125 random += 0x20000000; |
115 #endif // CPU(X86_64) | 126 #endif // CPU(X86_64) |
116 random &= kPageAllocationGranularityBaseMask; | 127 random &= kPageAllocationGranularityBaseMask; |
117 return reinterpret_cast<void*>(random); | 128 return reinterpret_cast<void*>(random); |
118 } | 129 } |
119 | 130 |
120 } | 131 } |
OLD | NEW |