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.

291 lines
7.7 KiB

  1. /********************************************************************/
  2. /** Microsoft Generic Packet Scheduler **/
  3. /** Copyright(c) Microsoft Corp., 1996-1997 **/
  4. /********************************************************************/
  5. #ifndef __GPCDBG
  6. #define __GPCDBG
  7. //*** gpcdbg.h - GPC definitions & prototypes for debug/memory handling
  8. //
  9. #define GPC_MEM_MARK 'KRAM'
  10. /*
  11. /////////////////////////////////////////////////////////////////
  12. //
  13. // defines
  14. //
  15. /////////////////////////////////////////////////////////////////
  16. */
  17. #if DBG
  18. #undef ASSERT
  19. #define ASSERT( Value ) \
  20. { \
  21. if ((ULONG_PTR)(Value) == 0) { \
  22. KdPrint(("** ASSERT Failed ** %s\n",#Value));\
  23. KdPrint(("Assert Failed at line %d in file %s\n",__LINE__,__FILE__));\
  24. DbgBreakPoint(); \
  25. } \
  26. }
  27. //
  28. // DBG=1
  29. //
  30. #define GpcAllocMem( _pAddress,_Length,_Tag ) \
  31. { \
  32. PCHAR _Addr; \
  33. ULONG _Size = (((_Length)+3)&0xfffffffc) + 3*sizeof(ULONG); \
  34. _Addr=ExAllocatePoolWithTag(NonPagedPool,_Size,_Tag ); \
  35. TRACE(MEMORY,_Addr+8,_Length,"GpcAllocMem"); \
  36. if (_Addr) { \
  37. NdisFillMemory(_Addr, _Size, 0x7f); \
  38. *(PULONG)_Addr = _Size; \
  39. *(PULONG)(_Addr+sizeof(ULONG)) = GPC_MEM_MARK; \
  40. *(PULONG)(_Addr+_Size-sizeof(ULONG)) = GPC_MEM_MARK; \
  41. (PVOID)(*_pAddress) = (PVOID)(_Addr + 2*sizeof(ULONG)); \
  42. BytesAllocated += _Size; \
  43. } else { \
  44. *_pAddress = NULL; \
  45. } \
  46. }
  47. #define GpcFreeMem( _Address,_Tag ) \
  48. { \
  49. PCHAR _Addr = ((PUCHAR)_Address) - 2*sizeof(ULONG); \
  50. ULONG _Size = *(PULONG)_Addr; \
  51. TRACE(MEMORY,_Address,_Size-12,"GpcFreeMem"); \
  52. ASSERT(*(PULONG)(_Addr+sizeof(ULONG)) == GPC_MEM_MARK); \
  53. ASSERT(*(PULONG)(_Addr+_Size-sizeof(ULONG)) == GPC_MEM_MARK); \
  54. NdisFillMemory(_Addr, _Size, 0xCC); \
  55. ExFreePool( _Addr ); \
  56. BytesAllocated -= _Size; \
  57. }
  58. #define GpcAllocFromLL(_ptr, _list, _tag) \
  59. { \
  60. PCHAR _Addr; \
  61. if (_Addr = (PCHAR)NdisAllocateFromNPagedLookasideList(_list)) { \
  62. *(PULONG)(_Addr) = GPC_MEM_MARK; \
  63. (PVOID)(*_ptr) = (PVOID)(_Addr + sizeof(ULONG_PTR)); \
  64. TRACE(MEMORY,_tag,*_ptr,"GpcAllocFromLL"); \
  65. } else { \
  66. *_ptr = NULL; \
  67. } \
  68. }
  69. #define GpcFreeToLL(_ptr, _list, _tag) \
  70. { \
  71. PCHAR _Addr = ((PUCHAR)_ptr) - sizeof(ULONG_PTR); \
  72. ASSERT(*(PULONG)_Addr == GPC_MEM_MARK); \
  73. *(PULONG)_Addr = 0x77777777; \
  74. NdisFreeToNPagedLookasideList(_list, _Addr); \
  75. TRACE(MEMORY,_tag,_ptr,"GpcFreeToLL"); \
  76. }
  77. #define GET_IRQL(_i) _i = KeGetCurrentIrql()
  78. #define VERIFY_IRQL(_i) ASSERT((_i)==KeGetCurrentIrql())
  79. #define DEFINE_KIRQL(_i) KIRQL _i
  80. #else // DBG != 1
  81. #define GpcAllocMem( Addr,Len,_Tag ) \
  82. *Addr = ExAllocatePoolWithTag(NonPagedPool, Len, _Tag )
  83. #define GpcFreeMem( Address,_Tag ) \
  84. ExFreePool( (Address) )
  85. #define GpcAllocFromLL(_ptr, _list, _tag) \
  86. *_ptr = NdisAllocateFromNPagedLookasideList(_list)
  87. #define GpcFreeToLL(_ptr, _list, _tag) \
  88. NdisFreeToNPagedLookasideList(_list, _ptr)
  89. #define GET_IRQL(_i)
  90. #define VERIFY_IRQL(_i)
  91. #define DEFINE_KIRQL(_i)
  92. #endif // if DBG
  93. #if DBG
  94. #define LockedIncrement( Count,_p ) LockedInc(Count,__FILE__,__LINE__,_p)
  95. #else
  96. #define LockedIncrement( Count,_p ) NdisInterlockedIncrement((PLONG)Count)
  97. #endif
  98. #if DBG
  99. #define LockedDecrement( Count,_p ) LockedDec(Count,__FILE__,__LINE__,_p)
  100. #else
  101. #define LockedDecrement( Count,_p ) NdisInterlockedDecrement((PLONG)Count)
  102. #endif
  103. #define KD_PRINT 0x00000001
  104. #define INIT 0x00000002
  105. #define BLOB 0x00000004
  106. #define PATTERN 0x00000008
  107. #define NOTIFY 0x00000010
  108. #define REGISTER 0x00000020
  109. #define MEMORY 0x00000040
  110. #define LOOKUP 0x00000080
  111. #define LOCKS 0x00000100
  112. #define CLASSIFY 0x00000200
  113. #define RHIZOME 0x00000400
  114. #define PATHASH 0x00000800
  115. #define IOCTL 0x00001000
  116. #define CLIENT 0x00002000
  117. #define MAPHAND 0x00004000
  118. #define CLASSHAND 0x00008000
  119. #define PAT_TIMER 0x00010000
  120. #define REFCOUNT 0x00020000
  121. #define PARAM_EX 0x80000000 // this is reserved for the trace routine
  122. #if DBG
  123. #define DBGPRINT(Mask, String) \
  124. { \
  125. if(Mask & DbgPrintFlags)\
  126. DbgPrint String;\
  127. }
  128. #define TRACE( Mask,P1,P2,_fname ) \
  129. { \
  130. if (Mask & DebugFlags)\
  131. TraceRtn((PUCHAR)__FILE__,(ULONG)__LINE__,_fname,(ULONG_PTR)(P1),(ULONG_PTR)(P2),KeGetCurrentProcessorNumber(),KeGetCurrentIrql(),Mask|PARAM_EX);\
  132. }
  133. #else
  134. #define DBGPRINT(Mask, String)
  135. #define TRACE( Mask,P1,P2,_fname )
  136. #endif
  137. /*
  138. /////////////////////////////////////////////////////////////////
  139. //
  140. // externs & prototypes
  141. //
  142. /////////////////////////////////////////////////////////////////
  143. */
  144. extern ULONG DebugFlags;
  145. extern ULONG DbgPrintFlags;
  146. extern ULONG BytesAllocated;
  147. VOID
  148. TraceRtn(
  149. IN UCHAR *File,
  150. IN ULONG Line,
  151. IN UCHAR *FuncName,
  152. IN ULONG_PTR Param1,
  153. IN ULONG_PTR Param2,
  154. IN ULONG Param3,
  155. IN ULONG Param4,
  156. IN ULONG Mask
  157. );
  158. _inline LONGLONG
  159. GetTime(
  160. VOID
  161. )
  162. /*++
  163. Routine Description:
  164. Get the current system time
  165. Arguments:
  166. Return Value:
  167. System time (in base OS time units)
  168. --*/
  169. {
  170. LARGE_INTEGER Now;
  171. LARGE_INTEGER Frequency;
  172. #if defined(PERF_COUNTER) || defined (TRACE_PERF_COUNTER)
  173. Now = KeQueryPerformanceCounter(&Frequency);
  174. Now.QuadPart = (Now.QuadPart * OS_TIME_SCALE) / Frequency.QuadPart;
  175. #else
  176. NdisGetCurrentSystemTime( &Now );
  177. #endif
  178. return Now.QuadPart;
  179. }
  180. #define LOGSIZE 4000 // number of entries
  181. #define LOGWIDTH 64 // number of characters (one or two bytes) per entry
  182. //
  183. //
  184. typedef struct {
  185. UCHAR Row[ LOGWIDTH ];
  186. LONGLONG Time;
  187. ULONG Line;
  188. ULONG_PTR P1;
  189. ULONG_PTR P2;
  190. ULONG P3;
  191. ULONG P4;
  192. } ROW, *PROW;
  193. typedef struct {
  194. ULONG Index;
  195. PROW Current;
  196. PROW Buffer;
  197. ULONG Wraps;
  198. } LOG, *PLOG;
  199. _inline VOID
  200. DbgVerifyList(
  201. PLIST_ENTRY h
  202. )
  203. {
  204. PLIST_ENTRY p = h->Flink;
  205. PLIST_ENTRY q = h;
  206. int m = 1000;
  207. if (h->Flink == h) {
  208. ASSERT(h->Blink == h);
  209. }
  210. while (p != h && m > 0) {
  211. ASSERT(p->Blink == q);
  212. q = p;
  213. p = p->Flink;
  214. m--;
  215. }
  216. ASSERT(m > 0);
  217. }
  218. #endif //__GPCDBG