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.

273 lines
5.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. OUT BOOLEAN *IsComplusILImage
  80. )
  81. /*++
  82. Routine Description:
  83. This function is called each time a COM+ image is about to be launched. It checks
  84. to see if the image is an ILONLY image or not.
  85. Arguments:
  86. ImageSection - Open handle to the image section to examine.
  87. IsComplusILImage - Out boolean. TRUE if SectionImageHandle corresponds to an IL only
  88. COM+ image, otherwise FALSE.
  89. Return Value:
  90. NTSTATUS
  91. --*/
  92. {
  93. BOOLEAN MappedAsImage;
  94. PVOID ViewBase;
  95. SIZE_T ViewSize;
  96. ULONG EntrySize;
  97. PIMAGE_COR20_HEADER Cor20Header;
  98. PIMAGE_NT_HEADERS NtImageHeader;
  99. ULONG ComPlusPackage64;
  100. SIZE_T ReturnLength;
  101. MEMORY_BASIC_INFORMATION MemoryInformation;
  102. #if defined(BUILD_WOW6432)
  103. ULONG NativePageSize = Wow64GetSystemNativePageSize();
  104. #else
  105. #define NativePageSize BASE_SYSINFO.PageSize
  106. #endif
  107. NTSTATUS NtStatus = STATUS_SUCCESS;
  108. *IsComplusILImage = FALSE;
  109. //
  110. // Let's map in the image and look inside the headers
  111. //
  112. ViewSize = 0;
  113. ViewBase = NULL;
  114. NtStatus = NtMapViewOfSection (
  115. SectionImageHandle,
  116. NtCurrentProcess(),
  117. &ViewBase,
  118. 0L,
  119. 0L,
  120. NULL,
  121. &ViewSize,
  122. ViewShare,
  123. 0L,
  124. PAGE_READONLY
  125. );
  126. if (!NT_SUCCESS (NtStatus)) {
  127. ViewBase = NULL;
  128. goto Exit;
  129. }
  130. MappedAsImage = TRUE;
  131. //
  132. // Examine the image
  133. //
  134. __try {
  135. NtStatus = RtlImageNtHeaderEx(0, ViewBase, ViewSize, &NtImageHeader);
  136. if (!NT_SUCCESS(NtStatus)) {
  137. __leave;
  138. }
  139. if (NtImageHeader == NULL) {
  140. NtStatus = STATUS_INTERNAL_ERROR;
  141. __leave;
  142. }
  143. if (NtImageHeader->OptionalHeader.SectionAlignment < NativePageSize) {
  144. NtStatus = NtQueryVirtualMemory (NtCurrentProcess(),
  145. ViewBase,
  146. MemoryBasicInformation,
  147. &MemoryInformation,
  148. sizeof MemoryInformation,
  149. &ReturnLength);
  150. if ((NT_SUCCESS(NtStatus)) &&
  151. ((MemoryInformation.Protect == PAGE_READONLY) ||
  152. (MemoryInformation.Protect == PAGE_EXECUTE_READ))) {
  153. //
  154. // This is mapped as a native image if the PE header isn't
  155. // already copy on write.
  156. //
  157. NOTHING;
  158. }
  159. else {
  160. MappedAsImage = FALSE;
  161. ViewBase = LDR_VIEW_TO_DATAFILE (ViewBase);
  162. }
  163. }
  164. Cor20Header = RtlImageDirectoryEntryToData (
  165. ViewBase,
  166. MappedAsImage,
  167. IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR,
  168. &EntrySize
  169. );
  170. if ((Cor20Header != NULL) && (EntrySize != 0))
  171. {
  172. if ((Cor20Header->Flags & (COMIMAGE_FLAGS_32BITREQUIRED | COMIMAGE_FLAGS_ILONLY)) ==
  173. COMIMAGE_FLAGS_ILONLY)
  174. {
  175. ComPlusPackage64 = GetComPlusPackageInstallStatus ();
  176. if ((ComPlusPackage64 & COMPLUS_ENABLE_64BIT) != 0)
  177. {
  178. *IsComplusILImage = TRUE;
  179. }
  180. }
  181. }
  182. NtStatus = STATUS_SUCCESS;
  183. }
  184. __except (EXCEPTION_EXECUTE_HANDLER)
  185. {
  186. NtStatus = GetExceptionCode();
  187. }
  188. Exit:
  189. //
  190. // Unmap the section from memory
  191. //
  192. if (ViewBase != NULL) {
  193. NtUnmapViewOfSection (
  194. NtCurrentProcess(),
  195. LDR_DATAFILE_TO_VIEW(ViewBase)
  196. );
  197. }
  198. return NtStatus;
  199. }
  200. #endif