summaryrefslogtreecommitdiffstats
path: root/MdeModulePkg/Core/Dxe/Image
diff options
context:
space:
mode:
authorMichael Kubacki <michael.kubacki@microsoft.com>2021-12-05 14:54:02 -0800
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2021-12-07 17:24:28 +0000
commit1436aea4d5707e672672a11bda72be2c63c936c3 (patch)
tree370c9d5bd8823aa8ea7bce71a0f29bff71feff67 /MdeModulePkg/Core/Dxe/Image
parent7c7184e201a90a1d2376e615e55e3f4074731468 (diff)
downloadedk2-1436aea4d5707e672672a11bda72be2c63c936c3.tar.gz
edk2-1436aea4d5707e672672a11bda72be2c63c936c3.tar.bz2
edk2-1436aea4d5707e672672a11bda72be2c63c936c3.zip
MdeModulePkg: Apply uncrustify changes
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3737 Apply uncrustify changes to .c/.h files in the MdeModulePkg package Cc: Andrew Fish <afish@apple.com> Cc: Leif Lindholm <leif@nuviainc.com> Cc: Michael D Kinney <michael.d.kinney@intel.com> Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com> Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
Diffstat (limited to 'MdeModulePkg/Core/Dxe/Image')
-rw-r--r--MdeModulePkg/Core/Dxe/Image/Image.c851
-rw-r--r--MdeModulePkg/Core/Dxe/Image/Image.h11
2 files changed, 448 insertions, 414 deletions
diff --git a/MdeModulePkg/Core/Dxe/Image/Image.c b/MdeModulePkg/Core/Dxe/Image/Image.c
index 44b7f105a2..68bde5c15c 100644
--- a/MdeModulePkg/Core/Dxe/Image/Image.c
+++ b/MdeModulePkg/Core/Dxe/Image/Image.c
@@ -15,24 +15,24 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
LOADED_IMAGE_PRIVATE_DATA *mCurrentImage = NULL;
typedef struct {
- LIST_ENTRY Link;
- EDKII_PECOFF_IMAGE_EMULATOR_PROTOCOL *Emulator;
- UINT16 MachineType;
+ LIST_ENTRY Link;
+ EDKII_PECOFF_IMAGE_EMULATOR_PROTOCOL *Emulator;
+ UINT16 MachineType;
} EMULATOR_ENTRY;
-STATIC LIST_ENTRY mAvailableEmulators;
-STATIC EFI_EVENT mPeCoffEmuProtocolRegistrationEvent;
-STATIC VOID *mPeCoffEmuProtocolNotifyRegistration;
+STATIC LIST_ENTRY mAvailableEmulators;
+STATIC EFI_EVENT mPeCoffEmuProtocolRegistrationEvent;
+STATIC VOID *mPeCoffEmuProtocolNotifyRegistration;
//
// This code is needed to build the Image handle for the DXE Core
//
-LOADED_IMAGE_PRIVATE_DATA mCorePrivateImage = {
- LOADED_IMAGE_PRIVATE_DATA_SIGNATURE, // Signature
- NULL, // Image handle
- EFI_IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER, // Image type
- TRUE, // If entrypoint has been called
- NULL, // EntryPoint
+LOADED_IMAGE_PRIVATE_DATA mCorePrivateImage = {
+ LOADED_IMAGE_PRIVATE_DATA_SIGNATURE, // Signature
+ NULL, // Image handle
+ EFI_IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER, // Image type
+ TRUE, // If entrypoint has been called
+ NULL, // EntryPoint
{
EFI_LOADED_IMAGE_INFORMATION_REVISION, // Revision
NULL, // Parent handle
@@ -69,22 +69,22 @@ LOADED_IMAGE_PRIVATE_DATA mCorePrivateImage = {
// memory range usage. It is a bit mapped array in which every bit indicates the correspoding memory page
// available or not.
//
-GLOBAL_REMOVE_IF_UNREFERENCED UINT64 *mDxeCodeMemoryRangeUsageBitMap=NULL;
+GLOBAL_REMOVE_IF_UNREFERENCED UINT64 *mDxeCodeMemoryRangeUsageBitMap = NULL;
typedef struct {
- UINT16 MachineType;
- CHAR16 *MachineTypeName;
+ UINT16 MachineType;
+ CHAR16 *MachineTypeName;
} MACHINE_TYPE_INFO;
GLOBAL_REMOVE_IF_UNREFERENCED MACHINE_TYPE_INFO mMachineTypeInfo[] = {
- {EFI_IMAGE_MACHINE_IA32, L"IA32"},
- {EFI_IMAGE_MACHINE_IA64, L"IA64"},
- {EFI_IMAGE_MACHINE_X64, L"X64"},
- {EFI_IMAGE_MACHINE_ARMTHUMB_MIXED, L"ARM"},
- {EFI_IMAGE_MACHINE_AARCH64, L"AARCH64"}
+ { EFI_IMAGE_MACHINE_IA32, L"IA32" },
+ { EFI_IMAGE_MACHINE_IA64, L"IA64" },
+ { EFI_IMAGE_MACHINE_X64, L"X64" },
+ { EFI_IMAGE_MACHINE_ARMTHUMB_MIXED, L"ARM" },
+ { EFI_IMAGE_MACHINE_AARCH64, L"AARCH64" }
};
-UINT16 mDxeCoreImageMachineType = 0;
+UINT16 mDxeCoreImageMachineType = 0;
/**
Return machine type name.
@@ -95,12 +95,12 @@ UINT16 mDxeCoreImageMachineType = 0;
**/
CHAR16 *
GetMachineTypeName (
- UINT16 MachineType
+ UINT16 MachineType
)
{
UINTN Index;
- for (Index = 0; Index < sizeof(mMachineTypeInfo)/sizeof(mMachineTypeInfo[0]); Index++) {
+ for (Index = 0; Index < sizeof (mMachineTypeInfo)/sizeof (mMachineTypeInfo[0]); Index++) {
if (mMachineTypeInfo[Index].MachineType == MachineType) {
return mMachineTypeInfo[Index].MachineTypeName;
}
@@ -121,8 +121,8 @@ STATIC
VOID
EFIAPI
PeCoffEmuProtocolNotify (
- IN EFI_EVENT Event,
- IN VOID *Context
+ IN EFI_EVENT Event,
+ IN VOID *Context
)
{
EFI_STATUS Status;
@@ -136,13 +136,13 @@ PeCoffEmuProtocolNotify (
while (TRUE) {
BufferSize = sizeof (EmuHandle);
- Status = CoreLocateHandle (
- ByRegisterNotify,
- NULL,
- mPeCoffEmuProtocolNotifyRegistration,
- &BufferSize,
- &EmuHandle
- );
+ Status = CoreLocateHandle (
+ ByRegisterNotify,
+ NULL,
+ mPeCoffEmuProtocolNotifyRegistration,
+ &BufferSize,
+ &EmuHandle
+ );
if (EFI_ERROR (Status)) {
//
// If no more notification events exit
@@ -155,7 +155,7 @@ PeCoffEmuProtocolNotify (
&gEdkiiPeCoffImageEmulatorProtocolGuid,
(VOID **)&Emulator
);
- if (EFI_ERROR (Status) || Emulator == NULL) {
+ if (EFI_ERROR (Status) || (Emulator == NULL)) {
continue;
}
@@ -180,20 +180,20 @@ PeCoffEmuProtocolNotify (
**/
EFI_STATUS
CoreInitializeImageServices (
- IN VOID *HobStart
+ IN VOID *HobStart
)
{
- EFI_STATUS Status;
- LOADED_IMAGE_PRIVATE_DATA *Image;
- EFI_PHYSICAL_ADDRESS DxeCoreImageBaseAddress;
- UINT64 DxeCoreImageLength;
- VOID *DxeCoreEntryPoint;
- EFI_PEI_HOB_POINTERS DxeCoreHob;
+ EFI_STATUS Status;
+ LOADED_IMAGE_PRIVATE_DATA *Image;
+ EFI_PHYSICAL_ADDRESS DxeCoreImageBaseAddress;
+ UINT64 DxeCoreImageLength;
+ VOID *DxeCoreEntryPoint;
+ EFI_PEI_HOB_POINTERS DxeCoreHob;
//
// Searching for image hob
//
- DxeCoreHob.Raw = HobStart;
+ DxeCoreHob.Raw = HobStart;
while ((DxeCoreHob.Raw = GetNextHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, DxeCoreHob.Raw)) != NULL) {
if (CompareGuid (&DxeCoreHob.MemoryAllocationModule->MemoryAllocationHeader.Name, &gEfiHobMemoryAllocModuleGuid)) {
//
@@ -201,13 +201,15 @@ CoreInitializeImageServices (
//
break;
}
+
DxeCoreHob.Raw = GET_NEXT_HOB (DxeCoreHob);
}
+
ASSERT (DxeCoreHob.Raw != NULL);
DxeCoreImageBaseAddress = DxeCoreHob.MemoryAllocationModule->MemoryAllocationHeader.MemoryBaseAddress;
DxeCoreImageLength = DxeCoreHob.MemoryAllocationModule->MemoryAllocationHeader.MemoryLength;
- DxeCoreEntryPoint = (VOID *) (UINTN) DxeCoreHob.MemoryAllocationModule->EntryPoint;
+ DxeCoreEntryPoint = (VOID *)(UINTN)DxeCoreHob.MemoryAllocationModule->EntryPoint;
gDxeCoreFileName = &DxeCoreHob.MemoryAllocationModule->ModuleName;
//
@@ -215,13 +217,13 @@ CoreInitializeImageServices (
//
Image = &mCorePrivateImage;
- Image->EntryPoint = (EFI_IMAGE_ENTRY_POINT)(UINTN)DxeCoreEntryPoint;
- Image->ImageBasePage = DxeCoreImageBaseAddress;
- Image->NumberOfPages = (UINTN)(EFI_SIZE_TO_PAGES((UINTN)(DxeCoreImageLength)));
- Image->Tpl = gEfiCurrentTpl;
- Image->Info.SystemTable = gDxeCoreST;
- Image->Info.ImageBase = (VOID *)(UINTN)DxeCoreImageBaseAddress;
- Image->Info.ImageSize = DxeCoreImageLength;
+ Image->EntryPoint = (EFI_IMAGE_ENTRY_POINT)(UINTN)DxeCoreEntryPoint;
+ Image->ImageBasePage = DxeCoreImageBaseAddress;
+ Image->NumberOfPages = (UINTN)(EFI_SIZE_TO_PAGES ((UINTN)(DxeCoreImageLength)));
+ Image->Tpl = gEfiCurrentTpl;
+ Image->Info.SystemTable = gDxeCoreST;
+ Image->Info.ImageBase = (VOID *)(UINTN)DxeCoreImageBaseAddress;
+ Image->Info.ImageSize = DxeCoreImageLength;
//
// Install the protocol interfaces for this image
@@ -240,8 +242,8 @@ CoreInitializeImageServices (
// Fill in DXE globals
//
mDxeCoreImageMachineType = PeCoffLoaderGetMachineType (Image->Info.ImageBase);
- gDxeCoreImageHandle = Image->Handle;
- gDxeCoreLoadedImage = &Image->Info;
+ gDxeCoreImageHandle = Image->Handle;
+ gDxeCoreLoadedImage = &Image->Info;
//
// Create the PE/COFF emulator protocol registration event
@@ -253,7 +255,7 @@ CoreInitializeImageServices (
NULL,
&mPeCoffEmuProtocolRegistrationEvent
);
- ASSERT_EFI_ERROR(Status);
+ ASSERT_EFI_ERROR (Status);
//
// Register for protocol notifications on this event
@@ -263,7 +265,7 @@ CoreInitializeImageServices (
mPeCoffEmuProtocolRegistrationEvent,
&mPeCoffEmuProtocolNotifyRegistration
);
- ASSERT_EFI_ERROR(Status);
+ ASSERT_EFI_ERROR (Status);
InitializeListHead (&mAvailableEmulators);
@@ -289,16 +291,16 @@ CoreInitializeImageServices (
EFI_STATUS
EFIAPI
CoreReadImageFile (
- IN VOID *UserHandle,
- IN UINTN Offset,
- IN OUT UINTN *ReadSize,
- OUT VOID *Buffer
+ IN VOID *UserHandle,
+ IN UINTN Offset,
+ IN OUT UINTN *ReadSize,
+ OUT VOID *Buffer
)
{
- UINTN EndPosition;
+ UINTN EndPosition;
IMAGE_FILE_HANDLE *FHand;
- if (UserHandle == NULL || ReadSize == NULL || Buffer == NULL) {
+ if ((UserHandle == NULL) || (ReadSize == NULL) || (Buffer == NULL)) {
return EFI_INVALID_PARAMETER;
}
@@ -316,13 +318,15 @@ CoreReadImageFile (
if (EndPosition > FHand->SourceSize) {
*ReadSize = (UINT32)(FHand->SourceSize - Offset);
}
+
if (Offset >= FHand->SourceSize) {
- *ReadSize = 0;
+ *ReadSize = 0;
}
CopyMem (Buffer, (CHAR8 *)FHand->Source + Offset, *ReadSize);
return EFI_SUCCESS;
}
+
/**
To check memory usage bit map array to figure out if the memory range the image will be loaded in is available or not. If
memory range is available, the function will mark the corresponding bits to 1 which indicates the memory range is used.
@@ -336,66 +340,73 @@ CoreReadImageFile (
**/
EFI_STATUS
CheckAndMarkFixLoadingMemoryUsageBitMap (
- IN EFI_PHYSICAL_ADDRESS ImageBase,
- IN UINTN ImageSize
+ IN EFI_PHYSICAL_ADDRESS ImageBase,
+ IN UINTN ImageSize
)
{
- UINT32 DxeCodePageNumber;
- UINT64 DxeCodeSize;
- EFI_PHYSICAL_ADDRESS DxeCodeBase;
- UINTN BaseOffsetPageNumber;
- UINTN TopOffsetPageNumber;
- UINTN Index;
- //
- // The DXE code range includes RuntimeCodePage range and Boot time code range.
- //
- DxeCodePageNumber = PcdGet32(PcdLoadFixAddressRuntimeCodePageNumber);
- DxeCodePageNumber += PcdGet32(PcdLoadFixAddressBootTimeCodePageNumber);
- DxeCodeSize = EFI_PAGES_TO_SIZE(DxeCodePageNumber);
- DxeCodeBase = gLoadModuleAtFixAddressConfigurationTable.DxeCodeTopAddress - DxeCodeSize;
-
- //
- // If the memory usage bit map is not initialized, do it. Every bit in the array
- // indicate the status of the corresponding memory page, available or not
- //
- if (mDxeCodeMemoryRangeUsageBitMap == NULL) {
- mDxeCodeMemoryRangeUsageBitMap = AllocateZeroPool(((DxeCodePageNumber/64) + 1)*sizeof(UINT64));
- }
- //
- // If the Dxe code memory range is not allocated or the bit map array allocation failed, return EFI_NOT_FOUND
- //
- if (!gLoadFixedAddressCodeMemoryReady || mDxeCodeMemoryRangeUsageBitMap == NULL) {
- return EFI_NOT_FOUND;
- }
- //
- // Test the memory range for loading the image in the DXE code range.
- //
- if (gLoadModuleAtFixAddressConfigurationTable.DxeCodeTopAddress < ImageBase + ImageSize ||
- DxeCodeBase > ImageBase) {
- return EFI_NOT_FOUND;
- }
- //
- // Test if the memory is avalaible or not.
- //
- BaseOffsetPageNumber = EFI_SIZE_TO_PAGES((UINT32)(ImageBase - DxeCodeBase));
- TopOffsetPageNumber = EFI_SIZE_TO_PAGES((UINT32)(ImageBase + ImageSize - DxeCodeBase));
- for (Index = BaseOffsetPageNumber; Index < TopOffsetPageNumber; Index ++) {
- if ((mDxeCodeMemoryRangeUsageBitMap[Index / 64] & LShiftU64(1, (Index % 64))) != 0) {
- //
- // This page is already used.
- //
- return EFI_NOT_FOUND;
- }
- }
-
- //
- // Being here means the memory range is available. So mark the bits for the memory range
- //
- for (Index = BaseOffsetPageNumber; Index < TopOffsetPageNumber; Index ++) {
- mDxeCodeMemoryRangeUsageBitMap[Index / 64] |= LShiftU64(1, (Index % 64));
- }
- return EFI_SUCCESS;
+ UINT32 DxeCodePageNumber;
+ UINT64 DxeCodeSize;
+ EFI_PHYSICAL_ADDRESS DxeCodeBase;
+ UINTN BaseOffsetPageNumber;
+ UINTN TopOffsetPageNumber;
+ UINTN Index;
+
+ //
+ // The DXE code range includes RuntimeCodePage range and Boot time code range.
+ //
+ DxeCodePageNumber = PcdGet32 (PcdLoadFixAddressRuntimeCodePageNumber);
+ DxeCodePageNumber += PcdGet32 (PcdLoadFixAddressBootTimeCodePageNumber);
+ DxeCodeSize = EFI_PAGES_TO_SIZE (DxeCodePageNumber);
+ DxeCodeBase = gLoadModuleAtFixAddressConfigurationTable.DxeCodeTopAddress - DxeCodeSize;
+
+ //
+ // If the memory usage bit map is not initialized, do it. Every bit in the array
+ // indicate the status of the corresponding memory page, available or not
+ //
+ if (mDxeCodeMemoryRangeUsageBitMap == NULL) {
+ mDxeCodeMemoryRangeUsageBitMap = AllocateZeroPool (((DxeCodePageNumber/64) + 1)*sizeof (UINT64));
+ }
+
+ //
+ // If the Dxe code memory range is not allocated or the bit map array allocation failed, return EFI_NOT_FOUND
+ //
+ if (!gLoadFixedAddressCodeMemoryReady || (mDxeCodeMemoryRangeUsageBitMap == NULL)) {
+ return EFI_NOT_FOUND;
+ }
+
+ //
+ // Test the memory range for loading the image in the DXE code range.
+ //
+ if ((gLoadModuleAtFixAddressConfigurationTable.DxeCodeTopAddress < ImageBase + ImageSize) ||
+ (DxeCodeBase > ImageBase))
+ {
+ return EFI_NOT_FOUND;
+ }
+
+ //
+ // Test if the memory is avalaible or not.
+ //
+ BaseOffsetPageNumber = EFI_SIZE_TO_PAGES ((UINT32)(ImageBase - DxeCodeBase));
+ TopOffsetPageNumber = EFI_SIZE_TO_PAGES ((UINT32)(ImageBase + ImageSize - DxeCodeBase));
+ for (Index = BaseOffsetPageNumber; Index < TopOffsetPageNumber; Index++) {
+ if ((mDxeCodeMemoryRangeUsageBitMap[Index / 64] & LShiftU64 (1, (Index % 64))) != 0) {
+ //
+ // This page is already used.
+ //
+ return EFI_NOT_FOUND;
+ }
+ }
+
+ //
+ // Being here means the memory range is available. So mark the bits for the memory range
+ //
+ for (Index = BaseOffsetPageNumber; Index < TopOffsetPageNumber; Index++) {
+ mDxeCodeMemoryRangeUsageBitMap[Index / 64] |= LShiftU64 (1, (Index % 64));
+ }
+
+ return EFI_SUCCESS;
}
+
/**
Get the fixed loading address from image header assigned by build tool. This function only be called
@@ -408,85 +419,89 @@ CheckAndMarkFixLoadingMemoryUsageBitMap (
**/
EFI_STATUS
-GetPeCoffImageFixLoadingAssignedAddress(
+GetPeCoffImageFixLoadingAssignedAddress (
IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
)
{
- UINTN SectionHeaderOffset;
- EFI_STATUS Status;
- EFI_IMAGE_SECTION_HEADER SectionHeader;
- EFI_IMAGE_OPTIONAL_HEADER_UNION *ImgHdr;
- UINT16 Index;
- UINTN Size;
- UINT16 NumberOfSections;
- IMAGE_FILE_HANDLE *Handle;
- UINT64 ValueInSectionHeader;
-
-
- Status = EFI_NOT_FOUND;
-
- //
- // Get PeHeader pointer
- //
- Handle = (IMAGE_FILE_HANDLE*)ImageContext->Handle;
- ImgHdr = (EFI_IMAGE_OPTIONAL_HEADER_UNION *)((CHAR8* )Handle->Source + ImageContext->PeCoffHeaderOffset);
- SectionHeaderOffset = ImageContext->PeCoffHeaderOffset +
- sizeof (UINT32) +
- sizeof (EFI_IMAGE_FILE_HEADER) +
- ImgHdr->Pe32.FileHeader.SizeOfOptionalHeader;
- NumberOfSections = ImgHdr->Pe32.FileHeader.NumberOfSections;
-
- //
- // Get base address from the first section header that doesn't point to code section.
- //
- for (Index = 0; Index < NumberOfSections; Index++) {
- //
- // Read section header from file
- //
- Size = sizeof (EFI_IMAGE_SECTION_HEADER);
- Status = ImageContext->ImageRead (
- ImageContext->Handle,
- SectionHeaderOffset,
- &Size,
- &SectionHeader
- );
- if (EFI_ERROR (Status)) {
- return Status;
- }
- if (Size != sizeof (EFI_IMAGE_SECTION_HEADER)) {
- return EFI_NOT_FOUND;
- }
-
- Status = EFI_NOT_FOUND;
-
- if ((SectionHeader.Characteristics & EFI_IMAGE_SCN_CNT_CODE) == 0) {
- //
- // Build tool will save the address in PointerToRelocations & PointerToLineNumbers fields in the first section header
- // that doesn't point to code section in image header, as well as ImageBase field of image header. And there is an
- // assumption that when the feature is enabled, if a module is assigned a loading address by tools, PointerToRelocations
- // & PointerToLineNumbers fields should NOT be Zero, or else, these 2 fields should be set to Zero
- //
- ValueInSectionHeader = ReadUnaligned64((UINT64*)&SectionHeader.PointerToRelocations);
- if (ValueInSectionHeader != 0) {
- //
- // When the feature is configured as load module at fixed absolute address, the ImageAddress field of ImageContext
- // hold the specified address. If the feature is configured as load module at fixed offset, ImageAddress hold an offset
- // relative to top address
- //
- if ((INT64)PcdGet64(PcdLoadModuleAtFixAddressEnable) < 0) {
- ImageContext->ImageAddress = gLoadModuleAtFixAddressConfigurationTable.DxeCodeTopAddress + (INT64)(INTN)ImageContext->ImageAddress;
- }
- //
- // Check if the memory range is available.
- //
- Status = CheckAndMarkFixLoadingMemoryUsageBitMap (ImageContext->ImageAddress, (UINTN)(ImageContext->ImageSize + ImageContext->SectionAlignment));
- }
- break;
- }
- SectionHeaderOffset += sizeof (EFI_IMAGE_SECTION_HEADER);
- }
- DEBUG ((DEBUG_INFO|DEBUG_LOAD, "LOADING MODULE FIXED INFO: Loading module at fixed address 0x%11p. Status = %r \n", (VOID *)(UINTN)(ImageContext->ImageAddress), Status));
- return Status;
+ UINTN SectionHeaderOffset;
+ EFI_STATUS Status;
+ EFI_IMAGE_SECTION_HEADER SectionHeader;
+ EFI_IMAGE_OPTIONAL_HEADER_UNION *ImgHdr;
+ UINT16 Index;
+ UINTN Size;
+ UINT16 NumberOfSections;
+ IMAGE_FILE_HANDLE *Handle;
+ UINT64 ValueInSectionHeader;
+
+ Status = EFI_NOT_FOUND;
+
+ //
+ // Get PeHeader pointer
+ //
+ Handle = (IMAGE_FILE_HANDLE *)ImageContext->Handle;
+ ImgHdr = (EFI_IMAGE_OPTIONAL_HEADER_UNION *)((CHAR8 *)Handle->Source + ImageContext->PeCoffHeaderOffset);
+ SectionHeaderOffset = ImageContext->PeCoffHeaderOffset +
+ sizeof (UINT32) +
+ sizeof (EFI_IMAGE_FILE_HEADER) +
+ ImgHdr->Pe32.FileHeader.SizeOfOptionalHeader;
+ NumberOfSections = ImgHdr->Pe32.FileHeader.NumberOfSections;
+
+ //
+ // Get base address from the first section header that doesn't point to code section.
+ //
+ for (Index = 0; Index < NumberOfSections; Index++) {
+ //
+ // Read section header from file
+ //
+ Size = sizeof (EFI_IMAGE_SECTION_HEADER);
+ Status = ImageContext->ImageRead (
+ ImageContext->Handle,
+ SectionHeaderOffset,
+ &Size,
+ &SectionHeader
+ );
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ if (Size != sizeof (EFI_IMAGE_SECTION_HEADER)) {
+ return EFI_NOT_FOUND;
+ }
+
+ Status = EFI_NOT_FOUND;
+
+ if ((SectionHeader.Characteristics & EFI_IMAGE_SCN_CNT_CODE) == 0) {
+ //
+ // Build tool will save the address in PointerToRelocations & PointerToLineNumbers fields in the first section header
+ // that doesn't point to code section in image header, as well as ImageBase field of image header. And there is an
+ // assumption that when the feature is enabled, if a module is assigned a loading address by tools, PointerToRelocations
+ // & PointerToLineNumbers fields should NOT be Zero, or else, these 2 fields should be set to Zero
+ //
+ ValueInSectionHeader = ReadUnaligned64 ((UINT64 *)&SectionHeader.PointerToRelocations);
+ if (ValueInSectionHeader != 0) {
+ //
+ // When the feature is configured as load module at fixed absolute address, the ImageAddress field of ImageContext
+ // hold the specified address. If the feature is configured as load module at fixed offset, ImageAddress hold an offset
+ // relative to top address
+ //
+ if ((INT64)PcdGet64 (PcdLoadModuleAtFixAddressEnable) < 0) {
+ ImageContext->ImageAddress = gLoadModuleAtFixAddressConfigurationTable.DxeCodeTopAddress + (INT64)(INTN)ImageContext->ImageAddress;
+ }
+
+ //
+ // Check if the memory range is available.
+ //
+ Status = CheckAndMarkFixLoadingMemoryUsageBitMap (ImageContext->ImageAddress, (UINTN)(ImageContext->ImageSize + ImageContext->SectionAlignment));
+ }
+
+ break;
+ }
+
+ SectionHeaderOffset += sizeof (EFI_IMAGE_SECTION_HEADER);
+ }
+
+ DEBUG ((DEBUG_INFO|DEBUG_LOAD, "LOADING MODULE FIXED INFO: Loading module at fixed address 0x%11p. Status = %r \n", (VOID *)(UINTN)(ImageContext->ImageAddress), Status));
+ return Status;
}
/**
@@ -507,21 +522,24 @@ CoreIsImageTypeSupported (
IN OUT LOADED_IMAGE_PRIVATE_DATA *Image
)
{
- LIST_ENTRY *Link;
- EMULATOR_ENTRY *Entry;
+ LIST_ENTRY *Link;
+ EMULATOR_ENTRY *Entry;
for (Link = GetFirstNode (&mAvailableEmulators);
!IsNull (&mAvailableEmulators, Link);
- Link = GetNextNode (&mAvailableEmulators, Link)) {
-
+ Link = GetNextNode (&mAvailableEmulators, Link))
+ {
Entry = BASE_CR (Link, EMULATOR_ENTRY, Link);
if (Entry->MachineType != Image->ImageContext.Machine) {
continue;
}
- if (Entry->Emulator->IsImageSupported (Entry->Emulator,
+ if (Entry->Emulator->IsImageSupported (
+ Entry->Emulator,
Image->ImageContext.ImageType,
- Image->Info.FilePath)) {
+ Image->Info.FilePath
+ ))
+ {
Image->PeCoffEmu = Entry->Emulator;
return TRUE;
}
@@ -554,17 +572,17 @@ CoreIsImageTypeSupported (
**/
EFI_STATUS
CoreLoadPeImage (
- IN BOOLEAN BootPolicy,
- IN VOID *Pe32Handle,
- IN LOADED_IMAGE_PRIVATE_DATA *Image,
- IN EFI_PHYSICAL_ADDRESS DstBuffer OPTIONAL,
- OUT EFI_PHYSICAL_ADDRESS *EntryPoint OPTIONAL,
- IN UINT32 Attribute
+ IN BOOLEAN BootPolicy,
+ IN VOID *Pe32Handle,
+ IN LOADED_IMAGE_PRIVATE_DATA *Image,
+ IN EFI_PHYSICAL_ADDRESS DstBuffer OPTIONAL,
+ OUT EFI_PHYSICAL_ADDRESS *EntryPoint OPTIONAL,
+ IN UINT32 Attribute
)
{
- EFI_STATUS Status;
- BOOLEAN DstBufAlocated;
- UINTN Size;
+ EFI_STATUS Status;
+ BOOLEAN DstBufAlocated;
+ UINTN Size;
ZeroMem (&Image->ImageContext, sizeof (Image->ImageContext));
@@ -584,9 +602,12 @@ CoreLoadPeImage (
// The PE/COFF loader can support loading image types that can be executed.
// If we loaded an image type that we can not execute return EFI_UNSUPPORTED.
//
- DEBUG ((DEBUG_ERROR, "Image type %s can't be loaded on %s UEFI system.\n",
+ DEBUG ((
+ DEBUG_ERROR,
+ "Image type %s can't be loaded on %s UEFI system.\n",
GetMachineTypeName (Image->ImageContext.Machine),
- GetMachineTypeName (mDxeCoreImageMachineType)));
+ GetMachineTypeName (mDxeCoreImageMachineType)
+ ));
return EFI_UNSUPPORTED;
}
@@ -594,22 +615,22 @@ CoreLoadPeImage (
// Set EFI memory type based on ImageType
//
switch (Image->ImageContext.ImageType) {
- case EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION:
- Image->ImageContext.ImageCodeMemoryType = EfiLoaderCode;
- Image->ImageContext.ImageDataMemoryType = EfiLoaderData;
- break;
- case EFI_IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER:
- Image->ImageContext.ImageCodeMemoryType = EfiBootServicesCode;
- Image->ImageContext.ImageDataMemoryType = EfiBootServicesData;
- break;
- case EFI_IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER:
- case EFI_IMAGE_SUBSYSTEM_SAL_RUNTIME_DRIVER:
- Image->ImageContext.ImageCodeMemoryType = EfiRuntimeServicesCode;
- Image->ImageContext.ImageDataMemoryType = EfiRuntimeServicesData;
- break;
- default:
- Image->ImageContext.ImageError = IMAGE_ERROR_INVALID_SUBSYSTEM;
- return EFI_UNSUPPORTED;
+ case EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION:
+ Image->ImageContext.ImageCodeMemoryType = EfiLoaderCode;
+ Image->ImageContext.ImageDataMemoryType = EfiLoaderData;
+ break;
+ case EFI_IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER:
+ Image->ImageContext.ImageCodeMemoryType = EfiBootServicesCode;
+ Image->ImageContext.ImageDataMemoryType = EfiBootServicesData;
+ break;
+ case EFI_IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER:
+ case EFI_IMAGE_SUBSYSTEM_SAL_RUNTIME_DRIVER:
+ Image->ImageContext.ImageCodeMemoryType = EfiRuntimeServicesCode;
+ Image->ImageContext.ImageDataMemoryType = EfiRuntimeServicesData;
+ break;
+ default:
+ Image->ImageContext.ImageError = IMAGE_ERROR_INVALID_SUBSYSTEM;
+ return EFI_UNSUPPORTED;
}
//
@@ -641,43 +662,46 @@ CoreLoadPeImage (
// If Loading Module At Fixed Address feature is enabled, the module should be loaded to
// a specified address.
//
- if (PcdGet64(PcdLoadModuleAtFixAddressEnable) != 0 ) {
+ if (PcdGet64 (PcdLoadModuleAtFixAddressEnable) != 0 ) {
Status = GetPeCoffImageFixLoadingAssignedAddress (&(Image->ImageContext));
- if (EFI_ERROR (Status)) {
- //
- // If the code memory is not ready, invoke CoreAllocatePage with AllocateAnyPages to load the driver.
- //
- DEBUG ((DEBUG_INFO|DEBUG_LOAD, "LOADING MODULE FIXED ERROR: Loading module at fixed address failed since specified memory is not available.\n"));
-
- Status = CoreAllocatePages (
- AllocateAnyPages,
- (EFI_MEMORY_TYPE) (Image->ImageContext.ImageCodeMemoryType),
- Image->NumberOfPages,
- &Image->ImageContext.ImageAddress
- );
+ if (EFI_ERROR (Status)) {
+ //
+ // If the code memory is not ready, invoke CoreAllocatePage with AllocateAnyPages to load the driver.
+ //
+ DEBUG ((DEBUG_INFO|DEBUG_LOAD, "LOADING MODULE FIXED ERROR: Loading module at fixed address failed since specified memory is not available.\n"));
+
+ Status = CoreAllocatePages (
+ AllocateAnyPages,
+ (EFI_MEMORY_TYPE)(Image->ImageContext.ImageCodeMemoryType),
+ Image->NumberOfPages,
+ &Image->ImageContext.ImageAddress
+ );
}
} else {
- if (Image->ImageContext.ImageAddress >= 0x100000 || Image->ImageContext.RelocationsStripped) {
+ if ((Image->ImageContext.ImageAddress >= 0x100000) || Image->ImageContext.RelocationsStripped) {
Status = CoreAllocatePages (
AllocateAddress,
- (EFI_MEMORY_TYPE) (Image->ImageContext.ImageCodeMemoryType),
+ (EFI_MEMORY_TYPE)(Image->ImageContext.ImageCodeMemoryType),
Image->NumberOfPages,
&Image->ImageContext.ImageAddress
);
}
+
if (EFI_ERROR (Status) && !Image->ImageContext.RelocationsStripped) {
Status = CoreAllocatePages (
AllocateAnyPages,
- (EFI_MEMORY_TYPE) (Image->ImageContext.ImageCodeMemoryType),
+ (EFI_MEMORY_TYPE)(Image->ImageContext.ImageCodeMemoryType),
Image->NumberOfPages,
&Image->ImageContext.ImageAddress
);
}
}
+
if (EFI_ERROR (Status)) {
return Status;
}
+
DstBufAlocated = TRUE;
} else {
//
@@ -693,22 +717,23 @@ CoreLoadPeImage (
return EFI_INVALID_PARAMETER;
}
- if (Image->NumberOfPages != 0 &&
- Image->NumberOfPages <
- (EFI_SIZE_TO_PAGES ((UINTN)Image->ImageContext.ImageSize + Image->ImageContext.SectionAlignment))) {
+ if ((Image->NumberOfPages != 0) &&
+ (Image->NumberOfPages <
+ (EFI_SIZE_TO_PAGES ((UINTN)Image->ImageContext.ImageSize + Image->ImageContext.SectionAlignment))))
+ {
Image->NumberOfPages = EFI_SIZE_TO_PAGES ((UINTN)Image->ImageContext.ImageSize + Image->ImageContext.SectionAlignment);
return EFI_BUFFER_TOO_SMALL;
}
- Image->NumberOfPages = EFI_SIZE_TO_PAGES ((UINTN)Image->ImageContext.ImageSize + Image->ImageContext.SectionAlignment);
+ Image->NumberOfPages = EFI_SIZE_TO_PAGES ((UINTN)Image->ImageContext.ImageSize + Image->ImageContext.SectionAlignment);
Image->ImageContext.ImageAddress = DstBuffer;
}
Image->ImageBasePage = Image->ImageContext.ImageAddress;
if (!Image->ImageContext.IsTeImage) {
Image->ImageContext.ImageAddress =
- (Image->ImageContext.ImageAddress + Image->ImageContext.SectionAlignment - 1) &
- ~((UINTN)Image->ImageContext.SectionAlignment - 1);
+ (Image->ImageContext.ImageAddress + Image->ImageContext.SectionAlignment - 1) &
+ ~((UINTN)Image->ImageContext.SectionAlignment - 1);
}
//
@@ -755,7 +780,7 @@ CoreLoadPeImage (
//
// Get the image entry point.
//
- Image->EntryPoint = (EFI_IMAGE_ENTRY_POINT)(UINTN)Image->ImageContext.EntryPoint;
+ Image->EntryPoint = (EFI_IMAGE_ENTRY_POINT)(UINTN)Image->ImageContext.EntryPoint;
//
// Fill in the image information for the Loaded Image Protocol
@@ -763,19 +788,20 @@ CoreLoadPeImage (
Image->Type = Image->ImageContext.ImageType;
Image->Info.ImageBase = (VOID *)(UINTN)Image->ImageContext.ImageAddress;
Image->Info.ImageSize = Image->ImageContext.ImageSize;
- Image->Info.ImageCodeType = (EFI_MEMORY_TYPE) (Image->ImageContext.ImageCodeMemoryType);
- Image->Info.ImageDataType = (EFI_MEMORY_TYPE) (Image->ImageContext.ImageDataMemoryType);
+ Image->Info.ImageCodeType = (EFI_MEMORY_TYPE)(Image->ImageContext.ImageCodeMemoryType);
+ Image->Info.ImageDataType = (EFI_MEMORY_TYPE)(Image->ImageContext.ImageDataMemoryType);
if ((Attribute & EFI_LOAD_PE_IMAGE_ATTRIBUTE_RUNTIME_REGISTRATION) != 0) {
if (Image->ImageContext.ImageType == EFI_IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER) {
//
// Make a list off all the RT images so we can let the RT AP know about them.
//
- Image->RuntimeData = AllocateRuntimePool (sizeof(EFI_RUNTIME_IMAGE_ENTRY));
+ Image->RuntimeData = AllocateRuntimePool (sizeof (EFI_RUNTIME_IMAGE_ENTRY));
if (Image->RuntimeData == NULL) {
goto Done;
}
+
Image->RuntimeData->ImageBase = Image->Info.ImageBase;
- Image->RuntimeData->ImageSize = (UINT64) (Image->Info.ImageSize);
+ Image->RuntimeData->ImageSize = (UINT64)(Image->Info.ImageSize);
Image->RuntimeData->RelocationData = Image->ImageContext.FixupData;
Image->RuntimeData->Handle = Image->Handle;
InsertTailList (&gRuntime->ImageHead, &Image->RuntimeData->Link);
@@ -796,53 +822,57 @@ CoreLoadPeImage (
DEBUG_CODE_BEGIN ();
- UINTN Index;
- UINTN StartIndex;
- CHAR8 EfiFileName[256];
-
+ UINTN Index;
+ UINTN StartIndex;
+ CHAR8 EfiFileName[256];
- DEBUG ((DEBUG_INFO | DEBUG_LOAD,
- "Loading driver at 0x%11p EntryPoint=0x%11p ",
- (VOID *)(UINTN) Image->ImageContext.ImageAddress,
- FUNCTION_ENTRY_POINT (Image->ImageContext.EntryPoint)));
+ DEBUG ((
+ DEBUG_INFO | DEBUG_LOAD,
+ "Loading driver at 0x%11p EntryPoint=0x%11p ",
+ (VOID *)(UINTN)Image->ImageContext.ImageAddress,
+ FUNCTION_ENTRY_POINT (Image->ImageContext.EntryPoint)
+ ));
+ //
+ // Print Module Name by Pdb file path.
+ // Windows and Unix style file path are all trimmed correctly.
+ //
+ if (Image->ImageContext.PdbPointer != NULL) {
+ StartIndex = 0;
+ for (Index = 0; Image->ImageContext.PdbPointer[Index] != 0; Index++) {
+ if ((Image->ImageContext.PdbPointer[Index] == '\\') || (Image->ImageContext.PdbPointer[Index] == '/')) {
+ StartIndex = Index + 1;
+ }
+ }
//
- // Print Module Name by Pdb file path.
- // Windows and Unix style file path are all trimmed correctly.
+ // Copy the PDB file name to our temporary string, and replace .pdb with .efi
+ // The PDB file name is limited in the range of 0~255.
+ // If the length is bigger than 255, trim the redudant characters to avoid overflow in array boundary.
//
- if (Image->ImageContext.PdbPointer != NULL) {
- StartIndex = 0;
- for (Index = 0; Image->ImageContext.PdbPointer[Index] != 0; Index++) {
- if ((Image->ImageContext.PdbPointer[Index] == '\\') || (Image->ImageContext.PdbPointer[Index] == '/')) {
- StartIndex = Index + 1;
- }
- }
- //
- // Copy the PDB file name to our temporary string, and replace .pdb with .efi
- // The PDB file name is limited in the range of 0~255.
- // If the length is bigger than 255, trim the redudant characters to avoid overflow in array boundary.
- //
- for (Index = 0; Index < sizeof (EfiFileName) - 4; Index++) {
- EfiFileName[Index] = Image->ImageContext.PdbPointer[Index + StartIndex];
- if (EfiFileName[Index] == 0) {
- EfiFileName[Index] = '.';
- }
- if (EfiFileName[Index] == '.') {
- EfiFileName[Index + 1] = 'e';
- EfiFileName[Index + 2] = 'f';
- EfiFileName[Index + 3] = 'i';
- EfiFileName[Index + 4] = 0;
- break;
- }
+ for (Index = 0; Index < sizeof (EfiFileName) - 4; Index++) {
+ EfiFileName[Index] = Image->ImageContext.PdbPointer[Index + StartIndex];
+ if (EfiFileName[Index] == 0) {
+ EfiFileName[Index] = '.';
}
- if (Index == sizeof (EfiFileName) - 4) {
- EfiFileName[Index] = 0;
+ if (EfiFileName[Index] == '.') {
+ EfiFileName[Index + 1] = 'e';
+ EfiFileName[Index + 2] = 'f';
+ EfiFileName[Index + 3] = 'i';
+ EfiFileName[Index + 4] = 0;
+ break;
}
- DEBUG ((DEBUG_INFO | DEBUG_LOAD, "%a", EfiFileName)); // &Image->ImageContext.PdbPointer[StartIndex]));
}
- DEBUG ((DEBUG_INFO | DEBUG_LOAD, "\n"));
+
+ if (Index == sizeof (EfiFileName) - 4) {
+ EfiFileName[Index] = 0;
+ }
+
+ DEBUG ((DEBUG_INFO | DEBUG_LOAD, "%a", EfiFileName)); // &Image->ImageContext.PdbPointer[StartIndex]));
+ }
+
+ DEBUG ((DEBUG_INFO | DEBUG_LOAD, "\n"));
DEBUG_CODE_END ();
@@ -857,7 +887,7 @@ Done:
if (DstBufAlocated) {
CoreFreePages (Image->ImageContext.ImageAddress, Image->NumberOfPages);
Image->ImageContext.ImageAddress = 0;
- Image->ImageBasePage = 0;
+ Image->ImageBasePage = 0;
}
if (Image->ImageContext.FixupData != NULL) {
@@ -867,8 +897,6 @@ Done:
return Status;
}
-
-
/**
Get the image's private data from its handle.
@@ -901,7 +929,6 @@ CoreLoadedImageInfo (
return Image;
}
-
/**
Unloads EFI image from memory.
@@ -915,18 +942,18 @@ CoreUnloadAndCloseImage (
IN BOOLEAN FreePage
)
{
- EFI_STATUS Status;
- UINTN HandleCount;
- EFI_HANDLE *HandleBuffer;
- UINTN HandleIndex;
- EFI_GUID **ProtocolGuidArray;
- UINTN ArrayCount;
- UINTN ProtocolIndex;
- EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *OpenInfo;
- UINTN OpenInfoCount;
- UINTN OpenInfoIndex;
-
- HandleBuffer = NULL;
+ EFI_STATUS Status;
+ UINTN HandleCount;
+ EFI_HANDLE *HandleBuffer;
+ UINTN HandleIndex;
+ EFI_GUID **ProtocolGuidArray;
+ UINTN ArrayCount;
+ UINTN ProtocolIndex;
+ EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *OpenInfo;
+ UINTN OpenInfoCount;
+ UINTN OpenInfoIndex;
+
+ HandleBuffer = NULL;
ProtocolGuidArray = NULL;
if (Image->Started) {
@@ -951,7 +978,6 @@ CoreUnloadAndCloseImage (
// Free our references to the image handle
//
if (Image->Handle != NULL) {
-
Status = CoreLocateHandleBuffer (
AllHandles,
NULL,
@@ -985,16 +1011,19 @@ CoreUnloadAndCloseImage (
);
}
}
+
if (OpenInfo != NULL) {
- CoreFreePool(OpenInfo);
+ CoreFreePool (OpenInfo);
}
}
}
+
if (ProtocolGuidArray != NULL) {
- CoreFreePool(ProtocolGuidArray);
+ CoreFreePool (ProtocolGuidArray);
}
}
}
+
if (HandleBuffer != NULL) {
CoreFreePool (HandleBuffer);
}
@@ -1018,10 +1047,9 @@ CoreUnloadAndCloseImage (
Status = CoreUninstallProtocolInterface (
Image->Handle,
&gEfiHiiPackageListProtocolGuid,
- (VOID *) (UINTN) Image->ImageContext.HiiResourceData
+ (VOID *)(UINTN)Image->ImageContext.HiiResourceData
);
}
-
}
if (Image->RuntimeData != NULL) {
@@ -1032,6 +1060,7 @@ CoreUnloadAndCloseImage (
RemoveEntryList (&Image->RuntimeData->Link);
RemoveImageRecord (Image->RuntimeData);
}
+
CoreFreePool (Image->RuntimeData);
}
@@ -1060,7 +1089,6 @@ CoreUnloadAndCloseImage (
CoreFreePool (Image);
}
-
/**
Loads an EFI image into memory and returns a handle to the image.
@@ -1107,16 +1135,16 @@ CoreUnloadAndCloseImage (
**/
EFI_STATUS
CoreLoadImageCommon (
- IN BOOLEAN BootPolicy,
- IN EFI_HANDLE ParentImageHandle,
- IN EFI_DEVICE_PATH_PROTOCOL *FilePath,
- IN VOID *SourceBuffer OPTIONAL,
- IN UINTN SourceSize,
- IN EFI_PHYSICAL_ADDRESS DstBuffer OPTIONAL,
- IN OUT UINTN *NumberOfPages OPTIONAL,
- OUT EFI_HANDLE *ImageHandle,
- OUT EFI_PHYSICAL_ADDRESS *EntryPoint OPTIONAL,
- IN UINT32 Attribute
+ IN BOOLEAN BootPolicy,
+ IN EFI_HANDLE ParentImageHandle,
+ IN EFI_DEVICE_PATH_PROTOCOL *FilePath,
+ IN VOID *SourceBuffer OPTIONAL,
+ IN UINTN SourceSize,
+ IN EFI_PHYSICAL_ADDRESS DstBuffer OPTIONAL,
+ IN OUT UINTN *NumberOfPages OPTIONAL,
+ OUT EFI_HANDLE *ImageHandle,
+ OUT EFI_PHYSICAL_ADDRESS *EntryPoint OPTIONAL,
+ IN UINT32 Attribute
)
{
LOADED_IMAGE_PRIVATE_DATA *Image;
@@ -1142,23 +1170,23 @@ CoreLoadImageCommon (
//
// The caller must pass in a valid ParentImageHandle
//
- if (ImageHandle == NULL || ParentImageHandle == NULL) {
+ if ((ImageHandle == NULL) || (ParentImageHandle == NULL)) {
return EFI_INVALID_PARAMETER;
}
ParentImage = CoreLoadedImageInfo (ParentImageHandle);
if (ParentImage == NULL) {
- DEBUG((DEBUG_LOAD|DEBUG_ERROR, "LoadImageEx: Parent handle not an image handle\n"));
+ DEBUG ((DEBUG_LOAD|DEBUG_ERROR, "LoadImageEx: Parent handle not an image handle\n"));
return EFI_INVALID_PARAMETER;
}
ZeroMem (&FHand, sizeof (IMAGE_FILE_HANDLE));
- FHand.Signature = IMAGE_FILE_HANDLE_SIGNATURE;
- OriginalFilePath = FilePath;
- InputFilePath = FilePath;
- HandleFilePath = FilePath;
- DeviceHandle = NULL;
- Status = EFI_SUCCESS;
+ FHand.Signature = IMAGE_FILE_HANDLE_SIGNATURE;
+ OriginalFilePath = FilePath;
+ InputFilePath = FilePath;
+ HandleFilePath = FilePath;
+ DeviceHandle = NULL;
+ Status = EFI_SUCCESS;
AuthenticationStatus = 0;
ImageIsFromFv = FALSE;
ImageIsFromLoadFile = FALSE;
@@ -1169,10 +1197,11 @@ CoreLoadImageCommon (
if (SourceBuffer != NULL) {
FHand.Source = SourceBuffer;
FHand.SourceSize = SourceSize;
- Status = CoreLocateDevicePath (&gEfiDevicePathProtocolGuid, &HandleFilePath, &DeviceHandle);
+ Status = CoreLocateDevicePath (&gEfiDevicePathProtocolGuid, &HandleFilePath, &DeviceHandle);
if (EFI_ERROR (Status)) {
DeviceHandle = NULL;
}
+
if (SourceSize > 0) {
Status = EFI_SUCCESS;
} else {
@@ -1192,18 +1221,19 @@ CoreLoadImageCommon (
ImageIsFromFv = TRUE;
} else {
HandleFilePath = FilePath;
- Status = CoreLocateDevicePath (&gEfiSimpleFileSystemProtocolGuid, &HandleFilePath, &DeviceHandle);
+ Status = CoreLocateDevicePath (&gEfiSimpleFileSystemProtocolGuid, &HandleFilePath, &DeviceHandle);
if (EFI_ERROR (Status)) {
if (!BootPolicy) {
HandleFilePath = FilePath;
- Status = CoreLocateDevicePath (&gEfiLoadFile2ProtocolGuid, &HandleFilePath, &DeviceHandle);
+ Status = CoreLocateDevicePath (&gEfiLoadFile2ProtocolGuid, &HandleFilePath, &DeviceHandle);
}
+
if (EFI_ERROR (Status)) {
HandleFilePath = FilePath;
- Status = CoreLocateDevicePath (&gEfiLoadFileProtocolGuid, &HandleFilePath, &DeviceHandle);
+ Status = CoreLocateDevicePath (&gEfiLoadFileProtocolGuid, &HandleFilePath, &DeviceHandle);
if (!EFI_ERROR (Status)) {
ImageIsFromLoadFile = TRUE;
- Node = HandleFilePath;
+ Node = HandleFilePath;
}
}
}
@@ -1213,11 +1243,11 @@ CoreLoadImageCommon (
// Get the source file buffer by its device path.
//
FHand.Source = GetFileBufferByFilePath (
- BootPolicy,
- FilePath,
- &FHand.SourceSize,
- &AuthenticationStatus
- );
+ BootPolicy,
+ FilePath,
+ &FHand.SourceSize,
+ &AuthenticationStatus
+ );
if (FHand.Source == NULL) {
Status = EFI_NOT_FOUND;
} else {
@@ -1241,12 +1271,12 @@ CoreLoadImageCommon (
// Verify File Authentication through the Security2 Architectural Protocol
//
SecurityStatus = gSecurity2->FileAuthentication (
- gSecurity2,
- OriginalFilePath,
- FHand.Source,
- FHand.SourceSize,
- BootPolicy
- );
+ gSecurity2,
+ OriginalFilePath,
+ FHand.Source,
+ FHand.SourceSize,
+ BootPolicy
+ );
if (!EFI_ERROR (SecurityStatus) && ImageIsFromFv) {
//
// When Security2 is installed, Security Architectural Protocol must be published.
@@ -1277,7 +1307,7 @@ CoreLoadImageCommon (
//
// Check Security Status.
//
- if (EFI_ERROR (SecurityStatus) && SecurityStatus != EFI_SECURITY_VIOLATION) {
+ if (EFI_ERROR (SecurityStatus) && (SecurityStatus != EFI_SECURITY_VIOLATION)) {
if (SecurityStatus == EFI_ACCESS_DENIED) {
//
// Image was not loaded because the platform policy prohibits the image from being loaded.
@@ -1285,15 +1315,16 @@ CoreLoadImageCommon (
//
*ImageHandle = NULL;
}
+
Status = SecurityStatus;
- Image = NULL;
+ Image = NULL;
goto Done;
}
//
// Allocate a new image structure
//
- Image = AllocateZeroPool (sizeof(LOADED_IMAGE_PRIVATE_DATA));
+ Image = AllocateZeroPool (sizeof (LOADED_IMAGE_PRIVATE_DATA));
if (Image == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto Done;
@@ -1306,10 +1337,11 @@ CoreLoadImageCommon (
if (DeviceHandle != NULL) {
Status = CoreHandleProtocol (DeviceHandle, &gEfiDevicePathProtocolGuid, (VOID **)&HandleFilePath);
if (!EFI_ERROR (Status)) {
- FilePathSize = GetDevicePathSize (HandleFilePath) - sizeof(EFI_DEVICE_PATH_PROTOCOL);
- FilePath = (EFI_DEVICE_PATH_PROTOCOL *) (((UINT8 *)FilePath) + FilePathSize );
+ FilePathSize = GetDevicePathSize (HandleFilePath) - sizeof (EFI_DEVICE_PATH_PROTOCOL);
+ FilePath = (EFI_DEVICE_PATH_PROTOCOL *)(((UINT8 *)FilePath) + FilePathSize);
}
}
+
//
// Initialize the fields for an internal driver
//
@@ -1320,11 +1352,10 @@ CoreLoadImageCommon (
Image->Info.FilePath = DuplicateDevicePath (FilePath);
Image->Info.ParentHandle = ParentImageHandle;
-
if (NumberOfPages != NULL) {
- Image->NumberOfPages = *NumberOfPages ;
+ Image->NumberOfPages = *NumberOfPages;
} else {
- Image->NumberOfPages = 0 ;
+ Image->NumberOfPages = 0;
}
//
@@ -1352,6 +1383,7 @@ CoreLoadImageCommon (
*NumberOfPages = Image->NumberOfPages;
}
}
+
goto Done;
}
@@ -1367,7 +1399,7 @@ CoreLoadImageCommon (
}
//
- //Reinstall loaded image protocol to fire any notifications
+ // Reinstall loaded image protocol to fire any notifications
//
Status = CoreReinstallProtocolInterface (
Image->Handle,
@@ -1391,11 +1423,11 @@ CoreLoadImageCommon (
// Install Loaded Image Device Path Protocol onto the image handle of a PE/COFE image
//
Status = CoreInstallProtocolInterface (
- &Image->Handle,
- &gEfiLoadedImageDevicePathProtocolGuid,
- EFI_NATIVE_INTERFACE,
- Image->LoadedImageDevicePath
- );
+ &Image->Handle,
+ &gEfiLoadedImageDevicePathProtocolGuid,
+ EFI_NATIVE_INTERFACE,
+ Image->LoadedImageDevicePath
+ );
if (EFI_ERROR (Status)) {
goto Done;
}
@@ -1408,12 +1440,13 @@ CoreLoadImageCommon (
&Image->Handle,
&gEfiHiiPackageListProtocolGuid,
EFI_NATIVE_INTERFACE,
- (VOID *) (UINTN) Image->ImageContext.HiiResourceData
+ (VOID *)(UINTN)Image->ImageContext.HiiResourceData
);
if (EFI_ERROR (Status)) {
goto Done;
}
}
+
ProtectUefiImage (&Image->Info, Image->LoadedImageDevicePath);
//
@@ -1429,6 +1462,7 @@ Done:
if (FHand.FreeBuffer) {
CoreFreePool (FHand.Source);
}
+
if (OriginalFilePath != InputFilePath) {
CoreFreePool (OriginalFilePath);
}
@@ -1455,9 +1489,6 @@ Done:
return Status;
}
-
-
-
/**
Loads an EFI image into memory and returns a handle to the image.
@@ -1495,16 +1526,16 @@ Done:
EFI_STATUS
EFIAPI
CoreLoadImage (
- IN BOOLEAN BootPolicy,
- IN EFI_HANDLE ParentImageHandle,
- IN EFI_DEVICE_PATH_PROTOCOL *FilePath,
- IN VOID *SourceBuffer OPTIONAL,
- IN UINTN SourceSize,
- OUT EFI_HANDLE *ImageHandle
+ IN BOOLEAN BootPolicy,
+ IN EFI_HANDLE ParentImageHandle,
+ IN EFI_DEVICE_PATH_PROTOCOL *FilePath,
+ IN VOID *SourceBuffer OPTIONAL,
+ IN UINTN SourceSize,
+ OUT EFI_HANDLE *ImageHandle
)
{
- EFI_STATUS Status;
- EFI_HANDLE Handle;
+ EFI_STATUS Status;
+ EFI_HANDLE Handle;
PERF_LOAD_IMAGE_BEGIN (NULL);
@@ -1514,7 +1545,7 @@ CoreLoadImage (
FilePath,
SourceBuffer,
SourceSize,
- (EFI_PHYSICAL_ADDRESS) (UINTN) NULL,
+ (EFI_PHYSICAL_ADDRESS)(UINTN)NULL,
NULL,
ImageHandle,
NULL,
@@ -1561,19 +1592,20 @@ CoreStartImage (
OUT CHAR16 **ExitData OPTIONAL
)
{
- EFI_STATUS Status;
- LOADED_IMAGE_PRIVATE_DATA *Image;
- LOADED_IMAGE_PRIVATE_DATA *LastImage;
- UINT64 HandleDatabaseKey;
- UINTN SetJumpFlag;
- EFI_HANDLE Handle;
+ EFI_STATUS Status;
+ LOADED_IMAGE_PRIVATE_DATA *Image;
+ LOADED_IMAGE_PRIVATE_DATA *LastImage;
+ UINT64 HandleDatabaseKey;
+ UINTN SetJumpFlag;
+ EFI_HANDLE Handle;
Handle = ImageHandle;
Image = CoreLoadedImageInfo (ImageHandle);
- if (Image == NULL || Image->Started) {
+ if ((Image == NULL) || Image->Started) {
return EFI_INVALID_PARAMETER;
}
+
if (EFI_ERROR (Image->LoadImageStatus)) {
return Image->LoadImageStatus;
}
@@ -1582,32 +1614,36 @@ CoreStartImage (
// The image to be started must have the machine type supported by DxeCore.
//
if (!EFI_IMAGE_MACHINE_TYPE_SUPPORTED (Image->Machine) &&
- Image->PeCoffEmu == NULL) {
+ (Image->PeCoffEmu == NULL))
+ {
//
// Do not ASSERT here, because image might be loaded via EFI_IMAGE_MACHINE_CROSS_TYPE_SUPPORTED
// But it can not be started.
//
- DEBUG ((DEBUG_ERROR, "Image type %s can't be started ", GetMachineTypeName(Image->Machine)));
- DEBUG ((DEBUG_ERROR, "on %s UEFI system.\n", GetMachineTypeName(mDxeCoreImageMachineType)));
+ DEBUG ((DEBUG_ERROR, "Image type %s can't be started ", GetMachineTypeName (Image->Machine)));
+ DEBUG ((DEBUG_ERROR, "on %s UEFI system.\n", GetMachineTypeName (mDxeCoreImageMachineType)));
return EFI_UNSUPPORTED;
}
if (Image->PeCoffEmu != NULL) {
- Status = Image->PeCoffEmu->RegisterImage (Image->PeCoffEmu,
+ Status = Image->PeCoffEmu->RegisterImage (
+ Image->PeCoffEmu,
Image->ImageBasePage,
EFI_PAGES_TO_SIZE (Image->NumberOfPages),
- &Image->EntryPoint);
+ &Image->EntryPoint
+ );
if (EFI_ERROR (Status)) {
- DEBUG ((DEBUG_LOAD | DEBUG_ERROR,
+ DEBUG ((
+ DEBUG_LOAD | DEBUG_ERROR,
"CoreLoadPeImage: Failed to register foreign image with emulator - %r\n",
- Status));
+ Status
+ ));
return Status;
}
}
PERF_START_IMAGE_BEGIN (Handle);
-
//
// Push the current start image context, and
// link the current image to the head. This is the
@@ -1638,6 +1674,7 @@ CoreStartImage (
return EFI_OUT_OF_RESOURCES;
}
+
Image->JumpContext = ALIGN_POINTER (Image->JumpBuffer, BASE_LIBRARY_JUMP_BUFFER_ALIGNMENT);
SetJumpFlag = SetJump (Image->JumpContext);
@@ -1651,7 +1688,7 @@ CoreStartImage (
// Call the image's entry point
//
Image->Started = TRUE;
- Image->Status = Image->EntryPoint (ImageHandle, Image->Info.SystemTable);
+ Image->Status = Image->EntryPoint (ImageHandle, Image->Info.SystemTable);
//
// Add some debug information if the image returned with error.
@@ -1659,9 +1696,10 @@ CoreStartImage (
// all the resource in this situation.
//
DEBUG_CODE_BEGIN ();
- if (EFI_ERROR (Image->Status)) {
- DEBUG ((DEBUG_ERROR, "Error: Image at %11p start failed: %r\n", Image->Info.ImageBase, Image->Status));
- }
+ if (EFI_ERROR (Image->Status)) {
+ DEBUG ((DEBUG_ERROR, "Error: Image at %11p start failed: %r\n", Image->Info.ImageBase, Image->Status));
+ }
+
DEBUG_CODE_END ();
//
@@ -1700,20 +1738,21 @@ CoreStartImage (
// Handle the image's returned ExitData
//
DEBUG_CODE_BEGIN ();
- if (Image->ExitDataSize != 0 || Image->ExitData != NULL) {
-
- DEBUG ((DEBUG_LOAD, "StartImage: ExitDataSize %d, ExitData %p", (UINT32)Image->ExitDataSize, Image->ExitData));
- if (Image->ExitData != NULL) {
- DEBUG ((DEBUG_LOAD, " (%hs)", Image->ExitData));
- }
- DEBUG ((DEBUG_LOAD, "\n"));
+ if ((Image->ExitDataSize != 0) || (Image->ExitData != NULL)) {
+ DEBUG ((DEBUG_LOAD, "StartImage: ExitDataSize %d, ExitData %p", (UINT32)Image->ExitDataSize, Image->ExitData));
+ if (Image->ExitData != NULL) {
+ DEBUG ((DEBUG_LOAD, " (%hs)", Image->ExitData));
}
+
+ DEBUG ((DEBUG_LOAD, "\n"));
+ }
+
DEBUG_CODE_END ();
//
// Return the exit data to the caller
//
- if (ExitData != NULL && ExitDataSize != NULL) {
+ if ((ExitData != NULL) && (ExitDataSize != NULL)) {
*ExitDataSize = Image->ExitDataSize;
*ExitData = Image->ExitData;
} else {
@@ -1733,7 +1772,7 @@ CoreStartImage (
// If the image returned an error, or if the image is an application
// unload it
//
- if (EFI_ERROR (Image->Status) || Image->Type == EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION) {
+ if (EFI_ERROR (Image->Status) || (Image->Type == EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION)) {
CoreUnloadAndCloseImage (Image, TRUE);
//
// ImageHandle may be invalid after the image is unloaded, so use NULL handle to record perf log.
@@ -1823,11 +1862,12 @@ CoreExit (
//
if (ExitData != NULL) {
Image->ExitDataSize = ExitDataSize;
- Image->ExitData = AllocatePool (Image->ExitDataSize);
+ Image->ExitData = AllocatePool (Image->ExitDataSize);
if (Image->ExitData == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto Done;
}
+
CopyMem (Image->ExitData, ExitData, Image->ExitDataSize);
}
@@ -1847,9 +1887,6 @@ Done:
return Status;
}
-
-
-
/**
Unloads an image.
@@ -1888,7 +1925,6 @@ CoreUnloadImage (
if (Image->Info.Unload != NULL) {
Status = Image->Info.Unload (ImageHandle);
}
-
} else {
//
// This Image hasn't been started, thus it can be unloaded
@@ -1896,7 +1932,6 @@ CoreUnloadImage (
Status = EFI_SUCCESS;
}
-
if (!EFI_ERROR (Status)) {
//
// if the Image was not started or Unloaded O.K. then clean up
diff --git a/MdeModulePkg/Core/Dxe/Image/Image.h b/MdeModulePkg/Core/Dxe/Image/Image.h
index e9c44ab2a7..7e4175e562 100644
--- a/MdeModulePkg/Core/Dxe/Image/Image.h
+++ b/MdeModulePkg/Core/Dxe/Image/Image.h
@@ -6,19 +6,18 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/
-
#ifndef _IMAGE_H_
#define _IMAGE_H_
//
// Private Data Types
//
-#define IMAGE_FILE_HANDLE_SIGNATURE SIGNATURE_32('i','m','g','f')
+#define IMAGE_FILE_HANDLE_SIGNATURE SIGNATURE_32('i','m','g','f')
typedef struct {
- UINTN Signature;
- BOOLEAN FreeBuffer;
- VOID *Source;
- UINTN SourceSize;
+ UINTN Signature;
+ BOOLEAN FreeBuffer;
+ VOID *Source;
+ UINTN SourceSize;
} IMAGE_FILE_HANDLE;
#endif