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.

1214 lines
35 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. ioverifier.c
  5. Abstract:
  6. WinDbg Extension code for accessing I/O Verifier information
  7. Author:
  8. Adrian J. Oney (adriao) 11-Oct-2000
  9. Environment:
  10. User Mode.
  11. Revision History:
  12. --*/
  13. #include "precomp.h"
  14. #pragma hdrstop
  15. BOOLEAN
  16. GetTheSystemTime (
  17. OUT PLARGE_INTEGER Time
  18. );
  19. VOID
  20. PrintIrpStack(
  21. IN ULONG64 IrpSp
  22. );
  23. typedef enum {
  24. IOV_EVENT_NONE = 0,
  25. IOV_EVENT_IO_ALLOCATE_IRP,
  26. IOV_EVENT_IO_CALL_DRIVER,
  27. IOV_EVENT_IO_CALL_DRIVER_UNWIND,
  28. IOV_EVENT_IO_COMPLETE_REQUEST,
  29. IOV_EVENT_IO_COMPLETION_ROUTINE,
  30. IOV_EVENT_IO_COMPLETION_ROUTINE_UNWIND,
  31. IOV_EVENT_IO_CANCEL_IRP,
  32. IOV_EVENT_IO_FREE_IRP
  33. } IOV_LOG_EVENT;
  34. #define VI_DATABASE_HASH_SIZE 256
  35. #define VI_DATABASE_HASH_PRIME 131
  36. #define VI_DATABASE_CALCULATE_HASH(Irp) \
  37. (((((UINT_PTR) Irp)/PageSize)*VI_DATABASE_HASH_PRIME) % VI_DATABASE_HASH_SIZE)
  38. #define IRP_ALLOC_COUNT 8
  39. #define IRP_LOG_ENTRIES 16
  40. #define TRACKFLAG_SURROGATE 0x00000002
  41. #define TRACKFLAG_HAS_SURROGATE 0x00000004
  42. #define TRACKFLAG_PROTECTEDIRP 0x00000008
  43. #define TRACKFLAG_QUEUED_INTERNALLY 0x00000010
  44. #define TRACKFLAG_BOGUS 0x00000020
  45. #define TRACKFLAG_RELEASED 0x00000040
  46. #define TRACKFLAG_SRB_MUNGED 0x00000080
  47. #define TRACKFLAG_SWAPPED_BACK 0x00000100
  48. #define TRACKFLAG_DIRECT_BUFFERED 0x00000200
  49. #define TRACKFLAG_WATERMARKED 0x00100000
  50. #define TRACKFLAG_IO_ALLOCATED 0x00200000
  51. #define TRACKFLAG_UNWOUND_BADLY 0x00400000
  52. #define TRACKFLAG_PASSED_AT_BAD_IRQL 0x02000000
  53. #define TRACKFLAG_IN_TRANSIT 0x40000000
  54. ENUM_NAME LogEntryTypes[] = {
  55. ENUM_NAME(IOV_EVENT_NONE),
  56. ENUM_NAME(IOV_EVENT_IO_ALLOCATE_IRP),
  57. ENUM_NAME(IOV_EVENT_IO_CALL_DRIVER),
  58. ENUM_NAME(IOV_EVENT_IO_CALL_DRIVER_UNWIND),
  59. ENUM_NAME(IOV_EVENT_IO_COMPLETE_REQUEST),
  60. ENUM_NAME(IOV_EVENT_IO_COMPLETION_ROUTINE),
  61. ENUM_NAME(IOV_EVENT_IO_COMPLETION_ROUTINE_UNWIND),
  62. ENUM_NAME(IOV_EVENT_IO_CANCEL_IRP),
  63. ENUM_NAME(IOV_EVENT_IO_FREE_IRP),
  64. {0,0}
  65. };
  66. typedef enum {
  67. IOV_SYMBOL_PROBLEM,
  68. IOV_NO_DATABASE,
  69. IOV_ACCESS_PROBLEM,
  70. IOV_WALK_TERMINATED,
  71. IOV_ALL_PACKETS_WALKED,
  72. IOV_CTRL_C
  73. } IOV_WALK_RESULT;
  74. typedef BOOL (*PFN_IOVERIFIER_PACKET_ENUM)(ULONG64 Packet, PVOID Context);
  75. IOV_WALK_RESULT
  76. IoVerifierEnumIovPackets(
  77. IN ULONG64 TargetIrp OPTIONAL,
  78. IN PFN_IOVERIFIER_PACKET_ENUM Callback,
  79. IN PVOID Context,
  80. OUT ULONG *PacketsScanned
  81. );
  82. typedef struct {
  83. ULONG64 IrpToStopOn;
  84. } DUMP_CONTEXT, *PDUMP_CONTEXT;
  85. BOOL
  86. IoVerifierDumpIovPacketDetailed(
  87. IN ULONG64 IovPacketReal,
  88. IN PVOID Context
  89. );
  90. BOOL
  91. IoVerifierDumpIovPacketSummary(
  92. IN ULONG64 IovPacketReal,
  93. IN PVOID Context
  94. );
  95. DECLARE_API( iovirp )
  96. /*++
  97. Routine Description:
  98. Temporary verifier irp data dumper until this is integrated into !irp itself
  99. Arguments:
  100. args - the irp to dump
  101. Return Value:
  102. None
  103. --*/
  104. {
  105. ULONG64 irpToDump = 0;
  106. IOV_WALK_RESULT walkResult;
  107. DUMP_CONTEXT dumpContext;
  108. ULONG packetsOutstanding;
  109. irpToDump = GetExpression(args);
  110. dumpContext.IrpToStopOn = irpToDump;
  111. if (irpToDump == 0) {
  112. dprintf("!Irp Outstanding !DevStack !DrvObj\n");
  113. }
  114. walkResult = IoVerifierEnumIovPackets(
  115. irpToDump,
  116. irpToDump ? IoVerifierDumpIovPacketDetailed :
  117. IoVerifierDumpIovPacketSummary,
  118. &dumpContext,
  119. &packetsOutstanding
  120. );
  121. switch(walkResult) {
  122. case IOV_SYMBOL_PROBLEM:
  123. dprintf("No information available - check symbols\n");
  124. break;
  125. case IOV_NO_DATABASE:
  126. dprintf("No information available - the verifier is probably disabled\n");
  127. break;
  128. case IOV_ACCESS_PROBLEM:
  129. dprintf("A problem occured reading memory\n");
  130. break;
  131. case IOV_WALK_TERMINATED:
  132. case IOV_ALL_PACKETS_WALKED:
  133. case IOV_CTRL_C:
  134. default:
  135. break;
  136. }
  137. dprintf("Packets processed: 0x%x\n", packetsOutstanding);
  138. return S_OK;
  139. }
  140. IOV_WALK_RESULT
  141. IoVerifierEnumIovPackets(
  142. IN ULONG64 TargetIrp OPTIONAL,
  143. IN PFN_IOVERIFIER_PACKET_ENUM Callback,
  144. IN PVOID Context,
  145. OUT ULONG *PacketsScanned
  146. )
  147. {
  148. ULONG64 ViIrpDatabaseReal = 0;
  149. PVOID ViIrpDatabaseLocal;
  150. ULONG sizeofListEntry;
  151. ULONG start, end, i, hashLinkOffset;
  152. ULONG64 listEntryHead, listEntryNext, iovPacketReal, currentIrp;
  153. *PacketsScanned = 0;
  154. sizeofListEntry = GetTypeSize("nt!_LIST_ENTRY");
  155. if (sizeofListEntry == 0) {
  156. return IOV_SYMBOL_PROBLEM;
  157. }
  158. ViIrpDatabaseReal = GetPointerValue("nt!ViIrpDatabase");
  159. if (ViIrpDatabaseReal == 0) {
  160. return IOV_NO_DATABASE;
  161. }
  162. GetFieldOffset("nt!IOV_REQUEST_PACKET", "HashLink.Flink", &hashLinkOffset);
  163. if (TargetIrp != 0) {
  164. start = end = (ULONG ) (VI_DATABASE_CALCULATE_HASH(TargetIrp));
  165. } else {
  166. start = 0;
  167. end = VI_DATABASE_HASH_SIZE-1;
  168. }
  169. for(i=start; i<=end; i++) {
  170. listEntryHead = ViIrpDatabaseReal + (i*sizeofListEntry);
  171. if (GetFieldValue(listEntryHead, "nt!_LIST_ENTRY", "Flink", listEntryNext)) {
  172. return IOV_ACCESS_PROBLEM;
  173. }
  174. while(listEntryNext != listEntryHead) {
  175. (*PacketsScanned)++;
  176. iovPacketReal = listEntryNext - hashLinkOffset;
  177. if (GetFieldValue(iovPacketReal, "nt!IOV_REQUEST_PACKET", "HashLink.Flink", listEntryNext)) {
  178. return IOV_ACCESS_PROBLEM;
  179. }
  180. if (TargetIrp) {
  181. if (GetFieldValue(iovPacketReal, "nt!IOV_REQUEST_PACKET", "TrackedIrp", currentIrp)) {
  182. return IOV_ACCESS_PROBLEM;
  183. }
  184. if (TargetIrp != currentIrp) {
  185. continue;
  186. }
  187. }
  188. if (CheckControlC()) {
  189. return IOV_CTRL_C;
  190. }
  191. if (Callback(iovPacketReal, Context) == FALSE) {
  192. return IOV_WALK_TERMINATED;
  193. }
  194. }
  195. if (CheckControlC()) {
  196. return IOV_CTRL_C;
  197. }
  198. }
  199. return IOV_ALL_PACKETS_WALKED;
  200. }
  201. BOOL
  202. IoVerifierDumpIovPacketDetailed(
  203. IN ULONG64 IovPacketReal,
  204. IN PVOID Context
  205. )
  206. {
  207. ULONG i, j;
  208. UCHAR symBuffer[256];
  209. ULONG64 displacement, logBuffer, allocatorAddress, logBufferEntry;
  210. ULONG logBufferOffset, sizeofLogEntry, allocatorOffset;
  211. PDUMP_CONTEXT dumpContext;
  212. dumpContext = (PDUMP_CONTEXT) Context;
  213. InitTypeRead(IovPacketReal, nt!IOV_REQUEST_PACKET);
  214. dprintf("IovPacket\t%1p\n", IovPacketReal);
  215. dprintf("TrackedIrp\t%1p\n", ReadField(TrackedIrp));
  216. dprintf("HeaderLock\t%x\n", ReadField(HeaderLock));
  217. dprintf("LockIrql\t%x\n", ReadField(LockIrql));
  218. dprintf("ReferenceCount\t%x\n", ReadField(ReferenceCount));
  219. dprintf("PointerCount\t%x\n", ReadField(PointerCount));
  220. dprintf("HeaderFlags\t%08x\n", ReadField(HeaderFlags));
  221. dprintf("ChainHead\t%1p\n", ReadField(ChainHead));
  222. dprintf("Flags\t\t%08x\n", ReadField(Flags));
  223. dprintf("DepartureIrql\t%x\n", ReadField(DepartureIrql));
  224. dprintf("ArrivalIrql\t%x\n", ReadField(ArrivalIrql));
  225. dprintf("StackCount\t%x\n", ReadField(StackCount));
  226. dprintf("QuotaCharge\t%08x\n", ReadField(QuotaCharge));
  227. dprintf("QuotaProcess\t%1p\n", ReadField(QuotaProcess));
  228. dprintf("RealIrpCompletionRoutine\t%1p\n", ReadField(RealIrpCompletionRoutine));
  229. dprintf("RealIrpControl\t\t\t%x\n", ReadField(RealIrpControl));
  230. dprintf("RealIrpContext\t\t\t%1p\n", ReadField(RealIrpContext));
  231. dprintf("TopStackLocation\t%x\n", ReadField(TopStackLocation));
  232. dprintf("PriorityBoost\t\t%x\n", ReadField(PriorityBoost));
  233. dprintf("LastLocation\t\t%x\n", ReadField(LastLocation));
  234. dprintf("RefTrackingCount\t%x\n", ReadField(RefTrackingCount));
  235. dprintf("SystemDestVA\t\t%1p\n", ReadField(SystemDestVA));
  236. dprintf("VerifierSettings\t%1p\n", ReadField(VerifierSettings));
  237. dprintf("pIovSessionData\t\t%1p\n", ReadField(pIovSessionData));
  238. GetFieldOffset("nt!IOV_REQUEST_PACKET", "AllocatorStack", &allocatorOffset);
  239. dprintf("Allocation Stack:\n");
  240. for(i=0; i<IRP_ALLOC_COUNT; i++) {
  241. allocatorAddress = GetPointerFromAddress(IovPacketReal + allocatorOffset + i*DBG_PTR_SIZE);
  242. if (allocatorAddress) {
  243. symBuffer[0]='!';
  244. GetSymbol(allocatorAddress, symBuffer, &displacement);
  245. dprintf(" %s+%1p (%1p)\n",symBuffer,displacement,allocatorAddress);
  246. }
  247. }
  248. dprintf("\n");
  249. //
  250. // If this was compiled free, these will both come back zero.
  251. //
  252. i = (ULONG) ReadField(LogEntryTail);
  253. j = (ULONG) ReadField(LogEntryHead);
  254. if (i == j) {
  255. dprintf("IRP log entries: none stored\n");
  256. } else {
  257. GetFieldOffset("nt!IOV_REQUEST_PACKET", "LogEntries", &logBufferOffset);
  258. sizeofLogEntry = GetTypeSize("nt!IOV_LOG_ENTRY");
  259. logBuffer = IovPacketReal + logBufferOffset;
  260. while(i != j) {
  261. logBufferEntry = logBuffer + i*sizeofLogEntry;
  262. InitTypeRead(logBufferEntry, nt!IOV_LOG_ENTRY);
  263. dprintf("%s\t", getEnumName((ULONG) ReadField(Event), LogEntryTypes));
  264. dprintf("by %1p (%p) ", ReadField(Address), ReadField(Data));
  265. dprintf("on .thread %1p\n", ReadField(Thread));
  266. i = (i+1) % IRP_LOG_ENTRIES;
  267. }
  268. }
  269. InitTypeRead(IovPacketReal, nt!IOV_REQUEST_PACKET);
  270. return (dumpContext->IrpToStopOn != ReadField(TrackedIrp));
  271. }
  272. BOOL
  273. IoVerifierDumpIovPacketSummary(
  274. IN ULONG64 IovPacketReal,
  275. IN PVOID Context
  276. )
  277. {
  278. ULONG64 trackedIrp, iovSessionData, currentLocation, deviceObject;
  279. ULONG64 topStackLocation;
  280. ULONG64 iovCurStackLocation, iovNextStackLocation, currentIoStackLocation;
  281. PDUMP_CONTEXT dumpContext;
  282. ULONG pvoidSize, stackDataOffset;
  283. LARGE_INTEGER startTime, elapsedTime;
  284. TIME_FIELDS parsedTime;
  285. dumpContext = (PDUMP_CONTEXT) Context;
  286. pvoidSize = IsPtr64() ? 8 : 4;
  287. InitTypeRead(IovPacketReal, nt!IOV_REQUEST_PACKET);
  288. trackedIrp = ReadField(TrackedIrp);
  289. if (trackedIrp == 0) {
  290. //
  291. // If there's no IRP, it means we are tracking something that has
  292. // completed but hasn't unwound. Therefore we ignore it.
  293. //
  294. goto PrintSummaryExit;
  295. }
  296. if (ReadField(Flags) & TRACKFLAG_HAS_SURROGATE) {
  297. //
  298. // We only want to display the surrogate in this case.
  299. //
  300. goto PrintSummaryExit;
  301. }
  302. iovSessionData = ReadField(pIovSessionData);
  303. if (iovSessionData == 0) {
  304. //
  305. // We only want to display live IRPs
  306. //
  307. goto PrintSummaryExit;
  308. }
  309. topStackLocation = ReadField(TopStackLocation);
  310. InitTypeRead(trackedIrp, nt!IRP);
  311. currentLocation = ReadField(CurrentLocation);
  312. currentIoStackLocation = ReadField(Tail.Overlay.CurrentStackLocation);
  313. parsedTime.Minute = 0;
  314. if (currentLocation >= topStackLocation) {
  315. deviceObject = 0;
  316. dprintf("%1p [Completed] ", trackedIrp);
  317. } else {
  318. GetFieldOffset("nt!IOV_SESSION_DATA", "StackData", &stackDataOffset);
  319. iovCurStackLocation =
  320. iovSessionData + stackDataOffset +
  321. (GetTypeSize("nt!IOV_STACK_LOCATION")*currentLocation);
  322. InitTypeRead(iovCurStackLocation, nt!IOV_STACK_LOCATION);
  323. if (ReadField(InUse)) {
  324. iovNextStackLocation =
  325. iovSessionData + stackDataOffset +
  326. (GetTypeSize("nt!IOV_STACK_LOCATION")*(currentLocation - 1));
  327. InitTypeRead(iovNextStackLocation, nt!IOV_STACK_LOCATION);
  328. //
  329. // Calculate the elasped time for this slot.
  330. //
  331. if (currentLocation && ReadField(InUse)) {
  332. startTime.QuadPart = ReadField(PerfDispatchStart.QuadPart);
  333. } else {
  334. GetTheSystemTime(&startTime);
  335. }
  336. InitTypeRead(iovCurStackLocation, nt!IOV_STACK_LOCATION);
  337. elapsedTime.QuadPart =
  338. startTime.QuadPart - ReadField(PerfDispatchStart.QuadPart);
  339. RtlTimeToElapsedTimeFields( &elapsedTime, &parsedTime );
  340. InitTypeRead(currentIoStackLocation, nt!IO_STACK_LOCATION);
  341. deviceObject = ReadField(DeviceObject);
  342. //
  343. // Alright, we got the goods. Let's print what we know...
  344. //
  345. dprintf("%1p %ld:%02ld:%02ld.%04ld %1p ",
  346. trackedIrp,
  347. parsedTime.Hour,
  348. parsedTime.Minute,
  349. parsedTime.Second,
  350. parsedTime.Milliseconds,
  351. deviceObject
  352. );
  353. } else {
  354. InitTypeRead(currentIoStackLocation, nt!IO_STACK_LOCATION);
  355. deviceObject = ReadField(DeviceObject);
  356. dprintf("%08lx %08lx ", trackedIrp, deviceObject);
  357. }
  358. }
  359. if (deviceObject) {
  360. DumpDevice(deviceObject, 20, FALSE);
  361. }
  362. dprintf(" ");
  363. PrintIrpStack(currentIoStackLocation);
  364. #if 0
  365. if (parsedTime.Minute && (irp.CancelRoutine == NULL)) {
  366. //
  367. // This IRP has been held over a minute with no cancel routine.
  368. // Take a free moment to flame the driver writer.
  369. //
  370. dprintf("*") ;
  371. *Delayed = TRUE ; // Should *not* be set to false otherwise.
  372. }
  373. #endif
  374. dprintf("\n") ;
  375. #if 0
  376. if (DumpLevel>0) {
  377. IovPacketPrintDetailed(
  378. IovPacket,
  379. &irp,
  380. RunTime
  381. );
  382. }
  383. #endif
  384. PrintSummaryExit:
  385. return TRUE;
  386. }
  387. /*
  388. #include "precomp.h"
  389. #include "irpverif.h"
  390. #pragma hdrstop
  391. VOID
  392. IovPacketPrintSummary(
  393. IN PIOV_REQUEST_PACKET IovPacket,
  394. IN LARGE_INTEGER *RunTime,
  395. IN ULONG DumpLevel,
  396. OUT PBOOLEAN Delayed,
  397. OUT PLIST_ENTRY NextListEntry
  398. );
  399. BOOLEAN
  400. GetTheSystemTime (
  401. OUT PLARGE_INTEGER Time
  402. );
  403. VOID
  404. DumpAllTrackedIrps(
  405. VOID
  406. )
  407. {
  408. int i, j ;
  409. ULONG result;
  410. LIST_ENTRY iovPacketTable[IRP_TRACKING_HASH_SIZE] ;
  411. PLIST_ENTRY listHead, listEntry;
  412. LIST_ENTRY nextListEntry;
  413. PIOV_REQUEST_PACKET pIovPacket;
  414. LARGE_INTEGER RunTime ;
  415. ULONG_PTR tableAddress ;
  416. BOOLEAN delayed = FALSE ;
  417. tableAddress = GetExpression( "Nt!IovpIrpTrackingTable" ) ;
  418. if (tableAddress == 0) {
  419. goto DumpNoMore;
  420. }
  421. if (!ReadMemory(tableAddress, iovPacketTable,
  422. sizeof(LIST_ENTRY)*IRP_TRACKING_HASH_SIZE, &result)) {
  423. goto DumpNoMore;
  424. }
  425. dprintf("!Irp Outstanding !DevStack !DrvObj\n") ;
  426. GetTheSystemTime(&RunTime);
  427. for(i=j=0; i<IRP_TRACKING_HASH_SIZE; i++) {
  428. listEntry = &iovPacketTable[i];
  429. listHead = ((PLIST_ENTRY)tableAddress)+i;
  430. while(listEntry->Flink != listHead) {
  431. j++;
  432. pIovPacket = CONTAINING_RECORD(
  433. listEntry->Flink,
  434. IOV_REQUEST_PACKET,
  435. HashLink
  436. );
  437. dprintf("[%x.%x] = %x\n", i, j, pIovPacket) ;
  438. listEntry = &nextListEntry;
  439. IovPacketPrintSummary(
  440. pIovPacket,
  441. &RunTime,
  442. 0,
  443. &delayed,
  444. listEntry
  445. );
  446. if (IsListEmpty(listEntry)) {
  447. break;
  448. }
  449. if (CheckControlC()) {
  450. goto DumpNoMore;
  451. }
  452. }
  453. }
  454. if (!j) {
  455. dprintf("\nIrp tracking does not appear to be enabled. Use \"!patch "
  456. "IrpTrack\" in the\nchecked build to enable this feature.\n") ;
  457. }
  458. if (delayed) {
  459. dprintf("* PROBABLE DRIVER BUG: An IRP has been sitting in the driver for more\n"
  460. " than a minute without a cancel routine\n") ;
  461. }
  462. DumpNoMore:
  463. return ;
  464. }
  465. VOID
  466. IovPacketPrintDetailed(
  467. PIOV_REQUEST_PACKET IovPacket,
  468. PIRP IrpData,
  469. LARGE_INTEGER *RunTime
  470. )
  471. {
  472. CHAR buffer[80];
  473. ULONG displacement;
  474. IOV_REQUEST_PACKET iovPacketData;
  475. LARGE_INTEGER *startTime, elapsedTime ;
  476. TIME_FIELDS Times;
  477. IRP_ALLOC_DATA irpAllocData ;
  478. ULONG result;
  479. int i ;
  480. if (!ReadMemory((ULONG_PTR) IovPacket, &iovPacketData,
  481. sizeof(IOV_REQUEST_PACKET), &result)) {
  482. return;
  483. }
  484. dprintf(" TrackingData - 0x%08lx\n", IovPacket);
  485. dprintf(" TrackedIrp:0x%08lx\n", iovPacketData.TrackedIrp);
  486. dprintf(" Flags:0x%08lx\n", iovPacketData.Flags);
  487. if (iovPacketData.Flags&TRACKFLAG_ACTIVE) {
  488. dprintf(" TRACKFLAG_ACTIVE\n");
  489. }
  490. if (iovPacketData.Flags&TRACKFLAG_SURROGATE) {
  491. dprintf(" TRACKFLAG_SURROGATE\n");
  492. }
  493. if (iovPacketData.Flags&TRACKFLAG_HAS_SURROGATE) {
  494. dprintf(" TRACKFLAG_HAS_SURROGATE\n");
  495. }
  496. if (iovPacketData.Flags&TRACKFLAG_PROTECTEDIRP) {
  497. dprintf(" TRACKFLAG_PROTECTEDIRP\n");
  498. }
  499. if (iovPacketData.Flags&TRACKFLAG_QUEUED_INTERNALLY) {
  500. dprintf(" TRACKFLAG_QUEUED_INTERNALLY\n");
  501. }
  502. if (iovPacketData.Flags&TRACKFLAG_BOGUS) {
  503. dprintf(" TRACKFLAG_BOGUS\n");
  504. }
  505. if (iovPacketData.Flags&TRACKFLAG_RELEASED) {
  506. dprintf(" TRACKFLAG_RELEASED\n");
  507. }
  508. if (iovPacketData.Flags&TRACKFLAG_SRB_MUNGED) {
  509. dprintf(" TRACKFLAG_SRB_MUNGED\n");
  510. }
  511. if (iovPacketData.Flags&TRACKFLAG_SWAPPED_BACK) {
  512. dprintf(" TRACKFLAG_SWAPPED_BACK\n") ;
  513. }
  514. if (iovPacketData.Flags&TRACKFLAG_WATERMARKED) {
  515. dprintf(" TRACKFLAG_WATERMARKED\n");
  516. }
  517. if (iovPacketData.Flags&TRACKFLAG_IO_ALLOCATED) {
  518. dprintf(" TRACKFLAG_IO_ALLOCATED\n");
  519. }
  520. if (iovPacketData.Flags&TRACKFLAG_IGNORE_NONCOMPLETES) {
  521. dprintf(" TRACKFLAG_IGNORE_NONCOMPLETES\n");
  522. }
  523. if (iovPacketData.Flags&TRACKFLAG_PASSED_FAILURE) {
  524. dprintf(" TRACKFLAG_PASSED_FAILURE\n");
  525. }
  526. if (iovPacketData.Flags&TRACKFLAG_IN_TRANSIT) {
  527. dprintf(" TRACKFLAG_IN_TRANSIT\n");
  528. }
  529. if (iovPacketData.Flags&TRACKFLAG_REMOVED_FROM_TABLE) {
  530. dprintf(" TRACKFLAG_REMOVED_FROM_TABLE\n");
  531. }
  532. dprintf(" AssertFlags:0x%08lx\n", iovPacketData.AssertFlags);
  533. if (iovPacketData.AssertFlags&ASSERTFLAG_TRACKIRPS) {
  534. dprintf(" ASSERTFLAG_TRACKIRPS\n");
  535. }
  536. if (iovPacketData.AssertFlags&ASSERTFLAG_MONITOR_ALLOCS) {
  537. dprintf(" ASSERTFLAG_MONITOR_ALLOCS\n");
  538. }
  539. if (iovPacketData.AssertFlags&ASSERTFLAG_POLICEIRPS) {
  540. dprintf(" ASSERTFLAG_POLICEIRPS\n");
  541. }
  542. if (iovPacketData.AssertFlags&ASSERTFLAG_MONITORMAJORS) {
  543. dprintf(" ASSERTFLAG_MONITORMAJORS\n");
  544. }
  545. if (iovPacketData.AssertFlags&ASSERTFLAG_SURROGATE) {
  546. dprintf(" ASSERTFLAG_SURROGATE\n");
  547. }
  548. if (iovPacketData.AssertFlags&ASSERTFLAG_SMASH_SRBS) {
  549. dprintf(" ASSERTFLAG_SMASH_SRBS\n");
  550. }
  551. if (iovPacketData.AssertFlags&ASSERTFLAG_CONSUME_ALWAYS) {
  552. dprintf(" ASSERTFLAG_CONSUME_ALWAYS\n");
  553. }
  554. if (iovPacketData.AssertFlags&ASSERTFLAG_FORCEPENDING) {
  555. dprintf(" ASSERTFLAG_FORCEPENDING\n");
  556. }
  557. if (iovPacketData.AssertFlags&ASSERTFLAG_COMPLETEATDPC) {
  558. dprintf(" ASSERTFLAG_COMPLETEATDPC\n");
  559. }
  560. if (iovPacketData.AssertFlags&ASSERTFLAG_COMPLETEATPASSIVE) {
  561. dprintf(" ASSERTFLAG_COMPLETEATPASSIVE\n");
  562. }
  563. if (iovPacketData.AssertFlags&ASSERTFLAG_DEFERCOMPLETION) {
  564. dprintf(" ASSERTFLAG_DEFERCOMPLETION\n");
  565. }
  566. if (iovPacketData.AssertFlags&ASSERTFLAG_ROTATE_STATUS) {
  567. dprintf(" ASSERTFLAG_ROTATE_STATUS\n");
  568. }
  569. if (iovPacketData.AssertFlags&ASSERTFLAG_SEEDSTACK) {
  570. dprintf(" ASSERTFLAG_SEEDSTACK\n");
  571. }
  572. dprintf(" ReferenceCount:0x%x PointerCount:0x%x\n",
  573. iovPacketData.ReferenceCount,
  574. iovPacketData.PointerCount
  575. ) ;
  576. dprintf(" RealIrpCompletionRoutine:0x%08lx\n",
  577. iovPacketData.RealIrpCompletionRoutine
  578. ) ;
  579. dprintf(" RealIrpControl:0x%02lx RealIrpContext:0x%08lx\n",
  580. iovPacketData.RealIrpControl,
  581. iovPacketData.RealIrpContext
  582. ) ;
  583. dprintf(" TopStackLocation:0x%x LastLocation:0x%x StackCount:0x%x\n",
  584. iovPacketData.TopStackLocation,
  585. iovPacketData.LastLocation,
  586. iovPacketData.StackCount
  587. ) ;
  588. dprintf("\n RefTrackingCount:0x%x\n",
  589. iovPacketData.RefTrackingCount
  590. ) ;
  591. //
  592. // Calculate the elasped time for the entire IRP
  593. //
  594. elapsedTime.QuadPart =
  595. RunTime->QuadPart - IrpTrackingEntry->PerfCounterStart.QuadPart;
  596. RtlTimeToElapsedTimeFields ( &elapsedTime, &Times);
  597. dprintf(" IrpElapsedTime (hms) - %ld:%02ld:%02ld.%04ld\n",
  598. Times.Hour,
  599. Times.Minute,
  600. Times.Second,
  601. Times.Milliseconds
  602. );
  603. //
  604. // Preload symbols...
  605. //
  606. for(i=0; i<=IrpTrackingEntry->StackCount; i++) {
  607. if (StackLocationData[i].InUse) {
  608. GetSymbol((LPVOID)StackLocationData[i].LastDispatch, buffer, &displacement);
  609. }
  610. }
  611. //
  612. // Preload symbols...
  613. //
  614. for(i=0; i<IRP_ALLOC_COUNT; i++) {
  615. GetSymbol((LPVOID)iovPacketData.AllocatorStack[i], buffer, &displacement);
  616. }
  617. dprintf("\n Stack at time of IoAllocateIrp:\n") ;
  618. for(i=0; i<IRP_ALLOC_COUNT; i++) {
  619. buffer[0] = '!';
  620. GetSymbol((LPVOID)iovPacketData.AllocatorStack[i], buffer, &displacement);
  621. dprintf(" %s", buffer) ;
  622. if (displacement) {
  623. dprintf( "+0x%x", displacement );
  624. }
  625. dprintf("\n") ;
  626. }
  627. dprintf("\n ## InUse Head Flags IrpSp ElaspedTime Dispatch\n");
  628. for(i=0; i<=IrpTrackingEntry->StackCount; i++) {
  629. //
  630. // Show each stack location
  631. //
  632. if (StackLocationData[i].InUse) {
  633. if (i&&StackLocationData[i-1].InUse) {
  634. startTime = &StackLocationData[i-1].PerfCounterStart ;
  635. } else {
  636. startTime = RunTime ;
  637. }
  638. elapsedTime.QuadPart =
  639. startTime->QuadPart - StackLocationData[i].PerfCounterStart.QuadPart;
  640. RtlTimeToElapsedTimeFields ( &elapsedTime, &Times);
  641. buffer[0] = '!';
  642. GetSymbol((LPVOID)StackLocationData[i].LastDispatch, buffer, &displacement);
  643. dprintf(
  644. " %c%02lx Y %02lx %08lx %08lx %ld:%02ld:%02ld.%04ld %s",
  645. (IrpData->CurrentLocation == i) ? '>' : ' ',
  646. i,
  647. StackLocationData[i].OriginalRequestSLD - IrpTrackingPointer->StackData,
  648. StackLocationData[i].Flags,
  649. StackLocationData[i].IrpSp,
  650. Times.Hour,
  651. Times.Minute,
  652. Times.Second,
  653. Times.Milliseconds,
  654. buffer
  655. ) ;
  656. if (displacement) {
  657. dprintf( "+0x%x", displacement );
  658. }
  659. } else {
  660. dprintf(
  661. " %c%02lx N %08lx",
  662. (IrpData->CurrentLocation == i) ? '>' : ' ',
  663. i,
  664. StackLocationData[i].Flags
  665. ) ;
  666. }
  667. dprintf("\n") ;
  668. }
  669. dprintf("\n") ;
  670. }
  671. #endif
  672. */
  673. PCHAR IrpMajorNames[] = {
  674. "IRP_MJ_CREATE", // 0x00
  675. "IRP_MJ_CREATE_NAMED_PIPE", // 0x01
  676. "IRP_MJ_CLOSE", // 0x02
  677. "IRP_MJ_READ", // 0x03
  678. "IRP_MJ_WRITE", // 0x04
  679. "IRP_MJ_QUERY_INFORMATION", // 0x05
  680. "IRP_MJ_SET_INFORMATION", // 0x06
  681. "IRP_MJ_QUERY_EA", // 0x07
  682. "IRP_MJ_SET_EA", // 0x08
  683. "IRP_MJ_FLUSH_BUFFERS", // 0x09
  684. "IRP_MJ_QUERY_VOLUME_INFORMATION", // 0x0a
  685. "IRP_MJ_SET_VOLUME_INFORMATION", // 0x0b
  686. "IRP_MJ_DIRECTORY_CONTROL", // 0x0c
  687. "IRP_MJ_FILE_SYSTEM_CONTROL", // 0x0d
  688. "IRP_MJ_DEVICE_CONTROL", // 0x0e
  689. "IRP_MJ_INTERNAL_DEVICE_CONTROL", // 0x0f
  690. "IRP_MJ_SHUTDOWN", // 0x10
  691. "IRP_MJ_LOCK_CONTROL", // 0x11
  692. "IRP_MJ_CLEANUP", // 0x12
  693. "IRP_MJ_CREATE_MAILSLOT", // 0x13
  694. "IRP_MJ_QUERY_SECURITY", // 0x14
  695. "IRP_MJ_SET_SECURITY", // 0x15
  696. "IRP_MJ_POWER", // 0x16
  697. "IRP_MJ_SYSTEM_CONTROL", // 0x17
  698. "IRP_MJ_DEVICE_CHANGE", // 0x18
  699. "IRP_MJ_QUERY_QUOTA", // 0x19
  700. "IRP_MJ_SET_QUOTA", // 0x1a
  701. "IRP_MJ_PNP", // 0x1b
  702. NULL
  703. } ;
  704. #define MAX_NAMED_MAJOR_IRPS 0x1b
  705. PCHAR PnPIrpNames[] = {
  706. "IRP_MN_START_DEVICE", // 0x00
  707. "IRP_MN_QUERY_REMOVE_DEVICE", // 0x01
  708. "IRP_MN_REMOVE_DEVICE - ", // 0x02
  709. "IRP_MN_CANCEL_REMOVE_DEVICE", // 0x03
  710. "IRP_MN_STOP_DEVICE", // 0x04
  711. "IRP_MN_QUERY_STOP_DEVICE", // 0x05
  712. "IRP_MN_CANCEL_STOP_DEVICE", // 0x06
  713. "IRP_MN_QUERY_DEVICE_RELATIONS", // 0x07
  714. "IRP_MN_QUERY_INTERFACE", // 0x08
  715. "IRP_MN_QUERY_CAPABILITIES", // 0x09
  716. "IRP_MN_QUERY_RESOURCES", // 0x0A
  717. "IRP_MN_QUERY_RESOURCE_REQUIREMENTS", // 0x0B
  718. "IRP_MN_QUERY_DEVICE_TEXT", // 0x0C
  719. "IRP_MN_FILTER_RESOURCE_REQUIREMENTS", // 0x0D
  720. "INVALID_IRP_CODE", //
  721. "IRP_MN_READ_CONFIG", // 0x0F
  722. "IRP_MN_WRITE_CONFIG", // 0x10
  723. "IRP_MN_EJECT", // 0x11
  724. "IRP_MN_SET_LOCK", // 0x12
  725. "IRP_MN_QUERY_ID", // 0x13
  726. "IRP_MN_QUERY_PNP_DEVICE_STATE", // 0x14
  727. "IRP_MN_QUERY_BUS_INFORMATION", // 0x15
  728. "IRP_MN_DEVICE_USAGE_NOTIFICATION", // 0x16
  729. "IRP_MN_SURPRISE_REMOVAL", // 0x17
  730. "IRP_MN_QUERY_LEGACY_BUS_INFORMATION", // 0x18
  731. NULL
  732. } ;
  733. #define MAX_NAMED_PNP_IRP 0x18
  734. PCHAR WmiIrpNames[] = {
  735. "IRP_MN_QUERY_ALL_DATA", // 0x00
  736. "IRP_MN_QUERY_SINGLE_INSTANCE", // 0x01
  737. "IRP_MN_CHANGE_SINGLE_INSTANCE", // 0x02
  738. "IRP_MN_CHANGE_SINGLE_ITEM", // 0x03
  739. "IRP_MN_ENABLE_EVENTS", // 0x04
  740. "IRP_MN_DISABLE_EVENTS", // 0x05
  741. "IRP_MN_ENABLE_COLLECTION", // 0x06
  742. "IRP_MN_DISABLE_COLLECTION", // 0x07
  743. "IRP_MN_REGINFO", // 0x08
  744. "IRP_MN_EXECUTE_METHOD", // 0x09
  745. NULL
  746. } ;
  747. #define MAX_NAMED_WMI_IRP 0x9
  748. PCHAR PowerIrpNames[] = {
  749. "IRP_MN_WAIT_WAKE", // 0x00
  750. "IRP_MN_POWER_SEQUENCE", // 0x01
  751. "IRP_MN_SET_POWER", // 0x02
  752. "IRP_MN_QUERY_POWER", // 0x03
  753. NULL
  754. } ;
  755. #define MAX_NAMED_POWER_IRP 0x3
  756. VOID
  757. PrintIrpStack(
  758. IN ULONG64 IrpSp
  759. )
  760. {
  761. ULONG majorFunction, minorFunction, type;
  762. InitTypeRead(IrpSp, nt!IO_STACK_LOCATION);
  763. majorFunction = (ULONG) ReadField(MajorFunction);
  764. minorFunction = (ULONG) ReadField(MinorFunction);
  765. if ((majorFunction == IRP_MJ_INTERNAL_DEVICE_CONTROL) &&
  766. (minorFunction == IRP_MN_SCSI_CLASS)) {
  767. dprintf("IRP_MJ_SCSI") ;
  768. } else if (majorFunction<=MAX_NAMED_MAJOR_IRPS) {
  769. dprintf(IrpMajorNames[majorFunction]) ;
  770. } else if (majorFunction==0xFF) {
  771. dprintf("IRP_MJ_BOGUS") ;
  772. } else {
  773. dprintf("IRP_MJ_??") ;
  774. }
  775. switch(majorFunction) {
  776. case IRP_MJ_SYSTEM_CONTROL:
  777. dprintf(".") ;
  778. if (minorFunction<=MAX_NAMED_WMI_IRP) {
  779. dprintf(WmiIrpNames[minorFunction]) ;
  780. } else if (minorFunction==0xFF) {
  781. dprintf("IRP_MN_BOGUS") ;
  782. } else {
  783. dprintf("(??)") ;
  784. }
  785. break ;
  786. case IRP_MJ_PNP:
  787. dprintf(".") ;
  788. if (minorFunction<=MAX_NAMED_PNP_IRP) {
  789. dprintf(PnPIrpNames[minorFunction]) ;
  790. } else if (minorFunction==0xFF) {
  791. dprintf("IRP_MN_BOGUS") ;
  792. } else {
  793. dprintf("(??)") ;
  794. }
  795. switch(minorFunction) {
  796. case IRP_MN_QUERY_DEVICE_RELATIONS:
  797. type = (ULONG) ReadField(Parameters.QueryDeviceRelations.Type);
  798. switch(type) {
  799. case BusRelations:
  800. dprintf("(BusRelations)") ;
  801. break ;
  802. case EjectionRelations:
  803. dprintf("(EjectionRelations)") ;
  804. break ;
  805. case PowerRelations:
  806. dprintf("(PowerRelations)") ;
  807. break ;
  808. case RemovalRelations:
  809. dprintf("(RemovalRelations)") ;
  810. break ;
  811. case TargetDeviceRelation:
  812. dprintf("(TargetDeviceRelation)") ;
  813. break ;
  814. default:
  815. dprintf("(??)") ;
  816. break ;
  817. }
  818. break ;
  819. case IRP_MN_QUERY_INTERFACE:
  820. break ;
  821. case IRP_MN_QUERY_DEVICE_TEXT:
  822. type = (ULONG) ReadField(Parameters.QueryId.Type);
  823. switch(type) {
  824. case DeviceTextDescription:
  825. dprintf("(DeviceTextDescription)") ;
  826. break ;
  827. case DeviceTextLocationInformation:
  828. dprintf("(DeviceTextLocationInformation)") ;
  829. break ;
  830. default:
  831. dprintf("(??)") ;
  832. break ;
  833. }
  834. break ;
  835. case IRP_MN_WRITE_CONFIG:
  836. case IRP_MN_READ_CONFIG:
  837. dprintf("(WhichSpace=%x, Buffer=%x, Offset=%x, Length=%x)",
  838. ReadField(Parameters.ReadWriteConfig.WhichSpace),
  839. ReadField(Parameters.ReadWriteConfig.Buffer),
  840. ReadField(Parameters.ReadWriteConfig.Offset),
  841. ReadField(Parameters.ReadWriteConfig.Length)
  842. );
  843. break;
  844. case IRP_MN_SET_LOCK:
  845. if (ReadField(Parameters.SetLock.Lock)) dprintf("(True)") ;
  846. else dprintf("(False)") ;
  847. break ;
  848. case IRP_MN_QUERY_ID:
  849. type = (ULONG) ReadField(Parameters.QueryId.IdType);
  850. switch(type) {
  851. case BusQueryDeviceID:
  852. dprintf("(BusQueryDeviceID)") ;
  853. break ;
  854. case BusQueryHardwareIDs:
  855. dprintf("(BusQueryHardwareIDs)") ;
  856. break ;
  857. case BusQueryCompatibleIDs:
  858. dprintf("(BusQueryCompatibleIDs)") ;
  859. break ;
  860. case BusQueryInstanceID:
  861. dprintf("(BusQueryInstanceID)") ;
  862. break ;
  863. default:
  864. dprintf("(??)") ;
  865. break ;
  866. }
  867. break ;
  868. case IRP_MN_QUERY_BUS_INFORMATION:
  869. // BUGBUG: Should print out
  870. break ;
  871. case IRP_MN_DEVICE_USAGE_NOTIFICATION:
  872. type = (ULONG) ReadField(Parameters.UsageNotification.Type);
  873. switch(type) {
  874. case DeviceUsageTypeUndefined:
  875. dprintf("(DeviceUsageTypeUndefined") ;
  876. break ;
  877. case DeviceUsageTypePaging:
  878. dprintf("(DeviceUsageTypePaging") ;
  879. break ;
  880. case DeviceUsageTypeHibernation:
  881. dprintf("(DeviceUsageTypeHibernation") ;
  882. break ;
  883. case DeviceUsageTypeDumpFile:
  884. dprintf("(DeviceUsageTypeDumpFile") ;
  885. break ;
  886. default:
  887. dprintf("(??)") ;
  888. break ;
  889. }
  890. if (ReadField(Parameters.UsageNotification.InPath)) {
  891. dprintf(", InPath=TRUE)") ;
  892. } else {
  893. dprintf(", InPath=FALSE)") ;
  894. }
  895. break ;
  896. case IRP_MN_QUERY_LEGACY_BUS_INFORMATION:
  897. // BUGBUG: Should print out
  898. break ;
  899. default:
  900. break ;
  901. }
  902. break ;
  903. case IRP_MJ_POWER:
  904. dprintf(".") ;
  905. if (minorFunction<=MAX_NAMED_POWER_IRP) {
  906. dprintf(PowerIrpNames[minorFunction]) ;
  907. } else if (minorFunction==0xFF) {
  908. dprintf("IRP_MN_BOGUS") ;
  909. } else {
  910. dprintf("(??)") ;
  911. }
  912. break ;
  913. default:
  914. break ;
  915. }
  916. }
  917. BOOLEAN
  918. GetTheSystemTime (
  919. OUT PLARGE_INTEGER Time
  920. )
  921. {
  922. BYTE readTime[20]={0};
  923. PCHAR SysTime;
  924. ZeroMemory( Time, sizeof(*Time) );
  925. SysTime = "SystemTime";
  926. if (GetFieldValue(MM_SHARED_USER_DATA_VA, "nt!_KUSER_SHARED_DATA", SysTime, readTime)) {
  927. dprintf( "unable to read memory @ %lx or _KUSER_SHARED_DATA not found\n",
  928. MM_SHARED_USER_DATA_VA);
  929. return FALSE;
  930. }
  931. *Time = *(LARGE_INTEGER UNALIGNED *)&readTime[0];
  932. return TRUE;
  933. }