/* INCLUDES *****************************************************************/
#include <ntdll.h>
-#include <win32k/callback.h>
+#include <callback.h>
#define NDEBUG
#include <debug.h>
ULONG LdrpNumberOfTlsEntries;
ULONG LdrpNumberOfProcessors;
PVOID NtDllBase;
-LARGE_INTEGER RtlpTimeout;
+extern LARGE_INTEGER RtlpTimeout;
BOOLEAN RtlpTimeoutDisable;
LIST_ENTRY LdrpHashTable[LDR_HASH_TABLE_ENTRIES];
LIST_ENTRY LdrpDllNotificationList;
VOID RtlpInitializeVectoredExceptionHandling(VOID);
VOID NTAPI RtlpInitDeferedCriticalSection(VOID);
-VOID RtlInitializeHeapManager(VOID);
+VOID NTAPI RtlInitializeHeapManager(VOID);
extern BOOLEAN RtlpPageHeapEnabled;
ULONG RtlpDisableHeapLookaside; // TODO: Move to heap.c
/* Setup the object attributes */
InitializeObjectAttributes(&ObjectAttributes,
- Wow64 ?
+ Wow64 ?
&Wow64OptionsString : &ImageExecOptionsString,
OBJ_CASE_INSENSITIVE,
NULL,
KeyValueInformation = RtlAllocateHeap(RtlGetProcessHeap(),
0,
KeyInfoSize);
- if (KeyValueInformation == NULL)
+ if (KeyValueInformation != NULL)
+ {
+ /* Try again */
+ Status = ZwQueryValueKey(KeyHandle,
+ &ValueNameString,
+ KeyValuePartialInformation,
+ KeyValueInformation,
+ KeyInfoSize,
+ &ResultSize);
+ FreeHeap = TRUE;
+ }
+ else
{
/* Give up this time */
Status = STATUS_NO_MEMORY;
}
-
- /* Try again */
- Status = ZwQueryValueKey(KeyHandle,
- &ValueNameString,
- KeyValuePartialInformation,
- KeyValueInformation,
- KeyInfoSize,
- &ResultSize);
- FreeHeap = TRUE;
}
/* Check for success */
{
PULONG_PTR Cookie;
LARGE_INTEGER Counter;
- ULONG NewCookie;
+ ULONG_PTR NewCookie;
/* Fetch address of the cookie */
Cookie = LdrpFetchAddressOfSecurityCookie(LdrEntry->DllBase, LdrEntry->SizeOfImage);
/* Allocate an Activation Context Stack */
DPRINT("ActivationContextStack %p\n", NtCurrentTeb()->ActivationContextStackPointer);
- Status = RtlAllocateActivationContextStack((PVOID*)&NtCurrentTeb()->ActivationContextStackPointer);
+ Status = RtlAllocateActivationContextStack(&NtCurrentTeb()->ActivationContextStackPointer);
if (!NT_SUCCESS(Status))
{
DPRINT1("Warning: Unable to allocate ActivationContextStack\n");
EntryPoint = LdrEntry->EntryPoint;
/* Check if we are ready to call it */
- if ((EntryPoint) &&
+ if ((EntryPoint) &&
(LdrEntry->Flags & LDRP_PROCESS_ATTACH_CALLED) &&
(LdrEntry->Flags & LDRP_IMAGE_DLL))
{
/* Allocate space for all the entries */
LdrRootEntry = RtlAllocateHeap(RtlGetProcessHeap(),
0,
- Count * sizeof(LdrRootEntry));
+ Count * sizeof(*LdrRootEntry));
if (!LdrRootEntry) return STATUS_NO_MEMORY;
}
else
if (LdrEntry->EntryPoint)
{
/* Write in array */
+ ASSERT(i < Count);
LdrRootEntry[i] = LdrEntry;
/* Display debug message */
EntryPoint = LdrEntry->EntryPoint;
/* Check if we are ready to call it */
- if (EntryPoint &&
+ if (EntryPoint &&
(LdrEntry->Flags & LDRP_PROCESS_ATTACH_CALLED) &&
LdrEntry->Flags)
{
PTEB Teb = NtCurrentTeb();
PLIST_ENTRY NextEntry, ListHead;
PLDRP_TLS_DATA TlsData;
- ULONG TlsDataSize;
+ SIZE_T TlsDataSize;
PVOID *TlsVector;
/* Check if we have any entries */
NextEntry = NextEntry->Flink;
/* Allocate this vector */
- TlsDataSize = TlsData->TlsDirectory.EndAddressOfRawData -
+ TlsDataSize = TlsData->TlsDirectory.EndAddressOfRawData -
TlsData->TlsDirectory.StartAddressOfRawData;
TlsVector[TlsData->TlsDirectory.Characteristics] = RtlAllocateHeap(RtlGetProcessHeap(),
0,
ULONG HeapFlags;
PIMAGE_NT_HEADERS NtHeader;
LPWSTR NtDllName = NULL;
- NTSTATUS Status;
+ NTSTATUS Status, ImportStatus;
NLSTABLEINFO NlsTable;
PIMAGE_LOAD_CONFIG_DIRECTORY LoadConfig;
PTEB Teb = NtCurrentTeb();
/* Normalize the parameters */
ProcessParameters = RtlNormalizeProcessParams(Peb->ProcessParameters);
- ProcessParameters = Peb->ProcessParameters;
if (ProcessParameters)
{
/* Save the Image and Command Line Names */
}
/* Allocate an Activation Context Stack */
- Status = RtlAllocateActivationContextStack((PVOID *)&Teb->ActivationContextStackPointer);
+ Status = RtlAllocateActivationContextStack(&Teb->ActivationContextStackPointer);
if (!NT_SUCCESS(Status)) return Status;
// FIXME: Loader private heap is missing
}
/* Walk the IAT and load all the DLLs */
- LdrpWalkImportDescriptor(LdrpDefaultPath.Buffer, LdrpImageEntry);
+ ImportStatus = LdrpWalkImportDescriptor(LdrpDefaultPath.Buffer, LdrpImageEntry);
/* Check if relocation is needed */
if (Peb->ImageBaseAddress != (PVOID)NtHeader->OptionalHeader.ImageBase)
{
DPRINT1("LDR: Performing EXE relocation\n");
-
+
/* Change the protection to prepare for relocation */
ViewBase = Peb->ImageBaseAddress;
Status = LdrpSetProtection(ViewBase, FALSE);
DPRINT1("LdrRelocateImageWithBias() failed\n");
return Status;
}
-
+
/* Check if a start context was provided */
if (Context)
{
UNIMPLEMENTED; // We should support this
return STATUS_INVALID_IMAGE_FORMAT;
}
-
+
/* Restore the protection */
Status = LdrpSetProtection(ViewBase, TRUE);
if (!NT_SUCCESS(Status)) return Status;
/* Phase 0 is done */
LdrpLdrDatabaseIsSetup = TRUE;
+ /* Check whether all static imports were properly loaded and return here */
+ if (!NT_SUCCESS(ImportStatus)) return ImportStatus;
+
/* Initialize TLS */
Status = LdrpInitializeTls();
if (!NT_SUCCESS(Status))