Revision: 13933
http://edk2.svn.sourceforge.net/edk2/?rev=13933&view=rev
Author: lzeng14
Date: 2012-11-12 01:33:41 +0000 (Mon, 12 Nov 2012)
Log Message:
-----------
Free the buffer allocated by GetSectionFromAnyFv() when exit, and add Error
Status Check for InstallProtocolInterface(), GetSectionFromAnyFv() return.
Signed-off-by: Star Zeng <[email protected]>
Reviewed-by: Jiewen Yao <[email protected]>
Modified Paths:
--------------
trunk/edk2/EdkCompatibilityPkg/Compatibility/BootScriptSaveOnS3SaveStateThunk/ScriptSave.c
trunk/edk2/MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/ScriptExecute.c
Modified:
trunk/edk2/EdkCompatibilityPkg/Compatibility/BootScriptSaveOnS3SaveStateThunk/ScriptSave.c
===================================================================
---
trunk/edk2/EdkCompatibilityPkg/Compatibility/BootScriptSaveOnS3SaveStateThunk/ScriptSave.c
2012-11-09 06:39:56 UTC (rev 13932)
+++
trunk/edk2/EdkCompatibilityPkg/Compatibility/BootScriptSaveOnS3SaveStateThunk/ScriptSave.c
2012-11-12 01:33:41 UTC (rev 13933)
@@ -2,7 +2,7 @@
Implementation for S3 Boot Script Save thunk driver.
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
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
@@ -830,7 +830,7 @@
// 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;
Status = gBS->InstallProtocolInterface (
@@ -839,6 +839,7 @@
EFI_NATIVE_INTERFACE,
NULL
);
+ ASSERT_EFI_ERROR (Status);
Status = GetSectionFromAnyFv (
&gEfiCallerIdGuid,
@@ -847,15 +848,14 @@
(VOID **) &Buffer,
&BufferSize
);
+ ASSERT_EFI_ERROR (Status);
ImageContext.Handle = Buffer;
ImageContext.ImageRead = PeCoffLoaderImageReadFromMemory;
//
// Get information about the image being loaded
//
Status = PeCoffLoaderGetImageInfo (&ImageContext);
- if (EFI_ERROR (Status)) {
- return Status;
- }
+ ASSERT_EFI_ERROR (Status);
MemoryAddress = SIZE_4GB - 1;
PageNumber = EFI_SIZE_TO_PAGES (BufferSize +
ImageContext.SectionAlignment);
@@ -865,9 +865,7 @@
PageNumber,
&MemoryAddress
);
- if (EFI_ERROR (Status)) {
- return EFI_OUT_OF_RESOURCES;
- }
+ ASSERT_EFI_ERROR (Status);
ImageContext.ImageAddress = (PHYSICAL_ADDRESS)(UINTN)MemoryAddress;
//
// Align buffer on section boundry
@@ -878,30 +876,26 @@
// Load the image to our new buffer
//
Status = PeCoffLoaderLoadImage (&ImageContext);
- if (EFI_ERROR (Status)) {
- gBS->FreePages (MemoryAddress, PageNumber);
- return Status;
- }
+ ASSERT_EFI_ERROR (Status);
//
// Relocate the image in our new buffer
//
Status = PeCoffLoaderRelocateImage (&ImageContext);
+ ASSERT_EFI_ERROR (Status);
- if (EFI_ERROR (Status)) {
- PeCoffLoaderUnloadImage (&ImageContext);
- gBS->FreePages (MemoryAddress, PageNumber);
- return Status;
- }
//
+ // Free the buffer allocated by ReadSection since the image has been
relocated in the new buffer
+ //
+ gBS->FreePool (Buffer);
+
+ //
// Flush the instruction cache so the image data is written before we
execute it
//
InvalidateInstructionCacheRange ((VOID *)(UINTN)ImageContext.ImageAddress,
(UINTN)ImageContext.ImageSize);
Status = ((EFI_IMAGE_ENTRY_POINT)(UINTN)(ImageContext.EntryPoint))
(NewImageHandle, SystemTable);
- if (EFI_ERROR (Status)) {
- gBS->FreePages (MemoryAddress, PageNumber);
- return Status;
- }
+ ASSERT_EFI_ERROR (Status);
+
//
// Additional step for BootScriptThunk integrity
//
@@ -910,9 +904,7 @@
// Allocate BootScriptThunkData
//
BootScriptThunkData = AllocatePool (sizeof (BOOT_SCRIPT_THUNK_DATA));
- if (BootScriptThunkData == NULL) {
- return EFI_OUT_OF_RESOURCES;
- }
+ ASSERT (BootScriptThunkData != NULL);
BootScriptThunkData->BootScriptThunkBase = ImageContext.ImageAddress;
BootScriptThunkData->BootScriptThunkLength = ImageContext.ImageSize;
Modified:
trunk/edk2/MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/ScriptExecute.c
===================================================================
---
trunk/edk2/MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/ScriptExecute.c
2012-11-09 06:39:56 UTC (rev 13932)
+++
trunk/edk2/MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/ScriptExecute.c
2012-11-12 01:33:41 UTC (rev 13933)
@@ -235,7 +235,7 @@
// 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;
Status = gBS->InstallProtocolInterface (
@@ -244,6 +244,7 @@
EFI_NATIVE_INTERFACE,
NULL
);
+ ASSERT_EFI_ERROR (Status);
Status = GetSectionFromAnyFv (
&gEfiCallerIdGuid,
@@ -252,15 +253,14 @@
(VOID **) &Buffer,
&BufferSize
);
+ ASSERT_EFI_ERROR (Status);
ImageContext.Handle = Buffer;
ImageContext.ImageRead = PeCoffLoaderImageReadFromMemory;
//
// Get information about the image being loaded
//
Status = PeCoffLoaderGetImageInfo (&ImageContext);
- if (EFI_ERROR (Status)) {
- return Status;
- }
+ ASSERT_EFI_ERROR (Status);
Pages = EFI_SIZE_TO_PAGES(BufferSize + ImageContext.SectionAlignment);
FfsBuffer = 0xFFFFFFFF;
Status = gBS->AllocatePages (
@@ -269,9 +269,7 @@
Pages,
&FfsBuffer
);
- if (EFI_ERROR (Status)) {
- return EFI_OUT_OF_RESOURCES;
- }
+ ASSERT_EFI_ERROR (Status);
ImageContext.ImageAddress = (PHYSICAL_ADDRESS)(UINTN)FfsBuffer;
//
// Align buffer on section boundry
@@ -282,30 +280,26 @@
// Load the image to our new buffer
//
Status = PeCoffLoaderLoadImage (&ImageContext);
- if (EFI_ERROR (Status)) {
- gBS->FreePages (FfsBuffer, Pages);
- return Status;
- }
+ ASSERT_EFI_ERROR (Status);
//
// Relocate the image in our new buffer
//
Status = PeCoffLoaderRelocateImage (&ImageContext);
+ ASSERT_EFI_ERROR (Status);
- if (EFI_ERROR (Status)) {
- PeCoffLoaderUnloadImage (&ImageContext);
- gBS->FreePages (FfsBuffer, Pages);
- return Status;
- }
//
+ // Free the buffer allocated by ReadSection since the image has been
relocated in the new buffer
+ //
+ gBS->FreePool (Buffer);
+
+ //
// Flush the instruction cache so the image data is written before we
execute it
//
InvalidateInstructionCacheRange ((VOID
*)(UINTN)ImageContext.ImageAddress, (UINTN)ImageContext.ImageSize);
Status = ((EFI_IMAGE_ENTRY_POINT)(UINTN)(ImageContext.EntryPoint))
(NewImageHandle, SystemTable);
- if (EFI_ERROR (Status)) {
- gBS->FreePages (FfsBuffer, Pages);
- return Status;
- }
+ ASSERT_EFI_ERROR (Status);
+
//
// Additional step for BootScript integrity
// Save BootScriptExecutor image
@@ -334,9 +328,7 @@
Pages,
&BootScriptExecutorBuffer
);
- if (EFI_ERROR (Status)) {
- return EFI_OUT_OF_RESOURCES;
- }
+ ASSERT_EFI_ERROR (Status);
EfiBootScriptExecutorVariable = (BOOT_SCRIPT_EXECUTOR_VARIABLE
*)(UINTN)BootScriptExecutorBuffer;
EfiBootScriptExecutorVariable->BootScriptExecutorEntrypoint = (UINTN)
S3BootScriptExecutorEntryFunction ;
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_nov
_______________________________________________
edk2-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-commits