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 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 module.size = ldr_data_table_entry.SizeOfImage; | 246 module.size = ldr_data_table_entry.SizeOfImage; |
247 module.timestamp = ldr_data_table_entry.TimeDateStamp; | 247 module.timestamp = ldr_data_table_entry.TimeDateStamp; |
248 process_info->modules_.push_back(module); | 248 process_info->modules_.push_back(module); |
249 if (cur == last) | 249 if (cur == last) |
250 break; | 250 break; |
251 } | 251 } |
252 | 252 |
253 return true; | 253 return true; |
254 } | 254 } |
255 | 255 |
| 256 bool ReadMemoryInfo(HANDLE process, ProcessInfo* process_info) { |
| 257 DCHECK(process_info->memory_info_.empty()); |
| 258 |
| 259 SYSTEM_INFO system_info; |
| 260 GetSystemInfo(&system_info); |
| 261 const WinVMAddress min_address = |
| 262 reinterpret_cast<WinVMAddress>(system_info.lpMinimumApplicationAddress); |
| 263 const WinVMAddress max_address = |
| 264 reinterpret_cast<WinVMAddress>(system_info.lpMaximumApplicationAddress); |
| 265 MEMORY_BASIC_INFORMATION memory_basic_information; |
| 266 for (WinVMAddress address = min_address; address <= max_address; |
| 267 address += memory_basic_information.RegionSize) { |
| 268 size_t result = VirtualQueryEx(process, |
| 269 reinterpret_cast<void*>(address), |
| 270 &memory_basic_information, |
| 271 sizeof(memory_basic_information)); |
| 272 if (result == 0) { |
| 273 PLOG(ERROR) << "VirtualQueryEx"; |
| 274 return false; |
| 275 } |
| 276 |
| 277 process_info->memory_info_.push_back( |
| 278 ProcessInfo::MemoryInfo(memory_basic_information)); |
| 279 |
| 280 if (memory_basic_information.RegionSize == 0) { |
| 281 LOG(ERROR) << "RegionSize == 0"; |
| 282 return false; |
| 283 } |
| 284 } |
| 285 |
| 286 return true; |
| 287 } |
| 288 |
256 ProcessInfo::Module::Module() : name(), dll_base(0), size(0), timestamp() { | 289 ProcessInfo::Module::Module() : name(), dll_base(0), size(0), timestamp() { |
257 } | 290 } |
258 | 291 |
259 ProcessInfo::Module::~Module() { | 292 ProcessInfo::Module::~Module() { |
260 } | 293 } |
261 | 294 |
| 295 ProcessInfo::MemoryInfo::MemoryInfo(const MEMORY_BASIC_INFORMATION& mbi) |
| 296 : base_address(reinterpret_cast<WinVMAddress>(mbi.BaseAddress)), |
| 297 region_size(mbi.RegionSize), |
| 298 allocation_base(reinterpret_cast<WinVMAddress>(mbi.AllocationBase)), |
| 299 state(mbi.State), |
| 300 allocation_protect(mbi.AllocationProtect), |
| 301 protect(mbi.Protect), |
| 302 type(mbi.Type) { |
| 303 } |
| 304 |
| 305 ProcessInfo::MemoryInfo::~MemoryInfo() { |
| 306 } |
| 307 |
262 ProcessInfo::ProcessInfo() | 308 ProcessInfo::ProcessInfo() |
263 : process_id_(), | 309 : process_id_(), |
264 inherited_from_process_id_(), | 310 inherited_from_process_id_(), |
265 command_line_(), | 311 command_line_(), |
266 peb_address_(0), | 312 peb_address_(0), |
267 peb_size_(0), | 313 peb_size_(0), |
268 modules_(), | 314 modules_(), |
| 315 memory_info_(), |
269 is_64_bit_(false), | 316 is_64_bit_(false), |
270 is_wow64_(false), | 317 is_wow64_(false), |
271 initialized_() { | 318 initialized_() { |
272 } | 319 } |
273 | 320 |
274 ProcessInfo::~ProcessInfo() { | 321 ProcessInfo::~ProcessInfo() { |
275 } | 322 } |
276 | 323 |
277 bool ProcessInfo::Initialize(HANDLE process) { | 324 bool ProcessInfo::Initialize(HANDLE process) { |
278 INITIALIZATION_STATE_SET_INITIALIZING(initialized_); | 325 INITIALIZATION_STATE_SET_INITIALIZING(initialized_); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 | 360 |
314 result = is_64_bit_ ? ReadProcessData<process_types::internal::Traits64>( | 361 result = is_64_bit_ ? ReadProcessData<process_types::internal::Traits64>( |
315 process, peb_address_, this) | 362 process, peb_address_, this) |
316 : ReadProcessData<process_types::internal::Traits32>( | 363 : ReadProcessData<process_types::internal::Traits32>( |
317 process, peb_address_, this); | 364 process, peb_address_, this); |
318 if (!result) { | 365 if (!result) { |
319 LOG(ERROR) << "ReadProcessData failed"; | 366 LOG(ERROR) << "ReadProcessData failed"; |
320 return false; | 367 return false; |
321 } | 368 } |
322 | 369 |
| 370 if (!ReadMemoryInfo(process, this)) { |
| 371 LOG(ERROR) << "ReadMemoryInfo failed"; |
| 372 return false; |
| 373 } |
| 374 |
323 INITIALIZATION_STATE_SET_VALID(initialized_); | 375 INITIALIZATION_STATE_SET_VALID(initialized_); |
324 return true; | 376 return true; |
325 } | 377 } |
326 | 378 |
327 bool ProcessInfo::Is64Bit() const { | 379 bool ProcessInfo::Is64Bit() const { |
328 INITIALIZATION_STATE_DCHECK_VALID(initialized_); | 380 INITIALIZATION_STATE_DCHECK_VALID(initialized_); |
329 return is_64_bit_; | 381 return is_64_bit_; |
330 } | 382 } |
331 | 383 |
332 bool ProcessInfo::IsWow64() const { | 384 bool ProcessInfo::IsWow64() const { |
(...skipping 21 matching lines...) Expand all Loading... |
354 *peb_address = peb_address_; | 406 *peb_address = peb_address_; |
355 *peb_size = peb_size_; | 407 *peb_size = peb_size_; |
356 } | 408 } |
357 | 409 |
358 bool ProcessInfo::Modules(std::vector<Module>* modules) const { | 410 bool ProcessInfo::Modules(std::vector<Module>* modules) const { |
359 INITIALIZATION_STATE_DCHECK_VALID(initialized_); | 411 INITIALIZATION_STATE_DCHECK_VALID(initialized_); |
360 *modules = modules_; | 412 *modules = modules_; |
361 return true; | 413 return true; |
362 } | 414 } |
363 | 415 |
| 416 const std::vector<ProcessInfo::MemoryInfo>& ProcessInfo::MemoryInformation() |
| 417 const { |
| 418 return memory_info_; |
| 419 } |
| 420 |
364 } // namespace crashpad | 421 } // namespace crashpad |
OLD | NEW |