OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 29 matching lines...) Expand all Loading... |
40 #include <sys/mman.h> | 40 #include <sys/mman.h> |
41 | 41 |
42 #ifndef MADV_FREE | 42 #ifndef MADV_FREE |
43 #define MADV_FREE MADV_DONTNEED | 43 #define MADV_FREE MADV_DONTNEED |
44 #endif | 44 #endif |
45 | 45 |
46 #ifndef MAP_ANONYMOUS | 46 #ifndef MAP_ANONYMOUS |
47 #define MAP_ANONYMOUS MAP_ANON | 47 #define MAP_ANONYMOUS MAP_ANON |
48 #endif | 48 #endif |
49 | 49 |
50 #elif OS(WINDOWS) | 50 #elif OS(WIN) |
51 | 51 |
52 #include <windows.h> | 52 #include <windows.h> |
53 | 53 |
54 #else | 54 #else |
55 #error Unknown OS | 55 #error Unknown OS |
56 #endif // OS(UNIX) | 56 #endif // OS(UNIX) |
57 | 57 |
58 namespace WTF { | 58 namespace WTF { |
59 | 59 |
60 void* allocSuperPages(void* addr, size_t len) | 60 void* allocSuperPages(void* addr, size_t len) |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 | 139 |
140 char* getRandomSuperPageBase() | 140 char* getRandomSuperPageBase() |
141 { | 141 { |
142 uintptr_t random; | 142 uintptr_t random; |
143 random = static_cast<uintptr_t>(cryptographicallyRandomNumber()); | 143 random = static_cast<uintptr_t>(cryptographicallyRandomNumber()); |
144 #if CPU(X86_64) | 144 #if CPU(X86_64) |
145 random <<= 32UL; | 145 random <<= 32UL; |
146 random |= static_cast<uintptr_t>(cryptographicallyRandomNumber()); | 146 random |= static_cast<uintptr_t>(cryptographicallyRandomNumber()); |
147 // This address mask gives a low liklihood of address space collisions. | 147 // This address mask gives a low liklihood of address space collisions. |
148 // We handle the situation gracefully if there is a collision. | 148 // We handle the situation gracefully if there is a collision. |
149 #if OS(WINDOWS) | 149 #if OS(WIN) |
150 // 64-bit Windows has a bizarrely small 8TB user address space. | 150 // 64-bit Windows has a bizarrely small 8TB user address space. |
151 // Allocates in the 1-5TB region. | 151 // Allocates in the 1-5TB region. |
152 random &= (0x3ffffffffffUL & kSuperPageBaseMask); | 152 random &= (0x3ffffffffffUL & kSuperPageBaseMask); |
153 random += 0x10000000000UL; | 153 random += 0x10000000000UL; |
154 #else | 154 #else |
155 random &= (0x3fffffffffffUL & kSuperPageBaseMask); | 155 random &= (0x3fffffffffffUL & kSuperPageBaseMask); |
156 #endif | 156 #endif |
157 #else // !CPU(X86_64) | 157 #else // !CPU(X86_64) |
158 // This is a good range on Windows, Linux and Mac. | 158 // This is a good range on Windows, Linux and Mac. |
159 // Allocates in the 0.5-1.5GB region. | 159 // Allocates in the 0.5-1.5GB region. |
160 random &= (0x3fffffff & kSuperPageBaseMask); | 160 random &= (0x3fffffff & kSuperPageBaseMask); |
161 random += 0x20000000; | 161 random += 0x20000000; |
162 #endif // CPU(X86_64) | 162 #endif // CPU(X86_64) |
163 return reinterpret_cast<char*>(random); | 163 return reinterpret_cast<char*>(random); |
164 } | 164 } |
165 | 165 |
166 } // namespace WTF | 166 } // namespace WTF |
167 | 167 |
OLD | NEW |