RtlEnterCriticalSection (NtCurrentPeb()->LoaderLock);
}
LoadCount = Module->LoadCount;
- if (Module->LoadCount > 0)
+ if (Module->LoadCount > 0 && Module->LoadCount != 0xFFFF)
{
Module->LoadCount--;
}
PLDR_DATA_TABLE_ENTRY Module;
PIMAGE_TLS_DIRECTORY TlsDirectory;
PTLS_DATA TlsData;
+ ULONG Size;
DPRINT("LdrpInitializeTlsForProccess() called for %wZ\n", &ExeModule->BaseDllName);
RtlImageDirectoryEntryToData(Module->DllBase,
TRUE,
IMAGE_DIRECTORY_ENTRY_TLS,
- NULL);
+ &Size);
ASSERT(Module->TlsIndex < LdrpTlsCount);
TlsData = &LdrpTlsArray[Module->TlsIndex];
TlsData->StartAddressOfRawData = (PVOID)TlsDirectory->StartAddressOfRawData;
TlsData->TlsDataSize = TlsDirectory->EndAddressOfRawData - TlsDirectory->StartAddressOfRawData;
TlsData->TlsZeroSize = TlsDirectory->SizeOfZeroFill;
if (TlsDirectory->AddressOfCallBacks)
- TlsData->TlsAddressOfCallBacks = *TlsDirectory->AddressOfCallBacks;
+ TlsData->TlsAddressOfCallBacks = *(PIMAGE_TLS_CALLBACK*)TlsDirectory->AddressOfCallBacks;
else
TlsData->TlsAddressOfCallBacks = NULL;
TlsData->Module = Module;
&ObjectAttributes);
if (!NT_SUCCESS(Status))
{
- DPRINT("NtOpenSection() failed for '%wZ' (Status %lx)\n", DllName, Status);
+ DPRINT("NtOpenSection() failed for '%wZ' (Status 0x%08lx)\n", DllName, Status);
return Status;
}
FILE_SYNCHRONOUS_IO_NONALERT);
if (!NT_SUCCESS(Status))
{
- DPRINT1("Dll open of %wZ failed: Status = 0x%08x\n",
+ DPRINT1("Dll open of %wZ failed: Status = 0x%08lx\n",
&FullNtFileName, Status);
RtlFreeUnicodeString (&FullNtFileName);
return Status;
NULL);
if (!NT_SUCCESS(Status))
{
- DPRINT("Dll header read failed: Status = 0x%08x\n", Status);
+ DPRINT("Dll header read failed: Status = 0x%08lx\n", Status);
NtClose(FileHandle);
return Status;
}
if (!NT_SUCCESS(Status))
{
- DPRINT("NTDLL create section failed: Status = 0x%08x\n", Status);
+ DPRINT("NTDLL create section failed: Status = 0x%08lx\n", Status);
return Status;
}
*
* @implemented
*/
-NTSTATUS STDCALL
+NTSTATUS NTAPI
LdrLoadDll (IN PWSTR SearchPath OPTIONAL,
IN ULONG LoadFlags,
IN PUNICODE_STRING Name,
*
* @implemented
*/
-NTSTATUS STDCALL
+NTSTATUS NTAPI
LdrFindEntryForAddress(PVOID Address,
PLDR_DATA_TABLE_ENTRY *Module)
{
ExportDir->AddressOfFunctions
);
DPRINT(
- "LdrGetExportByOrdinal(Ordinal %d) = %p\n",
+ "LdrGetExportByOrdinal(Ordinal %lu) = %p\n",
Ordinal,
RVA(BaseAddress, ExFunctions[Ordinal - ExportDir->Base] )
);
PDWORD * ExFunctions;
PDWORD * ExNames;
USHORT * ExOrdinals;
- ULONG i;
PVOID ExName;
ULONG Ordinal;
PVOID Function;
LONG minn, maxn;
ULONG ExportDirSize;
- DPRINT("LdrGetExportByName %x %s %hu\n", BaseAddress, SymbolName, Hint);
+ DPRINT("LdrGetExportByName %p %s %hu\n", BaseAddress, SymbolName, Hint);
ExportDir = (PIMAGE_EXPORT_DIRECTORY)
RtlImageDirectoryEntryToData(BaseAddress,
}
/*
- * Try a binary search first
+ * Binary search
*/
minn = 0;
maxn = ExportDir->NumberOfNames - 1;
}
}
- /*
- * Fall back on a linear search
- */
- DPRINT("LdrGetExportByName(): Falling back on a linear search of export table\n");
- for (i = 0; i < ExportDir->NumberOfNames; i++)
- {
- ExName = RVA(BaseAddress, ExNames[i]);
- if (strcmp(ExName, (PCHAR)SymbolName) == 0)
- {
- Ordinal = ExOrdinals[i];
- Function = RVA(BaseAddress, ExFunctions[Ordinal]);
- DPRINT("%x %x %x\n", Function, ExportDir, ExportDir + ExportDirSize);
- if (((ULONG)Function >= (ULONG)ExportDir) &&
- ((ULONG)Function < (ULONG)ExportDir + (ULONG)ExportDirSize))
- {
- DPRINT("Forward: %s\n", (PCHAR)Function);
- Function = LdrFixupForward((PCHAR)Function);
- }
- if (Function == NULL)
- {
- break;
- }
- return Function;
- }
- }
DPRINT1("LdrGetExportByName(): failed to find %s\n",SymbolName);
return (PVOID)NULL;
}
NTSTATUS Status;
PIMAGE_IMPORT_DESCRIPTOR ImportModuleDirectory;
PCHAR Name;
+ ULONG Size;
- DPRINT("LdrpProcessImportDirectory(%x '%wZ', '%s')\n",
+ DPRINT("LdrpProcessImportDirectory(%p '%wZ', '%s')\n",
Module, &Module->BaseDllName, ImportedName);
RtlImageDirectoryEntryToData(Module->DllBase,
TRUE,
IMAGE_DIRECTORY_ENTRY_IMPORT,
- NULL);
+ &Size);
if (ImportModuleDirectory == NULL)
{
return STATUS_UNSUCCESSFUL;
ULONG IATSize;
PIMAGE_NT_HEADERS NTHeaders;
PCHAR Name;
+ ULONG Size;
- DPRINT("LdrpAdjustImportDirectory(Module %x '%wZ', %x '%wZ', %x '%s')\n",
+ DPRINT("LdrpAdjustImportDirectory(Module %p '%wZ', %p '%wZ', '%s')\n",
Module, &Module->BaseDllName, ImportedModule, &ImportedModule->BaseDllName, ImportedName);
ImportModuleDirectory = (PIMAGE_IMPORT_DESCRIPTOR)
RtlImageDirectoryEntryToData(Module->DllBase,
TRUE,
IMAGE_DIRECTORY_ENTRY_IMPORT,
- NULL);
+ &Size);
if (ImportModuleDirectory == NULL)
{
return STATUS_UNSUCCESSFUL;
NTSTATUS Status;
PLDR_DATA_TABLE_ENTRY ImportedModule;
PCHAR ImportedName;
+ ULONG Size;
- DPRINT("LdrFixupImports(SearchPath %x, Module %x)\n", SearchPath, Module);
+ DPRINT("LdrFixupImports(SearchPath %S, Module %p)\n", SearchPath, Module);
/* Check for tls data */
TlsDirectory = (PIMAGE_TLS_DIRECTORY)
RtlImageDirectoryEntryToData(Module->DllBase,
TRUE,
IMAGE_DIRECTORY_ENTRY_TLS,
- NULL);
+ &Size);
if (TlsDirectory)
{
TlsSize = TlsDirectory->EndAddressOfRawData
RtlImageDirectoryEntryToData(Module->DllBase,
TRUE,
IMAGE_DIRECTORY_ENTRY_IMPORT,
- NULL);
+ &Size);
BoundImportDescriptor = (PIMAGE_BOUND_IMPORT_DESCRIPTOR)
RtlImageDirectoryEntryToData(Module->DllBase,
TRUE,
IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT,
- NULL);
+ &Size);
if (BoundImportDescriptor != NULL && ImportModuleDirectory == NULL)
{
}
if (BoundImportDescriptor)
{
- DPRINT("BoundImportDescriptor %x\n", BoundImportDescriptor);
+ DPRINT("BoundImportDescriptor %p\n", BoundImportDescriptor);
BoundImportDescriptorCurrent = BoundImportDescriptor;
while (BoundImportDescriptorCurrent->OffsetModuleName)
}
else if (ImportModuleDirectory)
{
- DPRINT("ImportModuleDirectory %x\n", ImportModuleDirectory);
+ DPRINT("ImportModuleDirectory %p\n", ImportModuleDirectory);
ImportModuleDirectoryCurrent = ImportModuleDirectory;
while (ImportModuleDirectoryCurrent->Name)
PIMAGE_NT_HEADERS NTHeaders;
PLDR_DATA_TABLE_ENTRY tmpModule;
- DPRINT("LdrPEStartup(ImageBase %x SectionHandle %x)\n",
- ImageBase, (ULONG)SectionHandle);
+ DPRINT("LdrPEStartup(ImageBase %p SectionHandle %p)\n",
+ ImageBase, SectionHandle);
/*
* Overlay DOS and WNT headers structures
/*
* Compute the DLL's entry point's address.
*/
- DPRINT("ImageBase = %x\n",(ULONG)ImageBase);
- DPRINT("AddressOfEntryPoint = %x\n",(ULONG)NTHeaders->OptionalHeader.AddressOfEntryPoint);
+ DPRINT("ImageBase = %p\n", ImageBase);
+ DPRINT("AddressOfEntryPoint = 0x%lx\n",(ULONG)NTHeaders->OptionalHeader.AddressOfEntryPoint);
if (NTHeaders->OptionalHeader.AddressOfEntryPoint != 0)
{
EntryPoint = (PEPFUNC) ((ULONG_PTR)ImageBase
+ NTHeaders->OptionalHeader.AddressOfEntryPoint);
}
- DPRINT("LdrPEStartup() = %x\n",EntryPoint);
+ DPRINT("LdrPEStartup() = %p\n",EntryPoint);
return EntryPoint;
}
PAGE_READONLY);
if (!NT_SUCCESS(Status))
{
- DPRINT1("map view of section failed (Status %x)\n", Status);
+ DPRINT1("map view of section failed (Status 0x%08lx)\n", Status);
RtlFreeUnicodeString(&FullDosName);
NtClose(SectionHandle);
return(Status);
* relocation. */
if (ImageBase != (PVOID) NtHeaders->OptionalHeader.ImageBase)
{
- DPRINT1("Relocating (%x -> %x) %wZ\n",
+ DPRINT1("Relocating (%lx -> %p) %wZ\n",
NtHeaders->OptionalHeader.ImageBase, ImageBase, &FullDosName);
Status = LdrPerformRelocations(NtHeaders, ImageBase);
if (!NT_SUCCESS(Status))
PLDR_DATA_TABLE_ENTRY ImportedModule;
NTSTATUS Status;
LONG LoadCount;
-
+ ULONG Size;
if (Unload)
{
RtlImageDirectoryEntryToData(Module->DllBase,
TRUE,
IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT,
- NULL);
+ &Size);
if (BoundImportDescriptor)
{
/* dereferencing all imported modules, use the bound import descriptor */
RtlImageDirectoryEntryToData(Module->DllBase,
TRUE,
IMAGE_DIRECTORY_ENTRY_IMPORT,
- NULL);
+ &Size);
if (ImportModuleDirectory)
{
/* dereferencing all imported modules, use the import descriptor */
/*
* @implemented
*/
-NTSTATUS STDCALL
+NTSTATUS NTAPI
LdrUnloadDll (IN PVOID BaseAddress)
{
PLDR_DATA_TABLE_ENTRY Module;
/*
* @implemented
*/
-NTSTATUS STDCALL
+NTSTATUS NTAPI
LdrDisableThreadCalloutsForDll(IN PVOID BaseAddress)
{
PLIST_ENTRY ModuleListHead;
PLDR_DATA_TABLE_ENTRY Module;
NTSTATUS Status;
- DPRINT("LdrDisableThreadCalloutsForDll (BaseAddress %x)\n", BaseAddress);
+ DPRINT("LdrDisableThreadCalloutsForDll (BaseAddress %p)\n", BaseAddress);
Status = STATUS_DLL_NOT_FOUND;
RtlEnterCriticalSection (NtCurrentPeb()->LoaderLock);
{
Module = CONTAINING_RECORD(Entry, LDR_DATA_TABLE_ENTRY, InLoadOrderModuleList);
- DPRINT("BaseDllName %wZ BaseAddress %x\n", &Module->BaseDllName, Module->DllBase);
+ DPRINT("BaseDllName %wZ BaseAddress %p\n", &Module->BaseDllName, Module->DllBase);
if (Module->DllBase == BaseAddress)
{
/*
* @implemented
*/
-NTSTATUS STDCALL
-LdrGetDllHandle(IN PWCHAR Path OPTIONAL,
- IN ULONG Unknown2,
+NTSTATUS NTAPI
+LdrGetDllHandle(IN PWSTR DllPath OPTIONAL,
+ IN PULONG DllCharacteristics,
IN PUNICODE_STRING DllName,
- OUT PVOID* BaseAddress)
+ OUT PVOID *DllHandle)
{
PLDR_DATA_TABLE_ENTRY Module;
NTSTATUS Status;
- TRACE_LDR("LdrGetDllHandle, searching for %wZ from %S\n", DllName, Path ? Path : L"");
+ TRACE_LDR("LdrGetDllHandle, searching for %wZ from %S\n",
+ DllName, DllPath ? DllPath : L"");
/* NULL is the current executable */
if (DllName == NULL)
{
- *BaseAddress = ExeModule->DllBase;
- DPRINT("BaseAddress %x\n", *BaseAddress);
+ *DllHandle = ExeModule->DllBase;
+ DPRINT("BaseAddress 0x%lx\n", *DllHandle);
return STATUS_SUCCESS;
}
Status = LdrFindEntryForName(DllName, &Module, FALSE);
if (NT_SUCCESS(Status))
{
- *BaseAddress = Module->DllBase;
+ *DllHandle = Module->DllBase;
return STATUS_SUCCESS;
}
DPRINT("Failed to find dll %wZ\n", DllName);
- *BaseAddress = NULL;
+ *DllHandle = NULL;
return STATUS_DLL_NOT_FOUND;
}
/*
* @implemented
*/
-NTSTATUS STDCALL
+NTSTATUS NTAPI
LdrGetProcedureAddress (IN PVOID BaseAddress,
IN PANSI_STRING Name,
IN ULONG Ordinal,
TRACE_LDR("LdrGetProcedureAddress by ORDINAL - %d\n", Ordinal);
}
- DPRINT("LdrGetProcedureAddress (BaseAddress %x Name %Z Ordinal %lu ProcedureAddress %x)\n",
+ DPRINT("LdrGetProcedureAddress (BaseAddress %p Name %Z Ordinal %lu ProcedureAddress %p)\n",
BaseAddress, Name, Ordinal, ProcedureAddress);
if (Name && Name->Length)
{
return STATUS_SUCCESS;
}
- DPRINT("LdrGetProcedureAddress: Can't resolve symbol @%d\n", Ordinal);
+ DPRINT("LdrGetProcedureAddress: Can't resolve symbol @%lu\n", Ordinal);
}
return STATUS_PROCEDURE_NOT_FOUND;
}
while (Entry != ModuleListHead)
{
Module = CONTAINING_RECORD(Entry, LDR_DATA_TABLE_ENTRY, InInitializationOrderModuleList);
- if (((UnloadAll && Module->LoadCount <= 0) || Module->LoadCount == 0) &&
+ if (((UnloadAll && Module->LoadCount == 0xFFFF) || Module->LoadCount == 0) &&
Module->Flags & LDRP_ENTRY_PROCESSED &&
!(Module->Flags & LDRP_UNLOAD_IN_PROGRESS))
{
/*
* @implemented
*/
-NTSTATUS STDCALL
+NTSTATUS NTAPI
LdrShutdownProcess (VOID)
{
LdrpDetachProcess(TRUE);
/*
* @implemented
*/
-NTSTATUS STDCALL
+NTSTATUS NTAPI
LdrShutdownThread (VOID)
{
PLIST_ENTRY ModuleListHead;
*
* @implemented
*/
-NTSTATUS STDCALL
-LdrQueryProcessModuleInformation(IN PMODULE_INFORMATION ModuleInformation OPTIONAL,
+NTSTATUS NTAPI
+LdrQueryProcessModuleInformation(IN PRTL_PROCESS_MODULES ModuleInformation OPTIONAL,
IN ULONG Size OPTIONAL,
OUT PULONG ReturnedSize)
{
PLIST_ENTRY ModuleListHead;
PLIST_ENTRY Entry;
PLDR_DATA_TABLE_ENTRY Module;
- PDEBUG_MODULE_INFORMATION ModulePtr = NULL;
+ PRTL_PROCESS_MODULE_INFORMATION ModulePtr = NULL;
NTSTATUS Status = STATUS_SUCCESS;
ULONG UsedSize = sizeof(ULONG);
ANSI_STRING AnsiString;
ModulePtr++;
ModuleInformation->ModuleCount++;
}
- UsedSize += sizeof(DEBUG_MODULE_INFORMATION);
+ UsedSize += sizeof(RTL_PROCESS_MODULE_INFORMATION);
Entry = Entry->Flink;
}
*
* @implemented
*/
-NTSTATUS STDCALL
+NTSTATUS NTAPI
LdrVerifyImageMatchesChecksum (IN HANDLE FileHandle,
ULONG Unknown1,
ULONG Unknown2,
*
* @implemented
*/
-NTSTATUS STDCALL
+NTSTATUS NTAPI
LdrQueryImageFileExecutionOptions (IN PUNICODE_STRING SubKey,
IN PCWSTR ValueName,
IN ULONG Type,
KeyInfo = RtlAllocateHeap (RtlGetProcessHeap(),
HEAP_ZERO_MEMORY,
KeyInfoSize);
+ if (KeyInfo == NULL)
+ {
+ NtClose (KeyHandle);
+ return STATUS_INSUFFICIENT_RESOURCES;
+ }
RtlInitUnicodeString (&ValueNameString,
(PWSTR)ValueName);
if (KeyInfo == NULL)
{
NtClose (KeyHandle);
- return Status;
+ return STATUS_INSUFFICIENT_RESOURCES;
}
Status = NtQueryValueKey (KeyHandle,
}
-PIMAGE_BASE_RELOCATION STDCALL
+PIMAGE_BASE_RELOCATION NTAPI
LdrProcessRelocationBlock(IN PVOID Address,
IN USHORT Count,
IN PUSHORT TypeOffset,