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.

293 lines
8.6 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. actctxctb.cpp
  5. Abstract:
  6. Code to manage the list of activation context contributors in sxs.dll.
  7. Author:
  8. Michael J. Grier (MGrier) 23-Feb-2000
  9. Revision History:
  10. --*/
  11. #include "stdinc.h"
  12. CCriticalSectionNoConstructor g_ActCtxCtbListCritSec;
  13. PACTCTXCTB g_ActCtxCtbListHead;
  14. ULONG g_ActCtxCtbListCount;
  15. #if SXSP_EXTENSIBLE_CONTRIBUTORS
  16. BOOL
  17. SxspAddActCtxContributor(
  18. PCWSTR DllName,
  19. PCSTR Prefix,
  20. SIZE_T PrefixCch,
  21. const GUID *ExtensionGuid,
  22. ULONG SectionId,
  23. ULONG Format,
  24. PCWSTR ContributorName
  25. )
  26. {
  27. CSxsPointer<ACTCTXCTB> Contrib;
  28. BOOL fSuccess = FALSE;
  29. FN_TRACE_WIN32(fSuccess);
  30. PARAMETER_CHECK(
  31. (Format == ACTIVATION_CONTEXT_SECTION_FORMAT_STRING_TABLE) || (Format == ACTIVATION_CONTEXT_SECTION_FORMAT_GUID_TABLE));
  32. PARAMETER_CHECK(PrefixCch <= ACTCTXCTB_MAX_PREFIX_LENGTH);
  33. PARAMETER_CHECK(ContributorName != NULL);
  34. PARAMETER_CHECK(DllName != NULL);
  35. IFALLOCFAILED_EXIT(Contrib = new ACTCTXCTB);
  36. Contrib->m_Format = Format;
  37. if (ExtensionGuid != NULL)
  38. {
  39. Contrib->m_ExtensionGuid = *ExtensionGuid;
  40. Contrib->m_IsExtendedSection = ((Contrib->m_ExtensionGuid != GUID_NULL) != FALSE);
  41. }
  42. else
  43. {
  44. Contrib->m_ExtensionGuid = GUID_NULL;
  45. Contrib->m_IsExtendedSection = false;
  46. }
  47. IFW32FALSE_EXIT(Contrib->m_ContributorNameBuffer.Win32Assign(ContributorName, ::wcslen(ContributorName)));
  48. IFW32FALSE_EXIT(Contrib->m_DllNameBuffer.Win32Assign(DllName, ::wcslen(DllName)));
  49. if (PrefixCch != 0)
  50. IFW32FALSE_EXIT(Contrib->m_PrefixBuffer.Win32Assign(Prefix, PrefixCch));
  51. Contrib->m_PrefixCch = PrefixCch;
  52. Contrib->m_SectionId = SectionId;
  53. Contrib->m_RefCount = 1;
  54. {
  55. CSxsLockCriticalSection lock(g_ActCtxCtbListCritSec);
  56. IFW32FALSE_EXIT(lock.Lock());
  57. Contrib->m_Next = g_ActCtxCtbListHead;
  58. g_ActCtxCtbListHead = Contrib.Detach();
  59. g_ActCtxCtbListCount++;
  60. }
  61. fSuccess = TRUE;
  62. Exit:
  63. return fSuccess;
  64. }
  65. #endif
  66. BOOL
  67. SxspAddBuiltinActCtxContributor(
  68. ACTCTXCTB_CALLBACK_FUNCTION CallbackFunction,
  69. const GUID *ExtensionGuid,
  70. ULONG SectionId,
  71. ULONG Format,
  72. PCWSTR ContributorName
  73. )
  74. {
  75. SMARTPTR(ACTCTXCTB) Contrib;
  76. BOOL fSuccess = FALSE;
  77. FN_TRACE_WIN32(fSuccess);
  78. PARAMETER_CHECK(
  79. (Format == ACTIVATION_CONTEXT_SECTION_FORMAT_STRING_TABLE) ||
  80. (Format == ACTIVATION_CONTEXT_SECTION_FORMAT_GUID_TABLE) ||
  81. (Format == 0));
  82. PARAMETER_CHECK(CallbackFunction != NULL);
  83. PARAMETER_CHECK(ContributorName != NULL);
  84. IFW32FALSE_EXIT(Contrib.Win32Allocate(__FILE__, __LINE__));
  85. Contrib->m_BuiltinContributor = true;
  86. Contrib->m_CallbackFunction = CallbackFunction;
  87. if (ExtensionGuid != NULL)
  88. {
  89. Contrib->m_ExtensionGuid = *ExtensionGuid;
  90. Contrib->m_IsExtendedSection = ((Contrib->m_ExtensionGuid != GUID_NULL) != FALSE);
  91. }
  92. else
  93. {
  94. Contrib->m_ExtensionGuid = GUID_NULL;
  95. Contrib->m_IsExtendedSection = false;
  96. }
  97. IFW32FALSE_EXIT(Contrib->m_ContributorNameBuffer.Win32Assign(ContributorName, ::wcslen(ContributorName)));
  98. Contrib->m_SectionId = SectionId;
  99. Contrib->m_Format = Format;
  100. Contrib->m_RefCount = 1;
  101. {
  102. CSxsLockCriticalSection lock(g_ActCtxCtbListCritSec);
  103. IFW32FALSE_EXIT(lock.Lock());
  104. Contrib->m_Next = g_ActCtxCtbListHead;
  105. g_ActCtxCtbListHead = Contrib.Detach();
  106. g_ActCtxCtbListCount++;
  107. }
  108. fSuccess = TRUE;
  109. Exit:
  110. return fSuccess;
  111. }
  112. BOOL
  113. SxspInitActCtxContributors(
  114. )
  115. {
  116. FN_PROLOG_WIN32;
  117. IFW32FALSE_EXIT(g_ActCtxCtbListCritSec.ConstructWithSEH());
  118. ASSERT(g_ActCtxCtbListHead == NULL);
  119. ASSERT(g_ActCtxCtbListCount == 0);
  120. IFW32FALSE_EXIT(::SxspAddBuiltinActCtxContributor(
  121. &SxspAssemblyMetadataContributorCallback,
  122. NULL,
  123. ACTIVATION_CONTEXT_SECTION_ASSEMBLY_INFORMATION,
  124. ACTIVATION_CONTEXT_SECTION_FORMAT_STRING_TABLE,
  125. L"Builtin Assembly Metadata Contributor"));
  126. IFW32FALSE_EXIT(::SxspAddBuiltinActCtxContributor(
  127. &SxspDllRedirectionContributorCallback,
  128. NULL,
  129. ACTIVATION_CONTEXT_SECTION_DLL_REDIRECTION,
  130. ACTIVATION_CONTEXT_SECTION_FORMAT_STRING_TABLE,
  131. L"Builtin DLL Redirection contributor"));
  132. IFW32FALSE_EXIT(::SxspAddBuiltinActCtxContributor(
  133. &SxspWindowClassRedirectionContributorCallback,
  134. NULL,
  135. ACTIVATION_CONTEXT_SECTION_WINDOW_CLASS_REDIRECTION,
  136. ACTIVATION_CONTEXT_SECTION_FORMAT_STRING_TABLE,
  137. L"Builtin Window Class Redirection contributor"));
  138. IFW32FALSE_EXIT(::SxspAddBuiltinActCtxContributor(
  139. &SxspComClassRedirectionContributorCallback,
  140. NULL,
  141. ACTIVATION_CONTEXT_SECTION_COM_SERVER_REDIRECTION,
  142. ACTIVATION_CONTEXT_SECTION_FORMAT_GUID_TABLE,
  143. L"Builtin COM Server Redirection contributor"));
  144. IFW32FALSE_EXIT(::SxspAddBuiltinActCtxContributor(
  145. &SxspComProgIdRedirectionContributorCallback,
  146. NULL,
  147. ACTIVATION_CONTEXT_SECTION_COM_PROGID_REDIRECTION,
  148. ACTIVATION_CONTEXT_SECTION_FORMAT_STRING_TABLE,
  149. L"Builtin COM ProgId redirection contributor"));
  150. IFW32FALSE_EXIT(::SxspAddBuiltinActCtxContributor(
  151. &SxspComTypeLibRedirectionContributorCallback,
  152. NULL,
  153. ACTIVATION_CONTEXT_SECTION_COM_TYPE_LIBRARY_REDIRECTION,
  154. ACTIVATION_CONTEXT_SECTION_FORMAT_GUID_TABLE,
  155. L"Builtin COM Type Library redirection contributor"));
  156. IFW32FALSE_EXIT(::SxspAddBuiltinActCtxContributor(
  157. &SxspComInterfaceRedirectionContributorCallback,
  158. NULL,
  159. ACTIVATION_CONTEXT_SECTION_COM_INTERFACE_REDIRECTION,
  160. ACTIVATION_CONTEXT_SECTION_FORMAT_GUID_TABLE,
  161. L"Builtin COM interface redirection contributor"));
  162. IFW32FALSE_EXIT(::SxspAddBuiltinActCtxContributor(
  163. &SxspClrInteropContributorCallback,
  164. NULL,
  165. ACTIVATION_CONTEXT_SECTION_CLR_SURROGATES,
  166. ACTIVATION_CONTEXT_SECTION_FORMAT_GUID_TABLE,
  167. L"Builtin NDP surrogate data contributor"));
  168. FN_EPILOG;
  169. }
  170. VOID
  171. SxspUninitActCtxContributors(
  172. VOID
  173. )
  174. {
  175. FN_TRACE();
  176. PACTCTXCTB pCtb;
  177. g_ActCtxCtbListCritSec.Destruct();
  178. pCtb = g_ActCtxCtbListHead;
  179. while (pCtb != NULL)
  180. {
  181. PACTCTXCTB pNext = pCtb->m_Next;
  182. pCtb->Release();
  183. pCtb = pNext;
  184. }
  185. }
  186. BOOL
  187. SxspPrepareContributor(
  188. PACTCTXCTB Contrib
  189. )
  190. {
  191. #if SXSP_EXTENSIBLE_CONTRIBUTORS
  192. BOOL fSuccess = FALSE;
  193. FN_TRACE_WIN32(fSuccess);
  194. CDynamicLinkLibrary DllHandle;
  195. PARAMETER_CHECK(Contrib != NULL);
  196. if ((Contrib->m_DllHandle == NULL) &&
  197. (!Contrib->m_BuiltinContributor))
  198. {
  199. ACTCTXCTB_CBINIT InitData;
  200. ACTCTXCTB_CALLBACK_FUNCTION CallbackFunction = NULL;
  201. #define PROCEDURE_NAME "ContributeActCtxSection"
  202. CHAR ProcNameBuffer[ACTCTXCTB_MAX_PREFIX_LENGTH + sizeof(PROCEDURE_NAME)];
  203. PCSTR ProcName = PROCEDURE_NAME;
  204. IFW32FALSE_EXIT(DllHandle.Create(Contrib->m_DllNameBuffer));
  205. if (Contrib->m_PrefixBuffer[0] != NULL)
  206. {
  207. strcpy(ProcNameBuffer, Contrib->m_PrefixBuffer);
  208. strcat(ProcNameBuffer, PROCEDURE_NAME);
  209. ProcName = ProcNameBuffer;
  210. }
  211. IFW32FALSE_EXIT(DllHandle.GetProcAddress(ProcName, &CallbackFunction));
  212. // We're pretty much all set. Initialize the contributor.
  213. InitData.Header.Reason = ACTCTXCTB_CBREASON_INIT;
  214. InitData.Header.ExtensionGuid = Contrib->GetExtensionGuidPtr();
  215. InitData.Header.SectionId = Contrib->m_SectionId;
  216. InitData.Header.ContributorContext = NULL;
  217. InitData.Header.Flags = 0;
  218. IFW32FALSE_EXIT(((*CallbackFunction)((PACTCTXCTB_CALLBACK_DATA) &InitData.Header)));
  219. ASSERT(InitData.Header.Reason == ACTCTXCTB_CBREASON_INIT);
  220. ASSERT(InitData.Header.ExtensionGuid == Contrib->GetExtensionGuidPtr());
  221. ASSERT(InitData.Header.SectionId == Contrib->m_SectionId);
  222. ASSERT(InitData.Header.ContributorContext == NULL);
  223. ASSERT(InitData.Header.Flags == 0);
  224. Contrib->m_DllHandle = DllHandle.Detach();
  225. Contrib->m_CallbackFunction = CallbackFunction;
  226. Contrib->m_ContributorContext = InitData.Header.ContributorContext;
  227. }
  228. fSuccess = TRUE;
  229. Exit:
  230. return fSuccess;
  231. #else
  232. return TRUE;
  233. #endif
  234. }