mirror of
https://github.com/reactos/reactos.git
synced 2025-08-06 06:22:58 +00:00
[NTOS]: Better clean up behind ourselves on failure paths (aka. closing handles). These functions are clearly not written with correct cleanup-on-failure concept in mind...
svn path=/trunk/; revision=74735
This commit is contained in:
parent
7d14e79c4c
commit
07a0591894
2 changed files with 62 additions and 16 deletions
|
@ -382,7 +382,8 @@ CmpInitializeMachineDependentConfiguration(IN PLOADER_PARAMETER_BLOCK LoaderBloc
|
||||||
NULL,
|
NULL,
|
||||||
NULL);
|
NULL);
|
||||||
Status = NtOpenKey(&SystemHandle, KEY_READ | KEY_WRITE, &ObjectAttributes);
|
Status = NtOpenKey(&SystemHandle, KEY_READ | KEY_WRITE, &ObjectAttributes);
|
||||||
if (!NT_SUCCESS(Status)) return Status;
|
if (!NT_SUCCESS(Status))
|
||||||
|
return Status;
|
||||||
|
|
||||||
/* Create the BIOS Information key */
|
/* Create the BIOS Information key */
|
||||||
RtlInitUnicodeString(&KeyName,
|
RtlInitUnicodeString(&KeyName,
|
||||||
|
@ -406,7 +407,10 @@ CmpInitializeMachineDependentConfiguration(IN PLOADER_PARAMETER_BLOCK LoaderBloc
|
||||||
BiosHandle = NULL;
|
BiosHandle = NULL;
|
||||||
}
|
}
|
||||||
else if (!NT_SUCCESS(Status))
|
else if (!NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
NtClose(SystemHandle);
|
||||||
return Status;
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
/* Create the CPU Key, and check if it already existed */
|
/* Create the CPU Key, and check if it already existed */
|
||||||
RtlInitUnicodeString(&KeyName, L"CentralProcessor");
|
RtlInitUnicodeString(&KeyName, L"CentralProcessor");
|
||||||
|
@ -431,7 +435,11 @@ CmpInitializeMachineDependentConfiguration(IN PLOADER_PARAMETER_BLOCK LoaderBloc
|
||||||
CmpConfigurationData = ExAllocatePoolWithTag(PagedPool,
|
CmpConfigurationData = ExAllocatePoolWithTag(PagedPool,
|
||||||
CmpConfigurationAreaSize,
|
CmpConfigurationAreaSize,
|
||||||
TAG_CM);
|
TAG_CM);
|
||||||
if (!CmpConfigurationData) return STATUS_INSUFFICIENT_RESOURCES;
|
if (!CmpConfigurationData)
|
||||||
|
{
|
||||||
|
// FIXME: Cleanup stuff!!
|
||||||
|
return STATUS_INSUFFICIENT_RESOURCES;
|
||||||
|
}
|
||||||
|
|
||||||
/* Loop all CPUs */
|
/* Loop all CPUs */
|
||||||
for (i = 0; i < KeNumberProcessors; i++)
|
for (i = 0; i < KeNumberProcessors; i++)
|
||||||
|
@ -440,7 +448,7 @@ CmpInitializeMachineDependentConfiguration(IN PLOADER_PARAMETER_BLOCK LoaderBloc
|
||||||
Prcb = KiProcessorBlock[i];
|
Prcb = KiProcessorBlock[i];
|
||||||
|
|
||||||
/* Setup the Configuration Entry for the Processor */
|
/* Setup the Configuration Entry for the Processor */
|
||||||
RtlZeroMemory(&ConfigData, sizeof (ConfigData));
|
RtlZeroMemory(&ConfigData, sizeof(ConfigData));
|
||||||
ConfigData.ComponentEntry.Class = ProcessorClass;
|
ConfigData.ComponentEntry.Class = ProcessorClass;
|
||||||
ConfigData.ComponentEntry.Type = CentralProcessor;
|
ConfigData.ComponentEntry.Type = CentralProcessor;
|
||||||
ConfigData.ComponentEntry.Key = i;
|
ConfigData.ComponentEntry.Key = i;
|
||||||
|
@ -477,7 +485,12 @@ CmpInitializeMachineDependentConfiguration(IN PLOADER_PARAMETER_BLOCK LoaderBloc
|
||||||
InterfaceTypeUndefined,
|
InterfaceTypeUndefined,
|
||||||
0xFFFFFFFF,
|
0xFFFFFFFF,
|
||||||
IndexTable);
|
IndexTable);
|
||||||
if (!NT_SUCCESS(Status)) return(Status);
|
if (!NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
NtClose(BiosHandle);
|
||||||
|
NtClose(SystemHandle);
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
/* Check if we have an FPU */
|
/* Check if we have an FPU */
|
||||||
if (KeI386NpxPresent)
|
if (KeI386NpxPresent)
|
||||||
|
@ -505,8 +518,10 @@ CmpInitializeMachineDependentConfiguration(IN PLOADER_PARAMETER_BLOCK LoaderBloc
|
||||||
IndexTable);
|
IndexTable);
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
/* Failed, close the CPU handle and return */
|
/* We failed, close all the opened handles and return */
|
||||||
NtClose(KeyHandle);
|
NtClose(KeyHandle);
|
||||||
|
NtClose(BiosHandle);
|
||||||
|
NtClose(SystemHandle);
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -672,7 +687,15 @@ CmpInitializeMachineDependentConfiguration(IN PLOADER_PARAMETER_BLOCK LoaderBloc
|
||||||
Status = ZwOpenSection(&SectionHandle,
|
Status = ZwOpenSection(&SectionHandle,
|
||||||
SECTION_ALL_ACCESS,
|
SECTION_ALL_ACCESS,
|
||||||
&ObjectAttributes);
|
&ObjectAttributes);
|
||||||
if (!NT_SUCCESS(Status)) goto Quickie;
|
if (!NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
/* We failed, close all the opened handles and return */
|
||||||
|
// NtClose(KeyHandle);
|
||||||
|
NtClose(BiosHandle);
|
||||||
|
NtClose(SystemHandle);
|
||||||
|
/* 'Quickie' closes KeyHandle */
|
||||||
|
goto Quickie;
|
||||||
|
}
|
||||||
|
|
||||||
/* Map the first 1KB of memory to get the IVT */
|
/* Map the first 1KB of memory to get the IVT */
|
||||||
ViewSize = PAGE_SIZE;
|
ViewSize = PAGE_SIZE;
|
||||||
|
@ -939,7 +962,7 @@ CmpInitializeMachineDependentConfiguration(IN PLOADER_PARAMETER_BLOCK LoaderBloc
|
||||||
if (BiosVersion) ExFreePoolWithTag(BiosVersion, TAG_CM);
|
if (BiosVersion) ExFreePoolWithTag(BiosVersion, TAG_CM);
|
||||||
|
|
||||||
Quickie:
|
Quickie:
|
||||||
/* Close the procesor handle */
|
/* Close the processor handle */
|
||||||
NtClose(KeyHandle);
|
NtClose(KeyHandle);
|
||||||
return STATUS_SUCCESS;
|
return STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
|
@ -95,7 +95,7 @@ CmpGetBiosDate(IN PCHAR BiosStart,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Add slashes were we previously had NULLs */
|
/* Add slashes where we previously had NULLs */
|
||||||
CurrentDate[4] = CurrentDate[7] = '/';
|
CurrentDate[4] = CurrentDate[7] = '/';
|
||||||
|
|
||||||
/* Check which date is newer */
|
/* Check which date is newer */
|
||||||
|
@ -244,7 +244,7 @@ CmpInitializeMachineDependentConfiguration(IN PLOADER_PARAMETER_BLOCK LoaderBloc
|
||||||
PCHAR PartialString = NULL, BiosVersion;
|
PCHAR PartialString = NULL, BiosVersion;
|
||||||
CHAR CpuString[48];
|
CHAR CpuString[48];
|
||||||
PVOID BaseAddress = NULL;
|
PVOID BaseAddress = NULL;
|
||||||
LARGE_INTEGER ViewBase = {{0}};
|
LARGE_INTEGER ViewBase = {{0, 0}};
|
||||||
ULONG_PTR VideoRomBase;
|
ULONG_PTR VideoRomBase;
|
||||||
PCHAR CurrentVersion;
|
PCHAR CurrentVersion;
|
||||||
extern UNICODE_STRING KeRosProcessorName, KeRosBiosDate, KeRosBiosVersion;
|
extern UNICODE_STRING KeRosProcessorName, KeRosBiosDate, KeRosBiosVersion;
|
||||||
|
@ -287,7 +287,8 @@ CmpInitializeMachineDependentConfiguration(IN PLOADER_PARAMETER_BLOCK LoaderBloc
|
||||||
NULL,
|
NULL,
|
||||||
NULL);
|
NULL);
|
||||||
Status = NtOpenKey(&SystemHandle, KEY_READ | KEY_WRITE, &ObjectAttributes);
|
Status = NtOpenKey(&SystemHandle, KEY_READ | KEY_WRITE, &ObjectAttributes);
|
||||||
if (!NT_SUCCESS(Status)) return Status;
|
if (!NT_SUCCESS(Status))
|
||||||
|
return Status;
|
||||||
|
|
||||||
/* Create the BIOS Information key */
|
/* Create the BIOS Information key */
|
||||||
RtlInitUnicodeString(&KeyName,
|
RtlInitUnicodeString(&KeyName,
|
||||||
|
@ -311,7 +312,10 @@ CmpInitializeMachineDependentConfiguration(IN PLOADER_PARAMETER_BLOCK LoaderBloc
|
||||||
BiosHandle = NULL;
|
BiosHandle = NULL;
|
||||||
}
|
}
|
||||||
else if (!NT_SUCCESS(Status))
|
else if (!NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
NtClose(SystemHandle);
|
||||||
return Status;
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
/* Create the CPU Key, and check if it already existed */
|
/* Create the CPU Key, and check if it already existed */
|
||||||
RtlInitUnicodeString(&KeyName, L"CentralProcessor");
|
RtlInitUnicodeString(&KeyName, L"CentralProcessor");
|
||||||
|
@ -336,7 +340,11 @@ CmpInitializeMachineDependentConfiguration(IN PLOADER_PARAMETER_BLOCK LoaderBloc
|
||||||
CmpConfigurationData = ExAllocatePoolWithTag(PagedPool,
|
CmpConfigurationData = ExAllocatePoolWithTag(PagedPool,
|
||||||
CmpConfigurationAreaSize,
|
CmpConfigurationAreaSize,
|
||||||
TAG_CM);
|
TAG_CM);
|
||||||
if (!CmpConfigurationData) return STATUS_INSUFFICIENT_RESOURCES;
|
if (!CmpConfigurationData)
|
||||||
|
{
|
||||||
|
// FIXME: Cleanup stuff!!
|
||||||
|
return STATUS_INSUFFICIENT_RESOURCES;
|
||||||
|
}
|
||||||
|
|
||||||
/* Loop all CPUs */
|
/* Loop all CPUs */
|
||||||
for (i = 0; i < KeNumberProcessors; i++)
|
for (i = 0; i < KeNumberProcessors; i++)
|
||||||
|
@ -345,7 +353,7 @@ CmpInitializeMachineDependentConfiguration(IN PLOADER_PARAMETER_BLOCK LoaderBloc
|
||||||
Prcb = KiProcessorBlock[i];
|
Prcb = KiProcessorBlock[i];
|
||||||
|
|
||||||
/* Setup the Configuration Entry for the Processor */
|
/* Setup the Configuration Entry for the Processor */
|
||||||
RtlZeroMemory(&ConfigData, sizeof (ConfigData));
|
RtlZeroMemory(&ConfigData, sizeof(ConfigData));
|
||||||
ConfigData.ComponentEntry.Class = ProcessorClass;
|
ConfigData.ComponentEntry.Class = ProcessorClass;
|
||||||
ConfigData.ComponentEntry.Type = CentralProcessor;
|
ConfigData.ComponentEntry.Type = CentralProcessor;
|
||||||
ConfigData.ComponentEntry.Key = i;
|
ConfigData.ComponentEntry.Key = i;
|
||||||
|
@ -382,7 +390,12 @@ CmpInitializeMachineDependentConfiguration(IN PLOADER_PARAMETER_BLOCK LoaderBloc
|
||||||
InterfaceTypeUndefined,
|
InterfaceTypeUndefined,
|
||||||
0xFFFFFFFF,
|
0xFFFFFFFF,
|
||||||
IndexTable);
|
IndexTable);
|
||||||
if (!NT_SUCCESS(Status)) return(Status);
|
if (!NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
NtClose(BiosHandle);
|
||||||
|
NtClose(SystemHandle);
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
/* Setup the Configuration Entry for the FPU */
|
/* Setup the Configuration Entry for the FPU */
|
||||||
|
@ -408,8 +421,10 @@ CmpInitializeMachineDependentConfiguration(IN PLOADER_PARAMETER_BLOCK LoaderBloc
|
||||||
IndexTable);
|
IndexTable);
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
/* Failed, close the CPU handle and return */
|
/* We failed, close all the opened handles and return */
|
||||||
NtClose(KeyHandle);
|
NtClose(KeyHandle);
|
||||||
|
NtClose(BiosHandle);
|
||||||
|
NtClose(SystemHandle);
|
||||||
return Status;
|
return Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -428,7 +443,7 @@ CmpInitializeMachineDependentConfiguration(IN PLOADER_PARAMETER_BLOCK LoaderBloc
|
||||||
//Ki386Cpuid(0x80000000, &ExtendedId, &Dummy, &Dummy, &Dummy);
|
//Ki386Cpuid(0x80000000, &ExtendedId, &Dummy, &Dummy, &Dummy);
|
||||||
if (ExtendedId >= 0x80000004)
|
if (ExtendedId >= 0x80000004)
|
||||||
{
|
{
|
||||||
/* Do all the CPUIDs requred to get the full name */
|
/* Do all the CPUIDs required to get the full name */
|
||||||
PartialString = CpuString;
|
PartialString = CpuString;
|
||||||
for (ExtendedId = 2; ExtendedId <= 4; ExtendedId++)
|
for (ExtendedId = 2; ExtendedId <= 4; ExtendedId++)
|
||||||
{
|
{
|
||||||
|
@ -559,7 +574,15 @@ CmpInitializeMachineDependentConfiguration(IN PLOADER_PARAMETER_BLOCK LoaderBloc
|
||||||
Status = ZwOpenSection(&SectionHandle,
|
Status = ZwOpenSection(&SectionHandle,
|
||||||
SECTION_ALL_ACCESS,
|
SECTION_ALL_ACCESS,
|
||||||
&ObjectAttributes);
|
&ObjectAttributes);
|
||||||
if (!NT_SUCCESS(Status)) goto Quickie;
|
if (!NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
/* We failed, close all the opened handles and return */
|
||||||
|
// NtClose(KeyHandle);
|
||||||
|
NtClose(BiosHandle);
|
||||||
|
NtClose(SystemHandle);
|
||||||
|
/* 'Quickie' closes KeyHandle */
|
||||||
|
goto Quickie;
|
||||||
|
}
|
||||||
|
|
||||||
/* Map the first 1KB of memory to get the IVT */
|
/* Map the first 1KB of memory to get the IVT */
|
||||||
ViewSize = PAGE_SIZE;
|
ViewSize = PAGE_SIZE;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue