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.

212 lines
6.8 KiB

  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. device.c
  5. Abstract:
  6. WinDbg Extension Api
  7. Author:
  8. Wesley Witt (wesw) 15-Aug-1993
  9. Environment:
  10. User Mode.
  11. Revision History:
  12. --*/
  13. #include "precomp.h"
  14. #pragma hdrstop
  15. //-----------------------------------------------------------------------------------------
  16. //
  17. // api declaration macros & api access macros
  18. //
  19. //-----------------------------------------------------------------------------------------
  20. extern WINDBG_EXTENSION_APIS ExtensionApis;
  21. #define KD_OBJECT_HEADER_TO_QUOTA_INFO( roh, loh ) (POBJECT_HEADER_QUOTA_INFO) \
  22. ((loh)->QuotaInfoOffset == 0 ? NULL : ((PCHAR)(roh) - (loh)->QuotaInfoOffset))
  23. #define KD_OBJECT_HEADER_TO_HANDLE_INFO( roh, loh ) (POBJECT_HEADER_HANDLE_INFO) \
  24. ((loh)->HandleInfoOffset == 0 ? NULL : ((PCHAR)(roh) - (loh)->HandleInfoOffset))
  25. #define KD_OBJECT_HEADER_TO_NAME_INFO( roh, loh ) (POBJECT_HEADER_NAME_INFO) \
  26. ((loh)->NameInfoOffset == 0 ? NULL : ((PCHAR)(roh) - (loh)->NameInfoOffset))
  27. #define KD_OBJECT_HEADER_TO_CREATOR_INFO( roh, loh ) (POBJECT_HEADER_CREATOR_INFO) \
  28. (((loh)->Flags & OB_FLAG_CREATOR_INFO) == 0 ? NULL : ((PCHAR)(roh) - sizeof(OBJECT_HEADER_CREATOR_INFO))))
  29. VOID
  30. DumpDevice(
  31. PVOID DeviceAddress,
  32. BOOLEAN FullDetail
  33. );
  34. VOID PrintDeviceObject(PVOID fieldPtr, ULONG fieldProxy, ULONG printDetail)
  35. {
  36. dprintf("Device Object @ %08x\n", fieldProxy);
  37. DumpDevice((PVOID)fieldProxy, TRUE);
  38. }
  39. VOID
  40. DumpDevice(
  41. PVOID DeviceAddress,
  42. BOOLEAN FullDetail
  43. )
  44. /*++
  45. Routine Description:
  46. Displays the driver name for the device object if FullDetail == FALSE.
  47. Otherwise displays more information about the device and the device queue.
  48. Arguments:
  49. DeviceAddress - address of device object to dump.
  50. FullDetail - TRUE means the device object name, driver name, and
  51. information about Irps queued to the device.
  52. Return Value:
  53. None
  54. --*/
  55. {
  56. ULONG result;
  57. ULONG i;
  58. PUCHAR buffer;
  59. DEVICE_OBJECT deviceObject;
  60. UNICODE_STRING unicodeString;
  61. PLIST_ENTRY nextEntry;
  62. PVOID queueAddress;
  63. PIRP irp;
  64. KDEVICE_QUEUE_ENTRY queueEntry;
  65. POBJECT_HEADER pObjectHeader;
  66. OBJECT_HEADER objectHeader;
  67. POBJECT_HEADER_NAME_INFO pNameInfo;
  68. OBJECT_HEADER_NAME_INFO NameInfo;
  69. if ((!ReadMemory( (DWORD)DeviceAddress,
  70. &deviceObject,
  71. sizeof(deviceObject),
  72. &result)) || (result < sizeof(deviceObject))) {
  73. dprintf("%08lx: Could not read device object\n", DeviceAddress);
  74. return;
  75. }
  76. if (deviceObject.Type != IO_TYPE_DEVICE) {
  77. dprintf("%08lx: is not a device object\n", DeviceAddress);
  78. return;
  79. }
  80. if (FullDetail == TRUE) {
  81. //
  82. // Dump the device name if present.
  83. //
  84. pObjectHeader = OBJECT_TO_OBJECT_HEADER(DeviceAddress);
  85. if (ReadMemory( (DWORD)pObjectHeader,
  86. &objectHeader,
  87. sizeof(objectHeader),
  88. &result) && (result == sizeof(objectHeader))) {
  89. pNameInfo = KD_OBJECT_HEADER_TO_NAME_INFO( pObjectHeader, &objectHeader );
  90. if (ReadMemory((DWORD)pNameInfo,
  91. &NameInfo,
  92. sizeof(NameInfo),
  93. &result) && (result == sizeof(NameInfo))) {
  94. buffer = LocalAlloc(LPTR, NameInfo.Name.MaximumLength);
  95. if (buffer != NULL) {
  96. unicodeString.MaximumLength = NameInfo.Name.MaximumLength;
  97. unicodeString.Length = NameInfo.Name.Length;
  98. unicodeString.Buffer = (PWSTR)buffer;
  99. if (ReadMemory((DWORD)NameInfo.Name.Buffer,
  100. buffer,
  101. unicodeString.Length,
  102. &result) && (result == unicodeString.Length)) {
  103. dprintf(" %wZ", &unicodeString);
  104. }
  105. LocalFree(buffer);
  106. }
  107. }
  108. }
  109. }
  110. // DumpDriver((PVOID) deviceObject.DriverObject, FALSE);
  111. if (FullDetail == TRUE) {
  112. //
  113. // Dump Irps related to driver.
  114. //
  115. dprintf(" DriverObject %08lx\n", deviceObject.DriverObject);
  116. dprintf("Current Irp %08lx RefCount %d Type %08lx ",
  117. deviceObject.CurrentIrp,
  118. deviceObject.ReferenceCount,
  119. deviceObject.DeviceType);
  120. if (deviceObject.AttachedDevice) {
  121. dprintf("AttachedDev %08lx ", deviceObject.AttachedDevice);
  122. }
  123. if (deviceObject.Vpb) {
  124. dprintf("Vpb %08lx ", deviceObject.Vpb);
  125. }
  126. dprintf("DevExt %08lx\n", deviceObject.DeviceExtension);
  127. if (deviceObject.DeviceQueue.Busy) {
  128. if (IsListEmpty(&deviceObject.DeviceQueue.DeviceListHead)) {
  129. dprintf("Device queue is busy -- Queue empty\n");
  130. } else {
  131. dprintf("DeviceQueue: ");
  132. nextEntry = deviceObject.DeviceQueue.DeviceListHead.Flink;
  133. i = 0;
  134. while ((PCH) nextEntry != (PCH)
  135. ((PCH) DeviceAddress +
  136. ((PCH) &deviceObject.DeviceQueue.DeviceListHead.Flink -
  137. (PCH) &deviceObject))) {
  138. queueAddress = CONTAINING_RECORD(nextEntry,
  139. KDEVICE_QUEUE_ENTRY,
  140. DeviceListEntry);
  141. if ((!ReadMemory((DWORD)queueAddress,
  142. &queueEntry,
  143. sizeof(queueEntry),
  144. &result)) || (result < sizeof(queueEntry))) {
  145. dprintf("%08lx: Could not read queue entry\n", DeviceAddress);
  146. return;
  147. }
  148. irp = CONTAINING_RECORD(&queueEntry,
  149. IRP,
  150. Tail.Overlay.DeviceQueueEntry);
  151. dprintf("%08lx%s",
  152. irp,
  153. (i & 0x03) == 0x03 ? "\n\t " : " ");
  154. if (CheckControlC()) {
  155. break;
  156. }
  157. }
  158. dprintf("\n");
  159. }
  160. } else {
  161. dprintf("Device queue is not busy.\n");
  162. }
  163. }
  164. }