| 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_SIMULATE_CRASH_MAC_H_ |
| 16 #define CRASHPAD_CLIENT_SIMULATE_CRASH_MAC_H_ |
| 17 |
| 18 #include <mach/mach.h> |
| 19 |
| 20 #include "client/capture_context_mac.h" |
| 21 |
| 22 //! \file |
| 23 |
| 24 namespace crashpad { |
| 25 |
| 26 //! \brief Simulates a exception without crashing. |
| 27 //! |
| 28 //! This function searches for an `EXC_CRASH` handler in the same manner that |
| 29 //! the kernel does, and sends it an exception message to that handler in the |
| 30 //! format that the handler expects, considering the behavior and thread state |
| 31 //! flavor that are registered for it. The exception sent to the handler will be |
| 32 //! ::kMachExceptionSimulated, not `EXC_CRASH`. |
| 33 //! |
| 34 //! Typically, the CRASHPAD_SIMULATE_CRASH() macro will be used in preference to |
| 35 //! this function, because it combines the context-capture operation with the |
| 36 //! raising of a simulated exception. |
| 37 //! |
| 38 //! This function returns normally after the exception message is processed. If |
| 39 //! no valid handler was found, or no handler processed the exception |
| 40 //! successfully, a warning will be logged, but these conditions are not |
| 41 //! considered fatal. |
| 42 //! |
| 43 //! \param[in] cpu_context The thread state to pass to the exception handler as |
| 44 //! the exception context, provided that it is compatible with the thread |
| 45 //! state flavor that the exception handler accepts. If it is not |
| 46 //! compatible, the correct thread state for the handler will be obtained by |
| 47 //! calling `thread_get_state()`. |
| 48 void SimulateCrash(const NativeCPUContext& cpu_context); |
| 49 |
| 50 } // namespace crashpad |
| 51 |
| 52 //! \brief Captures the CPU context and simulates an exception without crashing. |
| 53 #define CRASHPAD_SIMULATE_CRASH() \ |
| 54 do { \ |
| 55 crashpad::NativeCPUContext cpu_context; \ |
| 56 crashpad::CaptureContext(&cpu_context); \ |
| 57 crashpad::SimulateCrash(cpu_context); \ |
| 58 } while (false) |
| 59 |
| 60 #endif // CRASHPAD_CLIENT_SIMULATE_CRASH_MAC_H_ |
| OLD | NEW |