mirror of https://github.com/acidanthera/audk.git
Free the buffer allocated by GetSectionFromAnyFv() when exit, and add Error Status Check for InstallProtocolInterface(), GetSectionFromAnyFv() return.
Signed-off-by: Star Zeng <star.zeng@intel.com> Reviewed-by: Jiewen Yao <jiewen.yao@intel.com> git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@13933 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
parent
6b13aa602a
commit
e0d216f6a8
|
@ -2,7 +2,7 @@
|
||||||
Implementation for S3 Boot Script Save thunk driver.
|
Implementation for S3 Boot Script Save thunk driver.
|
||||||
This thunk driver consumes PI S3SaveState protocol to produce framework S3BootScriptSave Protocol
|
This thunk driver consumes PI S3SaveState protocol to produce framework S3BootScriptSave Protocol
|
||||||
|
|
||||||
Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
|
Copyright (c) 2010 - 2012, 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
|
||||||
|
@ -830,7 +830,7 @@ InitializeScriptSaveOnS3SaveState (
|
||||||
// This is the first-time loaded by DXE core. reload itself to NVS mem
|
// This is the first-time loaded by DXE core. reload itself to NVS mem
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
// A workarouond: Here we install a dummy handle
|
// A workaround: Here we install a dummy handle
|
||||||
//
|
//
|
||||||
NewImageHandle = NULL;
|
NewImageHandle = NULL;
|
||||||
Status = gBS->InstallProtocolInterface (
|
Status = gBS->InstallProtocolInterface (
|
||||||
|
@ -839,6 +839,7 @@ InitializeScriptSaveOnS3SaveState (
|
||||||
EFI_NATIVE_INTERFACE,
|
EFI_NATIVE_INTERFACE,
|
||||||
NULL
|
NULL
|
||||||
);
|
);
|
||||||
|
ASSERT_EFI_ERROR (Status);
|
||||||
|
|
||||||
Status = GetSectionFromAnyFv (
|
Status = GetSectionFromAnyFv (
|
||||||
&gEfiCallerIdGuid,
|
&gEfiCallerIdGuid,
|
||||||
|
@ -847,15 +848,14 @@ InitializeScriptSaveOnS3SaveState (
|
||||||
(VOID **) &Buffer,
|
(VOID **) &Buffer,
|
||||||
&BufferSize
|
&BufferSize
|
||||||
);
|
);
|
||||||
|
ASSERT_EFI_ERROR (Status);
|
||||||
ImageContext.Handle = Buffer;
|
ImageContext.Handle = Buffer;
|
||||||
ImageContext.ImageRead = PeCoffLoaderImageReadFromMemory;
|
ImageContext.ImageRead = PeCoffLoaderImageReadFromMemory;
|
||||||
//
|
//
|
||||||
// Get information about the image being loaded
|
// Get information about the image being loaded
|
||||||
//
|
//
|
||||||
Status = PeCoffLoaderGetImageInfo (&ImageContext);
|
Status = PeCoffLoaderGetImageInfo (&ImageContext);
|
||||||
if (EFI_ERROR (Status)) {
|
ASSERT_EFI_ERROR (Status);
|
||||||
return Status;
|
|
||||||
}
|
|
||||||
|
|
||||||
MemoryAddress = SIZE_4GB - 1;
|
MemoryAddress = SIZE_4GB - 1;
|
||||||
PageNumber = EFI_SIZE_TO_PAGES (BufferSize + ImageContext.SectionAlignment);
|
PageNumber = EFI_SIZE_TO_PAGES (BufferSize + ImageContext.SectionAlignment);
|
||||||
|
@ -865,9 +865,7 @@ InitializeScriptSaveOnS3SaveState (
|
||||||
PageNumber,
|
PageNumber,
|
||||||
&MemoryAddress
|
&MemoryAddress
|
||||||
);
|
);
|
||||||
if (EFI_ERROR (Status)) {
|
ASSERT_EFI_ERROR (Status);
|
||||||
return EFI_OUT_OF_RESOURCES;
|
|
||||||
}
|
|
||||||
ImageContext.ImageAddress = (PHYSICAL_ADDRESS)(UINTN)MemoryAddress;
|
ImageContext.ImageAddress = (PHYSICAL_ADDRESS)(UINTN)MemoryAddress;
|
||||||
//
|
//
|
||||||
// Align buffer on section boundry
|
// Align buffer on section boundry
|
||||||
|
@ -878,30 +876,26 @@ InitializeScriptSaveOnS3SaveState (
|
||||||
// Load the image to our new buffer
|
// Load the image to our new buffer
|
||||||
//
|
//
|
||||||
Status = PeCoffLoaderLoadImage (&ImageContext);
|
Status = PeCoffLoaderLoadImage (&ImageContext);
|
||||||
if (EFI_ERROR (Status)) {
|
ASSERT_EFI_ERROR (Status);
|
||||||
gBS->FreePages (MemoryAddress, PageNumber);
|
|
||||||
return Status;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Relocate the image in our new buffer
|
// Relocate the image in our new buffer
|
||||||
//
|
//
|
||||||
Status = PeCoffLoaderRelocateImage (&ImageContext);
|
Status = PeCoffLoaderRelocateImage (&ImageContext);
|
||||||
|
ASSERT_EFI_ERROR (Status);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Free the buffer allocated by ReadSection since the image has been relocated in the new buffer
|
||||||
|
//
|
||||||
|
gBS->FreePool (Buffer);
|
||||||
|
|
||||||
if (EFI_ERROR (Status)) {
|
|
||||||
PeCoffLoaderUnloadImage (&ImageContext);
|
|
||||||
gBS->FreePages (MemoryAddress, PageNumber);
|
|
||||||
return Status;
|
|
||||||
}
|
|
||||||
//
|
//
|
||||||
// Flush the instruction cache so the image data is written before we execute it
|
// Flush the instruction cache so the image data is written before we execute it
|
||||||
//
|
//
|
||||||
InvalidateInstructionCacheRange ((VOID *)(UINTN)ImageContext.ImageAddress, (UINTN)ImageContext.ImageSize);
|
InvalidateInstructionCacheRange ((VOID *)(UINTN)ImageContext.ImageAddress, (UINTN)ImageContext.ImageSize);
|
||||||
Status = ((EFI_IMAGE_ENTRY_POINT)(UINTN)(ImageContext.EntryPoint)) (NewImageHandle, SystemTable);
|
Status = ((EFI_IMAGE_ENTRY_POINT)(UINTN)(ImageContext.EntryPoint)) (NewImageHandle, SystemTable);
|
||||||
if (EFI_ERROR (Status)) {
|
ASSERT_EFI_ERROR (Status);
|
||||||
gBS->FreePages (MemoryAddress, PageNumber);
|
|
||||||
return Status;
|
|
||||||
}
|
|
||||||
//
|
//
|
||||||
// Additional step for BootScriptThunk integrity
|
// Additional step for BootScriptThunk integrity
|
||||||
//
|
//
|
||||||
|
@ -910,9 +904,7 @@ InitializeScriptSaveOnS3SaveState (
|
||||||
// Allocate BootScriptThunkData
|
// Allocate BootScriptThunkData
|
||||||
//
|
//
|
||||||
BootScriptThunkData = AllocatePool (sizeof (BOOT_SCRIPT_THUNK_DATA));
|
BootScriptThunkData = AllocatePool (sizeof (BOOT_SCRIPT_THUNK_DATA));
|
||||||
if (BootScriptThunkData == NULL) {
|
ASSERT (BootScriptThunkData != NULL);
|
||||||
return EFI_OUT_OF_RESOURCES;
|
|
||||||
}
|
|
||||||
|
|
||||||
BootScriptThunkData->BootScriptThunkBase = ImageContext.ImageAddress;
|
BootScriptThunkData->BootScriptThunkBase = ImageContext.ImageAddress;
|
||||||
BootScriptThunkData->BootScriptThunkLength = ImageContext.ImageSize;
|
BootScriptThunkData->BootScriptThunkLength = ImageContext.ImageSize;
|
||||||
|
|
|
@ -235,7 +235,7 @@ BootScriptExecutorEntryPoint (
|
||||||
// This is the first-time loaded by DXE core. reload itself to NVS mem
|
// This is the first-time loaded by DXE core. reload itself to NVS mem
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
// A workarouond: Here we install a dummy handle
|
// A workaround: Here we install a dummy handle
|
||||||
//
|
//
|
||||||
NewImageHandle = NULL;
|
NewImageHandle = NULL;
|
||||||
Status = gBS->InstallProtocolInterface (
|
Status = gBS->InstallProtocolInterface (
|
||||||
|
@ -244,6 +244,7 @@ BootScriptExecutorEntryPoint (
|
||||||
EFI_NATIVE_INTERFACE,
|
EFI_NATIVE_INTERFACE,
|
||||||
NULL
|
NULL
|
||||||
);
|
);
|
||||||
|
ASSERT_EFI_ERROR (Status);
|
||||||
|
|
||||||
Status = GetSectionFromAnyFv (
|
Status = GetSectionFromAnyFv (
|
||||||
&gEfiCallerIdGuid,
|
&gEfiCallerIdGuid,
|
||||||
|
@ -252,15 +253,14 @@ BootScriptExecutorEntryPoint (
|
||||||
(VOID **) &Buffer,
|
(VOID **) &Buffer,
|
||||||
&BufferSize
|
&BufferSize
|
||||||
);
|
);
|
||||||
|
ASSERT_EFI_ERROR (Status);
|
||||||
ImageContext.Handle = Buffer;
|
ImageContext.Handle = Buffer;
|
||||||
ImageContext.ImageRead = PeCoffLoaderImageReadFromMemory;
|
ImageContext.ImageRead = PeCoffLoaderImageReadFromMemory;
|
||||||
//
|
//
|
||||||
// Get information about the image being loaded
|
// Get information about the image being loaded
|
||||||
//
|
//
|
||||||
Status = PeCoffLoaderGetImageInfo (&ImageContext);
|
Status = PeCoffLoaderGetImageInfo (&ImageContext);
|
||||||
if (EFI_ERROR (Status)) {
|
ASSERT_EFI_ERROR (Status);
|
||||||
return Status;
|
|
||||||
}
|
|
||||||
Pages = EFI_SIZE_TO_PAGES(BufferSize + ImageContext.SectionAlignment);
|
Pages = EFI_SIZE_TO_PAGES(BufferSize + ImageContext.SectionAlignment);
|
||||||
FfsBuffer = 0xFFFFFFFF;
|
FfsBuffer = 0xFFFFFFFF;
|
||||||
Status = gBS->AllocatePages (
|
Status = gBS->AllocatePages (
|
||||||
|
@ -269,9 +269,7 @@ BootScriptExecutorEntryPoint (
|
||||||
Pages,
|
Pages,
|
||||||
&FfsBuffer
|
&FfsBuffer
|
||||||
);
|
);
|
||||||
if (EFI_ERROR (Status)) {
|
ASSERT_EFI_ERROR (Status);
|
||||||
return EFI_OUT_OF_RESOURCES;
|
|
||||||
}
|
|
||||||
ImageContext.ImageAddress = (PHYSICAL_ADDRESS)(UINTN)FfsBuffer;
|
ImageContext.ImageAddress = (PHYSICAL_ADDRESS)(UINTN)FfsBuffer;
|
||||||
//
|
//
|
||||||
// Align buffer on section boundry
|
// Align buffer on section boundry
|
||||||
|
@ -282,30 +280,26 @@ BootScriptExecutorEntryPoint (
|
||||||
// Load the image to our new buffer
|
// Load the image to our new buffer
|
||||||
//
|
//
|
||||||
Status = PeCoffLoaderLoadImage (&ImageContext);
|
Status = PeCoffLoaderLoadImage (&ImageContext);
|
||||||
if (EFI_ERROR (Status)) {
|
ASSERT_EFI_ERROR (Status);
|
||||||
gBS->FreePages (FfsBuffer, Pages);
|
|
||||||
return Status;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Relocate the image in our new buffer
|
// Relocate the image in our new buffer
|
||||||
//
|
//
|
||||||
Status = PeCoffLoaderRelocateImage (&ImageContext);
|
Status = PeCoffLoaderRelocateImage (&ImageContext);
|
||||||
|
ASSERT_EFI_ERROR (Status);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Free the buffer allocated by ReadSection since the image has been relocated in the new buffer
|
||||||
|
//
|
||||||
|
gBS->FreePool (Buffer);
|
||||||
|
|
||||||
if (EFI_ERROR (Status)) {
|
|
||||||
PeCoffLoaderUnloadImage (&ImageContext);
|
|
||||||
gBS->FreePages (FfsBuffer, Pages);
|
|
||||||
return Status;
|
|
||||||
}
|
|
||||||
//
|
//
|
||||||
// Flush the instruction cache so the image data is written before we execute it
|
// Flush the instruction cache so the image data is written before we execute it
|
||||||
//
|
//
|
||||||
InvalidateInstructionCacheRange ((VOID *)(UINTN)ImageContext.ImageAddress, (UINTN)ImageContext.ImageSize);
|
InvalidateInstructionCacheRange ((VOID *)(UINTN)ImageContext.ImageAddress, (UINTN)ImageContext.ImageSize);
|
||||||
Status = ((EFI_IMAGE_ENTRY_POINT)(UINTN)(ImageContext.EntryPoint)) (NewImageHandle, SystemTable);
|
Status = ((EFI_IMAGE_ENTRY_POINT)(UINTN)(ImageContext.EntryPoint)) (NewImageHandle, SystemTable);
|
||||||
if (EFI_ERROR (Status)) {
|
ASSERT_EFI_ERROR (Status);
|
||||||
gBS->FreePages (FfsBuffer, Pages);
|
|
||||||
return Status;
|
|
||||||
}
|
|
||||||
//
|
//
|
||||||
// Additional step for BootScript integrity
|
// Additional step for BootScript integrity
|
||||||
// Save BootScriptExecutor image
|
// Save BootScriptExecutor image
|
||||||
|
@ -334,9 +328,7 @@ BootScriptExecutorEntryPoint (
|
||||||
Pages,
|
Pages,
|
||||||
&BootScriptExecutorBuffer
|
&BootScriptExecutorBuffer
|
||||||
);
|
);
|
||||||
if (EFI_ERROR (Status)) {
|
ASSERT_EFI_ERROR (Status);
|
||||||
return EFI_OUT_OF_RESOURCES;
|
|
||||||
}
|
|
||||||
|
|
||||||
EfiBootScriptExecutorVariable = (BOOT_SCRIPT_EXECUTOR_VARIABLE *)(UINTN)BootScriptExecutorBuffer;
|
EfiBootScriptExecutorVariable = (BOOT_SCRIPT_EXECUTOR_VARIABLE *)(UINTN)BootScriptExecutorBuffer;
|
||||||
EfiBootScriptExecutorVariable->BootScriptExecutorEntrypoint = (UINTN) S3BootScriptExecutorEntryFunction ;
|
EfiBootScriptExecutorVariable->BootScriptExecutorEntrypoint = (UINTN) S3BootScriptExecutorEntryFunction ;
|
||||||
|
|
Loading…
Reference in New Issue