simulate_crash_mac.h 2.4 KB

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