| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/allocator/partition_allocator/page_allocator.h" | 5 #include "base/allocator/partition_allocator/page_allocator.h" |
| 6 | 6 |
| 7 #include <limits.h> | 7 #include <limits.h> |
| 8 | 8 |
| 9 #include "base/allocator/partition_allocator/address_space_randomization.h" | 9 #include "base/allocator/partition_allocator/address_space_randomization.h" |
| 10 #include "base/atomicops.h" | 10 #include "base/atomicops.h" |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 return !mprotect(addr, len, PROT_READ | PROT_WRITE); | 209 return !mprotect(addr, len, PROT_READ | PROT_WRITE); |
| 210 #else | 210 #else |
| 211 return !!VirtualAlloc(addr, len, MEM_COMMIT, PAGE_READWRITE); | 211 return !!VirtualAlloc(addr, len, MEM_COMMIT, PAGE_READWRITE); |
| 212 #endif | 212 #endif |
| 213 } | 213 } |
| 214 | 214 |
| 215 void decommitSystemPages(void* addr, size_t len) { | 215 void decommitSystemPages(void* addr, size_t len) { |
| 216 DCHECK(!(len & kSystemPageOffsetMask)); | 216 DCHECK(!(len & kSystemPageOffsetMask)); |
| 217 #if defined(OS_POSIX) | 217 #if defined(OS_POSIX) |
| 218 int ret = madvise(addr, len, MADV_FREE); | 218 int ret = madvise(addr, len, MADV_FREE); |
| 219 if (ret != 0 && errno == EINVAL) { |
| 220 // MADV_FREE only works on Linux 4.5+ . If request failed, |
| 221 // retry with older MADV_DONTNEED . Note that MADV_FREE |
| 222 // being defined at compile time doesn't imply runtime support. |
| 223 ret = madvise(addr, len, MADV_DONTNEED); |
| 224 } |
| 219 CHECK(!ret); | 225 CHECK(!ret); |
| 220 #else | 226 #else |
| 221 setSystemPagesInaccessible(addr, len); | 227 setSystemPagesInaccessible(addr, len); |
| 222 #endif | 228 #endif |
| 223 } | 229 } |
| 224 | 230 |
| 225 void recommitSystemPages(void* addr, size_t len) { | 231 void recommitSystemPages(void* addr, size_t len) { |
| 226 DCHECK(!(len & kSystemPageOffsetMask)); | 232 DCHECK(!(len & kSystemPageOffsetMask)); |
| 227 #if defined(OS_POSIX) | 233 #if defined(OS_POSIX) |
| 228 (void)addr; | 234 (void)addr; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 CHECK(ret); | 269 CHECK(ret); |
| 264 } | 270 } |
| 265 #endif | 271 #endif |
| 266 } | 272 } |
| 267 | 273 |
| 268 uint32_t getAllocPageErrorCode() { | 274 uint32_t getAllocPageErrorCode() { |
| 269 return base::subtle::Acquire_Load(&s_allocPageErrorCode); | 275 return base::subtle::Acquire_Load(&s_allocPageErrorCode); |
| 270 } | 276 } |
| 271 | 277 |
| 272 } // namespace base | 278 } // namespace base |
| OLD | NEW |