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.

329 lines
10 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 GpcAllocMemWithQuota( _pAddress,_Length,_Tag ) \
  48. { \
  49. PCHAR _Addr; \
  50. ULONG _Size = (((_Length)+3)&0xfffffffc) + 3*sizeof(ULONG); \
  51. try{ \
  52. _Addr=ExAllocatePoolWithQuotaTag(NonPagedPool,_Size,_Tag ); \
  53. } \
  54. except( EXCEPTION_EXECUTE_HANDLER) { \
  55. _Addr=NULL; \
  56. } \
  57. TRACE(MEMORY,_Addr+8,_Length,"GpcAllocMem"); \
  58. if (_Addr) { \
  59. NdisFillMemory(_Addr, _Size, 0x7f); \
  60. *(PULONG)_Addr = _Size; \
  61. *(PULONG)(_Addr+sizeof(ULONG)) = GPC_MEM_MARK; \
  62. *(PULONG)(_Addr+_Size-sizeof(ULONG)) = GPC_MEM_MARK; \
  63. (PVOID)(*_pAddress) = (PVOID)(_Addr + 2*sizeof(ULONG)); \
  64. BytesAllocated += _Size; \
  65. } else { \
  66. *_pAddress = NULL; \
  67. } \
  68. }
  69. #define GpcFreeMem( _Address,_Tag ) \
  70. { \
  71. PCHAR _Addr = ((PUCHAR)_Address) - 2*sizeof(ULONG); \
  72. ULONG _Size = *(PULONG)_Addr; \
  73. TRACE(MEMORY,_Address,_Size-12,"GpcFreeMem"); \
  74. ASSERT(*(PULONG)(_Addr+sizeof(ULONG)) == GPC_MEM_MARK); \
  75. ASSERT(*(PULONG)(_Addr+_Size-sizeof(ULONG)) == GPC_MEM_MARK); \
  76. NdisFillMemory(_Addr, _Size, 0xCC); \
  77. ExFreePool( _Addr ); \
  78. BytesAllocated -= _Size; \
  79. }
  80. #define GpcAllocFromLL(_ptr, _list, _tag) \
  81. { \
  82. PCHAR _Addr; \
  83. if (_Addr = (PCHAR)NdisAllocateFromNPagedLookasideList(_list)) { \
  84. *(PULONG)(_Addr) = GPC_MEM_MARK; \
  85. (PVOID)(*_ptr) = (PVOID)(_Addr + sizeof(ULONG_PTR)); \
  86. TRACE(MEMORY,_tag,*_ptr,"GpcAllocFromLL"); \
  87. } else { \
  88. *_ptr = NULL; \
  89. } \
  90. }
  91. #define GpcFreeToLL(_ptr, _list, _tag) \
  92. { \
  93. PCHAR _Addr = ((PUCHAR)_ptr) - sizeof(ULONG_PTR); \
  94. ASSERT(*(PULONG)_Addr == GPC_MEM_MARK); \
  95. *(PULONG)_Addr = 0x77777777; \
  96. NdisFreeToNPagedLookasideList(_list, _Addr); \
  97. TRACE(MEMORY,_tag,_ptr,"GpcFreeToLL"); \
  98. }
  99. #define GET_IRQL(_i) _i = KeGetCurrentIrql()
  100. #define VERIFY_IRQL(_i) ASSERT((_i)==KeGetCurrentIrql())
  101. #define DEFINE_KIRQL(_i) KIRQL _i
  102. #else // DBG != 1
  103. #define GpcAllocMem( Addr,Len,_Tag ) \
  104. *Addr = ExAllocatePoolWithTag(NonPagedPool, Len, _Tag )
  105. #define GpcAllocMemWithQuota( Addr,Len,_Tag ) \
  106. try{ \
  107. *Addr=ExAllocatePoolWithQuotaTag(NonPagedPool,Len,_Tag ); \
  108. } \
  109. except( EXCEPTION_EXECUTE_HANDLER) { \
  110. *Addr=NULL; \
  111. }
  112. #define GpcFreeMem( Address,_Tag ) \
  113. ExFreePool( (Address) )
  114. #define GpcAllocFromLL(_ptr, _list, _tag) \
  115. *_ptr = NdisAllocateFromNPagedLookasideList(_list)
  116. #define GpcFreeToLL(_ptr, _list, _tag) \
  117. NdisFreeToNPagedLookasideList(_list, _ptr)
  118. #define GET_IRQL(_i)
  119. #define VERIFY_IRQL(_i)
  120. #define DEFINE_KIRQL(_i)
  121. #endif // if DBG
  122. #if DBG
  123. #define LockedIncrement( Count,_p ) LockedInc(Count,__FILE__,__LINE__,_p)
  124. #else
  125. #define LockedIncrement( Count,_p ) NdisInterlockedIncrement((PLONG)Count)
  126. #endif
  127. #if DBG
  128. #define LockedDecrement( Count,_p ) LockedDec(Count,__FILE__,__LINE__,_p)
  129. #else
  130. #define LockedDecrement( Count,_p ) NdisInterlockedDecrement((PLONG)Count)
  131. #endif
  132. #define KD_PRINT 0x00000001
  133. #define INIT 0x00000002
  134. #define BLOB 0x00000004
  135. #define PATTERN 0x00000008
  136. #define NOTIFY 0x00000010
  137. #define REGISTER 0x00000020
  138. #define MEMORY 0x00000040
  139. #define LOOKUP 0x00000080
  140. #define LOCKS 0x00000100
  141. #define CLASSIFY 0x00000200
  142. #define RHIZOME 0x00000400
  143. #define PATHASH 0x00000800
  144. #define IOCTL 0x00001000
  145. #define CLIENT 0x00002000
  146. #define MAPHAND 0x00004000
  147. #define CLASSHAND 0x00008000
  148. #define PAT_TIMER 0x00010000
  149. #define REFCOUNT 0x00020000
  150. #define PARAM_EX 0x80000000 // this is reserved for the trace routine
  151. #if DBG
  152. #define DBGPRINT(Mask, String) \
  153. { \
  154. if(Mask & DbgPrintFlags)\
  155. DbgPrint String;\
  156. }
  157. #define TRACE( Mask,P1,P2,_fname ) \
  158. { \
  159. if (Mask & DebugFlags)\
  160. TraceRtn((PUCHAR)__FILE__,(ULONG)__LINE__,_fname,(ULONG_PTR)(P1),(ULONG_PTR)(P2),KeGetCurrentProcessorNumber(),KeGetCurrentIrql(),Mask|PARAM_EX);\
  161. }
  162. #else
  163. #define DBGPRINT(Mask, String)
  164. #define TRACE( Mask,P1,P2,_fname )
  165. #endif
  166. /*
  167. /////////////////////////////////////////////////////////////////
  168. //
  169. // externs & prototypes
  170. //
  171. /////////////////////////////////////////////////////////////////
  172. */
  173. extern ULONG DebugFlags;
  174. extern ULONG DbgPrintFlags;
  175. extern ULONG BytesAllocated;
  176. VOID
  177. TraceRtn(
  178. IN UCHAR *File,
  179. IN ULONG Line,
  180. IN UCHAR *FuncName,
  181. IN ULONG_PTR Param1,
  182. IN ULONG_PTR Param2,
  183. IN ULONG Param3,
  184. IN ULONG Param4,
  185. IN ULONG Mask
  186. );
  187. _inline LONGLONG
  188. GetTime(
  189. VOID
  190. )
  191. /*++
  192. Routine Description:
  193. Get the current system time
  194. Arguments:
  195. Return Value:
  196. System time (in base OS time units)
  197. --*/
  198. {
  199. LARGE_INTEGER Now;
  200. LARGE_INTEGER Frequency;
  201. #if defined(PERF_COUNTER) || defined (TRACE_PERF_COUNTER)
  202. Now = KeQueryPerformanceCounter(&Frequency);
  203. Now.QuadPart = (Now.QuadPart * OS_TIME_SCALE) / Frequency.QuadPart;
  204. #else
  205. NdisGetCurrentSystemTime( &Now );
  206. #endif
  207. return Now.QuadPart;
  208. }
  209. #define LOGSIZE 4000 // number of entries
  210. #define LOGWIDTH 64 // number of characters (one or two bytes) per entry
  211. //
  212. //
  213. typedef struct {
  214. UCHAR Row[ LOGWIDTH ];
  215. LONGLONG Time;
  216. ULONG Line;
  217. ULONG_PTR P1;
  218. ULONG_PTR P2;
  219. ULONG P3;
  220. ULONG P4;
  221. } ROW, *PROW;
  222. typedef struct {
  223. ULONG Index;
  224. PROW Current;
  225. PROW Buffer;
  226. ULONG Wraps;
  227. } LOG, *PLOG;
  228. _inline VOID
  229. DbgVerifyList(
  230. PLIST_ENTRY h
  231. )
  232. {
  233. PLIST_ENTRY p = h->Flink;
  234. PLIST_ENTRY q = h;
  235. int m = 1000;
  236. if (h->Flink == h) {
  237. ASSERT(h->Blink == h);
  238. }
  239. while (p != h && m > 0) {
  240. ASSERT(p->Blink == q);
  241. q = p;
  242. p = p->Flink;
  243. m--;
  244. }
  245. ASSERT(m > 0);
  246. }
  247. #endif //__GPCDBG