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.

194 lines
5.5 KiB

  1. /////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 2001 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // recvcom
  7. //
  8. // Abstract:
  9. // This module contains some common (shared) receive code
  10. //
  11. //////////////////////////////////////////////////////////
  12. #include "sysvars.h"
  13. //////////////////////////////////////////////////////////////
  14. // private constants, types, and prototypes
  15. //////////////////////////////////////////////////////////////
  16. const PCHAR strFunc1 = "TSPacketReceived";
  17. //const PCHAR strFunc2 = "TSFreePacketData";
  18. const PCHAR strFunc3 = "TSMakeMdlForUserBuffer";
  19. //////////////////////////////////////////////////////////////
  20. // public functions
  21. //////////////////////////////////////////////////////////////
  22. // ------------------------------------------
  23. //
  24. // Function: TSPacketReceived
  25. //
  26. // Arguments: pAddressObject -- current address object
  27. // pReceiveData -- receive data structure
  28. // fIsExpedited -- TRUE if an expedited receive
  29. //
  30. // Returns: none
  31. //
  32. // Descript: This function accepts a packet which has been completely
  33. // received, and deals with it as appropriate for the
  34. // packets type
  35. //
  36. // ------------------------------------------------
  37. VOID
  38. TSPacketReceived(PADDRESS_OBJECT pAddressObject,
  39. PRECEIVE_DATA pReceiveData,
  40. BOOLEAN fIsExpedited)
  41. {
  42. TSAcquireSpinLock(&pAddressObject->TdiSpinLock);
  43. //
  44. // expedited receives go on expedited list
  45. // (expedited is only with connected)
  46. //
  47. if (fIsExpedited)
  48. {
  49. if (pAddressObject->pTailRcvExpData)
  50. {
  51. pAddressObject->pTailRcvExpData->pNextReceiveData = pReceiveData;
  52. pReceiveData->pPrevReceiveData = pAddressObject->pTailRcvExpData;
  53. }
  54. else
  55. {
  56. pAddressObject->pHeadRcvExpData = pReceiveData;
  57. }
  58. pAddressObject->pTailRcvExpData = pReceiveData;
  59. }
  60. //
  61. // normal connection receive and all datagram receive
  62. //
  63. else
  64. {
  65. if (pAddressObject->pTailReceiveData)
  66. {
  67. pAddressObject->pTailReceiveData->pNextReceiveData = pReceiveData;
  68. pReceiveData->pPrevReceiveData = pAddressObject->pTailReceiveData;
  69. }
  70. else
  71. {
  72. pAddressObject->pHeadReceiveData = pReceiveData;
  73. }
  74. pAddressObject->pTailReceiveData = pReceiveData;
  75. }
  76. TSReleaseSpinLock(&pAddressObject->TdiSpinLock);
  77. }
  78. // ---------------------------------------------------
  79. //
  80. // Function: TSFreePacketData
  81. //
  82. // Arguments: pAddressObject -- current address object
  83. //
  84. // Returns: none
  85. //
  86. // Descript: This function cleans up any received data still on
  87. // the address object prior to its shutting down
  88. // This is called when closing an address object that was
  89. // used for receiving datagrams OR that was involved in a
  90. // connection
  91. //
  92. // ---------------------------------------------------
  93. VOID
  94. TSFreePacketData(PADDRESS_OBJECT pAddressObject)
  95. {
  96. PRECEIVE_DATA pReceiveData;
  97. TSAcquireSpinLock(&pAddressObject->TdiSpinLock);
  98. pReceiveData = pAddressObject->pHeadReceiveData;
  99. pAddressObject->pHeadReceiveData = NULL;
  100. pAddressObject->pTailReceiveData = NULL;
  101. TSReleaseSpinLock(&pAddressObject->TdiSpinLock);
  102. while (pReceiveData)
  103. {
  104. PRECEIVE_DATA pNextReceiveData
  105. = pReceiveData->pNextReceiveData;
  106. TSFreeMemory(pReceiveData->pucDataBuffer);
  107. TSFreeMemory(pReceiveData);
  108. pReceiveData = pNextReceiveData;
  109. }
  110. }
  111. // -------------------------------------------------
  112. //
  113. // Function: TSMakeMdlForUserBuffer
  114. //
  115. // Arguments: pucDataBuffer -- address of user buffer
  116. // ulDataLength -- length of user buffer
  117. // ProcessorMode -- mode to do probe in?
  118. // IoAccessMode -- type of access required
  119. //
  120. // Returns: pMdl if successful, NULL if exception occurred
  121. //
  122. // Descript: Creates mdl and locks user mode memory
  123. //
  124. // -------------------------------------------------
  125. PMDL
  126. TSMakeMdlForUserBuffer(PUCHAR pucDataBuffer,
  127. ULONG ulDataLength,
  128. LOCK_OPERATION AccessType)
  129. {
  130. PMDL pMdl = IoAllocateMdl(pucDataBuffer,
  131. ulDataLength,
  132. FALSE,
  133. FALSE,
  134. NULL);
  135. if (pMdl)
  136. {
  137. __try
  138. {
  139. MmProbeAndLockPages(pMdl,
  140. KernelMode,
  141. AccessType);
  142. PUCHAR pucBuffer = (PUCHAR)MmGetSystemAddressForMdl(pMdl);
  143. if (pucBuffer == NULL)
  144. {
  145. DebugPrint1("%s: MmProbeAndLockPages failed\n",
  146. strFunc3);
  147. MmUnlockPages(pMdl);
  148. IoFreeMdl(pMdl);
  149. pMdl = NULL;
  150. }
  151. }
  152. __except(EXCEPTION_EXECUTE_HANDLER)
  153. {
  154. NTSTATUS lStatus = GetExceptionCode();
  155. DebugPrint2("%s: Exception %x.\n",
  156. strFunc3,
  157. lStatus);
  158. IoFreeMdl(pMdl);
  159. pMdl = NULL;
  160. }
  161. }
  162. return pMdl;
  163. }
  164. ///////////////////////////////////////////////////////////////////////////////
  165. // end of file recvcom.cpp
  166. ///////////////////////////////////////////////////////////////////////////////