1 /* $Id: utils.c,v 1.50 2002/04/26 13:08:18 ekohl Exp $
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: lib/ntdll/ldr/startup.c
6 * PURPOSE: Process startup for PE executables
7 * PROGRAMMERS: Jean Michault
8 * Rex Jolliff (rex@lvcablemodem.com)
13 * - Fix calling of entry points
14 * - Handle loading flags correctly
18 /* INCLUDES *****************************************************************/
20 #include <reactos/config.h>
21 #include <ddk/ntddk.h>
25 #include <ntdll/ldr.h>
26 #include <ntos/minmax.h>
29 #ifdef DBG_NTDLL_LDR_UTILS
32 #include <ntdll/ntdll.h>
34 /* PROTOTYPES ****************************************************************/
37 /* Type for a DLL's entry point */
38 typedef WINBOOL STDCALL
39 (* PDLLMAIN_FUNC
)(HANDLE hInst
,
40 ULONG ul_reason_for_call
,
43 static NTSTATUS
LdrFindEntryForName(PUNICODE_STRING Name
, PLDR_MODULE
*Module
);
44 static PVOID
LdrFixupForward(PCHAR ForwardName
);
45 static PVOID
LdrGetExportByName(PVOID BaseAddress
, PUCHAR SymbolName
, USHORT Hint
);
48 /* FUNCTIONS *****************************************************************/
53 VOID
LdrLoadModuleSymbols(PLDR_MODULE ModuleObject
)
67 /***************************************************************************
72 * Adjusts the name of a dll to a fully qualified name.
75 * FullDllName: Pointer to caller supplied storage for the fully
77 * DllName: Pointer to the dll name.
78 * BaseName: TRUE: Only the file name is passed to FullDllName
79 * FALSE: The full path is preserved in FullDllName
87 * A given path is not affected by the adjustment, but the file
91 * ntdll.xyz --> ntdll.xyz
95 LdrAdjustDllName (PUNICODE_STRING FullDllName
,
96 PUNICODE_STRING DllName
,
99 WCHAR Buffer
[MAX_PATH
];
104 Length
= DllName
->Length
/ sizeof(WCHAR
);
106 if (BaseName
== TRUE
)
108 /* get the base dll name */
109 Pointer
= DllName
->Buffer
+ Length
;
116 while (Pointer
>= DllName
->Buffer
&& *Pointer
!= L
'\\' && *Pointer
!= L
'/');
119 Length
= Extension
- Pointer
;
120 memmove (Buffer
, Pointer
, Length
* sizeof(WCHAR
));
124 /* get the full dll name */
125 memmove (Buffer
, DllName
->Buffer
, DllName
->Length
);
128 /* Build the DLL's absolute name */
129 Extension
= wcsrchr (Buffer
, L
'.');
130 if ((Extension
!= NULL
) && (*Extension
== L
'.'))
132 /* with extension - remove dot if it's the last character */
133 if (Buffer
[Length
- 1] == L
'.')
139 /* name without extension - assume that it is .dll */
140 memmove (Buffer
+ Length
, L
".dll", 10);
143 RtlCreateUnicodeString (FullDllName
,
148 /***************************************************************************
165 LdrLoadDll (IN PWSTR SearchPath OPTIONAL
,
167 IN PUNICODE_STRING Name
,
168 OUT PVOID
*BaseAddress OPTIONAL
)
170 WCHAR SearchPathBuffer
[MAX_PATH
];
171 WCHAR FullDosName
[MAX_PATH
];
172 UNICODE_STRING AdjustedName
;
173 UNICODE_STRING FullNtFileName
;
174 OBJECT_ATTRIBUTES FileObjectAttributes
;
175 char BlockBuffer
[1024];
176 PIMAGE_DOS_HEADER DosHeader
;
178 PIMAGE_NT_HEADERS NTHeaders
;
180 ULONG InitialViewSize
;
183 HANDLE SectionHandle
;
184 PDLLMAIN_FUNC Entrypoint
= NULL
;
189 *BaseAddress
= NtCurrentPeb()->ImageBaseAddress
;
190 return STATUS_SUCCESS
;
195 DPRINT("LdrLoadDll(Name \"%wZ\" BaseAddress %x)\n",
198 /* adjust the full dll name */
199 LdrAdjustDllName (&AdjustedName
,
202 DPRINT("AdjustedName: %wZ\n", &AdjustedName
);
205 * Test if dll is already loaded.
207 if (LdrFindEntryForName(&AdjustedName
, &Module
) == STATUS_SUCCESS
)
209 DPRINT("DLL %wZ already loaded.\n", &AdjustedName
);
210 if (Module
->LoadCount
!= -1)
212 *BaseAddress
= Module
->BaseAddress
;
213 return STATUS_SUCCESS
;
215 DPRINT("Loading \"%wZ\"\n", Name
);
217 if (SearchPath
== NULL
)
219 SearchPath
= SearchPathBuffer
;
220 wcscpy (SearchPathBuffer
, SharedUserData
->NtSystemRoot
);
221 wcscat (SearchPathBuffer
, L
"\\system32;");
222 wcscat (SearchPathBuffer
, SharedUserData
->NtSystemRoot
);
223 wcscat (SearchPathBuffer
, L
";.");
226 DPRINT("SearchPath %S\n", SearchPath
);
228 if (RtlDosSearchPath_U (SearchPath
,
234 return STATUS_DLL_NOT_FOUND
;
236 DPRINT("FullDosName %S\n", FullDosName
);
238 RtlFreeUnicodeString (&AdjustedName
);
240 if (!RtlDosPathNameToNtPathName_U (FullDosName
,
244 return STATUS_DLL_NOT_FOUND
;
246 DPRINT("FullNtFileName %wZ\n", &FullNtFileName
);
248 InitializeObjectAttributes(&FileObjectAttributes
,
254 DPRINT("Opening dll \"%wZ\"\n", &FullNtFileName
);
256 Status
= ZwOpenFile(&FileHandle
,
258 &FileObjectAttributes
,
262 if (!NT_SUCCESS(Status
))
264 DbgPrint("Dll open of %wZ failed: Status = 0x%08x\n",
265 &FullNtFileName
, Status
);
266 RtlFreeUnicodeString (&FullNtFileName
);
269 RtlFreeUnicodeString (&FullNtFileName
);
271 Status
= ZwReadFile(FileHandle
,
280 if (!NT_SUCCESS(Status
))
282 DPRINT("Dll header read failed: Status = 0x%08x\n", Status
);
287 * Overlay DOS and NT headers structures to the
288 * buffer with DLL's header raw data.
290 DosHeader
= (PIMAGE_DOS_HEADER
) BlockBuffer
;
291 NTHeaders
= (PIMAGE_NT_HEADERS
) (BlockBuffer
+ DosHeader
->e_lfanew
);
293 * Check it is a PE image file.
295 if ((DosHeader
->e_magic
!= IMAGE_DOS_MAGIC
)
296 || (DosHeader
->e_lfanew
== 0L)
297 || (*(PULONG
)(NTHeaders
) != IMAGE_PE_MAGIC
))
299 DPRINT("NTDLL format invalid\n");
302 return STATUS_UNSUCCESSFUL
;
305 ImageBase
= (PVOID
) NTHeaders
->OptionalHeader
.ImageBase
;
306 ImageSize
= NTHeaders
->OptionalHeader
.SizeOfImage
;
308 DPRINT("ImageBase 0x%08x\n", ImageBase
);
311 * Create a section for dll.
313 Status
= ZwCreateSection(&SectionHandle
,
318 SEC_COMMIT
| SEC_IMAGE
,
320 if (!NT_SUCCESS(Status
))
322 DPRINT("NTDLL create section failed: Status = 0x%08x\n", Status
);
328 * Map the dll into the process.
332 Status
= ZwMapViewOfSection(SectionHandle
,
342 if (!NT_SUCCESS(Status
))
344 DbgPrint("NTDLL.LDR: map view of section failed (Status %x)\n",
351 /* relocate dll and fixup import table */
352 if ((NTHeaders
->FileHeader
.Characteristics
& IMAGE_FILE_DLL
) ==
356 (PDLLMAIN_FUNC
) LdrPEStartup(ImageBase
, SectionHandle
);
357 if (Entrypoint
== NULL
)
359 return(STATUS_UNSUCCESSFUL
);
363 /* build module entry */
364 Module
= RtlAllocateHeap(RtlGetProcessHeap(),
366 sizeof (LDR_MODULE
));
367 Module
->BaseAddress
= (PVOID
)ImageBase
;
368 Module
->EntryPoint
= NTHeaders
->OptionalHeader
.AddressOfEntryPoint
;
369 if (Module
->EntryPoint
!= 0)
370 Module
->EntryPoint
+= (ULONG
)Module
->BaseAddress
;
371 Module
->SizeOfImage
= ImageSize
;
372 if (NtCurrentPeb()->Ldr
->Initialized
== TRUE
)
374 /* loading while app is running */
375 Module
->LoadCount
= 1;
380 * loading while app is initializing
381 * dll must not be unloaded
383 Module
->LoadCount
= -1;
386 Module
->TlsIndex
= 0;
387 Module
->CheckSum
= NTHeaders
->OptionalHeader
.CheckSum
;
388 Module
->TimeDateStamp
= NTHeaders
->FileHeader
.TimeDateStamp
;
390 RtlCreateUnicodeString (&Module
->FullDllName
,
392 RtlCreateUnicodeString (&Module
->BaseDllName
,
393 wcsrchr(FullDosName
, L
'\\') + 1);
394 DPRINT ("BaseDllName %wZ\n", &Module
->BaseDllName
);
396 /* FIXME: aquire loader lock */
397 InsertTailList(&NtCurrentPeb()->Ldr
->InLoadOrderModuleList
,
398 &Module
->InLoadOrderModuleList
);
399 InsertTailList(&NtCurrentPeb()->Ldr
->InInitializationOrderModuleList
,
400 &Module
->InInitializationOrderModuleList
);
401 /* FIXME: release loader lock */
404 LdrLoadModuleSymbols(Module
);
408 if ((NTHeaders
->FileHeader
.Characteristics
& IMAGE_FILE_DLL
) ==
411 if (Module
->EntryPoint
!= 0)
413 Entrypoint
= (PDLLMAIN_FUNC
)Module
->EntryPoint
;
415 DPRINT("Calling entry point at 0x%08x\n", Entrypoint
);
416 if (FALSE
== Entrypoint(Module
->BaseAddress
,
420 DPRINT("NTDLL.LDR: DLL \"%wZ\" failed to initialize\n",
421 &Module
->BaseDllName
);
422 /* FIXME: should clean up and fail */
426 DPRINT("NTDLL.LDR: DLL \"%wZ\" initialized successfully\n",
427 &Module
->BaseDllName
);
432 DPRINT("NTDLL.LDR: Entrypoint is NULL for \"%wZ\"\n",
433 &Module
->BaseDllName
);
437 *BaseAddress
= Module
->BaseAddress
;
438 return STATUS_SUCCESS
;
442 /***************************************************************************
444 * LdrFindEntryForAddress
458 LdrFindEntryForAddress(PVOID Address
,
461 PLIST_ENTRY ModuleListHead
;
463 PLDR_MODULE ModulePtr
;
465 DPRINT("NTDLL.LdrFindEntryForAddress(Address %p)\n", Address
);
467 if (NtCurrentPeb()->Ldr
== NULL
)
468 return(STATUS_NO_MORE_ENTRIES
);
470 ModuleListHead
= &NtCurrentPeb()->Ldr
->InLoadOrderModuleList
;
471 Entry
= ModuleListHead
->Flink
;
472 if (Entry
== ModuleListHead
)
473 return(STATUS_NO_MORE_ENTRIES
);
475 while (Entry
!= ModuleListHead
)
477 ModulePtr
= CONTAINING_RECORD(Entry
, LDR_MODULE
, InLoadOrderModuleList
);
479 DPRINT("Scanning %wZ at %p\n", &ModulePtr
->BaseDllName
, ModulePtr
->BaseAddress
);
481 if ((Address
>= ModulePtr
->BaseAddress
) &&
482 (Address
<= (ModulePtr
->BaseAddress
+ ModulePtr
->SizeOfImage
)))
485 return(STATUS_SUCCESS
);
488 Entry
= Entry
->Flink
;
491 DPRINT("Failed to find module entry.\n");
493 return(STATUS_NO_MORE_ENTRIES
);
497 /***************************************************************************
499 * LdrFindEntryForName
513 LdrFindEntryForName(PUNICODE_STRING Name
,
516 PLIST_ENTRY ModuleListHead
;
518 PLDR_MODULE ModulePtr
;
520 DPRINT("NTDLL.LdrFindEntryForName(Name %wZ)\n", Name
);
522 if (NtCurrentPeb()->Ldr
== NULL
)
523 return(STATUS_NO_MORE_ENTRIES
);
525 ModuleListHead
= &NtCurrentPeb()->Ldr
->InLoadOrderModuleList
;
526 Entry
= ModuleListHead
->Flink
;
527 if (Entry
== ModuleListHead
)
528 return(STATUS_NO_MORE_ENTRIES
);
530 // NULL is the current process
533 *Module
= CONTAINING_RECORD(Entry
, LDR_MODULE
, InLoadOrderModuleList
);
534 return(STATUS_SUCCESS
);
537 while (Entry
!= ModuleListHead
)
539 ModulePtr
= CONTAINING_RECORD(Entry
, LDR_MODULE
, InLoadOrderModuleList
);
541 DPRINT("Scanning %wZ %wZ\n", &ModulePtr
->BaseDllName
, Name
);
543 if (RtlCompareUnicodeString(&ModulePtr
->BaseDllName
, Name
, TRUE
) == 0)
546 return(STATUS_SUCCESS
);
549 Entry
= Entry
->Flink
;
552 DPRINT("Failed to find dll %wZ\n", Name
);
554 return(STATUS_NO_MORE_ENTRIES
);
557 /**********************************************************************
573 LdrFixupForward(PCHAR ForwardName
)
575 CHAR NameBuffer
[128];
576 UNICODE_STRING DllName
;
577 UNICODE_STRING FunctionName
;
582 strcpy(NameBuffer
, ForwardName
);
583 p
= strchr(NameBuffer
, '.');
588 DPRINT("Dll: %s Function: %s\n", NameBuffer
, p
+1);
589 RtlCreateUnicodeStringFromAsciiz (&DllName
,
592 Status
= LdrGetDllHandle (0, 0, &DllName
, &BaseAddress
);
593 if (!NT_SUCCESS(Status
))
595 Status
= LdrLoadDll(NULL
,
599 if (!NT_SUCCESS(Status
))
601 DbgPrint("LdrFixupForward: failed to load %wZ\n", &DllName
);
602 RtlFreeUnicodeString (&DllName
);
607 RtlFreeUnicodeString (&DllName
);
608 DPRINT("BaseAddress: %p\n", BaseAddress
);
610 return LdrGetExportByName(BaseAddress
, p
+1, -1);
617 /**********************************************************************
619 * LdrGetExportByOrdinal
633 LdrGetExportByOrdinal (
638 PIMAGE_EXPORT_DIRECTORY ExportDir
;
639 PDWORD
* ExFunctions
;
642 ExportDir
= (PIMAGE_EXPORT_DIRECTORY
)
643 RtlImageDirectoryEntryToData (BaseAddress
,
645 IMAGE_DIRECTORY_ENTRY_EXPORT
,
649 ExOrdinals
= (USHORT
*)
652 ExportDir
->AddressOfNameOrdinals
654 ExFunctions
= (PDWORD
*)
657 ExportDir
->AddressOfFunctions
660 "LdrGetExportByOrdinal(Ordinal %d) = %x\n",
662 ExFunctions
[ExOrdinals
[Ordinal
- ExportDir
->Base
]]
664 return(ExFunctions
[ExOrdinals
[Ordinal
- ExportDir
->Base
]]);
668 /**********************************************************************
684 LdrGetExportByName(PVOID BaseAddress
,
688 PIMAGE_EXPORT_DIRECTORY ExportDir
;
689 PDWORD
* ExFunctions
;
699 DPRINT("LdrGetExportByName %x %s %hu\n", BaseAddress
, SymbolName
, Hint
);
701 ExportDir
= (PIMAGE_EXPORT_DIRECTORY
)
702 RtlImageDirectoryEntryToData(BaseAddress
,
704 IMAGE_DIRECTORY_ENTRY_EXPORT
,
706 if (ExportDir
== NULL
)
708 DbgPrint("LdrGetExportByName(): no export directory!\n");
713 * Get header pointers
715 ExNames
= (PDWORD
*)RVA(BaseAddress
,
716 ExportDir
->AddressOfNames
);
717 ExOrdinals
= (USHORT
*)RVA(BaseAddress
,
718 ExportDir
->AddressOfNameOrdinals
);
719 ExFunctions
= (PDWORD
*)RVA(BaseAddress
,
720 ExportDir
->AddressOfFunctions
);
723 * Check the hint first
725 if (Hint
< ExportDir
->NumberOfFunctions
)
727 ExName
= RVA(BaseAddress
, ExNames
[Hint
]);
728 if (strcmp(ExName
, SymbolName
) == 0)
730 Ordinal
= ExOrdinals
[Hint
];
731 Function
= RVA(BaseAddress
, ExFunctions
[Ordinal
]);
732 if (((ULONG
)Function
>= (ULONG
)ExportDir
) &&
733 ((ULONG
)Function
< (ULONG
)ExportDir
+ (ULONG
)ExportDirSize
))
735 DPRINT("Forward: %s\n", (PCHAR
)Function
);
736 Function
= LdrFixupForward((PCHAR
)Function
);
738 if (Function
!= NULL
)
744 * Try a binary search first
747 maxn
= ExportDir
->NumberOfFunctions
;
753 mid
= (minn
+ maxn
) / 2;
755 ExName
= RVA(BaseAddress
, ExNames
[mid
]);
756 res
= strcmp(ExName
, SymbolName
);
759 Ordinal
= ExOrdinals
[mid
];
760 Function
= RVA(BaseAddress
, ExFunctions
[Ordinal
]);
761 if (((ULONG
)Function
>= (ULONG
)ExportDir
) &&
762 ((ULONG
)Function
< (ULONG
)ExportDir
+ (ULONG
)ExportDirSize
))
764 DPRINT("Forward: %s\n", (PCHAR
)Function
);
765 Function
= LdrFixupForward((PCHAR
)Function
);
767 if (Function
!= NULL
)
770 else if (minn
== maxn
)
772 DPRINT("LdrGetExportByName(): binary search failed\n");
786 * Fall back on a linear search
788 DPRINT("LdrGetExportByName(): Falling back on a linear search of export table\n");
789 for (i
= 0; i
< ExportDir
->NumberOfFunctions
; i
++)
791 ExName
= RVA(BaseAddress
, ExNames
[i
]);
792 if (strcmp(ExName
,SymbolName
) == 0)
794 Ordinal
= ExOrdinals
[i
];
795 Function
= RVA(BaseAddress
, ExFunctions
[Ordinal
]);
796 DPRINT("%x %x %x\n", Function
, ExportDir
, ExportDir
+ ExportDirSize
);
797 if (((ULONG
)Function
>= (ULONG
)ExportDir
) &&
798 ((ULONG
)Function
< (ULONG
)ExportDir
+ (ULONG
)ExportDirSize
))
800 DPRINT("Forward: %s\n", (PCHAR
)Function
);
801 Function
= LdrFixupForward((PCHAR
)Function
);
806 DbgPrint("LdrGetExportByName(): failed to find %s\n",SymbolName
);
811 /**********************************************************************
813 * LdrPerformRelocations
816 * Relocate a DLL's memory image.
827 static NTSTATUS
LdrPerformRelocations (PIMAGE_NT_HEADERS NTHeaders
,
830 USHORT NumberOfEntries
;
836 PRELOCATION_DIRECTORY RelocationDir
;
837 PRELOCATION_ENTRY RelocationBlock
;
841 RelocationRVA
= NTHeaders
->OptionalHeader
842 .DataDirectory
[IMAGE_DIRECTORY_ENTRY_BASERELOC
]
847 RelocationDir
= (PRELOCATION_DIRECTORY
)
848 ((PCHAR
)ImageBase
+ RelocationRVA
);
850 while (RelocationDir
->SizeOfBlock
)
852 Delta32
= (ULONG
)(ImageBase
-
853 NTHeaders
->OptionalHeader
.ImageBase
);
854 RelocationBlock
= (PRELOCATION_ENTRY
) (
857 + sizeof (RELOCATION_DIRECTORY
)
860 RelocationDir
->SizeOfBlock
861 - sizeof (RELOCATION_DIRECTORY
)
863 / sizeof (RELOCATION_ENTRY
);
866 (i
< NumberOfEntries
);
871 RelocationBlock
[i
].TypeOffset
874 + RelocationDir
->VirtualAddress
;
876 * What kind of relocations should we perform
877 * for the current entry?
879 switch (RelocationBlock
[i
].TypeOffset
>> 12)
881 case TYPE_RELOC_ABSOLUTE
:
884 case TYPE_RELOC_HIGH
:
885 pValue16
= (PUSHORT
) (ImageBase
+ Offset
);
886 *pValue16
+= Delta32
>> 16;
890 pValue16
= (PUSHORT
)(ImageBase
+ Offset
);
891 *pValue16
+= Delta32
& 0xffff;
894 case TYPE_RELOC_HIGHLOW
:
895 pValue32
= (PULONG
) (ImageBase
+ Offset
);
896 *pValue32
+= Delta32
;
899 case TYPE_RELOC_HIGHADJ
:
900 /* FIXME: do the highadjust fixup */
902 "TYPE_RELOC_HIGHADJ fixup not implemented"
905 return(STATUS_UNSUCCESSFUL
);
908 DPRINT("unexpected fixup type\n");
909 return STATUS_UNSUCCESSFUL
;
912 RelocationRVA
+= RelocationDir
->SizeOfBlock
;
913 RelocationDir
= (PRELOCATION_DIRECTORY
) (
919 return STATUS_SUCCESS
;
923 /**********************************************************************
928 * Compute the entry point for every symbol the DLL imports
929 * from other modules.
940 static NTSTATUS
LdrFixupImports(PIMAGE_NT_HEADERS NTHeaders
,
943 PIMAGE_IMPORT_MODULE_DIRECTORY ImportModuleDirectory
;
948 DPRINT("LdrFixupImports(NTHeaders %x, ImageBase %x)\n", NTHeaders
,
952 * Process each import module.
954 ImportModuleDirectory
= (PIMAGE_IMPORT_MODULE_DIRECTORY
)(
955 ImageBase
+ NTHeaders
->OptionalHeader
956 .DataDirectory
[IMAGE_DIRECTORY_ENTRY_IMPORT
]
958 DPRINT("ImportModuleDirectory %x\n", ImportModuleDirectory
);
960 while (ImportModuleDirectory
->dwRVAModuleName
)
962 PVOID
* ImportAddressList
;
963 PULONG FunctionNameList
;
964 UNICODE_STRING DllName
;
968 DPRINT("ImportModule->Directory->dwRVAModuleName %s\n",
969 (PCHAR
)(ImageBase
+ ImportModuleDirectory
->dwRVAModuleName
));
971 RtlCreateUnicodeStringFromAsciiz (&DllName
,
972 (PCHAR
)(ImageBase
+ ImportModuleDirectory
->dwRVAModuleName
));
974 Status
= LdrGetDllHandle (0, 0, &DllName
, &BaseAddress
);
975 if (!NT_SUCCESS(Status
))
977 Status
= LdrLoadDll(NULL
,
981 RtlFreeUnicodeString (&DllName
);
982 if (!NT_SUCCESS(Status
))
984 DbgPrint("LdrFixupImports:failed to load %s\n"
986 + ImportModuleDirectory
->dwRVAModuleName
));
993 * Get the import address list.
995 ImportAddressList
= (PVOID
*)(NTHeaders
->OptionalHeader
.ImageBase
996 + ImportModuleDirectory
->dwRVAFunctionAddressList
);
999 * Get the list of functions to import.
1001 if (ImportModuleDirectory
->dwRVAFunctionNameList
!= 0)
1003 FunctionNameList
= (PULONG
) (
1005 + ImportModuleDirectory
->dwRVAFunctionNameList
1012 + ImportModuleDirectory
->dwRVAFunctionAddressList
);
1015 * Walk through function list and fixup addresses.
1017 while (*FunctionNameList
!= 0L)
1019 if ((*FunctionNameList
) & 0x80000000)
1021 Ordinal
= (*FunctionNameList
) & 0x7fffffff;
1022 *ImportAddressList
=
1023 LdrGetExportByOrdinal(BaseAddress
,
1028 pName
= (DWORD
) (ImageBase
+ *FunctionNameList
+ 2);
1029 pHint
= *(PWORD
)(ImageBase
+ *FunctionNameList
);
1031 *ImportAddressList
=
1032 LdrGetExportByName(BaseAddress
, (PUCHAR
)pName
, pHint
);
1033 if ((*ImportAddressList
) == NULL
)
1035 DbgPrint("Failed to import %s\n", pName
);
1036 return STATUS_UNSUCCESSFUL
;
1039 ImportAddressList
++;
1042 ImportModuleDirectory
++;
1044 return STATUS_SUCCESS
;
1048 /**********************************************************************
1053 * 1. Map the DLL's sections into memory.
1054 * 2. Relocate, if needed the DLL.
1055 * 3. Fixup any imported symbol.
1056 * 4. Compute the DLL's entry point.
1060 * Address at which the DLL's image
1064 * Handle of the section that contains
1068 * NULL on error; otherwise the entry point
1069 * to call for initializing the DLL.
1076 PEPFUNC
LdrPEStartup (PVOID ImageBase
,
1077 HANDLE SectionHandle
)
1080 PEPFUNC EntryPoint
= NULL
;
1081 PIMAGE_DOS_HEADER DosHeader
;
1082 PIMAGE_NT_HEADERS NTHeaders
;
1084 DPRINT("LdrPEStartup(ImageBase %x SectionHandle %x)\n",
1085 ImageBase
, (ULONG
)SectionHandle
);
1088 * Overlay DOS and WNT headers structures
1089 * to the DLL's image.
1091 DosHeader
= (PIMAGE_DOS_HEADER
) ImageBase
;
1092 NTHeaders
= (PIMAGE_NT_HEADERS
) (ImageBase
+ DosHeader
->e_lfanew
);
1095 * If the base address is different from the
1096 * one the DLL is actually loaded, perform any
1099 if (ImageBase
!= (PVOID
) NTHeaders
->OptionalHeader
.ImageBase
)
1101 DbgPrint("LDR: Performing relocations\n");
1102 Status
= LdrPerformRelocations(NTHeaders
, ImageBase
);
1103 if (!NT_SUCCESS(Status
))
1105 DbgPrint("LdrPerformRelocations() failed\n");
1111 * If the DLL's imports symbols from other
1112 * modules, fixup the imported calls entry points.
1114 if (NTHeaders
->OptionalHeader
.DataDirectory
[IMAGE_DIRECTORY_ENTRY_IMPORT
]
1115 .VirtualAddress
!= 0)
1117 DPRINT("About to fixup imports\n");
1118 Status
= LdrFixupImports(NTHeaders
, ImageBase
);
1119 if (!NT_SUCCESS(Status
))
1121 DbgPrint("LdrFixupImports() failed\n");
1124 DPRINT("Fixup done\n");
1128 * Compute the DLL's entry point's address.
1130 DPRINT("ImageBase = %x\n",(ULONG
)ImageBase
);
1131 DPRINT("AddressOfEntryPoint = %x\n",(ULONG
)NTHeaders
->OptionalHeader
.AddressOfEntryPoint
);
1132 if (NTHeaders
->OptionalHeader
.AddressOfEntryPoint
!= 0)
1134 EntryPoint
= (PEPFUNC
) (ImageBase
1135 + NTHeaders
->OptionalHeader
.AddressOfEntryPoint
);
1137 DPRINT("LdrPEStartup() = %x\n",EntryPoint
);
1143 LdrUnloadDll (IN PVOID BaseAddress
)
1145 PIMAGE_NT_HEADERS NtHeaders
;
1146 PDLLMAIN_FUNC Entrypoint
;
1147 PLIST_ENTRY ModuleListHead
;
1152 if (BaseAddress
== NULL
)
1153 return STATUS_SUCCESS
;
1155 ModuleListHead
= &NtCurrentPeb()->Ldr
->InLoadOrderModuleList
;
1156 Entry
= ModuleListHead
->Flink
;
1158 while (Entry
!= ModuleListHead
)
1160 Module
= CONTAINING_RECORD(Entry
, LDR_MODULE
, InLoadOrderModuleList
);
1161 if (Module
->BaseAddress
== BaseAddress
)
1163 if (Module
->LoadCount
== -1)
1165 /* never unload this dll */
1166 return STATUS_SUCCESS
;
1168 else if (Module
->LoadCount
> 1)
1170 Module
->LoadCount
--;
1171 return STATUS_SUCCESS
;
1174 NtHeaders
= RtlImageNtHeader (Module
->BaseAddress
);
1175 if ((NtHeaders
->FileHeader
.Characteristics
& IMAGE_FILE_DLL
) == IMAGE_FILE_DLL
)
1177 if (Module
->EntryPoint
!= 0)
1179 Entrypoint
= (PDLLMAIN_FUNC
)Module
->EntryPoint
;
1180 DPRINT("Calling entry point at 0x%08x\n", Entrypoint
);
1181 Entrypoint(Module
->BaseAddress
,
1187 DPRINT("NTDLL.LDR: Entrypoint is NULL for \n");
1190 Status
= ZwUnmapViewOfSection (NtCurrentProcess (),
1191 Module
->BaseAddress
);
1192 ZwClose (Module
->SectionHandle
);
1194 /* remove the module entry from the list */
1195 RtlFreeUnicodeString (&Module
->FullDllName
);
1196 RtlFreeUnicodeString (&Module
->BaseDllName
);
1197 RemoveEntryList (Entry
);
1198 RtlFreeHeap (RtlGetProcessHeap (), 0, Module
);
1203 Entry
= Entry
->Flink
;
1206 DPRINT("NTDLL.LDR: Dll not found\n")
1208 return STATUS_UNSUCCESSFUL
;
1213 LdrFindResource_U(PVOID BaseAddress
,
1214 PLDR_RESOURCE_INFO ResourceInfo
,
1216 PIMAGE_RESOURCE_DATA_ENTRY
*ResourceDataEntry
)
1218 PIMAGE_RESOURCE_DIRECTORY ResDir
;
1219 PIMAGE_RESOURCE_DIRECTORY ResBase
;
1220 PIMAGE_RESOURCE_DIRECTORY_ENTRY ResEntry
;
1221 NTSTATUS Status
= STATUS_SUCCESS
;
1227 DPRINT ("LdrFindResource_U()\n");
1229 /* Get the pointer to the resource directory */
1230 ResDir
= (PIMAGE_RESOURCE_DIRECTORY
)
1231 RtlImageDirectoryEntryToData (BaseAddress
,
1233 IMAGE_DIRECTORY_ENTRY_RESOURCE
,
1237 return STATUS_RESOURCE_DATA_NOT_FOUND
;
1240 DPRINT("ResourceDirectory: %x\n", (ULONG
)ResDir
);
1244 /* Let's go into resource tree */
1245 for (i
= 0; i
< Level
; i
++)
1247 DPRINT("ResDir: %x\n", (ULONG
)ResDir
);
1248 Id
= ((PULONG
)ResourceInfo
)[i
];
1249 EntryCount
= ResDir
->NumberOfNamedEntries
;
1250 ResEntry
= (PIMAGE_RESOURCE_DIRECTORY_ENTRY
)(ResDir
+ 1);
1251 DPRINT("ResEntry %x\n", (ULONG
)ResEntry
);
1252 if (Id
& 0xFFFF0000)
1254 /* Resource name is a unicode string */
1255 for (; EntryCount
--; ResEntry
++)
1257 /* Scan entries for equal name */
1258 if (ResEntry
->Name
& 0x80000000)
1260 ws
= (PWCHAR
)((ULONG
)ResDir
+ (ResEntry
->Name
& 0x7FFFFFFF));
1261 if (!wcsncmp((PWCHAR
)Id
, ws
+ 1, *ws
) &&
1262 wcslen((PWCHAR
)Id
) == (int)*ws
)
1271 /* We use ID number instead of string */
1272 ResEntry
+= EntryCount
;
1273 EntryCount
= ResDir
->NumberOfIdEntries
;
1274 for (; EntryCount
--; ResEntry
++)
1276 /* Scan entries for equal name */
1277 if (ResEntry
->Name
== Id
)
1279 DPRINT("ID entry found %x\n", Id
);
1284 DPRINT("Error %lu\n", i
);
1289 return STATUS_RESOURCE_TYPE_NOT_FOUND
;
1292 return STATUS_RESOURCE_NAME_NOT_FOUND
;
1295 if (ResDir
->NumberOfNamedEntries
|| ResDir
->NumberOfIdEntries
)
1297 /* Use the first available language */
1298 ResEntry
= (IMAGE_RESOURCE_DIRECTORY_ENTRY
*)(ResDir
+ 1);
1301 return STATUS_RESOURCE_LANG_NOT_FOUND
;
1304 return STATUS_RESOURCE_DATA_NOT_FOUND
;
1307 return STATUS_INVALID_PARAMETER
;
1310 ResDir
= (PIMAGE_RESOURCE_DIRECTORY
)((ULONG
)ResBase
+
1311 (ResEntry
->OffsetToData
& 0x7FFFFFFF));
1313 DPRINT("ResourceDataEntry: %x\n", (ULONG
)ResDir
);
1315 if (ResourceDataEntry
)
1317 *ResourceDataEntry
= (PVOID
)ResDir
;
1325 LdrAccessResource(IN PVOID BaseAddress
,
1326 IN PIMAGE_RESOURCE_DATA_ENTRY ResourceDataEntry
,
1327 OUT PVOID
*Resource OPTIONAL
,
1328 OUT PULONG Size OPTIONAL
)
1330 PIMAGE_SECTION_HEADER Section
;
1331 PIMAGE_NT_HEADERS NtHeader
;
1338 Data
= (ULONG
)RtlImageDirectoryEntryToData (BaseAddress
,
1340 IMAGE_DIRECTORY_ENTRY_RESOURCE
,
1343 return STATUS_RESOURCE_DATA_NOT_FOUND
;
1345 if ((ULONG
)BaseAddress
& 1)
1347 /* loaded as ordinary file */
1348 NtHeader
= RtlImageNtHeader((PVOID
)((ULONG
)BaseAddress
& ~1UL));
1349 Offset
= (ULONG
)BaseAddress
- Data
+ NtHeader
->OptionalHeader
.DataDirectory
[IMAGE_DIRECTORY_ENTRY_RESOURCE
].VirtualAddress
;
1350 Section
= RtlImageRvaToSection (NtHeader
, BaseAddress
, NtHeader
->OptionalHeader
.DataDirectory
[IMAGE_DIRECTORY_ENTRY_RESOURCE
].VirtualAddress
);
1351 if (Section
== NULL
)
1353 return STATUS_RESOURCE_DATA_NOT_FOUND
;
1356 if (Section
->Misc
.VirtualSize
< ResourceDataEntry
->OffsetToData
)
1358 SectionRva
= RtlImageRvaToSection (NtHeader
, BaseAddress
, ResourceDataEntry
->OffsetToData
)->VirtualAddress
;
1359 SectionVa
= RtlImageRvaToVa(NtHeader
, BaseAddress
, SectionRva
, NULL
);
1360 Offset
= SectionRva
- SectionVa
+ Data
- Section
->VirtualAddress
;
1366 *Resource
= (PVOID
)(ResourceDataEntry
->OffsetToData
- Offset
+ (ULONG
)BaseAddress
);
1371 *Size
= ResourceDataEntry
->Size
;
1374 return STATUS_SUCCESS
;
1379 LdrDisableThreadCalloutsForDll (IN PVOID BaseAddress
)
1381 PLIST_ENTRY ModuleListHead
;
1386 DPRINT("LdrDisableThreadCalloutsForDll (BaseAddress %x)\n",
1389 Status
= STATUS_DLL_NOT_FOUND
;
1391 ModuleListHead
= &NtCurrentPeb()->Ldr
->InLoadOrderModuleList
;
1392 Entry
= ModuleListHead
->Flink
;
1394 while (Entry
!= ModuleListHead
)
1396 Module
= CONTAINING_RECORD(Entry
, LDR_MODULE
, InLoadOrderModuleList
);
1398 DPRINT("BaseDllName %wZ BaseAddress %x\n",
1399 &Module
->BaseDllName
,
1400 Module
->BaseAddress
);
1402 if (Module
->BaseAddress
== BaseAddress
)
1404 if (Module
->TlsIndex
== 0)
1406 Module
->Flags
|= 0x00040000;
1407 Status
= STATUS_SUCCESS
;
1412 Entry
= Entry
->Flink
;
1420 LdrFindResourceDirectory_U (IN PVOID BaseAddress
,
1425 PIMAGE_RESOURCE_DIRECTORY ResDir
;
1426 PIMAGE_RESOURCE_DIRECTORY_ENTRY ResEntry
;
1429 NTSTATUS Status
= STATUS_SUCCESS
;
1432 /* Get the pointer to the resource directory */
1433 ResDir
= (PIMAGE_RESOURCE_DIRECTORY
)
1434 RtlImageDirectoryEntryToData (BaseAddress
,
1436 IMAGE_DIRECTORY_ENTRY_RESOURCE
,
1440 return STATUS_RESOURCE_DATA_NOT_FOUND
;
1443 /* Let's go into resource tree */
1444 for (i
= 0; i
< level
; i
++, name
++)
1446 EntryCount
= ResDir
->NumberOfNamedEntries
;
1447 ResEntry
= (PIMAGE_RESOURCE_DIRECTORY_ENTRY
)(ResDir
+ 1);
1448 if ((ULONG
)(*name
) & 0xFFFF0000)
1450 /* Resource name is a unicode string */
1451 for (; EntryCount
--; ResEntry
++)
1453 /* Scan entries for equal name */
1454 if (ResEntry
->Name
& 0x80000000)
1456 ws
= (WCHAR
*)((ULONG
)ResDir
+ (ResEntry
->Name
& 0x7FFFFFFF));
1457 if (!wcsncmp( *name
, ws
+ 1, *ws
) && wcslen( *name
) == (int)*ws
)
1466 /* We use ID number instead of string */
1467 ResEntry
+= EntryCount
;
1468 EntryCount
= ResDir
->NumberOfIdEntries
;
1469 for (; EntryCount
--; ResEntry
++)
1471 /* Scan entries for equal name */
1472 if (ResEntry
->Name
== (ULONG
)(*name
))
1480 return STATUS_RESOURCE_TYPE_NOT_FOUND
;
1483 return STATUS_RESOURCE_NAME_NOT_FOUND
;
1486 Status
= STATUS_RESOURCE_LANG_NOT_FOUND
;
1487 /* Just use first language entry */
1488 if (ResDir
->NumberOfNamedEntries
|| ResDir
->NumberOfIdEntries
)
1490 ResEntry
= (IMAGE_RESOURCE_DIRECTORY_ENTRY
*)(ResDir
+ 1);
1496 return STATUS_RESOURCE_DATA_NOT_FOUND
;
1499 return STATUS_INVALID_PARAMETER
;
1502 ResDir
= (PIMAGE_RESOURCE_DIRECTORY
)((ULONG
)ResDir
+ ResEntry
->OffsetToData
);
1507 *addr
= (PVOID
)ResDir
;
1515 LdrGetDllHandle (IN ULONG Unknown1
,
1517 IN PUNICODE_STRING DllName
,
1518 OUT PVOID
*BaseAddress
)
1520 UNICODE_STRING FullDllName
;
1521 PLIST_ENTRY ModuleListHead
;
1525 DPRINT("LdrGetDllHandle (Unknown1 %x Unknown2 %x DllName %wZ BaseAddress %p)\n",
1526 Unknown1
, Unknown2
, DllName
, BaseAddress
);
1528 /* NULL is the current executable */
1529 if ( DllName
== NULL
)
1531 *BaseAddress
= NtCurrentPeb()->ImageBaseAddress
;
1532 DPRINT("BaseAddress %x\n", *BaseAddress
);
1533 return STATUS_SUCCESS
;
1536 LdrAdjustDllName (&FullDllName
,
1540 DPRINT("FullDllName %wZ\n",
1543 ModuleListHead
= &NtCurrentPeb()->Ldr
->InLoadOrderModuleList
;
1544 Entry
= ModuleListHead
->Flink
;
1546 while (Entry
!= ModuleListHead
)
1548 Module
= CONTAINING_RECORD(Entry
, LDR_MODULE
, InLoadOrderModuleList
);
1550 DPRINT("EntryPoint %x\n", Module
->EntryPoint
);
1551 DPRINT("Comparing %wZ and %wZ\n",
1552 &Module
->BaseDllName
,
1555 if (!RtlCompareUnicodeString(&Module
->BaseDllName
, &FullDllName
, TRUE
))
1557 RtlFreeUnicodeString (&FullDllName
);
1558 *BaseAddress
= Module
->BaseAddress
;
1559 DPRINT("BaseAddress %x\n", *BaseAddress
);
1560 return STATUS_SUCCESS
;
1563 Entry
= Entry
->Flink
;
1566 DPRINT("Failed to find dll %wZ\n", &FullDllName
);
1567 RtlFreeUnicodeString (&FullDllName
);
1568 *BaseAddress
= NULL
;
1569 return STATUS_DLL_NOT_FOUND
;
1574 LdrGetProcedureAddress (IN PVOID BaseAddress
,
1575 IN PANSI_STRING Name
,
1577 OUT PVOID
*ProcedureAddress
)
1579 PIMAGE_EXPORT_DIRECTORY ExportDir
;
1585 DPRINT("LdrGetProcedureAddress (BaseAddress %x Name %Z Ordinal %lu ProcedureAddress %x)\n",
1586 BaseAddress
, Name
, Ordinal
, ProcedureAddress
);
1588 /* Get the pointer to the export directory */
1589 ExportDir
= (PIMAGE_EXPORT_DIRECTORY
)
1590 RtlImageDirectoryEntryToData (BaseAddress
,
1592 IMAGE_DIRECTORY_ENTRY_EXPORT
,
1595 DPRINT("ExportDir %x i %lu\n", ExportDir
, i
);
1597 if (!ExportDir
|| !i
|| !ProcedureAddress
)
1599 return STATUS_INVALID_PARAMETER
;
1602 AddressPtr
= (PULONG
)((ULONG
)BaseAddress
+ (ULONG
)ExportDir
->AddressOfFunctions
);
1603 if (Name
&& Name
->Length
)
1606 OrdinalPtr
= (PUSHORT
)((ULONG
)BaseAddress
+ (ULONG
)ExportDir
->AddressOfNameOrdinals
);
1607 NamePtr
= (PULONG
)((ULONG
)BaseAddress
+ (ULONG
)ExportDir
->AddressOfNames
);
1608 for( i
= 0; i
< ExportDir
->NumberOfNames
; i
++, NamePtr
++, OrdinalPtr
++)
1610 if (!_strnicmp(Name
->Buffer
, (char*)(BaseAddress
+ *NamePtr
), Name
->Length
))
1612 *ProcedureAddress
= (PVOID
)((ULONG
)BaseAddress
+ (ULONG
)AddressPtr
[*OrdinalPtr
]);
1613 return STATUS_SUCCESS
;
1616 DbgPrint("LdrGetProcedureAddress: Can't resolve symbol '%Z'\n", Name
);
1621 Ordinal
&= 0x0000FFFF;
1622 if (Ordinal
- ExportDir
->Base
< ExportDir
->NumberOfFunctions
)
1624 *ProcedureAddress
= (PVOID
)((ULONG
)BaseAddress
+ (ULONG
)AddressPtr
[Ordinal
- ExportDir
->Base
]);
1625 return STATUS_SUCCESS
;
1627 DbgPrint("LdrGetProcedureAddress: Can't resolve symbol @%d\n", Ordinal
);
1630 return STATUS_PROCEDURE_NOT_FOUND
;
1635 LdrShutdownProcess (VOID
)
1637 PLIST_ENTRY ModuleListHead
;
1641 DPRINT("LdrShutdownProcess() called\n");
1643 RtlEnterCriticalSection (NtCurrentPeb()->LoaderLock
);
1645 ModuleListHead
= &NtCurrentPeb()->Ldr
->InInitializationOrderModuleList
;
1646 Entry
= ModuleListHead
->Blink
;
1648 while (Entry
!= ModuleListHead
)
1650 Module
= CONTAINING_RECORD(Entry
, LDR_MODULE
, InInitializationOrderModuleList
);
1652 DPRINT(" Unloading %S\n",
1653 &Module
->BaseDllName
);
1654 // PJS: only detach from static dlls, they should FreeLibrary() any dlls that
1655 // they loaded dynamically, and when the last reference is gone, that lib will
1657 if (Module
->EntryPoint
!= 0 && Module
->LoadCount
== -1)
1659 PDLLMAIN_FUNC Entrypoint
= (PDLLMAIN_FUNC
)Module
->EntryPoint
;
1661 DPRINT("Calling entry point at 0x%08x\n", Entrypoint
);
1662 Entrypoint (Module
->BaseAddress
,
1667 Entry
= Entry
->Blink
;
1670 RtlLeaveCriticalSection (NtCurrentPeb()->LoaderLock
);
1672 DPRINT("LdrShutdownProcess() done\n");
1674 return STATUS_SUCCESS
;
1679 LdrShutdownThread (VOID
)
1681 PLIST_ENTRY ModuleListHead
;
1685 DPRINT("LdrShutdownThread() called\n");
1687 RtlEnterCriticalSection (NtCurrentPeb()->LoaderLock
);
1689 ModuleListHead
= &NtCurrentPeb()->Ldr
->InInitializationOrderModuleList
;
1690 Entry
= ModuleListHead
->Blink
;
1692 while (Entry
!= ModuleListHead
)
1694 Module
= CONTAINING_RECORD(Entry
, LDR_MODULE
, InInitializationOrderModuleList
);
1696 DPRINT(" Unloading %wZ\n",
1697 &Module
->BaseDllName
);
1699 if (Module
->EntryPoint
!= 0)
1701 PDLLMAIN_FUNC Entrypoint
= (PDLLMAIN_FUNC
)Module
->EntryPoint
;
1703 DPRINT("Calling entry point at 0x%08x\n", Entrypoint
);
1704 Entrypoint (Module
->BaseAddress
,
1709 Entry
= Entry
->Blink
;
1712 RtlLeaveCriticalSection (NtCurrentPeb()->LoaderLock
);
1714 DPRINT("LdrShutdownThread() done\n");
1716 return STATUS_SUCCESS
;
1720 /***************************************************************************
1722 * LdrQueryProcessModuleInformation
1735 LdrQueryProcessModuleInformation(IN PMODULE_INFORMATION ModuleInformation OPTIONAL
,
1736 IN ULONG Size OPTIONAL
,
1737 OUT PULONG ReturnedSize
)
1740 PLIST_ENTRY ModuleListHead
;
1743 PMODULE_ENTRY ModulePtr
= NULL
;
1744 NTSTATUS Status
= STATUS_SUCCESS
;
1745 ULONG UsedSize
= sizeof(ULONG
);
1746 ANSI_STRING AnsiString
;
1749 DPRINT("LdrQueryProcessModuleInformation() called\n");
1751 RtlEnterCriticalSection (NtCurrentPeb()->LoaderLock
);
1753 if (ModuleInformation
== NULL
|| Size
== 0)
1755 Status
= STATUS_INFO_LENGTH_MISMATCH
;
1759 ModuleInformation
->ModuleCount
= 0;
1760 ModulePtr
= &ModuleInformation
->ModuleEntry
[0];
1761 Status
= STATUS_SUCCESS
;
1764 ModuleListHead
= &NtCurrentPeb()->Ldr
->InLoadOrderModuleList
;
1765 Entry
= ModuleListHead
->Flink
;
1767 while (Entry
!= ModuleListHead
)
1769 Module
= CONTAINING_RECORD(Entry
, LDR_MODULE
, InLoadOrderModuleList
);
1771 DPRINT(" Module %wZ\n",
1772 &Module
->FullDllName
);
1774 if (UsedSize
> Size
)
1776 Status
= STATUS_INFO_LENGTH_MISMATCH
;
1778 else if (ModuleInformation
!= NULL
)
1780 ModulePtr
->Unknown0
= 0; // FIXME: ??
1781 ModulePtr
->Unknown1
= 0; // FIXME: ??
1782 ModulePtr
->BaseAddress
= Module
->BaseAddress
;
1783 ModulePtr
->SizeOfImage
= Module
->SizeOfImage
;
1784 ModulePtr
->Flags
= Module
->Flags
;
1785 ModulePtr
->Unknown2
= 0; // FIXME: load order index ??
1786 ModulePtr
->Unknown3
= 0; // FIXME: ??
1787 ModulePtr
->LoadCount
= Module
->LoadCount
;
1789 AnsiString
.Length
= 0;
1790 AnsiString
.MaximumLength
= 256;
1791 AnsiString
.Buffer
= ModulePtr
->ModuleName
;
1792 RtlUnicodeStringToAnsiString(&AnsiString
,
1793 &Module
->FullDllName
,
1795 p
= strrchr(ModulePtr
->ModuleName
, '\\');
1797 ModulePtr
->PathLength
= p
- ModulePtr
->ModuleName
+ 1;
1799 ModulePtr
->PathLength
= 0;
1802 ModuleInformation
->ModuleCount
++;
1804 UsedSize
+= sizeof(MODULE_ENTRY
);
1806 Entry
= Entry
->Flink
;
1809 RtlLeaveCriticalSection (NtCurrentPeb()->LoaderLock
);
1811 if (ReturnedSize
!= 0)
1812 *ReturnedSize
= UsedSize
;
1814 DPRINT("LdrQueryProcessModuleInformation() done\n");