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.

239 lines
4.7 KiB

  1. /*++
  2. Copyright (c) 2001, Microsoft Corporation
  3. Module Name:
  4. tls.h
  5. Abstract:
  6. This file defines the TLS.
  7. Author:
  8. Revision History:
  9. Notes:
  10. --*/
  11. #ifndef _TLS_H_
  12. #define _TLS_H_
  13. #include "boolean.h"
  14. #include "cregkey.h"
  15. #include "globals.h"
  16. const TCHAR c_szKeyCUAS[] = TEXT("SOFTWARE\\Microsoft\\CTF\\CUAS");
  17. const TCHAR c_szNonEAComposition[] = TEXT("NonEAComposition");
  18. const DWORD c_dwDisabled = 1;
  19. const DWORD c_dwEnabled = 2;
  20. class CicBridge;
  21. class CicProfile;
  22. class TLS
  23. {
  24. public:
  25. static inline BOOL Initialize()
  26. {
  27. dwTLSIndex = TlsAlloc();
  28. if (dwTLSIndex == TLS_OUT_OF_INDEXES)
  29. return FALSE;
  30. return TRUE;
  31. }
  32. static inline void Uninitialize()
  33. {
  34. if (dwTLSIndex != TLS_OUT_OF_INDEXES)
  35. {
  36. TlsFree(dwTLSIndex);
  37. dwTLSIndex = TLS_OUT_OF_INDEXES;
  38. }
  39. }
  40. static inline TLS* GetTLS()
  41. {
  42. //
  43. // Should allocate TLS data if doesn't exist.
  44. //
  45. return InternalAllocateTLS();
  46. }
  47. static inline TLS* ReferenceTLS()
  48. {
  49. //
  50. // Shouldn't allocate TLS data even TLS data doesn't exist.
  51. //
  52. return (TLS*)TlsGetValue(dwTLSIndex);
  53. }
  54. static inline BOOL DestroyTLS()
  55. {
  56. return InternalDestroyTLS();
  57. }
  58. inline DWORD GetSystemInfoFlags()
  59. {
  60. return dwSystemInfoFlags;
  61. }
  62. inline VOID SetSystemInfoFlags(DWORD dw)
  63. {
  64. dwSystemInfoFlags = dw;
  65. }
  66. inline CicBridge* GetCicBridge()
  67. {
  68. return pCicBridge;
  69. }
  70. inline VOID SetCicBridge(CicBridge* pv)
  71. {
  72. pCicBridge = pv;
  73. }
  74. inline CicProfile* GetCicProfile()
  75. {
  76. return pCicProfile;
  77. }
  78. inline VOID SetCicProfile(CicProfile* pv)
  79. {
  80. pCicProfile = pv;
  81. }
  82. inline ITfThreadMgr_P* GetTIM()
  83. {
  84. return ptim;
  85. }
  86. inline VOID SetTIM(ITfThreadMgr_P* pv)
  87. {
  88. ptim = pv;
  89. }
  90. inline BOOL IsCTFAware()
  91. {
  92. return CTFAware.IsSetFlag();
  93. }
  94. inline BOOL IsCTFUnaware()
  95. {
  96. return CTFAware.IsResetFlag();
  97. }
  98. inline VOID SetCTFAware()
  99. {
  100. CTFAware.SetFlag();
  101. }
  102. inline VOID ResetCTFAware()
  103. {
  104. CTFAware.ResetFlag();
  105. }
  106. inline BOOL IsAIMMAware()
  107. {
  108. return AIMMAware.IsSetFlag();
  109. }
  110. inline VOID SetAIMMAware()
  111. {
  112. AIMMAware.SetFlag();
  113. }
  114. inline VOID ResetAIMMAware()
  115. {
  116. AIMMAware.ResetFlag();
  117. }
  118. inline BOOL IsEnabledKeystrokeFeed()
  119. {
  120. return EnabledKeystrokeFeed.IsSetFlag();
  121. }
  122. inline VOID SetEnabledKeystrokeFeed()
  123. {
  124. EnabledKeystrokeFeed.SetFlag();
  125. }
  126. inline VOID ResetEnabledKeystrokeFeed()
  127. {
  128. EnabledKeystrokeFeed.ResetFlag();
  129. }
  130. inline VOID SetDeactivatedOnce()
  131. {
  132. DeactivatedOnce.SetFlag();
  133. }
  134. inline BOOL IsDeactivatedOnce()
  135. {
  136. return DeactivatedOnce.IsSetFlag();
  137. }
  138. inline BOOL NonEACompositionEnabled()
  139. {
  140. if (!dwNonEAComposition)
  141. {
  142. CMyRegKey regkey;
  143. DWORD dw;
  144. if (S_OK != regkey.Open(HKEY_CURRENT_USER, c_szKeyCUAS, KEY_READ) ||
  145. S_OK != regkey.QueryValue(dw, c_szNonEAComposition))
  146. {
  147. dw = c_dwDisabled;
  148. }
  149. dwNonEAComposition = dw; // dw == 1 disabled, 2 enabled
  150. }
  151. return dwNonEAComposition == c_dwEnabled;
  152. }
  153. private:
  154. DWORD dwSystemInfoFlags;
  155. CicBridge* pCicBridge;
  156. CicProfile* pCicProfile;
  157. ITfThreadMgr_P* ptim;
  158. CBoolean CTFAware;
  159. CBoolean AIMMAware;
  160. CBoolean EnabledKeystrokeFeed;
  161. CBoolean DeactivatedOnce;
  162. DWORD dwNonEAComposition;
  163. private:
  164. static inline TLS* InternalAllocateTLS()
  165. {
  166. TLS* ptls = (TLS*)TlsGetValue(dwTLSIndex);
  167. if (ptls == NULL)
  168. {
  169. if (DllShutDownInProgress())
  170. return NULL;
  171. if ((ptls = (TLS*)cicMemAllocClear(sizeof(TLS))) == NULL)
  172. return NULL;
  173. if (! TlsSetValue(dwTLSIndex, ptls))
  174. {
  175. cicMemFree(ptls);
  176. return NULL;
  177. }
  178. //
  179. // Set Inital value
  180. //
  181. ptls->SetCTFAware(); // Set CTFAware
  182. ptls->SetEnabledKeystrokeFeed();
  183. }
  184. return ptls;
  185. }
  186. static BOOL InternalDestroyTLS();
  187. private:
  188. static DWORD dwTLSIndex;
  189. };
  190. #endif // _TLS_H_