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.

173 lines
3.9 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. rxtdi.c
  5. Abstract:
  6. This module implements the NT TDI related routines used by RXCE. The wrappers are necessary to
  7. ensure that all the OS dependencies can be localized to select modules like this for
  8. customization.
  9. Revision History:
  10. Balan Sethu Raman [SethuR] 15-Feb-1995
  11. --*/
  12. #include "precomp.h"
  13. #pragma hdrstop
  14. ULONG
  15. ComputeTransportAddressLength(
  16. PTRANSPORT_ADDRESS pTransportAddress)
  17. /*++
  18. Routine Description:
  19. computes the length in bytes of a TRANSPORT_ADDRESS structure
  20. Arguments:
  21. pTransportAddress - TRANSPORT_ADDRESS instance
  22. Return Value:
  23. the length of the instance in bytes
  24. Notes:
  25. Since this structure is packed the arithmetic has to be done using unaligned pointers.
  26. --*/
  27. {
  28. ULONG Size = 0;
  29. if (pTransportAddress != NULL) {
  30. LONG Index;
  31. TA_ADDRESS *pTaAddress;
  32. Size = FIELD_OFFSET(TRANSPORT_ADDRESS,Address) +
  33. FIELD_OFFSET(TA_ADDRESS,Address) * pTransportAddress->TAAddressCount;
  34. pTaAddress = (TA_ADDRESS *)pTransportAddress->Address;
  35. for (Index = 0;Index <pTransportAddress->TAAddressCount;Index++) {
  36. Size += pTaAddress->AddressLength;
  37. pTaAddress = (TA_ADDRESS *)((PCHAR)pTaAddress +
  38. FIELD_OFFSET(TA_ADDRESS,Address) +
  39. pTaAddress->AddressLength);
  40. }
  41. }
  42. return Size;
  43. }
  44. PIRP
  45. RxCeAllocateIrpWithMDL(
  46. IN CCHAR StackSize,
  47. IN BOOLEAN ChargeQuota,
  48. IN PMDL Buffer)
  49. /*++
  50. Routine Description:
  51. computes the length in bytes of a TRANSPORT_ADDRESS structure
  52. Arguments:
  53. pTransportAddress - TRANSPORT_ADDRESS instance
  54. Return Value:
  55. the length of the instance in bytes
  56. Notes:
  57. Currently the RxCeAllocateIrp and RxCeFreeIrp are implemented as wrappers around the
  58. IO calls. One possible optimization to consider would be to maintain a pool of IRP's
  59. which can be reused.
  60. --*/
  61. {
  62. PIRP pIrp = NULL;
  63. PRX_IRP_LIST_ITEM pListItem = NULL;
  64. pIrp = IoAllocateIrp(StackSize,ChargeQuota);
  65. if (pIrp != NULL) {
  66. pListItem = RxAllocatePoolWithTag(
  67. NonPagedPool,
  68. sizeof(RX_IRP_LIST_ITEM),
  69. RX_IRPC_POOLTAG);
  70. if (pListItem == NULL) {
  71. IoFreeIrp(pIrp);
  72. pIrp = NULL;
  73. } else {
  74. KIRQL SavedIrql;
  75. pListItem->pIrp = pIrp;
  76. pListItem->CopyDataBuffer = Buffer;
  77. pListItem->Completed = 0;
  78. InitializeListHead(&pListItem->IrpsList);
  79. KeAcquireSpinLock(&RxIrpsListSpinLock,&SavedIrql);
  80. InsertTailList(&RxIrpsList,&pListItem->IrpsList);
  81. KeReleaseSpinLock(&RxIrpsListSpinLock,SavedIrql);
  82. }
  83. }
  84. return pIrp;
  85. }
  86. VOID
  87. RxCeFreeIrp(PIRP pIrp)
  88. /*++
  89. Routine Description:
  90. frees an IRP
  91. Arguments:
  92. pIrp - IRP to be freed
  93. --*/
  94. {
  95. KIRQL SavedIrql;
  96. PLIST_ENTRY pListEntry;
  97. BOOLEAN IrpFound = FALSE;
  98. PRX_IRP_LIST_ITEM pListItem = NULL;
  99. KeAcquireSpinLock(&RxIrpsListSpinLock,&SavedIrql);
  100. pListEntry = RxIrpsList.Flink;
  101. while (pListEntry != &RxIrpsList) {
  102. pListItem = CONTAINING_RECORD(
  103. pListEntry,
  104. RX_IRP_LIST_ITEM,
  105. IrpsList);
  106. if (pListItem->pIrp == pIrp) {
  107. IrpFound = TRUE;
  108. //ASSERT(pListItem->Completed);
  109. RemoveEntryList(pListEntry);
  110. RxFreePool(pListItem);
  111. break;
  112. } else {
  113. pListEntry = pListEntry->Flink;
  114. }
  115. }
  116. KeReleaseSpinLock(&RxIrpsListSpinLock,SavedIrql);
  117. ASSERT(IrpFound);
  118. IoFreeIrp(pIrp);
  119. }