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.

298 lines
6.0 KiB

  1. #include "precomp.h"
  2. //
  3. // OSI.C
  4. // OS Isolation Layer, Win95 version
  5. //
  6. // Copyright(c) Microsoft 1997-
  7. //
  8. #include <version.h>
  9. #include <ndcgver.h>
  10. #include <osi.h>
  11. extern "C"
  12. {
  13. #include <asthk.h>
  14. }
  15. #define MLZ_FILE_ZONE ZONE_CORE
  16. //
  17. // OSI_Load()
  18. // This handles our process attach code. It establishes thunks to the
  19. // 16-bit Win95 library. WE CAN ONLY DO THIS ONCE. It is imperative
  20. // that a flat-thunk pair come/go together, since the 32-bit piece hangs
  21. // on to a shared memory section that is the thunk table in the 16-bit piece.
  22. //
  23. void OSI_Load(void)
  24. {
  25. DebugEntry(OSI_Load);
  26. ASSERT(!g_hInstAs16);
  27. g_asWin95 = TRUE;
  28. //
  29. // Establish the thunks with AS16
  30. //
  31. if (FT_thkConnectToFlatThkPeer(TEXT("nmaswin.dll"), TEXT("nmas.dll")))
  32. {
  33. OSILoad16(&g_hInstAs16);
  34. ASSERT(g_hInstAs16);
  35. }
  36. else
  37. {
  38. ERROR_OUT(("Couldn't load nmaswin.dll"));
  39. //
  40. // Note, even on load failure, we will continue. We just don't let
  41. // you do app sharing stuff.
  42. //
  43. }
  44. DebugExitVOID(OSI_Load);
  45. }
  46. //
  47. // OSI_Unload()
  48. // This handles our process detach code. It frees the 16-bit library that
  49. // we are pared with.
  50. //
  51. void OSI_Unload(void)
  52. {
  53. DebugEntry(OSI_Unload);
  54. if (g_hInstAs16)
  55. {
  56. //
  57. // See comment for OSI_Term(). On catastropic failure, we may
  58. // call this BEFORE OSI_Term. So null out variables it uses.
  59. //
  60. g_osiInitialized = FALSE;
  61. //
  62. // Free 16-bit library so loads + frees are paired. Note that 16-bit
  63. // cleanup occurs when the library is freed.
  64. //
  65. FreeLibrary16(g_hInstAs16);
  66. g_hInstAs16 = 0;
  67. }
  68. DebugExitVOID(OSI_Unload);
  69. }
  70. //
  71. // OSI_Init
  72. // This initializes our display driver/hook dll communication code.
  73. //
  74. // We load our 16-bit library and establish thunks to it.
  75. //
  76. void OSI_Init(void)
  77. {
  78. DebugEntry(OSI_Init);
  79. if (!g_hInstAs16)
  80. {
  81. WARNING_OUT(("No app sharing at all since library not present"));
  82. DC_QUIT;
  83. }
  84. //
  85. // We are quasi initialized.
  86. //
  87. g_osiInitialized = TRUE;
  88. ASSERT(g_asMainWindow);
  89. ASSERT(g_asHostProp);
  90. //
  91. // Call into 16-bit code to do any initialization necessary
  92. //
  93. g_asCanHost = OSIInit16(DCS_MAKE_VERSION(), g_asMainWindow, g_asHostProp,
  94. (LPDWORD)&g_asSharedMemory, (LPDWORD)g_poaData,
  95. (LPDWORD)&g_lpimSharedData, (LPDWORD)&g_sbcEnabled, (LPDWORD)g_asbcShuntBuffers,
  96. g_asbcBitMasks);
  97. if (g_asCanHost)
  98. {
  99. ASSERT(g_asSharedMemory);
  100. ASSERT(g_poaData[0]);
  101. ASSERT(g_poaData[1]);
  102. ASSERT(g_lpimSharedData);
  103. if (g_sbcEnabled)
  104. {
  105. ASSERT(g_asbcShuntBuffers[0]);
  106. }
  107. }
  108. else
  109. {
  110. ASSERT(!g_asSharedMemory);
  111. ASSERT(!g_poaData[0]);
  112. ASSERT(!g_poaData[1]);
  113. ASSERT(!g_sbcEnabled);
  114. ASSERT(!g_asbcShuntBuffers[0]);
  115. }
  116. DC_EXIT_POINT:
  117. DebugExitVOID(OSI_Init);
  118. }
  119. //
  120. // OSI_Term()
  121. // This cleans up our resources, closes the driver, etc.
  122. //
  123. void OSI_Term(void)
  124. {
  125. UINT i;
  126. DebugEntry(OSI_Term);
  127. ASSERT(GetCurrentThreadId() == g_asMainThreadId);
  128. if (g_osiInitialized)
  129. {
  130. g_osiInitialized = FALSE;
  131. //
  132. // In Ctl+Alt+Del, the process detach of mnmcpi32.dll may happen
  133. // first, followed by the process detach of mnmcrsp_.dll. The latter
  134. // will call DCS_Term, which will call OSI_Term(). We don't want to
  135. // blow up. So OSI_Unload nulls out these variables also.
  136. //
  137. ASSERT(g_hInstAs16);
  138. OSITerm16(FALSE);
  139. }
  140. // Clear our shared memory variables
  141. for (i = 0; i < 3; i++)
  142. {
  143. g_asbcBitMasks[i] = 0;
  144. }
  145. for (i = 0; i < SBC_NUM_TILE_SIZES; i++)
  146. {
  147. g_asbcShuntBuffers[i] = NULL;
  148. }
  149. g_sbcEnabled = FALSE;
  150. g_asSharedMemory = NULL;
  151. g_poaData[0] = NULL;
  152. g_poaData[1] = NULL;
  153. g_asCanHost = FALSE;
  154. g_lpimSharedData = NULL;
  155. DebugExitVOID(OSI_Term);
  156. }
  157. //
  158. // OSI_FunctionRequest()
  159. //
  160. // This is a generic way of communicating with the graphics part of
  161. // hosting. On NT, it's a real display driver, and this uses ExtEscape.
  162. // On Win95, it's a 16-bit dll, and this uses a thunk.
  163. //
  164. BOOL OSI_FunctionRequest
  165. (
  166. DWORD escapeFn,
  167. LPOSI_ESCAPE_HEADER pRequest,
  168. DWORD requestLen
  169. )
  170. {
  171. BOOL rc;
  172. DebugEntry(OSI_FunctionRequest);
  173. ASSERT(g_osiInitialized);
  174. ASSERT(g_hInstAs16);
  175. //
  176. // NOTE: In Win95, since we use a direct thunk to communicate
  177. // with our driver, we don't really need to
  178. // (1) Fill in an identifier (AS16 knows it's us)
  179. // (2) Fill in the escape fn field
  180. // (3) Fill in the version stamp (the thunk fixups will fail
  181. // if pieces are mismatched)
  182. //
  183. // However, we keep the identifer field around. If/when we support
  184. // multiple AS clients at the same time, we will want to know
  185. // who the caller was.
  186. //
  187. pRequest->identifier = OSI_ESCAPE_IDENTIFIER;
  188. pRequest->escapeFn = escapeFn;
  189. pRequest->version = DCS_MAKE_VERSION();
  190. rc = OSIFunctionRequest16(escapeFn, pRequest, requestLen);
  191. DebugExitBOOL(OSI_FunctionRequest, rc);
  192. return(rc);
  193. }
  194. BOOL WINAPI OSI_StartWindowTracking(void)
  195. {
  196. ASSERT(g_hInstAs16);
  197. return(OSIStartWindowTracking16());
  198. }
  199. void WINAPI OSI_StopWindowTracking(void)
  200. {
  201. ASSERT(g_hInstAs16);
  202. OSIStopWindowTracking16();
  203. }
  204. BOOL WINAPI OSI_IsWindowScreenSaver(HWND hwnd)
  205. {
  206. ASSERT(g_hInstAs16);
  207. return(OSIIsWindowScreenSaver16(hwnd));
  208. }
  209. BOOL WINAPI OSI_IsWOWWindow(HWND hwnd)
  210. {
  211. return(FALSE);
  212. }
  213. BOOL WINAPI OSI_ShareWindow(HWND hwnd, UINT uType, BOOL fRepaint, BOOL fUpdateCount)
  214. {
  215. ASSERT(g_hInstAs16);
  216. return(OSIShareWindow16(hwnd, uType, fRepaint, fUpdateCount));
  217. }
  218. BOOL WINAPI OSI_UnshareWindow(HWND hwnd, BOOL fUpdateCount)
  219. {
  220. ASSERT(g_hInstAs16);
  221. return(OSIUnshareWindow16(hwnd, fUpdateCount));
  222. }
  223. void OSI_RepaintDesktop(void)
  224. {
  225. }
  226. void OSI_SetGUIEffects(BOOL fOn)
  227. {
  228. }