ExceptionHandler.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * ExceptionHandler.h
  3. * ------------------
  4. * Purpose: Code for handling crashes (unhandled exceptions) in OpenMPT.
  5. * Notes : (currently none)
  6. * Authors: OpenMPT Devs
  7. * The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
  8. */
  9. #pragma once
  10. #include "openmpt/all/BuildSettings.hpp"
  11. OPENMPT_NAMESPACE_BEGIN
  12. class ExceptionHandler
  13. {
  14. public:
  15. struct Context
  16. {
  17. void SetDescription(mpt::ustring desc)
  18. {
  19. description = std::move(desc);
  20. }
  21. mpt::ustring description;
  22. };
  23. public:
  24. static bool fullMemDump;
  25. static bool stopSoundDeviceOnCrash;
  26. static bool stopSoundDeviceBeforeDump;
  27. static bool delegateToWindowsHandler;
  28. static bool debugExceptionHandler;
  29. // these are expected to be set on startup and never changed again
  30. static bool useAnyCrashHandler;
  31. static bool useImplicitFallbackSEH;
  32. static bool useExplicitSEH;
  33. static bool handleStdTerminate;
  34. static bool handleStdUnexpected;
  35. static bool handleMfcExceptions;
  36. // Call this to activate unhandled exception filtering
  37. // and register a std::terminate_handler.
  38. static void Register();
  39. static void ConfigureSystemHandler();
  40. static void UnconfigureSystemHandler();
  41. static void Unregister();
  42. enum class TaintReason
  43. {
  44. Driver,
  45. Plugin,
  46. };
  47. static void TaintProcess(TaintReason reason);
  48. public:
  49. static Context *SetContext(Context *newContext) noexcept;
  50. class ContextSetter
  51. {
  52. private:
  53. Context *m_OldContext;
  54. public:
  55. inline ContextSetter(Context *newContext) noexcept
  56. : m_OldContext(SetContext(newContext))
  57. {
  58. return;
  59. }
  60. ContextSetter(const ContextSetter &) = delete;
  61. ContextSetter &operator=(const ContextSetter &) = delete;
  62. inline ~ContextSetter()
  63. {
  64. SetContext(m_OldContext);
  65. }
  66. };
  67. static LONG WINAPI UnhandledExceptionFilterContinue(_EXCEPTION_POINTERS *pExceptionInfo);
  68. static LONG WINAPI ExceptionFilter(_EXCEPTION_POINTERS *pExceptionInfo);
  69. static void UnhandledMFCException(CException * e, const MSG * pMsg);
  70. };
  71. void DebugInjectCrash();
  72. void DebugTraceDump();
  73. OPENMPT_NAMESPACE_END