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.

836 lines
20 KiB

  1. /*++ BUILD Version: 0004 // Increment this if a change has global effects
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. ntldr.h
  5. Abstract:
  6. This module implements the public interfaces of the Loader (Ldr)
  7. subsystem. Ldr is coupled with the session manager. It is not
  8. a separate process.
  9. Author:
  10. Mike O'Leary (mikeol) 22-Mar-1990
  11. [Environment:]
  12. optional-environment-info (e.g. kernel mode only...)
  13. [Notes:]
  14. optional-notes
  15. Revision History:
  16. --*/
  17. #ifndef _NTLDRAPI_
  18. #define _NTLDRAPI_
  19. #if _MSC_VER > 1000
  20. #pragma once
  21. #endif
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. //
  26. // Private flags for loader data table entries
  27. //
  28. #define LDRP_STATIC_LINK 0x00000002
  29. #define LDRP_IMAGE_DLL 0x00000004
  30. #define LDRP_LOAD_IN_PROGRESS 0x00001000
  31. #define LDRP_UNLOAD_IN_PROGRESS 0x00002000
  32. #define LDRP_ENTRY_PROCESSED 0x00004000
  33. #define LDRP_ENTRY_INSERTED 0x00008000
  34. #define LDRP_CURRENT_LOAD 0x00010000
  35. #define LDRP_FAILED_BUILTIN_LOAD 0x00020000
  36. #define LDRP_DONT_CALL_FOR_THREADS 0x00040000
  37. #define LDRP_PROCESS_ATTACH_CALLED 0x00080000
  38. #define LDRP_DEBUG_SYMBOLS_LOADED 0x00100000
  39. #define LDRP_IMAGE_NOT_AT_BASE 0x00200000
  40. #define LDRP_COR_IMAGE 0x00400000
  41. #define LDRP_COR_OWNS_UNMAP 0x00800000
  42. #define LDRP_SYSTEM_MAPPED 0x01000000
  43. #define LDRP_IMAGE_VERIFYING 0x02000000
  44. #define LDRP_DRIVER_DEPENDENT_DLL 0x04000000
  45. #define LDRP_ENTRY_NATIVE 0x08000000
  46. #define LDRP_REDIRECTED 0x10000000
  47. #define LDRP_NON_PAGED_DEBUG_INFO 0x20000000
  48. #define LDRP_MM_LOADED 0x40000000
  49. //
  50. // Loader Data Table. Used to track DLLs loaded into an
  51. // image.
  52. //
  53. typedef struct _LDR_DATA_TABLE_ENTRY {
  54. LIST_ENTRY InLoadOrderLinks;
  55. LIST_ENTRY InMemoryOrderLinks;
  56. LIST_ENTRY InInitializationOrderLinks;
  57. PVOID DllBase;
  58. PVOID EntryPoint;
  59. ULONG SizeOfImage;
  60. UNICODE_STRING FullDllName;
  61. UNICODE_STRING BaseDllName;
  62. ULONG Flags;
  63. USHORT LoadCount;
  64. USHORT TlsIndex;
  65. union {
  66. LIST_ENTRY HashLinks;
  67. struct {
  68. PVOID SectionPointer;
  69. ULONG CheckSum;
  70. };
  71. };
  72. union {
  73. struct {
  74. ULONG TimeDateStamp;
  75. };
  76. struct {
  77. PVOID LoadedImports;
  78. };
  79. };
  80. struct _ACTIVATION_CONTEXT * EntryPointActivationContext;
  81. PVOID PatchInformation;
  82. } LDR_DATA_TABLE_ENTRY, *PLDR_DATA_TABLE_ENTRY;
  83. typedef const struct _LDR_DATA_TABLE_ENTRY *PCLDR_DATA_TABLE_ENTRY;
  84. typedef struct _KLDR_DATA_TABLE_ENTRY {
  85. LIST_ENTRY InLoadOrderLinks;
  86. PVOID ExceptionTable;
  87. ULONG ExceptionTableSize;
  88. // ULONG padding on IA64
  89. PVOID GpValue;
  90. PNON_PAGED_DEBUG_INFO NonPagedDebugInfo;
  91. PVOID DllBase;
  92. PVOID EntryPoint;
  93. ULONG SizeOfImage;
  94. UNICODE_STRING FullDllName;
  95. UNICODE_STRING BaseDllName;
  96. ULONG Flags;
  97. USHORT LoadCount;
  98. USHORT __Unused5;
  99. PVOID SectionPointer;
  100. ULONG CheckSum;
  101. // ULONG padding on IA64
  102. PVOID LoadedImports;
  103. PVOID PatchInformation;
  104. } KLDR_DATA_TABLE_ENTRY, *PKLDR_DATA_TABLE_ENTRY;
  105. typedef struct _LDR_DATA_TABLE_ENTRY32 {
  106. LIST_ENTRY32 InLoadOrderLinks;
  107. LIST_ENTRY32 InMemoryOrderLinks;
  108. LIST_ENTRY32 InInitializationOrderLinks;
  109. ULONG DllBase;
  110. ULONG EntryPoint;
  111. ULONG SizeOfImage;
  112. UNICODE_STRING32 FullDllName;
  113. UNICODE_STRING32 BaseDllName;
  114. ULONG Flags;
  115. USHORT LoadCount;
  116. USHORT TlsIndex;
  117. union {
  118. LIST_ENTRY32 HashLinks;
  119. struct {
  120. ULONG SectionPointer;
  121. ULONG CheckSum;
  122. };
  123. };
  124. union {
  125. struct {
  126. ULONG TimeDateStamp;
  127. };
  128. struct {
  129. ULONG LoadedImports;
  130. };
  131. };
  132. //
  133. // NOTE : Do not grow this structure at the dump files used a packed
  134. // array of these structures.
  135. //
  136. } LDR_DATA_TABLE_ENTRY32, *PLDR_DATA_TABLE_ENTRY32;
  137. typedef struct _LDR_DATA_TABLE_ENTRY64 {
  138. LIST_ENTRY64 InLoadOrderLinks;
  139. LIST_ENTRY64 InMemoryOrderLinks;
  140. LIST_ENTRY64 InInitializationOrderLinks;
  141. ULONG64 DllBase;
  142. ULONG64 EntryPoint;
  143. ULONG SizeOfImage;
  144. UNICODE_STRING64 FullDllName;
  145. UNICODE_STRING64 BaseDllName;
  146. ULONG Flags;
  147. USHORT LoadCount;
  148. USHORT TlsIndex;
  149. union {
  150. LIST_ENTRY64 HashLinks;
  151. struct {
  152. ULONG64 SectionPointer;
  153. ULONG CheckSum;
  154. };
  155. };
  156. union {
  157. struct {
  158. ULONG TimeDateStamp;
  159. };
  160. struct {
  161. ULONG64 LoadedImports;
  162. };
  163. };
  164. //
  165. // NOTE : Do not grow this structure at the dump files used a packed
  166. // array of these structures.
  167. //
  168. } LDR_DATA_TABLE_ENTRY64, *PLDR_DATA_TABLE_ENTRY64;
  169. typedef struct _KLDR_DATA_TABLE_ENTRY32 {
  170. LIST_ENTRY32 InLoadOrderLinks;
  171. ULONG __Undefined1;
  172. ULONG __Undefined2;
  173. ULONG __Undefined3;
  174. ULONG NonPagedDebugInfo;
  175. ULONG DllBase;
  176. ULONG EntryPoint;
  177. ULONG SizeOfImage;
  178. UNICODE_STRING32 FullDllName;
  179. UNICODE_STRING32 BaseDllName;
  180. ULONG Flags;
  181. USHORT LoadCount;
  182. USHORT __Undefined5;
  183. ULONG __Undefined6;
  184. ULONG CheckSum;
  185. ULONG TimeDateStamp;
  186. //
  187. // NOTE : Do not grow this structure at the dump files used a packed
  188. // array of these structures.
  189. //
  190. } KLDR_DATA_TABLE_ENTRY32, *PKLDR_DATA_TABLE_ENTRY32;
  191. typedef struct _KLDR_DATA_TABLE_ENTRY64 {
  192. LIST_ENTRY64 InLoadOrderLinks;
  193. ULONG64 __Undefined1;
  194. ULONG64 __Undefined2;
  195. ULONG64 __Undefined3;
  196. ULONG64 NonPagedDebugInfo;
  197. ULONG64 DllBase;
  198. ULONG64 EntryPoint;
  199. ULONG SizeOfImage;
  200. UNICODE_STRING64 FullDllName;
  201. UNICODE_STRING64 BaseDllName;
  202. ULONG Flags;
  203. USHORT LoadCount;
  204. USHORT __Undefined5;
  205. ULONG64 __Undefined6;
  206. ULONG CheckSum;
  207. ULONG __padding1;
  208. ULONG TimeDateStamp;
  209. ULONG __padding2;
  210. //
  211. // NOTE : Do not grow this structure at the dump files used a packed
  212. // array of these structures.
  213. //
  214. } KLDR_DATA_TABLE_ENTRY64, *PKLDR_DATA_TABLE_ENTRY64;
  215. #define DLL_PROCESS_ATTACH 1 // winnt
  216. #define DLL_THREAD_ATTACH 2 // winnt
  217. #define DLL_THREAD_DETACH 3 // winnt
  218. #define DLL_PROCESS_DETACH 0 // winnt
  219. #define DLL_PROCESS_VERIFIER 4 // winnt
  220. typedef
  221. BOOLEAN
  222. (*PDLL_INIT_ROUTINE) (
  223. IN PVOID DllHandle,
  224. IN ULONG Reason,
  225. IN PCONTEXT Context OPTIONAL
  226. );
  227. typedef
  228. BOOLEAN
  229. (*PPROCESS_STARTER_ROUTINE) (
  230. IN PVOID RealStartAddress
  231. );
  232. VOID
  233. LdrProcessStarterHelper(
  234. IN PPROCESS_STARTER_ROUTINE ProcessStarter,
  235. IN PVOID RealStartAddress
  236. );
  237. VOID
  238. NTAPI
  239. LdrShutdownProcess(
  240. VOID
  241. );
  242. VOID
  243. NTAPI
  244. LdrShutdownThread(
  245. VOID
  246. );
  247. NTSTATUS
  248. NTAPI
  249. LdrLoadDll(
  250. IN PCWSTR DllPath OPTIONAL,
  251. IN PULONG DllCharacteristics OPTIONAL,
  252. IN PCUNICODE_STRING DllName,
  253. OUT PVOID *DllHandle
  254. );
  255. NTSTATUS
  256. NTAPI
  257. LdrGetDllHandle(
  258. IN PCWSTR DllPath OPTIONAL,
  259. IN PULONG DllCharacteristics OPTIONAL,
  260. IN PCUNICODE_STRING DllName,
  261. OUT PVOID *DllHandle
  262. );
  263. NTSTATUS
  264. NTAPI
  265. LdrUnloadDll(
  266. IN PVOID DllHandle
  267. );
  268. typedef
  269. NTSTATUS
  270. (NTAPI * PLDR_MANIFEST_PROBER_ROUTINE) (
  271. IN PVOID DllBase,
  272. IN PCWSTR FullDllPath,
  273. OUT PVOID *ActivationContext
  274. );
  275. VOID
  276. NTAPI
  277. LdrSetDllManifestProber(
  278. IN PLDR_MANIFEST_PROBER_ROUTINE ManifestProberRoutine
  279. );
  280. #if defined(BLDR_KERNEL_RUNTIME)
  281. typedef ULONG ARC_STATUS;
  282. typedef ARC_STATUS LDR_RELOCATE_IMAGE_RETURN_TYPE;
  283. #else
  284. typedef NTSTATUS LDR_RELOCATE_IMAGE_RETURN_TYPE;
  285. #endif
  286. LDR_RELOCATE_IMAGE_RETURN_TYPE
  287. LdrRelocateImage (
  288. IN PVOID NewBase,
  289. IN CONST CHAR* LoaderName,
  290. IN LDR_RELOCATE_IMAGE_RETURN_TYPE Success,
  291. IN LDR_RELOCATE_IMAGE_RETURN_TYPE Conflict,
  292. IN LDR_RELOCATE_IMAGE_RETURN_TYPE Invalid
  293. );
  294. #if defined(NTOS_KERNEL_RUNTIME) && defined(_ALPHA_)
  295. NTSTATUS
  296. LdrDoubleRelocateImage (
  297. IN PVOID NewBase,
  298. IN PVOID CurrentBase,
  299. IN CONST CHAR* LoaderName,
  300. IN NTSTATUS Success,
  301. IN NTSTATUS Conflict,
  302. IN NTSTATUS Invalid
  303. );
  304. #endif
  305. LDR_RELOCATE_IMAGE_RETURN_TYPE
  306. LdrRelocateImageWithBias (
  307. IN PVOID NewBase,
  308. IN LONGLONG Bias,
  309. IN CONST CHAR* LoaderName,
  310. IN LDR_RELOCATE_IMAGE_RETURN_TYPE Success,
  311. IN LDR_RELOCATE_IMAGE_RETURN_TYPE Conflict,
  312. IN LDR_RELOCATE_IMAGE_RETURN_TYPE Invalid
  313. );
  314. PIMAGE_BASE_RELOCATION
  315. NTAPI
  316. LdrProcessRelocationBlock(
  317. IN ULONG_PTR VA,
  318. IN ULONG SizeOfBlock,
  319. IN PUSHORT NextOffset,
  320. IN LONG_PTR Diff
  321. );
  322. BOOLEAN
  323. NTAPI
  324. LdrVerifyMappedImageMatchesChecksum (
  325. IN PVOID BaseAddress,
  326. IN ULONG FileLength
  327. );
  328. typedef
  329. VOID
  330. (*PLDR_IMPORT_MODULE_CALLBACK)(
  331. IN PVOID Parameter,
  332. PCHAR ModuleName
  333. );
  334. NTSTATUS
  335. NTAPI
  336. LdrVerifyImageMatchesChecksum (
  337. IN HANDLE ImageFileHandle,
  338. IN PLDR_IMPORT_MODULE_CALLBACK ImportCallbackRoutine OPTIONAL,
  339. IN PVOID ImportCallbackParameter,
  340. OUT PUSHORT ImageCharacteristics OPTIONAL
  341. );
  342. NTSTATUS
  343. NTAPI
  344. LdrGetProcedureAddress(
  345. IN PVOID DllHandle,
  346. IN CONST ANSI_STRING* ProcedureName OPTIONAL,
  347. IN ULONG ProcedureNumber OPTIONAL,
  348. OUT PVOID *ProcedureAddress
  349. );
  350. #define LDR_RESOURCE_ID_NAME_MASK ((~(ULONG_PTR)0) << 16) /* lower 16bits clear */
  351. #define LDR_RESOURCE_ID_NAME_MINVAL (( (ULONG_PTR)1) << 16) /* 17th bit set */
  352. //
  353. // These are how you currently pass the flag to FindResource.
  354. //
  355. // VIEW_TO_DATAFILE and DATAFILE_TO_VIEW are idempotent,
  356. // so you can covert a datafile to a datafile with VIEW_TO_DATAFILE.
  357. // Think of better names therefore..
  358. //
  359. #define LDR_VIEW_TO_DATAFILE(x) ((PVOID)(((ULONG_PTR)(x)) | (ULONG_PTR)1))
  360. #define LDR_IS_DATAFILE(x) (((ULONG_PTR)(x)) & (ULONG_PTR)1)
  361. #define LDR_IS_VIEW(x) (!LDR_IS_DATAFILE(x))
  362. #define LDR_DATAFILE_TO_VIEW(x) ((PVOID)(((ULONG_PTR)(x)) & ~(ULONG_PTR)1))
  363. //
  364. // These functions work on ULONG, ULONG_PTR, ULONG64, etc.
  365. // They do not work on pointers.
  366. //
  367. #define LDR_VIEW_TO_DATAFILE_INTEGER(x) ((x) | 1)
  368. #define LDR_IS_DATAFILE_INTEGER(x) (((x) & 1) == 1)
  369. #define LDR_IS_VIEW_INTEGER(x) (((x) & 1) == 0)
  370. #define LDR_DATAFILE_TO_VIEW_INTEGER(x) ((x) - ((x) & 1))
  371. //
  372. // Flags to LdrCreateOutOfProcessImage.
  373. //
  374. // These first two values must not share any bits, even though this is an enum,
  375. // because LDR_DLL_MAPPED_AS_UNREFORMATED_IMAGE is actually changed to one of them
  376. // and then it is treated as bits.
  377. #define LDR_DLL_MAPPED_AS_IMAGE (0x00000001)
  378. #define LDR_DLL_MAPPED_AS_DATA (0x00000002)
  379. #define LDR_DLL_MAPPED_AS_UNFORMATED_IMAGE (0x00000003)
  380. #define LDR_DLL_MAPPED_AS_MASK (0x00000003)
  381. //
  382. // These are flags to a function that doesn't yet exist:
  383. // LdrpSearchResourceSectionEx and/or LdrpSearchOutOfProcessResourceSection
  384. //
  385. #define LDRP_FIND_RESOURCE_DATA (0x00000000)
  386. #define LDRP_FIND_RESOURCE_DIRECTORY (0x00000002)
  387. //
  388. // Flags to LdrFindResourceEx/LdrpSearchResourceSection/LdrFindOutOfProcessResource.
  389. //
  390. #define LDR_FIND_RESOURCE_LANGUAGE_CAN_FALLBACK (0x00000000)
  391. #define LDR_FIND_RESOURCE_LANGUAGE_EXACT (0x00000004)
  392. #define LDR_FIND_RESOURCE_LANGUAGE_REDIRECT_VERSION (0x00000008)
  393. NTSTATUS
  394. NTAPI
  395. LdrFindResourceDirectory_U(
  396. IN PVOID DllHandle,
  397. IN CONST ULONG_PTR* ResourceIdPath,
  398. IN ULONG ResourceIdPathLength,
  399. OUT PIMAGE_RESOURCE_DIRECTORY *ResourceDirectory
  400. );
  401. NTSTATUS
  402. NTAPI
  403. LdrFindResource_U(
  404. IN PVOID DllHandle,
  405. IN CONST ULONG_PTR* ResourceIdPath,
  406. IN ULONG ResourceIdPathLength,
  407. OUT PIMAGE_RESOURCE_DATA_ENTRY *ResourceDataEntry
  408. );
  409. NTSTATUS
  410. NTAPI
  411. LdrFindResourceEx_U(
  412. ULONG Flags,
  413. IN PVOID DllHandle,
  414. IN CONST ULONG_PTR* ResourceIdPath,
  415. IN ULONG ResourceIdPathLength,
  416. OUT PIMAGE_RESOURCE_DATA_ENTRY *ResourceDataEntry
  417. );
  418. #ifndef NTOS_KERNEL_RUNTIME
  419. #if !defined(RTL_BUFFER)
  420. // This is duplicated in nturtl.h.
  421. #define RTL_BUFFER RTL_BUFFER
  422. typedef struct _RTL_BUFFER {
  423. PUCHAR Buffer;
  424. PUCHAR StaticBuffer;
  425. SIZE_T Size;
  426. SIZE_T StaticSize;
  427. SIZE_T ReservedForAllocatedSize; // for future doubling
  428. PVOID ReservedForIMalloc; // for future pluggable growth
  429. } RTL_BUFFER, *PRTL_BUFFER;
  430. #endif
  431. //
  432. // This will always contain the MS-DOS header,
  433. // File header, Optional header, and Section headers.
  434. //
  435. // If multiple fast resource loads are needed, we could
  436. // populate it on demand with resource directory stuff too.
  437. //
  438. // This struct is opaque.
  439. // Only access it with Ldr*OutOfProcess* functions.
  440. //
  441. typedef struct _LDR_OUT_OF_PROCESS_IMAGE {
  442. RTL_BUFFER HeadersBuffer;
  443. HANDLE ProcessHandle;
  444. ULONG64 DllHandle; // base of mapped section, not kernel handle
  445. ULONG Flags;
  446. } LDR_OUT_OF_PROCESS_IMAGE, *PLDR_OUT_OF_PROCESS_IMAGE;
  447. NTSTATUS
  448. NTAPI
  449. LdrCreateOutOfProcessImage(
  450. IN ULONG Flags,
  451. IN HANDLE ProcessHandle,
  452. IN ULONG64 DllHandle, // base of mapped section, not kernel handle
  453. OUT PLDR_OUT_OF_PROCESS_IMAGE Image
  454. );
  455. //
  456. // - You may destroy an out of process image that is all zeros.
  457. // - You may destroy an out of process image repeatedly.
  458. //
  459. VOID
  460. NTAPI
  461. LdrDestroyOutOfProcessImage(
  462. IN OUT PLDR_OUT_OF_PROCESS_IMAGE Image
  463. );
  464. NTSTATUS
  465. NTAPI
  466. LdrFindCreateProcessManifest(
  467. IN ULONG Flags,
  468. PLDR_OUT_OF_PROCESS_IMAGE Image,
  469. IN CONST ULONG_PTR* ResourceIdPath,
  470. IN ULONG ResourceIdPathLength,
  471. OUT PIMAGE_RESOURCE_DATA_ENTRY ResourceDataEntry
  472. );
  473. NTSTATUS
  474. NTAPI
  475. LdrAccessOutOfProcessResource(
  476. IN ULONG Flags,
  477. PLDR_OUT_OF_PROCESS_IMAGE Image,
  478. IN CONST IMAGE_RESOURCE_DATA_ENTRY* DataEntry,
  479. OUT PULONG64 Address OPTIONAL,
  480. OUT PULONG Size OPTIONAL
  481. );
  482. #endif
  483. // type, id/name, langid
  484. #define LDR_MAXIMUM_RESOURCE_PATH_DEPTH (3)
  485. typedef struct _LDR_ENUM_RESOURCE_ENTRY {
  486. union {
  487. ULONG_PTR NameOrId;
  488. PIMAGE_RESOURCE_DIRECTORY_STRING Name;
  489. struct {
  490. USHORT Id;
  491. USHORT NameIsPresent;
  492. };
  493. } Path[ LDR_MAXIMUM_RESOURCE_PATH_DEPTH ];
  494. PVOID Data;
  495. ULONG Size;
  496. ULONG Reserved;
  497. } LDR_ENUM_RESOURCE_ENTRY, *PLDR_ENUM_RESOURCE_ENTRY;
  498. NTSTATUS
  499. NTAPI
  500. LdrEnumResources(
  501. IN PVOID DllHandle,
  502. IN CONST ULONG_PTR* ResourceIdPath,
  503. IN ULONG ResourceIdPathLength,
  504. IN OUT PULONG NumberOfResources,
  505. OUT PLDR_ENUM_RESOURCE_ENTRY Resources OPTIONAL
  506. );
  507. NTSTATUS
  508. NTAPI
  509. LdrAccessResource(
  510. IN PVOID DllHandle,
  511. IN CONST IMAGE_RESOURCE_DATA_ENTRY* ResourceDataEntry,
  512. OUT PVOID *Address OPTIONAL,
  513. OUT PULONG Size OPTIONAL
  514. );
  515. NTSTATUS
  516. NTAPI
  517. LdrFindEntryForAddress(
  518. IN PVOID Address,
  519. OUT PLDR_DATA_TABLE_ENTRY *TableEntry
  520. );
  521. NTSTATUS
  522. NTAPI
  523. LdrDisableThreadCalloutsForDll (
  524. IN PVOID DllHandle
  525. );
  526. typedef struct _RTL_PROCESS_MODULE_INFORMATION {
  527. HANDLE Section; // Not filled in
  528. PVOID MappedBase;
  529. PVOID ImageBase;
  530. ULONG ImageSize;
  531. ULONG Flags;
  532. USHORT LoadOrderIndex;
  533. USHORT InitOrderIndex;
  534. USHORT LoadCount;
  535. USHORT OffsetToFileName;
  536. UCHAR FullPathName[ 256 ];
  537. } RTL_PROCESS_MODULE_INFORMATION, *PRTL_PROCESS_MODULE_INFORMATION;
  538. typedef struct _RTL_PROCESS_MODULES {
  539. ULONG NumberOfModules;
  540. RTL_PROCESS_MODULE_INFORMATION Modules[ 1 ];
  541. } RTL_PROCESS_MODULES, *PRTL_PROCESS_MODULES;
  542. NTSTATUS
  543. NTAPI
  544. LdrQueryProcessModuleInformation(
  545. OUT PRTL_PROCESS_MODULES ModuleInformation,
  546. IN ULONG ModuleInformationLength,
  547. OUT PULONG ReturnLength OPTIONAL
  548. );
  549. NTSTATUS
  550. NTAPI
  551. LdrQueryImageFileExecutionOptions(
  552. IN PCUNICODE_STRING ImagePathName,
  553. IN PCWSTR OptionName,
  554. IN ULONG Type,
  555. OUT PVOID Buffer,
  556. IN ULONG BufferSize,
  557. OUT PULONG ResultSize OPTIONAL
  558. );
  559. NTSTATUS
  560. LdrQueryImageFileExecutionOptionsEx(
  561. IN PCUNICODE_STRING ImagePathName,
  562. IN PCWSTR OptionName,
  563. IN ULONG Type,
  564. OUT PVOID Buffer,
  565. IN ULONG BufferSize,
  566. OUT PULONG ResultSize OPTIONAL,
  567. IN BOOLEAN Wow64Path
  568. );
  569. BOOLEAN
  570. NTAPI
  571. LdrAlternateResourcesEnabled(
  572. VOID
  573. );
  574. PVOID
  575. NTAPI
  576. LdrGetAlternateResourceModuleHandle(
  577. IN PVOID Module
  578. );
  579. PVOID
  580. NTAPI
  581. LdrLoadAlternateResourceModule(
  582. IN PVOID Module,
  583. IN LPCWSTR PathToAlternateModule OPTIONAL
  584. );
  585. BOOLEAN
  586. NTAPI
  587. LdrUnloadAlternateResourceModule(
  588. IN PVOID Module
  589. );
  590. BOOLEAN
  591. NTAPI
  592. LdrFlushAlternateResourceModules(
  593. VOID
  594. );
  595. #define LDR_DLL_LOADED_FLAG_RELOCATED (0x00000001)
  596. typedef struct _LDR_DLL_LOADED_NOTIFICATION_DATA {
  597. ULONG Flags;
  598. PCUNICODE_STRING FullDllName;
  599. PCUNICODE_STRING BaseDllName;
  600. PVOID DllBase;
  601. ULONG SizeOfImage;
  602. } LDR_DLL_LOADED_NOTIFICATION_DATA, *PLDR_DLL_LOADED_NOTIFICATION_DATA;
  603. typedef const LDR_DLL_LOADED_NOTIFICATION_DATA *PCLDR_DLL_LOADED_NOTIFICATION_DATA;
  604. #define LDR_DLL_UNLOADED_FLAG_PROCESS_TERMINATION (0x00000001)
  605. typedef struct _LDR_DLL_UNLOADED_NOTIFICATION_DATA {
  606. ULONG Flags;
  607. PCUNICODE_STRING FullDllName;
  608. PCUNICODE_STRING BaseDllName;
  609. PVOID DllBase;
  610. ULONG SizeOfImage;
  611. } LDR_DLL_UNLOADED_NOTIFICATION_DATA, *PLDR_DLL_UNLOADED_NOTIFICATION_DATA;
  612. typedef const LDR_DLL_UNLOADED_NOTIFICATION_DATA *PCLDR_DLL_UNLOADED_NOTIFICATION_DATA;
  613. typedef union _LDR_DLL_NOTIFICATION_DATA {
  614. LDR_DLL_LOADED_NOTIFICATION_DATA Loaded;
  615. LDR_DLL_UNLOADED_NOTIFICATION_DATA Unloaded;
  616. } LDR_DLL_NOTIFICATION_DATA, *PLDR_DLL_NOTIFICATION_DATA;
  617. typedef const LDR_DLL_NOTIFICATION_DATA *PCLDR_DLL_NOTIFICATION_DATA;
  618. #define LDR_DLL_NOTIFICATION_REASON_LOADED (1)
  619. #define LDR_DLL_NOTIFICATION_REASON_UNLOADED (2)
  620. typedef
  621. VOID (NTAPI *PLDR_DLL_NOTIFICATION_FUNCTION)(
  622. IN ULONG NotificationReason,
  623. IN PCLDR_DLL_NOTIFICATION_DATA NotificationData,
  624. IN PVOID Context
  625. );
  626. NTSTATUS
  627. NTAPI
  628. LdrRegisterDllNotification(
  629. IN ULONG Flags,
  630. IN PLDR_DLL_NOTIFICATION_FUNCTION NotificationFunction,
  631. IN PVOID Context,
  632. OUT PVOID *Cookie
  633. );
  634. NTSTATUS
  635. NTAPI
  636. LdrUnregisterDllNotification(
  637. IN PVOID Cookie
  638. );
  639. typedef
  640. VOID (NTAPI *PLDR_LOADED_MODULE_ENUMERATION_CALLBACK_FUNCTION)(
  641. IN PCLDR_DATA_TABLE_ENTRY DataTableEntry,
  642. IN PVOID Context,
  643. IN OUT BOOLEAN *StopEnumeration
  644. );
  645. NTSTATUS
  646. NTAPI
  647. LdrEnumerateLoadedModules(
  648. IN ULONG Flags,
  649. IN PLDR_LOADED_MODULE_ENUMERATION_CALLBACK_FUNCTION CallbackFunction,
  650. IN PVOID Context
  651. );
  652. #define LDR_LOCK_LOADER_LOCK_FLAG_RAISE_ON_ERRORS (0x00000001)
  653. #define LDR_LOCK_LOADER_LOCK_FLAG_TRY_ONLY (0x00000002)
  654. #define LDR_LOCK_LOADER_LOCK_DISPOSITION_INVALID (0)
  655. #define LDR_LOCK_LOADER_LOCK_DISPOSITION_LOCK_ACQUIRED (1)
  656. #define LDR_LOCK_LOADER_LOCK_DISPOSITION_LOCK_NOT_ACQUIRED (2)
  657. NTSTATUS
  658. NTAPI
  659. LdrLockLoaderLock(
  660. IN ULONG Flags,
  661. OUT ULONG *Disposition OPTIONAL, // not optional if LDR_LOCK_LOADER_LOCK_FLAG_TRY_ONLY is set
  662. OUT PVOID *Cookie
  663. );
  664. #define LDR_UNLOCK_LOADER_LOCK_FLAG_RAISE_ON_ERRORS (0x00000001)
  665. NTSTATUS
  666. NTAPI
  667. LdrUnlockLoaderLock(
  668. IN ULONG Flags,
  669. IN OUT PVOID Cookie
  670. );
  671. #define LDR_GET_DLL_HANDLE_EX_UNCHANGED_REFCOUNT (0x00000001)
  672. #define LDR_GET_DLL_HANDLE_EX_PIN (0x00000002)
  673. NTSTATUS
  674. NTAPI
  675. LdrGetDllHandleEx(
  676. IN ULONG Flags,
  677. IN PCWSTR DllPath OPTIONAL,
  678. IN PULONG DllCharacteristics OPTIONAL,
  679. IN PCUNICODE_STRING DllName,
  680. OUT PVOID *DllHandle OPTIONAL
  681. );
  682. #define LDR_ADDREF_DLL_PIN (0x00000001)
  683. NTSTATUS
  684. NTAPI
  685. LdrAddRefDll(
  686. ULONG Flags,
  687. PVOID DllHandle
  688. );
  689. typedef
  690. NTSTATUS (NTAPI *PLDR_APP_COMPAT_DLL_REDIRECTION_CALLBACK_FUNCTION)(
  691. IN ULONG Flags,
  692. IN PCWSTR DllName,
  693. IN PCWSTR DllPath OPTIONAL,
  694. IN OUT PULONG DllCharacteristics OPTIONAL,
  695. IN PVOID CallbackData,
  696. OUT PWSTR *EffectiveDllPath
  697. );
  698. NTSTATUS
  699. NTAPI
  700. LdrSetAppCompatDllRedirectionCallback(
  701. IN ULONG Flags,
  702. IN PLDR_APP_COMPAT_DLL_REDIRECTION_CALLBACK_FUNCTION CallbackFunction,
  703. IN PVOID CallbackData
  704. );
  705. #ifdef __cplusplus
  706. }
  707. #endif
  708. #endif // _NTLDRAPI_