mirror of
https://github.com/acidanthera/audk.git
synced 2025-09-23 09:47:44 +02:00
MdePkg/BaseUefiImageLib: Factor out ExecutionSupport
This commit is contained in:
parent
efb6eea39e
commit
07d0ca418e
@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
[Sources]
|
[Sources]
|
||||||
CommonSupport.c
|
CommonSupport.c
|
||||||
|
ExecutionSupport.c
|
||||||
PeCoffSupport.h
|
PeCoffSupport.h
|
||||||
PeCoffSupport.c
|
PeCoffSupport.c
|
||||||
UefiImageLibPeCoff.c
|
UefiImageLibPeCoff.c
|
||||||
|
@ -11,7 +11,6 @@
|
|||||||
#include <Uefi/UefiSpec.h>
|
#include <Uefi/UefiSpec.h>
|
||||||
|
|
||||||
#include <Library/BaseOverflowLib.h>
|
#include <Library/BaseOverflowLib.h>
|
||||||
#include <Library/CacheMaintenanceLib.h>
|
|
||||||
#include <Library/DebugLib.h>
|
#include <Library/DebugLib.h>
|
||||||
#include <Library/UefiImageLib.h>
|
#include <Library/UefiImageLib.h>
|
||||||
|
|
||||||
@ -41,7 +40,6 @@ UefiImageLoaderGetImageEntryPoint (
|
|||||||
UINT32 EntryPointAddress;
|
UINT32 EntryPointAddress;
|
||||||
|
|
||||||
ASSERT (Context != NULL);
|
ASSERT (Context != NULL);
|
||||||
ASSERT (Context->ImageBuffer != NULL);
|
|
||||||
|
|
||||||
ImageAddress = UefiImageLoaderGetImageAddress (Context);
|
ImageAddress = UefiImageLoaderGetImageAddress (Context);
|
||||||
EntryPointAddress = UefiImageGetEntryPointAddress (Context);
|
EntryPointAddress = UefiImageGetEntryPointAddress (Context);
|
||||||
@ -49,104 +47,6 @@ UefiImageLoaderGetImageEntryPoint (
|
|||||||
return ImageAddress + EntryPointAddress;
|
return ImageAddress + EntryPointAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
RETURN_STATUS
|
|
||||||
UefiImageRelocateImageInplaceForExecution (
|
|
||||||
IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context
|
|
||||||
)
|
|
||||||
{
|
|
||||||
RETURN_STATUS Status;
|
|
||||||
UINTN ImageAddress;
|
|
||||||
UINTN ImageSize;
|
|
||||||
|
|
||||||
Status = UefiImageRelocateImageInplace (Context);
|
|
||||||
if (RETURN_ERROR (Status)) {
|
|
||||||
DEBUG_RAISE ();
|
|
||||||
return Status;
|
|
||||||
}
|
|
||||||
|
|
||||||
ImageAddress = UefiImageLoaderGetImageAddress (Context);
|
|
||||||
ImageSize = UefiImageGetImageSizeInplace (Context);
|
|
||||||
//
|
|
||||||
// Flush the instruction cache so the image data is written before
|
|
||||||
// execution.
|
|
||||||
//
|
|
||||||
InvalidateInstructionCacheRange ((VOID *) ImageAddress, ImageSize);
|
|
||||||
|
|
||||||
return RETURN_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
// FIXME: Check Subsystem here
|
|
||||||
RETURN_STATUS
|
|
||||||
UefiImageLoadImageForExecution (
|
|
||||||
IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context,
|
|
||||||
OUT VOID *Destination,
|
|
||||||
IN UINT32 DestinationSize,
|
|
||||||
OUT UEFI_IMAGE_LOADER_RUNTIME_CONTEXT *RuntimeContext OPTIONAL,
|
|
||||||
IN UINT32 RuntimeContextSize
|
|
||||||
)
|
|
||||||
{
|
|
||||||
RETURN_STATUS Status;
|
|
||||||
UINTN BaseAddress;
|
|
||||||
UINTN SizeOfImage;
|
|
||||||
//
|
|
||||||
// Load the Image into the memory space.
|
|
||||||
//
|
|
||||||
Status = UefiImageLoadImage (Context, Destination, DestinationSize);
|
|
||||||
if (RETURN_ERROR (Status)) {
|
|
||||||
return Status;
|
|
||||||
}
|
|
||||||
//
|
|
||||||
// Relocate the Image to the address it has been loaded to.
|
|
||||||
//
|
|
||||||
BaseAddress = UefiImageLoaderGetImageAddress (Context);
|
|
||||||
Status = UefiImageRelocateImage (
|
|
||||||
Context,
|
|
||||||
BaseAddress,
|
|
||||||
RuntimeContext,
|
|
||||||
RuntimeContextSize
|
|
||||||
);
|
|
||||||
if (RETURN_ERROR (Status)) {
|
|
||||||
return Status;
|
|
||||||
}
|
|
||||||
|
|
||||||
SizeOfImage = UefiImageGetImageSize (Context);
|
|
||||||
//
|
|
||||||
// Flush the instruction cache so the image data is written before execution.
|
|
||||||
//
|
|
||||||
InvalidateInstructionCacheRange ((VOID *) BaseAddress, SizeOfImage);
|
|
||||||
|
|
||||||
return RETURN_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
RETURN_STATUS
|
|
||||||
UefiImageRuntimeRelocateImageForExecution (
|
|
||||||
IN OUT VOID *Image,
|
|
||||||
IN UINT32 ImageSize,
|
|
||||||
IN UINT64 BaseAddress,
|
|
||||||
IN CONST UEFI_IMAGE_LOADER_RUNTIME_CONTEXT *RuntimeContext
|
|
||||||
)
|
|
||||||
{
|
|
||||||
RETURN_STATUS Status;
|
|
||||||
//
|
|
||||||
// Relocate the Image to the new address.
|
|
||||||
//
|
|
||||||
Status = UefiImageRuntimeRelocateImage (
|
|
||||||
Image,
|
|
||||||
ImageSize,
|
|
||||||
BaseAddress,
|
|
||||||
RuntimeContext
|
|
||||||
);
|
|
||||||
if (RETURN_ERROR (Status)) {
|
|
||||||
return Status;
|
|
||||||
}
|
|
||||||
//
|
|
||||||
// Flush the instruction cache so the image data is written before execution.
|
|
||||||
//
|
|
||||||
InvalidateInstructionCacheRange (Image, ImageSize);
|
|
||||||
|
|
||||||
return RETURN_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
// FIXME: Some image prints use this and some don't. Is this really needed?
|
// FIXME: Some image prints use this and some don't. Is this really needed?
|
||||||
RETURN_STATUS
|
RETURN_STATUS
|
||||||
UefiImageGetModuleNameFromSymbolsPath (
|
UefiImageGetModuleNameFromSymbolsPath (
|
||||||
|
113
MdePkg/Library/BaseUefiImageLib/ExecutionSupport.c
Normal file
113
MdePkg/Library/BaseUefiImageLib/ExecutionSupport.c
Normal file
@ -0,0 +1,113 @@
|
|||||||
|
/** @file
|
||||||
|
Support for functions common to all Image formats.
|
||||||
|
|
||||||
|
Copyright (c) 2021, Marvin Häuser. All rights reserved.<BR>
|
||||||
|
|
||||||
|
SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
**/
|
||||||
|
|
||||||
|
#include <Base.h>
|
||||||
|
#include <Uefi/UefiBaseType.h>
|
||||||
|
#include <Uefi/UefiSpec.h>
|
||||||
|
|
||||||
|
#include <Library/BaseOverflowLib.h>
|
||||||
|
#include <Library/CacheMaintenanceLib.h>
|
||||||
|
#include <Library/DebugLib.h>
|
||||||
|
#include <Library/UefiImageLib.h>
|
||||||
|
|
||||||
|
RETURN_STATUS
|
||||||
|
UefiImageRelocateImageInplaceForExecution (
|
||||||
|
IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context
|
||||||
|
)
|
||||||
|
{
|
||||||
|
RETURN_STATUS Status;
|
||||||
|
UINTN ImageAddress;
|
||||||
|
UINTN ImageSize;
|
||||||
|
|
||||||
|
Status = UefiImageRelocateImageInplace (Context);
|
||||||
|
if (RETURN_ERROR (Status)) {
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
|
ImageAddress = UefiImageLoaderGetImageAddress (Context);
|
||||||
|
ImageSize = UefiImageGetImageSizeInplace (Context);
|
||||||
|
//
|
||||||
|
// Flush the instruction cache so the image data is written before
|
||||||
|
// execution.
|
||||||
|
//
|
||||||
|
InvalidateInstructionCacheRange ((VOID *) ImageAddress, ImageSize);
|
||||||
|
|
||||||
|
return RETURN_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME: Check Subsystem here
|
||||||
|
RETURN_STATUS
|
||||||
|
UefiImageLoadImageForExecution (
|
||||||
|
IN OUT UEFI_IMAGE_LOADER_IMAGE_CONTEXT *Context,
|
||||||
|
OUT VOID *Destination,
|
||||||
|
IN UINT32 DestinationSize,
|
||||||
|
OUT UEFI_IMAGE_LOADER_RUNTIME_CONTEXT *RuntimeContext OPTIONAL,
|
||||||
|
IN UINT32 RuntimeContextSize
|
||||||
|
)
|
||||||
|
{
|
||||||
|
RETURN_STATUS Status;
|
||||||
|
UINTN BaseAddress;
|
||||||
|
UINTN SizeOfImage;
|
||||||
|
//
|
||||||
|
// Load the Image into the memory space.
|
||||||
|
//
|
||||||
|
Status = UefiImageLoadImage (Context, Destination, DestinationSize);
|
||||||
|
if (RETURN_ERROR (Status)) {
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
//
|
||||||
|
// Relocate the Image to the address it has been loaded to.
|
||||||
|
//
|
||||||
|
BaseAddress = UefiImageLoaderGetImageAddress (Context);
|
||||||
|
Status = UefiImageRelocateImage (
|
||||||
|
Context,
|
||||||
|
BaseAddress,
|
||||||
|
RuntimeContext,
|
||||||
|
RuntimeContextSize
|
||||||
|
);
|
||||||
|
if (RETURN_ERROR (Status)) {
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
|
SizeOfImage = UefiImageGetImageSize (Context);
|
||||||
|
//
|
||||||
|
// Flush the instruction cache so the image data is written before execution.
|
||||||
|
//
|
||||||
|
InvalidateInstructionCacheRange ((VOID *) BaseAddress, SizeOfImage);
|
||||||
|
|
||||||
|
return RETURN_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
RETURN_STATUS
|
||||||
|
UefiImageRuntimeRelocateImageForExecution (
|
||||||
|
IN OUT VOID *Image,
|
||||||
|
IN UINT32 ImageSize,
|
||||||
|
IN UINT64 BaseAddress,
|
||||||
|
IN CONST UEFI_IMAGE_LOADER_RUNTIME_CONTEXT *RuntimeContext
|
||||||
|
)
|
||||||
|
{
|
||||||
|
RETURN_STATUS Status;
|
||||||
|
//
|
||||||
|
// Relocate the Image to the new address.
|
||||||
|
//
|
||||||
|
Status = UefiImageRuntimeRelocateImage (
|
||||||
|
Image,
|
||||||
|
ImageSize,
|
||||||
|
BaseAddress,
|
||||||
|
RuntimeContext
|
||||||
|
);
|
||||||
|
if (RETURN_ERROR (Status)) {
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
//
|
||||||
|
// Flush the instruction cache so the image data is written before execution.
|
||||||
|
//
|
||||||
|
InvalidateInstructionCacheRange (Image, ImageSize);
|
||||||
|
|
||||||
|
return RETURN_SUCCESS;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user