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.

249 lines
5.5 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name:
  4. vmem.cpp
  5. Abstract:
  6. !vprot using the debug engine virtual query interface.
  7. --*/
  8. #include "precomp.h"
  9. #pragma hdrstop
  10. #define PAGE_ALL (PAGE_READONLY|\
  11. PAGE_READWRITE|\
  12. PAGE_WRITECOPY|\
  13. PAGE_EXECUTE|\
  14. PAGE_EXECUTE_READ|\
  15. PAGE_EXECUTE_READWRITE|\
  16. PAGE_EXECUTE_WRITECOPY|\
  17. PAGE_NOACCESS)
  18. VOID
  19. PrintPageFlags(DWORD Flags)
  20. {
  21. switch(Flags & PAGE_ALL)
  22. {
  23. case PAGE_READONLY:
  24. dprintf("PAGE_READONLY");
  25. break;
  26. case PAGE_READWRITE:
  27. dprintf("PAGE_READWRITE");
  28. break;
  29. case PAGE_WRITECOPY:
  30. dprintf("PAGE_WRITECOPY");
  31. break;
  32. case PAGE_EXECUTE:
  33. dprintf("PAGE_EXECUTE");
  34. break;
  35. case PAGE_EXECUTE_READ:
  36. dprintf("PAGE_EXECUTE_READ");
  37. break;
  38. case PAGE_EXECUTE_READWRITE:
  39. dprintf("PAGE_EXECUTE_READWRITE");
  40. break;
  41. case PAGE_EXECUTE_WRITECOPY:
  42. dprintf("PAGE_EXECUTE_WRITECOPY");
  43. break;
  44. case PAGE_NOACCESS:
  45. if ((Flags & ~PAGE_NOACCESS) == 0)
  46. {
  47. dprintf("PAGE_NOACCESS");
  48. break;
  49. } // else fall through
  50. default:
  51. dprintf("*** Invalid page protection ***\n");
  52. return;
  53. }
  54. if (Flags & PAGE_NOCACHE)
  55. {
  56. dprintf(" + PAGE_NOCACHE");
  57. }
  58. if (Flags & PAGE_GUARD)
  59. {
  60. dprintf(" + PAGE_GUARD");
  61. }
  62. dprintf("\n");
  63. }
  64. void
  65. DumpMemBasicInfo(PMEMORY_BASIC_INFORMATION64 Basic,
  66. BOOL Verbose)
  67. {
  68. dprintf("BaseAddress: %p\n", Basic->BaseAddress);
  69. if (Verbose)
  70. {
  71. dprintf("AllocationBase: %p\n", Basic->AllocationBase);
  72. if (Basic->State != MEM_FREE ||
  73. Basic->AllocationProtect)
  74. {
  75. dprintf("AllocationProtect: %08x ", Basic->AllocationProtect);
  76. PrintPageFlags(Basic->AllocationProtect);
  77. }
  78. }
  79. dprintf("RegionSize: %p\n", Basic->RegionSize);
  80. dprintf("State: %08x ", Basic->State);
  81. switch(Basic->State)
  82. {
  83. case MEM_COMMIT:
  84. dprintf("MEM_COMMIT\n");
  85. break;
  86. case MEM_FREE:
  87. dprintf("MEM_FREE\n");
  88. break;
  89. case MEM_RESERVE:
  90. dprintf("MEM_RESERVE\n");
  91. break;
  92. default:
  93. dprintf("*** Invalid page state ***\n");
  94. break;
  95. }
  96. if (Basic->State != MEM_RESERVE ||
  97. Basic->Protect)
  98. {
  99. dprintf("Protect: %08x ", Basic->Protect);
  100. PrintPageFlags(Basic->Protect);
  101. }
  102. if (Basic->State != MEM_FREE ||
  103. Basic->Type)
  104. {
  105. dprintf("Type: %08x ", Basic->Type);
  106. switch(Basic->Type)
  107. {
  108. case MEM_IMAGE:
  109. dprintf("MEM_IMAGE\n");
  110. break;
  111. case MEM_MAPPED:
  112. dprintf("MEM_MAPPED\n");
  113. break;
  114. case MEM_PRIVATE:
  115. dprintf("MEM_PRIVATE\n");
  116. break;
  117. default:
  118. dprintf("*** Invalid page type ***\n");
  119. break;
  120. }
  121. }
  122. }
  123. DECLARE_API( vprot )
  124. /*++
  125. Routine Description:
  126. This debugger extension dumps the virtual memory info for the
  127. address specified.
  128. Arguments:
  129. Return Value:
  130. --*/
  131. {
  132. ULONG64 Address;
  133. MEMORY_BASIC_INFORMATION64 Basic;
  134. INIT_API();
  135. Address = GetExpression( args );
  136. if ((Status = g_ExtData->QueryVirtual(Address, &Basic)) != S_OK)
  137. {
  138. dprintf("vprot: QueryVirtual failed, error = 0x%08X\n", Status);
  139. goto Exit;
  140. }
  141. if (Basic.BaseAddress > Address ||
  142. Basic.BaseAddress + Basic.RegionSize <= Address)
  143. {
  144. dprintf("vprot: No containing memory region found.\n");
  145. goto Exit;
  146. }
  147. DumpMemBasicInfo(&Basic, TRUE);
  148. Exit:
  149. EXIT_API();
  150. return S_OK;
  151. }
  152. DECLARE_API( vadump )
  153. {
  154. ULONG64 Address;
  155. MEMORY_BASIC_INFORMATION64 Basic;
  156. ULONG SessClass, SessQual;
  157. BOOL Verbose = FALSE;
  158. INIT_API();
  159. for (;;)
  160. {
  161. while (*args == ' ' || *args == '\t')
  162. {
  163. args++;
  164. }
  165. if (*args != '-' && *args != '/')
  166. {
  167. break;
  168. }
  169. args++;
  170. switch(*args)
  171. {
  172. case 'v':
  173. Verbose = TRUE;
  174. break;
  175. default:
  176. ExtErr("Unknown option '%c'\n", *args);
  177. break;
  178. }
  179. args++;
  180. }
  181. if (g_ExtControl->GetDebuggeeType(&SessClass, &SessQual) != S_OK)
  182. {
  183. ExtErr("Unable to get debuggee type\n");
  184. goto Exit;
  185. }
  186. Address = 0;
  187. for (;;)
  188. {
  189. if ((Status = g_ExtData->QueryVirtual(Address, &Basic)) != S_OK)
  190. {
  191. break;
  192. }
  193. if (SessQual != DEBUG_USER_WINDOWS_SMALL_DUMP)
  194. {
  195. // Full dumps contain the real memory info
  196. // so show all of the information.
  197. DumpMemBasicInfo(&Basic, Verbose);
  198. }
  199. else
  200. {
  201. // Minidumps don't contain extended memory
  202. // info so just show the region addresses.
  203. dprintf("BaseAddress: %p\n", Basic.BaseAddress);
  204. dprintf("RegionSize: %p\n", Basic.RegionSize);
  205. }
  206. dprintf("\n");
  207. Address = Basic.BaseAddress + Basic.RegionSize;
  208. }
  209. Exit:
  210. EXIT_API();
  211. return S_OK;
  212. }