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.

332 lines
10 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. //
  107. // Define the global in memory structure tag information
  108. //
  109. extern NODE_TYPE_INFO_NEW NewNodeTypeCodes[];
  110. #define TypeCodeInfoIndex( X) SearchTypeCodeIndex( X, NewNodeTypeCodes)
  111. ULONG
  112. SearchTypeCodeIndex (
  113. IN USHORT TypeCode,
  114. IN NODE_TYPE_INFO_NEW TypeCodes[]
  115. );
  116. #define AVERAGE(TOTAL,COUNT) ((COUNT) != 0 ? (TOTAL)/(COUNT) : 0)
  117. //
  118. // DUMP_WITH_OFFSET -- for dumping pointers contained in structures.
  119. //
  120. #define DUMP8_WITH_OFFSET(type, ptr, element, label) \
  121. dprintf( "\n(%03x) %8hx %s ", \
  122. FIELD_OFFSET(type, element), \
  123. (USHORT)((UCHAR)ptr.element), \
  124. label )
  125. #define DUMP16_WITH_OFFSET(type, ptr, element, label) \
  126. dprintf( "\n(%03x) %8hx %s ", \
  127. FIELD_OFFSET(type, element), \
  128. (USHORT)ptr.element, \
  129. label )
  130. #define DUMP_WITH_OFFSET(type, ptr, element, label) \
  131. dprintf( "\n(%03x) %08x %s ", \
  132. FIELD_OFFSET(type, element), \
  133. ptr.element, \
  134. label )
  135. #define DUMP64_WITH_OFFSET(type, ptr, element, label) \
  136. dprintf( "\n(%03x) %016I64x %s ", \
  137. FIELD_OFFSET(type, element), \
  138. ptr.element, \
  139. label )
  140. //
  141. // DUMP_EMBW_OFFSET -- for dumping elements embedded in structures.
  142. //
  143. #define DUMP_EMBW_OFFSET(type, address, element, label) \
  144. dprintf( "\n(%03x) %08x -> %s ", \
  145. FIELD_OFFSET(type, element), \
  146. ((PUCHAR)address) + FIELD_OFFSET(type, element), \
  147. label )
  148. #define ReadM( B, A, L) { \
  149. ULONG RmResult; \
  150. if (!ReadMemory( (A), (B), (L), &RmResult)) { \
  151. dprintf( "Unable to read %d bytes at 0x%I64x\n", (L), (A)); \
  152. return; \
  153. } \
  154. }
  155. #define RM( Addr, Obj, pObj, Type, Result ) { \
  156. (pObj) = (Type)(Addr); \
  157. if ( !ReadMemory( (Addr), &(Obj), sizeof( Obj ), &(Result)) ) { \
  158. dprintf( "Unable to read %d bytes at %p\n", sizeof(Obj), (Addr)); \
  159. return; \
  160. } \
  161. }
  162. #define RMSS( Addr, Length, Obj, pObj, Type, Result ) { \
  163. (pObj) = (Type)(Addr); \
  164. if ( !ReadMemory( (Addr), &(Obj), (Length), &(Result)) ) { \
  165. dprintf( "Unable to read %d bytes at %p\n", (Length), (Addr)); \
  166. return; \
  167. } \
  168. }
  169. #define ROE( X) { \
  170. ULONG _E_; \
  171. if (_E_ = (X)) { \
  172. dprintf("Error %d (File %s Line %d)\n", _E_, __FILE__, __LINE__); \
  173. return; \
  174. } \
  175. }
  176. VOID
  177. DumpStr(
  178. IN ULONG FieldOffset,
  179. IN ULONG64 StringAddress,
  180. IN PUCHAR Label,
  181. IN BOOLEAN CrFirst,
  182. IN BOOLEAN Wide
  183. );
  184. //
  185. // ....( TYPE, LOCAL_RECORD, REMOTE_ADDRESS_OF_RECORD, TYPE_FIELD_NAME, LABEL)
  186. //
  187. #define DUMP_UCST_OFFSET( type, ptr, address, resident, element, label) \
  188. DumpWStr( FIELD_OFFSET(type, element), \
  189. resident ? (((PUCHAR)address) + FIELD_OFFSET(type, element)) : *((PVOID*)&(ptr.element)), \
  190. resident ? &(ptr.element) : NULL, \
  191. label, TRUE \
  192. )
  193. #define DUMP_UCST_OFFSET_NO_CR( 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, FALSE \
  198. )
  199. #define DUMP_STRN_OFFSET( type, ptr, address, resident, element, label) \
  200. DumpStr( FIELD_OFFSET(type, element), \
  201. resident ? (((PUCHAR)address) + FIELD_OFFSET(type, element)) : *((PVOID*)&(ptr.element)), \
  202. resident ? &(ptr.element) : NULL, \
  203. label, TRUE \
  204. )
  205. #define DUMP_STRN_OFFSET_NO_CR( 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, FALSE \
  210. )
  211. #define DUMP_RAW_TERM_STRN_OFFSET( type, ptr, address, element, label) \
  212. dprintf( "\n(%03x) %08x -> %s = '%s'", \
  213. FIELD_OFFSET(type, element), \
  214. ((PUCHAR)address) + FIELD_OFFSET(type, element), \
  215. label , \
  216. ptr.element)
  217. VOID
  218. DumpList(
  219. IN ULONG64 RemoteListEntryAddress,
  220. IN ELEMENT_DUMP_ROUTINE ProcessElementRoutine,
  221. IN ULONG OffsetToContainerStart,
  222. IN BOOLEAN ProcessThisEntry,
  223. IN ULONG Options
  224. );
  225. VOID
  226. ParseAndDump (
  227. IN PCHAR args,
  228. IN STRUCT_DUMP_ROUTINE DumpFunction,
  229. ULONG Processor,
  230. HANDLE hCurrentThread
  231. );
  232. ULONG
  233. Dt( IN UCHAR *Type,
  234. IN ULONG64 Addr,
  235. IN ULONG Recur,
  236. IN ULONG FieldInfoCount,
  237. IN FIELD_INFO FieldInfo[]
  238. );
  239. //
  240. // Definitions nicked from fsrtl/largemcb.c to enable dumping of FAT/UDFS
  241. // MCB structures
  242. //
  243. typedef struct _MAPPING {
  244. VBN NextVbn;
  245. LBN Lbn;
  246. } MAPPING;
  247. typedef MAPPING *PMAPPING;
  248. typedef struct _NONOPAQUE_MCB {
  249. PFAST_MUTEX FastMutex;
  250. ULONG MaximumPairCount;
  251. ULONG PairCount;
  252. POOL_TYPE PoolType;
  253. PMAPPING Mapping;
  254. } NONOPAQUE_MCB;
  255. typedef NONOPAQUE_MCB *PNONOPAQUE_MCB;
  256. //
  257. // A macro to return the size, in bytes, of a retrieval mapping structure
  258. //
  259. #define SizeOfMapping(MCB) ((sizeof(MAPPING) * (MCB)->MaximumPairCount))
  260. #endif