ReportError.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. #pragma once
  6. enum ErrorReason
  7. {
  8. JavascriptDispatch_OUTOFMEMORY = 1,
  9. Fatal_Internal_Error = 2,
  10. Fatal_Debug_Heap_OUTOFMEMORY = 3,
  11. Fatal_Amd64StackWalkerOutOfContexts = 4,
  12. // Unused = 5,
  13. Fatal_Binary_Inconsistency = 6,
  14. WriteBarrier_OUTOFMEMORY = 7,
  15. CustomHeap_MEMORYCORRUPTION = 8,
  16. LargeHeapBlock_Metadata_Corrupt = 9,
  17. Fatal_Version_Inconsistency = 10,
  18. MarkStack_OUTOFMEMORY = 11,
  19. EnterScript_FromDOM_NoScriptScope = 12,
  20. Fatal_FailedToBox_OUTOFMEMORY = 13,
  21. Fatal_Recycler_MemoryCorruption = 14,
  22. Fatal_Debugger_AttachDetach_Failure = 15,
  23. Fatal_EntryExitRecordCorruption = 16,
  24. Fatal_UnexpectedExceptionHandling = 17,
  25. Fatal_RpcFailure = 18,
  26. Fatal_JsReentrancy_Error = 19,
  27. Fatal_TTDAbort = 20,
  28. Fatal_Failed_API_Result = 21,
  29. Fatal_OutOfMemory = 22,
  30. Fatal_RecyclerVisitedHost_LargeHeapBlock = 23,
  31. Fatal_JsBuiltIn_Error = 24,
  32. };
  33. extern "C" void ReportFatalException(
  34. __in ULONG_PTR context,
  35. __in HRESULT exceptionCode,
  36. __in ErrorReason reasonCode,
  37. __in ULONG scenario);
  38. // We can have other error handle code path with
  39. // unique call stack so we can collect data in Dr. Watson.
  40. void JavascriptDispatch_OOM_fatal_error(
  41. __in ULONG_PTR context);
  42. void CustomHeap_BadPageState_unrecoverable_error(
  43. __in ULONG_PTR context);
  44. void Amd64StackWalkerOutOfContexts_unrecoverable_error(
  45. __in ULONG_PTR context);
  46. void FailedToBox_OOM_unrecoverable_error(
  47. __in ULONG_PTR context);
  48. #if defined(RECYCLER_WRITE_BARRIER) && defined(TARGET_64)
  49. void X64WriteBarrier_OOM_unrecoverable_error();
  50. #endif
  51. void DebugHeap_OOM_fatal_error();
  52. void MarkStack_OOM_unrecoverable_error();
  53. void Binary_Inconsistency_fatal_error();
  54. void Version_Inconsistency_fatal_error();
  55. void EntryExitRecord_Corrupted_unrecoverable_error();
  56. void UnexpectedExceptionHandling_fatal_error();
  57. #ifdef LARGEHEAPBLOCK_ENCODING
  58. void LargeHeapBlock_Metadata_Corrupted(
  59. __in ULONG_PTR context, __in unsigned char calculatedCheckSum);
  60. #endif
  61. void FromDOM_NoScriptScope_unrecoverable_error();
  62. void Debugger_AttachDetach_unrecoverable_error(HRESULT hr);
  63. void RpcFailure_unrecoverable_error(HRESULT hr);
  64. void OutOfMemory_unrecoverable_error();
  65. #ifndef DISABLE_SEH
  66. // RtlReportException is available on Vista and up, but we cannot use it for OOB release.
  67. // Use UnhandleExceptionFilter to let the default handler handles it.
  68. inline LONG FatalExceptionFilter(
  69. __in LPEXCEPTION_POINTERS lpep)
  70. {
  71. LONG rc = UnhandledExceptionFilter(lpep);
  72. // re == EXCEPTION_EXECUTE_HANDLER means there is no debugger attached, let's terminate
  73. // the process. Otherwise give control to the debugger.
  74. // Note: in case when postmortem debugger is registered but no actual debugger attached,
  75. // rc will be 0 (and EXCEPTION_EXECUTE_HANDLER is 1), so it acts as if there is debugger attached.
  76. if (rc == EXCEPTION_EXECUTE_HANDLER)
  77. {
  78. TerminateProcess(GetCurrentProcess(), (UINT)DBG_TERMINATE_PROCESS);
  79. }
  80. else
  81. {
  82. // However, if debugger was not attached for some reason, terminate the process.
  83. if (!IsDebuggerPresent())
  84. {
  85. TerminateProcess(GetCurrentProcess(), (UINT)DBG_TERMINATE_PROCESS);
  86. }
  87. DebugBreak();
  88. }
  89. return EXCEPTION_CONTINUE_SEARCH;
  90. }
  91. #endif // DISABLE_SEH
  92. template<class Fn>
  93. static STDMETHODIMP DebugApiWrapper(Fn fn)
  94. {
  95. // If an assertion or AV is hit, it triggers a SEH exception. SEH exceptions escaped here will be eaten by PDM. To prevent assertions
  96. // from getting unnoticed, we install a SEH exception filter and crash the process.
  97. #if ENABLE_DEBUG_API_WRAPPER
  98. __try
  99. {
  100. #endif
  101. return fn();
  102. #if ENABLE_DEBUG_API_WRAPPER
  103. }
  104. __except(FatalExceptionFilter(GetExceptionInformation()))
  105. {
  106. }
  107. return E_FAIL;
  108. #endif
  109. }