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 13 matching lines...) Expand all Loading... | |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #include "config.h" | 31 #include "config.h" |
32 #include "wtf/PageAllocator.h" | 32 #include "wtf/PageAllocator.h" |
33 | 33 |
34 #include "wtf/Assertions.h" | |
35 #include "wtf/CPU.h" | |
36 #include "wtf/CryptographicallyRandomNumber.h" | 34 #include "wtf/CryptographicallyRandomNumber.h" |
37 | 35 |
38 #if OS(POSIX) | 36 #if OS(POSIX) |
39 | 37 |
40 #include <sys/mman.h> | 38 #include <sys/mman.h> |
41 | 39 |
42 #ifndef MADV_FREE | 40 #ifndef MADV_FREE |
43 #define MADV_FREE MADV_DONTNEED | 41 #define MADV_FREE MADV_DONTNEED |
44 #endif | 42 #endif |
45 | 43 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
90 } | 88 } |
91 void* ret = ptr; | 89 void* ret = ptr; |
92 #else | 90 #else |
93 // Windows is a lot simpler because we've designed around its | 91 // Windows is a lot simpler because we've designed around its |
94 // coarser-grained alignement. | 92 // coarser-grained alignement. |
95 void* ret = VirtualAlloc(addr, len, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE ); | 93 void* ret = VirtualAlloc(addr, len, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE ); |
96 if (!ret) | 94 if (!ret) |
97 ret = VirtualAlloc(0, len, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); | 95 ret = VirtualAlloc(0, len, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); |
98 RELEASE_ASSERT(ret); | 96 RELEASE_ASSERT(ret); |
99 #endif // OS(POSIX) | 97 #endif // OS(POSIX) |
98 | |
99 #if CPU(32BIT) | |
100 SuperPageBitmap::registerSuperPage(ret); | |
Tom Sepez
2013/10/02 22:56:53
I think you can get rid of these ifdefs as well by
| |
101 #endif | |
100 return ret; | 102 return ret; |
101 } | 103 } |
102 | 104 |
103 void freeSuperPages(void* addr, size_t len) | 105 void freeSuperPages(void* addr, size_t len) |
104 { | 106 { |
105 ASSERT(!(reinterpret_cast<uintptr_t>(addr) & kSuperPageOffsetMask)); | 107 ASSERT(!(reinterpret_cast<uintptr_t>(addr) & kSuperPageOffsetMask)); |
106 ASSERT(!(len & kSuperPageOffsetMask)); | 108 ASSERT(!(len & kSuperPageOffsetMask)); |
107 #if OS(POSIX) | 109 #if OS(POSIX) |
108 int ret = munmap(addr, len); | 110 int ret = munmap(addr, len); |
109 ASSERT(!ret); | 111 ASSERT(!ret); |
110 #else | 112 #else |
111 BOOL ret = VirtualFree(addr, 0, MEM_RELEASE); | 113 BOOL ret = VirtualFree(addr, 0, MEM_RELEASE); |
112 ASSERT(ret); | 114 ASSERT(ret); |
113 #endif | 115 #endif |
116 | |
117 #if CPU(32BIT) | |
118 SuperPageBitmap::unregisterSuperPage(addr); | |
119 #endif | |
114 } | 120 } |
115 | 121 |
116 void setSystemPagesInaccessible(void* addr, size_t len) | 122 void setSystemPagesInaccessible(void* addr, size_t len) |
117 { | 123 { |
118 ASSERT(!(len & kSystemPageOffsetMask)); | 124 ASSERT(!(len & kSystemPageOffsetMask)); |
119 #if OS(POSIX) | 125 #if OS(POSIX) |
120 int ret = mprotect(addr, len, PROT_NONE); | 126 int ret = mprotect(addr, len, PROT_NONE); |
121 ASSERT(!ret); | 127 ASSERT(!ret); |
122 #else | 128 #else |
123 BOOL ret = VirtualFree(addr, len, MEM_DECOMMIT); | 129 BOOL ret = VirtualFree(addr, len, MEM_DECOMMIT); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
156 #endif | 162 #endif |
157 #else // !CPU(X86_64) | 163 #else // !CPU(X86_64) |
158 // This is a good range on Windows, Linux and Mac. | 164 // This is a good range on Windows, Linux and Mac. |
159 // Allocates in the 0.5-1.5GB region. | 165 // Allocates in the 0.5-1.5GB region. |
160 random &= (0x3fffffff & kSuperPageBaseMask); | 166 random &= (0x3fffffff & kSuperPageBaseMask); |
161 random += 0x20000000; | 167 random += 0x20000000; |
162 #endif // CPU(X86_64) | 168 #endif // CPU(X86_64) |
163 return reinterpret_cast<char*>(random); | 169 return reinterpret_cast<char*>(random); |
164 } | 170 } |
165 | 171 |
172 #if CPU(32BIT) | |
173 unsigned char SuperPageBitmap::s_bitmap[1 << (32 - kSuperPageShift - 3)]; | |
174 | |
175 void SuperPageBitmap::registerSuperPage(void* ptr) | |
176 { | |
177 ASSERT(!isPointerInSuperPage(ptr)); | |
178 uintptr_t raw = reinterpret_cast<uintptr_t>(ptr); | |
179 raw >>= kSuperPageShift; | |
180 size_t idx = raw >> 3; | |
181 size_t bit = raw & 7; | |
182 ASSERT(idx < sizeof(s_bitmap)); | |
183 s_bitmap[idx] |= (1 << bit); | |
184 } | |
185 | |
186 void SuperPageBitmap::unregisterSuperPage(void* ptr) | |
187 { | |
188 ASSERT(isPointerInSuperPage(ptr)); | |
189 uintptr_t raw = reinterpret_cast<uintptr_t>(ptr); | |
190 raw >>= kSuperPageShift; | |
191 size_t idx = raw >> 3; | |
192 size_t bit = raw & 7; | |
193 ASSERT(idx < sizeof(s_bitmap)); | |
194 s_bitmap[idx] &= ~(1 << bit); | |
195 } | |
196 #endif | |
197 | |
166 } // namespace WTF | 198 } // namespace WTF |
167 | 199 |
OLD | NEW |