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.

207 lines
6.2 KiB

  1. /****************************************************************************/
  2. // noadisp.c
  3. //
  4. // RDP Order Accumulation code
  5. //
  6. // Copyright (C) 1997-2000 Microsoft Corporation
  7. /****************************************************************************/
  8. #include <precmpdd.h>
  9. #define hdrstop
  10. #define TRC_FILE "noadisp"
  11. #define TRC_GROUP TRC_GROUP_DCSHARE
  12. #include <adcg.h>
  13. #include <adcs.h>
  14. #define DC_INCLUDE_DATA
  15. #include <ndddata.c>
  16. #undef DC_INCLUDE_DATA
  17. #include <noadisp.h>
  18. #include <nprcount.h>
  19. // No data, don't waste time including the file.
  20. //#include <noadata.c>
  21. #include <nschdisp.h>
  22. // Common functions.
  23. #include <aoacom.c>
  24. /****************************************************************************/
  25. // OA_DDInit
  26. /****************************************************************************/
  27. void RDPCALL OA_DDInit()
  28. {
  29. DC_BEGIN_FN("OA_DDInit");
  30. // Don't waste time including the nonexistent data.
  31. //#define DC_INIT_DATA
  32. //#include <noadata.c>
  33. //#undef DC_INIT_DATA
  34. DC_END_FN();
  35. }
  36. /****************************************************************************/
  37. // OA_InitShm
  38. /****************************************************************************/
  39. void RDPCALL OA_InitShm(void)
  40. {
  41. DC_BEGIN_FN("OA_InitShm");
  42. // Init OA shm variables that need it. Be sure not to init the
  43. // order heap itself.
  44. OA_ResetOrderList();
  45. DC_END_FN();
  46. }
  47. /****************************************************************************/
  48. // OA_AllocOrderMem
  49. //
  50. // Allocates order heap memory. Returns a pointer to the heap block.
  51. /****************************************************************************/
  52. PINT_ORDER RDPCALL OA_AllocOrderMem(PDD_PDEV ppdev, unsigned OrderDataLength)
  53. {
  54. unsigned Size;
  55. PINT_ORDER pOrder;
  56. DC_BEGIN_FN("OA_AllocOrderMem");
  57. // Round up the total allocation to the nearest 4 bytes to keep the 4 byte
  58. // alignment within the heap.
  59. Size = sizeof(INT_ORDER) + OrderDataLength;
  60. Size = (Size + sizeof(PVOID) - 1) & ~(sizeof(PVOID)-1);
  61. // If we don't have enough heap space, flush and check again.
  62. // Not being able to flush simply means the network is backed up,
  63. // callers should be able to handle this.
  64. if ((pddShm->oa.nextOrder + Size) >= OA_ORDER_HEAP_SIZE)
  65. SCH_DDOutputAvailable(ppdev, TRUE);
  66. if ((pddShm->oa.nextOrder + Size) < OA_ORDER_HEAP_SIZE) {
  67. TRC_ASSERT((pddShm->oa.nextOrder == (pddShm->oa.nextOrder & ~(sizeof(PVOID)-1))),
  68. (TB,"oa.nextOrder %u is not DWORD_PTR-aligned",
  69. pddShm->oa.nextOrder));
  70. // Init the header.
  71. pOrder = (INT_ORDER *)(pddShm->oa.orderHeap + pddShm->oa.nextOrder);
  72. pOrder->OrderLength = OrderDataLength;
  73. // Add to the end of the order list.
  74. InsertTailList(&pddShm->oa.orderListHead, &pOrder->list);
  75. // Update the end-of-heap pointer to point to the next section of
  76. // free heap.
  77. pddShm->oa.nextOrder += Size;
  78. TRC_DBG((TB, "Alloc order, addr %p, size %u", pOrder,
  79. OrderDataLength));
  80. }
  81. else {
  82. TRC_ALT((TB, "Heap limit hit"));
  83. pOrder = NULL;
  84. }
  85. DC_END_FN();
  86. return pOrder;
  87. }
  88. /****************************************************************************/
  89. // OA_FreeOrderMem
  90. //
  91. // Frees order memory allocated by OA_AllocOrderMem().
  92. /****************************************************************************/
  93. void RDPCALL OA_FreeOrderMem(PINT_ORDER pOrder)
  94. {
  95. PINT_ORDER pOrderTail;
  96. DC_BEGIN_FN("OA_FreeOrderMem");
  97. TRC_DBG((TB, "Free order %p", pOrder));
  98. // Check for freeing the last item in the list.
  99. if ((&pOrder->list) == pddShm->oa.orderListHead.Blink) {
  100. // This is the last item in the heap, so we can set the marker for
  101. // the next order memory to be used back to the start of the order
  102. // being freed.
  103. pddShm->oa.nextOrder = (UINT32)((BYTE *)pOrder - pddShm->oa.orderHeap);
  104. }
  105. // Remove the item from the chain.
  106. RemoveEntryList(&pOrder->list);
  107. DC_END_FN();
  108. }
  109. /****************************************************************************/
  110. // OA_AppendToOrderList
  111. //
  112. // Finalizes the heap addition of an order, without doing extra processing,
  113. // by adding the final order size to the total size of ready-to-send orders
  114. // in the heap.
  115. /****************************************************************************/
  116. void OA_AppendToOrderList(PINT_ORDER _pOrder)
  117. {
  118. unsigned i, j;
  119. PINT_ORDER pPrevOrder;
  120. DC_BEGIN_FN("OA_AppendToOrderList");
  121. pddShm->oa.TotalOrderBytes += (_pOrder)->OrderLength;
  122. #if DC_DEBUG
  123. // Add checksum for order
  124. _pOrder->CheckSum = 0;
  125. for (i = 0; i < _pOrder->OrderLength; i++) {
  126. _pOrder->CheckSum += _pOrder->OrderData[i];
  127. }
  128. #endif
  129. #if DC_DEBUG
  130. // Check past 3 orders
  131. pPrevOrder = (PINT_ORDER)_pOrder;
  132. for (j = 0; j < 3; j++) {
  133. unsigned sum = 0;
  134. if (pPrevOrder->list.Blink != &_pShm->oa.orderListHead) {
  135. pPrevOrder = CONTAINING_RECORD(pPrevOrder->list.Blink,
  136. INT_ORDER, list);
  137. for (i = 0; i < pPrevOrder->OrderLength; i++) {
  138. sum += pPrevOrder->OrderData[i];
  139. }
  140. if (pPrevOrder->CheckSum != sum) {
  141. TRC_ASSERT((FALSE), (TB, "order heap corruption: %p", pPrevOrder));
  142. }
  143. }
  144. else {
  145. break;
  146. }
  147. }
  148. #endif
  149. TRC_ASSERT(((BYTE *)(_pOrder) - pddShm->oa.orderHeap +
  150. ((_pOrder)->OrderLength) <=
  151. pddShm->oa.nextOrder),(TB,"OA_Append: Order is too long "
  152. "for heap allocation size: OrdLen=%u, Start=%u, NextOrd=%u",
  153. (_pOrder)->OrderLength, (BYTE *)(_pOrder) - pddShm->oa.orderHeap,
  154. pddShm->oa.nextOrder));
  155. TRC_DBG((TB,"OA_Append: Appending %u bytes at %p",
  156. (_pOrder)->OrderLength, (_pOrder)));
  157. INC_INCOUNTER(IN_SND_TOTAL_ORDER);
  158. ADD_INCOUNTER(IN_SND_ORDER_BYTES, (_pOrder)->OrderLength);
  159. DC_END_FN();
  160. }