mirror of https://github.com/acidanthera/audk.git
Change BuildGuidHob and BuildGuidDataHob to return NULL upon failure.
Guarantee no memory corruption in an out of memory condition even in production builds. Signed-off-by: niruiyu Reviewed-by: mdkinney git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@11778 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
parent
2dfdd3eb97
commit
f99d3d23cb
|
@ -1,6 +1,6 @@
|
||||||
/*++
|
/*++
|
||||||
|
|
||||||
Copyright (c) 2004 - 2006, Intel Corporation. All rights reserved.<BR>
|
Copyright (c) 2004 - 2011, Intel Corporation. All rights reserved.<BR>
|
||||||
This program and the accompanying materials
|
This program and the accompanying materials
|
||||||
are licensed and made available under the terms and conditions of the BSD License
|
are licensed and made available under the terms and conditions of the BSD License
|
||||||
which accompanies this distribution. The full text of the license may be found at
|
which accompanies this distribution. The full text of the license may be found at
|
||||||
|
@ -210,7 +210,8 @@ BuildResourceDescriptorHob (
|
||||||
@param Guid The GUID to tag the customized HOB.
|
@param Guid The GUID to tag the customized HOB.
|
||||||
@param DataLength The size of the data payload for the GUID HOB.
|
@param DataLength The size of the data payload for the GUID HOB.
|
||||||
|
|
||||||
@return The start address of GUID HOB data.
|
@retval NULL The GUID HOB could not be allocated.
|
||||||
|
@retval others The start address of GUID HOB data.
|
||||||
|
|
||||||
**/
|
**/
|
||||||
VOID *
|
VOID *
|
||||||
|
@ -237,7 +238,8 @@ BuildGuidHob (
|
||||||
@param Data The data to be copied into the data field of the GUID HOB.
|
@param Data The data to be copied into the data field of the GUID HOB.
|
||||||
@param DataLength The size of the data payload for the GUID HOB.
|
@param DataLength The size of the data payload for the GUID HOB.
|
||||||
|
|
||||||
@return The start address of GUID HOB data.
|
@retval NULL The GUID HOB could not be allocated.
|
||||||
|
@retval others The start address of GUID HOB data.
|
||||||
|
|
||||||
**/
|
**/
|
||||||
VOID *
|
VOID *
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/*++
|
/*++
|
||||||
|
|
||||||
Copyright (c) 2004 - 2006, Intel Corporation. All rights reserved.<BR>
|
Copyright (c) 2004 - 2011, Intel Corporation. All rights reserved.<BR>
|
||||||
This program and the accompanying materials
|
This program and the accompanying materials
|
||||||
are licensed and made available under the terms and conditions of the BSD License
|
are licensed and made available under the terms and conditions of the BSD License
|
||||||
which accompanies this distribution. The full text of the license may be found at
|
which accompanies this distribution. The full text of the license may be found at
|
||||||
|
@ -294,7 +294,8 @@ BuildResourceDescriptorHob (
|
||||||
@param Guid The GUID to tag the customized HOB.
|
@param Guid The GUID to tag the customized HOB.
|
||||||
@param DataLength The size of the data payload for the GUID HOB.
|
@param DataLength The size of the data payload for the GUID HOB.
|
||||||
|
|
||||||
@return The start address of GUID HOB data.
|
@retval NULL The GUID HOB could not be allocated.
|
||||||
|
@retval others The start address of GUID HOB data.
|
||||||
|
|
||||||
**/
|
**/
|
||||||
VOID *
|
VOID *
|
||||||
|
@ -328,7 +329,8 @@ BuildGuidHob (
|
||||||
@param Data The data to be copied into the data field of the GUID HOB.
|
@param Data The data to be copied into the data field of the GUID HOB.
|
||||||
@param DataLength The size of the data payload for the GUID HOB.
|
@param DataLength The size of the data payload for the GUID HOB.
|
||||||
|
|
||||||
@return The start address of GUID HOB data.
|
@retval NULL The GUID HOB could not be allocated.
|
||||||
|
@retval others The start address of GUID HOB data.
|
||||||
|
|
||||||
**/
|
**/
|
||||||
VOID *
|
VOID *
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/*++
|
/*++
|
||||||
|
|
||||||
Copyright (c) 2004 - 2007, Intel Corporation. All rights reserved.<BR>
|
Copyright (c) 2004 - 2011, Intel Corporation. All rights reserved.<BR>
|
||||||
This program and the accompanying materials
|
This program and the accompanying materials
|
||||||
are licensed and made available under the terms and conditions of the BSD License
|
are licensed and made available under the terms and conditions of the BSD License
|
||||||
which accompanies this distribution. The full text of the license may be found at
|
which accompanies this distribution. The full text of the license may be found at
|
||||||
|
@ -207,7 +207,8 @@ GetBootModeHob (
|
||||||
@param Type Type of the new HOB.
|
@param Type Type of the new HOB.
|
||||||
@param Length Length of the new HOB to allocate.
|
@param Length Length of the new HOB to allocate.
|
||||||
|
|
||||||
@return The address of new HOB.
|
@retval NULL The HOB could not be allocated.
|
||||||
|
@retval others The address of new HOB.
|
||||||
|
|
||||||
**/
|
**/
|
||||||
STATIC
|
STATIC
|
||||||
|
@ -221,10 +222,13 @@ InternalPeiCreateHob (
|
||||||
VOID *Hob;
|
VOID *Hob;
|
||||||
|
|
||||||
Status = PeiServicesCreateHob (Type, Length, &Hob);
|
Status = PeiServicesCreateHob (Type, Length, &Hob);
|
||||||
|
if (EFI_ERROR (Status)) {
|
||||||
|
Hob = NULL;
|
||||||
|
}
|
||||||
//
|
//
|
||||||
// Assume the process of HOB building is always successful.
|
// Assume the process of HOB building is always successful.
|
||||||
//
|
//
|
||||||
ASSERT_EFI_ERROR (Status);
|
ASSERT (Hob != NULL);
|
||||||
return Hob;
|
return Hob;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -255,6 +259,9 @@ GlueBuildModuleHob (
|
||||||
EFI_HOB_MEMORY_ALLOCATION_MODULE *Hob;
|
EFI_HOB_MEMORY_ALLOCATION_MODULE *Hob;
|
||||||
|
|
||||||
Hob = InternalPeiCreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, (UINT16) sizeof (EFI_HOB_MEMORY_ALLOCATION_MODULE));
|
Hob = InternalPeiCreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, (UINT16) sizeof (EFI_HOB_MEMORY_ALLOCATION_MODULE));
|
||||||
|
if (Hob == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
CopyGuid (&(Hob->MemoryAllocationHeader.Name), &gEfiHobMemoryAllocModuleGuid);
|
CopyGuid (&(Hob->MemoryAllocationHeader.Name), &gEfiHobMemoryAllocModuleGuid);
|
||||||
Hob->MemoryAllocationHeader.MemoryBaseAddress = MemoryAllocationModule;
|
Hob->MemoryAllocationHeader.MemoryBaseAddress = MemoryAllocationModule;
|
||||||
|
@ -296,6 +303,9 @@ BuildResourceDescriptorHob (
|
||||||
EFI_HOB_RESOURCE_DESCRIPTOR *Hob;
|
EFI_HOB_RESOURCE_DESCRIPTOR *Hob;
|
||||||
|
|
||||||
Hob = InternalPeiCreateHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, (UINT16) sizeof (EFI_HOB_RESOURCE_DESCRIPTOR));
|
Hob = InternalPeiCreateHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, (UINT16) sizeof (EFI_HOB_RESOURCE_DESCRIPTOR));
|
||||||
|
if (Hob == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Hob->ResourceType = ResourceType;
|
Hob->ResourceType = ResourceType;
|
||||||
Hob->ResourceAttribute = ResourceAttribute;
|
Hob->ResourceAttribute = ResourceAttribute;
|
||||||
|
@ -318,7 +328,8 @@ BuildResourceDescriptorHob (
|
||||||
@param Guid The GUID to tag the customized HOB.
|
@param Guid The GUID to tag the customized HOB.
|
||||||
@param DataLength The size of the data payload for the GUID HOB.
|
@param DataLength The size of the data payload for the GUID HOB.
|
||||||
|
|
||||||
@return The start address of GUID HOB data.
|
@retval NULL The GUID HOB could not be allocated.
|
||||||
|
@retval others The start address of GUID HOB data.
|
||||||
|
|
||||||
**/
|
**/
|
||||||
VOID *
|
VOID *
|
||||||
|
@ -330,12 +341,20 @@ BuildGuidHob (
|
||||||
{
|
{
|
||||||
EFI_HOB_GUID_TYPE *Hob;
|
EFI_HOB_GUID_TYPE *Hob;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Make sure Guid is valid
|
||||||
|
//
|
||||||
|
ASSERT (Guid != NULL);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Make sure that data length is not too long.
|
// Make sure that data length is not too long.
|
||||||
//
|
//
|
||||||
ASSERT (DataLength <= (0xffff - sizeof (EFI_HOB_GUID_TYPE)));
|
ASSERT (DataLength <= (0xffff - sizeof (EFI_HOB_GUID_TYPE)));
|
||||||
|
|
||||||
Hob = InternalPeiCreateHob (EFI_HOB_TYPE_GUID_EXTENSION, (UINT16) (sizeof (EFI_HOB_GUID_TYPE) + DataLength));
|
Hob = InternalPeiCreateHob (EFI_HOB_TYPE_GUID_EXTENSION, (UINT16) (sizeof (EFI_HOB_GUID_TYPE) + DataLength));
|
||||||
|
if (Hob == NULL) {
|
||||||
|
return Hob;
|
||||||
|
}
|
||||||
CopyGuid (&Hob->Name, Guid);
|
CopyGuid (&Hob->Name, Guid);
|
||||||
return Hob + 1;
|
return Hob + 1;
|
||||||
}
|
}
|
||||||
|
@ -357,7 +376,8 @@ BuildGuidHob (
|
||||||
@param Data The data to be copied into the data field of the GUID HOB.
|
@param Data The data to be copied into the data field of the GUID HOB.
|
||||||
@param DataLength The size of the data payload for the GUID HOB.
|
@param DataLength The size of the data payload for the GUID HOB.
|
||||||
|
|
||||||
@return The start address of GUID HOB data.
|
@retval NULL The GUID HOB could not be allocated.
|
||||||
|
@retval others The start address of GUID HOB data.
|
||||||
|
|
||||||
**/
|
**/
|
||||||
VOID *
|
VOID *
|
||||||
|
@ -373,6 +393,9 @@ BuildGuidDataHob (
|
||||||
ASSERT (Data != NULL || DataLength == 0);
|
ASSERT (Data != NULL || DataLength == 0);
|
||||||
|
|
||||||
HobData = BuildGuidHob (Guid, DataLength);
|
HobData = BuildGuidHob (Guid, DataLength);
|
||||||
|
if (HobData == NULL) {
|
||||||
|
return HobData;
|
||||||
|
}
|
||||||
|
|
||||||
return CopyMem (HobData, Data, DataLength);
|
return CopyMem (HobData, Data, DataLength);
|
||||||
}
|
}
|
||||||
|
@ -403,6 +426,9 @@ BuildFvHob (
|
||||||
//
|
//
|
||||||
ASSERT (((EFI_FIRMWARE_VOLUME_HEADER*)((UINTN)BaseAddress))->Signature == EFI_FVH_SIGNATURE);
|
ASSERT (((EFI_FIRMWARE_VOLUME_HEADER*)((UINTN)BaseAddress))->Signature == EFI_FVH_SIGNATURE);
|
||||||
Hob = InternalPeiCreateHob (EFI_HOB_TYPE_FV, (UINT16) sizeof (EFI_HOB_FIRMWARE_VOLUME));
|
Hob = InternalPeiCreateHob (EFI_HOB_TYPE_FV, (UINT16) sizeof (EFI_HOB_FIRMWARE_VOLUME));
|
||||||
|
if (Hob == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Hob->BaseAddress = BaseAddress;
|
Hob->BaseAddress = BaseAddress;
|
||||||
Hob->Length = Length;
|
Hob->Length = Length;
|
||||||
|
@ -430,6 +456,9 @@ BuildCvHob (
|
||||||
EFI_HOB_CAPSULE_VOLUME *Hob;
|
EFI_HOB_CAPSULE_VOLUME *Hob;
|
||||||
|
|
||||||
Hob = InternalPeiCreateHob (EFI_HOB_TYPE_CV, (UINT16) sizeof (EFI_HOB_CAPSULE_VOLUME));
|
Hob = InternalPeiCreateHob (EFI_HOB_TYPE_CV, (UINT16) sizeof (EFI_HOB_CAPSULE_VOLUME));
|
||||||
|
if (Hob == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Hob->BaseAddress = BaseAddress;
|
Hob->BaseAddress = BaseAddress;
|
||||||
Hob->Length = Length;
|
Hob->Length = Length;
|
||||||
|
@ -457,6 +486,9 @@ BuildCpuHob (
|
||||||
EFI_HOB_CPU *Hob;
|
EFI_HOB_CPU *Hob;
|
||||||
|
|
||||||
Hob = InternalPeiCreateHob (EFI_HOB_TYPE_CPU, (UINT16) sizeof (EFI_HOB_CPU));
|
Hob = InternalPeiCreateHob (EFI_HOB_TYPE_CPU, (UINT16) sizeof (EFI_HOB_CPU));
|
||||||
|
if (Hob == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Hob->SizeOfMemorySpace = SizeOfMemorySpace;
|
Hob->SizeOfMemorySpace = SizeOfMemorySpace;
|
||||||
Hob->SizeOfIoSpace = SizeOfIoSpace;
|
Hob->SizeOfIoSpace = SizeOfIoSpace;
|
||||||
|
@ -489,6 +521,9 @@ BuildStackHob (
|
||||||
EFI_HOB_MEMORY_ALLOCATION_STACK *Hob;
|
EFI_HOB_MEMORY_ALLOCATION_STACK *Hob;
|
||||||
|
|
||||||
Hob = InternalPeiCreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, (UINT16) sizeof (EFI_HOB_MEMORY_ALLOCATION_STACK));
|
Hob = InternalPeiCreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, (UINT16) sizeof (EFI_HOB_MEMORY_ALLOCATION_STACK));
|
||||||
|
if (Hob == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
CopyGuid (&(Hob->AllocDescriptor.Name), &gEfiHobMemoryAllocStackGuid);
|
CopyGuid (&(Hob->AllocDescriptor.Name), &gEfiHobMemoryAllocStackGuid);
|
||||||
Hob->AllocDescriptor.MemoryBaseAddress = BaseAddress;
|
Hob->AllocDescriptor.MemoryBaseAddress = BaseAddress;
|
||||||
|
@ -525,6 +560,9 @@ BuildBspStoreHob (
|
||||||
EFI_HOB_MEMORY_ALLOCATION_BSP_STORE *Hob;
|
EFI_HOB_MEMORY_ALLOCATION_BSP_STORE *Hob;
|
||||||
|
|
||||||
Hob = InternalPeiCreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, (UINT16) sizeof (EFI_HOB_MEMORY_ALLOCATION_BSP_STORE));
|
Hob = InternalPeiCreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, (UINT16) sizeof (EFI_HOB_MEMORY_ALLOCATION_BSP_STORE));
|
||||||
|
if (Hob == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
CopyGuid (&(Hob->AllocDescriptor.Name), &gEfiHobMemoryAllocBspStoreGuid);
|
CopyGuid (&(Hob->AllocDescriptor.Name), &gEfiHobMemoryAllocBspStoreGuid);
|
||||||
Hob->AllocDescriptor.MemoryBaseAddress = BaseAddress;
|
Hob->AllocDescriptor.MemoryBaseAddress = BaseAddress;
|
||||||
|
@ -561,7 +599,10 @@ GlueBuildMemoryAllocationHob (
|
||||||
EFI_HOB_MEMORY_ALLOCATION *Hob;
|
EFI_HOB_MEMORY_ALLOCATION *Hob;
|
||||||
|
|
||||||
Hob = InternalPeiCreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, (UINT16) sizeof (EFI_HOB_MEMORY_ALLOCATION));
|
Hob = InternalPeiCreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, (UINT16) sizeof (EFI_HOB_MEMORY_ALLOCATION));
|
||||||
|
if (Hob == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
ZeroMem (&(Hob->AllocDescriptor.Name), sizeof (EFI_GUID));
|
ZeroMem (&(Hob->AllocDescriptor.Name), sizeof (EFI_GUID));
|
||||||
Hob->AllocDescriptor.MemoryBaseAddress = BaseAddress;
|
Hob->AllocDescriptor.MemoryBaseAddress = BaseAddress;
|
||||||
Hob->AllocDescriptor.MemoryLength = Length;
|
Hob->AllocDescriptor.MemoryLength = Length;
|
||||||
|
|
Loading…
Reference in New Issue