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.

336 lines
7.2 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 >= g_byDebugLevel) && \
  106. ((g_fDebugComp & WANARP_STREAM_##Stream) == WANARP_STREAM_##Stream))\
  107. { \
  108. DbgPrint("[WANARP] "); \
  109. DbgPrint Str; \
  110. } \
  111. }
  112. #define TraceEnter(Stream, Str) Trace(Stream, TRACE, ("Entering "Str"\n"))
  113. #define TraceLeave(Stream, Str) Trace(Stream, TRACE, ("Leaving "Str"\n"))
  114. #else // RT_TRACE_DEBUG
  115. #define Trace(Stream, Level, Str)
  116. #define TraceEnter(Stream, Str)
  117. #define TraceLeave(Stream, Str)
  118. #endif // RT_TRACE_DEBUG
  119. #if RT_LOCK_DEBUG
  120. extern KSPIN_LOCK g_ksLockLock;
  121. #ifndef __FILE_SIG__
  122. #error File signature not defined
  123. #endif
  124. typedef struct _RT_LOCK
  125. {
  126. ULONG ulLockSig;
  127. BOOLEAN bAcquired;
  128. PKTHREAD pktLastThread;
  129. ULONG ulFileSig;
  130. ULONG ulLineNumber;
  131. KSPIN_LOCK kslLock;
  132. }RT_LOCK, *PRT_LOCK;
  133. VOID
  134. RtpInitializeSpinLock(
  135. IN PRT_LOCK pLock,
  136. IN ULONG ulFileSig,
  137. IN ULONG ulLineNumber
  138. );
  139. VOID
  140. RtpAcquireSpinLock(
  141. IN PRT_LOCK pLock,
  142. OUT PKIRQL pkiIrql,
  143. IN ULONG ulFileSig,
  144. IN ULONG ulLineNumber,
  145. IN BOOLEAN bAtDpc
  146. );
  147. VOID
  148. RtpReleaseSpinLock(
  149. IN PRT_LOCK pLock,
  150. IN KIRQL kiIrql,
  151. IN ULONG ulFileSig,
  152. IN ULONG ulLineNumber,
  153. IN BOOLEAN bFromDpc
  154. );
  155. #define RT_LOCK_SIG 'KCOL'
  156. #define RtInitializeSpinLock(X) RtpInitializeSpinLock((X), __FILE_SIG__, __LINE__)
  157. #define RtAcquireSpinLock(X, Y) RtpAcquireSpinLock((X), (Y), __FILE_SIG__, __LINE__, FALSE)
  158. #define RtAcquireSpinLockAtDpcLevel(X) RtpAcquireSpinLock((X), NULL, __FILE_SIG__, __LINE__, TRUE)
  159. #define RtReleaseSpinLock(X, Y) RtpReleaseSpinLock((X), (Y), __FILE_SIG__, __LINE__, FALSE)
  160. #define RtReleaseSpinLockFromDpcLevel(X) RtpReleaseSpinLock((X), 0, __FILE_SIG__, __LINE__, TRUE)
  161. #else // RT_LOCK_DEBUG
  162. typedef KSPIN_LOCK RT_LOCK, *PRT_LOCK;
  163. #define RtInitializeSpinLock KeInitializeSpinLock
  164. #define RtAcquireSpinLock KeAcquireSpinLock
  165. #define RtAcquireSpinLockAtDpcLevel KeAcquireSpinLockAtDpcLevel
  166. #define RtReleaseSpinLock KeReleaseSpinLock
  167. #define RtReleaseSpinLockFromDpcLevel KeReleaseSpinLockFromDpcLevel
  168. #endif // RT_LOCK_DEBUG
  169. #if RT_MEM_DEBUG
  170. #ifndef __FILE_SIG__
  171. #error File signature not defined
  172. #endif
  173. //
  174. // Memory Allocation/Freeing Audit:
  175. //
  176. //
  177. // The RT_ALLOCATION structure stores all info about one allocation
  178. //
  179. typedef struct _RT_ALLOCATION
  180. {
  181. LIST_ENTRY leLink;
  182. ULONG ulMemSig;
  183. ULONG ulFileSig;
  184. ULONG ulLineNumber;
  185. ULONG ulSize;
  186. UCHAR pucData[1];
  187. }RT_ALLOCATION, *PRT_ALLOCATION;
  188. //
  189. // The RT_FREE structure stores info about an allocation
  190. // that was freed. Later if the memory is touched, the
  191. // free list can be scanned to see where the allocation was
  192. // freed
  193. //
  194. typedef struct _RT_FREE
  195. {
  196. LIST_ENTRY leLink;
  197. UINT_PTR pStartAddr;
  198. ULONG ulSize;
  199. ULONG ulMemSig;
  200. ULONG ulAllocFileSig;
  201. ULONG ulAllocLineNumber;
  202. ULONG ulFreeFileSig;
  203. ULONG ulFreeLineNumber;
  204. }RT_FREE, *PRT_FREE;
  205. #define RT_MEMORY_SIG 'YRMM'
  206. #define RT_FREE_SIG 'EERF'
  207. PVOID
  208. RtpAllocate(
  209. IN POOL_TYPE ptPool,
  210. IN ULONG ulSize,
  211. IN ULONG ulTag,
  212. IN ULONG ulFileSig,
  213. IN ULONG ulLineNumber
  214. );
  215. VOID
  216. RtpFree(
  217. PVOID pvPointer,
  218. IN ULONG ulFileSig,
  219. IN ULONG ulLineNumber
  220. );
  221. VOID
  222. RtAuditMemory();
  223. #define RtAllocate(X, Y, Z) RtpAllocate((X), (Y), (Z), __FILE_SIG__, __LINE__)
  224. #define RtFree(X) RtpFree((X), __FILE_SIG__, __LINE__)
  225. #else // RT_MEM_DEBUG
  226. #define RtAllocate ExAllocatePoolWithTag
  227. #define RtFree ExFreePool
  228. #define RtAuditMemory()
  229. #endif // RT_MEM_DEBUG
  230. #endif // __RT_DEBUG_H__