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.

472 lines
8.7 KiB

  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. ref.c
  5. Abstract:
  6. Implements the cref, eref, and gref commands.
  7. Author:
  8. Keith Moore (keithmo) 09-Dec-1995
  9. Environment:
  10. User Mode.
  11. Revision History:
  12. --*/
  13. #include "afdkdp.h"
  14. #pragma hdrstop
  15. DECLARE_API( eref )
  16. /*++
  17. Routine Description:
  18. Dumps the AFD_REFERENCE_DEBUG structure at the specified address.
  19. Arguments:
  20. None.
  21. Return Value:
  22. None.
  23. --*/
  24. {
  25. ULONG64 address = 0;
  26. ULONG idx;
  27. gClient = pClient;
  28. if (!CheckKmGlobals ()) {
  29. return E_INVALIDARG;
  30. }
  31. //
  32. // Verify we're running a checked AFD.SYS.
  33. //
  34. if( !IsReferenceDebug ) {
  35. dprintf(
  36. "eref: this command only available with CHECKED or specially\n"
  37. " built (with /DREFERENCE_DEBUG=1) AFD.SYS!\n"
  38. );
  39. return E_INVALIDARG;
  40. }
  41. //
  42. // Snag the address from the command line.
  43. //
  44. address = GetExpression (args);
  45. if( address == 0 ) {
  46. dprintf( "\nUsage: eref endpoint_address\n" );
  47. return E_INVALIDARG;
  48. }
  49. if (GetFieldValue (address,
  50. "AFD!AFD_ENDPOINT",
  51. "CurrentReferenceSlot",
  52. idx)!=0) {
  53. dprintf("\neref: Could not read CurrentReferenceSlot for endpoint %p\n",
  54. address );
  55. return E_INVALIDARG;
  56. }
  57. if (SavedMinorVersion>=3554) {
  58. ULONG timeHigh;
  59. if (GetFieldValue (address,
  60. "AFD!AFD_ENDPOINT",
  61. "CurrentTimeHigh",
  62. timeHigh)!=0) {
  63. dprintf("\neref: Could not read CurrentTimeHigh for endpoint %p\n",
  64. address );
  65. return E_INVALIDARG;
  66. }
  67. DumpAfdReferenceDebug(
  68. address+EndpRefOffset, (ULONGLONG)idx+((ULONGLONG)timeHigh<<32)
  69. );
  70. }
  71. else {
  72. DumpAfdReferenceDebug(
  73. address+EndpRefOffset, idx
  74. );
  75. }
  76. return S_OK;
  77. } // eref
  78. DECLARE_API( cref )
  79. /*++
  80. Routine Description:
  81. Dumps the AFD_REFERENCE_DEBUG structure at the specified address.
  82. Arguments:
  83. None.
  84. Return Value:
  85. None.
  86. --*/
  87. {
  88. ULONG64 address = 0;
  89. ULONG idx;
  90. gClient = pClient;
  91. if (!CheckKmGlobals ()) {
  92. return E_INVALIDARG;
  93. }
  94. //
  95. // Verify we're running a checked AFD.SYS.
  96. //
  97. if( !IsReferenceDebug ) {
  98. dprintf(
  99. "cref: this command only available with CHECKED or specially\n"
  100. " built (with /DREFERENCE_DEBUG=1) AFD.SYS!\n"
  101. );
  102. return E_INVALIDARG;
  103. }
  104. //
  105. // Snag the address from the command line.
  106. //
  107. address = GetExpression (args);
  108. if( address == 0 ) {
  109. dprintf( "\nUsage: cref connection_address\n" );
  110. return E_INVALIDARG;
  111. }
  112. if (GetFieldValue (address,
  113. "AFD!AFD_CONNECTION",
  114. "CurrentReferenceSlot",
  115. idx)!=0) {
  116. dprintf("\ncref: Could not read CurrentReferenceSlot for connection %p\n",
  117. address );
  118. return E_INVALIDARG;
  119. }
  120. if (SavedMinorVersion>=3554) {
  121. ULONG timeHigh;
  122. if (GetFieldValue (address,
  123. "AFD!AFD_CONNECTION",
  124. "CurrentTimeHigh",
  125. timeHigh)!=0) {
  126. dprintf("\neref: Could not read CurrentTimeHigh for connection %p\n",
  127. address );
  128. return E_INVALIDARG;
  129. }
  130. DumpAfdReferenceDebug(
  131. address+ConnRefOffset, (ULONGLONG)idx+((ULONGLONG)timeHigh<<32)
  132. );
  133. }
  134. else {
  135. DumpAfdReferenceDebug(
  136. address+ConnRefOffset, idx
  137. );
  138. }
  139. return S_OK;
  140. } // cref
  141. DECLARE_API( tref )
  142. /*++
  143. Routine Description:
  144. Dumps the AFD_REFERENCE_DEBUG structure at the specified address.
  145. Arguments:
  146. None.
  147. Return Value:
  148. None.
  149. --*/
  150. {
  151. ULONG64 address = 0;
  152. ULONG idx;
  153. gClient = pClient;
  154. if (!CheckKmGlobals ()) {
  155. return E_INVALIDARG;
  156. }
  157. //
  158. // Verify we're running a checked AFD.SYS.
  159. //
  160. if( !IsReferenceDebug ) {
  161. dprintf(
  162. "tref: this command only available with CHECKED or specially\n"
  163. " built (with /DREFERENCE_DEBUG=1) AFD.SYS!\n"
  164. );
  165. return E_INVALIDARG;
  166. }
  167. //
  168. // Snag the address from the command line.
  169. //
  170. address = GetExpression (args);
  171. if( address == 0 ) {
  172. dprintf( "\nUsage: tref tpacket_info_address\n" );
  173. return E_INVALIDARG;
  174. }
  175. if (GetFieldValue (address,
  176. "AFD!AFD_TPACKETS_INFO_INTERNAL",
  177. "CurrentReferenceSlot",
  178. idx)!=0) {
  179. dprintf("\ntref: Could not read CurrentReferenceSlot for tpInfo %p\n",
  180. address );
  181. return E_INVALIDARG;
  182. }
  183. if (SavedMinorVersion>=3554) {
  184. ULONG timeHigh;
  185. if (GetFieldValue (address,
  186. "AFD!AFD_TPACKETS_INFO_INTERNAL",
  187. "CurrentTimeHigh",
  188. timeHigh)!=0) {
  189. dprintf("\neref: Could not read CurrentTimeHigh for tpInfo %p\n",
  190. address );
  191. return E_INVALIDARG;
  192. }
  193. DumpAfdReferenceDebug(
  194. address+TPackRefOffset, (ULONGLONG)idx+((ULONGLONG)timeHigh<<32)
  195. );
  196. }
  197. else {
  198. DumpAfdReferenceDebug(
  199. address+TPackRefOffset, idx
  200. );
  201. }
  202. return S_OK;
  203. } // tref
  204. DECLARE_API( gref )
  205. /*++
  206. Routine Description:
  207. Dumps the AFD_GLOBAL_REFERENCE_DEBUG structure in the system.
  208. Arguments:
  209. None.
  210. Return Value:
  211. None.
  212. --*/
  213. {
  214. #if GLOBAL_REFERENCE_DEBUG
  215. ULONG64 address;
  216. DWORD currentSlot;
  217. DWORD slot;
  218. ULONG result;
  219. ULONG64 compareAddress = 0;
  220. DWORD numEntries;
  221. DWORD maxEntries;
  222. DWORD entriesToRead;
  223. CHAR buffer[sizeof(AFD_GLOBAL_REFERENCE_DEBUG) * 64];
  224. gClient = pClient;
  225. if (!CheckKmGlobals ()) {
  226. return E_INVALIDARG;
  227. }
  228. //
  229. // Verify we're running a checked AFD.SYS.
  230. //
  231. if( !IsCheckedAfd ) {
  232. dprintf(
  233. "gref: this command only available with CHECKED AFD.SYS!\n"
  234. );
  235. return E_INVALIDARG;
  236. }
  237. //
  238. // Snag the optional "connection compare" address from the command line.
  239. //
  240. sscanf( args, "%lx", &compareAddress );
  241. //
  242. // Find the global reference data.
  243. //
  244. address = GetExpression( "afd!AfdGlobalReference" );
  245. if( address == 0 ) {
  246. dprintf( "cannot find afd!AfdGlobalReference\n" );
  247. return E_INVALIDARG;
  248. }
  249. currentSlot = GetExpression( "afd!AfdGlobalReferenceSlot" );
  250. if( currentSlot == 0 ) {
  251. dprintf( "cannot find afd!AfdGlobalReferenceSlot\n" );
  252. return E_INVALIDARG;
  253. }
  254. if( !ReadMemory(
  255. currentSlot,
  256. &currentSlot,
  257. sizeof(currentSlot),
  258. &result
  259. ) ) {
  260. dprintf( "cannot read afd!AfdGlobalReferenceSlot\n" );
  261. return E_INVALIDARG;
  262. }
  263. if( currentSlot < MAX_GLOBAL_REFERENCE ) {
  264. numEntries = currentSlot;
  265. } else {
  266. numEntries = MAX_GLOBAL_REFERENCE;
  267. }
  268. //
  269. // Dump it all.
  270. //
  271. slot = 0;
  272. maxEntries = sizeof(buffer) / sizeof(AFD_GLOBAL_REFERENCE_DEBUG);
  273. currentSlot %= MAX_GLOBAL_REFERENCE;
  274. while( numEntries > 0 ) {
  275. entriesToRead = min( numEntries, maxEntries );
  276. if (CheckControlC ())
  277. break;
  278. if( !ReadMemory(
  279. address,
  280. buffer,
  281. entriesToRead * sizeof(AFD_GLOBAL_REFERENCE_DEBUG),
  282. &result
  283. ) ) {
  284. dprintf(
  285. "gref: cannot read AFD_GLOBAL_REFERENCE_DEBUG @ %p\n",
  286. address
  287. );
  288. return;
  289. }
  290. if( DumpAfdGlobalReferenceDebug(
  291. (PAFD_GLOBAL_REFERENCE_DEBUG)buffer,
  292. address,
  293. currentSlot,
  294. slot,
  295. entriesToRead,
  296. compareAddress
  297. ) ) {
  298. break;
  299. }
  300. address += entriesToRead * sizeof(AFD_GLOBAL_REFERENCE_DEBUG);
  301. slot += entriesToRead;
  302. numEntries -= entriesToRead;
  303. }
  304. return S_OK;
  305. #else
  306. dprintf(
  307. "gref: not yet implemented\n"
  308. );
  309. return E_INVALIDARG;
  310. #endif
  311. } // gref