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.

352 lines
11 KiB

  1. /*++
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. bowdbg.h
  5. Abstract:
  6. This include file definies the redirector debug facility definitions
  7. Author:
  8. Larry Osterman (LarryO) 2-Jun-1990
  9. Revision History:
  10. 2-Jun-1990 LarryO
  11. Created
  12. --*/
  13. #ifndef _DEBUG_
  14. #define _DEBUG_
  15. //
  16. // The global bowser debug level variable, its values are:
  17. //
  18. #define DPRT_ALWAYS 0x00000000 // Always gets printed
  19. #define DPRT_DOMAIN 0x00000004 // Emulated Domain
  20. #define DPRT_ANNOUNCE 0x00000008 // Server announcements
  21. #define DPRT_TDI 0x00000010 // Transport specific
  22. #define DPRT_FSPDISP 0x00000020 // BowserFsp Dispatch (not covered by other specific levels)
  23. #define DPRT_BROWSER 0x00000040 // Browser general stuff
  24. #define DPRT_ELECT 0x00000080 // Election stuff
  25. #define DPRT_CLIENT 0x00000200 // Client requests
  26. #define DPRT_MASTER 0x00000400 // Browse master specific info
  27. #define DPRT_SRVENUM 0x00000800 // NetServerEnum
  28. #define DPRT_NETLOGON 0x00001000
  29. #define DPRT_FSCTL 0x00002000 // FSCTL
  30. #define DPRT_INIT 0x00008000 // Initialization code
  31. //
  32. // Verbose bits below.
  33. //
  34. #define DPRT_REF 0x00010000 // Transport specific reference counts
  35. #define DPRT_SCAVTHRD 0x00020000 // Scavenger
  36. #define DPRT_TIMER 0x00040000 // Timer related messages
  37. #define DPRT_PACK 0x00080000 // String packing and unpacking
  38. extern LONG BowserDebugTraceLevel;
  39. extern LONG BowserDebugLogLevel;
  40. #if DBG
  41. #define PAGED_DBG 1
  42. #endif
  43. #ifdef PAGED_DBG
  44. #undef PAGED_CODE
  45. #define PAGED_CODE() \
  46. struct { ULONG bogus; } ThisCodeCantBePaged; \
  47. ThisCodeCantBePaged; \
  48. if (KeGetCurrentIrql() > APC_LEVEL) { \
  49. KdPrint(( "BOWSER: Pageable code called at IRQL %d. File %s, Line %d\n", KeGetCurrentIrql(), __FILE__, __LINE__ )); \
  50. ASSERT(FALSE); \
  51. }
  52. #define PAGED_CODE_CHECK() if (ThisCodeCantBePaged) ;
  53. extern ULONG ThisCodeCantBePaged;
  54. #define DISCARDABLE_CODE(_SectionName) { \
  55. if (RdrSectionInfo[(_SectionName)].ReferenceCount == 0) { \
  56. KdPrint(( "BOWSER: Discardable code called while code not locked. File %s, Line %d\n", __FILE__, __LINE__ )); \
  57. ASSERT(FALSE); \
  58. } \
  59. }
  60. #else
  61. #define PAGED_CODE_CHECK()
  62. #define DISCARDABLE_CODE(_SectionName)
  63. #endif
  64. #if DBG
  65. #define ACQUIRE_SPIN_LOCK(a, b) { \
  66. PAGED_CODE_CHECK(); \
  67. KeAcquireSpinLock(a, b); \
  68. }
  69. #define RELEASE_SPIN_LOCK(a, b) { \
  70. PAGED_CODE_CHECK(); \
  71. KeReleaseSpinLock(a, b); \
  72. }
  73. #else
  74. #define ACQUIRE_SPIN_LOCK(a, b) KeAcquireSpinLock(a, b)
  75. #define RELEASE_SPIN_LOCK(a, b) KeReleaseSpinLock(a, b)
  76. #endif
  77. #define POOL_ANNOUNCEMENT 'naBL'
  78. #define POOL_VIEWBUFFER 'bvBL'
  79. #define POOL_TRANSPORT 'pxBL'
  80. #define POOL_PAGED_TRANSPORT 'tpBL'
  81. #define POOL_TRANSPORTNAME 'ntBL'
  82. #define POOL_EABUFFER 'aeBL'
  83. #define POOL_SENDDATAGRAM 'sdBL'
  84. #define POOL_CONNECTINFO 'icBL'
  85. #define POOL_MAILSLOT_HEADER 'hmBL'
  86. #define POOL_BACKUPLIST 'lbBL'
  87. #define POOL_BROWSERSERVERLIST 'lsBL'
  88. #define POOL_BROWSERSERVER 'sbBL'
  89. #define POOL_GETBLIST_REQUEST 'bgBL'
  90. #define POOL_BACKUPLIST_RESP 'rbBL'
  91. #define POOL_MAILSLOT_BUFFER 'bmBL'
  92. #define POOL_NETLOGON_BUFFER 'lnBL'
  93. #define POOL_ILLEGALDGRAM 'diBL'
  94. #define POOL_MASTERANNOUNCE 'amBL'
  95. #define POOL_BOWSERNAME 'nbBL'
  96. #define POOL_IRPCONTEXT 'ciBL'
  97. #define POOL_WORKITEM 'iwBL'
  98. #define POOL_ELECTCONTEXT 'leBL'
  99. #define POOL_BECOMEBACKUPCTX 'bbBL'
  100. #define POOL_BECOMEBACKUPREQ 'rbBL'
  101. #define POOL_PAGED_TRANSPORTNAME 'npBL'
  102. #define POOL_ADDNAME_STRUCT 'naBL'
  103. #define POOL_POSTDG_CONTEXT 'dpBL'
  104. #define POOL_IPX_NAME_CONTEXT 'ciBL'
  105. #define POOL_IPX_NAME_PACKET 'piBL'
  106. #define POOL_IPX_CONNECTION_INFO 'iiBL'
  107. #define POOL_ADAPTER_STATUS 'saBL'
  108. #define POOL_SHORT_CONTEXT 'csBL'
  109. #define POOL_DOMAIN_INFO 'idBL'
  110. #define POOL_NAME_ENUM_BUFFER 'enBL'
  111. #define POOL_SERVER_ENUM_BUFFER 'esBL'
  112. #if !BOWSERPOOLDBG
  113. #if POOL_TAGGING
  114. #define ALLOCATE_POOL(a,b, c) ExAllocatePoolWithTag(a, b, c)
  115. #define ALLOCATE_POOL_WITH_QUOTA(a, b, c) ExAllocatePoolWithTagQuota(a, b, c)
  116. #else
  117. #define ALLOCATE_POOL(a,b, c) ExAllocatePool(a, b)
  118. #define ALLOCATE_POOL_WITH_QUOTA(a, b, c) ExAllocatePoolWithQuota(a, b)
  119. #endif
  120. #define FREE_POOL(a) ExFreePool(a)
  121. #else
  122. PVOID
  123. BowserAllocatePool (
  124. IN POOL_TYPE PoolType,
  125. IN ULONG NumberOfBytes,
  126. IN PCHAR FileName,
  127. IN ULONG LineNumber,
  128. IN ULONG Tag
  129. );
  130. PVOID
  131. BowserAllocatePoolWithQuota (
  132. IN POOL_TYPE PoolType,
  133. IN ULONG NumberOfBytes,
  134. IN PCHAR FileName,
  135. IN ULONG LineNumber,
  136. IN ULONG Tag
  137. );
  138. VOID
  139. BowserFreePool (
  140. IN PVOID P
  141. );
  142. #define ALLOCATE_POOL(a,b, c) BowserAllocatePool(a,b,__FILE__, __LINE__, c)
  143. #define ALLOCATE_POOL_WITH_QUOTA(a,b, c) BowserAllocatePoolWithQuota(a,b,__FILE__, __LINE__, c)
  144. #define FREE_POOL(a) BowserFreePool(a)
  145. #define POOL_MAXTYPE 30
  146. #endif
  147. #if DBG
  148. // Can't call dlof from non-pageable code
  149. #define dprintf(LEVEL,String) { \
  150. if (((LEVEL) == 0) || (BowserDebugTraceLevel & (LEVEL))) { \
  151. DbgPrint String; \
  152. } \
  153. }
  154. #define InternalError(String) { \
  155. DbgPrint("Internal Bowser Error "); \
  156. DbgPrint String; \
  157. DbgPrint("\nFile %s, Line %d\n", __FILE__, __LINE__);\
  158. ASSERT(FALSE); \
  159. }
  160. #ifndef PRODUCT1
  161. #define dlog(LEVEL,String) { \
  162. if (((LEVEL) == 0) || (BowserDebugTraceLevel & (LEVEL))) { \
  163. DbgPrint String; \
  164. } \
  165. if (((LEVEL) == 0) || (BowserDebugLogLevel & (LEVEL))) { \
  166. BowserTrace String; \
  167. } \
  168. }
  169. VOID
  170. BowserTrace(
  171. PCHAR FormatString,
  172. ...
  173. );
  174. #else
  175. #define dlog(LEVEL,String) { NOTHING };
  176. #endif
  177. VOID
  178. BowserInitializeTraceLog(
  179. VOID
  180. );
  181. VOID
  182. BowserUninitializeTraceLog(
  183. VOID
  184. );
  185. NTSTATUS
  186. BowserOpenTraceLogFile(
  187. IN PWCHAR TraceFileName
  188. );
  189. NTSTATUS
  190. BowserDebugCall(
  191. IN PLMDR_REQUEST_PACKET InputBuffer,
  192. IN ULONG InputBufferLength
  193. );
  194. #else
  195. #define dprintf(LEVEL, String) {NOTHING;}
  196. #define InternalError(String) {NOTHING;}
  197. #define dlog(LEVEL,String) { NOTHING; }
  198. #endif // DBG
  199. #endif // _DEBUG_
  200. //
  201. // Macro to ensure that the buffer pointed to by the specified UNICODE_STRING
  202. // is entirely contained in the InputBuffer.
  203. //
  204. // Assumptions:
  205. // InputBuffer and InputBufferLength are defined outside this macro.
  206. // InputBuffer has already been captured and relocated.
  207. // Status is the return status for the calling procedure
  208. // This macro is called from within a try/finally
  209. // bSkipBuffInc allows skipping of buffer inclusion test (for
  210. // 32 bit ioctls on 64 bit systems, see GetBrowserServerList)
  211. //
  212. #define ENSURE_IN_INPUT_BUFFER( _x, bAllowEmpty, bSkipBuffInc ) \
  213. { \
  214. if ( (_x)->Length == 0 ) { \
  215. if ( bAllowEmpty ) { \
  216. (_x)->Buffer = NULL; \
  217. (_x)->MaximumLength = 0; \
  218. } else { \
  219. try_return( Status = STATUS_INVALID_PARAMETER ); \
  220. } \
  221. } else if ( (_x)->MaximumLength > InputBufferLength || \
  222. (_x)->MaximumLength < (_x)->Length || \
  223. ( !bSkipBuffInc && \
  224. ((LPBYTE)((_x)->Buffer) < (LPBYTE)InputBuffer || \
  225. (LPBYTE)InputBuffer + InputBufferLength - (_x)->MaximumLength < \
  226. ((LPBYTE)(_x)->Buffer)))){ \
  227. try_return( Status = STATUS_INVALID_PARAMETER ); \
  228. } \
  229. }
  230. // verify only that _s Unicode str buffer is within _inbuf ioctl boundaries
  231. // (short form of above test). Test is skipped for empty strings.
  232. #define ENSURE_BUFFER_BOUNDARIES( _inbuf, _s) \
  233. if ( (_s)->Length && \
  234. ( (LPBYTE)(ULONG_PTR)((_s)->Buffer) < (LPBYTE)_inbuf || \
  235. (LPBYTE)_inbuf + InputBufferLength - (_s)->MaximumLength < \
  236. ((LPBYTE)(ULONG_PTR)(_s)->Buffer))){ \
  237. try_return( Status = STATUS_INVALID_PARAMETER ); \
  238. }
  239. //
  240. // Same as above but for an LPWSTR
  241. //
  242. #define ENSURE_IN_INPUT_BUFFER_STR( _x ) \
  243. { \
  244. PWCHAR _p; \
  245. if ((LPBYTE)(_x) < (LPBYTE)InputBuffer || \
  246. (LPBYTE)(_x) >= (LPBYTE)InputBuffer + InputBufferLength || \
  247. !POINTER_IS_ALIGNED( (_x), ALIGN_WCHAR) ) { \
  248. try_return( Status = STATUS_INVALID_PARAMETER ); \
  249. } \
  250. for ( _p = (PWCHAR)(_x);; _p++) { \
  251. if ( (LPBYTE)_p >= (LPBYTE)InputBuffer + InputBufferLength ) { \
  252. try_return( Status = STATUS_INVALID_PARAMETER ); \
  253. } \
  254. if ( *_p == L'\0' ) { \
  255. break; \
  256. } \
  257. } \
  258. }
  259. //
  260. // Capture a unicode string from user mode
  261. //
  262. // The string structure itself has already been captured.
  263. // The macro simply captures the string and copies it to a buffer.
  264. //
  265. #define CAPTURE_UNICODE_STRING( _x, _y ) \
  266. {\
  267. if ( (_x)->Length == 0 ) { \
  268. (_x)->Buffer = NULL; \
  269. (_x)->MaximumLength = 0; \
  270. } else if ( (_x)->Length+sizeof(WCHAR) > sizeof(_y) ) {\
  271. try_return( Status = STATUS_INVALID_PARAMETER ); \
  272. } else {\
  273. try {\
  274. ProbeForRead( (_x)->Buffer,\
  275. (_x)->Length,\
  276. sizeof(WCHAR) );\
  277. RtlCopyMemory( (_y), (_x)->Buffer, (_x)->Length );\
  278. ((PWCHAR)(_y))[(_x)->Length/sizeof(WCHAR)] = L'\0';\
  279. (_x)->Buffer = (_y);\
  280. (_x)->MaximumLength = (_x)->Length + sizeof(WCHAR);\
  281. } except (BR_EXCEPTION) { \
  282. try_return (Status = GetExceptionCode());\
  283. }\
  284. }\
  285. }
  286. //
  287. // Define an exception filter to improve debuggin capabilities.
  288. //
  289. #if DBG
  290. #define BR_EXCEPTION BrExceptionFilter(GetExceptionInformation())
  291. LONG BrExceptionFilter( EXCEPTION_POINTERS * pException);
  292. #else // DBG
  293. #define BR_EXCEPTION EXCEPTION_EXECUTE_HANDLER
  294. #endif // DBG