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.

215 lines
5.0 KiB

  1. /*++
  2. Copyright (c) 1999-2000 Microsoft Corporation
  3. Module Name:
  4. tcpipbuf.h
  5. Abstract:
  6. This file implements inline wrappers for the NdisBufferVirtualAddress
  7. and NdisQueryBuffer (which in turn calls MmGetSystemAddressForMdl)
  8. so that we can test the failure paths and add TCP/IP functionality
  9. as required.
  10. Revision History:
  11. --*/
  12. #if DBG
  13. // #define DBG_MAP_BUFFER 1
  14. #if DBG_MAP_BUFFER
  15. // This is to allow us to test failure conditions.
  16. extern ULONG g_cFailSafeMDLQueries;
  17. extern ULONG g_fPerformMDLFailure;
  18. #endif // DBG_MAP_BUFFER
  19. #define TcpipBufferVirtualAddress(pBuffer, Priority) \
  20. DbgTcpipBufferVirtualAddress(pBuffer, Priority, __FILE__, __LINE__)
  21. #define TcpipQueryBuffer(pBuffer, ppvBuffer, pcbBuffer, Priority) \
  22. DbgTcpipQueryBuffer(pBuffer, ppvBuffer, pcbBuffer, Priority, __FILE__, __LINE__)
  23. __inline PVOID
  24. DbgTcpipBufferVirtualAddress(
  25. IN PNDIS_BUFFER pBuffer,
  26. IN UINT Priority,
  27. IN char *pFileName,
  28. IN int cLineNumber
  29. )
  30. {
  31. PVOID pvBuffer;
  32. #if DBG_MAP_BUFFER
  33. if (g_fPerformMDLFailure == TRUE)
  34. {
  35. if (InterlockedDecrement(&g_cFailSafeMDLQueries) == 0)
  36. {
  37. // Stop failing requests.
  38. g_fPerformMDLFailure = FALSE;
  39. }
  40. DbgPrint("TcpipBufferVirtualAddress FORCED failure - MDL %x: %s @ line %d\n",
  41. pBuffer, pFileName, cLineNumber);
  42. return (NULL);
  43. }
  44. #endif // DBG_MAP_BUFFER
  45. #if MILLEN
  46. pvBuffer = NdisBufferVirtualAddress(pBuffer);
  47. #else // MILLEN
  48. pvBuffer = NdisBufferVirtualAddressSafe(pBuffer, Priority);
  49. #endif // !MILLEN
  50. if (pvBuffer == NULL)
  51. {
  52. DbgPrint("TcpipBufferVirtualAddress failure - MDL %x: %s @ line %d\n",
  53. pBuffer, pFileName, cLineNumber);
  54. }
  55. return (pvBuffer);
  56. }
  57. __inline VOID
  58. DbgTcpipQueryBuffer(
  59. IN PNDIS_BUFFER pNdisBuffer,
  60. OUT PVOID * ppvBuffer OPTIONAL,
  61. OUT PUINT pcbBuffer,
  62. IN UINT Priority,
  63. IN char *pFileName,
  64. IN int cLineNumber
  65. )
  66. {
  67. #if DBG_MAP_BUFFER
  68. if (g_fPerformMDLFailure == TRUE)
  69. {
  70. if (InterlockedDecrement(&g_cFailSafeMDLQueries) == 0)
  71. {
  72. // Stop failing requests.
  73. g_fPerformMDLFailure = FALSE;
  74. }
  75. *ppvBuffer = NULL;
  76. *pcbBuffer = MmGetMdlByteCount(pNdisBuffer);
  77. DbgPrint("TcpipQueryBuffer FORCED failure - MDL %x: %s @ line %d\n",
  78. pNdisBuffer, pFileName, cLineNumber);
  79. return;
  80. }
  81. #endif // DBG_MAP_BUFFER
  82. #if MILLEN
  83. NdisQueryBuffer(pNdisBuffer, ppvBuffer, pcbBuffer);
  84. #else // MILLEN
  85. NdisQueryBufferSafe(pNdisBuffer, ppvBuffer, pcbBuffer, Priority);
  86. #endif // !MILLEN
  87. if (*ppvBuffer == NULL)
  88. {
  89. DbgPrint("TcpipQueryBuffer failure - MDL %x: %s @ line %d\n",
  90. pNdisBuffer, pFileName, cLineNumber);
  91. }
  92. return;
  93. }
  94. #if DBG_MAP_BUFFER
  95. #define IOCTL_IP_DBG_TEST_FAIL_MAP_BUFFER \
  96. _IP_CTL_CODE(40, METHOD_BUFFERED, FILE_WRITE_ACCESS)
  97. __inline NTSTATUS
  98. DbgTestFailMapBuffers(
  99. ULONG cFailures
  100. )
  101. {
  102. if (g_fPerformMDLFailure == FALSE) {
  103. DbgPrint("DbgTestFailMapBuffers %d\n", cFailures);
  104. g_cFailSafeMDLQueries = cFailures;
  105. g_fPerformMDLFailure = TRUE;
  106. } else {
  107. return (STATUS_UNSUCCESSFUL);
  108. }
  109. return (STATUS_SUCCESS);
  110. }
  111. #endif // DBG_MAP_BUFFER
  112. #else // DBG
  113. __inline PVOID
  114. TcpipBufferVirtualAddress(
  115. IN PNDIS_BUFFER pBuffer,
  116. IN INT Priority
  117. )
  118. {
  119. #if MILLEN
  120. return (NdisBufferVirtualAddress(pBuffer));
  121. #else // MILLEN
  122. return (NdisBufferVirtualAddressSafe(pBuffer, Priority));
  123. #endif // !MILLEN
  124. }
  125. __inline VOID
  126. TcpipQueryBuffer(
  127. IN PNDIS_BUFFER pNdisBuffer,
  128. OUT PVOID * ppvBuffer OPTIONAL,
  129. OUT PUINT pcbBuffer,
  130. IN UINT Priority
  131. )
  132. {
  133. #if MILLEN
  134. NdisQueryBuffer(pNdisBuffer, ppvBuffer, pcbBuffer);
  135. #else // MILLEN
  136. NdisQueryBufferSafe(pNdisBuffer, ppvBuffer, pcbBuffer, Priority);
  137. #endif // !MILLEN
  138. return;
  139. }
  140. #endif // !DBG
  141. #if MILLEN
  142. typedef struct _XNDIS_BUFFER {
  143. struct _NDIS_BUFFER *Next;
  144. PVOID VirtualAddress;
  145. PVOID Pool;
  146. UINT Length;
  147. UINT Signature;
  148. } XNDIS_BUFFER, *PXNDIS_BUFFER;
  149. __inline VOID
  150. NdisAdjustBuffer(
  151. IN PNDIS_BUFFER Mdl,
  152. IN PVOID NewVirtualAddress,
  153. IN UINT NewLength
  154. )
  155. {
  156. PXNDIS_BUFFER Buffer = (PXNDIS_BUFFER) Mdl;
  157. Buffer->VirtualAddress = NewVirtualAddress;
  158. Buffer->Length = NewLength;
  159. }
  160. #else // MILLEN
  161. __inline VOID
  162. NdisAdjustBuffer(
  163. IN PNDIS_BUFFER Buffer,
  164. IN PVOID NewVirtualAddress,
  165. IN UINT NewLength
  166. )
  167. {
  168. PMDL Mdl = (PMDL) Buffer;
  169. Mdl->MappedSystemVa = NewVirtualAddress;
  170. Mdl->ByteCount = NewLength;
  171. Mdl->ByteOffset = BYTE_OFFSET(NewVirtualAddress);
  172. }
  173. #endif // !MILLEN