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

Side by Side Diff: base/allocator/partition_allocator/page_allocator.h

Issue 2518253002: Move Partition Allocator into Chromium base. (Closed)
Patch Set: Created 4 years, 1 month 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
OLDNEW
1 /* 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be
3 * 3 // found in the LICENSE file.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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.
29 */
30 4
31 #ifndef WTF_PageAllocator_h 5 #ifndef BASE_ALLOCATOR_PARTITION_ALLOCATOR_PAGE_ALLOCATOR_H
32 #define WTF_PageAllocator_h 6 #define BASE_ALLOCATOR_PARTITION_ALLOCATOR_PAGE_ALLOCATOR_H
33 7
34 #include "wtf/Assertions.h"
35 #include "wtf/CPU.h"
36 #include "wtf/WTFExport.h"
37 #include <cstddef>
38 #include <stdint.h> 8 #include <stdint.h>
39 9
40 namespace WTF { 10 #include <cstddef>
41 11
42 #if OS(WIN) 12 #include "base/base_export.h"
Primiano Tucci (use gerrit) 2016/11/22 14:28:32 include build/build_config.h
palmer 2016/11/24 01:05:56 Done.
13 #include "base/compiler_specific.h"
14
15 namespace base {
16
17 #if OS_WIN
Primiano Tucci (use gerrit) 2016/11/22 14:28:32 defined(OS_WIN)
palmer 2016/11/24 01:05:56 Done.
43 static const size_t kPageAllocationGranularityShift = 16; // 64KB 18 static const size_t kPageAllocationGranularityShift = 16; // 64KB
44 #else 19 #else
45 static const size_t kPageAllocationGranularityShift = 12; // 4KB 20 static const size_t kPageAllocationGranularityShift = 12; // 4KB
46 #endif 21 #endif
47 static const size_t kPageAllocationGranularity = 22 static const size_t kPageAllocationGranularity =
48 1 << kPageAllocationGranularityShift; 23 1 << kPageAllocationGranularityShift;
49 static const size_t kPageAllocationGranularityOffsetMask = 24 static const size_t kPageAllocationGranularityOffsetMask =
50 kPageAllocationGranularity - 1; 25 kPageAllocationGranularity - 1;
51 static const size_t kPageAllocationGranularityBaseMask = 26 static const size_t kPageAllocationGranularityBaseMask =
52 ~kPageAllocationGranularityOffsetMask; 27 ~kPageAllocationGranularityOffsetMask;
(...skipping 13 matching lines...) Expand all
66 // The requested address is just a hint; the actual address returned may 41 // The requested address is just a hint; the actual address returned may
67 // differ. The returned address will be aligned at least to align bytes. 42 // differ. The returned address will be aligned at least to align bytes.
68 // len is in bytes, and must be a multiple of kPageAllocationGranularity. 43 // len is in bytes, and must be a multiple of kPageAllocationGranularity.
69 // align is in bytes, and must be a power-of-two multiple of 44 // align is in bytes, and must be a power-of-two multiple of
70 // kPageAllocationGranularity. 45 // kPageAllocationGranularity.
71 // If addr is null, then a suitable and randomized address will be chosen 46 // If addr is null, then a suitable and randomized address will be chosen
72 // automatically. 47 // automatically.
73 // PageAccessibilityConfiguration controls the permission of the 48 // PageAccessibilityConfiguration controls the permission of the
74 // allocated pages. 49 // allocated pages.
75 // This call will return null if the allocation cannot be satisfied. 50 // This call will return null if the allocation cannot be satisfied.
76 WTF_EXPORT void* allocPages(void* addr, 51 BASE_EXPORT void* allocPages(void* addr,
77 size_t len, 52 size_t len,
78 size_t align, 53 size_t align,
79 PageAccessibilityConfiguration); 54 PageAccessibilityConfiguration);
80 55
81 // Free one or more pages. 56 // Free one or more pages.
82 // addr and len must match a previous call to allocPages(). 57 // addr and len must match a previous call to allocPages().
83 WTF_EXPORT void freePages(void* addr, size_t len); 58 BASE_EXPORT void freePages(void* addr, size_t len);
84 59
85 // Mark one or more system pages as being inaccessible. 60 // Mark one or more system pages as being inaccessible.
86 // Subsequently accessing any address in the range will fault, and the 61 // Subsequently accessing any address in the range will fault, and the
87 // addresses will not be re-used by future allocations. 62 // addresses will not be re-used by future allocations.
88 // len must be a multiple of kSystemPageSize bytes. 63 // len must be a multiple of kSystemPageSize bytes.
89 WTF_EXPORT void setSystemPagesInaccessible(void* addr, size_t len); 64 BASE_EXPORT void setSystemPagesInaccessible(void* addr, size_t len);
90 65
91 // Mark one or more system pages as being accessible. 66 // Mark one or more system pages as being accessible.
92 // The pages will be readable and writeable. 67 // The pages will be readable and writeable.
93 // len must be a multiple of kSystemPageSize bytes. 68 // len must be a multiple of kSystemPageSize bytes.
94 // The result bool value indicates whether the permission 69 // The result bool value indicates whether the permission
95 // change succeeded or not. You must check the result 70 // change succeeded or not. You must check the result
96 // (in most cases you need to RELEASE_ASSERT that it is 71 // (in most cases you need to CHECK that it is true).
97 // true). 72 BASE_EXPORT WARN_UNUSED_RESULT bool setSystemPagesAccessible(void* addr,
98 WTF_EXPORT WARN_UNUSED_RETURN bool setSystemPagesAccessible(void* addr, 73 size_t len);
99 size_t len);
100 74
101 // 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
102 // 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.
103 // System pages are re-committed by calling recommitSystemPages(). Touching 77 // System pages are re-committed by calling recommitSystemPages(). Touching
104 // a decommitted page _may_ fault. 78 // a decommitted page _may_ fault.
105 // Clients should not make any assumptions about the contents of decommitted 79 // Clients should not make any assumptions about the contents of decommitted
106 // system pages, before or after they write to the page. The only guarantee 80 // system pages, before or after they write to the page. The only guarantee
107 // provided is that the contents of the system page will be deterministic again 81 // provided is that the contents of the system page will be deterministic again
108 // after recommitting and writing to it. In particlar note that system pages are 82 // after recommitting and writing to it. In particlar note that system pages are
109 // not guaranteed to be zero-filled upon re-commit. len must be a multiple of 83 // not guaranteed to be zero-filled upon re-commit. len must be a multiple of
110 // kSystemPageSize bytes. 84 // kSystemPageSize bytes.
111 WTF_EXPORT void decommitSystemPages(void* addr, size_t len); 85 BASE_EXPORT void decommitSystemPages(void* addr, size_t len);
112 86
113 // Recommit one or more system pages. Decommitted system pages must be 87 // Recommit one or more system pages. Decommitted system pages must be
114 // recommitted before they are read are written again. 88 // recommitted before they are read are written again.
115 // Note that this operation may be a no-op on some platforms. 89 // Note that this operation may be a no-op on some platforms.
116 // len must be a multiple of kSystemPageSize bytes. 90 // len must be a multiple of kSystemPageSize bytes.
117 WTF_EXPORT void recommitSystemPages(void* addr, size_t len); 91 BASE_EXPORT void recommitSystemPages(void* addr, size_t len);
118 92
119 // Discard one or more system pages. Discarding is a hint to the system that 93 // Discard one or more system pages. Discarding is a hint to the system that
120 // the page is no longer required. The hint may: 94 // the page is no longer required. The hint may:
121 // - Do nothing. 95 // - Do nothing.
122 // - Discard the page immediately, freeing up physical pages. 96 // - Discard the page immediately, freeing up physical pages.
123 // - Discard the page at some time in the future in response to memory pressure. 97 // - Discard the page at some time in the future in response to memory pressure.
124 // Only committed pages should be discarded. Discarding a page does not 98 // Only committed pages should be discarded. Discarding a page does not
125 // decommit it, and it is valid to discard an already-discarded page. 99 // decommit it, and it is valid to discard an already-discarded page.
126 // A read or write to a discarded page will not fault. 100 // A read or write to a discarded page will not fault.
127 // Reading from a discarded page may return the original page content, or a 101 // Reading from a discarded page may return the original page content, or a
128 // page full of zeroes. 102 // page full of zeroes.
129 // Writing to a discarded page is the only guaranteed way to tell the system 103 // Writing to a discarded page is the only guaranteed way to tell the system
130 // that the page is required again. Once written to, the content of the page is 104 // that the page is required again. Once written to, the content of the page is
131 // guaranteed stable once more. After being written to, the page content may be 105 // guaranteed stable once more. After being written to, the page content may be
132 // based on the original page content, or a page of zeroes. 106 // based on the original page content, or a page of zeroes.
133 // len must be a multiple of kSystemPageSize bytes. 107 // len must be a multiple of kSystemPageSize bytes.
134 WTF_EXPORT void discardSystemPages(void* addr, size_t len); 108 BASE_EXPORT void discardSystemPages(void* addr, size_t len);
135 109
136 WTF_EXPORT ALWAYS_INLINE uintptr_t roundUpToSystemPage(uintptr_t address) { 110 BASE_EXPORT ALWAYS_INLINE uintptr_t roundUpToSystemPage(uintptr_t address) {
Primiano Tucci (use gerrit) 2016/11/22 14:28:32 export + always_inline: one of the two is a lie :)
palmer 2016/11/24 01:05:56 Done.
137 return (address + kSystemPageOffsetMask) & kSystemPageBaseMask; 111 return (address + kSystemPageOffsetMask) & kSystemPageBaseMask;
138 } 112 }
139 113
140 WTF_EXPORT ALWAYS_INLINE uintptr_t roundDownToSystemPage(uintptr_t address) { 114 BASE_EXPORT ALWAYS_INLINE uintptr_t roundDownToSystemPage(uintptr_t address) {
141 return address & kSystemPageBaseMask; 115 return address & kSystemPageBaseMask;
142 } 116 }
143 117
118 // TODO(palmer): Fix this, and the comment.
119 //
144 // Only allowed inside WTF for investigating WTF::initializeWithoutV8 crashes. 120 // Only allowed inside WTF for investigating WTF::initializeWithoutV8 crashes.
145 // Guess, the function fails because of mmap (or VirtualAlloc) failure. 121 // Guess, the function fails because of mmap (or VirtualAlloc) failure.
146 // The following function returns errno (or GetLastError code) when mmap 122 // The following function returns errno (or GetLastError code) when mmap
147 // (or VirtualAlloc) fails. 123 // (or VirtualAlloc) fails.
148 uint32_t getAllocPageErrorCode(); 124 uint32_t getAllocPageErrorCode();
149 125
150 } // namespace WTF 126 } // namespace base
151 127
152 #endif // WTF_PageAllocator_h 128 #endif // BASE_ALLOCATOR_PARTITION_ALLOCATOR_PAGE_ALLOCATOR_H
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698