Leaked source code of windows server 2003
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.

152 lines
4.0 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. #include <windows.h>
  37. #include <mtdll.h>
  38. #include <eh.h>
  39. #include <ehhooks.h>
  40. #include <ehassert.h>
  41. #pragma hdrstop
  42. /////////////////////////////////////////////////////////////////////////////
  43. //
  44. // The global variables:
  45. //
  46. #ifndef _MT
  47. _se_translator_function __pSETranslator = NULL;
  48. terminate_function __pTerminate = NULL;
  49. unexpected_function __pUnexpected = &terminate;
  50. #endif // !_MT
  51. _inconsistency_function __pInconsistency= &terminate;
  52. /////////////////////////////////////////////////////////////////////////////
  53. //
  54. // terminate - call the terminate handler (presumably we went south).
  55. // THIS MUST NEVER RETURN!
  56. //
  57. // Open issues:
  58. // * How do we guarantee that the whole process has stopped, and not just
  59. // the current thread?
  60. //
  61. _CRTIMP void __cdecl terminate(void)
  62. {
  63. EHTRACE_ENTER_MSG("No exit");
  64. //
  65. // Let the user wrap things up their way.
  66. //
  67. if ( __pTerminate ) {
  68. __try {
  69. __pTerminate();
  70. }
  71. __except (EXCEPTION_EXECUTE_HANDLER) {
  72. //
  73. // Intercept ANY exception from the terminate handler
  74. //
  75. }
  76. }
  77. //
  78. // If the terminate handler returned, faulted, or otherwise failed to
  79. // halt the process/thread, we'll do it.
  80. //
  81. abort();
  82. }
  83. /////////////////////////////////////////////////////////////////////////////
  84. //
  85. // unexpected - call the unexpected handler (presumably we went south, or nearly).
  86. // THIS MUST NEVER RETURN!
  87. //
  88. // Open issues:
  89. // * How do we guarantee that the whole process has stopped, and not just
  90. // the current thread?
  91. //
  92. void __cdecl unexpected(void)
  93. {
  94. EHTRACE_ENTER;
  95. //
  96. // Let the user wrap things up their way.
  97. //
  98. if ( __pUnexpected )
  99. __pUnexpected();
  100. //
  101. // If the unexpected handler returned, we'll give the terminate handler a chance.
  102. //
  103. terminate();
  104. }
  105. /////////////////////////////////////////////////////////////////////////////
  106. //
  107. // _inconsistency - call the inconsistency handler (Run-time processing error!)
  108. // THIS MUST NEVER RETURN!
  109. //
  110. // Open issues:
  111. // * How do we guarantee that the whole process has stopped, and not just
  112. // the current thread?
  113. //
  114. void __cdecl _inconsistency(void)
  115. {
  116. EHTRACE_ENTER;
  117. //
  118. // Let the user wrap things up their way.
  119. //
  120. if ( __pInconsistency )
  121. __try {
  122. __pInconsistency();
  123. }
  124. __except (EXCEPTION_EXECUTE_HANDLER) {
  125. //
  126. // Intercept ANY exception from the terminate handler
  127. //
  128. }
  129. //
  130. // If the inconsistency handler returned, faulted, or otherwise
  131. // failed to halt the process/thread, we'll do it.
  132. //
  133. terminate();
  134. }