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.

296 lines
7.4 KiB

  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. buffer.c
  5. Abstract:
  6. Implements the buffer command.
  7. Author:
  8. Keith Moore (keithmo) 15-Apr-1996
  9. Environment:
  10. User Mode.
  11. Revision History:
  12. --*/
  13. #include "afdkdp.h"
  14. #pragma hdrstop
  15. BOOL
  16. DumpBuffersCallback(
  17. ULONG64 ActualAddress,
  18. ULONG64 Context
  19. );
  20. //
  21. // Public functions.
  22. //
  23. DECLARE_API( buff )
  24. /*++
  25. Routine Description:
  26. Dumps the AFD_BUFFER structure at the specified address.
  27. Arguments:
  28. None.
  29. Return Value:
  30. None.
  31. --*/
  32. {
  33. ULONG64 address = 0;
  34. ULONG result;
  35. CHAR expr[MAX_ADDRESS_EXPRESSION];
  36. PCHAR argp;
  37. INT i;
  38. gClient = pClient;
  39. argp = ProcessOptions ((PCHAR)args);
  40. if (argp==NULL)
  41. return E_INVALIDARG;
  42. if (Options&AFDKD_BRIEF_DISPLAY) {
  43. dprintf (AFDKD_BRIEF_BUFFER_DISPLAY_HEADER);
  44. }
  45. if ((argp[0]==0) || (Options & AFDKD_ENDPOINT_SCAN)) {
  46. EnumEndpoints(
  47. DumpBuffersCallback,
  48. 0
  49. );
  50. dprintf ("\nTotal buffers: %ld", EntityCount);
  51. }
  52. else {
  53. //
  54. // Snag the address from the command line.
  55. //
  56. while (sscanf( argp, "%s%n", expr, &i )==1) {
  57. if( CheckControlC() ) {
  58. break;
  59. }
  60. argp+=i;
  61. address = GetExpression (expr);
  62. result = (ULONG)InitTypeRead (address, AFD!AFD_BUFFER_HEADER);
  63. if (result!=0) {
  64. dprintf ("\nDumpAfdBuffer: Could not read AFD_BUFFER_HEADER @p, err: %ld\n",
  65. address, result);
  66. break ;
  67. }
  68. if (Options & AFDKD_BRIEF_DISPLAY) {
  69. DumpAfdBufferBrief (
  70. address
  71. );
  72. }
  73. else {
  74. DumpAfdBuffer (
  75. address
  76. );
  77. }
  78. if (Options & AFDKD_FIELD_DISPLAY) {
  79. ProcessFieldOutput (address, "AFD!AFD_BUFFER");
  80. }
  81. }
  82. }
  83. if (Options&AFDKD_BRIEF_DISPLAY) {
  84. dprintf (AFDKD_BRIEF_BUFFER_DISPLAY_TRAILER);
  85. }
  86. else {
  87. dprintf ("\n");
  88. }
  89. return S_OK;
  90. } // buffer
  91. VOID
  92. DumpBufferList (
  93. ULONG64 ListAddress,
  94. LPSTR Header
  95. )
  96. {
  97. LIST_ENTRY64 listEntry;
  98. ULONG64 address;
  99. ULONG64 nextEntry;
  100. ULONG result;
  101. if( !ReadListEntry(
  102. ListAddress,
  103. &listEntry) ) {
  104. dprintf(
  105. "\nDumpBufferList: Could not read buffer list head @ %p\n",
  106. ListAddress
  107. );
  108. return ;
  109. }
  110. if (listEntry.Flink==ListAddress) {
  111. dprintf(".");
  112. return ;
  113. }
  114. if (Header) {
  115. dprintf (Header);
  116. }
  117. nextEntry = listEntry.Flink;
  118. while( nextEntry != ListAddress ) {
  119. if (nextEntry==0) {
  120. dprintf(
  121. "\nDumpBuffersCallback: next entry is NULL for list @ %p\n",
  122. ListAddress
  123. );
  124. break;
  125. }
  126. if (CheckControlC ())
  127. break;
  128. address = nextEntry - BufferLinkOffset;
  129. result = (ULONG)InitTypeRead (address, AFD!AFD_BUFFER_HEADER);
  130. if (result!=0) {
  131. dprintf ("\nDumpBuffersCallback: Could not read AFD_BUFFER_HEADER @p, err: %ld\n",
  132. address, result);
  133. break ;
  134. }
  135. nextEntry = ReadField (BufferListEntry.Flink);
  136. if (!(Options & AFDKD_CONDITIONAL) ||
  137. CheckConditional (address, "AFD!AFD_BUFFER") ) {
  138. if (Options & AFDKD_NO_DISPLAY)
  139. dprintf ("+");
  140. else {
  141. if (Options & AFDKD_BRIEF_DISPLAY) {
  142. DumpAfdBufferBrief (
  143. address
  144. );
  145. }
  146. else {
  147. DumpAfdBuffer (
  148. address
  149. );
  150. }
  151. if (Options & AFDKD_FIELD_DISPLAY) {
  152. ProcessFieldOutput (address, "AFD!AFD_BUFFER");
  153. }
  154. }
  155. EntityCount += 1;
  156. }
  157. else {
  158. dprintf (",");
  159. }
  160. }
  161. }
  162. ULONG
  163. DumpBufferListCB (
  164. PFIELD_INFO pField,
  165. PVOID UserContext
  166. )
  167. {
  168. ULONG result;
  169. CHAR header[64];
  170. AFD_CONNECTION_STATE_FLAGS flags;
  171. result = GetFieldValue (pField->address, "AFD!AFD_CONNECTION", "ConnectionStateFlags", flags);
  172. if ((result==0) &&
  173. !flags.TdiBufferring ) {
  174. _snprintf (header, sizeof (header)-1, "\nConnection: %I64X", pField->address);
  175. header[sizeof(header)-1] = 0;
  176. DumpBufferList (pField->address+ConnectionBufferListOffset, header);
  177. }
  178. return result;
  179. }
  180. BOOL
  181. DumpBuffersCallback(
  182. ULONG64 ActualAddress,
  183. ULONG64 Context
  184. )
  185. /*++
  186. Routine Description:
  187. Dumps buffers for the endpoint/connection.
  188. Arguments:
  189. ActualAddress - The actual address of the list
  190. Return Value:
  191. ULONG - Sum of pool charged for the buffers in the list.
  192. --*/
  193. {
  194. AFD_ENDPOINT endpoint;
  195. ULONG64 connAddr;
  196. AFD_CONNECTION_STATE_FLAGS flags;
  197. CHAR header[64];
  198. endpoint.Type = (USHORT)ReadField (Type);
  199. endpoint.State = (UCHAR)ReadField (State);
  200. if (endpoint.Type==AfdBlockTypeDatagram) {
  201. _snprintf (header, sizeof (header)-1, "\nEndpoint %I64X", ActualAddress);
  202. header[sizeof(header)-1] = 0;
  203. DumpBufferList (ActualAddress+DatagramBufferListOffset, header);
  204. }
  205. else if (((endpoint.Type & AfdBlockTypeVcConnecting)==AfdBlockTypeVcConnecting) &&
  206. ( (connAddr=ReadField (Common.VirtualCircuit.Connection))!=0 ||
  207. ((endpoint.State==AfdEndpointStateClosing || endpoint.State==AfdEndpointStateTransmitClosing) &&
  208. (connAddr=ReadField(WorkItem.Context))!=0) ) &&
  209. (GetFieldValue (connAddr, "AFD!AFD_CONNECTION", "ConnectionStateFlags", flags)==0) &&
  210. !flags.TdiBufferring ) {
  211. _snprintf (header, sizeof (header)-1, "\nEndpoint: %I64X, connection: %I64X", ActualAddress, connAddr);
  212. header[sizeof(header)-1] = 0;
  213. DumpBufferList (connAddr+ConnectionBufferListOffset, header);
  214. }
  215. else if ((endpoint.Type & AfdBlockTypeVcListening)==AfdBlockTypeVcListening) {
  216. ListType (
  217. "AFD!AFD_CONNECTION", // Type
  218. ActualAddress+UnacceptedConnListOffset, // Address
  219. 1, // ListByFieldAddress
  220. "ListLink.Flink", // NextPointer
  221. NULL, // Context
  222. DumpBufferListCB // Callback
  223. );
  224. ListType (
  225. "AFD!AFD_CONNECTION", // Type
  226. ActualAddress+ReturnedConnListOffset, // Address
  227. 1, // ListByFieldAddress
  228. "ListLink.Flink", // NextPointer
  229. NULL, // Context
  230. DumpBufferListCB // Callback
  231. );
  232. }
  233. return TRUE;
  234. }