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 "handler/mac/crash_report_exception_handler.h" | 15 #include "handler/mac/crash_report_exception_handler.h" |
16 | 16 |
17 #include <servers/bootstrap.h> | 17 #include <servers/bootstrap.h> |
18 | 18 |
19 #include <vector> | 19 #include <vector> |
20 | 20 |
21 #include "base/logging.h" | 21 #include "base/logging.h" |
22 #include "base/mac/mach_logging.h" | 22 #include "base/mac/mach_logging.h" |
23 #include "base/strings/stringprintf.h" | 23 #include "base/strings/stringprintf.h" |
24 #include "minidump/minidump_file_writer.h" | 24 #include "minidump/minidump_file_writer.h" |
| 25 #include "snapshot/mac/crashpad_info_client_options.h" |
25 #include "snapshot/mac/process_snapshot_mac.h" | 26 #include "snapshot/mac/process_snapshot_mac.h" |
26 #include "util/file/file_writer.h" | 27 #include "util/file/file_writer.h" |
27 #include "util/mach/exc_client_variants.h" | 28 #include "util/mach/exc_client_variants.h" |
28 #include "util/mach/exception_behaviors.h" | 29 #include "util/mach/exception_behaviors.h" |
29 #include "util/mach/mach_extensions.h" | 30 #include "util/mach/mach_extensions.h" |
30 #include "util/mach/scoped_task_suspend.h" | 31 #include "util/mach/scoped_task_suspend.h" |
31 #include "util/misc/uuid.h" | 32 #include "util/misc/uuid.h" |
32 | 33 |
33 namespace crashpad { | 34 namespace crashpad { |
34 | 35 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 return KERN_FAILURE; | 110 return KERN_FAILURE; |
110 } | 111 } |
111 | 112 |
112 ScopedTaskSuspend suspend(task); | 113 ScopedTaskSuspend suspend(task); |
113 | 114 |
114 ProcessSnapshotMac process_snapshot; | 115 ProcessSnapshotMac process_snapshot; |
115 if (!process_snapshot.Initialize(task)) { | 116 if (!process_snapshot.Initialize(task)) { |
116 return KERN_FAILURE; | 117 return KERN_FAILURE; |
117 } | 118 } |
118 | 119 |
119 if (!process_snapshot.InitializeException(thread, | 120 CrashpadInfoClientOptions client_options; |
120 exception, | 121 process_snapshot.GetCrashpadOptions(&client_options); |
121 code, | 122 |
122 code_count, | 123 if (client_options.crashpad_handler_behavior != |
123 *flavor, | 124 CrashpadInfoClientOptions::TriState::kDisabled) { |
124 old_state, | 125 if (!process_snapshot.InitializeException(thread, |
125 old_state_count)) { | 126 exception, |
126 return KERN_FAILURE; | 127 code, |
| 128 code_count, |
| 129 *flavor, |
| 130 old_state, |
| 131 old_state_count)) { |
| 132 return KERN_FAILURE; |
| 133 } |
| 134 |
| 135 process_snapshot.SetAnnotationsSimpleMap(*process_annotations_); |
| 136 |
| 137 CrashReportDatabase::NewReport* new_report; |
| 138 CrashReportDatabase::OperationStatus database_status = |
| 139 database_->PrepareNewCrashReport(&new_report); |
| 140 if (database_status != CrashReportDatabase::kNoError) { |
| 141 return KERN_FAILURE; |
| 142 } |
| 143 |
| 144 CallErrorWritingCrashReport call_error_writing_crash_report(database_, |
| 145 new_report); |
| 146 |
| 147 WeakFileHandleFileWriter file_writer(new_report->handle); |
| 148 |
| 149 MinidumpFileWriter minidump; |
| 150 minidump.InitializeFromSnapshot(&process_snapshot); |
| 151 if (!minidump.WriteEverything(&file_writer)) { |
| 152 return KERN_FAILURE; |
| 153 } |
| 154 |
| 155 call_error_writing_crash_report.Disarm(); |
| 156 |
| 157 UUID uuid; |
| 158 database_status = database_->FinishedWritingCrashReport(new_report, &uuid); |
| 159 if (database_status != CrashReportDatabase::kNoError) { |
| 160 return KERN_FAILURE; |
| 161 } |
| 162 |
| 163 upload_thread_->ReportPending(); |
127 } | 164 } |
128 | 165 |
129 process_snapshot.SetAnnotationsSimpleMap(*process_annotations_); | 166 if (client_options.system_crash_reporter_forwarding != |
130 | 167 CrashpadInfoClientOptions::TriState::kDisabled && |
131 CrashReportDatabase::NewReport* new_report; | 168 (exception == EXC_CRASH || |
132 CrashReportDatabase::OperationStatus database_status = | 169 exception == EXC_RESOURCE || |
133 database_->PrepareNewCrashReport(&new_report); | 170 exception == EXC_GUARD)) { |
134 if (database_status != CrashReportDatabase::kNoError) { | |
135 return KERN_FAILURE; | |
136 } | |
137 | |
138 CallErrorWritingCrashReport call_error_writing_crash_report(database_, | |
139 new_report); | |
140 | |
141 WeakFileHandleFileWriter file_writer(new_report->handle); | |
142 | |
143 MinidumpFileWriter minidump; | |
144 minidump.InitializeFromSnapshot(&process_snapshot); | |
145 if (!minidump.WriteEverything(&file_writer)) { | |
146 return KERN_FAILURE; | |
147 } | |
148 | |
149 call_error_writing_crash_report.Disarm(); | |
150 | |
151 UUID uuid; | |
152 database_status = database_->FinishedWritingCrashReport(new_report, &uuid); | |
153 if (database_status != CrashReportDatabase::kNoError) { | |
154 return KERN_FAILURE; | |
155 } | |
156 | |
157 upload_thread_->ReportPending(); | |
158 | |
159 if (exception == EXC_CRASH || | |
160 exception == EXC_RESOURCE || | |
161 exception == EXC_GUARD) { | |
162 // Don’t forward simulated exceptions such as kMachExceptionSimulated to the | 171 // Don’t forward simulated exceptions such as kMachExceptionSimulated to the |
163 // system crash reporter. Only forward the types of exceptions that it would | 172 // system crash reporter. Only forward the types of exceptions that it would |
164 // receive under normal conditions. Although the system crash reporter is | 173 // receive under normal conditions. Although the system crash reporter is |
165 // able to deal with other exceptions including simulated ones, forwarding | 174 // able to deal with other exceptions including simulated ones, forwarding |
166 // them to the system crash reporter could present the system’s crash UI for | 175 // them to the system crash reporter could present the system’s crash UI for |
167 // processes that haven’t actually crashed, and could result in reports not | 176 // processes that haven’t actually crashed, and could result in reports not |
168 // actually associated with crashes being sent to the operating system | 177 // actually associated with crashes being sent to the operating system |
169 // vendor. | 178 // vendor. |
170 mach_port_t system_crash_reporter_port; | 179 mach_port_t system_crash_reporter_port; |
171 const char kSystemCrashReporterServiceName[] = "com.apple.ReportCrash"; | 180 const char kSystemCrashReporterServiceName[] = "com.apple.ReportCrash"; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 &new_state_forward_count); | 216 &new_state_forward_count); |
208 MACH_LOG_IF(WARNING, kr != KERN_SUCCESS, kr) | 217 MACH_LOG_IF(WARNING, kr != KERN_SUCCESS, kr) |
209 << "UniversalExceptionRaise " << kSystemCrashReporterServiceName; | 218 << "UniversalExceptionRaise " << kSystemCrashReporterServiceName; |
210 } | 219 } |
211 } | 220 } |
212 | 221 |
213 return ExcServerSuccessfulReturnValue(behavior, false); | 222 return ExcServerSuccessfulReturnValue(behavior, false); |
214 } | 223 } |
215 | 224 |
216 } // namespace crashpad | 225 } // namespace crashpad |
OLD | NEW |