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

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

Issue 2518253002: Move Partition Allocator into Chromium base. (Closed)
Patch Set: Move OOM_CRASH into its own, more specific header. Fixes Windows build. Created 4 years 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/Compiler.h"
37 #include "wtf/WTFExport.h"
38 #include <cstddef>
39 #include <stdint.h> 8 #include <stdint.h>
40 9
41 namespace WTF { 10 #include <cstddef>
42 11
43 #if OS(WIN) 12 #include "base/base_export.h"
13 #include "base/compiler_specific.h"
14 #include "build/build_config.h"
15
16 namespace base {
17
18 #if defined(OS_WIN)
44 static const size_t kPageAllocationGranularityShift = 16; // 64KB 19 static const size_t kPageAllocationGranularityShift = 16; // 64KB
45 #else 20 #else
46 static const size_t kPageAllocationGranularityShift = 12; // 4KB 21 static const size_t kPageAllocationGranularityShift = 12; // 4KB
47 #endif 22 #endif
48 static const size_t kPageAllocationGranularity = 23 static const size_t kPageAllocationGranularity =
49 1 << kPageAllocationGranularityShift; 24 1 << kPageAllocationGranularityShift;
50 static const size_t kPageAllocationGranularityOffsetMask = 25 static const size_t kPageAllocationGranularityOffsetMask =
51 kPageAllocationGranularity - 1; 26 kPageAllocationGranularity - 1;
52 static const size_t kPageAllocationGranularityBaseMask = 27 static const size_t kPageAllocationGranularityBaseMask =
53 ~kPageAllocationGranularityOffsetMask; 28 ~kPageAllocationGranularityOffsetMask;
(...skipping 13 matching lines...) Expand all
67 // The requested address is just a hint; the actual address returned may 42 // The requested address is just a hint; the actual address returned may
68 // differ. The returned address will be aligned at least to align bytes. 43 // differ. The returned address will be aligned at least to align bytes.
69 // len is in bytes, and must be a multiple of kPageAllocationGranularity. 44 // len is in bytes, and must be a multiple of kPageAllocationGranularity.
70 // align is in bytes, and must be a power-of-two multiple of 45 // align is in bytes, and must be a power-of-two multiple of
71 // kPageAllocationGranularity. 46 // kPageAllocationGranularity.
72 // If addr is null, then a suitable and randomized address will be chosen 47 // If addr is null, then a suitable and randomized address will be chosen
73 // automatically. 48 // automatically.
74 // PageAccessibilityConfiguration controls the permission of the 49 // PageAccessibilityConfiguration controls the permission of the
75 // allocated pages. 50 // allocated pages.
76 // This call will return null if the allocation cannot be satisfied. 51 // This call will return null if the allocation cannot be satisfied.
77 WTF_EXPORT void* allocPages(void* addr, 52 BASE_EXPORT void* allocPages(void* addr,
78 size_t len, 53 size_t len,
79 size_t align, 54 size_t align,
80 PageAccessibilityConfiguration); 55 PageAccessibilityConfiguration);
81 56
82 // Free one or more pages. 57 // Free one or more pages.
83 // addr and len must match a previous call to allocPages(). 58 // addr and len must match a previous call to allocPages().
84 WTF_EXPORT void freePages(void* addr, size_t len); 59 BASE_EXPORT void freePages(void* addr, size_t len);
85 60
86 // Mark one or more system pages as being inaccessible. 61 // Mark one or more system pages as being inaccessible.
87 // Subsequently accessing any address in the range will fault, and the 62 // Subsequently accessing any address in the range will fault, and the
88 // addresses will not be re-used by future allocations. 63 // addresses will not be re-used by future allocations.
89 // len must be a multiple of kSystemPageSize bytes. 64 // len must be a multiple of kSystemPageSize bytes.
90 WTF_EXPORT void setSystemPagesInaccessible(void* addr, size_t len); 65 BASE_EXPORT void setSystemPagesInaccessible(void* addr, size_t len);
91 66
92 // Mark one or more system pages as being accessible. 67 // Mark one or more system pages as being accessible.
93 // The pages will be readable and writeable. 68 // The pages will be readable and writeable.
94 // len must be a multiple of kSystemPageSize bytes. 69 // len must be a multiple of kSystemPageSize bytes.
95 // The result bool value indicates whether the permission 70 // The result bool value indicates whether the permission
96 // change succeeded or not. You must check the result 71 // change succeeded or not. You must check the result
97 // (in most cases you need to RELEASE_ASSERT that it is 72 // (in most cases you need to CHECK that it is true).
98 // true). 73 BASE_EXPORT WARN_UNUSED_RESULT bool setSystemPagesAccessible(void* addr,
99 WTF_EXPORT WARN_UNUSED_RESULT bool setSystemPagesAccessible(void* addr, 74 size_t len);
100 size_t len);
101 75
102 // Decommit one or more system pages. Decommitted means that the physical memory 76 // Decommit one or more system pages. Decommitted means that the physical memory
103 // is released to the system, but the virtual address space remains reserved. 77 // is released to the system, but the virtual address space remains reserved.
104 // System pages are re-committed by calling recommitSystemPages(). Touching 78 // System pages are re-committed by calling recommitSystemPages(). Touching
105 // a decommitted page _may_ fault. 79 // a decommitted page _may_ fault.
106 // Clients should not make any assumptions about the contents of decommitted 80 // Clients should not make any assumptions about the contents of decommitted
107 // system pages, before or after they write to the page. The only guarantee 81 // system pages, before or after they write to the page. The only guarantee
108 // provided is that the contents of the system page will be deterministic again 82 // provided is that the contents of the system page will be deterministic again
109 // after recommitting and writing to it. In particlar note that system pages are 83 // after recommitting and writing to it. In particlar note that system pages are
110 // not guaranteed to be zero-filled upon re-commit. len must be a multiple of 84 // not guaranteed to be zero-filled upon re-commit. len must be a multiple of
111 // kSystemPageSize bytes. 85 // kSystemPageSize bytes.
112 WTF_EXPORT void decommitSystemPages(void* addr, size_t len); 86 BASE_EXPORT void decommitSystemPages(void* addr, size_t len);
113 87
114 // Recommit one or more system pages. Decommitted system pages must be 88 // Recommit one or more system pages. Decommitted system pages must be
115 // recommitted before they are read are written again. 89 // recommitted before they are read are written again.
116 // Note that this operation may be a no-op on some platforms. 90 // Note that this operation may be a no-op on some platforms.
117 // len must be a multiple of kSystemPageSize bytes. 91 // len must be a multiple of kSystemPageSize bytes.
118 WTF_EXPORT void recommitSystemPages(void* addr, size_t len); 92 BASE_EXPORT void recommitSystemPages(void* addr, size_t len);
119 93
120 // Discard one or more system pages. Discarding is a hint to the system that 94 // Discard one or more system pages. Discarding is a hint to the system that
121 // the page is no longer required. The hint may: 95 // the page is no longer required. The hint may:
122 // - Do nothing. 96 // - Do nothing.
123 // - Discard the page immediately, freeing up physical pages. 97 // - Discard the page immediately, freeing up physical pages.
124 // - Discard the page at some time in the future in response to memory pressure. 98 // - Discard the page at some time in the future in response to memory pressure.
125 // Only committed pages should be discarded. Discarding a page does not 99 // Only committed pages should be discarded. Discarding a page does not
126 // decommit it, and it is valid to discard an already-discarded page. 100 // decommit it, and it is valid to discard an already-discarded page.
127 // A read or write to a discarded page will not fault. 101 // A read or write to a discarded page will not fault.
128 // Reading from a discarded page may return the original page content, or a 102 // Reading from a discarded page may return the original page content, or a
129 // page full of zeroes. 103 // page full of zeroes.
130 // Writing to a discarded page is the only guaranteed way to tell the system 104 // Writing to a discarded page is the only guaranteed way to tell the system
131 // that the page is required again. Once written to, the content of the page is 105 // that the page is required again. Once written to, the content of the page is
132 // guaranteed stable once more. After being written to, the page content may be 106 // guaranteed stable once more. After being written to, the page content may be
133 // based on the original page content, or a page of zeroes. 107 // based on the original page content, or a page of zeroes.
134 // len must be a multiple of kSystemPageSize bytes. 108 // len must be a multiple of kSystemPageSize bytes.
135 WTF_EXPORT void discardSystemPages(void* addr, size_t len); 109 BASE_EXPORT void discardSystemPages(void* addr, size_t len);
136 110
137 WTF_EXPORT ALWAYS_INLINE uintptr_t roundUpToSystemPage(uintptr_t address) { 111 ALWAYS_INLINE uintptr_t roundUpToSystemPage(uintptr_t address) {
138 return (address + kSystemPageOffsetMask) & kSystemPageBaseMask; 112 return (address + kSystemPageOffsetMask) & kSystemPageBaseMask;
139 } 113 }
140 114
141 WTF_EXPORT ALWAYS_INLINE uintptr_t roundDownToSystemPage(uintptr_t address) { 115 ALWAYS_INLINE uintptr_t roundDownToSystemPage(uintptr_t address) {
142 return address & kSystemPageBaseMask; 116 return address & kSystemPageBaseMask;
143 } 117 }
144 118
145 // Only allowed inside WTF for investigating WTF::initializeWithoutV8 crashes. 119 // Returns errno (or GetLastError code) when mmap (or VirtualAlloc) fails.
146 // Guess, the function fails because of mmap (or VirtualAlloc) failure. 120 BASE_EXPORT uint32_t getAllocPageErrorCode();
147 // The following function returns errno (or GetLastError code) when mmap
148 // (or VirtualAlloc) fails.
149 uint32_t getAllocPageErrorCode();
150 121
151 } // namespace WTF 122 } // namespace base
152 123
153 #endif // WTF_PageAllocator_h 124 #endif // BASE_ALLOCATOR_PARTITION_ALLOCATOR_PAGE_ALLOCATOR_H
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698