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

Side by Side Diff: snapshot/win/process_reader_win.cc

Issue 1126413008: win: Implement exception snapshot (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: fixes2 Created 5 years, 4 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/exception_snapshot_win_test.cc ('k') | snapshot/win/process_snapshot_win.h » ('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,
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 <winternl.h> 17 #include <winternl.h>
18 18
19 #include "base/memory/scoped_ptr.h" 19 #include "base/memory/scoped_ptr.h"
20 #include "base/numerics/safe_conversions.h" 20 #include "base/numerics/safe_conversions.h"
21 #include "util/win/nt_internals.h"
21 #include "util/win/process_structs.h" 22 #include "util/win/process_structs.h"
22 #include "util/win/scoped_handle.h" 23 #include "util/win/scoped_handle.h"
23 #include "util/win/time.h" 24 #include "util/win/time.h"
24 25
25 namespace crashpad { 26 namespace crashpad {
26 27
27 namespace { 28 namespace {
28 29
29 NTSTATUS NtQuerySystemInformation(
30 SYSTEM_INFORMATION_CLASS system_information_class,
31 PVOID system_information,
32 ULONG system_information_length,
33 PULONG return_length) {
34 static decltype(::NtQuerySystemInformation)* nt_query_system_information =
35 reinterpret_cast<decltype(::NtQuerySystemInformation)*>(GetProcAddress(
36 LoadLibrary(L"ntdll.dll"), "NtQuerySystemInformation"));
37 DCHECK(nt_query_system_information);
38 return nt_query_system_information(system_information_class,
39 system_information,
40 system_information_length,
41 return_length);
42 }
43
44 // The 4th argument is CLIENT_ID*, but as we can't typedef that, we simply cast
45 // to void* here.
46 typedef NTSTATUS(WINAPI* NtOpenThreadFunction)(
47 PHANDLE ThreadHandle,
48 ACCESS_MASK DesiredAccess,
49 POBJECT_ATTRIBUTES ObjectAttributes,
50 const void* ClientId);
51
52 template <class Traits>
53 NTSTATUS NtOpenThread(PHANDLE thread_handle,
54 ACCESS_MASK desired_access,
55 POBJECT_ATTRIBUTES object_attributes,
56 const process_types::CLIENT_ID<Traits>* client_id) {
57 static NtOpenThreadFunction nt_open_thread =
58 reinterpret_cast<NtOpenThreadFunction>(
59 GetProcAddress(LoadLibrary(L"ntdll.dll"), "NtOpenThread"));
60 DCHECK(nt_open_thread);
61 return nt_open_thread(thread_handle,
62 desired_access,
63 object_attributes,
64 static_cast<const void*>(client_id));
65 }
66
67 // Copied from ntstatus.h because um/winnt.h conflicts with general inclusion of
68 // ntstatus.h.
69 #define STATUS_BUFFER_TOO_SMALL ((NTSTATUS)0xC0000023L)
70 #define STATUS_INFO_LENGTH_MISMATCH ((NTSTATUS)0xC0000004L)
71
72 // Gets a pointer to the process information structure after a given one, or 30 // Gets a pointer to the process information structure after a given one, or
73 // null when iteration is complete, assuming they've been retrieved in a block 31 // null when iteration is complete, assuming they've been retrieved in a block
74 // via NtQuerySystemInformation(). 32 // via NtQuerySystemInformation().
75 template <class Traits> 33 template <class Traits>
76 process_types::SYSTEM_PROCESS_INFORMATION<Traits>* NextProcess( 34 process_types::SYSTEM_PROCESS_INFORMATION<Traits>* NextProcess(
77 process_types::SYSTEM_PROCESS_INFORMATION<Traits>* process) { 35 process_types::SYSTEM_PROCESS_INFORMATION<Traits>* process) {
78 ULONG offset = process->NextEntryOffset; 36 ULONG offset = process->NextEntryOffset;
79 if (offset == 0) 37 if (offset == 0)
80 return nullptr; 38 return nullptr;
81 return reinterpret_cast<process_types::SYSTEM_PROCESS_INFORMATION<Traits>*>( 39 return reinterpret_cast<process_types::SYSTEM_PROCESS_INFORMATION<Traits>*>(
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 INITIALIZATION_STATE_DCHECK_VALID(initialized_); 287 INITIALIZATION_STATE_DCHECK_VALID(initialized_);
330 288
331 if (!process_info_.Modules(&modules_)) { 289 if (!process_info_.Modules(&modules_)) {
332 LOG(ERROR) << "couldn't retrieve modules"; 290 LOG(ERROR) << "couldn't retrieve modules";
333 } 291 }
334 292
335 return modules_; 293 return modules_;
336 } 294 }
337 295
338 } // namespace crashpad 296 } // namespace crashpad
OLDNEW
« no previous file with comments | « snapshot/win/exception_snapshot_win_test.cc ('k') | snapshot/win/process_snapshot_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698