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.

337 lines
7.0 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. debug.h
  5. Abstract:
  6. Debug macros for the ARP module
  7. Revision History:
  8. Notes:
  9. --*/
  10. #ifndef __RT_DEBUG_H__
  11. #define __RT_DEBUG_H__
  12. VOID
  13. RtInitializeDebug();
  14. //
  15. // Tags for Pools
  16. //
  17. #define WAN_ADAPTER_TAG 'aprW'
  18. #define WAN_INTERFACE_TAG 'iprW'
  19. #define WAN_REQUEST_TAG 'rprW'
  20. #define WAN_STRING_TAG 'sprW'
  21. #define WAN_CONN_TAG 'cprW'
  22. #define WAN_PACKET_TAG 'wPDN'
  23. #define FREE_TAG 'fprW'
  24. #define WAN_DATA_TAG 'dprW'
  25. #define WAN_HEADER_TAG 'hprW'
  26. #define WAN_NOTIFICATION_TAG 'nprW'
  27. //
  28. // File signatures for everyone
  29. //
  30. #define DEBUG_SIG 'gbed'
  31. #define DRIVER_SIG 'rvrd'
  32. #define BPOOL_SIG 'lopb'
  33. #define PPOOL_SIG 'lopp'
  34. #define ADAPTER_SIG 'tpdA'
  35. #define IOCTL_SIG 'tcoi'
  36. #define CONN_SIG 'nnoc'
  37. #define INFO_SIG 'ofni'
  38. #define RCV_SIG 'vcer'
  39. #define SEND_SIG 'dnes'
  40. #define GUID_SIG 'diug'
  41. //
  42. // We use the RT_XXX_DEBUG flags so that we can force to
  43. // different debug modes on free builds by changing sources.
  44. // On a checked build, all debugging is on
  45. //
  46. #if DBG
  47. #ifndef RT_TRACE_DEBUG
  48. #define RT_TRACE_DEBUG 1
  49. #endif
  50. #ifndef RT_LOCK_DEBUG
  51. #define RT_LOCK_DEBUG 1
  52. #endif
  53. #ifndef RT_ASSERT_ON
  54. #define RT_ASSERT_ON 1
  55. #endif
  56. #ifndef RT_MEM_DEBUG
  57. #define RT_MEM_DEBUG 1
  58. #endif
  59. #else // DBG
  60. #ifndef RT_TRACE_DEBUG
  61. #define RT_TRACE_DEBUG 0
  62. #endif
  63. #ifndef RT_LOCK_DEBUG
  64. #define RT_LOCK_DEBUG 0
  65. #endif
  66. #ifndef RT_ASSERT_ON
  67. #define RT_ASSERT_ON 0
  68. #endif
  69. #ifndef RT_MEM_DEBUG
  70. #define RT_MEM_DEBUG 0
  71. #endif
  72. #endif // DBG
  73. #if RT_ASSERT_ON
  74. #define RtAssert(X) \
  75. { \
  76. if(!(X)) \
  77. { \
  78. DbgPrint("[WANARP] Assertion failed in %s at line %d\n",\
  79. __FILE__,__LINE__); \
  80. DbgPrint("WANARP: Assertion " #X "\n"); \
  81. DbgBreakPoint(); \
  82. } \
  83. }
  84. #else // RT_ASSERT_ON
  85. #define RtAssert(X)
  86. #endif
  87. #if RT_TRACE_DEBUG
  88. BYTE g_byDebugLevel;
  89. DWORD g_fDebugComp;
  90. #define WANARP_STREAM_GLOBAL 0x00000001
  91. #define WANARP_STREAM_MEMORY 0x00000002
  92. #define WANARP_STREAM_ADPT 0x00000004
  93. #define WANARP_STREAM_CONN 0x00000008
  94. #define WANARP_STREAM_SEND 0x00000010
  95. #define WANARP_STREAM_RCV 0x00000020
  96. #define WANARP_STREAM_UTIL 0x00000040
  97. #define RT_DBG_LEVEL_NONE 0xFF
  98. #define RT_DBG_LEVEL_FATAL 0xF0
  99. #define RT_DBG_LEVEL_ERROR 0xE0
  100. #define RT_DBG_LEVEL_WARN 0xD0
  101. #define RT_DBG_LEVEL_INFO 0xC0
  102. #define RT_DBG_LEVEL_TRACE 0xB0
  103. #define Trace(Stream, Level, Str) \
  104. { \
  105. if ((RT_DBG_LEVEL_##Level >= RT_DBG_LEVEL_ERROR) || \
  106. ((RT_DBG_LEVEL_##Level >= g_byDebugLevel) && \
  107. ((g_fDebugComp & WANARP_STREAM_##Stream) == WANARP_STREAM_##Stream)))\
  108. { \
  109. DbgPrint("[WANARP] "); \
  110. DbgPrint Str; \
  111. } \
  112. }
  113. #define TraceEnter(Stream, Str) Trace(Stream, TRACE, ("Entering "Str"\n"))
  114. #define TraceLeave(Stream, Str) Trace(Stream, TRACE, ("Leaving "Str"\n"))
  115. #else // RT_TRACE_DEBUG
  116. #define Trace(Stream, Level, Str)
  117. #define TraceEnter(Stream, Str)
  118. #define TraceLeave(Stream, Str)
  119. #endif // RT_TRACE_DEBUG
  120. #if RT_LOCK_DEBUG
  121. extern KSPIN_LOCK g_ksLockLock;
  122. #ifndef __FILE_SIG__
  123. #error File signature not defined
  124. #endif
  125. typedef struct _RT_LOCK
  126. {
  127. ULONG ulLockSig;
  128. BOOLEAN bAcquired;
  129. PKTHREAD pktLastThread;
  130. ULONG ulFileSig;
  131. ULONG ulLineNumber;
  132. KSPIN_LOCK kslLock;
  133. }RT_LOCK, *PRT_LOCK;
  134. VOID
  135. RtpInitializeSpinLock(
  136. IN PRT_LOCK pLock,
  137. IN ULONG ulFileSig,
  138. IN ULONG ulLineNumber
  139. );
  140. VOID
  141. RtpAcquireSpinLock(
  142. IN PRT_LOCK pLock,
  143. OUT PKIRQL pkiIrql,
  144. IN ULONG ulFileSig,
  145. IN ULONG ulLineNumber,
  146. IN BOOLEAN bAtDpc
  147. );
  148. VOID
  149. RtpReleaseSpinLock(
  150. IN PRT_LOCK pLock,
  151. IN KIRQL kiIrql,
  152. IN ULONG ulFileSig,
  153. IN ULONG ulLineNumber,
  154. IN BOOLEAN bFromDpc
  155. );
  156. #define RT_LOCK_SIG 'KCOL'
  157. #define RtInitializeSpinLock(X) RtpInitializeSpinLock((X), __FILE_SIG__, __LINE__)
  158. #define RtAcquireSpinLock(X, Y) RtpAcquireSpinLock((X), (Y), __FILE_SIG__, __LINE__, FALSE)
  159. #define RtAcquireSpinLockAtDpcLevel(X) RtpAcquireSpinLock((X), NULL, __FILE_SIG__, __LINE__, TRUE)
  160. #define RtReleaseSpinLock(X, Y) RtpReleaseSpinLock((X), (Y), __FILE_SIG__, __LINE__, FALSE)
  161. #define RtReleaseSpinLockFromDpcLevel(X) RtpReleaseSpinLock((X), 0, __FILE_SIG__, __LINE__, TRUE)
  162. #else // RT_LOCK_DEBUG
  163. typedef KSPIN_LOCK RT_LOCK, *PRT_LOCK;
  164. #define RtInitializeSpinLock KeInitializeSpinLock
  165. #define RtAcquireSpinLock KeAcquireSpinLock
  166. #define RtAcquireSpinLockAtDpcLevel KeAcquireSpinLockAtDpcLevel
  167. #define RtReleaseSpinLock KeReleaseSpinLock
  168. #define RtReleaseSpinLockFromDpcLevel KeReleaseSpinLockFromDpcLevel
  169. #endif // RT_LOCK_DEBUG
  170. #if RT_MEM_DEBUG
  171. #ifndef __FILE_SIG__
  172. #error File signature not defined
  173. #endif
  174. //
  175. // Memory Allocation/Freeing Audit:
  176. //
  177. //
  178. // The RT_ALLOCATION structure stores all info about one allocation
  179. //
  180. typedef struct _RT_ALLOCATION
  181. {
  182. LIST_ENTRY leLink;
  183. ULONG ulMemSig;
  184. ULONG ulFileSig;
  185. ULONG ulLineNumber;
  186. ULONG ulSize;
  187. UCHAR pucData[1];
  188. }RT_ALLOCATION, *PRT_ALLOCATION;
  189. //
  190. // The RT_FREE structure stores info about an allocation
  191. // that was freed. Later if the memory is touched, the
  192. // free list can be scanned to see where the allocation was
  193. // freed
  194. //
  195. typedef struct _RT_FREE
  196. {
  197. LIST_ENTRY leLink;
  198. UINT_PTR pStartAddr;
  199. ULONG ulSize;
  200. ULONG ulMemSig;
  201. ULONG ulAllocFileSig;
  202. ULONG ulAllocLineNumber;
  203. ULONG ulFreeFileSig;
  204. ULONG ulFreeLineNumber;
  205. }RT_FREE, *PRT_FREE;
  206. #define RT_MEMORY_SIG 'YRMM'
  207. #define RT_FREE_SIG 'EERF'
  208. PVOID
  209. RtpAllocate(
  210. IN POOL_TYPE ptPool,
  211. IN ULONG ulSize,
  212. IN ULONG ulTag,
  213. IN ULONG ulFileSig,
  214. IN ULONG ulLineNumber
  215. );
  216. VOID
  217. RtpFree(
  218. PVOID pvPointer,
  219. IN ULONG ulFileSig,
  220. IN ULONG ulLineNumber
  221. );
  222. VOID
  223. RtAuditMemory();
  224. #define RtAllocate(X, Y, Z) RtpAllocate((X), (Y), (Z), __FILE_SIG__, __LINE__)
  225. #define RtFree(X) RtpFree((X), __FILE_SIG__, __LINE__)
  226. #else // RT_MEM_DEBUG
  227. #define RtAllocate ExAllocatePoolWithTag
  228. #define RtFree ExFreePool
  229. #define RtAuditMemory()
  230. #endif // RT_MEM_DEBUG
  231. #endif // __RT_DEBUG_H__