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" | |
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 ProcessReaderWin process_reader; | |
48 if (!process_reader.Initialize(process)) { | |
49 LOG(WARNING) << "ProcessReaderWin Initialize failed"; | |
50 return kFailedTerminationCode; | |
51 } | |
52 ExceptionInformation exception_information; | |
53 if (!process_reader.ReadMemory(exception_information_address, | |
54 sizeof(exception_information), | |
55 &exception_information)) { | |
56 LOG(WARNING) << "ReadMemory ExceptionInformation failed"; | |
57 return kFailedTerminationCode; | |
58 } | |
59 | |
60 // TODO(scottmg): ScopedProcessSuspend | |
61 | |
62 ProcessSnapshotWin process_snapshot; | |
63 if (!process_snapshot.Initialize(process)) { | |
Mark Mentovai
2015/09/03 18:33:37
ProcessSnapshotWin is going to make a ProcessReade
scottmg
2015/09/03 19:54:31
Done.
| |
64 LOG(WARNING) << "ProcessSnapshotWin Initialize failed"; | |
Mark Mentovai
2015/09/03 18:33:37
You can use :: here, and you can say ProcessSnapsh
scottmg
2015/09/03 19:54:31
Done.
| |
65 return kFailedTerminationCode; | |
66 } | |
67 | |
68 if (!process_snapshot.InitializeException( | |
69 exception_information.thread_id, | |
70 exception_information.exception_pointers)) { | |
71 LOG(WARNING) << "InitializeException failed"; | |
72 return kFailedTerminationCode; | |
73 } | |
74 | |
75 // Now that we have the exception information, even if something else fails we | |
76 // can terminate the process with the correct exit code. | |
77 unsigned int termination_code = process_snapshot.Exception()->Exception(); | |
Mark Mentovai
2015/09/03 18:33:37
OK, but not required, to be const. (I’m trying to
scottmg
2015/09/03 19:54:31
Done.
| |
78 | |
79 CrashpadInfoClientOptions client_options; | |
80 process_snapshot.GetCrashpadOptions(&client_options); | |
81 if (client_options.crashpad_handler_behavior != TriState::kDisabled) { | |
82 UUID client_id; | |
83 Settings* const settings = database_->GetSettings(); | |
84 if (settings) { | |
85 // If GetSettings() or GetClientID() fails, something else will log a | |
86 // message and client_id will be left at its default value, all zeroes, | |
87 // which is appropriate. | |
88 settings->GetClientID(&client_id); | |
89 } | |
90 | |
91 process_snapshot.SetClientID(client_id); | |
92 process_snapshot.SetAnnotationsSimpleMap(*process_annotations_); | |
93 | |
94 CrashReportDatabase::NewReport* new_report; | |
95 CrashReportDatabase::OperationStatus database_status = | |
96 database_->PrepareNewCrashReport(&new_report); | |
97 if (database_status != CrashReportDatabase::kNoError) { | |
98 LOG(ERROR) << "PrepareNewCrashReport failed"; | |
99 return termination_code; | |
100 } | |
101 | |
102 process_snapshot.SetReportID(new_report->uuid); | |
103 | |
104 CrashReportDatabase::CallErrorWritingCrashReport | |
105 call_error_writing_crash_report(database_, new_report); | |
106 | |
107 WeakFileHandleFileWriter file_writer(new_report->handle); | |
108 | |
109 MinidumpFileWriter minidump; | |
110 minidump.InitializeFromSnapshot(&process_snapshot); | |
111 if (!minidump.WriteEverything(&file_writer)) { | |
112 LOG(ERROR) << "WriteEverything failed"; | |
113 return termination_code; | |
114 } | |
115 | |
116 call_error_writing_crash_report.Disarm(); | |
117 | |
118 UUID uuid; | |
119 database_status = database_->FinishedWritingCrashReport(new_report, &uuid); | |
120 if (database_status != CrashReportDatabase::kNoError) { | |
121 LOG(ERROR) << "FinishedWritingCrashReport failed"; | |
122 return termination_code; | |
123 } | |
124 | |
125 upload_thread_->ReportPending(); | |
126 } | |
127 | |
128 return termination_code; | |
129 } | |
130 | |
131 } // namespace crashpad | |
OLD | NEW |