blob: d9b4007aa46c83f479b923c70a5259f863a84db5 [file] [log] [blame]
Mark Mentovai62786902022-09-06 19:14:07 -04001// Copyright 2015 The Crashpad Authors
Mark Mentovai409742c2015-02-04 18:32:42 -05002//
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#ifndef CRASHPAD_HANDLER_MAC_CRASH_REPORT_EXCEPTION_HANDLER_H_
16#define CRASHPAD_HANDLER_MAC_CRASH_REPORT_EXCEPTION_HANDLER_H_
17
18#include <mach/mach.h>
19
Mark Mentovaiae1ccf62015-03-05 15:40:47 -050020#include <map>
21#include <string>
22
Mark Mentovai409742c2015-02-04 18:32:42 -050023#include "client/crash_report_database.h"
Scott Graham86419cf2015-08-18 15:34:10 -070024#include "handler/crash_report_upload_thread.h"
Sigurdur Asgeirsson30385d42017-04-11 14:48:10 -040025#include "handler/user_stream_data_source.h"
Mark Mentovai409742c2015-02-04 18:32:42 -050026#include "util/mach/exc_server_variants.h"
27
28namespace crashpad {
29
30//! \brief An exception handler that writes crash reports for exception messages
31//! to a CrashReportDatabase.
Joshua Perazacd92fba2019-08-30 11:51:47 -070032class CrashReportExceptionHandler final
33 : public UniversalMachExcServer::Interface {
Mark Mentovai409742c2015-02-04 18:32:42 -050034 public:
35 //! \brief Creates a new object that will store crash reports in \a database.
36 //!
37 //! \param[in] database The database to store crash reports in. Weak.
Mark Mentovai4b6d54b2015-02-12 15:03:59 -050038 //! \param[in] upload_thread The upload thread to notify when a new crash
Joshua Perazaebad8bd2018-02-20 10:55:17 -080039 //! report is written into \a database. Report upload is skipped if this
40 //! value is `nullptr`.
Mark Mentovaiae1ccf62015-03-05 15:40:47 -050041 //! \param[in] process_annotations A map of annotations to insert as
42 //! process-level annotations into each crash report that is written. Do
43 //! not confuse this with module-level annotations, which are under the
44 //! control of the crashing process, and are used to implement Chrome’s
45 //! “crash keys.” Process-level annotations are those that are beyond the
46 //! control of the crashing process, which must reliably be set even if
47 //! the process crashes before it’s able to establish its own annotations.
48 //! To interoperate with Breakpad servers, the recommended practice is to
49 //! specify values for the `"prod"` and `"ver"` keys as process
50 //! annotations.
Mark Mentovai5d07d812017-04-13 12:56:52 -040051 //! \param[in] user_stream_data_sources Data sources to be used to extend
52 //! crash reports. For each crash report that is written, the data sources
53 //! are called in turn. These data sources may contribute additional
54 //! minidump streams. `nullptr` if not required.
Mark Mentovaiae1ccf62015-03-05 15:40:47 -050055 CrashReportExceptionHandler(
56 CrashReportDatabase* database,
57 CrashReportUploadThread* upload_thread,
Sigurdur Asgeirsson30385d42017-04-11 14:48:10 -040058 const std::map<std::string, std::string>* process_annotations,
59 const UserStreamDataSources* user_stream_data_sources);
Mark Mentovai409742c2015-02-04 18:32:42 -050060
Peter Boström1aa478d2021-09-20 12:55:12 -070061 CrashReportExceptionHandler(const CrashReportExceptionHandler&) = delete;
62 CrashReportExceptionHandler& operator=(const CrashReportExceptionHandler&) =
63 delete;
64
Mark Mentovai409742c2015-02-04 18:32:42 -050065 ~CrashReportExceptionHandler();
66
67 // UniversalMachExcServer::Interface:
68
69 //! \brief Processes an exception message by writing a crash report to this
70 //! object’s CrashReportDatabase.
71 kern_return_t CatchMachException(
72 exception_behavior_t behavior,
73 exception_handler_t exception_port,
74 thread_t thread,
75 task_t task,
76 exception_type_t exception,
77 const mach_exception_data_type_t* code,
78 mach_msg_type_number_t code_count,
79 thread_state_flavor_t* flavor,
Mark Mentovai40b1d7c2015-04-02 15:28:28 -040080 ConstThreadState old_state,
Mark Mentovai409742c2015-02-04 18:32:42 -050081 mach_msg_type_number_t old_state_count,
82 thread_state_t new_state,
83 mach_msg_type_number_t* new_state_count,
84 const mach_msg_trailer_t* trailer,
85 bool* destroy_complex_request) override;
86
87 private:
88 CrashReportDatabase* database_; // weak
Mark Mentovai4b6d54b2015-02-12 15:03:59 -050089 CrashReportUploadThread* upload_thread_; // weak
Mark Mentovaiae1ccf62015-03-05 15:40:47 -050090 const std::map<std::string, std::string>* process_annotations_; // weak
Sigurdur Asgeirsson30385d42017-04-11 14:48:10 -040091 const UserStreamDataSources* user_stream_data_sources_; // weak
Mark Mentovai409742c2015-02-04 18:32:42 -050092};
93
94} // namespace crashpad
95
96#endif // CRASHPAD_HANDLER_MAC_CRASH_REPORT_EXCEPTION_HANDLER_H_