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.

734 lines
18 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. ldrp.h
  5. Abstract:
  6. Private types... for executive portion of loader
  7. Author:
  8. Mark Lucovsky (markl) 26-Mar-1990
  9. Revision History:
  10. --*/
  11. #ifndef _LDRP_
  12. #define _LDRP_
  13. #pragma warning(disable:4214) // bit field types other than int
  14. #pragma warning(disable:4201) // nameless struct/union
  15. #pragma warning(disable:4115) // named type definition in parentheses
  16. #pragma warning(disable:4127) // condition expression is constant
  17. #include <nt.h>
  18. #include <ntrtl.h>
  19. #include <nturtl.h>
  20. #include <string.h>
  21. #define NOEXTAPI
  22. #include "wdbgexts.h"
  23. #include <ntdbg.h>
  24. #include <sxstypes.h>
  25. #if defined(_WIN64)
  26. extern INVERTED_FUNCTION_TABLE LdrpInvertedFunctionTable;
  27. #endif
  28. #if DBG
  29. #define LdrpShouldDbgPrintStatus(st) \
  30. (!NT_SUCCESS(st) \
  31. && (ShowSnaps \
  32. || ( (st) != STATUS_NO_SUCH_FILE \
  33. && (st) != STATUS_DLL_NOT_FOUND \
  34. && (st) != STATUS_OBJECT_NAME_NOT_FOUND \
  35. )))
  36. #else
  37. #define LdrpShouldDbgPrintStatus(st) (FALSE)
  38. #endif
  39. #if DBG
  40. #define LDR_ERROR_DPFLTR DPFLTR_ERROR_LEVEL
  41. #else
  42. #define LDR_ERROR_DPFLTR ((ShowSnaps || ShowErrors) ? DPFLTR_ERROR_LEVEL : DPFLTR_INFO_LEVEL)
  43. #endif // DBG
  44. extern BOOLEAN LdrpImageHasTls;
  45. extern UNICODE_STRING LdrpDefaultPath;
  46. extern HANDLE LdrpKnownDllObjectDirectory;
  47. #define LDRP_MAX_KNOWN_PATH 128
  48. extern WCHAR LdrpKnownDllPathBuffer[LDRP_MAX_KNOWN_PATH];
  49. extern UNICODE_STRING LdrpKnownDllPath;
  50. extern PLDR_MANIFEST_PROBER_ROUTINE LdrpManifestProberRoutine;
  51. extern PLDR_APP_COMPAT_DLL_REDIRECTION_CALLBACK_FUNCTION LdrpAppCompatDllRedirectionCallbackFunction;
  52. extern PVOID LdrpAppCompatDllRedirectionCallbackData;
  53. extern PVOID LdrpHeap;
  54. extern RTL_CRITICAL_SECTION LdrpLoaderLock;
  55. extern PCUNICODE_STRING LdrpTopLevelDllBeingLoaded;
  56. extern PTEB LdrpTopLevelDllBeingLoadedTeb;
  57. extern BOOLEAN LdrpBreakOnExceptions;
  58. extern PLDR_DATA_TABLE_ENTRY LdrpNtDllDataTableEntry;
  59. extern PLDR_DATA_TABLE_ENTRY LdrpCurrentDllInitializer;
  60. extern BOOLEAN LdrpShowInitRoutines;
  61. extern BOOLEAN LdrpShowRecursiveDllLoads;
  62. extern BOOLEAN LdrpBreakOnRecursiveDllLoads;
  63. extern BOOLEAN LdrpLoaderLockAcquisionCount;
  64. extern BOOLEAN g_LdrBreakOnLdrpInitializeProcessFailure;
  65. extern PEB_LDR_DATA PebLdr;
  66. extern const UNICODE_STRING SlashSystem32SlashMscoreeDllString;
  67. extern const UNICODE_STRING SlashSystem32SlashString;
  68. extern const UNICODE_STRING MscoreeDllString;
  69. #define ASCII_CHAR_IS_N(_ch) (((_ch) == 'n') || ((_ch) == 'N'))
  70. #define ASCII_CHAR_IS_T(_ch) (((_ch) == 't') || ((_ch) == 'T'))
  71. #define ASCII_CHAR_IS_D(_ch) (((_ch) == 'd') || ((_ch) == 'D'))
  72. #define ASCII_CHAR_IS_L(_ch) (((_ch) == 'l') || ((_ch) == 'L'))
  73. #define ASCII_CHAR_IS_DOT(_ch) ((_ch) == '.')
  74. #define ASCII_STRING_IS_NTDLL(_p) \
  75. ((_p) != NULL) && \
  76. (((_p)->Length == (5 * sizeof(CHAR))) && \
  77. (ASCII_CHAR_IS_N((_p)->Buffer[0]) && \
  78. ASCII_CHAR_IS_T((_p)->Buffer[1]) && \
  79. ASCII_CHAR_IS_D((_p)->Buffer[2]) && \
  80. ASCII_CHAR_IS_L((_p)->Buffer[3]) && \
  81. ASCII_CHAR_IS_L((_p)->Buffer[4])) || \
  82. ((_p)->Length == ((5 + 1 + 3) * sizeof(CHAR))) && \
  83. (ASCII_CHAR_IS_N((_p)->Buffer[0]) && \
  84. ASCII_CHAR_IS_T((_p)->Buffer[1]) && \
  85. ASCII_CHAR_IS_D((_p)->Buffer[2]) && \
  86. ASCII_CHAR_IS_L((_p)->Buffer[3]) && \
  87. ASCII_CHAR_IS_L((_p)->Buffer[4]) && \
  88. ASCII_CHAR_IS_DOT((_p)->Buffer[5]) && \
  89. ASCII_CHAR_IS_D((_p)->Buffer[6]) && \
  90. ASCII_CHAR_IS_L((_p)->Buffer[7]) && \
  91. ASCII_CHAR_IS_L((_p)->Buffer[8])))
  92. //
  93. // NOTICE-2002/08/01-JayKrell
  94. // + 1 is to preserve that code was using 266
  95. // after explaining why it should be 265. Note
  96. // that sizeof("") includes a nul.
  97. // DOS_MAX_PATH_LENGTH is 260 (Win32 MAX_PATH)
  98. // LDR_MAX_PATH is 266
  99. // We will be removing path length limits in the
  100. // ldr in the future.
  101. //
  102. #define LDR_MAX_PATH (DOS_MAX_PATH_LENGTH + sizeof("\\??\\") + 1)
  103. extern LIST_ENTRY RtlpCalloutEntryList;
  104. #if defined(_AMD64_) || defined(_IA64_)
  105. extern LIST_ENTRY RtlpDynamicFunctionTable;
  106. #endif
  107. extern RTL_CRITICAL_SECTION RtlpCalloutEntryLock;
  108. typedef struct _LDRP_DLL_NOTIFICATION_BLOCK {
  109. LIST_ENTRY Links;
  110. PLDR_DLL_NOTIFICATION_FUNCTION NotificationFunction;
  111. PVOID Context;
  112. } LDRP_DLL_NOTIFICATION_BLOCK, *PLDRP_DLL_NOTIFICATION_BLOCK;
  113. //
  114. // Synchronized via LdrpLoaderLock
  115. //
  116. extern LIST_ENTRY LdrpDllNotificationList;
  117. #define LDR_NUMBER_OF(x) (sizeof(x) / sizeof((x)[0]))
  118. #if defined (BUILD_WOW6432)
  119. NTSTATUS
  120. LdrpWx86FormatVirtualImage(
  121. IN PCUNICODE_STRING DosImagePathName OPTIONAL,
  122. IN PIMAGE_NT_HEADERS32 NtHeaders,
  123. IN PVOID DllBase
  124. );
  125. NTSTATUS
  126. LdrpWx86ProtectImagePages (
  127. IN PVOID Base,
  128. IN BOOLEAN Reset
  129. );
  130. NTSTATUS
  131. Wx86SetRelocatedSharedProtection (
  132. IN PVOID Base,
  133. IN BOOLEAN Reset
  134. );
  135. ULONG
  136. LdrpWx86RelocatedFixupDiff(
  137. IN PUCHAR ImageBase,
  138. IN PIMAGE_NT_HEADERS NtHeaders,
  139. IN ULONG Offset
  140. );
  141. BOOLEAN
  142. LdrpWx86DllHasRelocatedSharedSection(
  143. IN PUCHAR ImageBase);
  144. NTSTATUS
  145. RtlpWow64GetNativeSystemInformation(
  146. IN SYSTEM_INFORMATION_CLASS SystemInformationClass,
  147. IN PVOID NativeSystemInformation,
  148. IN ULONG InformationLength,
  149. OUT PULONG ReturnLength OPTIONAL
  150. );
  151. #define NATIVE_PAGE_SIZE NativePageSize
  152. #define NATIVE_PAGE_SHIFT NativePageShift
  153. #define NATIVE_BYTES_TO_PAGES(Size) ((ULONG)((ULONG_PTR)(Size) >> NATIVE_PAGE_SHIFT) + \
  154. (((ULONG)(Size) & (NATIVE_PAGE_SIZE - 1)) != 0))
  155. #else
  156. #define NATIVE_PAGE_SIZE PAGE_SIZE
  157. #define NATIVE_PAGE_SHIFT PAGE_SHIFT
  158. #define NATIVE_BYTES_TO_PAGES(Size) BYTES_TO_PAGES(Size)
  159. #endif
  160. #if defined(_WIN64) || defined(BUILD_WOW6432)
  161. extern ULONG NativePageSize;
  162. extern ULONG NativePageShift;
  163. #endif
  164. VOID
  165. RtlpWaitForCriticalSection (
  166. IN PRTL_CRITICAL_SECTION CriticalSection
  167. );
  168. VOID
  169. RtlpUnWaitCriticalSection (
  170. IN PRTL_CRITICAL_SECTION CriticalSection
  171. );
  172. #define LDRP_HASH_TABLE_SIZE 32
  173. #define LDRP_HASH_MASK (LDRP_HASH_TABLE_SIZE-1)
  174. #define LDRP_COMPUTE_HASH_INDEX(wch) ( (RtlUpcaseUnicodeChar((wch)) - (WCHAR)'A') & LDRP_HASH_MASK )
  175. extern LIST_ENTRY LdrpHashTable[LDRP_HASH_TABLE_SIZE];
  176. // LDRP_BAD_DLL Sundown: sign-extended value.
  177. #define LDRP_BAD_DLL LongToPtr(0xffbadd11)
  178. extern LIST_ENTRY LdrpDefaultPathCache;
  179. typedef struct _LDRP_PATH_CACHE {
  180. LIST_ENTRY Links;
  181. UNICODE_STRING Component;
  182. HANDLE Directory;
  183. } LDRP_PATH_CACHE, *PLDRP_PATH_CACHE;
  184. NTSTATUS
  185. LdrpSnapIAT(
  186. IN PLDR_DATA_TABLE_ENTRY LdrDataTableEntry_Export,
  187. IN PLDR_DATA_TABLE_ENTRY LdrDataTableEntry_Import,
  188. IN PCIMAGE_IMPORT_DESCRIPTOR ImportDescriptor,
  189. IN BOOLEAN SnapForwardersOnly
  190. );
  191. NTSTATUS
  192. LdrpSnapThunk(
  193. IN PVOID DllBase,
  194. IN PVOID ImageBase,
  195. IN PIMAGE_THUNK_DATA OriginalThunk,
  196. IN OUT PIMAGE_THUNK_DATA Thunk,
  197. IN PCIMAGE_EXPORT_DIRECTORY ExportDirectory,
  198. IN ULONG ExportSize,
  199. IN BOOLEAN StaticSnap,
  200. IN PCSZ DllName OPTIONAL
  201. );
  202. USHORT
  203. LdrpNameToOrdinal(
  204. IN PCSZ Name,
  205. IN ULONG NumberOfNames,
  206. IN PVOID DllBase,
  207. IN PULONG NameTableBase,
  208. IN PUSHORT NameOrdinalTableBase
  209. );
  210. PLDR_DATA_TABLE_ENTRY
  211. LdrpAllocateDataTableEntry (
  212. IN PVOID DllBase
  213. );
  214. __forceinline
  215. VOID
  216. LdrpDeallocateDataTableEntry (
  217. IN PLDR_DATA_TABLE_ENTRY Entry
  218. )
  219. {
  220. ASSERT (Entry != NULL);
  221. RtlFreeHeap (LdrpHeap, 0, Entry);
  222. }
  223. VOID
  224. LdrpFinalizeAndDeallocateDataTableEntry (
  225. IN PLDR_DATA_TABLE_ENTRY Entry
  226. );
  227. BOOLEAN
  228. LdrpCheckForLoadedDll(
  229. IN PCWSTR DllPath OPTIONAL,
  230. IN PCUNICODE_STRING DllName,
  231. IN BOOLEAN StaticLink,
  232. IN BOOLEAN Redirected,
  233. OUT PLDR_DATA_TABLE_ENTRY *LdrDataTableEntry
  234. );
  235. BOOLEAN
  236. LdrpCheckForLoadedDllHandle(
  237. IN PVOID DllHandle,
  238. OUT PLDR_DATA_TABLE_ENTRY *LdrDataTableEntry
  239. );
  240. NTSTATUS
  241. LdrpMapDll(
  242. IN PCWSTR DllPath OPTIONAL,
  243. IN PCWSTR DllName,
  244. IN PULONG DllCharacteristics OPTIONAL,
  245. IN BOOLEAN StaticLink,
  246. IN BOOLEAN Redirected,
  247. OUT PLDR_DATA_TABLE_ENTRY *LdrDataTableEntry
  248. );
  249. NTSTATUS
  250. LdrpWalkImportDescriptor(
  251. IN PCWSTR DllPath OPTIONAL,
  252. IN PLDR_DATA_TABLE_ENTRY LdrDataTableEntry
  253. );
  254. NTSTATUS
  255. LdrpRunInitializeRoutines(
  256. IN PCONTEXT Context OPTIONAL
  257. );
  258. int
  259. LdrpInitializeProcessWrapperFilter(
  260. IN const struct _EXCEPTION_POINTERS *ExceptionPointers
  261. );
  262. int
  263. LdrpGenericExceptionFilter(
  264. IN const struct _EXCEPTION_POINTERS *ExceptionPointers,
  265. IN PCSZ FunctionName
  266. );
  267. //
  268. // ISSUE-2000/11/20-mgrier
  269. // These functions are VOID because they should really never be able to fail.
  270. //
  271. // In the current implementation, they do perform ANSI -> UNICODE conversions
  272. // which may fail in the current code page (may have been changed since when
  273. // the DLL was loaded) and apply Fusion DLL redirection to DLLs which can
  274. // require a large filename buffer than is allocated on the stack.
  275. //
  276. // These cases are ignored for now. Both problems should be fixed by
  277. // reworking the LDR_DATA_TABLE_ENTRY to have an array of pointers to the
  278. // downstream LDR_DATA_TABLE_ENTRY structs and not have to do any work
  279. // later on, but that's a lot of work for now; the ANSI -> UNICODE thing
  280. // has been there for ages and in practice, the paths that Fusion
  281. // redirects to have to fix in DOS_MAX_PATH_LENGTH, so we'll emit some
  282. // debug spew in the failure case, but ignore the failures.
  283. //
  284. // I started both fixes (returning status or allocating the array
  285. // at dll load time) but neither are trivial. Returning a status will just
  286. // make FreeLibrary() fail and leave the refcounts of the DLLs after the
  287. // one that failed inconsistent. Allocating the array is nontrivial
  288. // to do it the right way where the LDR_DATA_TABLE_ENTRY and the array
  289. // are allocated in a single allocation, and having the loader make more
  290. // even heap allocations seems like the wrong thing to do.
  291. //
  292. /*
  293. VOID
  294. LdrpReferenceLoadedDll(
  295. IN PLDR_DATA_TABLE_ENTRY LdrDataTableEntry
  296. );
  297. VOID
  298. LdrpDereferenceLoadedDll(
  299. IN PLDR_DATA_TABLE_ENTRY LdrDataTableEntry
  300. );
  301. VOID
  302. LdrpPinLoadedDll(
  303. IN PLDR_DATA_TABLE_ENTRY LdrDataTableEntry
  304. );
  305. */
  306. #define LdrpReferenceLoadedDll(LdrDataTableEntry) LdrpUpdateLoadCount2((LdrDataTableEntry), LDRP_UPDATE_LOAD_COUNT_INCREMENT)
  307. #define LdrpDereferenceLoadedDll(LdrDataTableEntry) LdrpUpdateLoadCount2((LdrDataTableEntry), LDRP_UPDATE_LOAD_COUNT_DECREMENT)
  308. #define LdrpPinLoadedDll(LdrDataTableEntry) LdrpUpdateLoadCount2((LdrDataTableEntry), LDRP_UPDATE_LOAD_COUNT_PIN)
  309. #define LDRP_UPDATE_LOAD_COUNT_INCREMENT (1)
  310. #define LDRP_UPDATE_LOAD_COUNT_DECREMENT (2)
  311. #define LDRP_UPDATE_LOAD_COUNT_PIN (3)
  312. VOID
  313. LdrpUpdateLoadCount3(
  314. IN PLDR_DATA_TABLE_ENTRY LdrDataTableEntry,
  315. IN ULONG UpdateCountHow,
  316. IN OUT PUNICODE_STRING PreAllocatedRedirectionBuffer OPTIONAL
  317. );
  318. VOID
  319. LdrpUpdateLoadCount2(
  320. IN PLDR_DATA_TABLE_ENTRY LdrDataTableEntry,
  321. IN ULONG UpdateCountHow
  322. );
  323. NTSTATUS
  324. LdrpInitializeProcess(
  325. IN PCONTEXT Context OPTIONAL,
  326. IN PVOID SystemDllBase
  327. );
  328. VOID
  329. LdrpInitialize(
  330. IN PCONTEXT Context,
  331. IN PVOID SystemArgument1,
  332. IN PVOID SystemArgument2
  333. );
  334. VOID
  335. LdrpInsertMemoryTableEntry(
  336. IN PLDR_DATA_TABLE_ENTRY LdrDataTableEntry
  337. );
  338. NTSTATUS
  339. LdrpResolveDllName(
  340. IN PCWSTR DllPath OPTIONAL,
  341. IN PCWSTR DllName,
  342. IN BOOLEAN Redirected,
  343. OUT PUNICODE_STRING FullDllName,
  344. OUT PUNICODE_STRING BaseDllName,
  345. OUT PHANDLE DllFile
  346. );
  347. NTSTATUS
  348. LdrpResolveDllNameForAppPrivateRedirection(
  349. IN PCUNICODE_STRING DllName,
  350. OUT PUNICODE_STRING FullDllName
  351. );
  352. NTSTATUS
  353. LdrpCreateDllSection(
  354. IN PCUNICODE_STRING FullDllName,
  355. IN HANDLE DllFile,
  356. IN PULONG DllCharacteristics OPTIONAL,
  357. OUT PHANDLE SectionHandle
  358. );
  359. VOID
  360. LdrpInitializePathCache(
  361. VOID
  362. );
  363. PVOID
  364. LdrpFetchAddressOfEntryPoint(
  365. IN PVOID Base
  366. );
  367. NTSTATUS
  368. LdrpCheckForKnownDll(
  369. IN PCWSTR DllName,
  370. OUT PUNICODE_STRING FullDllName,
  371. OUT PUNICODE_STRING BaseDllName,
  372. OUT HANDLE *Section
  373. );
  374. NTSTATUS
  375. LdrpSetProtection (
  376. IN PVOID Base,
  377. IN BOOLEAN Reset
  378. );
  379. #if DBG
  380. extern ULONG LdrpCompareCount;
  381. extern ULONG LdrpSnapBypass;
  382. extern ULONG LdrpNormalSnap;
  383. extern ULONG LdrpSectionOpens;
  384. extern ULONG LdrpSectionCreates;
  385. extern ULONG LdrpSectionMaps;
  386. extern ULONG LdrpSectionRelocates;
  387. extern BOOLEAN LdrpDisplayLoadTime;
  388. extern LARGE_INTEGER BeginTime, InitcTime, InitbTime, IniteTime, EndTime, ElapsedTime, Interval;
  389. #endif // DBG
  390. extern BOOLEAN ShowSnaps;
  391. extern BOOLEAN ShowErrors;
  392. extern BOOLEAN RtlpTimoutDisable;
  393. extern LARGE_INTEGER RtlpTimeout;
  394. extern ULONG NtGlobalFlag;
  395. extern LIST_ENTRY RtlCriticalSectionList;
  396. extern RTL_CRITICAL_SECTION RtlCriticalSectionLock;
  397. extern BOOLEAN LdrpShutdownInProgress;
  398. extern BOOLEAN LdrpInLdrInit;
  399. extern BOOLEAN LdrpLdrDatabaseIsSetup;
  400. extern BOOLEAN LdrpVerifyDlls;
  401. extern BOOLEAN LdrpShutdownInProgress;
  402. extern BOOLEAN LdrpImageHasTls;
  403. extern PLDR_DATA_TABLE_ENTRY LdrpImageEntry;
  404. extern LIST_ENTRY LdrpUnloadHead;
  405. extern BOOLEAN LdrpActiveUnloadCount;
  406. extern PLDR_DATA_TABLE_ENTRY LdrpGetModuleHandleCache;
  407. extern PLDR_DATA_TABLE_ENTRY LdrpLoadedDllHandleCache;
  408. extern ULONG LdrpFatalHardErrorCount;
  409. extern UNICODE_STRING LdrpDefaultPath;
  410. extern RTL_CRITICAL_SECTION FastPebLock;
  411. extern HANDLE LdrpShutdownThreadId;
  412. extern ULONG LdrpNumberOfProcessors;
  413. extern UNICODE_STRING DefaultExtension;
  414. extern UNICODE_STRING User32String;
  415. extern UNICODE_STRING Kernel32String;
  416. typedef struct _LDRP_TLS_ENTRY {
  417. LIST_ENTRY Links;
  418. IMAGE_TLS_DIRECTORY Tls;
  419. } LDRP_TLS_ENTRY, *PLDRP_TLS_ENTRY;
  420. extern LIST_ENTRY LdrpTlsList;
  421. extern ULONG LdrpNumberOfTlsEntries;
  422. NTSTATUS
  423. LdrpInitializeTls(
  424. VOID
  425. );
  426. NTSTATUS
  427. LdrpAllocateTls(
  428. VOID
  429. );
  430. VOID
  431. LdrpFreeTls(
  432. VOID
  433. );
  434. VOID
  435. LdrpCallTlsInitializers(
  436. PVOID DllBase,
  437. ULONG Reason
  438. );
  439. NTSTATUS
  440. LdrpAllocateUnicodeString(
  441. OUT PUNICODE_STRING StringOut,
  442. IN USHORT Length
  443. );
  444. NTSTATUS
  445. LdrpCopyUnicodeString(
  446. OUT PUNICODE_STRING StringOut,
  447. IN PCUNICODE_STRING StringIn
  448. );
  449. VOID
  450. LdrpFreeUnicodeString(
  451. IN OUT PUNICODE_STRING String
  452. );
  453. VOID
  454. LdrpEnsureLoaderLockIsHeld(
  455. VOID
  456. );
  457. #define LDRP_LOAD_DLL_FLAG_DLL_IS_REDIRECTED (0x00000001)
  458. NTSTATUS
  459. LdrpLoadDll(
  460. IN ULONG Flags OPTIONAL,
  461. IN PCWSTR DllPath OPTIONAL,
  462. IN PULONG DllCharacteristics OPTIONAL,
  463. IN PCUNICODE_STRING DllName,
  464. OUT PVOID *DllHandle,
  465. IN BOOLEAN RunInitRoutines
  466. );
  467. NTSTATUS
  468. NTAPI
  469. LdrpGetProcedureAddress(
  470. IN PVOID DllHandle,
  471. IN CONST ANSI_STRING* ProcedureName OPTIONAL,
  472. IN ULONG ProcedureNumber OPTIONAL,
  473. OUT PVOID *ProcedureAddress,
  474. IN BOOLEAN RunInitRoutines
  475. );
  476. PLIST_ENTRY
  477. RtlpLockProcessHeapsList( VOID );
  478. VOID
  479. RtlpUnlockProcessHeapsList( VOID );
  480. BOOLEAN
  481. RtlpSerializeHeap(
  482. IN PVOID HeapHandle
  483. );
  484. ULONG NtdllBaseTag;
  485. #define MAKE_TAG( t ) (RTL_HEAP_MAKE_TAG( NtdllBaseTag, (t) ))
  486. #define CSR_TAG 0
  487. #define LDR_TAG 1
  488. #define CURDIR_TAG 2
  489. #define TLS_TAG 3
  490. #define DBG_TAG 4
  491. #define SE_TAG 5
  492. #define TEMP_TAG 6
  493. #define ATOM_TAG 7
  494. PVOID
  495. LdrpDefineDllTag(
  496. PWSTR TagName,
  497. PUSHORT TagIndex
  498. );
  499. #define LDRP_ACTIVATE_ACTIVATION_CONTEXT(LdrpDllActivateActivationContext_TableEntry) \
  500. { \
  501. RTL_CALLER_ALLOCATED_ACTIVATION_CONTEXT_STACK_FRAME LdrpDllActivateActivationContext_ActivationFrame = \
  502. { sizeof(LdrpDllActivateActivationContext_ActivationFrame), \
  503. RTL_CALLER_ALLOCATED_ACTIVATION_CONTEXT_STACK_FRAME_FORMAT_WHISTLER \
  504. }; \
  505. \
  506. RtlActivateActivationContextUnsafeFast(&LdrpDllActivateActivationContext_ActivationFrame, (LdrpDllActivateActivationContext_TableEntry)->EntryPointActivationContext); \
  507. __try {
  508. #define LDRP_DEACTIVATE_ACTIVATION_CONTEXT() \
  509. } __finally { \
  510. RtlDeactivateActivationContextUnsafeFast(&LdrpDllActivateActivationContext_ActivationFrame); \
  511. } \
  512. }
  513. #if defined(_X86_)
  514. BOOLEAN
  515. LdrpCallInitRoutine(
  516. IN PDLL_INIT_ROUTINE InitRoutine,
  517. IN PVOID DllHandle,
  518. IN ULONG Reason,
  519. IN PCONTEXT Context OPTIONAL
  520. );
  521. #else
  522. #define LdrpCallInitRoutine(InitRoutine, DllHandle, Reason, Context) \
  523. (InitRoutine)((DllHandle), (Reason), (Context))
  524. #endif
  525. NTSTATUS
  526. LdrpCorValidateImage(
  527. IN OUT PVOID *pImageBase,
  528. IN LPWSTR ImageName
  529. );
  530. VOID
  531. LdrpCorUnloadImage(
  532. IN PVOID ImageBase
  533. );
  534. VOID
  535. LdrpCorReplaceStartContext(
  536. IN PCONTEXT Context
  537. );
  538. typedef VOID (*PCOR_EXE_MAIN)(VOID);
  539. extern PCOR_EXE_MAIN CorExeMain;
  540. VOID
  541. LdrpSendDllNotifications (
  542. IN PLDR_DATA_TABLE_ENTRY Entry,
  543. IN ULONG NotificationType,
  544. IN ULONG Flags
  545. );
  546. //
  547. // The prototypes for the shim engine callback
  548. //
  549. typedef void (*PFNSE_INSTALLBEFOREINIT)(PUNICODE_STRING UnicodeImageName,
  550. PVOID pShimExeData);
  551. typedef BOOLEAN (*PFNSE_INSTALLAFTERINIT)(PUNICODE_STRING UnicodeImageName,
  552. PVOID pShimExeData);
  553. typedef void (*PFNSE_DLLLOADED)(PLDR_DATA_TABLE_ENTRY LdrEntry);
  554. typedef void (*PFNSE_DLLUNLOADED)(PLDR_DATA_TABLE_ENTRY LdrEntry);
  555. typedef void (*PFNSE_GETPROCADDRESS)(PVOID* pProcAddress);
  556. typedef int (*PFNSE_ISSHIMDLL)(PVOID pDllBase);
  557. typedef void (*PFNSE_PROCESSDYING)(void);
  558. //
  559. // Private function from ntos\rtl\stktrace.c needed to pickup the real address
  560. // of a stack trace given an index.
  561. //
  562. PVOID
  563. RtlpGetStackTraceAddress (
  564. USHORT Index
  565. );
  566. //
  567. // Function defined in ntos\rtl\stktrace.c needed to speedup
  568. // RtlCaptureStackContext on x86.
  569. //
  570. VOID
  571. RtlpStkMarkDllRange (
  572. PLDR_DATA_TABLE_ENTRY DllEntry
  573. );
  574. //
  575. // resource.c
  576. //
  577. extern BOOLEAN RtlpCriticalSectionVerifier;
  578. BOOLEAN
  579. RtlpCreateCriticalSectionSem(
  580. IN PRTL_CRITICAL_SECTION CriticalSection
  581. );
  582. //
  583. // Application verifier
  584. //
  585. #include "avrfp.h"
  586. //
  587. // Hot-patching
  588. //
  589. #include "hotpatch.h"
  590. NTSTATUS
  591. LdrpRundownHotpatchList(
  592. PRTL_PATCH_HEADER PatchHead
  593. );
  594. typedef NTSTATUS (NTAPI * PKERNEL32_PROCESS_INIT_POST_IMPORT_FUNCTION)(VOID);
  595. extern PKERNEL32_PROCESS_INIT_POST_IMPORT_FUNCTION Kernel32ProcessInitPostImportFunction;
  596. #endif // _LDRP_