Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(58)

Side by Side Diff: Source/wtf/PageAllocator.h

Issue 25640003: Optimize test for pointer being in a partition on 32-bit. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fix variable name. Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/wtf/CPU.h ('k') | Source/wtf/PageAllocator.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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/Assertions.h"
35 #include "wtf/CPU.h"
36 #include <stdint.h>
37
34 namespace WTF { 38 namespace WTF {
35 39
36 // Our granulatity of page allocation is 64KB. This is a Windows limitation, 40 // 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 41 // but we apply the same requirement for all platforms in order to keep
38 // things simple and consistent. 42 // things simple and consistent.
39 // We term these 64KB allocations "super pages". They're just a clump of 43 // We term these 64KB allocations "super pages". They're just a clump of
40 // underlying 4KB system pages. 44 // underlying 4KB system pages.
41 static const size_t kSuperPageSize = 1 << 16; // 64KB 45 static const size_t kSuperPageShift = 16; // 64KB
46 static const size_t kSuperPageSize = 1 << kSuperPageShift;
42 static const size_t kSuperPageOffsetMask = kSuperPageSize - 1; 47 static const size_t kSuperPageOffsetMask = kSuperPageSize - 1;
43 static const size_t kSuperPageBaseMask = ~kSuperPageOffsetMask; 48 static const size_t kSuperPageBaseMask = ~kSuperPageOffsetMask;
44 49
45 // All Blink-supported systems have 4096 sized system pages and can handle 50 // All Blink-supported systems have 4096 sized system pages and can handle
46 // permissions and commit / decommit at this granularity. 51 // permissions and commit / decommit at this granularity.
47 static const size_t kSystemPageSize = 4096; 52 static const size_t kSystemPageSize = 4096;
48 static const size_t kSystemPageOffsetMask = kSystemPageSize - 1; 53 static const size_t kSystemPageOffsetMask = kSystemPageSize - 1;
49 54
50 static const size_t kNumSystemPagesPerSuperPage = kSuperPageSize / kSystemPageSi ze; 55 static const size_t kNumSystemPagesPerSuperPage = kSuperPageSize / kSystemPageSi ze;
51 56
(...skipping 13 matching lines...) Expand all
65 // Subsequently accessing any address in the range will fault, the addresses 70 // Subsequently accessing any address in the range will fault, the addresses
66 // will not be re-used by future allocations. 71 // will not be re-used by future allocations.
67 // len must be a multiple of kSystemPageSize bytes. 72 // len must be a multiple of kSystemPageSize bytes.
68 void setSystemPagesInaccessible(void* addr, size_t len); 73 void setSystemPagesInaccessible(void* addr, size_t len);
69 74
70 // Decommit one or more system pages. Decommitted means that the physical memory 75 // 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. 76 // is released to the system, but the virtual address space remains reserved.
72 // System pages are re-committed by writing to them. 77 // System pages are re-committed by writing to them.
73 // Clients should not make any assumptions about the contents of decommitted 78 // 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 79 // 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 80 // provided is that the contents of the system page will be deterministic again
81 // after writing to it. In particlar note that system pages are not guaranteed
76 // to be zero-filled upon re-commit. 82 // to be zero-filled upon re-commit.
77 // len must be a multiple of kSystemPageSize bytes. 83 // len must be a multiple of kSystemPageSize bytes.
78 void decommitSystemPages(void* addr, size_t len); 84 void decommitSystemPages(void* addr, size_t len);
79 85
80 // Returns a suitable pointer for starting to allocate super pages. 86 // Returns a suitable pointer for starting to allocate super pages.
81 // The pointer is not guaranteed to be "unused", but does represent an address 87 // 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 88 // that has a good chance of being unused. The pointer is also randomized to
83 // provide reasonable ASLR. 89 // provide reasonable ASLR.
84 char* getRandomSuperPageBase(); 90 char* getRandomSuperPageBase();
85 91
92 #if CPU(32BIT)
93 class SuperPageBitmap {
94 public:
95 ALWAYS_INLINE static bool isAvailable()
96 {
97 return true;
98 }
99
100 ALWAYS_INLINE static bool isPointerInSuperPage(void* ptr)
101 {
102 uintptr_t raw = reinterpret_cast<uintptr_t>(ptr);
103 raw >>= kSuperPageShift;
104 size_t byteIndex = raw >> 3;
105 size_t bit = raw & 7;
106 ASSERT(byteIndex < sizeof(s_bitmap));
107 return s_bitmap[byteIndex] & (1 << bit);
108 }
109
110 static void registerSuperPage(void* ptr);
111 static void unregisterSuperPage(void* ptr);
112
113 private:
114 static unsigned char s_bitmap[1 << (32 - kSuperPageShift - 3)];
115 };
116
117 #else // CPU(32BIT)
118
119 class SuperPageBitmap {
120 public:
121 ALWAYS_INLINE static bool isAvailable()
122 {
123 return false;
124 }
125
126 ALWAYS_INLINE static bool isPointerInSuperPage(void* ptr)
127 {
128 ASSERT(false);
129 return false;
130 }
131
132 static void registerSuperPage(void* ptr) { }
133 static void unregisterSuperPage(void* ptr) { }
134 };
135
136 #endif // CPU(32BIT)
137
86 } // namespace WTF 138 } // namespace WTF
87 139
88 #endif // WTF_PageAllocator_h 140 #endif // WTF_PageAllocator_h
OLDNEW
« no previous file with comments | « Source/wtf/CPU.h ('k') | Source/wtf/PageAllocator.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698