Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

168 lines
4.1 KiB

  1. /***
  2. *hooks.cxx - global (per-thread) variables and functions for EH callbacks
  3. *
  4. * Copyright (c) 1993-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * global (per-thread) variables for assorted callbacks, and
  8. * the functions that do those callbacks.
  9. *
  10. * Entry Points:
  11. *
  12. * * terminate()
  13. * * unexpected()
  14. * * _inconsistency()
  15. *
  16. * External Names: (only for single-threaded version)
  17. *
  18. * * __pSETranslator
  19. * * __pTerminate
  20. * * __pUnexpected
  21. * * __pInconsistency
  22. *
  23. *Revision History:
  24. * 05-25-93 BS Module created
  25. * 10-17-94 BWT Disable code for PPC.
  26. * 02-08-95 JWM Mac merge.
  27. * 04-13-95 DAK Add Kernel EH support
  28. * 05-17-99 PML Remove all Macintosh support.
  29. * 10-22-99 PML Add EHTRACE support
  30. * 06-20-00 PML Get rid of unnecessary __try/__finallys.
  31. *
  32. ****/
  33. #include <stddef.h>
  34. #include <stdlib.h>
  35. #include <excpt.h>
  36. # if defined(_NTSUBSET_)
  37. extern "C" {
  38. #include <nt.h>
  39. #include <ntrtl.h>
  40. #include <nturtl.h>
  41. #include <ntstatus.h> // STATUS_UNHANDLED_EXCEPTION
  42. #include <ntos.h>
  43. }
  44. # endif /* _NTSUBSET_ */
  45. #include <windows.h>
  46. #include <mtdll.h>
  47. #include <eh.h>
  48. #include <ehhooks.h>
  49. #include <ehassert.h>
  50. #pragma hdrstop
  51. /////////////////////////////////////////////////////////////////////////////
  52. //
  53. // The global variables:
  54. //
  55. #ifndef _MT
  56. _se_translator_function __pSETranslator = NULL;
  57. terminate_function __pTerminate = NULL;
  58. unexpected_function __pUnexpected = &terminate;
  59. #endif // !_MT
  60. _inconsistency_function __pInconsistency= &terminate;
  61. /////////////////////////////////////////////////////////////////////////////
  62. //
  63. // terminate - call the terminate handler (presumably we went south).
  64. // THIS MUST NEVER RETURN!
  65. //
  66. // Open issues:
  67. // * How do we guarantee that the whole process has stopped, and not just
  68. // the current thread?
  69. //
  70. _CRTIMP void __cdecl terminate(void)
  71. {
  72. EHTRACE_ENTER_MSG("No exit");
  73. //
  74. // Let the user wrap things up their way.
  75. //
  76. if ( __pTerminate ) {
  77. __try {
  78. __pTerminate();
  79. }
  80. __except (EXCEPTION_EXECUTE_HANDLER) {
  81. //
  82. // Intercept ANY exception from the terminate handler
  83. //
  84. }
  85. }
  86. //
  87. // If the terminate handler returned, faulted, or otherwise failed to
  88. // halt the process/thread, we'll do it.
  89. //
  90. # if defined(_NTSUBSET_)
  91. KeBugCheck( (ULONG) STATUS_UNHANDLED_EXCEPTION );
  92. # else
  93. abort();
  94. # endif
  95. }
  96. /////////////////////////////////////////////////////////////////////////////
  97. //
  98. // unexpected - call the unexpected handler (presumably we went south, or nearly).
  99. // THIS MUST NEVER RETURN!
  100. //
  101. // Open issues:
  102. // * How do we guarantee that the whole process has stopped, and not just
  103. // the current thread?
  104. //
  105. void __cdecl unexpected(void)
  106. {
  107. EHTRACE_ENTER;
  108. //
  109. // Let the user wrap things up their way.
  110. //
  111. if ( __pUnexpected )
  112. __pUnexpected();
  113. //
  114. // If the unexpected handler returned, we'll give the terminate handler a chance.
  115. //
  116. terminate();
  117. }
  118. /////////////////////////////////////////////////////////////////////////////
  119. //
  120. // _inconsistency - call the inconsistency handler (Run-time processing error!)
  121. // THIS MUST NEVER RETURN!
  122. //
  123. // Open issues:
  124. // * How do we guarantee that the whole process has stopped, and not just
  125. // the current thread?
  126. //
  127. void __cdecl _inconsistency(void)
  128. {
  129. EHTRACE_ENTER;
  130. //
  131. // Let the user wrap things up their way.
  132. //
  133. if ( __pInconsistency )
  134. __try {
  135. __pInconsistency();
  136. }
  137. __except (EXCEPTION_EXECUTE_HANDLER) {
  138. //
  139. // Intercept ANY exception from the terminate handler
  140. //
  141. }
  142. //
  143. // If the inconsistency handler returned, faulted, or otherwise
  144. // failed to halt the process/thread, we'll do it.
  145. //
  146. terminate();
  147. }