Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 97 PLOG(ERROR) << "ReadProcessMemory " << __FUNCSIG__; | 97 PLOG(ERROR) << "ReadProcessMemory " << __FUNCSIG__; |
| 98 return false; | 98 return false; |
| 99 } | 99 } |
| 100 if (bytes_read != sizeof(T)) { | 100 if (bytes_read != sizeof(T)) { |
| 101 LOG(ERROR) << "ReadProcessMemory " << __FUNCSIG__ << " incorrect size"; | 101 LOG(ERROR) << "ReadProcessMemory " << __FUNCSIG__ << " incorrect size"; |
| 102 return false; | 102 return false; |
| 103 } | 103 } |
| 104 return true; | 104 return true; |
| 105 } | 105 } |
| 106 | 106 |
| 107 // Map from Traits to an MEMORY_BASIC_INFORMATIIONxx. | |
| 108 template <class Traits> | |
| 109 struct MemoryBasicInformationForTraits; | |
| 110 | |
| 111 template <> | |
| 112 struct MemoryBasicInformationForTraits<process_types::internal::Traits32> { | |
| 113 using type = MEMORY_BASIC_INFORMATION32; | |
| 114 }; | |
| 115 | |
| 116 template <> | |
| 117 struct MemoryBasicInformationForTraits<process_types::internal::Traits64> { | |
| 118 using type = MEMORY_BASIC_INFORMATION64; | |
| 119 }; | |
| 120 | |
| 107 } // namespace | 121 } // namespace |
| 108 | 122 |
| 109 template <class Traits> | 123 template <class Traits> |
| 110 bool GetProcessBasicInformation(HANDLE process, | 124 bool GetProcessBasicInformation(HANDLE process, |
| 111 bool is_wow64, | 125 bool is_wow64, |
| 112 ProcessInfo* process_info, | 126 ProcessInfo* process_info, |
| 113 WinVMAddress* peb_address, | 127 WinVMAddress* peb_address, |
| 114 WinVMSize* peb_size) { | 128 WinVMSize* peb_size) { |
| 115 ULONG bytes_returned; | 129 ULONG bytes_returned; |
| 116 process_types::PROCESS_BASIC_INFORMATION<Traits> process_basic_information; | 130 process_types::PROCESS_BASIC_INFORMATION<Traits> process_basic_information; |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 246 module.size = ldr_data_table_entry.SizeOfImage; | 260 module.size = ldr_data_table_entry.SizeOfImage; |
| 247 module.timestamp = ldr_data_table_entry.TimeDateStamp; | 261 module.timestamp = ldr_data_table_entry.TimeDateStamp; |
| 248 process_info->modules_.push_back(module); | 262 process_info->modules_.push_back(module); |
| 249 if (cur == last) | 263 if (cur == last) |
| 250 break; | 264 break; |
| 251 } | 265 } |
| 252 | 266 |
| 253 return true; | 267 return true; |
| 254 } | 268 } |
| 255 | 269 |
| 270 template <class Traits> | |
| 271 bool ReadMemoryInfo(HANDLE process, ProcessInfo* process_info) { | |
| 272 DCHECK(process_info->memory_info_.empty()); | |
| 273 | |
| 274 SYSTEM_INFO system_info; | |
| 275 GetSystemInfo(&system_info); | |
| 276 uint64_t min_address = | |
|
Mark Mentovai
2015/09/26 02:02:14
const WinVMAddress?
scottmg
2015/09/26 03:12:36
Done.
| |
| 277 reinterpret_cast<uint64_t>(system_info.lpMinimumApplicationAddress); | |
| 278 uint64_t max_address = | |
| 279 reinterpret_cast<uint64_t>(system_info.lpMaximumApplicationAddress); | |
|
Mark Mentovai
2015/09/26 02:02:14
Is this correct for 64-reads-32-on-64?
scottmg
2015/09/26 03:12:36
Hmm, good point, that's tricky. After playing arou
| |
| 280 uint64_t address = min_address; | |
| 281 while (address <= max_address) { | |
|
Mark Mentovai
2015/09/26 02:02:14
for (WinVMAddress address = min_address; address <
scottmg
2015/09/26 03:12:36
Done.
| |
| 282 MemoryBasicInformationForTraits<Traits>::type memory_basic_information; | |
| 283 size_t result = VirtualQueryEx( | |
| 284 process, | |
| 285 reinterpret_cast<void*>(address), | |
| 286 reinterpret_cast<MEMORY_BASIC_INFORMATION*>(&memory_basic_information), | |
| 287 sizeof(memory_basic_information)); | |
| 288 if (result == 0) { | |
| 289 PLOG(ERROR) << "VirtualQueryEx"; | |
| 290 return false; | |
| 291 } | |
| 292 | |
| 293 process_info->memory_info_.push_back( | |
| 294 ProcessInfo::MemoryInfo(memory_basic_information)); | |
| 295 | |
| 296 address += memory_basic_information.RegionSize; | |
|
Mark Mentovai
2015/09/26 02:02:14
DCHECK_GT(RegionSize, 0);
so that a very busted m
scottmg
2015/09/26 03:12:36
Done. (if with LOG rather than DCHECK)
| |
| 297 } | |
| 298 | |
| 299 return true; | |
| 300 } | |
| 301 | |
| 256 ProcessInfo::Module::Module() : name(), dll_base(0), size(0), timestamp() { | 302 ProcessInfo::Module::Module() : name(), dll_base(0), size(0), timestamp() { |
| 257 } | 303 } |
| 258 | 304 |
| 259 ProcessInfo::Module::~Module() { | 305 ProcessInfo::Module::~Module() { |
| 260 } | 306 } |
| 261 | 307 |
| 308 ProcessInfo::MemoryInfo::MemoryInfo() | |
| 309 : base_address(0), | |
| 310 region_size(0), | |
| 311 allocation_base(0), | |
| 312 state(0), | |
| 313 allocation_protect(0), | |
| 314 protect(0), | |
| 315 type(0) { | |
| 316 } | |
| 317 | |
| 318 template <class MBI> | |
| 319 ProcessInfo::MemoryInfo::MemoryInfo(const MBI& mbi) | |
| 320 : base_address(mbi.BaseAddress), | |
| 321 region_size(mbi.RegionSize), | |
| 322 allocation_base(mbi.AllocationBase), | |
| 323 state(mbi.State), | |
| 324 allocation_protect(mbi.AllocationProtect), | |
| 325 protect(mbi.Protect), | |
| 326 type(mbi.Type) { | |
| 327 } | |
| 328 | |
| 329 ProcessInfo::MemoryInfo::~MemoryInfo() { | |
| 330 } | |
| 331 | |
| 262 ProcessInfo::ProcessInfo() | 332 ProcessInfo::ProcessInfo() |
| 263 : process_id_(), | 333 : process_id_(), |
| 264 inherited_from_process_id_(), | 334 inherited_from_process_id_(), |
| 265 command_line_(), | 335 command_line_(), |
| 266 peb_address_(0), | 336 peb_address_(0), |
| 267 peb_size_(0), | 337 peb_size_(0), |
| 268 modules_(), | 338 modules_(), |
| 339 memory_info_(), | |
| 269 is_64_bit_(false), | 340 is_64_bit_(false), |
| 270 is_wow64_(false), | 341 is_wow64_(false), |
| 271 initialized_() { | 342 initialized_() { |
| 272 } | 343 } |
| 273 | 344 |
| 274 ProcessInfo::~ProcessInfo() { | 345 ProcessInfo::~ProcessInfo() { |
| 275 } | 346 } |
| 276 | 347 |
| 277 bool ProcessInfo::Initialize(HANDLE process) { | 348 bool ProcessInfo::Initialize(HANDLE process) { |
| 278 INITIALIZATION_STATE_SET_INITIALIZING(initialized_); | 349 INITIALIZATION_STATE_SET_INITIALIZING(initialized_); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 313 | 384 |
| 314 result = is_64_bit_ ? ReadProcessData<process_types::internal::Traits64>( | 385 result = is_64_bit_ ? ReadProcessData<process_types::internal::Traits64>( |
| 315 process, peb_address_, this) | 386 process, peb_address_, this) |
| 316 : ReadProcessData<process_types::internal::Traits32>( | 387 : ReadProcessData<process_types::internal::Traits32>( |
| 317 process, peb_address_, this); | 388 process, peb_address_, this); |
| 318 if (!result) { | 389 if (!result) { |
| 319 LOG(ERROR) << "ReadProcessData failed"; | 390 LOG(ERROR) << "ReadProcessData failed"; |
| 320 return false; | 391 return false; |
| 321 } | 392 } |
| 322 | 393 |
| 394 result = | |
| 395 is_64_bit_ | |
| 396 ? ReadMemoryInfo<process_types::internal::Traits64>(process, this) | |
| 397 : ReadMemoryInfo<process_types::internal::Traits32>(process, this); | |
| 398 if (!result) { | |
| 399 LOG(ERROR) << "ReadMemoryInfo failed"; | |
| 400 return false; | |
| 401 } | |
| 402 | |
| 323 INITIALIZATION_STATE_SET_VALID(initialized_); | 403 INITIALIZATION_STATE_SET_VALID(initialized_); |
| 324 return true; | 404 return true; |
| 325 } | 405 } |
| 326 | 406 |
| 327 bool ProcessInfo::Is64Bit() const { | 407 bool ProcessInfo::Is64Bit() const { |
| 328 INITIALIZATION_STATE_DCHECK_VALID(initialized_); | 408 INITIALIZATION_STATE_DCHECK_VALID(initialized_); |
| 329 return is_64_bit_; | 409 return is_64_bit_; |
| 330 } | 410 } |
| 331 | 411 |
| 332 bool ProcessInfo::IsWow64() const { | 412 bool ProcessInfo::IsWow64() const { |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 354 *peb_address = peb_address_; | 434 *peb_address = peb_address_; |
| 355 *peb_size = peb_size_; | 435 *peb_size = peb_size_; |
| 356 } | 436 } |
| 357 | 437 |
| 358 bool ProcessInfo::Modules(std::vector<Module>* modules) const { | 438 bool ProcessInfo::Modules(std::vector<Module>* modules) const { |
| 359 INITIALIZATION_STATE_DCHECK_VALID(initialized_); | 439 INITIALIZATION_STATE_DCHECK_VALID(initialized_); |
| 360 *modules = modules_; | 440 *modules = modules_; |
| 361 return true; | 441 return true; |
| 362 } | 442 } |
| 363 | 443 |
| 444 const std::vector<ProcessInfo::MemoryInfo>& ProcessInfo::MemoryInformation() | |
| 445 const { | |
| 446 return memory_info_; | |
| 447 } | |
| 448 | |
| 364 } // namespace crashpad | 449 } // namespace crashpad |
| OLD | NEW |