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.

333 lines
6.9 KiB

  1. /*
  2. * debspew.h - Debug macros and their retail translations.
  3. *
  4. * Taken from URL code by ChrisPi 9-11-95
  5. *
  6. */
  7. #ifndef _DEBSPEW_H_
  8. #define _DEBSPEW_H_
  9. #ifdef __cplusplus
  10. extern "C" {
  11. #endif /* __cplusplus */
  12. #include <tchar.h>
  13. #include <limits.h>
  14. #include <shlobj.h>
  15. #include "stock.h"
  16. #include "olestock.h"
  17. #ifdef DEBUG
  18. #include "resstr.h"
  19. #endif /* DEBUG */
  20. #include "valid.h"
  21. #define DATA_SEG_READ_ONLY ".text"
  22. #define DATA_SEG_PER_INSTANCE ".data"
  23. #define DATA_SEG_SHARED ".shared"
  24. /* parameter validation macros */
  25. /*
  26. * call as:
  27. *
  28. * bPTwinOK = IS_VALID_READ_PTR(ptwin, CTWIN);
  29. *
  30. * bHTwinOK = IS_VALID_HANDLE(htwin, TWIN);
  31. */
  32. #ifdef DEBUG
  33. #define IS_VALID_READ_PTR(ptr, type) \
  34. (IsBadReadPtr((ptr), sizeof(type)) ? \
  35. (ERROR_OUT(("invalid %s read pointer - %#08lx", (PCSTR)"P"#type, (ptr))), FALSE) : \
  36. TRUE)
  37. #define IS_VALID_WRITE_PTR(ptr, type) \
  38. (IsBadWritePtr((PVOID)(ptr), sizeof(type)) ? \
  39. (ERROR_OUT(("invalid %s write pointer - %#08lx", (PCSTR)"P"#type, (ptr))), FALSE) : \
  40. TRUE)
  41. #define IS_VALID_STRING_PTR_A(ptr, type) \
  42. (IsBadStringPtrA((ptr), (UINT)-1) ? \
  43. (ERROR_OUT(("invalid %s pointer - %#08lx", (PCSTR)"P"#type, (ptr))), FALSE) : \
  44. TRUE)
  45. #define IS_VALID_STRING_PTR_W(ptr, type) \
  46. (IsBadStringPtrW((ptr), (UINT)-1) ? \
  47. (ERROR_OUT(("invalid %s pointer - %#08lx", (PCSTR)"P"#type, (ptr))), FALSE) : \
  48. TRUE)
  49. #if defined(UNICODE)
  50. #define IS_VALID_STRING_PTR IS_VALID_STRING_PTR_W
  51. #else // defined(UNICODE)
  52. #define IS_VALID_STRING_PTR IS_VALID_STRING_PTR_A
  53. #endif // defined(UNICODE)
  54. #define IS_VALID_CODE_PTR(ptr, type) \
  55. (IsBadCodePtr((FARPROC)(ptr)) ? \
  56. (ERROR_OUT(("invalid %s code pointer - %#08lx", (PCSTR)#type, (ptr))), FALSE) : \
  57. TRUE)
  58. #define IS_VALID_READ_BUFFER_PTR(ptr, type, len) \
  59. (IsBadReadPtr((ptr), len) ? \
  60. (ERROR_OUT(("invalid %s read pointer - %#08lx", (PCSTR)"P"#type, (ptr))), FALSE) : \
  61. TRUE)
  62. #define IS_VALID_WRITE_BUFFER_PTR(ptr, type, len) \
  63. (IsBadWritePtr((ptr), len) ? \
  64. (ERROR_OUT(("invalid %s write pointer - %#08lx", (PCSTR)"P"#type, (ptr))), FALSE) : \
  65. TRUE)
  66. #define FLAGS_ARE_VALID(dwFlags, dwAllFlags) \
  67. (((dwFlags) & (~(dwAllFlags))) ? \
  68. (ERROR_OUT(("invalid flags set - %#08lx", ((dwFlags) & (~(dwAllFlags))))), FALSE) : \
  69. TRUE)
  70. #else
  71. #define IS_VALID_READ_PTR(ptr, type) \
  72. (! IsBadReadPtr((ptr), sizeof(type)))
  73. #define IS_VALID_WRITE_PTR(ptr, type) \
  74. (! IsBadWritePtr((PVOID)(ptr), sizeof(type)))
  75. #define IS_VALID_STRING_PTR(ptr, type) \
  76. (! IsBadStringPtr((ptr), (UINT)-1))
  77. #define IS_VALID_CODE_PTR(ptr, type) \
  78. (! IsBadCodePtr((FARPROC)(ptr)))
  79. #define IS_VALID_READ_BUFFER_PTR(ptr, type, len) \
  80. (! IsBadReadPtr((ptr), len))
  81. #define IS_VALID_WRITE_BUFFER_PTR(ptr, type, len) \
  82. (! IsBadWritePtr((ptr), len))
  83. #define FLAGS_ARE_VALID(dwFlags, dwAllFlags) \
  84. (((dwFlags) & (~(dwAllFlags))) ? FALSE : TRUE)
  85. #endif
  86. /* handle validation macros */
  87. #ifdef DEBUG
  88. #define IS_VALID_HANDLE(hnd, type) \
  89. (IsValidH##type(hnd) ? \
  90. TRUE : \
  91. (ERROR_OUT(("invalid H" #type " - %#08lx", (hnd))), FALSE))
  92. #else
  93. #define IS_VALID_HANDLE(hnd, type) \
  94. (IsValidH##type(hnd))
  95. #endif
  96. /* structure validation macros */
  97. #ifdef VSTF
  98. #ifdef DEBUG
  99. #define IS_VALID_STRUCT_PTR(ptr, type) \
  100. (IsValidP##type(ptr) ? \
  101. TRUE : \
  102. (ERROR_OUT(("invalid %s pointer - %#08lx", (PCSTR)"P"#type, (ptr))), FALSE))
  103. #else
  104. #define IS_VALID_STRUCT_PTR(ptr, type) \
  105. (IsValidP##type(ptr))
  106. #endif
  107. #else
  108. #define IS_VALID_STRUCT_PTR(ptr, type) \
  109. (! IsBadReadPtr((ptr), sizeof(type)))
  110. #endif
  111. /* OLE interface validation macro */
  112. #define IS_VALID_INTERFACE_PTR(ptr, iface) \
  113. IS_VALID_STRUCT_PTR(ptr, C##iface)
  114. #ifdef DEBUG
  115. #define CALLTRACE_OUT(s) DbgZPrintFunction s
  116. #define DebugEntry(szFunctionName) \
  117. (CALLTRACE_OUT((#szFunctionName "() entered.")))
  118. #define DebugExit(szFunctionName, szResult) \
  119. (CALLTRACE_OUT(("%s() exiting, returning %s.", #szFunctionName, szResult)))
  120. #define DebugExitBOOL(szFunctionName, bool) \
  121. DebugExit(szFunctionName, GetBOOLString(bool))
  122. #define DebugExitCOMPARISONRESULT(szFunctionName, cr) \
  123. DebugExit(szFunctionName, GetCOMPARISONRESULTString(cr))
  124. #define DebugExitDWORD(szFunctionName, dw) \
  125. DebugExitULONG(szFunctionName, dw)
  126. #define DebugExitHRESULT(szFunctionName, hr) \
  127. DebugExit(szFunctionName, GetHRESULTString(hr))
  128. #define DebugExitINT(szFunctionName, n) \
  129. DebugExit(szFunctionName, GetINTString(n))
  130. #define DebugExitINT_PTR(szFunctionName, n) \
  131. DebugExit(szFunctionName, GetINT_PTRString(n))
  132. #define DebugExitULONG(szFunctionName, ul) \
  133. DebugExit(szFunctionName, GetULONGString(ul))
  134. #define DebugExitVOID(szFunctionName) \
  135. (CALLTRACE_OUT(("%s() exiting.", #szFunctionName)))
  136. #define DebugExitPVOID(szFunctionName, ptr) \
  137. DebugExit(szFunctionName, GetPVOIDString(ptr))
  138. #else
  139. #define DebugEntry(szFunctionName)
  140. #define DebugExit(szFunctionName, szResult)
  141. #define DebugExitBOOL(szFunctionName, bool)
  142. #define DebugExitCOMPARISONRESULT(szFunctionName, cr)
  143. #define DebugExitDWORD(szFunctionName, dw)
  144. #define DebugExitHRESULT(szFunctionName, hr)
  145. #define DebugExitINT(szFunctionName, n)
  146. #define DebugExitINT_PTR(szFunctionName, n)
  147. #define DebugExitULONG(szFunctionName, ul)
  148. #define DebugExitVOID(szFunctionName)
  149. #define DebugExitPVOID(szFunctionName, ptr)
  150. #endif
  151. /* Types
  152. ********/
  153. /* g_dwSpewFlags flags */
  154. typedef enum _spewflags
  155. {
  156. SPEW_FL_SPEW_PREFIX = 0x0001,
  157. SPEW_FL_SPEW_LOCATION = 0x0002,
  158. ALL_SPEW_FLAGS = (SPEW_FL_SPEW_PREFIX |
  159. SPEW_FL_SPEW_LOCATION)
  160. }
  161. SPEWFLAGS;
  162. /* g_uSpewSev values */
  163. typedef enum _spewsev
  164. {
  165. SPEW_TRACE,
  166. SPEW_CALLTRACE,
  167. SPEW_WARNING,
  168. SPEW_ERROR,
  169. SPEW_FATAL
  170. }
  171. SPEWSEV;
  172. /* Prototypes
  173. *************/
  174. /* debspew.c */
  175. #ifdef DEBUG
  176. extern BOOL SetDebugModuleIniSwitches(void);
  177. extern BOOL InitDebugModule(PCSTR);
  178. extern void ExitDebugModule(void);
  179. extern void SpewOut(PCSTR pcszFormat, ...);
  180. extern DWORD GetDebugOutputFlags(VOID);
  181. extern VOID SetDebugOutputFlags(DWORD dw);
  182. #else // DEBUG
  183. #define SetDebugModuleIniSwitches()
  184. #define InitDebugModule(str)
  185. #define ExitDebugModule()
  186. //#define SpewOut(fmt, ...)
  187. #define GetDebugOutputFlags()
  188. #define SetDebugOutputFlags(dw)
  189. #endif // DEBUG
  190. /* Global Variables
  191. *******************/
  192. #ifdef DEBUG
  193. /* dbg.cpp */
  194. extern HDBGZONE ghDbgZone;
  195. /* debspew.c */
  196. extern DWORD g_dwSpewFlags;
  197. extern UINT g_uSpewSev;
  198. extern UINT g_uSpewLine;
  199. extern PCSTR g_pcszSpewFile;
  200. extern WINDOWPLACEMENT g_wpSpew;
  201. /* defined by client */
  202. extern PCSTR g_pcszSpewModule;
  203. #endif
  204. /*
  205. * EVAL() may only be used as a logical expression.
  206. *
  207. * E.g.,
  208. *
  209. * if (EVAL(exp))
  210. * bResult = TRUE;
  211. */
  212. #ifdef DEBUG
  213. #define EVAL(exp) \
  214. ((exp) || \
  215. (ERROR_OUT(("evaluation failed '%s'", (PCSTR)#exp)), 0))
  216. #else
  217. #define EVAL(exp) \
  218. ((exp) != 0)
  219. #endif /* DEBUG */
  220. #ifdef __cplusplus
  221. }
  222. #endif /* __cplusplus */
  223. #endif /* _DEBSPEW_H_ */