[FORMATTING] Fix indentation.

svn path=/trunk/; revision=38354
This commit is contained in:
Dmitry Gorbachev 2008-12-26 13:50:35 +00:00
parent fd4de76baf
commit 4d4d9e60fb

View file

@ -1,7 +1,7 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: lib/ntdll/ldr/startup.c
* FILE: dll/ntdll/ldr/startup.c
* PURPOSE: Process startup for PE executables
* PROGRAMMERS: Jean Michault
* Rex Jolliff (rex@lvcablemodem.com)
@ -14,28 +14,30 @@
#include <debug.h>
#include <win32k/callback.h>
VOID RtlInitializeHeapManager (VOID);
VOID RtlInitializeHeapManager(VOID);
VOID LdrpInitLoader(VOID);
VOID NTAPI RtlpInitDeferedCriticalSection(VOID);
NTSTATUS LdrpAttachThread(VOID);
VOID RtlpInitializeVectoredExceptionHandling(VOID);
/* GLOBALS *******************************************************************/
PLDR_DATA_TABLE_ENTRY ExeModule;
static RTL_CRITICAL_SECTION PebLock;
static RTL_CRITICAL_SECTION LoaderLock;
static RTL_BITMAP TlsBitMap;
static RTL_BITMAP TlsExpansionBitMap;
PLDR_DATA_TABLE_ENTRY ExeModule;
NTSTATUS LdrpAttachThread (VOID);
VOID RtlpInitializeVectoredExceptionHandling(VOID);
#define VALUE_BUFFER_SIZE 256
BOOLEAN FASTCALL
ReadCompatibilitySetting(HANDLE Key, LPWSTR Value, PKEY_VALUE_PARTIAL_INFORMATION ValueInfo, DWORD *Buffer)
/* FUNCTIONS *****************************************************************/
BOOLEAN
FASTCALL
ReadCompatibilitySetting(HANDLE Key,
LPWSTR Value,
PKEY_VALUE_PARTIAL_INFORMATION ValueInfo,
DWORD * Buffer)
{
UNICODE_STRING ValueName;
NTSTATUS Status;
@ -54,12 +56,14 @@ ReadCompatibilitySetting(HANDLE Key, LPWSTR Value, PKEY_VALUE_PARTIAL_INFORMATIO
RtlFreeUnicodeString(&ValueName);
return FALSE;
}
RtlCopyMemory(Buffer, &ValueInfo->Data[0], sizeof(DWORD));
RtlFreeUnicodeString(&ValueName);
return TRUE;
}
VOID FASTCALL
VOID
FASTCALL
LoadImageFileExecutionOptions(PPEB Peb)
{
NTSTATUS Status = STATUS_SUCCESS;
@ -78,6 +82,7 @@ LoadImageFileExecutionOptions(PPEB Peb)
ImagePathName = Peb->ProcessParameters->ImagePathName;
ImageName.Buffer = ImagePathName.Buffer + ImagePathName.Length / sizeof(WCHAR);
ImageName.Length = 0;
while (ImagePathName.Buffer < ImageName.Buffer)
{
ImageName.Buffer--;
@ -87,13 +92,16 @@ LoadImageFileExecutionOptions(PPEB Peb)
break;
}
}
ImageName.Length = ImagePathName.Length - (ImageName.Buffer - ImagePathName.Buffer) * sizeof(WCHAR);
ImageName.MaximumLength = ImageName.Length + ImagePathName.MaximumLength - ImagePathName.Length;
ImageName.Length = ImagePathName.Length -
(ImageName.Buffer - ImagePathName.Buffer) * sizeof(WCHAR);
ImageName.MaximumLength = ImageName.Length +
ImagePathName.MaximumLength - ImagePathName.Length;
DPRINT("%wZ\n", &ImageName);
/* global flag */
Status = LdrQueryImageFileExecutionOptions (&ImageName,
Status = LdrQueryImageFileExecutionOptions(&ImageName,
L"GlobalFlag",
REG_SZ,
(PVOID)ValueBuffer,
@ -118,10 +126,8 @@ LoadImageFileExecutionOptions(PPEB Peb)
}
}
BOOLEAN FASTCALL
BOOLEAN
FASTCALL
LoadCompatibilitySettings(PPEB Peb)
{
NTSTATUS Status;
@ -136,13 +142,12 @@ LoadCompatibilitySettings(PPEB Peb)
PKEY_VALUE_PARTIAL_INFORMATION ValueInfo;
ULONG Length;
DWORD MajorVersion, MinorVersion, BuildNumber, PlatformId,
SPMajorVersion, SPMinorVersion= 0;
SPMajorVersion, SPMinorVersion = 0;
if(Peb->ProcessParameters &&
if (Peb->ProcessParameters &&
(Peb->ProcessParameters->ImagePathName.Length > 0))
{
Status = RtlOpenCurrentUser(KEY_READ,
&UserKey);
Status = RtlOpenCurrentUser(KEY_READ, &UserKey);
if (!NT_SUCCESS(Status))
{
return FALSE;
@ -154,18 +159,17 @@ LoadCompatibilitySettings(PPEB Peb)
UserKey,
NULL);
Status = NtOpenKey(&KeyHandle,
KEY_QUERY_VALUE,
&ObjectAttributes);
Status = NtOpenKey(&KeyHandle, KEY_QUERY_VALUE, &ObjectAttributes);
if (!NT_SUCCESS(Status))
{
if (UserKey) NtClose(UserKey);
if (UserKey)
NtClose(UserKey);
return FALSE;
}
/* query version name for application */
ValueInfo = (PKEY_VALUE_PARTIAL_INFORMATION)ValueBuffer;
ValueInfo = (PKEY_VALUE_PARTIAL_INFORMATION) ValueBuffer;
Status = NtQueryValueKey(KeyHandle,
&Peb->ProcessParameters->ImagePathName,
KeyValuePartialInformation,
@ -176,13 +180,14 @@ LoadCompatibilitySettings(PPEB Peb)
if (!NT_SUCCESS(Status) || (ValueInfo->Type != REG_SZ))
{
NtClose(KeyHandle);
if (UserKey) NtClose(UserKey);
if (UserKey)
NtClose(UserKey);
return FALSE;
}
ValueName.Length = ValueInfo->DataLength;
ValueName.MaximumLength = ValueInfo->DataLength;
ValueName.Buffer = (PWSTR)ValueInfo->Data;
ValueName.Buffer = (PWSTR) ValueInfo->Data;
/* load version info */
InitializeObjectAttributes(&ObjectAttributes,
@ -191,52 +196,60 @@ LoadCompatibilitySettings(PPEB Peb)
KeyHandle,
NULL);
Status = NtOpenKey(&SubKeyHandle,
KEY_QUERY_VALUE,
&ObjectAttributes);
Status = NtOpenKey(&SubKeyHandle, KEY_QUERY_VALUE, &ObjectAttributes);
if (!NT_SUCCESS(Status))
{
NtClose(KeyHandle);
if (UserKey) NtClose(UserKey);
if (UserKey)
NtClose(UserKey);
return FALSE;
}
DPRINT("Loading version information for: %wZ\n", &ValueName);
/* read settings from registry */
if(!ReadCompatibilitySetting(SubKeyHandle, L"MajorVersion", ValueInfo, &MajorVersion))
if (!ReadCompatibilitySetting(SubKeyHandle, L"MajorVersion", ValueInfo, &MajorVersion))
goto finish;
if(!ReadCompatibilitySetting(SubKeyHandle, L"MinorVersion", ValueInfo, &MinorVersion))
if (!ReadCompatibilitySetting(SubKeyHandle, L"MinorVersion", ValueInfo, &MinorVersion))
goto finish;
if(!ReadCompatibilitySetting(SubKeyHandle, L"BuildNumber", ValueInfo, &BuildNumber))
if (!ReadCompatibilitySetting(SubKeyHandle, L"BuildNumber", ValueInfo, &BuildNumber))
goto finish;
if(!ReadCompatibilitySetting(SubKeyHandle, L"PlatformId", ValueInfo, &PlatformId))
if (!ReadCompatibilitySetting(SubKeyHandle, L"PlatformId", ValueInfo, &PlatformId))
goto finish;
/* now assign the settings */
Peb->OSMajorVersion = (ULONG)MajorVersion;
Peb->OSMinorVersion = (ULONG)MinorVersion;
Peb->OSBuildNumber = (USHORT)BuildNumber;
Peb->OSPlatformId = (ULONG)PlatformId;
Peb->OSMajorVersion = (ULONG) MajorVersion;
Peb->OSMinorVersion = (ULONG) MinorVersion;
Peb->OSBuildNumber = (USHORT) BuildNumber;
Peb->OSPlatformId = (ULONG) PlatformId;
/* optional service pack version numbers */
if(ReadCompatibilitySetting(SubKeyHandle, L"SPMajorVersion", ValueInfo, &SPMajorVersion) &&
ReadCompatibilitySetting(SubKeyHandle, L"SPMinorVersion", ValueInfo, &SPMinorVersion))
Peb->OSCSDVersion = ((SPMajorVersion & 0xFF) << 8) | (SPMinorVersion & 0xFF);
if (ReadCompatibilitySetting(SubKeyHandle,
L"SPMajorVersion",
ValueInfo,
&SPMajorVersion) &&
ReadCompatibilitySetting(SubKeyHandle,
L"SPMinorVersion",
ValueInfo,
&SPMinorVersion))
{
Peb->OSCSDVersion = ((SPMajorVersion & 0xFF) << 8) |
(SPMinorVersion & 0xFF);
}
finish:
/* we're finished */
NtClose(SubKeyHandle);
NtClose(KeyHandle);
if (UserKey) NtClose(UserKey);
if (UserKey)
NtClose(UserKey);
return TRUE;
}
return FALSE;
}
/* FUNCTIONS *****************************************************************/
VOID
NTAPI
LdrpInit(PCONTEXT Context,
@ -262,7 +275,7 @@ LdrpInit(PCONTEXT Context,
if (NtCurrentPeb()->Ldr == NULL)
{
if (ImageBase <= (PVOID)0x1000)
if (ImageBase <= (PVOID) 0x1000)
{
DPRINT("ImageBase is null\n");
ZwTerminateProcess(NtCurrentProcess(), STATUS_INVALID_IMAGE_FORMAT);
@ -281,14 +294,14 @@ LdrpInit(PCONTEXT Context,
}
/* normalize process parameters */
RtlNormalizeProcessParams (Peb->ProcessParameters);
RtlNormalizeProcessParams(Peb->ProcessParameters);
/* Initialize NLS data */
RtlInitNlsTables (Peb->AnsiCodePageData,
RtlInitNlsTables(Peb->AnsiCodePageData,
Peb->OemCodePageData,
Peb->UnicodeCaseTableData,
&NlsTable);
RtlResetRtlTranslations (&NlsTable);
RtlResetRtlTranslations(&NlsTable);
NTHeaders = (PIMAGE_NT_HEADERS)((ULONG_PTR)ImageBase + PEDosHeader->e_lfanew);
@ -327,40 +340,36 @@ LdrpInit(PCONTEXT Context,
RtlpInitializeVectoredExceptionHandling();
/* initalize peb lock support */
RtlInitializeCriticalSection (&PebLock);
RtlInitializeCriticalSection(&PebLock);
Peb->FastPebLock = &PebLock;
Peb->FastPebLockRoutine = (PPEBLOCKROUTINE)RtlEnterCriticalSection;
Peb->FastPebUnlockRoutine = (PPEBLOCKROUTINE)RtlLeaveCriticalSection;
/* initialize tls bitmaps */
RtlInitializeBitMap (&TlsBitMap,
Peb->TlsBitmapBits,
TLS_MINIMUM_AVAILABLE);
RtlInitializeBitMap (&TlsExpansionBitMap,
Peb->TlsExpansionBitmapBits,
TLS_EXPANSION_SLOTS);
RtlInitializeBitMap(&TlsBitMap, Peb->TlsBitmapBits, TLS_MINIMUM_AVAILABLE);
RtlInitializeBitMap(&TlsExpansionBitMap, Peb->TlsExpansionBitmapBits, TLS_EXPANSION_SLOTS);
Peb->TlsBitmap = &TlsBitMap;
Peb->TlsExpansionBitmap = &TlsExpansionBitMap;
Peb->TlsExpansionCounter = TLS_MINIMUM_AVAILABLE;
/* Initialize table of callbacks for the kernel. */
Peb->KernelCallbackTable =
RtlAllocateHeap(RtlGetProcessHeap(),
Peb->KernelCallbackTable = RtlAllocateHeap(RtlGetProcessHeap(),
0,
sizeof(PVOID) * (USER32_CALLBACK_MAXIMUM + 1));
sizeof(PVOID) *
(USER32_CALLBACK_MAXIMUM + 1));
if (Peb->KernelCallbackTable == NULL)
{
DPRINT1("Failed to create callback table\n");
ZwTerminateProcess(NtCurrentProcess(),STATUS_INSUFFICIENT_RESOURCES);
ZwTerminateProcess(NtCurrentProcess(), STATUS_INSUFFICIENT_RESOURCES);
}
/* initalize loader lock */
RtlInitializeCriticalSection (&LoaderLock);
RtlInitializeCriticalSection(&LoaderLock);
Peb->LoaderLock = &LoaderLock;
/* create loader information */
Peb->Ldr = (PPEB_LDR_DATA)RtlAllocateHeap (Peb->ProcessHeap,
Peb->Ldr = (PPEB_LDR_DATA) RtlAllocateHeap(Peb->ProcessHeap,
0,
sizeof(PEB_LDR_DATA));
if (Peb->Ldr == NULL)
@ -368,6 +377,7 @@ LdrpInit(PCONTEXT Context,
DPRINT1("Failed to create loader data\n");
ZwTerminateProcess(NtCurrentProcess(), STATUS_INSUFFICIENT_RESOURCES);
}
Peb->Ldr->Length = sizeof(PEB_LDR_DATA);
Peb->Ldr->Initialized = FALSE;
Peb->Ldr->SsHandle = NULL;
@ -382,11 +392,12 @@ LdrpInit(PCONTEXT Context,
LoadImageFileExecutionOptions(Peb);
/* build full ntdll path */
wcscpy (FullNtDllPath, SharedUserData->NtSystemRoot);
wcscat (FullNtDllPath, L"\\system32\\ntdll.dll");
wcscpy(FullNtDllPath, SharedUserData->NtSystemRoot);
wcscat(FullNtDllPath, L"\\system32\\ntdll.dll");
/* add entry for ntdll */
NtModule = (PLDR_DATA_TABLE_ENTRY)RtlAllocateHeap (Peb->ProcessHeap,
NtModule = (PLDR_DATA_TABLE_ENTRY)
RtlAllocateHeap(Peb->ProcessHeap,
0,
sizeof(LDR_DATA_TABLE_ENTRY));
if (NtModule == NULL)
@ -398,18 +409,16 @@ LdrpInit(PCONTEXT Context,
NtModule->DllBase = BaseAddress;
NtModule->EntryPoint = 0; /* no entry point */
RtlCreateUnicodeString (&NtModule->FullDllName,
FullNtDllPath);
RtlCreateUnicodeString (&NtModule->BaseDllName,
L"ntdll.dll");
NtModule->Flags = LDRP_IMAGE_DLL|LDRP_ENTRY_PROCESSED;
RtlCreateUnicodeString(&NtModule->FullDllName, FullNtDllPath);
RtlCreateUnicodeString(&NtModule->BaseDllName, L"ntdll.dll");
NtModule->Flags = LDRP_IMAGE_DLL | LDRP_ENTRY_PROCESSED;
NtModule->LoadCount = -1; /* don't unload */
NtModule->TlsIndex = -1;
NtModule->SectionPointer = NULL;
NtModule->CheckSum = 0;
NTHeaders = RtlImageNtHeader (NtModule->DllBase);
NTHeaders = RtlImageNtHeader(NtModule->DllBase);
NtModule->SizeOfImage = LdrpGetResidentSize(NTHeaders);
NtModule->TimeDateStamp = NTHeaders->FileHeader.TimeDateStamp;
@ -428,7 +437,8 @@ LdrpInit(PCONTEXT Context,
if (NtCurrentPeb()->Ldr->Initialized == FALSE)
{
/* add entry for executable (becomes first list entry) */
ExeModule = (PLDR_DATA_TABLE_ENTRY)RtlAllocateHeap (Peb->ProcessHeap,
ExeModule = (PLDR_DATA_TABLE_ENTRY)
RtlAllocateHeap(Peb->ProcessHeap,
0,
sizeof(LDR_DATA_TABLE_ENTRY));
if (ExeModule == NULL)
@ -436,13 +446,14 @@ LdrpInit(PCONTEXT Context,
DPRINT1("Failed to create loader module infomation\n");
ZwTerminateProcess(NtCurrentProcess(), STATUS_INSUFFICIENT_RESOURCES);
}
ExeModule->DllBase = Peb->ImageBaseAddress;
if ((Peb->ProcessParameters == NULL) ||
(Peb->ProcessParameters->ImagePathName.Length == 0))
{
DPRINT1("Failed to access the process parameter block\n");
ZwTerminateProcess(NtCurrentProcess(),STATUS_UNSUCCESSFUL);
ZwTerminateProcess(NtCurrentProcess(), STATUS_UNSUCCESSFUL);
}
RtlCreateUnicodeString(&ExeModule->FullDllName,
@ -450,9 +461,7 @@ LdrpInit(PCONTEXT Context,
RtlCreateUnicodeString(&ExeModule->BaseDllName,
wcsrchr(ExeModule->FullDllName.Buffer, L'\\') + 1);
DPRINT("BaseDllName '%wZ' FullDllName '%wZ'\n",
&ExeModule->BaseDllName,
&ExeModule->FullDllName);
DPRINT("BaseDllName '%wZ' FullDllName '%wZ'\n", &ExeModule->BaseDllName, &ExeModule->FullDllName);
ExeModule->Flags = LDRP_ENTRY_PROCESSED;
ExeModule->LoadCount = -1; /* don't unload */
@ -460,7 +469,7 @@ LdrpInit(PCONTEXT Context,
ExeModule->SectionPointer = NULL;
ExeModule->CheckSum = 0;
NTHeaders = RtlImageNtHeader (ExeModule->DllBase);
NTHeaders = RtlImageNtHeader(ExeModule->DllBase);
ExeModule->SizeOfImage = LdrpGetResidentSize(NTHeaders);
ExeModule->TimeDateStamp = NTHeaders->FileHeader.TimeDateStamp;
@ -489,7 +498,8 @@ LdrpInit(PCONTEXT Context,
}
/* Break into debugger */
if (Peb->BeingDebugged) DbgBreakPoint();
if (Peb->BeingDebugged)
DbgBreakPoint();
}
/* attach the thread */