OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
Primiano Tucci (use gerrit)
2016/06/28 14:23:08
I think you have to update also heap_profiler_allo
| |
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/trace_event/heap_profiler_allocation_register.h" | 5 #include "base/trace_event/heap_profiler_allocation_register.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <sys/mman.h> | 8 #include <sys/mman.h> |
9 #include <unistd.h> | 9 #include <unistd.h> |
10 | 10 |
11 #include "base/bits.h" | 11 #include "base/bits.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/process/process_metrics.h" | 13 #include "base/process/process_metrics.h" |
14 | 14 |
15 #ifndef MAP_ANONYMOUS | 15 #ifndef MAP_ANONYMOUS |
16 #define MAP_ANONYMOUS MAP_ANON | 16 #define MAP_ANONYMOUS MAP_ANON |
17 #endif | 17 #endif |
18 | 18 |
19 namespace base { | 19 namespace base { |
20 namespace trace_event { | 20 namespace trace_event { |
21 namespace internal { | |
21 | 22 |
22 namespace { | 23 namespace { |
23 size_t GetGuardSize() { | 24 size_t GetGuardSize() { |
24 return GetPageSize(); | 25 return GetPageSize(); |
25 } | 26 } |
26 } | 27 } |
27 | 28 |
28 // static | 29 void* AllocateGuardedVirtualMemory(size_t size) { |
29 void* AllocationRegister::AllocateVirtualMemory(size_t size) { | |
30 size = bits::Align(size, GetPageSize()); | 30 size = bits::Align(size, GetPageSize()); |
31 | 31 |
32 // Add space for a guard page at the end. | 32 // Add space for a guard page at the end. |
33 size_t map_size = size + GetGuardSize(); | 33 size_t map_size = size + GetGuardSize(); |
34 | 34 |
35 void* addr = mmap(nullptr, map_size, PROT_READ | PROT_WRITE, | 35 void* addr = mmap(nullptr, map_size, PROT_READ | PROT_WRITE, |
36 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); | 36 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); |
37 | 37 |
38 PCHECK(addr != MAP_FAILED); | 38 PCHECK(addr != MAP_FAILED); |
39 | 39 |
40 // Mark the last page of the allocated address space as inaccessible | 40 // Mark the last page of the allocated address space as inaccessible |
41 // (PROT_NONE). The read/write accessible space is still at least |min_size| | 41 // (PROT_NONE). The read/write accessible space is still at least |min_size| |
42 // bytes. | 42 // bytes. |
43 void* guard_addr = | 43 void* guard_addr = |
44 reinterpret_cast<void*>(reinterpret_cast<uintptr_t>(addr) + size); | 44 reinterpret_cast<void*>(reinterpret_cast<uintptr_t>(addr) + size); |
45 int result = mprotect(guard_addr, GetGuardSize(), PROT_NONE); | 45 int result = mprotect(guard_addr, GetGuardSize(), PROT_NONE); |
46 PCHECK(result == 0); | 46 PCHECK(result == 0); |
47 | 47 |
48 return addr; | 48 return addr; |
49 } | 49 } |
50 | 50 |
51 // static | 51 // static |
52 void AllocationRegister::FreeVirtualMemory(void* address, | 52 void FreeGuardedVirtualMemory(void* address, size_t allocated_size) { |
53 size_t allocated_size) { | |
54 size_t size = bits::Align(allocated_size, GetPageSize()) + GetGuardSize(); | 53 size_t size = bits::Align(allocated_size, GetPageSize()) + GetGuardSize(); |
55 munmap(address, size); | 54 munmap(address, size); |
56 } | 55 } |
57 | 56 |
57 } // namespace internal | |
58 } // namespace trace_event | 58 } // namespace trace_event |
59 } // namespace base | 59 } // namespace base |
OLD | NEW |