OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 The Crashpad Authors. All rights reserved. | |
2 // | |
3 // Licensed under the Apache License, Version 2.0 (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 | |
6 // | |
7 // http://www.apache.org/licenses/LICENSE-2.0 | |
8 // | |
9 // Unless required by applicable law or agreed to in writing, software | |
10 // distributed under the License is distributed on an "AS IS" BASIS, | |
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
12 // See the License for the specific language governing permissions and | |
13 // limitations under the License. | |
14 | |
15 #include "snapshot/win/exception_snapshot_win.h" | |
16 | |
17 #include "snapshot/win/cpu_context_win.h" | |
18 #include "snapshot/win/process_reader_win.h" | |
19 #include "util/win/nt_internals.h" | |
20 #include "util/win/process_structs.h" | |
21 | |
22 namespace crashpad { | |
23 namespace internal { | |
24 | |
25 namespace { | |
26 | |
27 // ::GetThreadId is not available on XP, so get the thread id via | |
28 // NtQueryInformationThread. | |
29 template <class Traits> | |
30 uint64_t GetThreadId(HANDLE handle) { | |
Mark Mentovai
2015/08/18 16:17:19
Can you add a test for this that makes sure that i
scottmg
2015/08/18 16:56:00
Removed.
| |
31 process_types::THREAD_BASIC_INFORMATION<Traits> basic_information; | |
32 if (!NT_SUCCESS(crashpad::NtQueryInformationThread( | |
33 handle, | |
34 static_cast<THREADINFOCLASS>(ThreadBasicInformation), | |
35 &basic_information, | |
36 sizeof(basic_information), | |
37 nullptr))) { | |
38 LOG(ERROR) << "could not retrieve ThreadBasicInformation"; | |
Mark Mentovai
2015/08/18 16:17:19
This and a couple of other things we have would be
scottmg
2015/08/18 16:56:00
Removed.
| |
39 return 0; | |
40 } | |
41 return basic_information.ClientId.UniqueThread; | |
Mark Mentovai
2015/08/18 16:17:19
This is declared in our structs as a Pointer, but
scottmg
2015/08/18 16:56:00
Removed.
| |
42 } | |
43 | |
44 uint64_t GetThreadId(ProcessReaderWin* process_reader, HANDLE handle) { | |
Mark Mentovai
2015/08/18 16:17:19
Now I feel duped. This doesn’t seem to be called b
scottmg
2015/08/18 16:56:00
Oops, sorry. I previously had the thread HANDLE be
| |
45 if (process_reader->Is64Bit()) | |
46 return GetThreadId<process_types::internal::Traits64>(handle); | |
47 else | |
48 return GetThreadId<process_types::internal::Traits32>(handle); | |
49 } | |
50 | |
51 } // namespace | |
52 | |
53 ExceptionSnapshotWin::ExceptionSnapshotWin() | |
54 : ExceptionSnapshot(), | |
55 context_union_(), | |
56 context_(), | |
57 codes_(), | |
58 thread_id_(0), | |
59 exception_address_(0), | |
60 exception_flags_(0), | |
61 exception_code_(0), | |
62 initialized_() { | |
63 } | |
64 | |
65 ExceptionSnapshotWin::~ExceptionSnapshotWin() { | |
66 } | |
67 | |
68 bool ExceptionSnapshotWin::Initialize(ProcessReaderWin* process_reader, | |
69 DWORD thread_id, | |
70 WinVMAddress exception_pointers_address) { | |
71 INITIALIZATION_STATE_SET_INITIALIZING(initialized_); | |
72 | |
73 bool found_thread = false; | |
74 for (const auto& loop_thread : process_reader->Threads()) { | |
75 if (thread_id == loop_thread.id) { | |
76 found_thread = true; | |
77 break; | |
78 } | |
79 } | |
80 | |
81 if (!found_thread) { | |
82 LOG(ERROR) << "thread id not found in process"; | |
Mark Mentovai
2015/08/18 16:17:19
Spew out the problem ID here?
scottmg
2015/08/18 16:56:00
Done.
| |
83 return false; | |
84 } else { | |
85 thread_id_ = thread_id; | |
86 } | |
87 | |
88 EXCEPTION_POINTERS exception_pointers; | |
89 if (!process_reader->ReadMemory(exception_pointers_address, | |
90 sizeof(EXCEPTION_POINTERS), | |
91 &exception_pointers)) { | |
92 LOG(ERROR) << "EXCEPTION_POINTERS read failed"; | |
93 return false; | |
94 } | |
95 if (!exception_pointers.ExceptionRecord) { | |
96 LOG(ERROR) << "null ExceptionRecord"; | |
97 return false; | |
98 } | |
99 | |
100 if (process_reader->Is64Bit()) { | |
101 EXCEPTION_RECORD64 first_record; | |
102 if (!process_reader->ReadMemory( | |
103 reinterpret_cast<WinVMAddress>(exception_pointers.ExceptionRecord), | |
104 sizeof(first_record), | |
105 &first_record)) { | |
106 LOG(ERROR) << "ExceptionRecord"; | |
107 return false; | |
108 } | |
109 exception_code_ = first_record.ExceptionCode; | |
110 exception_flags_ = first_record.ExceptionFlags; | |
111 exception_address_ = first_record.ExceptionAddress; | |
112 for (DWORD i = 0; i < first_record.NumberParameters; ++i) | |
113 codes_.push_back(first_record.ExceptionInformation[i]); | |
114 if (first_record.ExceptionRecord) | |
115 LOG(WARNING) << "dropping chained ExceptionRecord"; | |
116 | |
117 context_.architecture = kCPUArchitectureX86_64; | |
118 context_.x86_64 = &context_union_.x86_64; | |
119 // We assume 64-on-64 here in that we're relying on the CONTEXT definition | |
120 // to be the x64 one. | |
121 CONTEXT context_record; | |
122 if (!process_reader->ReadMemory( | |
123 reinterpret_cast<WinVMAddress>(exception_pointers.ContextRecord), | |
124 sizeof(context_record), | |
125 &context_record)) { | |
126 LOG(ERROR) << "ContextRecord"; | |
127 return false; | |
128 } | |
129 InitializeX64Context(context_record, context_.x86_64); | |
130 } else { | |
131 CHECK(false) << "TODO(scottmg) x86"; | |
132 return false; | |
133 } | |
134 | |
135 INITIALIZATION_STATE_SET_VALID(initialized_); | |
136 return true; | |
137 } | |
138 | |
139 const CPUContext* ExceptionSnapshotWin::Context() const { | |
140 INITIALIZATION_STATE_DCHECK_VALID(initialized_); | |
141 return &context_; | |
142 } | |
143 | |
144 uint64_t ExceptionSnapshotWin::ThreadID() const { | |
145 INITIALIZATION_STATE_DCHECK_VALID(initialized_); | |
146 return thread_id_; | |
147 } | |
148 | |
149 uint32_t ExceptionSnapshotWin::Exception() const { | |
150 INITIALIZATION_STATE_DCHECK_VALID(initialized_); | |
151 return exception_code_; | |
152 } | |
153 | |
154 uint32_t ExceptionSnapshotWin::ExceptionInfo() const { | |
155 INITIALIZATION_STATE_DCHECK_VALID(initialized_); | |
156 return exception_flags_; | |
157 } | |
158 | |
159 uint64_t ExceptionSnapshotWin::ExceptionAddress() const { | |
160 INITIALIZATION_STATE_DCHECK_VALID(initialized_); | |
161 return exception_address_; | |
162 } | |
163 | |
164 const std::vector<uint64_t>& ExceptionSnapshotWin::Codes() const { | |
165 INITIALIZATION_STATE_DCHECK_VALID(initialized_); | |
166 return codes_; | |
167 } | |
168 | |
169 } // namespace internal | |
170 } // namespace crashpad | |
OLD | NEW |