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.

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