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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 sizeof(EXCEPTION_POINTERS), | 62 sizeof(EXCEPTION_POINTERS), |
63 &exception_pointers)) { | 63 &exception_pointers)) { |
64 LOG(ERROR) << "EXCEPTION_POINTERS read failed"; | 64 LOG(ERROR) << "EXCEPTION_POINTERS read failed"; |
65 return false; | 65 return false; |
66 } | 66 } |
67 if (!exception_pointers.ExceptionRecord) { | 67 if (!exception_pointers.ExceptionRecord) { |
68 LOG(ERROR) << "null ExceptionRecord"; | 68 LOG(ERROR) << "null ExceptionRecord"; |
69 return false; | 69 return false; |
70 } | 70 } |
71 | 71 |
| 72 #if defined(ARCH_CPU_64_BITS) |
72 if (process_reader->Is64Bit()) { | 73 if (process_reader->Is64Bit()) { |
73 EXCEPTION_RECORD64 first_record; | 74 CONTEXT context_record; |
74 if (!process_reader->ReadMemory( | 75 if (!InitializeFromExceptionPointers<EXCEPTION_RECORD64>( |
75 reinterpret_cast<WinVMAddress>(exception_pointers.ExceptionRecord), | 76 *process_reader, exception_pointers, &context_record)) { |
76 sizeof(first_record), | |
77 &first_record)) { | |
78 LOG(ERROR) << "ExceptionRecord"; | |
79 return false; | 77 return false; |
80 } | 78 } |
81 exception_code_ = first_record.ExceptionCode; | |
82 exception_flags_ = first_record.ExceptionFlags; | |
83 exception_address_ = first_record.ExceptionAddress; | |
84 for (DWORD i = 0; i < first_record.NumberParameters; ++i) | |
85 codes_.push_back(first_record.ExceptionInformation[i]); | |
86 if (first_record.ExceptionRecord) { | |
87 // https://code.google.com/p/crashpad/issues/detail?id=43 | |
88 LOG(WARNING) << "dropping chained ExceptionRecord"; | |
89 } | |
90 | |
91 context_.architecture = kCPUArchitectureX86_64; | 79 context_.architecture = kCPUArchitectureX86_64; |
92 context_.x86_64 = &context_union_.x86_64; | 80 context_.x86_64 = &context_union_.x86_64; |
93 // We assume 64-on-64 here in that we're relying on the CONTEXT definition | |
94 // to be the x64 one. | |
95 CONTEXT context_record; | |
96 if (!process_reader->ReadMemory( | |
97 reinterpret_cast<WinVMAddress>(exception_pointers.ContextRecord), | |
98 sizeof(context_record), | |
99 &context_record)) { | |
100 LOG(ERROR) << "ContextRecord"; | |
101 return false; | |
102 } | |
103 InitializeX64Context(context_record, context_.x86_64); | 81 InitializeX64Context(context_record, context_.x86_64); |
104 } else { | 82 } else { |
105 CHECK(false) << "TODO(scottmg) x86"; | 83 CHECK(false) << "TODO(scottmg) WOW64"; |
106 return false; | 84 return false; |
107 } | 85 } |
| 86 #else |
| 87 CONTEXT context_record; |
| 88 if (!InitializeFromExceptionPointers<EXCEPTION_RECORD32>( |
| 89 *process_reader, exception_pointers, &context_record)) { |
| 90 return false; |
| 91 } |
| 92 context_.architecture = kCPUArchitectureX86; |
| 93 context_.x86 = &context_union_.x86; |
| 94 InitializeX86Context(context_record, context_.x86); |
| 95 #endif // ARCH_CPU_64_BITS |
108 | 96 |
109 INITIALIZATION_STATE_SET_VALID(initialized_); | 97 INITIALIZATION_STATE_SET_VALID(initialized_); |
110 return true; | 98 return true; |
111 } | 99 } |
112 | 100 |
113 const CPUContext* ExceptionSnapshotWin::Context() const { | 101 const CPUContext* ExceptionSnapshotWin::Context() const { |
114 INITIALIZATION_STATE_DCHECK_VALID(initialized_); | 102 INITIALIZATION_STATE_DCHECK_VALID(initialized_); |
115 return &context_; | 103 return &context_; |
116 } | 104 } |
117 | 105 |
(...skipping 15 matching lines...) Expand all Loading... |
133 uint64_t ExceptionSnapshotWin::ExceptionAddress() const { | 121 uint64_t ExceptionSnapshotWin::ExceptionAddress() const { |
134 INITIALIZATION_STATE_DCHECK_VALID(initialized_); | 122 INITIALIZATION_STATE_DCHECK_VALID(initialized_); |
135 return exception_address_; | 123 return exception_address_; |
136 } | 124 } |
137 | 125 |
138 const std::vector<uint64_t>& ExceptionSnapshotWin::Codes() const { | 126 const std::vector<uint64_t>& ExceptionSnapshotWin::Codes() const { |
139 INITIALIZATION_STATE_DCHECK_VALID(initialized_); | 127 INITIALIZATION_STATE_DCHECK_VALID(initialized_); |
140 return codes_; | 128 return codes_; |
141 } | 129 } |
142 | 130 |
| 131 template <class ExceptionRecordType, class ContextType> |
| 132 bool ExceptionSnapshotWin::InitializeFromExceptionPointers( |
| 133 const ProcessReaderWin& process_reader, |
| 134 const EXCEPTION_POINTERS& exception_pointers, |
| 135 ContextType* context_record) { |
| 136 ExceptionRecordType first_record; |
| 137 if (!process_reader.ReadMemory( |
| 138 reinterpret_cast<WinVMAddress>(exception_pointers.ExceptionRecord), |
| 139 sizeof(first_record), |
| 140 &first_record)) { |
| 141 LOG(ERROR) << "ExceptionRecord"; |
| 142 return false; |
| 143 } |
| 144 exception_code_ = first_record.ExceptionCode; |
| 145 exception_flags_ = first_record.ExceptionFlags; |
| 146 exception_address_ = first_record.ExceptionAddress; |
| 147 for (DWORD i = 0; i < first_record.NumberParameters; ++i) |
| 148 codes_.push_back(first_record.ExceptionInformation[i]); |
| 149 if (first_record.ExceptionRecord) { |
| 150 // https://code.google.com/p/crashpad/issues/detail?id=43 |
| 151 LOG(WARNING) << "dropping chained ExceptionRecord"; |
| 152 } |
| 153 |
| 154 if (!process_reader.ReadMemory( |
| 155 reinterpret_cast<WinVMAddress>(exception_pointers.ContextRecord), |
| 156 sizeof(*context_record), |
| 157 context_record)) { |
| 158 LOG(ERROR) << "ContextRecord"; |
| 159 return false; |
| 160 } |
| 161 |
| 162 return true; |
| 163 } |
| 164 |
143 } // namespace internal | 165 } // namespace internal |
144 } // namespace crashpad | 166 } // namespace crashpad |
OLD | NEW |