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.

137 lines
4.9 KiB

  1. /***
  2. *ehassert.h - our own little versions of the assert macros.
  3. *
  4. * Copyright (c) 1993-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * Versions of the assert macros for exception handling.
  8. *
  9. * [Internal]
  10. *
  11. *Revision History:
  12. * 09-02-94 SKS This header file added.
  13. * 12-15-94 XY merged with mac header
  14. * 02-14-95 CFW Clean up Mac merge.
  15. * 03-29-95 CFW Add error message to internal headers.
  16. * 04-13-95 DAK Add NT Kernel EH support
  17. * 12-14-95 JWM Add "#pragma once".
  18. * 02-24-97 GJF Detab-ed.
  19. * 05-17-99 PML Remove all Macintosh support.
  20. * 10-22-99 PML Add EHTRACE support
  21. *
  22. ****/
  23. #if _MSC_VER > 1000 /*IFSTRIP=IGN*/
  24. #pragma once
  25. #endif
  26. #ifndef _INC_EHASSERT
  27. #define _INC_EHASSERT
  28. #ifndef _CRTBLD
  29. /*
  30. * This is an internal C runtime header file. It is used when building
  31. * the C runtimes only. It is not to be used as a public header file.
  32. */
  33. #error ERROR: Use of C runtime library internal header file.
  34. #endif /* _CRTBLD */
  35. #include <windows.h>
  36. #ifdef DEBUG
  37. #include <stdio.h>
  38. #include <stdlib.h>
  39. int __cdecl dprintf( char *, ... );
  40. #ifdef _NTSUBSET_
  41. #define DASSERT(c) ((c)?0: \
  42. (DbgPrint("Runtime internal error (%s, line %d)", __FILE__, __LINE__),\
  43. terminate()))
  44. #define DEXPECT(c) ((c)?0: \
  45. DbgPrint("Runtime internal error suspected (%s, line %d)", __FILE__, __LINE__))
  46. #else /* _NTSUBSET_ */
  47. #define DASSERT(c) ((c)?0: \
  48. (printf("Runtime internal error (%s, line %d)", __FILE__, __LINE__),\
  49. terminate()))
  50. #define DEXPECT(c) ((c)?0: \
  51. printf("Runtime internal error suspected (%s, line %d)", __FILE__, __LINE__))
  52. #endif /* _NTSUBSET_ */
  53. #else
  54. // Disable dprintf output
  55. #define dprintf
  56. #define DASSERT(c) ((c)?0:_inconsistency())
  57. #define DEXPECT(c) (c)
  58. #endif
  59. #define CHECKPTR(p) (_ValidateRead((p),sizeof(typeof(*(p))))
  60. #define CHECKCODE(p) (_ValidateExecute( (FARPROC)(p) )
  61. BOOL _ValidateRead( const void *data, UINT size = sizeof(char) );
  62. BOOL _ValidateWrite( void *data, UINT size = sizeof(char) );
  63. BOOL _ValidateExecute( FARPROC code );
  64. #if defined(ENABLE_EHTRACE) && (_MSC_VER >= 1300)
  65. // Warning: EH tracing can only be used in a single thread because this tracing
  66. // level global is not per-thread.
  67. extern int __ehtrace_level;
  68. void __cdecl EHTraceOutput(const char *format, ...);
  69. const char * EHTraceIndent(int level);
  70. const char * EHTraceFunc(const char *func);
  71. void EHTracePushLevel(int new_level);
  72. void EHTracePopLevel(bool restore);
  73. int EHTraceExceptFilter(const char *func, int expr);
  74. void EHTraceHandlerReturn(const char *func, int level, EXCEPTION_DISPOSITION result);
  75. #define EHTRACE_INIT int __ehtrace_local_level; __ehtrace_local_level = ++__ehtrace_level
  76. #define EHTRACE_RESET __ehtrace_level = 0
  77. #define EHTRACE_SAVE_LEVEL EHTracePushLevel(__ehtrace_local_level)
  78. #define EHTRACE_RESTORE_LEVEL(x) EHTracePopLevel(x)
  79. #define EHTRACE_ENTER EHTRACE_INIT; \
  80. EHTraceOutput( "Enter: %s%s\n", EHTraceIndent(__ehtrace_local_level), EHTraceFunc(__FUNCTION__) )
  81. #define EHTRACE_ENTER_MSG(x) EHTRACE_INIT; \
  82. EHTraceOutput( "Enter: %s%s: %s\n", EHTraceIndent(__ehtrace_local_level), EHTraceFunc(__FUNCTION__), x )
  83. #define EHTRACE_ENTER_FMT1(x,y) EHTRACE_INIT; \
  84. EHTraceOutput( "Enter: %s%s: " x "\n", EHTraceIndent(__ehtrace_local_level), EHTraceFunc(__FUNCTION__), y )
  85. #define EHTRACE_ENTER_FMT2(x,y,z) EHTRACE_INIT; \
  86. EHTraceOutput( "Enter: %s%s: " x "\n", EHTraceIndent(__ehtrace_local_level), EHTraceFunc(__FUNCTION__), y, z )
  87. #define EHTRACE_MSG(x) EHTraceOutput( "In : %s%s: %s\n", EHTraceIndent(__ehtrace_local_level), EHTraceFunc(__FUNCTION__), x )
  88. #define EHTRACE_FMT1(x,y) EHTraceOutput( "In : %s%s: " x "\n", EHTraceIndent(__ehtrace_local_level), EHTraceFunc(__FUNCTION__), y )
  89. #define EHTRACE_FMT2(x,y,z) EHTraceOutput( "In : %s%s: " x "\n", EHTraceIndent(__ehtrace_local_level), EHTraceFunc(__FUNCTION__), y, z )
  90. #define EHTRACE_EXCEPT(x) EHTRACE_SAVE_LEVEL, EHTraceExceptFilter( __FUNCTION__, x )
  91. #define EHTRACE_EXIT --__ehtrace_level
  92. #define EHTRACE_HANDLER_EXIT(x) EHTraceHandlerReturn( __FUNCTION__, __ehtrace_local_level, x); \
  93. EHTRACE_EXIT
  94. #else
  95. #define EHTRACE_RESET
  96. #define EHTRACE_SAVE_LEVEL
  97. #define EHTRACE_RESTORE_LEVEL(x)
  98. #define EHTRACE_ENTER
  99. #define EHTRACE_ENTER_MSG(x)
  100. #define EHTRACE_ENTER_FMT1(x,y)
  101. #define EHTRACE_ENTER_FMT2(x,y,z)
  102. #define EHTRACE_MSG(x)
  103. #define EHTRACE_FMT1(x,y)
  104. #define EHTRACE_FMT2(x,y,z)
  105. #define EHTRACE_EXCEPT(x) (x)
  106. #define EHTRACE_EXIT
  107. #define EHTRACE_HANDLER_EXIT(x)
  108. #endif /* ENABLE_EHTRACE */
  109. #endif /* _INC_EHASSERT */