Chromium Code Reviews| 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 "handler/win/crash_report_exception_handler.h" | |
| 16 | |
| 17 #include "client/crash_report_database.h" | |
| 18 #include "client/settings.h" | |
| 19 #include "handler/crash_report_upload_thread.h" | |
| 20 #include "minidump/minidump_file_writer.h" | |
| 21 #include "snapshot/win/process_reader_win.h" | |
|
Mark Mentovai
2015/09/03 20:07:29
Unused now.
scottmg
2015/09/03 20:30:01
Done.
| |
| 22 #include "snapshot/win/process_snapshot_win.h" | |
| 23 #include "util/file/file_writer.h" | |
| 24 #include "util/win/registration_protocol_win.h" | |
| 25 | |
| 26 namespace crashpad { | |
| 27 | |
| 28 CrashReportExceptionHandler::CrashReportExceptionHandler( | |
| 29 CrashReportDatabase* database, | |
| 30 CrashReportUploadThread* upload_thread, | |
| 31 const std::map<std::string, std::string>* process_annotations) | |
| 32 : database_(database), | |
| 33 upload_thread_(upload_thread), | |
| 34 process_annotations_(process_annotations) { | |
| 35 } | |
| 36 | |
| 37 CrashReportExceptionHandler::~CrashReportExceptionHandler() { | |
| 38 } | |
| 39 | |
| 40 void CrashReportExceptionHandler::ExceptionHandlerServerStarted() { | |
| 41 } | |
| 42 | |
| 43 unsigned int CrashReportExceptionHandler::ExceptionHandlerServerException( | |
| 44 HANDLE process, | |
| 45 WinVMAddress exception_information_address) { | |
| 46 const unsigned int kFailedTerminationCode = 0xffff7002; | |
| 47 | |
| 48 // TODO(scottmg): ScopedProcessSuspend | |
| 49 | |
| 50 ProcessSnapshotWin process_snapshot; | |
| 51 if (!process_snapshot.Initialize(process)) { | |
| 52 LOG(WARNING) << "ProcessSnapshotWin::Initialize failed"; | |
| 53 return kFailedTerminationCode; | |
| 54 } | |
| 55 | |
| 56 if (!process_snapshot.InitializeException(exception_information_address)) { | |
| 57 LOG(WARNING) << "ProcessSnapshotWin::InitializeException failed"; | |
| 58 return kFailedTerminationCode; | |
| 59 } | |
| 60 | |
| 61 // Now that we have the exception information, even if something else fails we | |
| 62 // can terminate the process with the correct exit code. | |
| 63 const unsigned int termination_code = | |
| 64 process_snapshot.Exception()->Exception(); | |
| 65 | |
| 66 CrashpadInfoClientOptions client_options; | |
| 67 process_snapshot.GetCrashpadOptions(&client_options); | |
| 68 if (client_options.crashpad_handler_behavior != TriState::kDisabled) { | |
|
Mark Mentovai
2015/09/03 20:07:29
For a follow-up if at all: is there anything we ca
scottmg
2015/09/03 20:30:01
I'm not sure. The only obvious way to pass it on t
| |
| 69 UUID client_id; | |
| 70 Settings* const settings = database_->GetSettings(); | |
| 71 if (settings) { | |
| 72 // If GetSettings() or GetClientID() fails, something else will log a | |
| 73 // message and client_id will be left at its default value, all zeroes, | |
| 74 // which is appropriate. | |
| 75 settings->GetClientID(&client_id); | |
| 76 } | |
| 77 | |
| 78 process_snapshot.SetClientID(client_id); | |
| 79 process_snapshot.SetAnnotationsSimpleMap(*process_annotations_); | |
| 80 | |
| 81 CrashReportDatabase::NewReport* new_report; | |
| 82 CrashReportDatabase::OperationStatus database_status = | |
| 83 database_->PrepareNewCrashReport(&new_report); | |
| 84 if (database_status != CrashReportDatabase::kNoError) { | |
| 85 LOG(ERROR) << "PrepareNewCrashReport failed"; | |
| 86 return termination_code; | |
| 87 } | |
| 88 | |
| 89 process_snapshot.SetReportID(new_report->uuid); | |
| 90 | |
| 91 CrashReportDatabase::CallErrorWritingCrashReport | |
| 92 call_error_writing_crash_report(database_, new_report); | |
| 93 | |
| 94 WeakFileHandleFileWriter file_writer(new_report->handle); | |
| 95 | |
| 96 MinidumpFileWriter minidump; | |
| 97 minidump.InitializeFromSnapshot(&process_snapshot); | |
| 98 if (!minidump.WriteEverything(&file_writer)) { | |
| 99 LOG(ERROR) << "WriteEverything failed"; | |
| 100 return termination_code; | |
| 101 } | |
| 102 | |
| 103 call_error_writing_crash_report.Disarm(); | |
| 104 | |
| 105 UUID uuid; | |
| 106 database_status = database_->FinishedWritingCrashReport(new_report, &uuid); | |
| 107 if (database_status != CrashReportDatabase::kNoError) { | |
| 108 LOG(ERROR) << "FinishedWritingCrashReport failed"; | |
| 109 return termination_code; | |
| 110 } | |
| 111 | |
| 112 upload_thread_->ReportPending(); | |
| 113 } | |
| 114 | |
| 115 return termination_code; | |
| 116 } | |
| 117 | |
| 118 } // namespace crashpad | |
| OLD | NEW |