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.

251 lines
4.9 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. compsup.c
  5. Abstract:
  6. This module implements COM+ support routines to detect COM+ images.
  7. Author:
  8. Samer Arafeh (samera) 23-Oct-2000
  9. Revision History:
  10. --*/
  11. #include "basedll.h"
  12. #include <wow64t.h>
  13. BOOL
  14. SetComPlusPackageInstallStatus(
  15. ULONG ComPlusPackage
  16. )
  17. /*++
  18. Routine Description:
  19. This function updates the COM+ package status on the system.
  20. Arguments:
  21. ComPlusPackage - Com+ package value to update.
  22. Return Value:
  23. BOOL.
  24. --*/
  25. {
  26. NTSTATUS NtStatus;
  27. if (ComPlusPackage & COMPLUS_INSTALL_FLAGS_INVALID)
  28. {
  29. BaseSetLastNTError (STATUS_INVALID_PARAMETER);
  30. return FALSE;
  31. }
  32. NtStatus = NtSetSystemInformation(
  33. SystemComPlusPackage,
  34. &ComPlusPackage,
  35. sizeof (ULONG)
  36. );
  37. if (!NT_SUCCESS (NtStatus))
  38. {
  39. BaseSetLastNTError (NtStatus);
  40. return FALSE;
  41. }
  42. return TRUE;
  43. }
  44. ULONG
  45. GetComPlusPackageInstallStatus(
  46. VOID
  47. )
  48. /*++
  49. Routine Description:
  50. This function reads the COM+ package status on the system.
  51. Arguments:
  52. None.
  53. Return Value:
  54. ULONG representing the COM+ package value.
  55. --*/
  56. {
  57. NTSTATUS NtStatus;
  58. ULONG ComPlusPackage;
  59. ComPlusPackage = USER_SHARED_DATA->ComPlusPackage;
  60. if (ComPlusPackage == (ULONG)-1)
  61. {
  62. //
  63. // If this is the first call ever, let's get the information from
  64. // the kernel.
  65. //
  66. NtQuerySystemInformation(
  67. SystemComPlusPackage,
  68. &ComPlusPackage,
  69. sizeof (ULONG),
  70. NULL
  71. );
  72. }
  73. return ComPlusPackage;
  74. }
  75. #if defined(_WIN64) || defined(BUILD_WOW6432)
  76. NTSTATUS
  77. BasepIsComplusILImage(
  78. IN HANDLE SectionImageHandle,
  79. IN PSECTION_IMAGE_INFORMATION SectionImageInformation,
  80. OUT BOOLEAN *IsComplusILImage
  81. )
  82. /*++
  83. Routine Description:
  84. This function is called each time a COM+ image is about to be launched. It checks
  85. to see if the image is an ILONLY image or not.
  86. Arguments:
  87. ImageSection - Open handle to the image section to examine.
  88. SectionImageInformation - Address of SECTION_IMAGE_INFORMATION for the image.
  89. IsComplusILImage - Out boolean. TRUE if SectionImageHandle corresponds to an IL only
  90. COM+ image, otherwise FALSE.
  91. Return Value:
  92. NTSTATUS
  93. --*/
  94. {
  95. PVOID ViewBase;
  96. SIZE_T ViewSize;
  97. ULONG EntrySize;
  98. PIMAGE_COR20_HEADER Cor20Header;
  99. PIMAGE_NT_HEADERS NtImageHeader;
  100. ULONG ComPlusPackage64;
  101. #if defined(BUILD_WOW6432)
  102. ULONG NativePageSize = Wow64GetSystemNativePageSize();
  103. #else
  104. #define NativePageSize BASE_SYSINFO.PageSize
  105. #endif
  106. NTSTATUS NtStatus = STATUS_SUCCESS;
  107. *IsComplusILImage = FALSE;
  108. //
  109. // Let's map in the image and look inside the headers
  110. //
  111. ViewSize = 0;
  112. ViewBase = NULL;
  113. NtStatus = NtMapViewOfSection (
  114. SectionImageHandle,
  115. NtCurrentProcess(),
  116. &ViewBase,
  117. 0L,
  118. 0L,
  119. NULL,
  120. &ViewSize,
  121. ViewShare,
  122. 0L,
  123. PAGE_READONLY
  124. );
  125. if (NT_SUCCESS (NtStatus))
  126. {
  127. //
  128. // Examine the image
  129. //
  130. try
  131. {
  132. NtImageHeader = RtlImageNtHeader (ViewBase);
  133. if (NtImageHeader != NULL)
  134. {
  135. if (NtImageHeader->OptionalHeader.SectionAlignment < NativePageSize)
  136. {
  137. ViewBase = LDR_VIEW_TO_DATAFILE (ViewBase);
  138. }
  139. Cor20Header = RtlImageDirectoryEntryToData (
  140. ViewBase,
  141. TRUE,
  142. IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR,
  143. &EntrySize
  144. );
  145. if ((Cor20Header != NULL) && (EntrySize != 0))
  146. {
  147. if ((Cor20Header->Flags & (COMIMAGE_FLAGS_32BITREQUIRED | COMIMAGE_FLAGS_ILONLY)) ==
  148. COMIMAGE_FLAGS_ILONLY)
  149. {
  150. ComPlusPackage64 = GetComPlusPackageInstallStatus ();
  151. if ((ComPlusPackage64 & COMPLUS_ENABLE_64BIT) != 0)
  152. {
  153. *IsComplusILImage = TRUE;
  154. }
  155. }
  156. }
  157. ViewBase = LDR_DATAFILE_TO_VIEW (ViewBase);
  158. }
  159. }
  160. except (EXCEPTION_EXECUTE_HANDLER)
  161. {
  162. NtStatus = GetExceptionCode();
  163. }
  164. //
  165. // Unmap the section from memory
  166. //
  167. NtUnmapViewOfSection (
  168. NtCurrentProcess(),
  169. ViewBase
  170. );
  171. }
  172. return NtStatus;
  173. }
  174. #endif