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

Side by Side Diff: util/win/process_info.cc

Issue 1370063005: MEM_RESERVE regions are not accessible by ReadProcessMemory() (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: . Created 5 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 | util/win/process_info_test.cc » ('j') | 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 Crashpad Authors. All rights reserved. 1 // Copyright 2015 The Crashpad Authors. All rights reserved.
2 // 2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License. 4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at 5 // You may obtain a copy of the License at
6 // 6 //
7 // http://www.apache.org/licenses/LICENSE-2.0 7 // http://www.apache.org/licenses/LICENSE-2.0
8 // 8 //
9 // Unless required by applicable law or agreed to in writing, software 9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, 10 // distributed under the License is distributed on an "AS IS" BASIS,
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 PLOG(ERROR) << "ReadProcessMemory " << __FUNCSIG__; 100 PLOG(ERROR) << "ReadProcessMemory " << __FUNCSIG__;
101 return false; 101 return false;
102 } 102 }
103 if (bytes_read != sizeof(T)) { 103 if (bytes_read != sizeof(T)) {
104 LOG(ERROR) << "ReadProcessMemory " << __FUNCSIG__ << " incorrect size"; 104 LOG(ERROR) << "ReadProcessMemory " << __FUNCSIG__ << " incorrect size";
105 return false; 105 return false;
106 } 106 }
107 return true; 107 return true;
108 } 108 }
109 109
110 bool RegionIsInaccessible(const ProcessInfo::MemoryInfo& memory_info) { 110 bool RegionIsAccessible(const ProcessInfo::MemoryInfo& memory_info) {
111 return memory_info.state == MEM_FREE || 111 return memory_info.state == MEM_COMMIT &&
112 (memory_info.state == MEM_COMMIT && 112 (memory_info.protect & PAGE_NOACCESS) == 0 &&
113 ((memory_info.protect & PAGE_NOACCESS) || 113 (memory_info.protect & PAGE_GUARD) == 0;
114 (memory_info.protect & PAGE_GUARD)));
115 } 114 }
116 115
117 } // namespace 116 } // namespace
118 117
119 template <class Traits> 118 template <class Traits>
120 bool GetProcessBasicInformation(HANDLE process, 119 bool GetProcessBasicInformation(HANDLE process,
121 bool is_wow64, 120 bool is_wow64,
122 ProcessInfo* process_info, 121 ProcessInfo* process_info,
123 WinVMAddress* peb_address, 122 WinVMAddress* peb_address,
124 WinVMSize* peb_size) { 123 WinVMSize* peb_size) {
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 (original_front_base_address + front.region_size) - front.base_address; 460 (original_front_base_address + front.region_size) - front.base_address;
462 461
463 ProcessInfo::MemoryInfo& back = overlapping.back(); 462 ProcessInfo::MemoryInfo& back = overlapping.back();
464 WinVMAddress back_end = back.base_address + back.region_size; 463 WinVMAddress back_end = back.base_address + back.region_size;
465 back.region_size = std::min(range.end(), back_end) - back.base_address; 464 back.region_size = std::min(range.end(), back_end) - back.base_address;
466 465
467 // Discard all non-accessible. 466 // Discard all non-accessible.
468 overlapping.erase(std::remove_if(overlapping.begin(), 467 overlapping.erase(std::remove_if(overlapping.begin(),
469 overlapping.end(), 468 overlapping.end(),
470 [](const ProcessInfo::MemoryInfo& mi) { 469 [](const ProcessInfo::MemoryInfo& mi) {
471 return RegionIsInaccessible(mi); 470 return !RegionIsAccessible(mi);
472 }), 471 }),
473 overlapping.end()); 472 overlapping.end());
474 if (overlapping.empty()) 473 if (overlapping.empty())
475 return std::vector<Range>(); 474 return std::vector<Range>();
476 475
477 // Convert to return type. 476 // Convert to return type.
478 std::vector<Range> as_ranges; 477 std::vector<Range> as_ranges;
479 for (const auto& mi : overlapping) { 478 for (const auto& mi : overlapping) {
480 as_ranges.push_back(Range(mi.base_address, mi.region_size)); 479 as_ranges.push_back(Range(mi.base_address, mi.region_size));
481 DCHECK(as_ranges.back().IsValid()); 480 DCHECK(as_ranges.back().IsValid());
482 } 481 }
483 482
484 // Coalesce remaining regions. 483 // Coalesce remaining regions.
485 std::vector<Range> result; 484 std::vector<Range> result;
486 result.push_back(as_ranges[0]); 485 result.push_back(as_ranges[0]);
487 for (size_t i = 1; i < as_ranges.size(); ++i) { 486 for (size_t i = 1; i < as_ranges.size(); ++i) {
488 if (result.back().end() == as_ranges[i].base()) { 487 if (result.back().end() == as_ranges[i].base()) {
489 result.back().SetRange(result.back().base(), 488 result.back().SetRange(result.back().base(),
490 result.back().size() + as_ranges[i].size()); 489 result.back().size() + as_ranges[i].size());
491 } else { 490 } else {
492 result.push_back(as_ranges[i]); 491 result.push_back(as_ranges[i]);
493 } 492 }
494 DCHECK(result.back().IsValid()); 493 DCHECK(result.back().IsValid());
495 } 494 }
496 495
497 return result; 496 return result;
498 } 497 }
499 498
500 } // namespace crashpad 499 } // namespace crashpad
OLDNEW
« no previous file with comments | « no previous file | util/win/process_info_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698