return FALSE;
}
-static inline LONG LdrpDecrementLoadCount(PLDR_DATA_TABLE_ENTRY Module, BOOLEAN Locked)
+static __inline LONG LdrpDecrementLoadCount(PLDR_DATA_TABLE_ENTRY Module, BOOLEAN Locked)
{
LONG LoadCount;
if (!Locked)
RtlEnterCriticalSection (NtCurrentPeb()->LoaderLock);
}
LoadCount = Module->LoadCount;
- if (Module->LoadCount > 0)
+ if (Module->LoadCount > 0 && Module->LoadCount != 0xFFFF)
{
Module->LoadCount--;
}
return LoadCount;
}
-static inline LONG LdrpIncrementLoadCount(PLDR_DATA_TABLE_ENTRY Module, BOOLEAN Locked)
+static __inline LONG LdrpIncrementLoadCount(PLDR_DATA_TABLE_ENTRY Module, BOOLEAN Locked)
{
LONG LoadCount;
if (!Locked)
RtlEnterCriticalSection (NtCurrentPeb()->LoaderLock);
}
LoadCount = Module->LoadCount;
- if (Module->LoadCount >= 0)
+ if (Module->LoadCount != 0xFFFF)
{
Module->LoadCount++;
}
return LoadCount;
}
-static inline VOID LdrpAcquireTlsSlot(PLDR_DATA_TABLE_ENTRY Module, ULONG Size, BOOLEAN Locked)
+static __inline VOID LdrpAcquireTlsSlot(PLDR_DATA_TABLE_ENTRY Module, ULONG Size, BOOLEAN Locked)
{
if (!Locked)
{
}
}
-static inline VOID LdrpTlsCallback(PLDR_DATA_TABLE_ENTRY Module, ULONG dwReason)
+static __inline VOID LdrpTlsCallback(PLDR_DATA_TABLE_ENTRY Module, ULONG dwReason)
{
PIMAGE_TLS_CALLBACK TlsCallback;
- if (Module->TlsIndex >= 0 && Module->LoadCount == -1)
+ if (Module->TlsIndex != 0xFFFF && Module->LoadCount == 0xFFFF)
{
TlsCallback = LdrpTlsArray[Module->TlsIndex].TlsAddressOfCallBacks;
if (TlsCallback)
TRACE_LDR("%wZ - Calling tls callback at %x\n",
&Module->BaseDllName, TlsCallback);
TlsCallback(Module->DllBase, dwReason, NULL);
- TlsCallback++;
+ TlsCallback = (PIMAGE_TLS_CALLBACK)((ULONG_PTR)TlsCallback + sizeof(PVOID));
}
}
}
static BOOLEAN LdrpCallDllEntry(PLDR_DATA_TABLE_ENTRY Module, DWORD dwReason, PVOID lpReserved)
{
- if (!(Module->Flags & IMAGE_DLL) ||
+ if (!(Module->Flags & LDRP_IMAGE_DLL) ||
Module->EntryPoint == 0)
{
return TRUE;
return STATUS_NO_MEMORY;
}
- TlsData = (PVOID)TlsPointers + LdrpTlsCount * sizeof(PVOID);
+ TlsData = (PVOID)((ULONG_PTR)TlsPointers + LdrpTlsCount * sizeof(PVOID));
Teb->ThreadLocalStoragePointer = TlsPointers;
TlsInfo = LdrpTlsArray;
if (TlsInfo->TlsDataSize)
{
memcpy(TlsData, TlsInfo->StartAddressOfRawData, TlsInfo->TlsDataSize);
- TlsData += TlsInfo->TlsDataSize;
+ TlsData = (PVOID)((ULONG_PTR)TlsData + TlsInfo->TlsDataSize);
}
if (TlsInfo->TlsZeroSize)
{
memset(TlsData, 0, TlsInfo->TlsZeroSize);
- TlsData += TlsInfo->TlsZeroSize;
+ TlsData = (PVOID)((ULONG_PTR)TlsData + TlsInfo->TlsZeroSize);
}
}
}
PLDR_DATA_TABLE_ENTRY Module;
PIMAGE_TLS_DIRECTORY TlsDirectory;
PTLS_DATA TlsData;
+ ULONG Size;
DPRINT("LdrpInitializeTlsForProccess() called for %wZ\n", &ExeModule->BaseDllName);
while (Entry != ModuleListHead)
{
Module = CONTAINING_RECORD(Entry, LDR_DATA_TABLE_ENTRY, InLoadOrderModuleList);
- if (Module->LoadCount == -1 &&
- Module->TlsIndex >= 0)
+ if (Module->LoadCount == 0xFFFF &&
+ Module->TlsIndex != 0xFFFF)
{
TlsDirectory = (PIMAGE_TLS_DIRECTORY)
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;
Module->DllBase = (PVOID)ImageBase;
Module->EntryPoint = (PVOID)NTHeaders->OptionalHeader.AddressOfEntryPoint;
if (Module->EntryPoint != 0)
- Module->EntryPoint += (ULONG)Module->DllBase;
+ Module->EntryPoint = (PVOID)((ULONG_PTR)Module->EntryPoint + (ULONG_PTR)Module->DllBase);
Module->SizeOfImage = LdrpGetResidentSize(NTHeaders);
if (NtCurrentPeb()->Ldr->Initialized == TRUE)
{
* loading while app is initializing
* dll must not be unloaded
*/
- Module->LoadCount = -1;
+ Module->LoadCount = 0xFFFF;
}
Module->Flags = 0;
&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)
{
DPRINT("Scanning %wZ at %p\n", &ModulePtr->BaseDllName, ModulePtr->DllBase);
if ((Address >= ModulePtr->DllBase) &&
- (Address <= (ModulePtr->DllBase + ModulePtr->SizeOfImage)))
+ ((ULONG_PTR)Address <= ((ULONG_PTR)ModulePtr->DllBase + ModulePtr->SizeOfImage)))
{
*Module = ModulePtr;
RtlLeaveCriticalSection(NtCurrentPeb()->LoaderLock);
0 == RtlCompareUnicodeString(&LdrpLastModule->FullDllName, &AdjustedName, TRUE)))
{
*Module = LdrpLastModule;
- if (Ref && (*Module)->LoadCount != -1)
+ if (Ref && (*Module)->LoadCount != 0xFFFF)
{
(*Module)->LoadCount++;
}
0 == RtlCompareUnicodeString(&ModulePtr->FullDllName, &AdjustedName, TRUE)))
{
*Module = LdrpLastModule = ModulePtr;
- if (Ref && ModulePtr->LoadCount != -1)
+ if (Ref && ModulePtr->LoadCount != 0xFFFF)
{
ModulePtr->LoadCount++;
}
ExportDir->AddressOfFunctions
);
DPRINT(
- "LdrGetExportByOrdinal(Ordinal %d) = %x\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;
}
{
Count = (RelocationDir->SizeOfBlock - sizeof(IMAGE_BASE_RELOCATION)) /
sizeof(USHORT);
- Page = ImageBase + RelocationDir->VirtualAddress;
+ Page = (PVOID)((ULONG_PTR)ImageBase + (ULONG_PTR)RelocationDir->VirtualAddress);
TypeOffset = (PUSHORT)(RelocationDir + 1);
/* Unprotect the page(s) we're about to relocate. */
if (RelocationDir->VirtualAddress + PAGE_SIZE <
NTHeaders->OptionalHeader.SizeOfImage)
{
- ProtectPage2 = ProtectPage + PAGE_SIZE;
+ ProtectPage2 = (PVOID)((ULONG_PTR)ProtectPage + PAGE_SIZE);
Status = NtProtectVirtualMemory(NtCurrentProcess(),
&ProtectPage2,
&ProtectSize,
}
/* Get the import address list. */
- ImportAddressList = (PVOID *)(Module->DllBase + (ULONG_PTR)ImportModuleDirectory->FirstThunk);
+ ImportAddressList = (PVOID *)((ULONG_PTR)Module->DllBase + (ULONG_PTR)ImportModuleDirectory->FirstThunk);
/* Get the list of functions to import. */
if (ImportModuleDirectory->OriginalFirstThunk != 0)
{
- FunctionNameList = (PULONG) (Module->DllBase + (ULONG_PTR)ImportModuleDirectory->OriginalFirstThunk);
+ FunctionNameList = (PULONG) ((ULONG_PTR)Module->DllBase + (ULONG_PTR)ImportModuleDirectory->OriginalFirstThunk);
}
else
{
- FunctionNameList = (PULONG)(Module->DllBase + (ULONG_PTR)ImportModuleDirectory->FirstThunk);
+ FunctionNameList = (PULONG)((ULONG_PTR)Module->DllBase + (ULONG_PTR)ImportModuleDirectory->FirstThunk);
}
/* Get the size of IAT. */
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;
{
/* Get the import address list. */
- ImportAddressList = (PVOID *)(Module->DllBase + (ULONG_PTR)ImportModuleDirectory->FirstThunk);
+ ImportAddressList = (PVOID *)((ULONG_PTR)Module->DllBase + (ULONG_PTR)ImportModuleDirectory->FirstThunk);
/* Get the list of functions to import. */
if (ImportModuleDirectory->OriginalFirstThunk != 0)
{
- FunctionNameList = (PULONG) (Module->DllBase + (ULONG_PTR)ImportModuleDirectory->OriginalFirstThunk);
+ FunctionNameList = (PULONG) ((ULONG_PTR)Module->DllBase + (ULONG_PTR)ImportModuleDirectory->OriginalFirstThunk);
}
else
{
- FunctionNameList = (PULONG)(Module->DllBase + (ULONG_PTR)ImportModuleDirectory->FirstThunk);
+ FunctionNameList = (PULONG)((ULONG_PTR)Module->DllBase + (ULONG_PTR)ImportModuleDirectory->FirstThunk);
}
/* Get the size of IAT. */
NTHeaders = RtlImageNtHeader (ImportedModule->DllBase);
Start = (PVOID)NTHeaders->OptionalHeader.ImageBase;
- End = Start + ImportedModule->SizeOfImage;
- Offset = ImportedModule->DllBase - Start;
+ End = (PVOID)((ULONG_PTR)Start + ImportedModule->SizeOfImage);
+ Offset = (ULONG)((ULONG_PTR)ImportedModule->DllBase - (ULONG_PTR)Start);
/* Walk through function list and fixup addresses. */
while (*FunctionNameList != 0L)
{
if (*ImportAddressList >= Start && *ImportAddressList < End)
{
- (*ImportAddressList) += Offset;
+ (*ImportAddressList) = (PVOID)((ULONG_PTR)(*ImportAddressList) + Offset);
}
ImportAddressList++;
FunctionNameList++;
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)
{
BOOLEAN WrongForwarder;
WrongForwarder = FALSE;
- if (ImportedModule->Flags & IMAGE_NOT_AT_BASE)
+ if (ImportedModule->Flags & LDRP_IMAGE_NOT_AT_BASE)
{
TRACE_LDR("%wZ has stale binding to %s\n",
&Module->BaseDllName, ImportedName);
LdrpDecrementLoadCount(Module, FALSE);
}
if (ForwarderModule->TimeDateStamp != BoundForwarderRef->TimeDateStamp ||
- ForwarderModule->Flags & IMAGE_NOT_AT_BASE)
+ ForwarderModule->Flags & LDRP_IMAGE_NOT_AT_BASE)
{
TRACE_LDR("%wZ has stale binding to %s\n",
&Module->BaseDllName, ForwarderName);
}
}
if (WrongForwarder ||
- ImportedModule->Flags & IMAGE_NOT_AT_BASE)
+ ImportedModule->Flags & LDRP_IMAGE_NOT_AT_BASE)
{
Status = LdrpProcessImportDirectory(Module, ImportedModule, ImportedName);
if (!NT_SUCCESS(Status))
return Status;
}
}
- else if (ImportedModule->Flags & IMAGE_NOT_AT_BASE)
+ else if (ImportedModule->Flags & LDRP_IMAGE_NOT_AT_BASE)
{
TRACE_LDR("Adjust imports for %s from %wZ\n",
ImportedName, &Module->BaseDllName);
}
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
* to the DLL's image.
*/
DosHeader = (PIMAGE_DOS_HEADER) ImageBase;
- NTHeaders = (PIMAGE_NT_HEADERS) (ImageBase + DosHeader->e_lfanew);
+ NTHeaders = (PIMAGE_NT_HEADERS) ((ULONG_PTR)ImageBase + DosHeader->e_lfanew);
/*
* If the base address is different from the
if (ImageBase != (PVOID) NTHeaders->OptionalHeader.ImageBase)
{
- (*Module)->Flags |= IMAGE_NOT_AT_BASE;
+ (*Module)->Flags |= LDRP_IMAGE_NOT_AT_BASE;
}
/*
/*
* 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) (ImageBase
+ 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))
(*Module)->SectionPointer = SectionHandle;
if (ImageBase != (PVOID) NtHeaders->OptionalHeader.ImageBase)
{
- (*Module)->Flags |= IMAGE_NOT_AT_BASE;
+ (*Module)->Flags |= LDRP_IMAGE_NOT_AT_BASE;
}
if (NtHeaders->FileHeader.Characteristics & IMAGE_FILE_DLL)
{
- (*Module)->Flags |= IMAGE_DLL;
+ (*Module)->Flags |= LDRP_IMAGE_DLL;
}
/* fixup the imported calls entry points */
Status = LdrFixupImports(SearchPath, *Module);
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)
{
- if (Module->TlsIndex == -1)
+ if (Module->TlsIndex == 0xFFFF)
{
- Module->Flags |= DONT_CALL_FOR_THREAD;
+ Module->Flags |= LDRP_DONT_CALL_FOR_THREADS;
Status = STATUS_SUCCESS;
}
break;
/*
* @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) &&
- Module->Flags & ENTRY_PROCESSED &&
- !(Module->Flags & UNLOAD_IN_PROGRESS))
+ if (((UnloadAll && Module->LoadCount == 0xFFFF) || Module->LoadCount == 0) &&
+ Module->Flags & LDRP_ENTRY_PROCESSED &&
+ !(Module->Flags & LDRP_UNLOAD_IN_PROGRESS))
{
- Module->Flags |= UNLOAD_IN_PROGRESS;
+ Module->Flags |= LDRP_UNLOAD_IN_PROGRESS;
if (Module == LdrpLastModule)
{
LdrpLastModule = NULL;
}
- if (Module->Flags & PROCESS_ATTACH_CALLED)
+ if (Module->Flags & LDRP_PROCESS_ATTACH_CALLED)
{
TRACE_LDR("Unload %wZ - Calling entry point at %x\n",
&Module->BaseDllName, Module->EntryPoint);
- LdrpCallDllEntry(Module, DLL_PROCESS_DETACH, (PVOID)(Module->LoadCount == -1 ? 1 : 0));
+ LdrpCallDllEntry(Module, DLL_PROCESS_DETACH, (PVOID)(Module->LoadCount == 0xFFFF ? 1 : 0));
}
else
{
{
Module = CONTAINING_RECORD(Entry, LDR_DATA_TABLE_ENTRY, InInitializationOrderModuleList);
Entry = Entry->Blink;
- if (Module->Flags & UNLOAD_IN_PROGRESS &&
- ((UnloadAll && Module->LoadCount >= 0) || Module->LoadCount == 0))
+ if (Module->Flags & LDRP_UNLOAD_IN_PROGRESS &&
+ ((UnloadAll && Module->LoadCount != 0xFFFF) || Module->LoadCount == 0))
{
/* remove the module entry from the list */
RemoveEntryList (&Module->InLoadOrderModuleList);
while (Entry != ModuleListHead)
{
Module = CONTAINING_RECORD(Entry, LDR_DATA_TABLE_ENTRY, InInitializationOrderModuleList);
- if (!(Module->Flags & (LOAD_IN_PROGRESS|UNLOAD_IN_PROGRESS|ENTRY_PROCESSED)))
+ if (!(Module->Flags & (LDRP_LOAD_IN_PROGRESS|LDRP_UNLOAD_IN_PROGRESS|LDRP_ENTRY_PROCESSED)))
{
- Module->Flags |= LOAD_IN_PROGRESS;
+ Module->Flags |= LDRP_LOAD_IN_PROGRESS;
TRACE_LDR("%wZ loaded - Calling init routine at %x for process attaching\n",
&Module->BaseDllName, Module->EntryPoint);
- Result = LdrpCallDllEntry(Module, DLL_PROCESS_ATTACH, (PVOID)(Module->LoadCount == -1 ? 1 : 0));
+ Result = LdrpCallDllEntry(Module, DLL_PROCESS_ATTACH, (PVOID)(Module->LoadCount == 0xFFFF ? 1 : 0));
if (!Result)
{
Status = STATUS_DLL_INIT_FAILED;
break;
}
- if (Module->Flags & IMAGE_DLL && Module->EntryPoint != 0)
+ if (Module->Flags & LDRP_IMAGE_DLL && Module->EntryPoint != 0)
{
- Module->Flags |= PROCESS_ATTACH_CALLED|ENTRY_PROCESSED;
+ Module->Flags |= LDRP_PROCESS_ATTACH_CALLED|LDRP_ENTRY_PROCESSED;
}
else
{
- Module->Flags |= ENTRY_PROCESSED;
+ Module->Flags |= LDRP_ENTRY_PROCESSED;
}
- Module->Flags &= ~LOAD_IN_PROGRESS;
+ Module->Flags &= ~LDRP_LOAD_IN_PROGRESS;
}
Entry = Entry->Flink;
}
/*
* @implemented
*/
-NTSTATUS STDCALL
+NTSTATUS NTAPI
LdrShutdownProcess (VOID)
{
LdrpDetachProcess(TRUE);
while (Entry != ModuleListHead)
{
Module = CONTAINING_RECORD(Entry, LDR_DATA_TABLE_ENTRY, InInitializationOrderModuleList);
- if (Module->Flags & PROCESS_ATTACH_CALLED &&
- !(Module->Flags & DONT_CALL_FOR_THREAD) &&
- !(Module->Flags & UNLOAD_IN_PROGRESS))
+ if (Module->Flags & LDRP_PROCESS_ATTACH_CALLED &&
+ !(Module->Flags & LDRP_DONT_CALL_FOR_THREADS) &&
+ !(Module->Flags & LDRP_UNLOAD_IN_PROGRESS))
{
TRACE_LDR("%wZ - Calling entry point at %x for thread attaching\n",
&Module->BaseDllName, Module->EntryPoint);
/*
* @implemented
*/
-NTSTATUS STDCALL
+NTSTATUS NTAPI
LdrShutdownThread (VOID)
{
PLIST_ENTRY ModuleListHead;
{
Module = CONTAINING_RECORD(Entry, LDR_DATA_TABLE_ENTRY, InInitializationOrderModuleList);
- if (Module->Flags & PROCESS_ATTACH_CALLED &&
- !(Module->Flags & DONT_CALL_FOR_THREAD) &&
- !(Module->Flags & UNLOAD_IN_PROGRESS))
+ if (Module->Flags & LDRP_PROCESS_ATTACH_CALLED &&
+ !(Module->Flags & LDRP_DONT_CALL_FOR_THREADS) &&
+ !(Module->Flags & LDRP_UNLOAD_IN_PROGRESS))
{
TRACE_LDR("%wZ - Calling entry point at %x for thread detaching\n",
&Module->BaseDllName, Module->EntryPoint);
*
* @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,
break;
case IMAGE_REL_BASED_HIGH:
- ShortPtr = (PUSHORT)(Address + Offset);
+ ShortPtr = (PUSHORT)((ULONG_PTR)Address + Offset);
*ShortPtr += HIWORD(Delta);
break;
case IMAGE_REL_BASED_LOW:
- ShortPtr = (PUSHORT)(Address + Offset);
+ ShortPtr = (PUSHORT)((ULONG_PTR)Address + Offset);
*ShortPtr += LOWORD(Delta);
break;
case IMAGE_REL_BASED_HIGHLOW:
- LongPtr = (PULONG)(Address + Offset);
+ LongPtr = (PULONG)((ULONG_PTR)Address + Offset);
*LongPtr += Delta;
break;