Chromium Code Reviews| 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 #ifndef WTF_PageAllocator_h | 31 #ifndef WTF_PageAllocator_h |
| 32 #define WTF_PageAllocator_h | 32 #define WTF_PageAllocator_h |
| 33 | 33 |
| 34 #include "wtf/CPU.h" | |
| 35 #include <stdint.h> | |
| 36 | |
| 34 namespace WTF { | 37 namespace WTF { |
| 35 | 38 |
| 36 // Our granulatity of page allocation is 64KB. This is a Windows limitation, | 39 // Our granulatity of page allocation is 64KB. This is a Windows limitation, |
| 37 // but we apply the same requirement for all platforms in order to keep | 40 // but we apply the same requirement for all platforms in order to keep |
| 38 // things simple and consistent. | 41 // things simple and consistent. |
| 39 // We term these 64KB allocations "super pages". They're just a clump of | 42 // We term these 64KB allocations "super pages". They're just a clump of |
| 40 // underlying 4KB system pages. | 43 // underlying 4KB system pages. |
| 41 static const size_t kSuperPageSize = 1 << 16; // 64KB | 44 static const size_t kSuperPageShift = 16; // 64KB |
| 45 static const size_t kSuperPageSize = 1 << kSuperPageShift; | |
| 42 static const size_t kSuperPageOffsetMask = kSuperPageSize - 1; | 46 static const size_t kSuperPageOffsetMask = kSuperPageSize - 1; |
| 43 static const size_t kSuperPageBaseMask = ~kSuperPageOffsetMask; | 47 static const size_t kSuperPageBaseMask = ~kSuperPageOffsetMask; |
| 44 | 48 |
| 45 // All Blink-supported systems have 4096 sized system pages and can handle | 49 // All Blink-supported systems have 4096 sized system pages and can handle |
| 46 // permissions and commit / decommit at this granularity. | 50 // permissions and commit / decommit at this granularity. |
| 47 static const size_t kSystemPageSize = 4096; | 51 static const size_t kSystemPageSize = 4096; |
| 48 static const size_t kSystemPageOffsetMask = kSystemPageSize - 1; | 52 static const size_t kSystemPageOffsetMask = kSystemPageSize - 1; |
| 49 | 53 |
| 50 static const size_t kNumSystemPagesPerSuperPage = kSuperPageSize / kSystemPageSi ze; | 54 static const size_t kNumSystemPagesPerSuperPage = kSuperPageSize / kSystemPageSi ze; |
| 51 | 55 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 65 // Subsequently accessing any address in the range will fault, the addresses | 69 // Subsequently accessing any address in the range will fault, the addresses |
| 66 // will not be re-used by future allocations. | 70 // will not be re-used by future allocations. |
| 67 // len must be a multiple of kSystemPageSize bytes. | 71 // len must be a multiple of kSystemPageSize bytes. |
| 68 void setSystemPagesInaccessible(void* addr, size_t len); | 72 void setSystemPagesInaccessible(void* addr, size_t len); |
| 69 | 73 |
| 70 // Decommit one or more system pages. Decommitted means that the physical memory | 74 // Decommit one or more system pages. Decommitted means that the physical memory |
| 71 // is released to the system, but the virtual address space remains reserved. | 75 // is released to the system, but the virtual address space remains reserved. |
| 72 // System pages are re-committed by writing to them. | 76 // System pages are re-committed by writing to them. |
| 73 // Clients should not make any assumptions about the contents of decommitted | 77 // Clients should not make any assumptions about the contents of decommitted |
| 74 // system pages, before or after they write to the page. The only guarantee | 78 // system pages, before or after they write to the page. The only guarantee |
| 75 // provided is that the contents of the system page will be deterministic again // after writing to it. In particlar note that system pages are not guaranteed | 79 // provided is that the contents of the system page will be deterministic again |
| 80 // after writing to it. In particlar note that system pages are not guaranteed | |
| 76 // to be zero-filled upon re-commit. | 81 // to be zero-filled upon re-commit. |
| 77 // len must be a multiple of kSystemPageSize bytes. | 82 // len must be a multiple of kSystemPageSize bytes. |
| 78 void decommitSystemPages(void* addr, size_t len); | 83 void decommitSystemPages(void* addr, size_t len); |
| 79 | 84 |
| 80 // Returns a suitable pointer for starting to allocate super pages. | 85 // Returns a suitable pointer for starting to allocate super pages. |
| 81 // The pointer is not guaranteed to be "unused", but does represent an address | 86 // The pointer is not guaranteed to be "unused", but does represent an address |
| 82 // that has a good chance of being unused. The pointer is also randomized to | 87 // that has a good chance of being unused. The pointer is also randomized to |
| 83 // provide reasonable ASLR. | 88 // provide reasonable ASLR. |
| 84 char* getRandomSuperPageBase(); | 89 char* getRandomSuperPageBase(); |
| 85 | 90 |
| 91 #if CPU(32BIT) | |
| 92 class SuperPageBitmap { | |
|
Tom Sepez
2013/10/02 16:51:31
Not sure this buys a lot over just having the s_bi
Tom Sepez
2013/10/02 16:57:33
Alternatively, you could call this a SuperPageTrac
| |
| 93 public: | |
| 94 ALWAYS_INLINE static bool isPointerInSuperPage(void* ptr) | |
| 95 { | |
| 96 uintptr_t raw = reinterpret_cast<uintptr_t>(ptr); | |
| 97 size_t idx = raw >> (kSuperPageShift + 3); | |
| 98 size_t bit = raw & 7; | |
|
Tom Sepez
2013/10/02 16:51:31
This doesn't seem right. You want the low 3 bits
| |
| 99 return s_bitmap[idx] & (1 << bit); | |
| 100 } | |
| 101 | |
| 102 static void registerSuperPage(void* ptr); | |
| 103 static void unregisterSuperPage(void* ptr); | |
| 104 | |
| 105 private: | |
| 106 static unsigned char s_bitmap[1 << (32 - kSuperPageShift - 3)]; | |
|
Tom Sepez
2013/10/02 16:51:31
I'd like this as a constant so we can assert that
| |
| 107 }; | |
| 108 #endif | |
| 109 | |
| 86 } // namespace WTF | 110 } // namespace WTF |
| 87 | 111 |
| 88 #endif // WTF_PageAllocator_h | 112 #endif // WTF_PageAllocator_h |
| OLD | NEW |