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 guard page into the page memory. |
207 // first os page is the guard page. | 208 Address payloadAddress = region->base() + pageOffset + blinkGuardPageSiz
e; |
208 Address payloadAddress = region->base() + pageOffset + WTF::kSystemPageS
ize; | |
209 return new PageMemory(region, MemoryRegion(payloadAddress, payloadSize))
; | 209 return new PageMemory(region, MemoryRegion(payloadAddress, payloadSize))
; |
210 } | 210 } |
211 | 211 |
212 // Allocate a virtual address space for one blink page with the | 212 // Allocate a virtual address space for one blink page with the |
213 // following layout: | 213 // following layout: |
214 // | 214 // |
215 // [ guard os page | ... payload ... | guard os page ] | 215 // [ guard os page | ... payload ... | guard os page ] |
216 // ^---{ aligned to blink page size } | 216 // ^---{ aligned to blink page size } |
217 // | 217 // |
218 // The returned page memory region will be zeroed. | 218 // The returned page memory region will be zeroed. |
219 // | 219 // |
220 static PageMemory* allocate(size_t payloadSize) | 220 static PageMemory* allocate(size_t payloadSize) |
221 { | 221 { |
222 ASSERT(payloadSize > 0); | 222 ASSERT(payloadSize > 0); |
223 | 223 |
224 // Virtual memory allocation routines operate in OS page sizes. | 224 // Virtual memory allocation routines operate in OS page sizes. |
225 // Round up the requested size to nearest os page size. | 225 // Round up the requested size to nearest os page size. |
226 payloadSize = roundToOsPageSize(payloadSize); | 226 payloadSize = roundToOsPageSize(payloadSize); |
227 | 227 |
228 // Overallocate by 2 times OS page size to have space for a | 228 // Overallocate by 2 times OS page size to have space for a |
229 // guard page at the beginning and end of blink heap page. | 229 // guard page at the beginning and end of blink heap page. |
230 size_t allocationSize = payloadSize + 2 * WTF::kSystemPageSize; | 230 size_t allocationSize = payloadSize + 2 * blinkGuardPageSize; |
231 PageMemoryRegion* pageMemoryRegion = PageMemoryRegion::allocateLargePage
(allocationSize); | 231 PageMemoryRegion* pageMemoryRegion = PageMemoryRegion::allocateLargePage
(allocationSize); |
232 PageMemory* storage = setupPageMemoryInRegion(pageMemoryRegion, 0, paylo
adSize); | 232 PageMemory* storage = setupPageMemoryInRegion(pageMemoryRegion, 0, paylo
adSize); |
233 RELEASE_ASSERT(storage->commit()); | 233 RELEASE_ASSERT(storage->commit()); |
234 return storage; | 234 return storage; |
235 } | 235 } |
236 | 236 |
237 private: | 237 private: |
238 PageMemory(PageMemoryRegion* reserved, const MemoryRegion& writable) | 238 PageMemory(PageMemoryRegion* reserved, const MemoryRegion& writable) |
239 : m_reserved(reserved) | 239 : m_reserved(reserved) |
240 , m_writable(writable) | 240 , m_writable(writable) |
241 { | 241 { |
242 ASSERT(reserved->contains(writable)); | 242 ASSERT(reserved->contains(writable)); |
243 | 243 |
244 // Register the writable area of the memory as part of the LSan root set
. | 244 // 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 | 245 // 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 | 246 // C++ objects can contain pointers to objects outside of the heap and |
247 // should therefore be part of the LSan root set. | 247 // should therefore be part of the LSan root set. |
248 __lsan_register_root_region(m_writable.base(), m_writable.size()); | 248 __lsan_register_root_region(m_writable.base(), m_writable.size()); |
249 } | 249 } |
250 | 250 |
251 | 251 |
252 PageMemoryRegion* m_reserved; | 252 PageMemoryRegion* m_reserved; |
253 MemoryRegion m_writable; | 253 MemoryRegion m_writable; |
254 }; | 254 }; |
255 | 255 |
256 } // namespace blink | 256 } // namespace blink |
257 | 257 |
258 #endif | 258 #endif |
OLD | NEW |