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

Side by Side Diff: base/trace_event/process_memory_dump.cc

Issue 2365333002: Fix memory corruption in base_unittests in some configuration. (Closed)
Patch Set: Created 4 years, 2 months 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/trace_event/process_memory_dump.h" 5 #include "base/trace_event/process_memory_dump.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 8
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
12 #include "base/process/process_metrics.h" 12 #include "base/process/process_metrics.h"
13 #include "base/strings/stringprintf.h" 13 #include "base/strings/stringprintf.h"
14 #include "base/trace_event/heap_profiler_heap_dump_writer.h" 14 #include "base/trace_event/heap_profiler_heap_dump_writer.h"
15 #include "base/trace_event/memory_infra_background_whitelist.h" 15 #include "base/trace_event/memory_infra_background_whitelist.h"
16 #include "base/trace_event/process_memory_totals.h" 16 #include "base/trace_event/process_memory_totals.h"
17 #include "base/trace_event/trace_event_argument.h" 17 #include "base/trace_event/trace_event_argument.h"
18 #include "build/build_config.h" 18 #include "build/build_config.h"
19 19
20 #if defined(OS_IOS) 20 #if defined(OS_IOS)
21 #include <sys/sysctl.h> 21 #include <mach/vm_page_size.h>
22 #endif 22 #endif
23 23
24 #if defined(OS_POSIX) 24 #if defined(OS_POSIX)
25 #include <sys/mman.h> 25 #include <sys/mman.h>
26 #endif 26 #endif
27 27
28 #if defined(OS_WIN) 28 #if defined(OS_WIN)
29 #include <Psapi.h> 29 #include <Psapi.h>
30 #endif 30 #endif
31 31
(...skipping 18 matching lines...) Expand all
50 } // namespace 50 } // namespace
51 51
52 // static 52 // static
53 bool ProcessMemoryDump::is_black_hole_non_fatal_for_testing_ = false; 53 bool ProcessMemoryDump::is_black_hole_non_fatal_for_testing_ = false;
54 54
55 #if defined(COUNT_RESIDENT_BYTES_SUPPORTED) 55 #if defined(COUNT_RESIDENT_BYTES_SUPPORTED)
56 // static 56 // static
57 size_t ProcessMemoryDump::GetSystemPageSize() { 57 size_t ProcessMemoryDump::GetSystemPageSize() {
58 #if defined(OS_IOS) 58 #if defined(OS_IOS)
59 // On iOS, getpagesize() returns the user page sizes, but for allocating 59 // On iOS, getpagesize() returns the user page sizes, but for allocating
60 // arrays for mincore(), kernel page sizes is needed. sysctlbyname() should 60 // arrays for mincore(), kernel page sizes is needed. Use vm_kernel_page_size
61 // be used for this. Refer to crbug.com/542671 and Apple rdar://23651782 61 // as recommended by Apple, https://forums.developer.apple.com/thread/47532/.
62 int pagesize; 62 // Refer to http://crbug.com/542671 and Apple rdar://23651782
63 size_t pagesize_len; 63 return vm_kernel_page_size;
64 int status = sysctlbyname("vm.pagesize", NULL, &pagesize_len, nullptr, 0); 64 #else
65 if (!status && pagesize_len == sizeof(pagesize)) { 65 return base::GetPageSize();
66 if (!sysctlbyname("vm.pagesize", &pagesize, &pagesize_len, nullptr, 0))
67 return pagesize;
68 }
69 LOG(ERROR) << "sysctlbyname(\"vm.pagesize\") failed.";
70 // Falls back to getpagesize() although it may be wrong in certain cases.
71 #endif // defined(OS_IOS) 66 #endif // defined(OS_IOS)
72 return base::GetPageSize();
Primiano Tucci (use gerrit) 2016/09/26 14:24:05 I liked this the old way, i.e. #if special case ..
sdefresne 2016/09/26 14:44:36 Won't this cause a warning by the compiler about u
73 } 67 }
74 68
75 // static 69 // static
76 size_t ProcessMemoryDump::CountResidentBytes(void* start_address, 70 size_t ProcessMemoryDump::CountResidentBytes(void* start_address,
77 size_t mapped_size) { 71 size_t mapped_size) {
78 const size_t page_size = GetSystemPageSize(); 72 const size_t page_size = GetSystemPageSize();
79 const uintptr_t start_pointer = reinterpret_cast<uintptr_t>(start_address); 73 const uintptr_t start_pointer = reinterpret_cast<uintptr_t>(start_address);
80 DCHECK_EQ(0u, start_pointer % page_size); 74 DCHECK_EQ(0u, start_pointer % page_size);
81 75
82 size_t offset = 0; 76 size_t offset = 0;
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 358
365 MemoryAllocatorDump* ProcessMemoryDump::GetBlackHoleMad() { 359 MemoryAllocatorDump* ProcessMemoryDump::GetBlackHoleMad() {
366 DCHECK(is_black_hole_non_fatal_for_testing_); 360 DCHECK(is_black_hole_non_fatal_for_testing_);
367 if (!black_hole_mad_) 361 if (!black_hole_mad_)
368 black_hole_mad_.reset(new MemoryAllocatorDump("discarded", this)); 362 black_hole_mad_.reset(new MemoryAllocatorDump("discarded", this));
369 return black_hole_mad_.get(); 363 return black_hole_mad_.get();
370 } 364 }
371 365
372 } // namespace trace_event 366 } // namespace trace_event
373 } // namespace base 367 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698