| 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 <atomic> | 9 #include <atomic> |
| 10 | 10 |
| 11 #include "base/allocator/partition_allocator/address_space_randomization.h" | 11 #include "base/allocator/partition_allocator/address_space_randomization.h" |
| 12 #include "base/base_export.h" | 12 #include "base/base_export.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "build/build_config.h" | 14 #include "build/build_config.h" |
| 15 | 15 |
| 16 #if defined(OS_MACOSX) |
| 17 #include <mach/mach.h> |
| 18 #endif |
| 19 |
| 16 #if defined(OS_POSIX) | 20 #if defined(OS_POSIX) |
| 17 | 21 |
| 18 #include <errno.h> | 22 #include <errno.h> |
| 19 #include <sys/mman.h> | 23 #include <sys/mman.h> |
| 20 | 24 |
| 21 #ifndef MADV_FREE | 25 #ifndef MADV_FREE |
| 22 #define MADV_FREE MADV_DONTNEED | 26 #define MADV_FREE MADV_DONTNEED |
| 23 #endif | 27 #endif |
| 24 | 28 |
| 25 #ifndef MAP_ANONYMOUS | 29 #ifndef MAP_ANONYMOUS |
| (...skipping 28 matching lines...) Expand all Loading... |
| 54 DCHECK(!(reinterpret_cast<uintptr_t>(hint) & | 58 DCHECK(!(reinterpret_cast<uintptr_t>(hint) & |
| 55 kPageAllocationGranularityOffsetMask)); | 59 kPageAllocationGranularityOffsetMask)); |
| 56 void* ret; | 60 void* ret; |
| 57 #if defined(OS_WIN) | 61 #if defined(OS_WIN) |
| 58 DWORD access_flag = | 62 DWORD access_flag = |
| 59 page_accessibility == PageAccessible ? PAGE_READWRITE : PAGE_NOACCESS; | 63 page_accessibility == PageAccessible ? PAGE_READWRITE : PAGE_NOACCESS; |
| 60 ret = VirtualAlloc(hint, length, MEM_RESERVE | MEM_COMMIT, access_flag); | 64 ret = VirtualAlloc(hint, length, MEM_RESERVE | MEM_COMMIT, access_flag); |
| 61 if (!ret) | 65 if (!ret) |
| 62 s_allocPageErrorCode = GetLastError(); | 66 s_allocPageErrorCode = GetLastError(); |
| 63 #else | 67 #else |
| 68 |
| 69 #if defined(OS_MACOSX) |
| 70 // Use a custom tag to make it easier to distinguish partition alloc regions |
| 71 // in vmmap. |
| 72 int fd = VM_MAKE_TAG(254); |
| 73 #else |
| 74 int fd = -1; |
| 75 #endif |
| 76 |
| 64 int access_flag = page_accessibility == PageAccessible | 77 int access_flag = page_accessibility == PageAccessible |
| 65 ? (PROT_READ | PROT_WRITE) | 78 ? (PROT_READ | PROT_WRITE) |
| 66 : PROT_NONE; | 79 : PROT_NONE; |
| 67 ret = mmap(hint, length, access_flag, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); | 80 ret = mmap(hint, length, access_flag, MAP_ANONYMOUS | MAP_PRIVATE, fd, 0); |
| 68 if (ret == MAP_FAILED) { | 81 if (ret == MAP_FAILED) { |
| 69 s_allocPageErrorCode = errno; | 82 s_allocPageErrorCode = errno; |
| 70 ret = 0; | 83 ret = 0; |
| 71 } | 84 } |
| 72 #endif | 85 #endif |
| 73 return ret; | 86 return ret; |
| 74 } | 87 } |
| 75 | 88 |
| 76 // Trims base to given length and alignment. Windows returns null on failure and | 89 // Trims base to given length and alignment. Windows returns null on failure and |
| 77 // frees base. | 90 // frees base. |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 CHECK(ret); | 290 CHECK(ret); |
| 278 } | 291 } |
| 279 #endif | 292 #endif |
| 280 } | 293 } |
| 281 | 294 |
| 282 uint32_t GetAllocPageErrorCode() { | 295 uint32_t GetAllocPageErrorCode() { |
| 283 return s_allocPageErrorCode; | 296 return s_allocPageErrorCode; |
| 284 } | 297 } |
| 285 | 298 |
| 286 } // namespace base | 299 } // namespace base |
| OLD | NEW |