mirror of
https://github.com/reactos/reactos.git
synced 2025-04-27 00:50:23 +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
|
* COPYRIGHT: See COPYING in the top level directory
|
||||||
* PROJECT: ReactOS kernel
|
* PROJECT: ReactOS kernel
|
||||||
* FILE: lib/ntdll/ldr/startup.c
|
* FILE: dll/ntdll/ldr/startup.c
|
||||||
* PURPOSE: Process startup for PE executables
|
* PURPOSE: Process startup for PE executables
|
||||||
* PROGRAMMERS: Jean Michault
|
* PROGRAMMERS: Jean Michault
|
||||||
* Rex Jolliff (rex@lvcablemodem.com)
|
* Rex Jolliff (rex@lvcablemodem.com)
|
||||||
|
@ -17,25 +17,27 @@
|
||||||
VOID RtlInitializeHeapManager(VOID);
|
VOID RtlInitializeHeapManager(VOID);
|
||||||
VOID LdrpInitLoader(VOID);
|
VOID LdrpInitLoader(VOID);
|
||||||
VOID NTAPI RtlpInitDeferedCriticalSection(VOID);
|
VOID NTAPI RtlpInitDeferedCriticalSection(VOID);
|
||||||
|
NTSTATUS LdrpAttachThread(VOID);
|
||||||
|
VOID RtlpInitializeVectoredExceptionHandling(VOID);
|
||||||
|
|
||||||
/* GLOBALS *******************************************************************/
|
/* GLOBALS *******************************************************************/
|
||||||
|
|
||||||
|
PLDR_DATA_TABLE_ENTRY ExeModule;
|
||||||
static RTL_CRITICAL_SECTION PebLock;
|
static RTL_CRITICAL_SECTION PebLock;
|
||||||
static RTL_CRITICAL_SECTION LoaderLock;
|
static RTL_CRITICAL_SECTION LoaderLock;
|
||||||
static RTL_BITMAP TlsBitMap;
|
static RTL_BITMAP TlsBitMap;
|
||||||
static RTL_BITMAP TlsExpansionBitMap;
|
static RTL_BITMAP TlsExpansionBitMap;
|
||||||
PLDR_DATA_TABLE_ENTRY ExeModule;
|
|
||||||
|
|
||||||
NTSTATUS LdrpAttachThread (VOID);
|
|
||||||
|
|
||||||
VOID RtlpInitializeVectoredExceptionHandling(VOID);
|
|
||||||
|
|
||||||
|
|
||||||
#define VALUE_BUFFER_SIZE 256
|
#define VALUE_BUFFER_SIZE 256
|
||||||
|
|
||||||
BOOLEAN FASTCALL
|
/* FUNCTIONS *****************************************************************/
|
||||||
ReadCompatibilitySetting(HANDLE Key, LPWSTR Value, PKEY_VALUE_PARTIAL_INFORMATION ValueInfo, DWORD *Buffer)
|
|
||||||
|
BOOLEAN
|
||||||
|
FASTCALL
|
||||||
|
ReadCompatibilitySetting(HANDLE Key,
|
||||||
|
LPWSTR Value,
|
||||||
|
PKEY_VALUE_PARTIAL_INFORMATION ValueInfo,
|
||||||
|
DWORD * Buffer)
|
||||||
{
|
{
|
||||||
UNICODE_STRING ValueName;
|
UNICODE_STRING ValueName;
|
||||||
NTSTATUS Status;
|
NTSTATUS Status;
|
||||||
|
@ -54,12 +56,14 @@ ReadCompatibilitySetting(HANDLE Key, LPWSTR Value, PKEY_VALUE_PARTIAL_INFORMATIO
|
||||||
RtlFreeUnicodeString(&ValueName);
|
RtlFreeUnicodeString(&ValueName);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
RtlCopyMemory(Buffer, &ValueInfo->Data[0], sizeof(DWORD));
|
RtlCopyMemory(Buffer, &ValueInfo->Data[0], sizeof(DWORD));
|
||||||
RtlFreeUnicodeString(&ValueName);
|
RtlFreeUnicodeString(&ValueName);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
VOID FASTCALL
|
VOID
|
||||||
|
FASTCALL
|
||||||
LoadImageFileExecutionOptions(PPEB Peb)
|
LoadImageFileExecutionOptions(PPEB Peb)
|
||||||
{
|
{
|
||||||
NTSTATUS Status = STATUS_SUCCESS;
|
NTSTATUS Status = STATUS_SUCCESS;
|
||||||
|
@ -78,6 +82,7 @@ LoadImageFileExecutionOptions(PPEB Peb)
|
||||||
ImagePathName = Peb->ProcessParameters->ImagePathName;
|
ImagePathName = Peb->ProcessParameters->ImagePathName;
|
||||||
ImageName.Buffer = ImagePathName.Buffer + ImagePathName.Length / sizeof(WCHAR);
|
ImageName.Buffer = ImagePathName.Buffer + ImagePathName.Length / sizeof(WCHAR);
|
||||||
ImageName.Length = 0;
|
ImageName.Length = 0;
|
||||||
|
|
||||||
while (ImagePathName.Buffer < ImageName.Buffer)
|
while (ImagePathName.Buffer < ImageName.Buffer)
|
||||||
{
|
{
|
||||||
ImageName.Buffer--;
|
ImageName.Buffer--;
|
||||||
|
@ -87,8 +92,11 @@ LoadImageFileExecutionOptions(PPEB Peb)
|
||||||
break;
|
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);
|
DPRINT("%wZ\n", &ImageName);
|
||||||
|
|
||||||
|
@ -118,10 +126,8 @@ LoadImageFileExecutionOptions(PPEB Peb)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOLEAN
|
||||||
|
FASTCALL
|
||||||
|
|
||||||
BOOLEAN FASTCALL
|
|
||||||
LoadCompatibilitySettings(PPEB Peb)
|
LoadCompatibilitySettings(PPEB Peb)
|
||||||
{
|
{
|
||||||
NTSTATUS Status;
|
NTSTATUS Status;
|
||||||
|
@ -141,8 +147,7 @@ LoadCompatibilitySettings(PPEB Peb)
|
||||||
if (Peb->ProcessParameters &&
|
if (Peb->ProcessParameters &&
|
||||||
(Peb->ProcessParameters->ImagePathName.Length > 0))
|
(Peb->ProcessParameters->ImagePathName.Length > 0))
|
||||||
{
|
{
|
||||||
Status = RtlOpenCurrentUser(KEY_READ,
|
Status = RtlOpenCurrentUser(KEY_READ, &UserKey);
|
||||||
&UserKey);
|
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
@ -154,13 +159,12 @@ LoadCompatibilitySettings(PPEB Peb)
|
||||||
UserKey,
|
UserKey,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
Status = NtOpenKey(&KeyHandle,
|
Status = NtOpenKey(&KeyHandle, KEY_QUERY_VALUE, &ObjectAttributes);
|
||||||
KEY_QUERY_VALUE,
|
|
||||||
&ObjectAttributes);
|
|
||||||
|
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
if (UserKey) NtClose(UserKey);
|
if (UserKey)
|
||||||
|
NtClose(UserKey);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,7 +180,8 @@ LoadCompatibilitySettings(PPEB Peb)
|
||||||
if (!NT_SUCCESS(Status) || (ValueInfo->Type != REG_SZ))
|
if (!NT_SUCCESS(Status) || (ValueInfo->Type != REG_SZ))
|
||||||
{
|
{
|
||||||
NtClose(KeyHandle);
|
NtClose(KeyHandle);
|
||||||
if (UserKey) NtClose(UserKey);
|
if (UserKey)
|
||||||
|
NtClose(UserKey);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -191,14 +196,13 @@ LoadCompatibilitySettings(PPEB Peb)
|
||||||
KeyHandle,
|
KeyHandle,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
Status = NtOpenKey(&SubKeyHandle,
|
Status = NtOpenKey(&SubKeyHandle, KEY_QUERY_VALUE, &ObjectAttributes);
|
||||||
KEY_QUERY_VALUE,
|
|
||||||
&ObjectAttributes);
|
|
||||||
|
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
NtClose(KeyHandle);
|
NtClose(KeyHandle);
|
||||||
if (UserKey) NtClose(UserKey);
|
if (UserKey)
|
||||||
|
NtClose(UserKey);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -221,22 +225,31 @@ LoadCompatibilitySettings(PPEB Peb)
|
||||||
Peb->OSPlatformId = (ULONG) PlatformId;
|
Peb->OSPlatformId = (ULONG) PlatformId;
|
||||||
|
|
||||||
/* optional service pack version numbers */
|
/* optional service pack version numbers */
|
||||||
if(ReadCompatibilitySetting(SubKeyHandle, L"SPMajorVersion", ValueInfo, &SPMajorVersion) &&
|
if (ReadCompatibilitySetting(SubKeyHandle,
|
||||||
ReadCompatibilitySetting(SubKeyHandle, L"SPMinorVersion", ValueInfo, &SPMinorVersion))
|
L"SPMajorVersion",
|
||||||
Peb->OSCSDVersion = ((SPMajorVersion & 0xFF) << 8) | (SPMinorVersion & 0xFF);
|
ValueInfo,
|
||||||
|
&SPMajorVersion) &&
|
||||||
|
ReadCompatibilitySetting(SubKeyHandle,
|
||||||
|
L"SPMinorVersion",
|
||||||
|
ValueInfo,
|
||||||
|
&SPMinorVersion))
|
||||||
|
{
|
||||||
|
Peb->OSCSDVersion = ((SPMajorVersion & 0xFF) << 8) |
|
||||||
|
(SPMinorVersion & 0xFF);
|
||||||
|
}
|
||||||
|
|
||||||
finish:
|
finish:
|
||||||
/* we're finished */
|
/* we're finished */
|
||||||
NtClose(SubKeyHandle);
|
NtClose(SubKeyHandle);
|
||||||
NtClose(KeyHandle);
|
NtClose(KeyHandle);
|
||||||
if (UserKey) NtClose(UserKey);
|
if (UserKey)
|
||||||
|
NtClose(UserKey);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* FUNCTIONS *****************************************************************/
|
|
||||||
|
|
||||||
VOID
|
VOID
|
||||||
NTAPI
|
NTAPI
|
||||||
LdrpInit(PCONTEXT Context,
|
LdrpInit(PCONTEXT Context,
|
||||||
|
@ -333,22 +346,18 @@ LdrpInit(PCONTEXT Context,
|
||||||
Peb->FastPebUnlockRoutine = (PPEBLOCKROUTINE)RtlLeaveCriticalSection;
|
Peb->FastPebUnlockRoutine = (PPEBLOCKROUTINE)RtlLeaveCriticalSection;
|
||||||
|
|
||||||
/* initialize tls bitmaps */
|
/* initialize tls bitmaps */
|
||||||
RtlInitializeBitMap (&TlsBitMap,
|
RtlInitializeBitMap(&TlsBitMap, Peb->TlsBitmapBits, TLS_MINIMUM_AVAILABLE);
|
||||||
Peb->TlsBitmapBits,
|
RtlInitializeBitMap(&TlsExpansionBitMap, Peb->TlsExpansionBitmapBits, TLS_EXPANSION_SLOTS);
|
||||||
TLS_MINIMUM_AVAILABLE);
|
|
||||||
RtlInitializeBitMap (&TlsExpansionBitMap,
|
|
||||||
Peb->TlsExpansionBitmapBits,
|
|
||||||
TLS_EXPANSION_SLOTS);
|
|
||||||
|
|
||||||
Peb->TlsBitmap = &TlsBitMap;
|
Peb->TlsBitmap = &TlsBitMap;
|
||||||
Peb->TlsExpansionBitmap = &TlsExpansionBitMap;
|
Peb->TlsExpansionBitmap = &TlsExpansionBitMap;
|
||||||
Peb->TlsExpansionCounter = TLS_MINIMUM_AVAILABLE;
|
Peb->TlsExpansionCounter = TLS_MINIMUM_AVAILABLE;
|
||||||
|
|
||||||
/* Initialize table of callbacks for the kernel. */
|
/* Initialize table of callbacks for the kernel. */
|
||||||
Peb->KernelCallbackTable =
|
Peb->KernelCallbackTable = RtlAllocateHeap(RtlGetProcessHeap(),
|
||||||
RtlAllocateHeap(RtlGetProcessHeap(),
|
|
||||||
0,
|
0,
|
||||||
sizeof(PVOID) * (USER32_CALLBACK_MAXIMUM + 1));
|
sizeof(PVOID) *
|
||||||
|
(USER32_CALLBACK_MAXIMUM + 1));
|
||||||
if (Peb->KernelCallbackTable == NULL)
|
if (Peb->KernelCallbackTable == NULL)
|
||||||
{
|
{
|
||||||
DPRINT1("Failed to create callback table\n");
|
DPRINT1("Failed to create callback table\n");
|
||||||
|
@ -368,6 +377,7 @@ LdrpInit(PCONTEXT Context,
|
||||||
DPRINT1("Failed to create loader data\n");
|
DPRINT1("Failed to create loader data\n");
|
||||||
ZwTerminateProcess(NtCurrentProcess(), STATUS_INSUFFICIENT_RESOURCES);
|
ZwTerminateProcess(NtCurrentProcess(), STATUS_INSUFFICIENT_RESOURCES);
|
||||||
}
|
}
|
||||||
|
|
||||||
Peb->Ldr->Length = sizeof(PEB_LDR_DATA);
|
Peb->Ldr->Length = sizeof(PEB_LDR_DATA);
|
||||||
Peb->Ldr->Initialized = FALSE;
|
Peb->Ldr->Initialized = FALSE;
|
||||||
Peb->Ldr->SsHandle = NULL;
|
Peb->Ldr->SsHandle = NULL;
|
||||||
|
@ -386,7 +396,8 @@ LdrpInit(PCONTEXT Context,
|
||||||
wcscat(FullNtDllPath, L"\\system32\\ntdll.dll");
|
wcscat(FullNtDllPath, L"\\system32\\ntdll.dll");
|
||||||
|
|
||||||
/* add entry for ntdll */
|
/* add entry for ntdll */
|
||||||
NtModule = (PLDR_DATA_TABLE_ENTRY)RtlAllocateHeap (Peb->ProcessHeap,
|
NtModule = (PLDR_DATA_TABLE_ENTRY)
|
||||||
|
RtlAllocateHeap(Peb->ProcessHeap,
|
||||||
0,
|
0,
|
||||||
sizeof(LDR_DATA_TABLE_ENTRY));
|
sizeof(LDR_DATA_TABLE_ENTRY));
|
||||||
if (NtModule == NULL)
|
if (NtModule == NULL)
|
||||||
|
@ -398,10 +409,8 @@ LdrpInit(PCONTEXT Context,
|
||||||
|
|
||||||
NtModule->DllBase = BaseAddress;
|
NtModule->DllBase = BaseAddress;
|
||||||
NtModule->EntryPoint = 0; /* no entry point */
|
NtModule->EntryPoint = 0; /* no entry point */
|
||||||
RtlCreateUnicodeString (&NtModule->FullDllName,
|
RtlCreateUnicodeString(&NtModule->FullDllName, FullNtDllPath);
|
||||||
FullNtDllPath);
|
RtlCreateUnicodeString(&NtModule->BaseDllName, L"ntdll.dll");
|
||||||
RtlCreateUnicodeString (&NtModule->BaseDllName,
|
|
||||||
L"ntdll.dll");
|
|
||||||
NtModule->Flags = LDRP_IMAGE_DLL | LDRP_ENTRY_PROCESSED;
|
NtModule->Flags = LDRP_IMAGE_DLL | LDRP_ENTRY_PROCESSED;
|
||||||
|
|
||||||
NtModule->LoadCount = -1; /* don't unload */
|
NtModule->LoadCount = -1; /* don't unload */
|
||||||
|
@ -428,7 +437,8 @@ LdrpInit(PCONTEXT Context,
|
||||||
if (NtCurrentPeb()->Ldr->Initialized == FALSE)
|
if (NtCurrentPeb()->Ldr->Initialized == FALSE)
|
||||||
{
|
{
|
||||||
/* add entry for executable (becomes first list entry) */
|
/* 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,
|
0,
|
||||||
sizeof(LDR_DATA_TABLE_ENTRY));
|
sizeof(LDR_DATA_TABLE_ENTRY));
|
||||||
if (ExeModule == NULL)
|
if (ExeModule == NULL)
|
||||||
|
@ -436,6 +446,7 @@ LdrpInit(PCONTEXT Context,
|
||||||
DPRINT1("Failed to create loader module infomation\n");
|
DPRINT1("Failed to create loader module infomation\n");
|
||||||
ZwTerminateProcess(NtCurrentProcess(), STATUS_INSUFFICIENT_RESOURCES);
|
ZwTerminateProcess(NtCurrentProcess(), STATUS_INSUFFICIENT_RESOURCES);
|
||||||
}
|
}
|
||||||
|
|
||||||
ExeModule->DllBase = Peb->ImageBaseAddress;
|
ExeModule->DllBase = Peb->ImageBaseAddress;
|
||||||
|
|
||||||
if ((Peb->ProcessParameters == NULL) ||
|
if ((Peb->ProcessParameters == NULL) ||
|
||||||
|
@ -450,9 +461,7 @@ LdrpInit(PCONTEXT Context,
|
||||||
RtlCreateUnicodeString(&ExeModule->BaseDllName,
|
RtlCreateUnicodeString(&ExeModule->BaseDllName,
|
||||||
wcsrchr(ExeModule->FullDllName.Buffer, L'\\') + 1);
|
wcsrchr(ExeModule->FullDllName.Buffer, L'\\') + 1);
|
||||||
|
|
||||||
DPRINT("BaseDllName '%wZ' FullDllName '%wZ'\n",
|
DPRINT("BaseDllName '%wZ' FullDllName '%wZ'\n", &ExeModule->BaseDllName, &ExeModule->FullDllName);
|
||||||
&ExeModule->BaseDllName,
|
|
||||||
&ExeModule->FullDllName);
|
|
||||||
|
|
||||||
ExeModule->Flags = LDRP_ENTRY_PROCESSED;
|
ExeModule->Flags = LDRP_ENTRY_PROCESSED;
|
||||||
ExeModule->LoadCount = -1; /* don't unload */
|
ExeModule->LoadCount = -1; /* don't unload */
|
||||||
|
@ -489,7 +498,8 @@ LdrpInit(PCONTEXT Context,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Break into debugger */
|
/* Break into debugger */
|
||||||
if (Peb->BeingDebugged) DbgBreakPoint();
|
if (Peb->BeingDebugged)
|
||||||
|
DbgBreakPoint();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* attach the thread */
|
/* attach the thread */
|
||||||
|
|
Loading…
Reference in a new issue