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.

265 lines
5.3 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. lnkext.c
  5. Abstract:
  6. This file contains the generic routines
  7. for debugging NBF's DLC links.
  8. Author:
  9. Chaitanya Kodeboyina
  10. Environment:
  11. User Mode
  12. --*/
  13. #include "precomp.h"
  14. #pragma hdrstop
  15. #include "lnkext.h"
  16. //
  17. // Exported Functions
  18. //
  19. DECLARE_API( lnks )
  20. /*++
  21. Routine Description:
  22. Print a list of DLC links given
  23. the 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. PrintDlcLinkList(NULL, proxyPtr, printDetail);
  40. }
  41. DECLARE_API( lnk )
  42. /*++
  43. Routine Description:
  44. Print the NBF's DLC Link at a
  45. memory location
  46. Arguments:
  47. args -
  48. Pointer to the NBF DLC Link
  49. Detail of debug information
  50. Return Value:
  51. None
  52. --*/
  53. {
  54. TP_LINK DlcLink;
  55. ULONG printDetail;
  56. ULONG proxyPtr;
  57. // Get the detail of debug information needed
  58. printDetail = NORM_SHAL;
  59. if (*args)
  60. {
  61. sscanf(args, "%x %lu", &proxyPtr, &printDetail);
  62. }
  63. // Get the NBF DLC Link
  64. if (ReadDlcLink(&DlcLink, proxyPtr) != 0)
  65. return;
  66. // Print this DLC Link
  67. PrintDlcLink(&DlcLink, proxyPtr, printDetail);
  68. }
  69. //
  70. // Global Helper Functions
  71. //
  72. VOID
  73. PrintDlcLinkList(PVOID ListEntryPointer, ULONG ListEntryProxy, ULONG printDetail)
  74. {
  75. TP_LINK DlcLink;
  76. LIST_ENTRY DlcLinkList;
  77. PLIST_ENTRY DlcLinkListPtr;
  78. PLIST_ENTRY DlcLinkListProxy;
  79. PLIST_ENTRY p, q;
  80. ULONG proxyPtr;
  81. ULONG numDlcLinks;
  82. ULONG bytesRead;
  83. // Get list-head address & debug print level
  84. proxyPtr = ListEntryProxy;
  85. if (ListEntryPointer == NULL)
  86. {
  87. // Read the list entry of NBF DLC links
  88. if (!ReadMemory(proxyPtr, &DlcLinkList, sizeof(LIST_ENTRY), &bytesRead))
  89. {
  90. dprintf("%s @ %08x: Could not read structure\n",
  91. "DLC Link ListEntry", proxyPtr);
  92. return;
  93. }
  94. DlcLinkListPtr = &DlcLinkList;
  95. }
  96. else
  97. {
  98. DlcLinkListPtr = ListEntryPointer;
  99. }
  100. // Traverse the doubly linked list
  101. dprintf("DLC Links:\n");
  102. DlcLinkListProxy = (PLIST_ENTRY)proxyPtr;
  103. numDlcLinks = 0;
  104. p = DlcLinkListPtr->Flink;
  105. while (p != DlcLinkListProxy)
  106. {
  107. // Another DLC Link
  108. numDlcLinks++;
  109. // Get DLC Link Ptr
  110. proxyPtr = (ULONG) CONTAINING_RECORD (p, TP_LINK, Linkage);
  111. // Get NBF DLC Link
  112. if (ReadDlcLink(&DlcLink, proxyPtr) != 0)
  113. break;
  114. // Print the DLC Link
  115. PrintDlcLink(&DlcLink, proxyPtr, printDetail);
  116. // Go to the next one
  117. p = DlcLink.Linkage.Flink;
  118. // Free the DLC Link
  119. FreeDlcLink(&DlcLink);
  120. }
  121. if (p == DlcLinkListProxy)
  122. {
  123. dprintf("Number of DLC Links: %lu\n", numDlcLinks);
  124. }
  125. }
  126. //
  127. // Local Helper Functions
  128. //
  129. UINT
  130. ReadDlcLink(PTP_LINK pDlcLink, ULONG proxyPtr)
  131. {
  132. ULONG bytesRead;
  133. // Read the current NBF DLC link
  134. if (!ReadMemory(proxyPtr, pDlcLink, sizeof(TP_LINK), &bytesRead))
  135. {
  136. dprintf("%s @ %08x: Could not read structure\n",
  137. "DLC Link", proxyPtr);
  138. return -1;
  139. }
  140. return 0;
  141. }
  142. UINT
  143. PrintDlcLink(PTP_LINK pDlcLink, ULONG proxyPtr, ULONG printDetail)
  144. {
  145. // Is this a valid NBF DLC link ?
  146. if (pDlcLink->Type != NBF_LINK_SIGNATURE)
  147. {
  148. dprintf("%s @ %08x: Could not match signature\n",
  149. "DLC Link", proxyPtr);
  150. return -1;
  151. }
  152. // What detail do we print at ?
  153. if (printDetail > MAX_DETAIL)
  154. printDetail = MAX_DETAIL;
  155. // Print Information at reqd detail
  156. FieldInDlcLink(proxyPtr, NULL, printDetail);
  157. return 0;
  158. }
  159. VOID PrintDlcLinkFromPtr(PVOID DlcLinkPtrPointer, ULONG DlcLinkPtrProxy, ULONG printDetail)
  160. {
  161. ULONG pDlcLinkProxy;
  162. ULONG bytesRead;
  163. TP_LINK DlcLink;
  164. if (DlcLinkPtrPointer == NULL)
  165. {
  166. if (!ReadMemory(DlcLinkPtrProxy, &DlcLinkPtrPointer, sizeof(PVOID), &bytesRead))
  167. {
  168. dprintf("%s @ %08x: Could not read structure\n",
  169. "NBF DLC Link Ptr", DlcLinkPtrProxy);
  170. return;
  171. }
  172. }
  173. pDlcLinkProxy = *(ULONG *)DlcLinkPtrPointer;
  174. dprintf("%08x (Ptr)\n", pDlcLinkProxy);
  175. if (pDlcLinkProxy)
  176. {
  177. if (ReadDlcLink(&DlcLink, pDlcLinkProxy) == 0)
  178. {
  179. PrintDlcLink(&DlcLink, pDlcLinkProxy, printDetail);
  180. }
  181. }
  182. }
  183. VOID
  184. FieldInDlcLink(ULONG structAddr, CHAR *fieldName, ULONG printDetail)
  185. {
  186. TP_LINK DlcLink;
  187. if (ReadDlcLink(&DlcLink, structAddr) == 0)
  188. {
  189. PrintFields(&DlcLink, structAddr, fieldName, printDetail, &DlcLinkInfo);
  190. }
  191. }
  192. UINT
  193. FreeDlcLink(PTP_LINK pDlcLink)
  194. {
  195. return 0;
  196. }