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: snapshot/win/process_snapshot_win.cc

Issue 1360863006: win: Add more memory regions to gathering of PEB (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@save-peb
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 | « snapshot/win/process_snapshot_win.h ('k') | 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 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_snapshot_win.h" 15 #include "snapshot/win/process_snapshot_win.h"
16 16
17 #include <algorithm>
18
17 #include "base/logging.h" 19 #include "base/logging.h"
18 #include "snapshot/win/module_snapshot_win.h" 20 #include "snapshot/win/module_snapshot_win.h"
19 #include "util/win/registration_protocol_win.h" 21 #include "util/win/registration_protocol_win.h"
20 #include "util/win/time.h" 22 #include "util/win/time.h"
21 23
22 namespace crashpad { 24 namespace crashpad {
23 25
24 ProcessSnapshotWin::ProcessSnapshotWin() 26 ProcessSnapshotWin::ProcessSnapshotWin()
25 : ProcessSnapshot(), 27 : ProcessSnapshot(),
26 system_(), 28 system_(),
(...skipping 14 matching lines...) Expand all
41 bool ProcessSnapshotWin::Initialize(HANDLE process, 43 bool ProcessSnapshotWin::Initialize(HANDLE process,
42 ProcessSuspensionState suspension_state) { 44 ProcessSuspensionState suspension_state) {
43 INITIALIZATION_STATE_SET_INITIALIZING(initialized_); 45 INITIALIZATION_STATE_SET_INITIALIZING(initialized_);
44 46
45 GetTimeOfDay(&snapshot_time_); 47 GetTimeOfDay(&snapshot_time_);
46 48
47 if (!process_reader_.Initialize(process, suspension_state)) 49 if (!process_reader_.Initialize(process, suspension_state))
48 return false; 50 return false;
49 51
50 system_.Initialize(&process_reader_); 52 system_.Initialize(&process_reader_);
51 WinVMAddress peb_address; 53
52 WinVMSize peb_size; 54 if (process_reader_.Is64Bit())
53 process_reader_.GetProcessInfo().Peb(&peb_address, &peb_size); 55 InitializePebData<process_types::internal::Traits64>();
54 peb_.Initialize(&process_reader_, peb_address, peb_size); 56 else
57 InitializePebData<process_types::internal::Traits32>();
55 58
56 InitializeThreads(); 59 InitializeThreads();
57 InitializeModules(); 60 InitializeModules();
58 61
59 INITIALIZATION_STATE_SET_VALID(initialized_); 62 INITIALIZATION_STATE_SET_VALID(initialized_);
60 return true; 63 return true;
61 } 64 }
62 65
63 bool ProcessSnapshotWin::InitializeException( 66 bool ProcessSnapshotWin::InitializeException(
64 WinVMAddress exception_information_address) { 67 WinVMAddress exception_information_address) {
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 return modules; 182 return modules;
180 } 183 }
181 184
182 const ExceptionSnapshot* ProcessSnapshotWin::Exception() const { 185 const ExceptionSnapshot* ProcessSnapshotWin::Exception() const {
183 return exception_.get(); 186 return exception_.get();
184 } 187 }
185 188
186 std::vector<const MemorySnapshot*> ProcessSnapshotWin::ExtraMemory() const { 189 std::vector<const MemorySnapshot*> ProcessSnapshotWin::ExtraMemory() const {
187 INITIALIZATION_STATE_DCHECK_VALID(initialized_); 190 INITIALIZATION_STATE_DCHECK_VALID(initialized_);
188 std::vector<const MemorySnapshot*> extra_memory; 191 std::vector<const MemorySnapshot*> extra_memory;
189 extra_memory.push_back(&peb_); 192 for (const auto& peb_memory : peb_memory_)
193 extra_memory.push_back(peb_memory);
190 return extra_memory; 194 return extra_memory;
191 } 195 }
192 196
193 void ProcessSnapshotWin::InitializeThreads() { 197 void ProcessSnapshotWin::InitializeThreads() {
194 const std::vector<ProcessReaderWin::Thread>& process_reader_threads = 198 const std::vector<ProcessReaderWin::Thread>& process_reader_threads =
195 process_reader_.Threads(); 199 process_reader_.Threads();
196 for (const ProcessReaderWin::Thread& process_reader_thread : 200 for (const ProcessReaderWin::Thread& process_reader_thread :
197 process_reader_threads) { 201 process_reader_threads) {
198 auto thread = make_scoped_ptr(new internal::ThreadSnapshotWin()); 202 auto thread = make_scoped_ptr(new internal::ThreadSnapshotWin());
199 if (thread->Initialize(&process_reader_, process_reader_thread)) { 203 if (thread->Initialize(&process_reader_, process_reader_thread)) {
200 threads_.push_back(thread.release()); 204 threads_.push_back(thread.release());
201 } 205 }
202 } 206 }
203 } 207 }
204 208
205 void ProcessSnapshotWin::InitializeModules() { 209 void ProcessSnapshotWin::InitializeModules() {
206 const std::vector<ProcessInfo::Module>& process_reader_modules = 210 const std::vector<ProcessInfo::Module>& process_reader_modules =
207 process_reader_.Modules(); 211 process_reader_.Modules();
208 for (const ProcessInfo::Module& process_reader_module : 212 for (const ProcessInfo::Module& process_reader_module :
209 process_reader_modules) { 213 process_reader_modules) {
210 auto module = make_scoped_ptr(new internal::ModuleSnapshotWin()); 214 auto module = make_scoped_ptr(new internal::ModuleSnapshotWin());
211 if (module->Initialize(&process_reader_, process_reader_module)) { 215 if (module->Initialize(&process_reader_, process_reader_module)) {
212 modules_.push_back(module.release()); 216 modules_.push_back(module.release());
213 } 217 }
214 } 218 }
215 } 219 }
216 220
221 template <class Traits>
222 void ProcessSnapshotWin::InitializePebData() {
223 WinVMAddress peb_address;
224 WinVMSize peb_size;
225 process_reader_.GetProcessInfo().Peb(&peb_address, &peb_size);
226 AddMemorySnapshot(peb_address, peb_size, &peb_memory_);
227
228 process_types::PEB<Traits> peb_data;
229 if (!process_reader_.ReadMemory(peb_address, peb_size, &peb_data)) {
230 LOG(ERROR) << "ReadMemory PEB";
231 return;
232 }
233
234 process_types::PEB_LDR_DATA<Traits> peb_ldr_data;
235 AddMemorySnapshot(
236 peb_data.Ldr, sizeof(peb_ldr_data), &peb_memory_);
237 if (!process_reader_.ReadMemory(
238 peb_data.Ldr, sizeof(peb_ldr_data), &peb_ldr_data)) {
239 LOG(ERROR) << "ReadMemory PEB_LDR_DATA";
240 return;
Mark Mentovai 2015/09/29 21:57:11 Don’t bail out here. You still might be able to sa
scottmg 2015/09/30 18:19:40 Done.
241 }
242
243 // Walk the LDR structure to retrieve its pointed-to data. We don't care too
Mark Mentovai 2015/09/29 21:57:10 Question: does MiniDumpWriteDump() collect these r
scottmg 2015/09/30 18:19:40 Doesn't look like MiniDumpWriteDump() grabs the LD
Mark Mentovai 2015/10/01 19:05:47 No real objection to including this, I’m just tryi
scottmg 2015/10/01 20:17:00 I'll include it for now then as it's nice to have
244 // much about this here as we have the data in other places already, but
245 // without it Windbg's `!peb` gets confused and won't dump other useful data
246 // in the PEB.
247 AddMemorySnapshotForLdrLIST_ENTRY(
Mark Mentovai 2015/09/29 21:57:11 I’ve got a new concern. A lot of the extra memory
scottmg 2015/09/30 18:19:40 Yeah, all good points. In general, I don't like h
Mark Mentovai 2015/10/01 19:05:47 scottmg wrote:
scottmg 2015/10/01 20:17:00 Good point. It's pretty localized at the moment, s
248 peb_ldr_data.InLoadOrderModuleList,
249 offsetof(process_types::LDR_DATA_TABLE_ENTRY<Traits>, InLoadOrderLinks),
250 &peb_memory_);
251 AddMemorySnapshotForLdrLIST_ENTRY(
252 peb_ldr_data.InMemoryOrderModuleList,
253 offsetof(process_types::LDR_DATA_TABLE_ENTRY<Traits>, InMemoryOrderLinks),
254 &peb_memory_);
255 AddMemorySnapshotForLdrLIST_ENTRY(
256 peb_ldr_data.InInitializationOrderModuleList,
257 offsetof(process_types::LDR_DATA_TABLE_ENTRY<Traits>,
258 InInitializationOrderLinks),
259 &peb_memory_);
260
261 process_types::RTL_USER_PROCESS_PARAMETERS<Traits> process_parameters;
262 if (!process_reader_.ReadMemory(peb_data.ProcessParameters,
263 sizeof(process_parameters),
264 &process_parameters)) {
265 LOG(ERROR) << "ReadMemory RTL_USER_PROCESS_PARAMETERS";
266 return;
267 }
268 AddMemorySnapshot(
269 peb_data.ProcessParameters, sizeof(process_parameters), &peb_memory_);
270
271 AddMemorySnapshotForUNICODE_STRING(
272 process_parameters.CurrentDirectory.DosPath, &peb_memory_);
273 AddMemorySnapshotForUNICODE_STRING(process_parameters.DllPath, &peb_memory_);
274 AddMemorySnapshotForUNICODE_STRING(process_parameters.ImagePathName,
275 &peb_memory_);
276 AddMemorySnapshotForUNICODE_STRING(process_parameters.CommandLine,
277 &peb_memory_);
278 AddMemorySnapshotForUNICODE_STRING(process_parameters.WindowTitle,
279 &peb_memory_);
280 AddMemorySnapshotForUNICODE_STRING(process_parameters.DesktopInfo,
281 &peb_memory_);
282 AddMemorySnapshotForUNICODE_STRING(process_parameters.ShellInfo,
283 &peb_memory_);
284 AddMemorySnapshotForUNICODE_STRING(process_parameters.RuntimeData,
285 &peb_memory_);
286 AddMemorySnapshot(
287 process_parameters.Environment,
288 DetermineSizeOfEnvironmentBlock(process_parameters.Environment),
289 &peb_memory_);
290 }
291
292 void ProcessSnapshotWin::AddMemorySnapshot(
293 WinVMAddress address,
294 WinVMSize size,
295 PointerVector<internal::MemorySnapshotWin>* into) {
296 if (size == 0)
297 return;
298 internal::MemorySnapshotWin* memory_snapshot =
299 new internal::MemorySnapshotWin();
300 memory_snapshot->Initialize(&process_reader_, address, size);
301 into->push_back(memory_snapshot);
302 }
303
304 template <class Traits>
305 void ProcessSnapshotWin::AddMemorySnapshotForUNICODE_STRING(
306 const process_types::UNICODE_STRING<Traits>& us,
307 PointerVector<internal::MemorySnapshotWin>* into) {
308 AddMemorySnapshot(us.Buffer, us.Length, into);
309 }
310
311 template <class Traits>
312 void ProcessSnapshotWin::AddMemorySnapshotForLdrLIST_ENTRY(
313 const process_types::LIST_ENTRY<Traits>& le, size_t offset_of_member,
314 PointerVector<internal::MemorySnapshotWin>* into) {
315 // Walk the doubly-linked list of entries, adding the list memory itself, as
316 // well as pointed-to strings.
317 Traits::Pointer last = le.Blink;
318 process_types::LDR_DATA_TABLE_ENTRY<Traits> entry;
319 Traits::Pointer cur = le.Flink;
320 for (;;) {
321 // |cur| is the pointer to LIST_ENTRY embedded in the LDR_DATA_TABLE_ENTRY.
322 // So we need to offset back to the beginning of the structure.
323 if (!process_reader_.ReadMemory(
324 cur - offset_of_member, sizeof(entry), &entry)) {
325 return;
326 }
327 AddMemorySnapshot(cur - offset_of_member, sizeof(entry), into);
328 AddMemorySnapshotForUNICODE_STRING(entry.FullDllName, into);
329 AddMemorySnapshotForUNICODE_STRING(entry.BaseDllName, into);
330
331 process_types::LIST_ENTRY<Traits>* links =
332 reinterpret_cast<process_types::LIST_ENTRY<Traits>*>(
333 reinterpret_cast<unsigned char*>(&entry) + offset_of_member);
334 cur = links->Flink;
335 if (cur == last)
336 break;
337 }
338 }
339
340 WinVMSize ProcessSnapshotWin::DetermineSizeOfEnvironmentBlock(
341 WinVMAddress start_of_environment_block) {
342 // http://blogs.msdn.com/b/oldnewthing/archive/2010/02/03/9957320.aspx On
343 // newer OSs there's no stated limit, but in practice grabbing 32k characters
344 // should be more than enough.
345 std::wstring env_block;
346 env_block.resize(32768);
347 WinVMSize bytes_read = process_reader_.ReadAvailableMemory(
348 start_of_environment_block,
349 env_block.size() * sizeof(env_block[0]),
350 &env_block[0]);
351 env_block.resize(
352 static_cast<unsigned int>(bytes_read / sizeof(env_block[0])));
353 const wchar_t terminator[] = { 0, 0 };
354 size_t at = env_block.find(std::wstring(terminator, arraysize(terminator)));
355 if (at != std::wstring::npos)
356 env_block.resize(at + arraysize(terminator));
357
358 return env_block.size() * sizeof(env_block[0]);
359 }
360
217 } // namespace crashpad 361 } // namespace crashpad
OLDNEW
« no previous file with comments | « snapshot/win/process_snapshot_win.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698