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.

383 lines
13 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. sxsp.h
  5. Abstract:
  6. Include file for ntdll-private definitions of Side-By-Side data structures.
  7. Author:
  8. Michael J. Grier (mgrier) October 26, 2000
  9. Environment:
  10. Revision History:
  11. --*/
  12. #if !defined(_NTDLL_SXSP_H_INCLUDED_)
  13. #define _NTDLL_SXSP_H_INCLUDED_
  14. #include <nturtl.h>
  15. #include <sxstypes.h>
  16. //
  17. // Private definitions for activation context management stuff
  18. //
  19. #define NUMBER_OF(x) (sizeof(x) / sizeof((x)[0]))
  20. //
  21. // Codes for the STATUS_SXS_CORRUPTION exception
  22. //
  23. #define SXS_CORRUPTION_CODE_FRAMELIST (1)
  24. #define SXS_CORRUPTION_CODE_FRAMELIST_SUBCODE_BAD_MAGIC (1)
  25. #define SXS_CORRUPTION_CODE_FRAMELIST_SUBCODE_BAD_INUSECOUNT (2)
  26. // SXS_CORRUPTION_CODE_FRAMELIST:
  27. //
  28. // ExceptionInformation[0] == SXS_CORRUPTION_CODE_FRAMELIST
  29. // ExceptionInformation[1] == one of: SXS_CORRUPTION_CODE_FRAMELIST_SUBCODE_BAD_MAGIC, SXS_CORRUPTION_CODE_FRAMELIST_SUBCODE_BAD_INUSECOUNT
  30. // ExceptionInformation[2] == Framelist list head in TEB
  31. // ExceptionInformation[3] == Framelist found to be corrupt
  32. typedef struct _RTL_HEAP_ALLOCATED_ACTIVATION_CONTEXT_STACK_FRAME {
  33. RTL_ACTIVATION_CONTEXT_STACK_FRAME Frame;
  34. ULONG_PTR Cookie;
  35. PVOID ActivationStackBackTrace[8];
  36. } RTL_HEAP_ALLOCATED_ACTIVATION_CONTEXT_STACK_FRAME, *PRTL_HEAP_ALLOCATED_ACTIVATION_CONTEXT_STACK_FRAME;
  37. NTSYSAPI
  38. VOID
  39. NTAPI
  40. RtlpAssemblyStorageMapResolutionDefaultCallback(
  41. IN ULONG CallbackReason,
  42. IN OUT ASSEMBLY_STORAGE_MAP_RESOLUTION_CALLBACK_DATA *CallbackData,
  43. IN PVOID CallbackContext
  44. );
  45. typedef struct _ASSEMBLY_STORAGE_MAP_ENTRY {
  46. ULONG Flags;
  47. UNICODE_STRING DosPath; // stored with a trailing unicode null
  48. HANDLE Handle; // open file handle on the directory to lock it down
  49. } ASSEMBLY_STORAGE_MAP_ENTRY, *PASSEMBLY_STORAGE_MAP_ENTRY;
  50. #define ASSEMBLY_STORAGE_MAP_ASSEMBLY_ARRAY_IS_HEAP_ALLOCATED (0x00000001)
  51. typedef struct _ASSEMBLY_STORAGE_MAP {
  52. ULONG Flags;
  53. ULONG AssemblyCount;
  54. PASSEMBLY_STORAGE_MAP_ENTRY *AssemblyArray;
  55. } ASSEMBLY_STORAGE_MAP, *PASSEMBLY_STORAGE_MAP;
  56. typedef struct _ACTIVATION_CONTEXT {
  57. LONG RefCount;
  58. ULONG Flags;
  59. PVOID ActivationContextData;
  60. PACTIVATION_CONTEXT_NOTIFY_ROUTINE NotificationRoutine;
  61. PVOID NotificationContext;
  62. ULONG SentNotifications[8];
  63. ULONG DisabledNotifications[8];
  64. ASSEMBLY_STORAGE_MAP StorageMap;
  65. PASSEMBLY_STORAGE_MAP_ENTRY InlineStorageMapEntries[32];
  66. } ACTIVATION_CONTEXT;
  67. #define ACTIVATION_CONTEXT_NOTIFICATION_DESTROY_INDEX (ACTIVATION_CONTEXT_NOTIFICATION_DESTROY >> 5)
  68. #define ACTIVATION_CONTEXT_NOTIFICATION_DESTROY_MASK ((ULONG) (1 << (ACTIVATION_CONTEXT_NOTIFICATION_DESTROY & 0x1f)))
  69. #define ACTIVATION_CONTEXT_NOTIFICATION_ZOMBIFY_INDEX (ACTIVATION_CONTEXT_NOTIFICATION_ZOMBIFY >> 5)
  70. #define ACTIVATION_CONTEXT_NOTIFICATION_ZOMBIFY_MASK ((ULONG) (1 << (ACTIVATION_CONTEXT_NOTIFICATION_ZOMBIFY & 0x1f)))
  71. #define ACTIVATION_CONTEXT_NOTIFICATION_USED_INDEX (ACTIVATION_CONTEXT_NOTIFICATION_USED >> 5)
  72. #define ACTIVATION_CONTEXT_NOTIFICATION_USED_MASK ((ULONG) (1 << (ACTIVATION_CONTEXT_NOTIFICATION_USED & 0x1f)))
  73. #define HAS_ACTIVATION_CONTEXT_NOTIFICATION_BEEN_SENT(_pac, _nt) (((_pac)->SentNotifications[ACTIVATION_CONTEXT_NOTIFICATION_ ## _nt ## _INDEX] & ACTIVATION_CONTEXT_NOTIFICATION_ ## _nt ## _MASK) != 0)
  74. #define HAS_ACTIVATION_CONTEXT_NOTIFICATION_BEEN_DISABLED(_pac, _nt) (((_pac)->DisabledNotifications[ACTIVATION_CONTEXT_NOTIFICATION_ ## _nt ## _INDEX] & ACTIVATION_CONTEXT_NOTIFICATION_ ## _nt ## _MASK) != 0)
  75. #define ACTIVATION_CONTEXT_SHOULD_SEND_NOTIFICATION(_pac, _nt) \
  76. ((!IS_SPECIAL_ACTCTX(_pac)) && ((_pac)->NotificationRoutine != NULL) && ((!HAS_ACTIVATION_CONTEXT_NOTIFICATION_BEEN_SENT((_pac), _nt)) || (!HAS_ACTIVATION_CONTEXT_NOTIFICATION_BEEN_DISABLED((_pac), _nt))))
  77. #define RECORD_ACTIVATION_CONTEXT_NOTIFICATION_SENT(_pac, _nt) { (_pac)->SentNotifications[ACTIVATION_CONTEXT_NOTIFICATION_ ## _nt ## _INDEX] |= ACTIVATION_CONTEXT_NOTIFICATION_ ## _nt ## _MASK; }
  78. #define RECORD_ACTIVATION_CONTEXT_NOTIFICATION_DISABLED(_pac, _nt) { (_pac)->DisabledNotifications[ACTIVATION_CONTEXT_NOTIFICATION_ ## _nt ## _INDEX] |= ACTIVATION_CONTEXT_NOTIFICATION_ ## _nt ## _MASK; }
  79. #define SEND_ACTIVATION_CONTEXT_NOTIFICATION(_pac, _nt, _data) \
  80. { \
  81. if (ACTIVATION_CONTEXT_SHOULD_SEND_NOTIFICATION((_pac), _nt)) { \
  82. BOOLEAN __DisableNotification = FALSE; \
  83. (*((_pac)->NotificationRoutine))( \
  84. ACTIVATION_CONTEXT_NOTIFICATION_ ## _nt, \
  85. (_pac), \
  86. (_pac)->ActivationContextData, \
  87. (_pac)->NotificationContext, \
  88. (_data), \
  89. &__DisableNotification); \
  90. RECORD_ACTIVATION_CONTEXT_NOTIFICATION_SENT((_pac), _nt); \
  91. if (__DisableNotification) \
  92. RECORD_ACTIVATION_CONTEXT_NOTIFICATION_DISABLED((_pac), _nt); \
  93. } \
  94. }
  95. //
  96. // Flags for ACTIVATION_CONTEXT
  97. //
  98. #define ACTIVATION_CONTEXT_ZOMBIFIED (0x00000001)
  99. #define ACTIVATION_CONTEXT_NOT_HEAP_ALLOCATED (0x00000002)
  100. //
  101. // Because activating an activation context may require a heap allocation
  102. // which may fail, sometimes (e.g. dispatching an APC) we must still
  103. // go forward with the operation. If there is an opportunity to
  104. // report the failure to activate back to the user, that should be done.
  105. // However, as in activating the necessary context prior to dispatching
  106. // an APC back to the user mode code, if the allocation fails, there is
  107. // no caller to whom to report the error.
  108. //
  109. // To alleviate this problem, failure paths should disable lookups on
  110. // the current stack frame via the RtlSetActivationContextSearchState()
  111. // API. Calling RtlSetActivationContextSearchState(FALSE) marks
  112. // the active frame as having lookups disabled. Attempts to query
  113. // the activation context stack will fail with the
  114. // STATUS_SXS_THREAD_QUERIES_DISABLED.
  115. //
  116. // This means that attempts to load libraries from within APCs where this
  117. // is true will fail, but it's surely better than either silently not
  118. // calling the APC or calling the APC with the wrong activation context
  119. // active.
  120. //
  121. #define ACTIVATION_CONTEXT_STACK_FRAMELIST_MAGIC 'tslF'
  122. typedef struct _ACTIVATION_CONTEXT_STACK_FRAMELIST {
  123. ULONG Magic; // Bit pattern to recognize a framelist
  124. ULONG FramesInUse;
  125. LIST_ENTRY Links;
  126. ULONG Flags;
  127. ULONG NotFramesInUse; // Inverted bits of FramesInUse. Useful for debugging.
  128. RTL_HEAP_ALLOCATED_ACTIVATION_CONTEXT_STACK_FRAME Frames[32];
  129. } ACTIVATION_CONTEXT_STACK_FRAMELIST, *PACTIVATION_CONTEXT_STACK_FRAMELIST;
  130. #define RTLP_VALIDATE_ACTIVATION_CONTEXT_DATA_FLAG_VALIDATE_SIZE (0x00000001)
  131. #define RTLP_VALIDATE_ACTIVATION_CONTEXT_DATA_FLAG_VALIDATE_OFFSETS (0x00000002)
  132. #define RTLP_VALIDATE_ACTIVATION_CONTEXT_DATA_FLAG_VALIDATE_READONLY (0x00000004)
  133. NTSTATUS
  134. RtlpValidateActivationContextData(
  135. IN ULONG Flags OPTIONAL,
  136. IN PCACTIVATION_CONTEXT_DATA Data,
  137. IN SIZE_T BufferSize OPTIONAL
  138. );
  139. NTSTATUS
  140. RtlpFindUnicodeStringInSection(
  141. IN const ACTIVATION_CONTEXT_STRING_SECTION_HEADER UNALIGNED * Header,
  142. IN SIZE_T SectionSize,
  143. IN PCUNICODE_STRING StringToFind,
  144. OUT PACTIVATION_CONTEXT_SECTION_KEYED_DATA DataOut OPTIONAL,
  145. IN OUT PULONG HashAlgorithm,
  146. IN OUT PULONG PseudoKey,
  147. OUT PULONG UserDataSize OPTIONAL,
  148. OUT VOID CONST ** UserData OPTIONAL
  149. );
  150. NTSTATUS
  151. RtlpFindGuidInSection(
  152. IN const ACTIVATION_CONTEXT_GUID_SECTION_HEADER UNALIGNED * Header,
  153. IN const GUID *GuidToFind,
  154. OUT PACTIVATION_CONTEXT_SECTION_KEYED_DATA DataOut OPTIONAL
  155. );
  156. NTSTATUS
  157. RtlpLocateActivationContextSection(
  158. IN PCACTIVATION_CONTEXT_DATA ActivationContextData,
  159. IN const GUID *ExtensionGuid,
  160. IN ULONG Id,
  161. OUT VOID CONST **SectionData,
  162. OUT ULONG *SectionLength
  163. );
  164. NTSTATUS
  165. RtlpCrackActivationContextStringSectionHeader(
  166. IN CONST VOID *SectionBase,
  167. IN SIZE_T SectionLength,
  168. OUT ULONG *FormatVersion OPTIONAL,
  169. OUT ULONG *DataFormatVersion OPTIONAL,
  170. OUT ULONG *SectionFlags OPTIONAL,
  171. OUT ULONG *ElementCount OPTIONAL,
  172. OUT PCACTIVATION_CONTEXT_STRING_SECTION_ENTRY *Elements OPTIONAL,
  173. OUT ULONG *HashAlgorithm OPTIONAL,
  174. OUT VOID CONST **SearchStructure OPTIONAL,
  175. OUT ULONG *UserDataSize OPTIONAL,
  176. OUT VOID CONST **UserData OPTIONAL
  177. );
  178. NTSTATUS
  179. RtlpGetActiveActivationContextApplicationDirectory(
  180. IN SIZE_T InLength,
  181. OUT PVOID OutBuffer,
  182. OUT SIZE_T *OutLength
  183. );
  184. NTSTATUS
  185. RtlpFindNextActivationContextSection(
  186. PFINDFIRSTACTIVATIONCONTEXTSECTION Context,
  187. VOID CONST **SectionData,
  188. ULONG *SectionLength,
  189. PACTIVATION_CONTEXT *ActivationContextOut
  190. );
  191. NTSTATUS
  192. RtlpAllocateActivationContextStackFrame(
  193. ULONG Flags,
  194. PTEB Teb,
  195. PRTL_HEAP_ALLOCATED_ACTIVATION_CONTEXT_STACK_FRAME *Frame
  196. );
  197. VOID
  198. RtlpFreeActivationContextStackFrame(
  199. PRTL_HEAP_ALLOCATED_ACTIVATION_CONTEXT_STACK_FRAME Frame
  200. );
  201. PSTR
  202. RtlpFormatGuidANSI(
  203. const GUID *Guid,
  204. PSTR Buffer,
  205. SIZE_T BufferLength
  206. );
  207. extern const ACTIVATION_CONTEXT_DATA RtlpTheEmptyActivationContextData;
  208. extern ACTIVATION_CONTEXT RtlpTheEmptyActivationContext;
  209. #define RTLP_DISALLOW_THE_EMPTY_ACTIVATION_CONTEXT(ActCtx) \
  210. { \
  211. ASSERT((ActCtx) != &RtlpTheEmptyActivationContext); \
  212. if ((ActCtx) == &RtlpTheEmptyActivationContext) { \
  213. DbgPrintEx( \
  214. DPFLTR_SXS_ID, \
  215. DPFLTR_ERROR_LEVEL, \
  216. "SXS: %s() passed the empty activation context\n", __FUNCTION__); \
  217. Status = STATUS_INVALID_PARAMETER; \
  218. goto Exit; \
  219. } \
  220. }
  221. #define RTLP_DISALLOW_THE_EMPTY_ACTIVATION_CONTEXT_DATA(ActCtxData) \
  222. { \
  223. ASSERT((ActCtxData) != &RtlpTheEmptyActivationContextData); \
  224. if ((ActCtxData) == &RtlpTheEmptyActivationContextData) { \
  225. DbgPrintEx( \
  226. DPFLTR_SXS_ID, \
  227. DPFLTR_ERROR_LEVEL, \
  228. "SXS: %s() passed the empty activation context data\n", __FUNCTION__); \
  229. Status = STATUS_INVALID_PARAMETER; \
  230. goto Exit; \
  231. } \
  232. }
  233. PACTIVATION_CONTEXT
  234. RtlpMapSpecialValuesToBuiltInActivationContexts(
  235. PACTIVATION_CONTEXT ActivationContext
  236. );
  237. NTSTATUS
  238. RtlpThreadPoolGetActiveActivationContext(
  239. PACTIVATION_CONTEXT* ActivationContext
  240. );
  241. NTSTATUS
  242. RtlpInitializeAssemblyStorageMap(
  243. PASSEMBLY_STORAGE_MAP Map,
  244. ULONG EntryCount,
  245. PASSEMBLY_STORAGE_MAP_ENTRY *EntryArray
  246. );
  247. VOID
  248. RtlpUninitializeAssemblyStorageMap(
  249. PASSEMBLY_STORAGE_MAP Map
  250. );
  251. NTSTATUS
  252. RtlpResolveAssemblyStorageMapEntry(
  253. IN OUT PASSEMBLY_STORAGE_MAP Map,
  254. IN PCACTIVATION_CONTEXT_DATA Data,
  255. IN ULONG AssemblyRosterIndex,
  256. IN PASSEMBLY_STORAGE_MAP_RESOLUTION_CALLBACK_ROUTINE Callback,
  257. IN PVOID CallbackContext
  258. );
  259. NTSTATUS
  260. RtlpInsertAssemblyStorageMapEntry(
  261. IN PASSEMBLY_STORAGE_MAP Map,
  262. IN ULONG AssemblyRosterIndex,
  263. IN PCUNICODE_STRING StorageLocation,
  264. IN HANDLE OpenDirectoryHandle
  265. );
  266. NTSTATUS
  267. RtlpProbeAssemblyStorageRootForAssembly(
  268. IN ULONG Flags,
  269. IN PCUNICODE_STRING Root,
  270. IN PCUNICODE_STRING AssemblyDirectory,
  271. OUT PUNICODE_STRING PreAllocatedString,
  272. OUT PUNICODE_STRING DynamicString,
  273. OUT PUNICODE_STRING *StringUsed,
  274. OUT HANDLE OpenDirectoryHandle
  275. );
  276. NTSTATUS
  277. RtlpGetAssemblyStorageMapRootLocation(
  278. IN HANDLE KeyHandle,
  279. IN PCUNICODE_STRING SubKeyName,
  280. OUT PUNICODE_STRING Root
  281. );
  282. #define RTLP_GET_ACTIVATION_CONTEXT_DATA_STORAGE_MAP_AND_ROSTER_HEADER_USE_PROCESS_DEFAULT (0x00000001)
  283. #define RTLP_GET_ACTIVATION_CONTEXT_DATA_STORAGE_MAP_AND_ROSTER_HEADER_USE_SYSTEM_DEFAULT (0x00000002)
  284. NTSTATUS
  285. RtlpGetActivationContextDataRosterHeader(
  286. IN ULONG Flags,
  287. IN PCACTIVATION_CONTEXT_DATA ActivationContextData,
  288. OUT PCACTIVATION_CONTEXT_DATA_ASSEMBLY_ROSTER_HEADER *AssemblyRosterHeader
  289. );
  290. NTSTATUS
  291. RtlpGetActivationContextDataStorageMapAndRosterHeader(
  292. IN ULONG Flags,
  293. IN PPEB Peb,
  294. IN PACTIVATION_CONTEXT ActivationContext,
  295. OUT PCACTIVATION_CONTEXT_DATA *ActivationContextData,
  296. OUT PASSEMBLY_STORAGE_MAP *AssemblyStorageMap,
  297. OUT PCACTIVATION_CONTEXT_DATA_ASSEMBLY_ROSTER_HEADER *AssemblyRosterHeader
  298. );
  299. #define RTLP_GET_ACTIVATION_CONTEXT_DATA_MAP_NULL_TO_EMPTY (0x00000001)
  300. NTSTATUS
  301. RtlpGetActivationContextData(
  302. IN ULONG Flags,
  303. IN PCACTIVATION_CONTEXT ActivationContext,
  304. IN PCFINDFIRSTACTIVATIONCONTEXTSECTION FindContext, OPTIONAL /* This is used for its flags. */
  305. OUT PCACTIVATION_CONTEXT_DATA * ActivationContextData
  306. );
  307. NTSTATUS
  308. RtlpFindActivationContextSection_FillOutReturnedData(
  309. IN ULONG Flags,
  310. OUT PACTIVATION_CONTEXT_SECTION_KEYED_DATA ReturnedData,
  311. IN OUT PACTIVATION_CONTEXT ActivationContext,
  312. IN PCFINDFIRSTACTIVATIONCONTEXTSECTION FindContext,
  313. IN const VOID * UNALIGNED Header,
  314. IN ULONG Header_UserDataOffset,
  315. IN ULONG Header_UserDataSize,
  316. IN ULONG SectionLength
  317. );
  318. #endif // !defined(_NTDLL_SXSP_H_INCLUDED_)