Mark Mentovai | 6278690 | 2022-09-06 19:14:07 -0400 | [diff] [blame] | 1 | // Copyright 2015 The Crashpad Authors |
Mark Mentovai | 409742c | 2015-02-04 18:32:42 -0500 | [diff] [blame] | 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 | #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 Mentovai | ae1ccf6 | 2015-03-05 15:40:47 -0500 | [diff] [blame] | 20 | #include <map> |
| 21 | #include <string> |
| 22 | |
Mark Mentovai | 409742c | 2015-02-04 18:32:42 -0500 | [diff] [blame] | 23 | #include "client/crash_report_database.h" |
Scott Graham | 86419cf | 2015-08-18 15:34:10 -0700 | [diff] [blame] | 24 | #include "handler/crash_report_upload_thread.h" |
Sigurdur Asgeirsson | 30385d4 | 2017-04-11 14:48:10 -0400 | [diff] [blame] | 25 | #include "handler/user_stream_data_source.h" |
Mark Mentovai | 409742c | 2015-02-04 18:32:42 -0500 | [diff] [blame] | 26 | #include "util/mach/exc_server_variants.h" |
| 27 | |
| 28 | namespace crashpad { |
| 29 | |
| 30 | //! \brief An exception handler that writes crash reports for exception messages |
| 31 | //! to a CrashReportDatabase. |
Joshua Peraza | cd92fba | 2019-08-30 11:51:47 -0700 | [diff] [blame] | 32 | class CrashReportExceptionHandler final |
| 33 | : public UniversalMachExcServer::Interface { |
Mark Mentovai | 409742c | 2015-02-04 18:32:42 -0500 | [diff] [blame] | 34 | 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 Mentovai | 4b6d54b | 2015-02-12 15:03:59 -0500 | [diff] [blame] | 38 | //! \param[in] upload_thread The upload thread to notify when a new crash |
Joshua Peraza | ebad8bd | 2018-02-20 10:55:17 -0800 | [diff] [blame] | 39 | //! report is written into \a database. Report upload is skipped if this |
| 40 | //! value is `nullptr`. |
Mark Mentovai | ae1ccf6 | 2015-03-05 15:40:47 -0500 | [diff] [blame] | 41 | //! \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 Mentovai | 5d07d81 | 2017-04-13 12:56:52 -0400 | [diff] [blame] | 51 | //! \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 Mentovai | ae1ccf6 | 2015-03-05 15:40:47 -0500 | [diff] [blame] | 55 | CrashReportExceptionHandler( |
| 56 | CrashReportDatabase* database, |
| 57 | CrashReportUploadThread* upload_thread, |
Sigurdur Asgeirsson | 30385d4 | 2017-04-11 14:48:10 -0400 | [diff] [blame] | 58 | const std::map<std::string, std::string>* process_annotations, |
| 59 | const UserStreamDataSources* user_stream_data_sources); |
Mark Mentovai | 409742c | 2015-02-04 18:32:42 -0500 | [diff] [blame] | 60 | |
Peter Boström | 1aa478d | 2021-09-20 12:55:12 -0700 | [diff] [blame] | 61 | CrashReportExceptionHandler(const CrashReportExceptionHandler&) = delete; |
| 62 | CrashReportExceptionHandler& operator=(const CrashReportExceptionHandler&) = |
| 63 | delete; |
| 64 | |
Mark Mentovai | 409742c | 2015-02-04 18:32:42 -0500 | [diff] [blame] | 65 | ~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 Mentovai | 40b1d7c | 2015-04-02 15:28:28 -0400 | [diff] [blame] | 80 | ConstThreadState old_state, |
Mark Mentovai | 409742c | 2015-02-04 18:32:42 -0500 | [diff] [blame] | 81 | 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 Mentovai | 4b6d54b | 2015-02-12 15:03:59 -0500 | [diff] [blame] | 89 | CrashReportUploadThread* upload_thread_; // weak |
Mark Mentovai | ae1ccf6 | 2015-03-05 15:40:47 -0500 | [diff] [blame] | 90 | const std::map<std::string, std::string>* process_annotations_; // weak |
Sigurdur Asgeirsson | 30385d4 | 2017-04-11 14:48:10 -0400 | [diff] [blame] | 91 | const UserStreamDataSources* user_stream_data_sources_; // weak |
Mark Mentovai | 409742c | 2015-02-04 18:32:42 -0500 | [diff] [blame] | 92 | }; |
| 93 | |
| 94 | } // namespace crashpad |
| 95 | |
| 96 | #endif // CRASHPAD_HANDLER_MAC_CRASH_REPORT_EXCEPTION_HANDLER_H_ |