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.

391 lines
8.8 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. conext.c
  5. Abstract:
  6. This file contains the generic routines
  7. for debugging NBF connections.
  8. Author:
  9. Chaitanya Kodeboyina
  10. Environment:
  11. User Mode
  12. --*/
  13. #include "precomp.h"
  14. #pragma hdrstop
  15. #include "conext.h"
  16. //
  17. // Exported Functions
  18. //
  19. DECLARE_API( cons )
  20. /*++
  21. Routine Description:
  22. Print a list of conections 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. ULONG linkage;
  34. // Get list-head address & debug print level
  35. printDetail = SUMM_INFO;
  36. if (*args)
  37. {
  38. sscanf(args, "%x %lu %lu", &proxyPtr, &linkage, &printDetail);
  39. }
  40. switch(linkage)
  41. {
  42. case LINKAGE:
  43. PrintConnectionListOnLink(NULL, proxyPtr, printDetail);
  44. break;
  45. case ADDRESS:
  46. PrintConnectionListOnAddress(NULL, proxyPtr, printDetail);
  47. break;
  48. case ADDFILE:
  49. PrintConnectionListOnAddrFile(NULL, proxyPtr, printDetail);
  50. break;
  51. default:
  52. break;
  53. }
  54. }
  55. DECLARE_API( con )
  56. /*++
  57. Routine Description:
  58. Print the NBF Connection at a
  59. memory location
  60. Arguments:
  61. args -
  62. Pointer to the NBF Connection
  63. Detail of debug information
  64. Return Value:
  65. None
  66. --*/
  67. {
  68. TP_CONNECTION Connection;
  69. ULONG printDetail;
  70. ULONG proxyPtr;
  71. // Get the detail of debug information needed
  72. printDetail = NORM_SHAL;
  73. if (*args)
  74. {
  75. sscanf(args, "%x %lu", &proxyPtr, &printDetail);
  76. }
  77. // Get the NBF Connection
  78. if (ReadConnection(&Connection, proxyPtr) != 0)
  79. return;
  80. // Print this Connection
  81. PrintConnection(&Connection, proxyPtr, printDetail);
  82. }
  83. //
  84. // Global Helper Functions
  85. //
  86. VOID
  87. PrintConnectionListOnLink(PVOID ListEntryPointer, ULONG ListEntryProxy, ULONG printDetail)
  88. {
  89. TP_CONNECTION Connection;
  90. LIST_ENTRY ConnectionList;
  91. PLIST_ENTRY ConnectionListPtr;
  92. PLIST_ENTRY ConnectionListProxy;
  93. PLIST_ENTRY p, q;
  94. ULONG proxyPtr;
  95. ULONG numConnects;
  96. ULONG bytesRead;
  97. // Get list-head address & debug print level
  98. proxyPtr = ListEntryProxy;
  99. if (ListEntryPointer == NULL)
  100. {
  101. // Read the list entry of NBF connections
  102. if (!ReadMemory(proxyPtr, &ConnectionList, sizeof(LIST_ENTRY), &bytesRead))
  103. {
  104. dprintf("%s @ %08x: Could not read structure\n",
  105. "Connection ListEntry", proxyPtr);
  106. return;
  107. }
  108. ConnectionListPtr = &ConnectionList;
  109. }
  110. else
  111. {
  112. ConnectionListPtr = ListEntryPointer;
  113. }
  114. // Traverse the doubly linked list
  115. dprintf("Connections On Link:\n");
  116. ConnectionListProxy = (PLIST_ENTRY)proxyPtr;
  117. numConnects = 0;
  118. p = ConnectionListPtr->Flink;
  119. while (p != ConnectionListProxy)
  120. {
  121. // Another Connection
  122. numConnects++;
  123. // Get Connection Ptr
  124. proxyPtr = (ULONG) CONTAINING_RECORD (p, TP_CONNECTION, LinkList);
  125. // Get NBF Connection
  126. if (ReadConnection(&Connection, proxyPtr) != 0)
  127. break;
  128. // Print the Connection
  129. PrintConnection(&Connection, proxyPtr, printDetail);
  130. // Go to the next one
  131. p = Connection.LinkList.Flink;
  132. // Free the Connection
  133. FreeConnection(&Connection);
  134. }
  135. if (p == ConnectionListProxy)
  136. {
  137. dprintf("Number of Connections On Link: %lu\n", numConnects);
  138. }
  139. }
  140. VOID
  141. PrintConnectionListOnAddress(PVOID ListEntryPointer, ULONG ListEntryProxy, ULONG printDetail)
  142. {
  143. TP_CONNECTION Connection;
  144. LIST_ENTRY ConnectionList;
  145. PLIST_ENTRY ConnectionListPtr;
  146. PLIST_ENTRY ConnectionListProxy;
  147. PLIST_ENTRY p, q;
  148. ULONG proxyPtr;
  149. ULONG numConnects;
  150. ULONG bytesRead;
  151. // Get list-head address & debug print level
  152. proxyPtr = ListEntryProxy;
  153. if (ListEntryPointer == NULL)
  154. {
  155. // Read the list entry of NBF connections
  156. if (!ReadMemory(proxyPtr, &ConnectionList, sizeof(LIST_ENTRY), &bytesRead))
  157. {
  158. dprintf("%s @ %08x: Could not read structure\n",
  159. "Connection ListEntry", proxyPtr);
  160. return;
  161. }
  162. ConnectionListPtr = &ConnectionList;
  163. }
  164. else
  165. {
  166. ConnectionListPtr = ListEntryPointer;
  167. }
  168. // Traverse the doubly linked list
  169. dprintf("Connections On Address:\n");
  170. ConnectionListProxy = (PLIST_ENTRY)proxyPtr;
  171. numConnects = 0;
  172. p = ConnectionListPtr->Flink;
  173. while (p != ConnectionListProxy)
  174. {
  175. // Another Connection
  176. numConnects++;
  177. // Get Connection Ptr
  178. proxyPtr = (ULONG) CONTAINING_RECORD (p, TP_CONNECTION, AddressList);
  179. // Get NBF Connection
  180. if (ReadConnection(&Connection, proxyPtr) != 0)
  181. break;
  182. // Print the Connection
  183. PrintConnection(&Connection, proxyPtr, printDetail);
  184. // Go to the next one
  185. p = Connection.AddressList.Flink;
  186. // Free the Connection
  187. FreeConnection(&Connection);
  188. }
  189. if (p == ConnectionListProxy)
  190. {
  191. dprintf("Number of Connections On Address: %lu\n", numConnects);
  192. }
  193. }
  194. VOID
  195. PrintConnectionListOnAddrFile(PVOID ListEntryPointer, ULONG ListEntryProxy, ULONG printDetail)
  196. {
  197. TP_CONNECTION Connection;
  198. LIST_ENTRY ConnectionList;
  199. PLIST_ENTRY ConnectionListPtr;
  200. PLIST_ENTRY ConnectionListProxy;
  201. PLIST_ENTRY p, q;
  202. ULONG proxyPtr;
  203. ULONG numConnects;
  204. ULONG bytesRead;
  205. // Get list-head address & debug print level
  206. proxyPtr = ListEntryProxy;
  207. if (ListEntryPointer == NULL)
  208. {
  209. // Read the list entry of NBF connections
  210. if (!ReadMemory(proxyPtr, &ConnectionList, sizeof(LIST_ENTRY), &bytesRead))
  211. {
  212. dprintf("%s @ %08x: Could not read structure\n",
  213. "Connection ListEntry", proxyPtr);
  214. return;
  215. }
  216. ConnectionListPtr = &ConnectionList;
  217. }
  218. else
  219. {
  220. ConnectionListPtr = ListEntryPointer;
  221. }
  222. // Traverse the doubly linked list
  223. dprintf("Connections On AddrFile:\n");
  224. ConnectionListProxy = (PLIST_ENTRY)proxyPtr;
  225. numConnects = 0;
  226. p = ConnectionListPtr->Flink;
  227. while (p != ConnectionListProxy)
  228. {
  229. // Another Connection
  230. numConnects++;
  231. // Get Connection Ptr
  232. proxyPtr = (ULONG) CONTAINING_RECORD (p, TP_CONNECTION, AddressFileList);
  233. // Get NBF Connection
  234. if (ReadConnection(&Connection, proxyPtr) != 0)
  235. break;
  236. // Print the Connection
  237. PrintConnection(&Connection, proxyPtr, printDetail);
  238. // Go to the next one
  239. p = Connection.AddressFileList.Flink;
  240. // Free the Connection
  241. FreeConnection(&Connection);
  242. }
  243. if (p == ConnectionListProxy)
  244. {
  245. dprintf("Number of Connections On AddrFile: %lu\n", numConnects);
  246. }
  247. }
  248. //
  249. // Local Helper Functions
  250. //
  251. UINT
  252. ReadConnection(PTP_CONNECTION pConnection, ULONG proxyPtr)
  253. {
  254. ULONG bytesRead;
  255. // Read the current NBF connection
  256. if (!ReadMemory(proxyPtr, pConnection, sizeof(TP_CONNECTION), &bytesRead))
  257. {
  258. dprintf("%s @ %08x: Could not read structure\n",
  259. "Connection", proxyPtr);
  260. return -1;
  261. }
  262. return 0;
  263. }
  264. UINT
  265. PrintConnection(PTP_CONNECTION pConnection, ULONG proxyPtr, ULONG printDetail)
  266. {
  267. // Is this a valid NBF connection ?
  268. if (pConnection->Type != NBF_CONNECTION_SIGNATURE)
  269. {
  270. dprintf("%s @ %08x: Could not match signature\n",
  271. "Connection", proxyPtr);
  272. return -1;
  273. }
  274. // What detail do we have to print at ?
  275. if (printDetail > MAX_DETAIL)
  276. printDetail = MAX_DETAIL;
  277. // Print Information at reqd detail
  278. FieldInConnection(proxyPtr, NULL, printDetail);
  279. return 0;
  280. }
  281. VOID
  282. FieldInConnection(ULONG structAddr, CHAR *fieldName, ULONG printDetail)
  283. {
  284. TP_CONNECTION Connection;
  285. if (ReadConnection(&Connection, structAddr) == 0)
  286. {
  287. PrintFields(&Connection, structAddr, fieldName, printDetail, &ConnectionInfo);
  288. }
  289. }
  290. UINT
  291. FreeConnection(PTP_CONNECTION pConnection)
  292. {
  293. return 0;
  294. }