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.

339 lines
11 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1992.
  5. //
  6. // File: PCH.cxx
  7. //
  8. // Contents: Pre-compiled header
  9. //
  10. // History: 21-Dec-92 BartoszM Created
  11. //
  12. //--------------------------------------------------------------------------
  13. #define KDEXTMODE
  14. //
  15. // Following define prevents the inclusion of extra filter related fields
  16. // in the FSRTL_COMMON_FCB_HEADER in fsrtl.h, whcih aren't in ntifs.h (used
  17. // by FAT)
  18. //
  19. #define BUILDING_FSKDEXT
  20. #ifndef __FATKDPCH_H
  21. #define __FATKDPCH_H
  22. #include <nt.h>
  23. #include <ntrtl.h>
  24. #include <nturtl.h>
  25. #include <ntos.h>
  26. #include <zwapi.h>
  27. // typedef int DCB;
  28. #include <windef.h>
  29. #include <windows.h>
  30. #include <memory.h>
  31. #include <fsrtl.h>
  32. #undef CREATE_NEW
  33. #undef OPEN_EXISTING
  34. //#include <ntifs.h>
  35. //#include <ntdddisk.h>
  36. //#include "..\nodetype.h"
  37. //#include "..\Fat.h"
  38. //#include "..\Lfn.h"
  39. //#include "..\FatStruc.h"
  40. //#include "..\FatData.h"
  41. #include <stdlib.h>
  42. #include <stdio.h>
  43. #include <string.h>
  44. //#include <imagehlp.h>
  45. // Stolen from ntrtl.h to override RECOMASSERT
  46. #undef ASSERT
  47. #undef ASSERTMSG
  48. #if DBG
  49. #define ASSERT( exp ) \
  50. if (!(exp)) \
  51. RtlAssert( #exp, __FILE__, __LINE__, NULL )
  52. #define ASSERTMSG( msg, exp ) \
  53. if (!(exp)) \
  54. RtlAssert( #exp, __FILE__, __LINE__, msg )
  55. #else
  56. #define ASSERT( exp )
  57. #define ASSERTMSG( msg, exp )
  58. #endif // DBG
  59. #define KDEXT_64BIT
  60. #include <wdbgexts.h>
  61. #define OFFSET(struct, elem) ((char *) &(struct->elem) - (char *) struct)
  62. #define _DRIVER
  63. #define KDBG_EXT
  64. #include "wmistr.h"
  65. #pragma hdrstop
  66. typedef struct _STATE {
  67. ULONG mask;
  68. ULONG value;
  69. CHAR *pszname;
  70. } STATE;
  71. VOID
  72. PrintState(STATE *ps, ULONG state);
  73. typedef VOID (*ELEMENT_DUMP_ROUTINE)(
  74. IN ULONG64 RemoteAddress,
  75. IN LONG Options
  76. );
  77. typedef ELEMENT_DUMP_ROUTINE *PELEMENT_DUMP_ROUTINE;
  78. struct _NODE_TYPE_INFO_NEW;
  79. typedef struct _NODE_TYPE_INFO_NEW *PNODE_TYPE_INFO_NEW;
  80. typedef VOID (*STRUCT_DUMP_ROUTINE)(
  81. IN ULONG64 Address,
  82. IN LONG Options,
  83. IN PNODE_TYPE_INFO_NEW InfoNode
  84. );
  85. typedef STRUCT_DUMP_ROUTINE *PSTRUCT_DUMP_ROUTINE;
  86. #define DUMP_ROUTINE( X) \
  87. VOID \
  88. X( IN ULONG64 Address, \
  89. IN LONG Options, \
  90. IN PNODE_TYPE_INFO_NEW InfoNode)
  91. //
  92. // Node types, names, and associated dump routines.
  93. //
  94. typedef struct _NODE_TYPE_INFO_NEW {
  95. USHORT TypeCode; // should be NODE_TYPE_CODE
  96. char *Text;
  97. char *TypeName;
  98. STRUCT_DUMP_ROUTINE DumpRoutine;
  99. // char *flagsfield; // TODO: add field to specify field recursion (dump params) as well?
  100. // STATE *flagsinfo;
  101. } NODE_TYPE_INFO_NEW;
  102. #define NodeTypeName( InfoIndex) (NewNodeTypeCodes[ (InfoIndex)].Text)
  103. #define NodeTypeTypeName( InfoIndex) (NewNodeTypeCodes[ (InfoIndex)].TypeName)
  104. #define NodeTypeDumpFunction( InfoIndex) (NewNodeTypeCodes[ (InfoIndex)].DumpRoutine)
  105. #define NodeTypeSize( InfoIndex) (NewNodeTypeCodes[ (InfoIndex)].Size)
  106. ULONG DumpRtlSplay(
  107. IN ULONG64 RemoteAddress,
  108. IN ELEMENT_DUMP_ROUTINE ProcessElementRoutine,
  109. IN ULONG OffsetToContainerStart,
  110. IN ULONG Options
  111. );
  112. //
  113. // Define the global in memory structure tag information
  114. //
  115. extern NODE_TYPE_INFO_NEW NewNodeTypeCodes[];
  116. #define TypeCodeInfoIndex( X) SearchTypeCodeIndex( X, NewNodeTypeCodes)
  117. ULONG
  118. SearchTypeCodeIndex (
  119. IN USHORT TypeCode,
  120. IN NODE_TYPE_INFO_NEW TypeCodes[]
  121. );
  122. #define AVERAGE(TOTAL,COUNT) ((COUNT) != 0 ? (TOTAL)/(COUNT) : 0)
  123. //
  124. // DUMP_WITH_OFFSET -- for dumping pointers contained in structures.
  125. //
  126. #define DUMP8_WITH_OFFSET(type, ptr, element, label) \
  127. dprintf( "\n(%03x) %8hx %s ", \
  128. FIELD_OFFSET(type, element), \
  129. (USHORT)((UCHAR)ptr.element), \
  130. label )
  131. #define DUMP16_WITH_OFFSET(type, ptr, element, label) \
  132. dprintf( "\n(%03x) %8hx %s ", \
  133. FIELD_OFFSET(type, element), \
  134. (USHORT)ptr.element, \
  135. label )
  136. #define DUMP_WITH_OFFSET(type, ptr, element, label) \
  137. dprintf( "\n(%03x) %08x %s ", \
  138. FIELD_OFFSET(type, element), \
  139. ptr.element, \
  140. label )
  141. #define DUMP64_WITH_OFFSET(type, ptr, element, label) \
  142. dprintf( "\n(%03x) %016I64x %s ", \
  143. FIELD_OFFSET(type, element), \
  144. ptr.element, \
  145. label )
  146. //
  147. // DUMP_EMBW_OFFSET -- for dumping elements embedded in structures.
  148. //
  149. #define DUMP_EMBW_OFFSET(type, address, element, label) \
  150. dprintf( "\n(%03x) %08x -> %s ", \
  151. FIELD_OFFSET(type, element), \
  152. ((PUCHAR)address) + FIELD_OFFSET(type, element), \
  153. label )
  154. #define ReadM( B, A, L) { \
  155. ULONG RmResult; \
  156. if (!ReadMemory( (A), (B), (L), &RmResult)) { \
  157. dprintf( "Unable to read %d bytes at 0x%I64x\n", (L), (A)); \
  158. return; \
  159. } \
  160. }
  161. #define RM( Addr, Obj, pObj, Type, Result ) { \
  162. (pObj) = (Type)(Addr); \
  163. if ( !ReadMemory( (Addr), &(Obj), sizeof( Obj ), &(Result)) ) { \
  164. dprintf( "Unable to read %d bytes at %p\n", sizeof(Obj), (Addr)); \
  165. return; \
  166. } \
  167. }
  168. #define RMSS( Addr, Length, Obj, pObj, Type, Result ) { \
  169. (pObj) = (Type)(Addr); \
  170. if ( !ReadMemory( (Addr), &(Obj), (Length), &(Result)) ) { \
  171. dprintf( "Unable to read %d bytes at %p\n", (Length), (Addr)); \
  172. return; \
  173. } \
  174. }
  175. #define ROE( X) { \
  176. ULONG _E_; \
  177. if (_E_ = (X)) { \
  178. dprintf("Error %d (File %s Line %d)\n", _E_, __FILE__, __LINE__); \
  179. return; \
  180. } \
  181. }
  182. VOID
  183. DumpStr(
  184. IN ULONG FieldOffset,
  185. IN ULONG64 StringAddress,
  186. IN PUCHAR Label,
  187. IN BOOLEAN CrFirst,
  188. IN BOOLEAN Wide
  189. );
  190. //
  191. // ....( TYPE, LOCAL_RECORD, REMOTE_ADDRESS_OF_RECORD, TYPE_FIELD_NAME, LABEL)
  192. //
  193. #define DUMP_UCST_OFFSET( type, ptr, address, resident, element, label) \
  194. DumpWStr( FIELD_OFFSET(type, element), \
  195. resident ? (((PUCHAR)address) + FIELD_OFFSET(type, element)) : *((PVOID*)&(ptr.element)), \
  196. resident ? &(ptr.element) : NULL, \
  197. label, TRUE \
  198. )
  199. #define DUMP_UCST_OFFSET_NO_CR( type, ptr, address, resident, element, label) \
  200. DumpWStr( FIELD_OFFSET(type, element), \
  201. resident ? (((PUCHAR)address) + FIELD_OFFSET(type, element)) : *((PVOID*)&(ptr.element)), \
  202. resident ? &(ptr.element) : NULL, \
  203. label, FALSE \
  204. )
  205. #define DUMP_STRN_OFFSET( type, ptr, address, resident, element, label) \
  206. DumpStr( FIELD_OFFSET(type, element), \
  207. resident ? (((PUCHAR)address) + FIELD_OFFSET(type, element)) : *((PVOID*)&(ptr.element)), \
  208. resident ? &(ptr.element) : NULL, \
  209. label, TRUE \
  210. )
  211. #define DUMP_STRN_OFFSET_NO_CR( type, ptr, address, resident, element, label) \
  212. DumpStr( FIELD_OFFSET(type, element), \
  213. resident ? (((PUCHAR)address) + FIELD_OFFSET(type, element)) : *((PVOID*)&(ptr.element)), \
  214. resident ? &(ptr.element) : NULL, \
  215. label, FALSE \
  216. )
  217. #define DUMP_RAW_TERM_STRN_OFFSET( type, ptr, address, element, label) \
  218. dprintf( "\n(%03x) %08x -> %s = '%s'", \
  219. FIELD_OFFSET(type, element), \
  220. ((PUCHAR)address) + FIELD_OFFSET(type, element), \
  221. label , \
  222. ptr.element)
  223. VOID
  224. DumpList(
  225. IN ULONG64 RemoteListEntryAddress,
  226. IN ELEMENT_DUMP_ROUTINE ProcessElementRoutine,
  227. IN ULONG OffsetToContainerStart,
  228. IN BOOLEAN ProcessThisEntry,
  229. IN ULONG Options
  230. );
  231. VOID
  232. ParseAndDump (
  233. IN PCHAR args,
  234. IN STRUCT_DUMP_ROUTINE DumpFunction,
  235. ULONG Processor,
  236. HANDLE hCurrentThread
  237. );
  238. ULONG
  239. Dt( IN UCHAR *Type,
  240. IN ULONG64 Addr,
  241. IN ULONG Recur,
  242. IN ULONG FieldInfoCount,
  243. IN FIELD_INFO FieldInfo[]
  244. );
  245. //
  246. // Definitions nicked from fsrtl/largemcb.c to enable dumping of FAT/UDFS
  247. // MCB structures
  248. //
  249. typedef struct _MAPPING {
  250. VBN NextVbn;
  251. LBN Lbn;
  252. } MAPPING;
  253. typedef MAPPING *PMAPPING;
  254. typedef struct _NONOPAQUE_MCB {
  255. PFAST_MUTEX FastMutex;
  256. ULONG MaximumPairCount;
  257. ULONG PairCount;
  258. POOL_TYPE PoolType;
  259. PMAPPING Mapping;
  260. } NONOPAQUE_MCB;
  261. typedef NONOPAQUE_MCB *PNONOPAQUE_MCB;
  262. //
  263. // A macro to return the size, in bytes, of a retrieval mapping structure
  264. //
  265. #define SizeOfMapping(MCB) ((sizeof(MAPPING) * (MCB)->MaximumPairCount))
  266. #endif