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.

302 lines
9.8 KiB

  1. //
  2. // Shared Memory Manager
  3. //
  4. #ifndef _H_SHM
  5. #define _H_SHM
  6. #include <oa.h>
  7. #include <ba.h>
  8. #include <osi.h>
  9. #include <sbc.h>
  10. #include <cm.h>
  11. //
  12. // List of component IDs for the data blocks passed around using shared
  13. // memory.
  14. //
  15. #define SHM_OA_DATA 0
  16. #define SHM_OA_FAST 1
  17. #define SHM_BA_FAST 2
  18. #define SHM_CM_FAST 3
  19. //
  20. // Number of components (actual number of entries in the above list).
  21. //
  22. #define SHM_NUM_COMPONENTS 4
  23. //
  24. // Structure to keep track of the buffer being used to pass data between
  25. // the display driver and the share core.
  26. //
  27. // busyFlag - indicates whether the display driver is using the memory
  28. //
  29. // newBuffer - index for which buffer the display driver should next
  30. // use to access the memory.
  31. //
  32. // currentBuffer - index for the buffer in use by the display driver if
  33. // busyFlag is set.
  34. // THIS FIELD IS USED ONLY BY THE DISPLAY DRIVER
  35. //
  36. // indexCount - count of how many times we have recursed into accessing
  37. // the buffer. The busyFlag and currentBuffer should only
  38. // be updated if indexCount was set to or changed from 0.
  39. // THIS FIELD IS USED ONLY BY THE DISPLAY DRIVER
  40. //
  41. // bufferBusy - indicates whether a particular buffer is being used
  42. // by the display driver.
  43. //
  44. //
  45. typedef struct tagBUFFER_CONTROL
  46. {
  47. long busyFlag;
  48. long newBuffer;
  49. long currentBuffer;
  50. long indexCount;
  51. long bufferBusy[2];
  52. } BUFFER_CONTROL;
  53. typedef BUFFER_CONTROL FAR * LPBUFFER_CONTROL;
  54. //
  55. // Shared memory as used by the display driver and share core to
  56. // communicate.
  57. //
  58. // On Win95, we can not easily address memory that isn't in a 64K segment
  59. // So on both platforms, when we map the shared memory, we also return pointers
  60. // to the CM_FAST_DATA structures anda the OA_FAST_DATA structures, each of
  61. // which lives in its own segment.
  62. //
  63. // On NT, the CM_FAST_DATA blocks come right after this one, then the
  64. // OA_SHARED_DATA blocks.
  65. //
  66. //
  67. // GENERAL
  68. // =======
  69. //
  70. // dataChanged - flags to indicate if a data block has been altered
  71. // (only used by the share core)
  72. //
  73. // FAST PATH DATA
  74. // ==============
  75. //
  76. // fastPath - buffer controls
  77. //
  78. // oaFast - OA fast changing data
  79. //
  80. // baFast - BA fast changing data
  81. //
  82. // DISPLAY DRIVER -> SHARE CORE
  83. // ============================
  84. //
  85. // displayToCore - buffer controls
  86. //
  87. //
  88. typedef struct tagSHM_SHARED_MEMORY
  89. {
  90. //
  91. // Flag set by display driver when the display is in full screen mode.
  92. // (e.g. DOS full screen).
  93. //
  94. DWORD fullScreen;
  95. //
  96. // Flag set by display driver or core when system palette has altered
  97. //
  98. LONG pmPaletteChanged;
  99. //
  100. // Flag set by display driver when the cursor is hidden.
  101. //
  102. LONG cmCursorHidden;
  103. //
  104. // Data passed from the Display Driver up to the Share Core.
  105. //
  106. BUFFER_CONTROL displayToCore;
  107. long dataChanged[SHM_NUM_COMPONENTS];
  108. //
  109. // Data passed regularly from the Display Driver to the Share Core.
  110. //
  111. // This buffer is switched on each periodic processing by the share
  112. // core. If the criteria for reading are satisfied, the main DD->SHCO
  113. // buffer is switched.
  114. //
  115. BUFFER_CONTROL fastPath;
  116. BA_FAST_DATA baFast[2];
  117. OA_FAST_DATA oaFast[2];
  118. CM_FAST_DATA cmFast[2];
  119. //
  120. // DO NOT BUMP SHARED MEMORY SIZE PAST 64K
  121. // 16-bit display driver puts each oaData in a 64K block
  122. // The SHM_ESC_MAP_MEMORY request returns back the pointers
  123. // to each oaData in addition to the shared memory block. In the
  124. // the case of the 32-bit NT display driver, the memory allocated is
  125. // in fact contiguous, so there's no waste in that case.
  126. //
  127. } SHM_SHARED_MEMORY;
  128. typedef SHM_SHARED_MEMORY FAR * LPSHM_SHARED_MEMORY;
  129. //
  130. // Macros to access the shared memory
  131. //
  132. //
  133. // OVERVIEW
  134. // ~~~~~~~~
  135. //
  136. // Note the following sets of macros are split into two parts - one for
  137. // accessing memory from the NT kernel and one for the Share Core. This
  138. // code plays a significant role in the synchronization of the shared
  139. // memory, so make sure you know how it works...
  140. //
  141. // The shared memory is double buffered, so that the kernel mode display
  142. // driver can come in at any point and is NEVER blocked by the share core
  143. // for access. The data is split into two major blocks - one to pass data
  144. // from the kernel to the Share Core and the other to pass the data back.
  145. //
  146. // The macros assume a certain structure to the shared memory which is
  147. // described below.
  148. //
  149. // NO VALIDATION OF POINTERS IS DONE IN THESE MACROS.
  150. //
  151. //
  152. // DISPLAY DRIVER ACCESS
  153. // ~~~~~~~~~~~~~~~~~~~~~
  154. //
  155. // ������������������������������Ŀ
  156. // � Shared Memory �
  157. // � ~~~~~~~~~~~~~ �
  158. // � �
  159. // � �����������ͻ �����������ͻ �
  160. // � � � � � �
  161. // � � kernel � � fast path � �
  162. // � � -> SHCO � � � �
  163. // � � � � � �
  164. // � � � � � �
  165. // � � (details � � � �
  166. // � � below) � � � �
  167. // � � � � � �
  168. // � �����������ͼ �����������ͼ �
  169. // ��������������������������������
  170. //
  171. //
  172. //
  173. // �����������������������������������������������������ͻ
  174. // � Kernel to share core data block �
  175. // � ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ �
  176. // � ���������������Ŀ ���������������Ŀ �
  177. // � � � busyFlag � � �
  178. // � � Share Core � 1 � Display Driver� �
  179. // � � � � � �
  180. // � � (read buffer) � newBuffer � (write buffer)� �
  181. // � � � � � � �
  182. // � � �<�������������>� � �
  183. // � � bufferBusy � � bufferBusy � �
  184. // � � 0 � � 1 � �
  185. // � � � currentBuffer � � �
  186. // � � � � � � �
  187. // � � � �������>� � �
  188. // � � � � � �
  189. // � � � � � �
  190. // � � � indexCount � � �
  191. // � � � 5 � � �
  192. // � ����������������� ����������������� �
  193. // � �
  194. // � �
  195. // �����������������������������������������������������ͼ
  196. //
  197. // The entire major block has a busyFlag, which indicates if the display
  198. // driver is accessing any of its shared memory. This flag is set as soon
  199. // as the display driver needs access to the shared memory (i.e. on entry
  200. // to the display driver graphics functions).
  201. //
  202. // The display driver then reads the index (newBuffer in the above drawing)
  203. // to decide which buffer to use. This is stored in the currentBuffer
  204. // index to use until the display driver releases the shared memory. The
  205. // secondary bufferBusy is now set for the buffer in use.
  206. //
  207. // The indexCount is maintained of the number of times the display driver
  208. // has started access to a block of memory so that (both) busyFlag and
  209. // bufferBusy can be released when the display driver has truly finished
  210. // with the memory.
  211. //
  212. //
  213. // SHARE CORE ACCESS
  214. // ~~~~~~~~~~~~~~~~~
  215. //
  216. // To access the shared memory, the share core just pulls out the data from
  217. // the buffer that the Share Core is not using (ie. the buffer pointed to
  218. // by NOT newBuffer).
  219. //
  220. // The synchronization between the two processes comes from the buffer
  221. // switch.
  222. //
  223. //
  224. // BUFFER SWITCHING (AND SYNCHRONIZATION)
  225. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  226. //
  227. // Buffer switching is determined by the Share Core. Data is accumulated
  228. // by the Share Core and sent on the periodic timing events. For full
  229. // details on the swapping method, refer to NSHMINT.C
  230. //
  231. // Data (such as window tracking) can be passed down at the meoment it is
  232. // generated by using the OSI functions.
  233. //
  234. // The Share Core also determines when it wants to get the latest set of
  235. // orders and screen data area and forces the switch. This is detailed in
  236. // NSHMINT.C
  237. //
  238. //
  239. // THE MACROS!
  240. // ~~~~~~~~~~~
  241. //
  242. // So, now we know a bit about the shared memory, what macros do we have to
  243. // access the shared memory? Here goes...
  244. //
  245. //
  246. // SHM_SYNC_READ - Force a sync of the read buffer between the tasks.
  247. // This should be called only by the Share Core.
  248. //
  249. // SHM_SYNC_FAST - Force a sync of the fast path buffer.
  250. // This should be called only by the Share Core.
  251. //
  252. //
  253. #ifdef DLL_DISP
  254. LPVOID SHM_StartAccess(int block);
  255. void SHM_StopAccess(int block);
  256. //
  257. // Macro to check any pointers that we are going to dereference.
  258. //
  259. #ifdef _DEBUG
  260. void SHM_CheckPointer(LPVOID ptr);
  261. #else
  262. #define SHM_CheckPointer(ptr)
  263. #endif // _DEBUG
  264. #else // !DLL_DISP
  265. void SHM_SwitchReadBuffer(void);
  266. void SHM_SwitchFastBuffer(void);
  267. #endif // DLL_DISP
  268. #endif // _H_SHM