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.

371 lines
12 KiB

  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. vad.c
  5. Abstract:
  6. WinDbg Extension Api
  7. Author:
  8. Lou Perazzoli (loup) 12-Jun-1992
  9. Environment:
  10. User Mode.
  11. Revision History:
  12. --*/
  13. #include "precomp.h"
  14. #pragma hdrstop
  15. CHAR *ProtectString[] = {
  16. "NO_ACCESS",
  17. "READONLY",
  18. "EXECUTE",
  19. "EXECUTE_READ",
  20. "READWRITE",
  21. "WRITECOPY",
  22. "EXECUTE_READWRITE",
  23. "EXECUTE_WRITECOPY"
  24. };
  25. DECLARE_API( vad )
  26. /*++
  27. Routine Description:
  28. Dumps all vads for process.
  29. Arguments:
  30. args - Address Flags
  31. Return Value:
  32. None
  33. --*/
  34. {
  35. ULONG64 Next;
  36. ULONG64 VadToDump;
  37. ULONG64 ParentStored;
  38. ULONG64 First;
  39. ULONG64 Left;
  40. ULONG64 Prev;
  41. ULONG Flags;
  42. ULONG Done;
  43. ULONG Level = 0;
  44. ULONG Count = 0;
  45. ULONG AverageLevel = 0;
  46. ULONG MaxLevel = 0;
  47. ULONG VadFlagsPrivateMemory=0, VadFlagsNoChange=0;
  48. ULONG PhysicalMapping=0,ImageMap=0,NoChange=0,LargePages=0,MemCommit=0,PrivateMemory=0,Protection=0;
  49. ULONG64 StartingVpn=0, EndingVpn=0, Parent=0, LeftChild=0, RightChild=0;
  50. ULONG64 ControlArea=0, FirstPrototypePte=0, LastContiguousPte=0, CommitCharge=0;
  51. VadToDump = 0;
  52. Flags = 0;
  53. if (GetExpressionEx(args, &VadToDump, &args)) {
  54. Flags = (ULONG) GetExpression(args);
  55. }
  56. if (VadToDump == 0) {
  57. dprintf("Specify the address of a VAD within the VAD tree\n");
  58. return E_INVALIDARG;
  59. }
  60. First = VadToDump;
  61. if (First == 0) {
  62. return E_INVALIDARG;
  63. }
  64. #define ReadFirstVad(fld, var) GetFieldValue(First, (PUCHAR) "MMVAD", #fld, var)
  65. #define ReadFirstVadShort(fld, var) GetFieldValue(First, (PUCHAR) "MMVAD_SHORT", #fld, var)
  66. if ( ReadFirstVadShort(u.VadFlags.PrivateMemory, VadFlagsPrivateMemory) ) {
  67. dprintf("%08p: Unable to get contents of VAD1\n",First );
  68. return E_INVALIDARG;
  69. }
  70. ReadFirstVadShort(u.VadFlags.NoChange, VadFlagsNoChange);
  71. ReadFirstVadShort(StartingVpn, StartingVpn);
  72. ReadFirstVadShort(EndingVpn, EndingVpn);
  73. ReadFirstVadShort(Parent, Parent);
  74. ReadFirstVadShort(LeftChild, LeftChild);
  75. ReadFirstVadShort(RightChild, RightChild);
  76. ReadFirstVadShort(u.VadFlags.CommitCharge, CommitCharge);
  77. if (Flags == 1) {
  78. ULONG FileOffset=0;
  79. ULONG64 ListFlink=0, ListBlink=0, Banked=0;
  80. ULONG CopyOnWrite=0,Inherit=0,ExtendableFile=0,SecNoChange=0;
  81. ULONG OneSecured=0,MultipleSecured=0,ReadOnly=0,StoredInVad=0;
  82. //
  83. // Dump only this vad.
  84. //
  85. if ((VadFlagsPrivateMemory == 0) ||
  86. (VadFlagsNoChange == 1)) {
  87. if ( ReadFirstVad(ControlArea, ControlArea) ) {
  88. dprintf("%08p: Unable to get contents of VAD2\n",First );
  89. return E_INVALIDARG;
  90. }
  91. ReadFirstVad(FirstPrototypePte, FirstPrototypePte);
  92. ReadFirstVad(LastContiguousPte, LastContiguousPte);
  93. ReadFirstVad(u2.VadFlags2.CopyOnWrite, CopyOnWrite);
  94. ReadFirstVad(u2.VadFlags2.Inherit, Inherit);
  95. ReadFirstVad(u2.VadFlags2.ExtendableFile, ExtendableFile);
  96. ReadFirstVad(u2.VadFlags2.SecNoChange, SecNoChange);
  97. ReadFirstVad(u2.VadFlags2.OneSecured, OneSecured);
  98. ReadFirstVad(u2.VadFlags2.MultipleSecured, MultipleSecured);
  99. ReadFirstVad(u2.VadFlags2.ReadOnly, ReadOnly);
  100. ReadFirstVad(u2.VadFlags2.StoredInVad, StoredInVad);
  101. ReadFirstVad(u2.VadFlags2.FileOffset, FileOffset);
  102. ReadFirstVad(u3.List.Flink, ListFlink);
  103. ReadFirstVad(u3.List.Blink, ListBlink);
  104. ReadFirstVad(u4.Banked, Banked);
  105. }
  106. ReadFirstVad(u.VadFlags.CommitCharge, CommitCharge);
  107. ReadFirstVad(u.VadFlags.PhysicalMapping, PhysicalMapping);
  108. ReadFirstVad(u.VadFlags.ImageMap, ImageMap);
  109. ReadFirstVad(u.VadFlags.Protection, Protection);
  110. ReadFirstVad(u.VadFlags.NoChange, NoChange);
  111. ReadFirstVad(u.VadFlags.LargePages, LargePages);
  112. ReadFirstVad(u.VadFlags.MemCommit, MemCommit);
  113. ReadFirstVad(u.VadFlags.PrivateMemory, PrivateMemory);
  114. dprintf("\nVAD @ %8p\n",VadToDump);
  115. dprintf(" Start VPN: %8p End VPN: %8p Control Area: %8p\n",
  116. StartingVpn,
  117. EndingVpn,
  118. ControlArea);
  119. dprintf(" First ProtoPte: %8p Last PTE %8p Commit Charge %8lx (%ld.)\n",
  120. FirstPrototypePte,
  121. LastContiguousPte,
  122. (ULONG)CommitCharge,
  123. (ULONG)CommitCharge
  124. );
  125. dprintf(" Secured.Flink %8p Blink %8p Banked/Extend: %8p Offset %lx\n",
  126. ListFlink,
  127. ListBlink,
  128. Banked,
  129. FileOffset);
  130. dprintf(" ");
  131. if (PhysicalMapping) { dprintf("PhysicalMapping "); }
  132. if (ImageMap) { dprintf("ImageMap "); }
  133. Inherit ? dprintf("ViewShare ") : dprintf("ViewUnmap ");
  134. if (NoChange) { dprintf("NoChange "); }
  135. if (CopyOnWrite) { dprintf("CopyOnWrite "); }
  136. if (LargePages) { dprintf("LargePages "); }
  137. if (MemCommit) { dprintf("MemCommit "); }
  138. if (PrivateMemory) { dprintf("PrivateMemory "); }
  139. dprintf ("%s\n\n",ProtectString[Protection & 7]);
  140. if (ExtendableFile) { dprintf("ExtendableFile "); }
  141. if (SecNoChange) { dprintf("SecNoChange "); }
  142. if (OneSecured) { dprintf("OneSecured "); }
  143. if (MultipleSecured) { dprintf("MultipleSecured "); }
  144. if (ReadOnly) { dprintf("ReadOnly "); }
  145. if (StoredInVad) { dprintf("StoredInVad "); }
  146. dprintf ("\n\n");
  147. return E_INVALIDARG;
  148. }
  149. Prev = First;
  150. while (LeftChild != 0) {
  151. if ( CheckControlC() ) {
  152. return E_INVALIDARG;
  153. }
  154. Prev = First;
  155. First = LeftChild;
  156. Level += 1;
  157. if (Level > MaxLevel) {
  158. MaxLevel = Level;
  159. }
  160. if (Flags & 2) {
  161. dprintf("Reading LeftChild VAD %08p\n",First );
  162. }
  163. if ( ReadFirstVadShort(LeftChild, LeftChild) ) {
  164. dprintf("%08p %08p: Unable to get contents of VAD3\n", First, Prev);
  165. return E_INVALIDARG;
  166. }
  167. }
  168. ReadFirstVadShort(StartingVpn, StartingVpn);
  169. ReadFirstVadShort(EndingVpn, EndingVpn);
  170. ReadFirstVadShort(Parent, Parent);
  171. ReadFirstVadShort(RightChild, RightChild);
  172. ReadFirstVadShort(u.VadFlags.CommitCharge, CommitCharge);
  173. ReadFirstVadShort(u.VadFlags.PrivateMemory, PrivateMemory);
  174. ReadFirstVadShort(u.VadFlags.PhysicalMapping, PhysicalMapping);
  175. ReadFirstVadShort(u.VadFlags.ImageMap, ImageMap);
  176. ReadFirstVadShort(u.VadFlags.Protection, Protection);
  177. dprintf("VAD level start end commit\n");
  178. dprintf("%p (%2ld) %8p %8p %4ld %s %s %s\n",
  179. First,
  180. Level,
  181. StartingVpn,
  182. EndingVpn,
  183. (ULONG)CommitCharge,
  184. PrivateMemory ? "Private" : "Mapped ",
  185. ImageMap ? "Exe " :
  186. PhysicalMapping ? "Phys" : " ",
  187. ProtectString[Protection & 7]
  188. );
  189. Count += 1;
  190. AverageLevel += Level;
  191. Next = First;
  192. while (Next != 0) {
  193. if ( CheckControlC() ) {
  194. return E_INVALIDARG;
  195. }
  196. if (RightChild == 0) {
  197. Done = TRUE;
  198. while ((ParentStored = Parent) != 0) {
  199. if ( CheckControlC() ) {
  200. return E_INVALIDARG;
  201. }
  202. Level -= 1;
  203. //
  204. // Locate the first ancestor of this node of which this
  205. // node is the left child of and return that node as the
  206. // next element.
  207. //
  208. First = ParentStored;
  209. if ( ReadFirstVadShort( LeftChild, LeftChild) ||
  210. ReadFirstVadShort(Parent, Parent) ) {
  211. dprintf("%08p %08p: Unable to get contents of VAD4\n",Parent, Prev);
  212. return E_INVALIDARG;
  213. }
  214. Prev = First;
  215. ReadFirstVadShort(StartingVpn, StartingVpn);
  216. ReadFirstVadShort(EndingVpn, EndingVpn);
  217. ReadFirstVadShort(RightChild, RightChild);
  218. ReadFirstVadShort(u.VadFlags.CommitCharge, CommitCharge);
  219. ReadFirstVadShort(u.VadFlags.PrivateMemory, PrivateMemory);
  220. ReadFirstVadShort(u.VadFlags.PhysicalMapping, PhysicalMapping);
  221. ReadFirstVadShort(u.VadFlags.ImageMap, ImageMap);
  222. ReadFirstVadShort(u.VadFlags.Protection, Protection);
  223. if (LeftChild == Next) {
  224. Next = ParentStored;
  225. dprintf("%p (%2ld) %8p %8p %4ld %s %s %s\n",
  226. Next,
  227. Level,
  228. StartingVpn,
  229. EndingVpn,
  230. (ULONG)CommitCharge,
  231. PrivateMemory ? "Private" : "Mapped ",
  232. ImageMap ? "Exe " :
  233. PhysicalMapping ? "Phys" : " ",
  234. ProtectString[Protection & 7]
  235. );
  236. Done = FALSE;
  237. Count += 1;
  238. AverageLevel += Level;
  239. break;
  240. }
  241. Next = ParentStored;
  242. }
  243. if (Done) {
  244. Next = 0;
  245. break;
  246. }
  247. } else {
  248. //
  249. // A right child exists, locate the left most child of that right child.
  250. //
  251. Next = RightChild;
  252. Level += 1;
  253. if (Level > MaxLevel) {
  254. MaxLevel = Level;
  255. }
  256. First = Next;
  257. if ( ReadFirstVadShort(LeftChild, LeftChild) ) {
  258. dprintf("%08p %08p: Unable to get contents of VAD5\n",Next, Prev);
  259. return E_INVALIDARG;
  260. }
  261. while ((Left = LeftChild) != 0) {
  262. if ( CheckControlC() ) {
  263. return E_INVALIDARG;
  264. }
  265. Level += 1;
  266. if (Level > MaxLevel) {
  267. MaxLevel = Level;
  268. }
  269. Next = Left;
  270. First = Next;
  271. if ( ReadFirstVadShort(LeftChild, LeftChild) ) {
  272. dprintf("%08p %08p: Unable to get contents of VAD6\n",Next, Prev);
  273. return E_INVALIDARG;
  274. }
  275. Prev = First;
  276. }
  277. ReadFirstVadShort(StartingVpn, StartingVpn);
  278. ReadFirstVadShort(EndingVpn, EndingVpn);
  279. ReadFirstVadShort(Parent, Parent);
  280. ReadFirstVadShort(RightChild, RightChild);
  281. ReadFirstVadShort(u.VadFlags.CommitCharge, CommitCharge);
  282. ReadFirstVadShort(u.VadFlags.PrivateMemory, PrivateMemory);
  283. ReadFirstVadShort(u.VadFlags.PhysicalMapping, PhysicalMapping);
  284. ReadFirstVadShort(u.VadFlags.ImageMap, ImageMap);
  285. ReadFirstVadShort(u.VadFlags.Protection, Protection);
  286. dprintf("%p (%2ld) %8p %8p %4ld %s %s %s\n",
  287. Next,
  288. Level,
  289. StartingVpn,
  290. EndingVpn,
  291. (ULONG)CommitCharge,
  292. PrivateMemory ? "Private" : "Mapped ",
  293. ImageMap ? "Exe " :
  294. PhysicalMapping ? "Phys" : " ",
  295. ProtectString[Protection & 7]
  296. );
  297. Count += 1;
  298. AverageLevel += Level;
  299. }
  300. }
  301. dprintf("\nTotal VADs: %5ld average level: %4ld maximum depth: %ld\n",
  302. Count, 1+(AverageLevel/Count),MaxLevel);
  303. #undef ReadFirstVad
  304. return S_OK;
  305. }