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, |
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 // See the License for the specific language governing permissions and | 12 // See the License for the specific language governing permissions and |
13 // limitations under the License. | 13 // limitations under the License. |
14 | 14 |
15 #include "snapshot/win/process_reader_win.h" | 15 #include "snapshot/win/process_reader_win.h" |
16 | 16 |
| 17 #include "base/numerics/safe_conversions.h" |
| 18 |
17 namespace crashpad { | 19 namespace crashpad { |
18 | 20 |
19 ProcessReaderWin::ProcessReaderWin() : process_info_(), initialized_() { | 21 ProcessReaderWin::ProcessReaderWin() |
| 22 : process_(INVALID_HANDLE_VALUE), |
| 23 process_info_(), |
| 24 modules_(), |
| 25 initialized_() { |
20 } | 26 } |
21 | 27 |
22 ProcessReaderWin::~ProcessReaderWin() { | 28 ProcessReaderWin::~ProcessReaderWin() { |
23 } | 29 } |
24 | 30 |
25 bool ProcessReaderWin::Initialize(HANDLE process) { | 31 bool ProcessReaderWin::Initialize(HANDLE process) { |
26 INITIALIZATION_STATE_SET_INITIALIZING(initialized_); | 32 INITIALIZATION_STATE_SET_INITIALIZING(initialized_); |
27 | 33 |
| 34 process_ = process; |
28 process_info_.Initialize(process); | 35 process_info_.Initialize(process); |
29 | 36 |
30 INITIALIZATION_STATE_SET_VALID(initialized_); | 37 INITIALIZATION_STATE_SET_VALID(initialized_); |
31 return true; | 38 return true; |
32 } | 39 } |
33 | 40 |
| 41 bool ProcessReaderWin::ReadMemory(WinVMAddress at, |
| 42 WinVMSize num_bytes, |
| 43 void* into) { |
| 44 SIZE_T bytes_read; |
| 45 if (!ReadProcessMemory(process_, |
| 46 reinterpret_cast<void*>(at), |
| 47 into, |
| 48 base::checked_cast<SIZE_T>(num_bytes), |
| 49 &bytes_read) || |
| 50 num_bytes != bytes_read) { |
| 51 PLOG(ERROR) << "ReadMemory at " << at << " of " << num_bytes << " failed"; |
| 52 return false; |
| 53 } |
| 54 return true; |
| 55 } |
| 56 |
| 57 const std::vector<ProcessInfo::Module>& ProcessReaderWin::Modules() { |
| 58 INITIALIZATION_STATE_DCHECK_VALID(initialized_); |
| 59 |
| 60 if (!process_info_.Modules(&modules_)) { |
| 61 LOG(ERROR) << "couldn't retrieve modules"; |
| 62 } |
| 63 |
| 64 return modules_; |
| 65 } |
| 66 |
34 } // namespace crashpad | 67 } // namespace crashpad |
OLD | NEW |