mirror of
https://github.com/reactos/reactos.git
synced 2025-08-04 22:46:43 +00:00
[FORMATTING] Fix indentation.
svn path=/trunk/; revision=38354
This commit is contained in:
parent
fd4de76baf
commit
4d4d9e60fb
1 changed files with 365 additions and 355 deletions
|
@ -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)
|
||||
|
@ -17,25 +17,27 @@
|
|||
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,8 +92,11 @@ 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);
|
||||
|
||||
|
@ -118,10 +126,8 @@ LoadImageFileExecutionOptions(PPEB Peb)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
BOOLEAN FASTCALL
|
||||
BOOLEAN
|
||||
FASTCALL
|
||||
LoadCompatibilitySettings(PPEB Peb)
|
||||
{
|
||||
NTSTATUS Status;
|
||||
|
@ -141,8 +147,7 @@ LoadCompatibilitySettings(PPEB Peb)
|
|||
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,13 +159,12 @@ 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;
|
||||
}
|
||||
|
||||
|
@ -176,7 +180,8 @@ LoadCompatibilitySettings(PPEB Peb)
|
|||
if (!NT_SUCCESS(Status) || (ValueInfo->Type != REG_SZ))
|
||||
{
|
||||
NtClose(KeyHandle);
|
||||
if (UserKey) NtClose(UserKey);
|
||||
if (UserKey)
|
||||
NtClose(UserKey);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
@ -191,14 +196,13 @@ 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;
|
||||
}
|
||||
|
||||
|
@ -221,22 +225,31 @@ LoadCompatibilitySettings(PPEB Peb)
|
|||
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,
|
||||
|
@ -333,22 +346,18 @@ LdrpInit(PCONTEXT Context,
|
|||
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");
|
||||
|
@ -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;
|
||||
|
@ -386,7 +396,8 @@ LdrpInit(PCONTEXT Context,
|
|||
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,10 +409,8 @@ LdrpInit(PCONTEXT Context,
|
|||
|
||||
NtModule->DllBase = BaseAddress;
|
||||
NtModule->EntryPoint = 0; /* no entry point */
|
||||
RtlCreateUnicodeString (&NtModule->FullDllName,
|
||||
FullNtDllPath);
|
||||
RtlCreateUnicodeString (&NtModule->BaseDllName,
|
||||
L"ntdll.dll");
|
||||
RtlCreateUnicodeString(&NtModule->FullDllName, FullNtDllPath);
|
||||
RtlCreateUnicodeString(&NtModule->BaseDllName, L"ntdll.dll");
|
||||
NtModule->Flags = LDRP_IMAGE_DLL | LDRP_ENTRY_PROCESSED;
|
||||
|
||||
NtModule->LoadCount = -1; /* don't unload */
|
||||
|
@ -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,6 +446,7 @@ LdrpInit(PCONTEXT Context,
|
|||
DPRINT1("Failed to create loader module infomation\n");
|
||||
ZwTerminateProcess(NtCurrentProcess(), STATUS_INSUFFICIENT_RESOURCES);
|
||||
}
|
||||
|
||||
ExeModule->DllBase = Peb->ImageBaseAddress;
|
||||
|
||||
if ((Peb->ProcessParameters == NULL) ||
|
||||
|
@ -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 */
|
||||
|
@ -489,7 +498,8 @@ LdrpInit(PCONTEXT Context,
|
|||
}
|
||||
|
||||
/* Break into debugger */
|
||||
if (Peb->BeingDebugged) DbgBreakPoint();
|
||||
if (Peb->BeingDebugged)
|
||||
DbgBreakPoint();
|
||||
}
|
||||
|
||||
/* attach the thread */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue