ReportError.cpp 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. #include "CommonExceptionsPch.h"
  6. // Disable inline so that _ReturnAdddress() will get the address of the calling function.
  7. _NOINLINE
  8. void ReportFatalException(
  9. __in ULONG_PTR context,
  10. __in HRESULT exceptionCode,
  11. __in ErrorReason reasonCode,
  12. __in ULONG scenario)
  13. {
  14. // avoid the error text methods to be optimized out.
  15. UNREFERENCED_PARAMETER(scenario);
  16. if (IsDebuggerPresent())
  17. {
  18. DebugBreak();
  19. }
  20. #ifdef DISABLE_SEH
  21. TerminateProcess(GetCurrentProcess(), (UINT)DBG_TERMINATE_PROCESS);
  22. #else
  23. void * addressToBlame = _ReturnAddress();
  24. __try
  25. {
  26. ULONG_PTR ExceptionInformation[2];
  27. ExceptionInformation[0] = (ULONG_PTR)reasonCode;
  28. ExceptionInformation[1] = (ULONG_PTR)context;
  29. RaiseException(exceptionCode, EXCEPTION_NONCONTINUABLE, 2, (ULONG_PTR*)ExceptionInformation);
  30. }
  31. __except(FatalExceptionFilter(GetExceptionInformation(), addressToBlame))
  32. {
  33. }
  34. #endif // DISABLE_SEH
  35. }
  36. // Disable optimization make sure all the frames are still available in Dr. Watson bug reports.
  37. #pragma optimize("", off)
  38. _NOINLINE void JavascriptDispatch_OOM_fatal_error(
  39. __in ULONG_PTR context)
  40. {
  41. int scenario = 1;
  42. ReportFatalException(context, E_OUTOFMEMORY, JavascriptDispatch_OUTOFMEMORY, scenario);
  43. };
  44. _NOINLINE void CustomHeap_BadPageState_unrecoverable_error(
  45. __in ULONG_PTR context)
  46. {
  47. int scenario = 1;
  48. ReportFatalException(context, E_UNEXPECTED, CustomHeap_MEMORYCORRUPTION, scenario);
  49. };
  50. _NOINLINE void MarkStack_OOM_unrecoverable_error()
  51. {
  52. int scenario = 1;
  53. ReportFatalException(NULL, E_OUTOFMEMORY, MarkStack_OUTOFMEMORY, scenario);
  54. };
  55. _NOINLINE void Amd64StackWalkerOutOfContexts_unrecoverable_error(
  56. __in ULONG_PTR context)
  57. {
  58. int scenario = 1;
  59. ReportFatalException(context, E_UNEXPECTED, Fatal_Amd64StackWalkerOutOfContexts, scenario);
  60. }
  61. _NOINLINE void FailedToBox_OOM_unrecoverable_error(
  62. __in ULONG_PTR context)
  63. {
  64. int scenario = 1;
  65. ReportFatalException(context, E_UNEXPECTED, Fatal_FailedToBox_OUTOFMEMORY, scenario);
  66. }
  67. #if defined(RECYCLER_WRITE_BARRIER) && defined(TARGET_64)
  68. _NOINLINE void X64WriteBarrier_OOM_unrecoverable_error()
  69. {
  70. int scenario = 3;
  71. ReportFatalException(NULL, E_OUTOFMEMORY, WriteBarrier_OUTOFMEMORY, scenario);
  72. }
  73. #endif
  74. _NOINLINE void DebugHeap_OOM_fatal_error()
  75. {
  76. int scenario = 3;
  77. ReportFatalException(NULL, E_OUTOFMEMORY, Fatal_Debug_Heap_OUTOFMEMORY, scenario);
  78. }
  79. _NOINLINE void Binary_Inconsistency_fatal_error()
  80. {
  81. int scenario = 4;
  82. ReportFatalException(NULL, E_UNEXPECTED, Fatal_Binary_Inconsistency, scenario);
  83. }
  84. _NOINLINE void Version_Inconsistency_fatal_error()
  85. {
  86. int scenario = 4;
  87. ReportFatalException(NULL, E_UNEXPECTED, Fatal_Version_Inconsistency, scenario);
  88. }
  89. #ifdef LARGEHEAPBLOCK_ENCODING
  90. _NOINLINE void LargeHeapBlock_Metadata_Corrupted(
  91. __in ULONG_PTR context, __in unsigned char calculatedChecksum)
  92. {
  93. int scenario = calculatedChecksum; /* For debugging purpose if checksum mismatch happen*/
  94. ReportFatalException(context, E_UNEXPECTED, LargeHeapBlock_Metadata_Corrupt, scenario);
  95. };
  96. #endif
  97. // If you see this error, it is because of a DOM bug. Assign to daniec or jdweiner.
  98. _NOINLINE void FromDOM_NoScriptScope_unrecoverable_error()
  99. {
  100. int scenario = 5;
  101. ReportFatalException(NULL, E_UNEXPECTED, EnterScript_FromDOM_NoScriptScope, scenario);
  102. }
  103. _NOINLINE void Debugger_AttachDetach_unrecoverable_error(HRESULT hr)
  104. {
  105. int scenario = 5;
  106. ReportFatalException(NULL, hr, Fatal_Debugger_AttachDetach_Failure, scenario);
  107. }
  108. _NOINLINE void EntryExitRecord_Corrupted_unrecoverable_error()
  109. {
  110. int scenario = 6;
  111. ReportFatalException(NULL, E_UNEXPECTED, Fatal_EntryExitRecordCorruption, scenario);
  112. }
  113. _NOINLINE void UnexpectedExceptionHandling_fatal_error()
  114. {
  115. int scenario = 7;
  116. ReportFatalException(NULL, E_UNEXPECTED, Fatal_UnexpectedExceptionHandling, scenario);
  117. }
  118. _NOINLINE void RpcFailure_unrecoverable_error(HRESULT hr)
  119. {
  120. int scenario = 8;
  121. ReportFatalException(NULL, hr, Fatal_RpcFailure, scenario);
  122. }
  123. _NOINLINE void OutOfMemory_unrecoverable_error()
  124. {
  125. int scenario = 9;
  126. ReportFatalException(NULL, E_OUTOFMEMORY, Fatal_OutOfMemory, scenario);
  127. }
  128. _NOINLINE void RecyclerSingleAllocationLimit_unrecoverable_error()
  129. {
  130. int scenario = 10;
  131. ReportFatalException(NULL, E_OUTOFMEMORY, Fatal_OutOfMemory, scenario);
  132. }
  133. _NOINLINE void MemGCSingleAllocationLimit_unrecoverable_error()
  134. {
  135. int scenario = 11;
  136. ReportFatalException(NULL, E_OUTOFMEMORY, Fatal_OutOfMemory, scenario);
  137. }
  138. // same as OutOfMemory_unrecoverable_error, but with a different `scenario`
  139. // - just to cause separate bucketing of these failures
  140. _NOINLINE void OutOfMemoryTooManyPinnedObjects_unrecoverable_error()
  141. {
  142. int scenario = 12;
  143. ReportFatalException(NULL, E_OUTOFMEMORY, Fatal_OutOfMemory, scenario);
  144. }
  145. // same as OutOfMemory_unrecoverable_error, but with a different `scenario`
  146. // - just to cause separate bucketing of these failures
  147. _NOINLINE void OutOfMemoryTooManyClosedContexts_unrecoverable_error()
  148. {
  149. int scenario = 13;
  150. ReportFatalException(NULL, E_OUTOFMEMORY, Fatal_OutOfMemory, scenario);
  151. }
  152. #pragma optimize("",on)