Source code of Windows XP (NT5)
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.

180 lines
3.5 KiB

  1. #include "precomp.h"
  2. //
  3. // SHM.C
  4. // Shared Memory Access, cpi32 and display driver sides both
  5. //
  6. // Copyright(c) Microsoft 1997-
  7. //
  8. //
  9. // SHM_StartAccess
  10. //
  11. LPVOID SHM_StartAccess(int block)
  12. {
  13. LPBUFFER_CONTROL pControl;
  14. LPVOID pMemBlock;
  15. DebugEntry(SHM_StartAccess);
  16. //
  17. // Test for shared memory present
  18. //
  19. ASSERT(g_asSharedMemory != NULL);
  20. //
  21. // Determine which data block we are handling...
  22. //
  23. switch (block)
  24. {
  25. case SHM_OA_DATA:
  26. pControl = &g_asSharedMemory->displayToCore;
  27. break;
  28. case SHM_OA_FAST:
  29. case SHM_BA_FAST:
  30. case SHM_CM_FAST:
  31. pControl = &g_asSharedMemory->fastPath;
  32. break;
  33. default:
  34. ERROR_OUT(("Unknown type %d", block));
  35. break;
  36. }
  37. //
  38. // Mark the double-buffer as busy.
  39. //
  40. pControl->busyFlag = 1;
  41. //
  42. // Set up the current buffer pointer if this is the first access to the
  43. // shared memory.
  44. //
  45. pControl->indexCount++;
  46. if (pControl->indexCount == 1)
  47. {
  48. //
  49. // Set up the 'in use' buffer pointer
  50. //
  51. pControl->currentBuffer = pControl->newBuffer;
  52. //
  53. // Mark the buffer as busy so that the Share Core knows where we
  54. // are.
  55. //
  56. pControl->bufferBusy[pControl->currentBuffer] = 1;
  57. }
  58. //
  59. // Get the pointer to the block to return
  60. //
  61. switch (block)
  62. {
  63. case SHM_OA_DATA:
  64. pMemBlock = g_poaData[pControl->currentBuffer];
  65. break;
  66. case SHM_OA_FAST:
  67. pMemBlock = &(g_asSharedMemory->oaFast[pControl->currentBuffer]);
  68. break;
  69. case SHM_BA_FAST:
  70. pMemBlock = &(g_asSharedMemory->baFast[pControl->currentBuffer]);
  71. break;
  72. case SHM_CM_FAST:
  73. pMemBlock = &(g_asSharedMemory->cmFast[pControl->currentBuffer]);
  74. break;
  75. default:
  76. ERROR_OUT(("Unknown type %d", block));
  77. break;
  78. }
  79. DebugExitPVOID(SHM_StartAccess, pMemBlock);
  80. return(pMemBlock);
  81. }
  82. //
  83. // SHM_StopAccess
  84. //
  85. void SHM_StopAccess(int block)
  86. {
  87. LPBUFFER_CONTROL pControl;
  88. DebugEntry(SHM_StopAccess);
  89. ASSERT(g_asSharedMemory != NULL);
  90. //
  91. // Determine which data block we are handling...
  92. //
  93. switch (block)
  94. {
  95. case SHM_OA_DATA:
  96. pControl = &g_asSharedMemory->displayToCore;
  97. break;
  98. case SHM_OA_FAST:
  99. case SHM_BA_FAST:
  100. case SHM_CM_FAST:
  101. pControl = &g_asSharedMemory->fastPath;
  102. break;
  103. default:
  104. ERROR_OUT(("Unknown type %d", block));
  105. break;
  106. }
  107. //
  108. // Decrement usage count - if we have finally finished with the memory,
  109. // clear the busy flags so that the Share Core knows it won't tread on
  110. // the display driver's toes.
  111. //
  112. pControl->indexCount--;
  113. if (pControl->indexCount == 0)
  114. {
  115. pControl->bufferBusy[pControl->currentBuffer] = 0;
  116. pControl->busyFlag = 0;
  117. }
  118. DebugExitVOID(SHM_StopAccess);
  119. }
  120. #ifdef _DEBUG
  121. //
  122. // SHM_CheckPointer - see shm.h
  123. //
  124. void SHM_CheckPointer(LPVOID ptr)
  125. {
  126. DebugEntry(SHMCheckPointer);
  127. if (ptr == NULL)
  128. {
  129. ERROR_OUT(("Null pointer"));
  130. DC_QUIT;
  131. }
  132. ASSERT(g_asSharedMemory);
  133. if (((LPBYTE)ptr - (LPBYTE)g_asSharedMemory < 0) ||
  134. ((LPBYTE)ptr - (LPBYTE)g_asSharedMemory >= SHM_SIZE_USED))
  135. {
  136. ERROR_OUT(("Bad pointer"));
  137. }
  138. DC_EXIT_POINT:
  139. DebugExitVOID(SHM_CheckPointer);
  140. }
  141. #endif // _DEBUG
  142.