Index: base/allocator/partition_allocator/page_allocator.cc |
diff --git a/third_party/WebKit/Source/wtf/allocator/PageAllocator.cpp b/base/allocator/partition_allocator/page_allocator.cc |
similarity index 69% |
rename from third_party/WebKit/Source/wtf/allocator/PageAllocator.cpp |
rename to base/allocator/partition_allocator/page_allocator.cc |
index 22e12d33c72d53cdf08139fba66f8a6c07e4050b..fc534d9d23ace083a4826ad80f0193f6a4a7a593 100644 |
--- a/third_party/WebKit/Source/wtf/allocator/PageAllocator.cpp |
+++ b/base/allocator/partition_allocator/page_allocator.cc |
@@ -1,42 +1,15 @@ |
-/* |
- * Copyright (C) 2013 Google Inc. All rights reserved. |
- * |
- * Redistribution and use in source and binary forms, with or without |
- * modification, are permitted provided that the following conditions are |
- * met: |
- * |
- * * Redistributions of source code must retain the above copyright |
- * notice, this list of conditions and the following disclaimer. |
- * * Redistributions in binary form must reproduce the above |
- * copyright notice, this list of conditions and the following disclaimer |
- * in the documentation and/or other materials provided with the |
- * distribution. |
- * * Neither the name of Google Inc. nor the names of its |
- * contributors may be used to endorse or promote products derived from |
- * this software without specific prior written permission. |
- * |
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
- */ |
- |
-#include "wtf/allocator/PageAllocator.h" |
- |
-#include "wtf/Assertions.h" |
-#include "wtf/Atomics.h" |
-#include "wtf/allocator/AddressSpaceRandomization.h" |
+// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "base/allocator/partition_allocator/page_allocator.h" |
#include <limits.h> |
-#if OS(POSIX) |
+#include "base/allocator/partition_allocator/address_space_randomization.h" |
+#include "base/logging.h" |
Primiano Tucci (use gerrit)
2016/11/22 14:28:32
+ build_config.h
palmer
2016/11/24 01:05:55
Done.
|
+ |
+#if defined(OS_POSIX) |
#include <errno.h> |
#include <sys/mman.h> |
@@ -53,7 +26,7 @@ |
static const bool kHintIsAdvisory = true; |
static uint32_t s_allocPageErrorCode = 0; |
-#elif OS(WIN) |
+#elif defined(OS_WIN) |
#include <windows.h> |
@@ -63,9 +36,9 @@ static uint32_t s_allocPageErrorCode = ERROR_SUCCESS; |
#else |
#error Unknown OS |
-#endif // OS(POSIX) |
+#endif // defined(OS_POSIX) |
-namespace WTF { |
+namespace base { |
// This internal function wraps the OS-specific page allocation call. The |
// behavior of the hint address is determined by the kHintIsAdvisory constant. |
@@ -76,11 +49,11 @@ static void* systemAllocPages( |
void* hint, |
size_t len, |
PageAccessibilityConfiguration pageAccessibility) { |
- ASSERT(!(len & kPageAllocationGranularityOffsetMask)); |
- ASSERT(!(reinterpret_cast<uintptr_t>(hint) & |
+ DCHECK(!(len & kPageAllocationGranularityOffsetMask)); |
+ DCHECK(!(reinterpret_cast<uintptr_t>(hint) & |
kPageAllocationGranularityOffsetMask)); |
void* ret; |
-#if OS(WIN) |
+#if defined(OS_WIN) |
DWORD accessFlag = |
pageAccessibility == PageAccessible ? PAGE_READWRITE : PAGE_NOACCESS; |
ret = VirtualAlloc(hint, len, MEM_RESERVE | MEM_COMMIT, accessFlag); |
@@ -110,21 +83,21 @@ static void* trimMapping(void* base, |
if (preSlack) |
preSlack = align - preSlack; |
size_t postSlack = baseLen - preSlack - trimLen; |
- ASSERT(baseLen >= trimLen || preSlack || postSlack); |
- ASSERT(preSlack < baseLen); |
- ASSERT(postSlack < baseLen); |
+ DCHECK(baseLen >= trimLen || preSlack || postSlack); |
+ DCHECK(preSlack < baseLen); |
+ DCHECK(postSlack < baseLen); |
void* ret = base; |
-#if OS(POSIX) // On POSIX we can resize the allocation run. |
+#if defined(OS_POSIX) // On POSIX we can resize the allocation run. |
(void)pageAccessibility; |
if (preSlack) { |
int res = munmap(base, preSlack); |
- RELEASE_ASSERT(!res); |
+ CHECK(!res); |
ret = reinterpret_cast<char*>(base) + preSlack; |
} |
if (postSlack) { |
int res = munmap(reinterpret_cast<char*>(ret) + trimLen, postSlack); |
- RELEASE_ASSERT(!res); |
+ CHECK(!res); |
} |
#else // On Windows we can't resize the allocation run. |
if (preSlack || postSlack) { |
@@ -141,15 +114,15 @@ void* allocPages(void* addr, |
size_t len, |
size_t align, |
PageAccessibilityConfiguration pageAccessibility) { |
- ASSERT(len >= kPageAllocationGranularity); |
- ASSERT(!(len & kPageAllocationGranularityOffsetMask)); |
- ASSERT(align >= kPageAllocationGranularity); |
- ASSERT(!(align & kPageAllocationGranularityOffsetMask)); |
- ASSERT(!(reinterpret_cast<uintptr_t>(addr) & |
+ DCHECK(len >= kPageAllocationGranularity); |
+ DCHECK(!(len & kPageAllocationGranularityOffsetMask)); |
+ DCHECK(align >= kPageAllocationGranularity); |
+ DCHECK(!(align & kPageAllocationGranularityOffsetMask)); |
+ DCHECK(!(reinterpret_cast<uintptr_t>(addr) & |
kPageAllocationGranularityOffsetMask)); |
uintptr_t alignOffsetMask = align - 1; |
uintptr_t alignBaseMask = ~alignOffsetMask; |
- ASSERT(!(reinterpret_cast<uintptr_t>(addr) & alignOffsetMask)); |
+ DCHECK(!(reinterpret_cast<uintptr_t>(addr) & alignOffsetMask)); |
// If the client passed null as the address, choose a good one. |
if (!addr) { |
@@ -190,7 +163,7 @@ void* allocPages(void* addr, |
// Map a larger allocation so we can force alignment, but continue randomizing |
// only on 64-bit POSIX. |
size_t tryLen = len + (align - kPageAllocationGranularity); |
- RELEASE_ASSERT(tryLen >= len); |
+ CHECK(tryLen >= len); |
void* ret; |
do { |
@@ -206,32 +179,32 @@ void* allocPages(void* addr, |
} |
void freePages(void* addr, size_t len) { |
- ASSERT(!(reinterpret_cast<uintptr_t>(addr) & |
+ DCHECK(!(reinterpret_cast<uintptr_t>(addr) & |
kPageAllocationGranularityOffsetMask)); |
- ASSERT(!(len & kPageAllocationGranularityOffsetMask)); |
-#if OS(POSIX) |
+ DCHECK(!(len & kPageAllocationGranularityOffsetMask)); |
+#if defined(OS_POSIX) |
int ret = munmap(addr, len); |
- RELEASE_ASSERT(!ret); |
+ CHECK(!ret); |
#else |
BOOL ret = VirtualFree(addr, 0, MEM_RELEASE); |
- RELEASE_ASSERT(ret); |
+ CHECK(ret); |
#endif |
} |
void setSystemPagesInaccessible(void* addr, size_t len) { |
- ASSERT(!(len & kSystemPageOffsetMask)); |
-#if OS(POSIX) |
+ DCHECK(!(len & kSystemPageOffsetMask)); |
+#if defined(OS_POSIX) |
int ret = mprotect(addr, len, PROT_NONE); |
- RELEASE_ASSERT(!ret); |
+ CHECK(!ret); |
#else |
BOOL ret = VirtualFree(addr, len, MEM_DECOMMIT); |
- RELEASE_ASSERT(ret); |
+ CHECK(ret); |
#endif |
} |
bool setSystemPagesAccessible(void* addr, size_t len) { |
- ASSERT(!(len & kSystemPageOffsetMask)); |
-#if OS(POSIX) |
+ DCHECK(!(len & kSystemPageOffsetMask)); |
+#if defined(OS_POSIX) |
return !mprotect(addr, len, PROT_READ | PROT_WRITE); |
#else |
return !!VirtualAlloc(addr, len, MEM_COMMIT, PAGE_READWRITE); |
@@ -239,27 +212,27 @@ bool setSystemPagesAccessible(void* addr, size_t len) { |
} |
void decommitSystemPages(void* addr, size_t len) { |
- ASSERT(!(len & kSystemPageOffsetMask)); |
-#if OS(POSIX) |
+ DCHECK(!(len & kSystemPageOffsetMask)); |
+#if defined(OS_POSIX) |
int ret = madvise(addr, len, MADV_FREE); |
- RELEASE_ASSERT(!ret); |
+ CHECK(!ret); |
#else |
setSystemPagesInaccessible(addr, len); |
#endif |
} |
void recommitSystemPages(void* addr, size_t len) { |
- ASSERT(!(len & kSystemPageOffsetMask)); |
-#if OS(POSIX) |
+ DCHECK(!(len & kSystemPageOffsetMask)); |
+#if defined(OS_POSIX) |
(void)addr; |
#else |
- RELEASE_ASSERT(setSystemPagesAccessible(addr, len)); |
+ CHECK(setSystemPagesAccessible(addr, len)); |
#endif |
} |
void discardSystemPages(void* addr, size_t len) { |
- ASSERT(!(len & kSystemPageOffsetMask)); |
-#if OS(POSIX) |
+ DCHECK(!(len & kSystemPageOffsetMask)); |
+#if defined(OS_POSIX) |
// On POSIX, the implementation detail is that discard and decommit are the |
// same, and lead to pages that are returned to the system immediately and |
// get replaced with zeroed pages when touched. So we just call |
@@ -286,7 +259,7 @@ void discardSystemPages(void* addr, size_t len) { |
// failure. |
if (ret) { |
void* ret = VirtualAlloc(addr, len, MEM_RESET, PAGE_READWRITE); |
- RELEASE_ASSERT(ret); |
+ CHECK(ret); |
} |
#endif |
} |
@@ -295,4 +268,4 @@ uint32_t getAllocPageErrorCode() { |
return acquireLoad(&s_allocPageErrorCode); |
} |
-} // namespace WTF |
+} // namespace base |