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.

235 lines
4.5 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. adrext.c
  5. Abstract:
  6. This file contains the generic routines
  7. for debugging NBF address structures.
  8. Author:
  9. Chaitanya Kodeboyina
  10. Environment:
  11. User Mode
  12. --*/
  13. #include "precomp.h"
  14. #pragma hdrstop
  15. #include "adrext.h"
  16. //
  17. // Exported Functions
  18. //
  19. DECLARE_API( adrs )
  20. /*++
  21. Routine Description:
  22. Print a list of addresses given the
  23. head LIST_ENTRY.
  24. Arguments:
  25. args - Address of the list entry, &
  26. Detail of debug information
  27. Return Value:
  28. None
  29. --*/
  30. {
  31. ULONG proxyPtr;
  32. ULONG printDetail;
  33. // Get list-head address & debug print level
  34. printDetail = SUMM_INFO;
  35. if (*args)
  36. {
  37. sscanf(args, "%x %lu", &proxyPtr, &printDetail);
  38. }
  39. PrintAddressList(NULL, proxyPtr, printDetail);
  40. }
  41. DECLARE_API( adr )
  42. /*++
  43. Routine Description:
  44. Print the NBF Address at a location
  45. Arguments:
  46. args -
  47. Pointer to the NBF Address
  48. Detail of debug information
  49. Return Value:
  50. None
  51. --*/
  52. {
  53. TP_ADDRESS Address;
  54. ULONG printDetail;
  55. ULONG proxyPtr;
  56. // Get the detail of debug information needed
  57. printDetail = NORM_SHAL;
  58. if (*args)
  59. {
  60. sscanf(args, "%x %lu", &proxyPtr, &printDetail);
  61. }
  62. // Get the NBF Address
  63. if (ReadAddress(&Address, proxyPtr) != 0)
  64. return;
  65. // Print this Address
  66. PrintAddress(&Address, proxyPtr, printDetail);
  67. }
  68. //
  69. // Global Helper Functions
  70. //
  71. VOID
  72. PrintAddressList(PVOID ListEntryPointer, ULONG ListEntryProxy, ULONG printDetail)
  73. {
  74. TP_ADDRESS Address;
  75. LIST_ENTRY AddressList;
  76. PLIST_ENTRY AddressListPtr;
  77. PLIST_ENTRY AddressListProxy;
  78. PLIST_ENTRY p, q;
  79. ULONG proxyPtr;
  80. ULONG numAddrs;
  81. ULONG bytesRead;
  82. // Get list-head address & debug print level
  83. proxyPtr = ListEntryProxy;
  84. if (ListEntryPointer == NULL)
  85. {
  86. // Read the list entry of NBF addresses
  87. if (!ReadMemory(proxyPtr, &AddressList, sizeof(LIST_ENTRY), &bytesRead))
  88. {
  89. dprintf("%s @ %08x: Could not read structure\n",
  90. "Address ListEntry", proxyPtr);
  91. return;
  92. }
  93. AddressListPtr = &AddressList;
  94. }
  95. else
  96. {
  97. AddressListPtr = ListEntryPointer;
  98. }
  99. // Traverse the doubly linked list
  100. dprintf("Addresses:\n");
  101. AddressListProxy = (PLIST_ENTRY)proxyPtr;
  102. numAddrs = 0;
  103. p = AddressListPtr->Flink;
  104. while (p != AddressListProxy)
  105. {
  106. // Another Address
  107. numAddrs++;
  108. // Get Address Ptr
  109. proxyPtr = (ULONG) CONTAINING_RECORD (p, TP_ADDRESS, Linkage);
  110. // Get NBF Address
  111. if (ReadAddress(&Address, proxyPtr) != 0)
  112. break;
  113. // Print the Address
  114. PrintAddress(&Address, proxyPtr, printDetail);
  115. // Go to the next one
  116. p = Address.Linkage.Flink;
  117. // Free the Address
  118. FreeAddress(&Address);
  119. }
  120. if (p == AddressListProxy)
  121. {
  122. dprintf("Number of Addresses: %lu\n", numAddrs);
  123. }
  124. }
  125. //
  126. // Local Helper Functions
  127. //
  128. UINT
  129. ReadAddress(PTP_ADDRESS pAddr, ULONG proxyPtr)
  130. {
  131. ULONG bytesRead;
  132. // Read the current NBF address
  133. if (!ReadMemory(proxyPtr, pAddr, sizeof(TP_ADDRESS), &bytesRead))
  134. {
  135. dprintf("%s @ %08x: Could not read structure\n",
  136. "Address", proxyPtr);
  137. return -1;
  138. }
  139. return 0;
  140. }
  141. UINT
  142. PrintAddress(PTP_ADDRESS pAddr, ULONG proxyPtr, ULONG printDetail)
  143. {
  144. // Is this a valid NBF address ?
  145. if (pAddr->Type != NBF_ADDRESS_SIGNATURE)
  146. {
  147. dprintf("%s @ %08x: Could not match signature\n",
  148. "Address", proxyPtr);
  149. return -1;
  150. }
  151. // What detail do we print at ?
  152. if (printDetail > MAX_DETAIL)
  153. printDetail = MAX_DETAIL;
  154. // Print Information at reqd detail
  155. FieldInAddress(proxyPtr, NULL, printDetail);
  156. return 0;
  157. }
  158. VOID
  159. FieldInAddress(ULONG structAddr, CHAR *fieldName, ULONG printDetail)
  160. {
  161. TP_ADDRESS Address;
  162. if (ReadAddress(&Address, structAddr) == 0)
  163. {
  164. PrintFields(&Address, structAddr, fieldName, printDetail, &AddressInfo);
  165. }
  166. }
  167. UINT
  168. FreeAddress(PTP_ADDRESS pAddr)
  169. {
  170. return 0;
  171. }