OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 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 #ifndef CRASHPAD_CLIENT_CRASHPAD_CLIENT_H_ |
| 16 #define CRASHPAD_CLIENT_CRASHPAD_CLIENT_H_ |
| 17 |
| 18 #include <string> |
| 19 #include <vector> |
| 20 |
| 21 #include "base/basictypes.h" |
| 22 #include "base/files/file_path.h" |
| 23 #include "build/build_config.h" |
| 24 |
| 25 #if defined(OS_MACOSX) |
| 26 #include "base/mac/scoped_mach_port.h" |
| 27 #endif |
| 28 |
| 29 namespace crashpad { |
| 30 |
| 31 //! \brief The primary interface for an application to have Crashpad monitor |
| 32 //! it for crashes. |
| 33 class CrashpadClient { |
| 34 public: |
| 35 CrashpadClient(); |
| 36 ~CrashpadClient(); |
| 37 |
| 38 //! \brief Starts a Crashpad handler process, performing any necessary |
| 39 //! handshake to configure it. |
| 40 //! |
| 41 //! This method does not actually direct any crashes to the Crashpad handler, |
| 42 //! because there may be alternative ways to use an existing Crashpad handler |
| 43 //! without having to start one. To begin directing crashes to the handler, |
| 44 //! started by this method, call UseHandler() after this method returns |
| 45 //! successfully. |
| 46 //! |
| 47 //! On Mac OS X, this method starts a Crashpad handler and obtains a Mach |
| 48 //! send right corresponding to a receive right held by the handler process. |
| 49 //! The handler process runs an exception server on this port. |
| 50 //! |
| 51 //! \param[in] handler The path to a Crashpad handler executable. |
| 52 //! \param[in] handler_arguments Arguments to pass to the Crashpad handler. |
| 53 //! Arguments required to perform the handshake are the responsibility of |
| 54 //! this method, and must not be specified in this parameter. |
| 55 //! |
| 56 //! \return `true` on success, `false` on failure with a message logged. |
| 57 bool StartHandler(const base::FilePath& handler, |
| 58 const std::vector<std::string>& handler_arguments); |
| 59 |
| 60 //! \brief Configures the process to direct its crashes to a Crashpad handler. |
| 61 //! |
| 62 //! The Crashpad handler must previously have been started by StartHandler(). |
| 63 //! |
| 64 //! On Mac OS X, this method sets the task’s exception port for `EXC_CRASH`, |
| 65 //! `EXC_RESOURCE`, and `EXC_GUARD` exceptions to the Mach send right obtained |
| 66 //! by StartHandler(). The handler will be installed with behavior |
| 67 //! `EXCEPTION_STATE_IDENTITY | MACH_EXCEPTION_CODES` and thread state flavor |
| 68 //! `MACHINE_THREAD_STATE`. Exception ports are inherited, so a Crashpad |
| 69 //! handler chosen by UseHandler() will remain the handler for any child |
| 70 //! processes created after UseHandler() is called. Child processes do not |
| 71 //! need to call StartHandler() or UseHandler() or be aware of Crashpad in any |
| 72 //! way. The Crashpad handler will receive crashes from child processes that |
| 73 //! have inherited it as their exception handler even after the process that |
| 74 //! called StartHandler() exits. |
| 75 //! |
| 76 //! \return `true` on success, `false` on failure with a message logged. |
| 77 bool UseHandler(); |
| 78 |
| 79 private: |
| 80 #if defined(OS_MACOSX) |
| 81 base::mac::ScopedMachSendRight exception_port_; |
| 82 #endif |
| 83 |
| 84 DISALLOW_COPY_AND_ASSIGN(CrashpadClient); |
| 85 }; |
| 86 |
| 87 } // namespace crashpad |
| 88 |
| 89 #endif // CRASHPAD_CLIENT_CRASHPAD_CLIENT_H_ |
OLD | NEW |