OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #ifndef PageMemory_h | 5 #ifndef PageMemory_h |
6 #define PageMemory_h | 6 #define PageMemory_h |
7 | 7 |
8 #include "platform/heap/Heap.h" | |
8 #include "wtf/Assertions.h" | 9 #include "wtf/Assertions.h" |
9 #include "wtf/PageAllocator.h" | 10 #include "wtf/PageAllocator.h" |
10 | 11 |
11 #if OS(POSIX) | 12 #if OS(POSIX) |
12 #include <sys/mman.h> | 13 #include <sys/mman.h> |
13 #include <unistd.h> | 14 #include <unistd.h> |
14 #endif | 15 #endif |
15 | 16 |
16 namespace blink { | 17 namespace blink { |
17 | 18 |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
196 } | 197 } |
197 | 198 |
198 void markUnused() { m_reserved->markPageUnused(writableStart()); } | 199 void markUnused() { m_reserved->markPageUnused(writableStart()); } |
199 | 200 |
200 PageMemoryRegion* region() { return m_reserved; } | 201 PageMemoryRegion* region() { return m_reserved; } |
201 | 202 |
202 Address writableStart() { return m_writable.base(); } | 203 Address writableStart() { return m_writable.base(); } |
203 | 204 |
204 static PageMemory* setupPageMemoryInRegion(PageMemoryRegion* region, size_t pageOffset, size_t payloadSize) | 205 static PageMemory* setupPageMemoryInRegion(PageMemoryRegion* region, size_t pageOffset, size_t payloadSize) |
205 { | 206 { |
206 // Setup the payload one OS page into the page memory. The | 207 // Setup the payload one OS page into the page memory. The |
sof
2015/08/16 16:41:56
nit: could you adjust the comment a bit to reflect
| |
207 // first os page is the guard page. | 208 // first os page is the guard page. |
208 Address payloadAddress = region->base() + pageOffset + WTF::kSystemPageS ize; | 209 Address payloadAddress = region->base() + pageOffset + blinkGuardPageSiz e; |
209 return new PageMemory(region, MemoryRegion(payloadAddress, payloadSize)) ; | 210 return new PageMemory(region, MemoryRegion(payloadAddress, payloadSize)) ; |
210 } | 211 } |
211 | 212 |
212 // Allocate a virtual address space for one blink page with the | 213 // Allocate a virtual address space for one blink page with the |
213 // following layout: | 214 // following layout: |
214 // | 215 // |
215 // [ guard os page | ... payload ... | guard os page ] | 216 // [ guard os page | ... payload ... | guard os page ] |
216 // ^---{ aligned to blink page size } | 217 // ^---{ aligned to blink page size } |
217 // | 218 // |
218 // The returned page memory region will be zeroed. | 219 // The returned page memory region will be zeroed. |
219 // | 220 // |
220 static PageMemory* allocate(size_t payloadSize) | 221 static PageMemory* allocate(size_t payloadSize) |
221 { | 222 { |
222 ASSERT(payloadSize > 0); | 223 ASSERT(payloadSize > 0); |
223 | 224 |
224 // Virtual memory allocation routines operate in OS page sizes. | 225 // Virtual memory allocation routines operate in OS page sizes. |
225 // Round up the requested size to nearest os page size. | 226 // Round up the requested size to nearest os page size. |
226 payloadSize = roundToOsPageSize(payloadSize); | 227 payloadSize = roundToOsPageSize(payloadSize); |
227 | 228 |
228 // Overallocate by 2 times OS page size to have space for a | 229 // Overallocate by 2 times OS page size to have space for a |
229 // guard page at the beginning and end of blink heap page. | 230 // guard page at the beginning and end of blink heap page. |
230 size_t allocationSize = payloadSize + 2 * WTF::kSystemPageSize; | 231 size_t allocationSize = payloadSize + 2 * blinkGuardPageSize; |
231 PageMemoryRegion* pageMemoryRegion = PageMemoryRegion::allocateLargePage (allocationSize); | 232 PageMemoryRegion* pageMemoryRegion = PageMemoryRegion::allocateLargePage (allocationSize); |
232 PageMemory* storage = setupPageMemoryInRegion(pageMemoryRegion, 0, paylo adSize); | 233 PageMemory* storage = setupPageMemoryInRegion(pageMemoryRegion, 0, paylo adSize); |
233 RELEASE_ASSERT(storage->commit()); | 234 RELEASE_ASSERT(storage->commit()); |
234 return storage; | 235 return storage; |
235 } | 236 } |
236 | 237 |
237 private: | 238 private: |
238 PageMemory(PageMemoryRegion* reserved, const MemoryRegion& writable) | 239 PageMemory(PageMemoryRegion* reserved, const MemoryRegion& writable) |
239 : m_reserved(reserved) | 240 : m_reserved(reserved) |
240 , m_writable(writable) | 241 , m_writable(writable) |
241 { | 242 { |
242 ASSERT(reserved->contains(writable)); | 243 ASSERT(reserved->contains(writable)); |
243 | 244 |
244 // Register the writable area of the memory as part of the LSan root set . | 245 // Register the writable area of the memory as part of the LSan root set . |
245 // Only the writable area is mapped and can contain C++ objects. Those | 246 // Only the writable area is mapped and can contain C++ objects. Those |
246 // C++ objects can contain pointers to objects outside of the heap and | 247 // C++ objects can contain pointers to objects outside of the heap and |
247 // should therefore be part of the LSan root set. | 248 // should therefore be part of the LSan root set. |
248 __lsan_register_root_region(m_writable.base(), m_writable.size()); | 249 __lsan_register_root_region(m_writable.base(), m_writable.size()); |
249 } | 250 } |
250 | 251 |
251 | 252 |
252 PageMemoryRegion* m_reserved; | 253 PageMemoryRegion* m_reserved; |
253 MemoryRegion m_writable; | 254 MemoryRegion m_writable; |
254 }; | 255 }; |
255 | 256 |
256 } // namespace blink | 257 } // namespace blink |
257 | 258 |
258 #endif | 259 #endif |
OLD | NEW |