X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FCore%2FDxe%2FImage%2FImage.c;h=c49ddfcc81d16cae42ff0f315dfe8fc405c8d6bf;hp=99170dca90d8d0ec10c4379b5c184faf137f3bcc;hb=471048388cda4935866f829365922cdf70a6a45c;hpb=e98cd821ebedd6472c12738bd53dc7cfd02bb4fb diff --git a/MdeModulePkg/Core/Dxe/Image/Image.c b/MdeModulePkg/Core/Dxe/Image/Image.c index 99170dca90..c49ddfcc81 100644 --- a/MdeModulePkg/Core/Dxe/Image/Image.c +++ b/MdeModulePkg/Core/Dxe/Image/Image.c @@ -1,7 +1,8 @@ -/*++ +/** @file + Core image handling services to load and unload PeImage. -Copyright (c) 2006 - 2007, Intel Corporation -All rights reserved. This program and the accompanying materials +Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.
+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 http://opensource.org/licenses/bsd-license.php @@ -9,21 +10,14 @@ http://opensource.org/licenses/bsd-license.php THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -Module Name: +**/ - Image.c +#include "DxeMain.h" +#include "Image.h" -Abstract: - - Core image handling services - ---*/ - -#include // // Module Globals // - LOADED_IMAGE_PRIVATE_DATA *mCurrentImage = NULL; LOAD_PE32_IMAGE_PRIVATE_DATA mLoadPe32PrivateData = { @@ -74,30 +68,69 @@ LOADED_IMAGE_PRIVATE_DATA mCorePrivateImage = { 0, // Machine NULL, // Ebc NULL, // RuntimeData - NULL, // DeviceHandleDevicePath + NULL // LoadedImageDevicePath }; +// +// The field is define for Loading modules at fixed address feature to tracker the PEI code +// 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; +typedef struct { + UINT16 MachineType; + CHAR16 *MachineTypeName; +} MACHINE_TYPE_INFO; -EFI_STATUS -CoreInitializeImageServices ( - IN VOID *HobStart +// +// EBC machine is not listed in this table, because EBC is in the default supported scopes of other machine type. +// +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"} +}; + +UINT16 mDxeCoreImageMachineType = 0; + +/** + Return machine type name. + + @param MachineType The machine type + + @return machine type name +**/ +CHAR16 * +GetMachineTypeName ( + UINT16 MachineType ) -/*++ +{ + UINTN Index; + + for (Index = 0; Index < sizeof(mMachineTypeInfo)/sizeof(mMachineTypeInfo[0]); Index++) { + if (mMachineTypeInfo[Index].MachineType == MachineType) { + return mMachineTypeInfo[Index].MachineTypeName; + } + } -Routine Description: + return L""; +} +/** Add the Image Services to EFI Boot Services Table and install the protocol interfaces for this image. -Arguments: - - HobStart - The HOB to initialize + @param HobStart The HOB to initialize -Returns: + @return Status code. - Status code. - ---*/ +**/ +EFI_STATUS +CoreInitializeImageServices ( + IN VOID *HobStart + ) { EFI_STATUS Status; LOADED_IMAGE_PRIVATE_DATA *Image; @@ -105,6 +138,7 @@ Returns: UINT64 DxeCoreImageLength; VOID *DxeCoreEntryPoint; EFI_PEI_HOB_POINTERS DxeCoreHob; + // // Searching for image hob // @@ -124,6 +158,7 @@ Returns: DxeCoreImageLength = DxeCoreHob.MemoryAllocationModule->MemoryAllocationHeader.MemoryLength; DxeCoreEntryPoint = (VOID *) (UINTN) DxeCoreHob.MemoryAllocationModule->EntryPoint; gDxeCoreFileName = &DxeCoreHob.MemoryAllocationModule->ModuleName; + // // Initialize the fields for an internal driver // @@ -153,57 +188,277 @@ Returns: // // Fill in DXE globals // + mDxeCoreImageMachineType = PeCoffLoaderGetMachineType (Image->Info.ImageBase); gDxeCoreImageHandle = Image->Handle; gDxeCoreLoadedImage = &Image->Info; - // - // Export DXE Core PE Loader functionality - // - return CoreInstallProtocolInterface ( - &mLoadPe32PrivateData.Handle, - &gEfiLoadPeImageProtocolGuid, - EFI_NATIVE_INTERFACE, - &mLoadPe32PrivateData.Pe32Image - ); + if (FeaturePcdGet (PcdFrameworkCompatibilitySupport)) { + // + // Export DXE Core PE Loader functionality for backward compatibility. + // + Status = CoreInstallProtocolInterface ( + &mLoadPe32PrivateData.Handle, + &gEfiLoadPeImageProtocolGuid, + EFI_NATIVE_INTERFACE, + &mLoadPe32PrivateData.Pe32Image + ); + } + + ProtectUefiImage (&Image->Info, Image->LoadedImageDevicePath); + + return Status; } +/** + Read image file (specified by UserHandle) into user specified buffer with specified offset + and length. + + @param UserHandle Image file handle + @param Offset Offset to the source file + @param ReadSize For input, pointer of size to read; For output, + pointer of size actually read. + @param Buffer Buffer to write into + + @retval EFI_SUCCESS Successfully read the specified part of file + into buffer. + +**/ EFI_STATUS -CoreLoadPeImage ( - IN VOID *Pe32Handle, - IN LOADED_IMAGE_PRIVATE_DATA *Image, - IN EFI_PHYSICAL_ADDRESS DstBuffer OPTIONAL, - OUT EFI_PHYSICAL_ADDRESS *EntryPoint OPTIONAL, - IN UINT32 Attribute +EFIAPI +CoreReadImageFile ( + IN VOID *UserHandle, + IN UINTN Offset, + IN OUT UINTN *ReadSize, + OUT VOID *Buffer ) -/*++ - -Routine Description: +{ + UINTN EndPosition; + IMAGE_FILE_HANDLE *FHand; - Loads, relocates, and invokes a PE/COFF image + if (UserHandle == NULL || ReadSize == NULL || Buffer == NULL) { + return EFI_INVALID_PARAMETER; + } -Arguments: + if (MAX_ADDRESS - Offset < *ReadSize) { + return EFI_INVALID_PARAMETER; + } - Pe32Handle - The handle of PE32 image - Image - PE image to be loaded - DstBuffer - The buffer to store the image - EntryPoint - A pointer to the entry point - Attribute - The bit mask of attributes to set for the load PE image + FHand = (IMAGE_FILE_HANDLE *)UserHandle; + ASSERT (FHand->Signature == IMAGE_FILE_HANDLE_SIGNATURE); -Returns: + // + // Move data from our local copy of the file + // + EndPosition = Offset + *ReadSize; + if (EndPosition > FHand->SourceSize) { + *ReadSize = (UINT32)(FHand->SourceSize - Offset); + } + if (Offset >= FHand->SourceSize) { + *ReadSize = 0; + } - EFI_SUCCESS - The file was loaded, relocated, and invoked + 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. + The function is only invoked when load modules at fixed address feature is enabled. + + @param ImageBase The base address the image will be loaded at. + @param ImageSize The size of the image + + @retval EFI_SUCCESS The memory range the image will be loaded in is available + @retval EFI_NOT_FOUND The memory range the image will be loaded in is not available +**/ +EFI_STATUS +CheckAndMarkFixLoadingMemoryUsageBitMap ( + 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; +} +/** - EFI_OUT_OF_RESOURCES - There was not enough memory to load and relocate the PE/COFF file + Get the fixed loading address from image header assigned by build tool. This function only be called + when Loading module at Fixed address feature enabled. - EFI_INVALID_PARAMETER - Invalid parameter + @param ImageContext Pointer to the image context structure that describes the PE/COFF + image that needs to be examined by this function. + @retval EFI_SUCCESS An fixed loading address is assigned to this image by build tools . + @retval EFI_NOT_FOUND The image has no assigned fixed loading address. - EFI_BUFFER_TOO_SMALL - Buffer for image is too small +**/ +EFI_STATUS +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 spcified 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 ((EFI_D_INFO|EFI_D_LOAD, "LOADING MODULE FIXED INFO: Loading module at fixed address 0x%11p. Status = %r \n", (VOID *)(UINTN)(ImageContext->ImageAddress), Status)); + return Status; +} +/** + Loads, relocates, and invokes a PE/COFF image ---*/ + @param BootPolicy If TRUE, indicates that the request originates + from the boot manager, and that the boot + manager is attempting to load FilePath as a + boot selection. + @param Pe32Handle The handle of PE32 image + @param Image PE image to be loaded + @param DstBuffer The buffer to store the image + @param EntryPoint A pointer to the entry point + @param Attribute The bit mask of attributes to set for the load + PE image + + @retval EFI_SUCCESS The file was loaded, relocated, and invoked + @retval EFI_OUT_OF_RESOURCES There was not enough memory to load and + relocate the PE/COFF file + @retval EFI_INVALID_PARAMETER Invalid parameter + @retval EFI_BUFFER_TOO_SMALL Buffer for image is too small + +**/ +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 + ) { - EFI_STATUS Status; - BOOLEAN DstBufAlocated; - UINTN Size; + EFI_STATUS Status; + BOOLEAN DstBufAlocated; + UINTN Size; ZeroMem (&Image->ImageContext, sizeof (Image->ImageContext)); @@ -219,13 +474,17 @@ Returns: } if (!EFI_IMAGE_MACHINE_TYPE_SUPPORTED (Image->ImageContext.Machine)) { - // - // 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_UNSUPORTED. - // - return EFI_UNSUPPORTED; + if (!EFI_IMAGE_MACHINE_CROSS_TYPE_SUPPORTED (Image->ImageContext.Machine)) { + // + // 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_UNSUPORTED. + // + DEBUG ((EFI_D_ERROR, "Image type %s can't be loaded ", GetMachineTypeName(Image->ImageContext.Machine))); + DEBUG ((EFI_D_ERROR, "on %s UEFI system.\n", GetMachineTypeName(mDxeCoreImageMachineType))); + return EFI_UNSUPPORTED; + } } - + // // Set EFI memory type based on ImageType // @@ -249,7 +508,7 @@ Returns: } // - // Allocate memory of the correct memory type aligned on the required image boundry + // Allocate memory of the correct memory type aligned on the required image boundary // DstBufAlocated = FALSE; if (DstBuffer == 0) { @@ -273,21 +532,43 @@ Returns: // no modules whose preferred load addresses are below 1MB. // Status = EFI_OUT_OF_RESOURCES; - if (Image->ImageContext.ImageAddress >= 0x100000 || Image->ImageContext.RelocationsStripped) { - Status = CoreAllocatePages ( - AllocateAddress, - (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), - Image->NumberOfPages, - &Image->ImageContext.ImageAddress - ); + // + // If Loading Module At Fixed Address feature is enabled, the module should be loaded to + // a specified address. + // + 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 ((EFI_D_INFO|EFI_D_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) { + Status = CoreAllocatePages ( + AllocateAddress, + (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), + Image->NumberOfPages, + &Image->ImageContext.ImageAddress + ); + } } if (EFI_ERROR (Status)) { return Status; @@ -319,9 +600,11 @@ Returns: } Image->ImageBasePage = Image->ImageContext.ImageAddress; - Image->ImageContext.ImageAddress = - (Image->ImageContext.ImageAddress + Image->ImageContext.SectionAlignment - 1) & - ~((UINTN)Image->ImageContext.SectionAlignment - 1); + if (!Image->ImageContext.IsTeImage) { + Image->ImageContext.ImageAddress = + (Image->ImageContext.ImageAddress + Image->ImageContext.SectionAlignment - 1) & + ~((UINTN)Image->ImageContext.SectionAlignment - 1); + } // // Load the image from the file into the allocated memory @@ -336,9 +619,9 @@ Returns: // is used to relocate the image when SetVirtualAddressMap() is called. The // relocation is done by the Runtime AP. // - if (Attribute & EFI_LOAD_PE_IMAGE_ATTRIBUTE_RUNTIME_REGISTRATION) { + if ((Attribute & EFI_LOAD_PE_IMAGE_ATTRIBUTE_RUNTIME_REGISTRATION) != 0) { if (Image->ImageContext.ImageType == EFI_IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER) { - Image->ImageContext.FixupData = CoreAllocateRuntimePool ((UINTN)(Image->ImageContext.FixupDataSize)); + Image->ImageContext.FixupData = AllocateRuntimePool ((UINTN)(Image->ImageContext.FixupDataSize)); if (Image->ImageContext.FixupData == NULL) { Status = EFI_OUT_OF_RESOURCES; goto Done; @@ -377,7 +660,8 @@ Returns: // Locate the EBC interpreter protocol // Status = CoreLocateProtocol (&gEfiEbcProtocolGuid, NULL, (VOID **)&Image->Ebc); - if (EFI_ERROR(Status)) { + if (EFI_ERROR(Status) || Image->Ebc == NULL) { + DEBUG ((DEBUG_LOAD | DEBUG_ERROR, "CoreLoadPeImage: There is no EBC interpreter for an EBC image.\n")); goto Done; } @@ -397,8 +681,8 @@ Returns: Status = Image->Ebc->CreateThunk ( Image->Ebc, Image->Handle, - (VOID *)(UINTN)Image->ImageContext.EntryPoint, - (VOID **)&Image->EntryPoint + (VOID *)(UINTN) Image->ImageContext.EntryPoint, + (VOID **) &Image->EntryPoint ); if (EFI_ERROR(Status)) { goto Done; @@ -413,12 +697,12 @@ Returns: Image->Info.ImageSize = Image->ImageContext.ImageSize; 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) { + 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 = CoreAllocateRuntimePool (sizeof(EFI_RUNTIME_IMAGE_ENTRY)); + Image->RuntimeData = AllocateRuntimePool (sizeof(EFI_RUNTIME_IMAGE_ENTRY)); if (Image->RuntimeData == NULL) { goto Done; } @@ -427,6 +711,7 @@ Returns: Image->RuntimeData->RelocationData = Image->ImageContext.FixupData; Image->RuntimeData->Handle = Image->Handle; InsertTailList (&gRuntime->ImageHead, &Image->RuntimeData->Link); + InsertImageRecord (Image->RuntimeData); } } @@ -446,36 +731,31 @@ Returns: UINTN Index; UINTN StartIndex; CHAR8 EfiFileName[256]; - - if (Image->ImageContext.Machine != IMAGE_FILE_MACHINE_IA64) { - DEBUG ((EFI_D_INFO | EFI_D_LOAD, - "Loading driver at 0x%10p EntryPoint=0x%10p ", - (VOID *)(UINTN)Image->ImageContext.ImageAddress, - (VOID *)(UINTN)Image->ImageContext.EntryPoint)); - } else { - // - // For IPF Image, the real entry point should be print. - // - DEBUG ((EFI_D_INFO | EFI_D_LOAD, - "Loading driver at 0x%10p EntryPoint=0x%10p ", - (VOID *)(UINTN)Image->ImageContext.ImageAddress, - (VOID *)(UINTN)(*(UINT64 *)(UINTN)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 + // 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] == '\\') { + 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); Index++) { + for (Index = 0; Index < sizeof (EfiFileName) - 4; Index++) { EfiFileName[Index] = Image->ImageContext.PdbPointer[Index + StartIndex]; if (EfiFileName[Index] == 0) { EfiFileName[Index] = '.'; @@ -488,9 +768,13 @@ Returns: break; } } - DEBUG ((EFI_D_INFO | EFI_D_LOAD, "%a", EfiFileName)); // &Image->ImageContext.PdbPointer[StartIndex])); + + if (Index == sizeof (EfiFileName) - 4) { + EfiFileName[Index] = 0; + } + DEBUG ((DEBUG_INFO | DEBUG_LOAD, "%a", EfiFileName)); // &Image->ImageContext.PdbPointer[StartIndex])); } - DEBUG ((EFI_D_INFO | EFI_D_LOAD, "\n")); + DEBUG ((DEBUG_INFO | DEBUG_LOAD, "\n")); DEBUG_CODE_END (); @@ -504,6 +788,8 @@ Done: if (DstBufAlocated) { CoreFreePages (Image->ImageContext.ImageAddress, Image->NumberOfPages); + Image->ImageContext.ImageAddress = 0; + Image->ImageBasePage = 0; } if (Image->ImageContext.FixupData != NULL) { @@ -514,25 +800,19 @@ Done: } -LOADED_IMAGE_PRIVATE_DATA * -CoreLoadedImageInfo ( - IN EFI_HANDLE ImageHandle - ) -/*++ - -Routine Description: +/** Get the image's private data from its handle. -Arguments: + @param ImageHandle The image handle - ImageHandle - The image handle + @return Return the image private data associated with ImageHandle. -Returns: - - Return the image private data associated with ImageHandle. - ---*/ +**/ +LOADED_IMAGE_PRIVATE_DATA * +CoreLoadedImageInfo ( + IN EFI_HANDLE ImageHandle + ) { EFI_STATUS Status; EFI_LOADED_IMAGE_PROTOCOL *LoadedImage; @@ -546,154 +826,430 @@ Returns: if (!EFI_ERROR (Status)) { Image = LOADED_IMAGE_PRIVATE_DATA_FROM_THIS (LoadedImage); } else { - DEBUG ((EFI_D_LOAD, "CoreLoadedImageInfo: Not an ImageHandle %x\n", ImageHandle)); + DEBUG ((DEBUG_LOAD, "CoreLoadedImageInfo: Not an ImageHandle %p\n", ImageHandle)); Image = NULL; } return Image; } -STATIC -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 - ) -/*++ -Routine Description: +/** + Unloads EFI image from memory. - Loads an EFI image into memory and returns a handle to the image. + @param Image EFI image + @param FreePage Free allocated pages -Arguments: - - BootPolicy - If TRUE, indicates that the request originates from the boot manager, - and that the boot manager is attempting to load FilePath as a boot selection. - ParentImageHandle - The caller's image handle. - FilePath - The specific file path from which the image is loaded. - SourceBuffer - If not NULL, a pointer to the memory location containing a copy of - the image to be loaded. - SourceSize - The size in bytes of SourceBuffer. - DstBuffer - The buffer to store the image - NumberOfPages - If not NULL, a pointer to the image's page number, if this number - is not enough, return EFI_BUFFER_TOO_SMALL and this parameter contain - the required number. - ImageHandle - Pointer to the returned image handle that is created when the image - is successfully loaded. - EntryPoint - A pointer to the entry point - Attribute - The bit mask of attributes to set for the load PE image - -Returns: - - EFI_SUCCESS - The image was loaded into memory. - EFI_NOT_FOUND - The FilePath was not found. - EFI_INVALID_PARAMETER - One of the parameters has an invalid value. - EFI_BUFFER_TOO_SMALL - The buffer is too small - EFI_UNSUPPORTED - The image type is not supported, or the device path cannot be - parsed to locate the proper protocol for loading the file. - EFI_OUT_OF_RESOURCES - Image was not loaded due to insufficient resources. ---*/ +**/ +VOID +CoreUnloadAndCloseImage ( + IN LOADED_IMAGE_PRIVATE_DATA *Image, + IN BOOLEAN FreePage + ) { - LOADED_IMAGE_PRIVATE_DATA *Image; - LOADED_IMAGE_PRIVATE_DATA *ParentImage; - IMAGE_FILE_HANDLE FHand; - EFI_STATUS Status; - EFI_STATUS SecurityStatus; - EFI_HANDLE DeviceHandle; - UINT32 AuthenticationStatus; - EFI_DEVICE_PATH_PROTOCOL *OriginalFilePath; - EFI_DEVICE_PATH_PROTOCOL *HandleFilePath; - UINTN FilePathSize; - - SecurityStatus = EFI_SUCCESS; + 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; - ASSERT (gEfiCurrentTpl < TPL_NOTIFY); - ParentImage = NULL; + HandleBuffer = NULL; + ProtocolGuidArray = NULL; - // - // The caller must pass in a valid ParentImageHandle - // - if (ImageHandle == NULL || ParentImageHandle == NULL) { - return EFI_INVALID_PARAMETER; + if (Image->Started) { + UnregisterMemoryProfileImage (Image); } - ParentImage = CoreLoadedImageInfo (ParentImageHandle); - if (ParentImage == NULL) { - DEBUG((EFI_D_LOAD|EFI_D_ERROR, "LoadImageEx: Parent handle not an image handle\n")); - return EFI_INVALID_PARAMETER; + UnprotectUefiImage (&Image->Info, Image->LoadedImageDevicePath); + + if (Image->Ebc != NULL) { + // + // If EBC protocol exists we must perform cleanups for this image. + // + Image->Ebc->UnloadImage (Image->Ebc, Image->Handle); } // - // Get simple read access to the source file + // Unload image, free Image->ImageContext->ModHandle // - OriginalFilePath = FilePath; - Status = CoreOpenImageFile ( - BootPolicy, - SourceBuffer, - SourceSize, - FilePath, - &DeviceHandle, - &FHand, - &AuthenticationStatus - ); - if (Status == EFI_ALREADY_STARTED) { - Image = NULL; - goto Done; - } else if (EFI_ERROR (Status)) { - return Status; - } + PeCoffLoaderUnloadImage (&Image->ImageContext); // - // Verify the Authentication Status through the Security Architectural Protocol + // Free our references to the image handle // - if ((gSecurity != NULL) && (OriginalFilePath != NULL)) { - SecurityStatus = gSecurity->FileAuthenticationState ( - gSecurity, - AuthenticationStatus, - OriginalFilePath - ); - if (EFI_ERROR (SecurityStatus) && SecurityStatus != EFI_SECURITY_VIOLATION) { - Status = SecurityStatus; - Image = NULL; - goto Done; + if (Image->Handle != NULL) { + + Status = CoreLocateHandleBuffer ( + AllHandles, + NULL, + NULL, + &HandleCount, + &HandleBuffer + ); + if (!EFI_ERROR (Status)) { + for (HandleIndex = 0; HandleIndex < HandleCount; HandleIndex++) { + Status = CoreProtocolsPerHandle ( + HandleBuffer[HandleIndex], + &ProtocolGuidArray, + &ArrayCount + ); + if (!EFI_ERROR (Status)) { + for (ProtocolIndex = 0; ProtocolIndex < ArrayCount; ProtocolIndex++) { + Status = CoreOpenProtocolInformation ( + HandleBuffer[HandleIndex], + ProtocolGuidArray[ProtocolIndex], + &OpenInfo, + &OpenInfoCount + ); + if (!EFI_ERROR (Status)) { + for (OpenInfoIndex = 0; OpenInfoIndex < OpenInfoCount; OpenInfoIndex++) { + if (OpenInfo[OpenInfoIndex].AgentHandle == Image->Handle) { + Status = CoreCloseProtocol ( + HandleBuffer[HandleIndex], + ProtocolGuidArray[ProtocolIndex], + Image->Handle, + OpenInfo[OpenInfoIndex].ControllerHandle + ); + } + } + if (OpenInfo != NULL) { + CoreFreePool(OpenInfo); + } + } + } + if (ProtocolGuidArray != NULL) { + CoreFreePool(ProtocolGuidArray); + } + } + } + if (HandleBuffer != NULL) { + CoreFreePool (HandleBuffer); + } } - } + CoreRemoveDebugImageInfoEntry (Image->Handle); - // - // Allocate a new image structure - // - Image = CoreAllocateZeroBootServicesPool (sizeof(LOADED_IMAGE_PRIVATE_DATA)); - if (Image == NULL) { - return EFI_OUT_OF_RESOURCES; - } + Status = CoreUninstallProtocolInterface ( + Image->Handle, + &gEfiLoadedImageDevicePathProtocolGuid, + Image->LoadedImageDevicePath + ); + + Status = CoreUninstallProtocolInterface ( + Image->Handle, + &gEfiLoadedImageProtocolGuid, + &Image->Info + ); + + if (Image->ImageContext.HiiResourceData != 0) { + Status = CoreUninstallProtocolInterface ( + Image->Handle, + &gEfiHiiPackageListProtocolGuid, + (VOID *) (UINTN) Image->ImageContext.HiiResourceData + ); + } + + } + + if (Image->RuntimeData != NULL) { + if (Image->RuntimeData->Link.ForwardLink != NULL) { + // + // Remove the Image from the Runtime Image list as we are about to Free it! + // + RemoveEntryList (&Image->RuntimeData->Link); + RemoveImageRecord (Image->RuntimeData); + } + CoreFreePool (Image->RuntimeData); + } // - // Pull out just the file portion of the DevicePath for the LoadedImage FilePath + // Free the Image from memory // - Status = CoreHandleProtocol (DeviceHandle, &gEfiDevicePathProtocolGuid, (VOID **)&HandleFilePath); - if (!EFI_ERROR (Status)) { - FilePathSize = CoreDevicePathSize (HandleFilePath) - sizeof(EFI_DEVICE_PATH_PROTOCOL); - FilePath = (EFI_DEVICE_PATH_PROTOCOL *) ( ((UINT8 *)FilePath) + FilePathSize ); - Image->DeviceHandleDevicePath = CoreDuplicateDevicePath (HandleFilePath); + if ((Image->ImageBasePage != 0) && FreePage) { + CoreFreePages (Image->ImageBasePage, Image->NumberOfPages); + } + + // + // Done with the Image structure + // + if (Image->Info.FilePath != NULL) { + CoreFreePool (Image->Info.FilePath); + } + + if (Image->LoadedImageDevicePath != NULL) { + CoreFreePool (Image->LoadedImageDevicePath); + } + + if (Image->FixupData != NULL) { + CoreFreePool (Image->FixupData); + } + + CoreFreePool (Image); +} + + +/** + Loads an EFI image into memory and returns a handle to the image. + + @param BootPolicy If TRUE, indicates that the request originates + from the boot manager, and that the boot + manager is attempting to load FilePath as a + boot selection. + @param ParentImageHandle The caller's image handle. + @param FilePath The specific file path from which the image is + loaded. + @param SourceBuffer If not NULL, a pointer to the memory location + containing a copy of the image to be loaded. + @param SourceSize The size in bytes of SourceBuffer. + @param DstBuffer The buffer to store the image + @param NumberOfPages If not NULL, it inputs a pointer to the page + number of DstBuffer and outputs a pointer to + the page number of the image. If this number is + not enough, return EFI_BUFFER_TOO_SMALL and + this parameter contains the required number. + @param ImageHandle Pointer to the returned image handle that is + created when the image is successfully loaded. + @param EntryPoint A pointer to the entry point + @param Attribute The bit mask of attributes to set for the load + PE image + + @retval EFI_SUCCESS The image was loaded into memory. + @retval EFI_NOT_FOUND The FilePath was not found. + @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value. + @retval EFI_BUFFER_TOO_SMALL The buffer is too small + @retval EFI_UNSUPPORTED The image type is not supported, or the device + path cannot be parsed to locate the proper + protocol for loading the file. + @retval EFI_OUT_OF_RESOURCES Image was not loaded due to insufficient + resources. + @retval EFI_LOAD_ERROR Image was not loaded because the image format was corrupt or not + understood. + @retval EFI_DEVICE_ERROR Image was not loaded because the device returned a read error. + @retval EFI_ACCESS_DENIED Image was not loaded because the platform policy prohibits the + image from being loaded. NULL is returned in *ImageHandle. + @retval EFI_SECURITY_VIOLATION Image was loaded and an ImageHandle was created with a + valid EFI_LOADED_IMAGE_PROTOCOL. However, the current + platform policy specifies that the image should not be started. + +**/ +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 + ) +{ + LOADED_IMAGE_PRIVATE_DATA *Image; + LOADED_IMAGE_PRIVATE_DATA *ParentImage; + IMAGE_FILE_HANDLE FHand; + EFI_STATUS Status; + EFI_STATUS SecurityStatus; + EFI_HANDLE DeviceHandle; + UINT32 AuthenticationStatus; + EFI_DEVICE_PATH_PROTOCOL *OriginalFilePath; + EFI_DEVICE_PATH_PROTOCOL *HandleFilePath; + EFI_DEVICE_PATH_PROTOCOL *InputFilePath; + EFI_DEVICE_PATH_PROTOCOL *Node; + UINTN FilePathSize; + BOOLEAN ImageIsFromFv; + BOOLEAN ImageIsFromLoadFile; + + SecurityStatus = EFI_SUCCESS; + + ASSERT (gEfiCurrentTpl < TPL_NOTIFY); + ParentImage = NULL; + + // + // The caller must pass in a valid ParentImageHandle + // + 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")); + 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; + AuthenticationStatus = 0; + ImageIsFromFv = FALSE; + ImageIsFromLoadFile = FALSE; + + // + // If the caller passed a copy of the file, then just use it + // + if (SourceBuffer != NULL) { + FHand.Source = SourceBuffer; + FHand.SourceSize = SourceSize; + Status = CoreLocateDevicePath (&gEfiDevicePathProtocolGuid, &HandleFilePath, &DeviceHandle); + if (EFI_ERROR (Status)) { + DeviceHandle = NULL; + } + if (SourceSize > 0) { + Status = EFI_SUCCESS; + } else { + Status = EFI_LOAD_ERROR; + } + } else { + if (FilePath == NULL) { + return EFI_INVALID_PARAMETER; + } + + // + // Try to get the image device handle by checking the match protocol. + // + Node = NULL; + Status = CoreLocateDevicePath (&gEfiFirmwareVolume2ProtocolGuid, &HandleFilePath, &DeviceHandle); + if (!EFI_ERROR (Status)) { + ImageIsFromFv = TRUE; + } else { + HandleFilePath = FilePath; + Status = CoreLocateDevicePath (&gEfiSimpleFileSystemProtocolGuid, &HandleFilePath, &DeviceHandle); + if (EFI_ERROR (Status)) { + if (!BootPolicy) { + HandleFilePath = FilePath; + Status = CoreLocateDevicePath (&gEfiLoadFile2ProtocolGuid, &HandleFilePath, &DeviceHandle); + } + if (EFI_ERROR (Status)) { + HandleFilePath = FilePath; + Status = CoreLocateDevicePath (&gEfiLoadFileProtocolGuid, &HandleFilePath, &DeviceHandle); + if (!EFI_ERROR (Status)) { + ImageIsFromLoadFile = TRUE; + Node = HandleFilePath; + } + } + } + } + + // + // Get the source file buffer by its device path. + // + FHand.Source = GetFileBufferByFilePath ( + BootPolicy, + FilePath, + &FHand.SourceSize, + &AuthenticationStatus + ); + if (FHand.Source == NULL) { + Status = EFI_NOT_FOUND; + } else { + FHand.FreeBuffer = TRUE; + if (ImageIsFromLoadFile) { + // + // LoadFile () may cause the device path of the Handle be updated. + // + OriginalFilePath = AppendDevicePath (DevicePathFromHandle (DeviceHandle), Node); + } + } + } + + if (EFI_ERROR (Status)) { + Image = NULL; + goto Done; } + if (gSecurity2 != NULL) { + // + // Verify File Authentication through the Security2 Architectural Protocol + // + SecurityStatus = gSecurity2->FileAuthentication ( + gSecurity2, + OriginalFilePath, + FHand.Source, + FHand.SourceSize, + BootPolicy + ); + if (!EFI_ERROR (SecurityStatus) && ImageIsFromFv) { + // + // When Security2 is installed, Security Architectural Protocol must be published. + // + ASSERT (gSecurity != NULL); + + // + // Verify the Authentication Status through the Security Architectural Protocol + // Only on images that have been read using Firmware Volume protocol. + // + SecurityStatus = gSecurity->FileAuthenticationState ( + gSecurity, + AuthenticationStatus, + OriginalFilePath + ); + } + } else if ((gSecurity != NULL) && (OriginalFilePath != NULL)) { + // + // Verify the Authentication Status through the Security Architectural Protocol + // + SecurityStatus = gSecurity->FileAuthenticationState ( + gSecurity, + AuthenticationStatus, + OriginalFilePath + ); + } + + // + // Check Security Status. + // + 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. + // It's the only place we could meet EFI_ACCESS_DENIED. + // + *ImageHandle = NULL; + } + Status = SecurityStatus; + Image = NULL; + goto Done; + } + + // + // Allocate a new image structure + // + Image = AllocateZeroPool (sizeof(LOADED_IMAGE_PRIVATE_DATA)); + if (Image == NULL) { + Status = EFI_OUT_OF_RESOURCES; + goto Done; + } + + // + // Pull out just the file portion of the DevicePath for the LoadedImage FilePath + // + FilePath = OriginalFilePath; + 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 ); + } + } // // Initialize the fields for an internal driver // Image->Signature = LOADED_IMAGE_PRIVATE_DATA_SIGNATURE; Image->Info.SystemTable = gDxeCoreST; Image->Info.DeviceHandle = DeviceHandle; - Image->Info.Revision = EFI_LOADED_IMAGE_INFORMATION_REVISION; - Image->Info.FilePath = CoreDuplicateDevicePath (FilePath); + Image->Info.Revision = EFI_LOADED_IMAGE_PROTOCOL_REVISION; + Image->Info.FilePath = DuplicateDevicePath (FilePath); Image->Info.ParentHandle = ParentImageHandle; @@ -721,7 +1277,7 @@ Returns: // // Load the image. If EntryPoint is Null, it will not be set. // - Status = CoreLoadPeImage (&FHand, Image, DstBuffer, EntryPoint, Attribute); + Status = CoreLoadPeImage (BootPolicy, &FHand, Image, DstBuffer, EntryPoint, Attribute); if (EFI_ERROR (Status)) { if ((Status == EFI_BUFFER_TOO_SMALL) || (Status == EFI_OUT_OF_RESOURCES)) { if (NumberOfPages != NULL) { @@ -731,10 +1287,14 @@ Returns: goto Done; } + if (NumberOfPages != NULL) { + *NumberOfPages = Image->NumberOfPages; + } + // // Register the image in the Debug Image Info Table if the attribute is set // - if (Attribute & EFI_LOAD_PE_IMAGE_ATTRIBUTE_DEBUG_IMAGE_INFO_TABLE_REGISTRATION) { + if ((Attribute & EFI_LOAD_PE_IMAGE_ATTRIBUTE_DEBUG_IMAGE_INFO_TABLE_REGISTRATION) != 0) { CoreNewDebugImageInfoEntry (EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL, &Image->Info, Image->Handle); } @@ -751,6 +1311,42 @@ Returns: goto Done; } + // + // If DevicePath parameter to the LoadImage() is not NULL, then make a copy of DevicePath, + // otherwise Loaded Image Device Path Protocol is installed with a NULL interface pointer. + // + if (OriginalFilePath != NULL) { + Image->LoadedImageDevicePath = DuplicateDevicePath (OriginalFilePath); + } + + // + // 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 + ); + if (EFI_ERROR (Status)) { + goto Done; + } + + // + // Install HII Package List Protocol onto the image handle + // + if (Image->ImageContext.HiiResourceData != 0) { + Status = CoreInstallProtocolInterface ( + &Image->Handle, + &gEfiHiiPackageListProtocolGuid, + EFI_NATIVE_INTERFACE, + (VOID *) (UINTN) Image->ImageContext.HiiResourceData + ); + if (EFI_ERROR (Status)) { + goto Done; + } + } + ProtectUefiImage (&Image->Info, Image->LoadedImageDevicePath); // // Success. Return the image handle @@ -765,6 +1361,9 @@ Done: if (FHand.FreeBuffer) { CoreFreePool (FHand.Source); } + if (OriginalFilePath != InputFilePath) { + CoreFreePool (OriginalFilePath); + } // // There was an error. If there's an Image structure, free it @@ -772,17 +1371,59 @@ Done: if (EFI_ERROR (Status)) { if (Image != NULL) { CoreUnloadAndCloseImage (Image, (BOOLEAN)(DstBuffer == 0)); - *ImageHandle = NULL; + Image = NULL; } } else if (EFI_ERROR (SecurityStatus)) { Status = SecurityStatus; } + // + // Track the return status from LoadImage. + // + if (Image != NULL) { + Image->LoadImageStatus = Status; + } + return Status; } + +/** + Loads an EFI image into memory and returns a handle to the image. + + @param BootPolicy If TRUE, indicates that the request originates + from the boot manager, and that the boot + manager is attempting to load FilePath as a + boot selection. + @param ParentImageHandle The caller's image handle. + @param FilePath The specific file path from which the image is + loaded. + @param SourceBuffer If not NULL, a pointer to the memory location + containing a copy of the image to be loaded. + @param SourceSize The size in bytes of SourceBuffer. + @param ImageHandle Pointer to the returned image handle that is + created when the image is successfully loaded. + + @retval EFI_SUCCESS The image was loaded into memory. + @retval EFI_NOT_FOUND The FilePath was not found. + @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value. + @retval EFI_UNSUPPORTED The image type is not supported, or the device + path cannot be parsed to locate the proper + protocol for loading the file. + @retval EFI_OUT_OF_RESOURCES Image was not loaded due to insufficient + resources. + @retval EFI_LOAD_ERROR Image was not loaded because the image format was corrupt or not + understood. + @retval EFI_DEVICE_ERROR Image was not loaded because the device returned a read error. + @retval EFI_ACCESS_DENIED Image was not loaded because the platform policy prohibits the + image from being loaded. NULL is returned in *ImageHandle. + @retval EFI_SECURITY_VIOLATION Image was loaded and an ImageHandle was created with a + valid EFI_LOADED_IMAGE_PROTOCOL. However, the current + platform policy specifies that the image should not be started. + +**/ EFI_STATUS EFIAPI CoreLoadImage ( @@ -793,37 +1434,15 @@ CoreLoadImage ( IN UINTN SourceSize, OUT EFI_HANDLE *ImageHandle ) -/*++ - -Routine Description: - - Loads an EFI image into memory and returns a handle to the image. - -Arguments: - - BootPolicy - If TRUE, indicates that the request originates from the boot manager, - and that the boot manager is attempting to load FilePath as a boot selection. - ParentImageHandle - The caller's image handle. - FilePath - The specific file path from which the image is loaded. - SourceBuffer - If not NULL, a pointer to the memory location containing a copy of - the image to be loaded. - SourceSize - The size in bytes of SourceBuffer. - ImageHandle - Pointer to the returned image handle that is created when the image - is successfully loaded. - -Returns: - - EFI_SUCCESS - The image was loaded into memory. - EFI_NOT_FOUND - The FilePath was not found. - EFI_INVALID_PARAMETER - One of the parameters has an invalid value. - EFI_UNSUPPORTED - The image type is not supported, or the device path cannot be - parsed to locate the proper protocol for loading the file. - EFI_OUT_OF_RESOURCES - Image was not loaded due to insufficient resources. ---*/ { EFI_STATUS Status; + UINT64 Tick; + EFI_HANDLE Handle; - PERF_START (NULL, "LoadImage", NULL, 0); + Tick = 0; + PERF_CODE ( + Tick = GetPerformanceCounter (); + ); Status = CoreLoadImageCommon ( BootPolicy, @@ -831,19 +1450,66 @@ Returns: FilePath, SourceBuffer, SourceSize, - (EFI_PHYSICAL_ADDRESS)NULL, + (EFI_PHYSICAL_ADDRESS) (UINTN) NULL, NULL, ImageHandle, NULL, EFI_LOAD_PE_IMAGE_ATTRIBUTE_RUNTIME_REGISTRATION | EFI_LOAD_PE_IMAGE_ATTRIBUTE_DEBUG_IMAGE_INFO_TABLE_REGISTRATION ); - PERF_END (NULL, "LoadImage", NULL, 0); + Handle = NULL; + if (!EFI_ERROR (Status)) { + // + // ImageHandle will be valid only Status is success. + // + Handle = *ImageHandle; + } + + PERF_START (Handle, "LoadImage:", NULL, Tick); + PERF_END (Handle, "LoadImage:", NULL, 0); return Status; } + +/** + Loads an EFI image into memory and returns a handle to the image with extended parameters. + + @param This Calling context + @param ParentImageHandle The caller's image handle. + @param FilePath The specific file path from which the image is + loaded. + @param SourceBuffer If not NULL, a pointer to the memory location + containing a copy of the image to be loaded. + @param SourceSize The size in bytes of SourceBuffer. + @param DstBuffer The buffer to store the image. + @param NumberOfPages For input, specifies the space size of the + image by caller if not NULL. For output, + specifies the actual space size needed. + @param ImageHandle Image handle for output. + @param EntryPoint Image entry point for output. + @param Attribute The bit mask of attributes to set for the load + PE image. + + @retval EFI_SUCCESS The image was loaded into memory. + @retval EFI_NOT_FOUND The FilePath was not found. + @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value. + @retval EFI_UNSUPPORTED The image type is not supported, or the device + path cannot be parsed to locate the proper + protocol for loading the file. + @retval EFI_OUT_OF_RESOURCES Image was not loaded due to insufficient + resources. + @retval EFI_LOAD_ERROR Image was not loaded because the image format was corrupt or not + understood. + @retval EFI_DEVICE_ERROR Image was not loaded because the device returned a read error. + @retval EFI_ACCESS_DENIED Image was not loaded because the platform policy prohibits the + image from being loaded. NULL is returned in *ImageHandle. + @retval EFI_SECURITY_VIOLATION Image was loaded and an ImageHandle was created with a + valid EFI_LOADED_IMAGE_PROTOCOL. However, the current + platform policy specifies that the image should not be started. + +**/ EFI_STATUS EFIAPI CoreLoadImageEx ( @@ -858,38 +1524,17 @@ CoreLoadImageEx ( OUT EFI_PHYSICAL_ADDRESS *EntryPoint OPTIONAL, IN UINT32 Attribute ) -/*++ - -Routine Description: +{ + EFI_STATUS Status; + UINT64 Tick; + EFI_HANDLE Handle; - Loads an EFI image into memory and returns a handle to the image with extended parameters. + Tick = 0; + PERF_CODE ( + Tick = GetPerformanceCounter (); + ); -Arguments: - - This - Calling context - ParentImageHandle - The caller's image handle. - FilePath - The specific file path from which the image is loaded. - SourceBuffer - If not NULL, a pointer to the memory location containing a copy of - the image to be loaded. - SourceSize - The size in bytes of SourceBuffer. - DstBuffer - The buffer to store the image. - NumberOfPages - For input, specifies the space size of the image by caller if not NULL. - For output, specifies the actual space size needed. - ImageHandle - Image handle for output. - EntryPoint - Image entry point for output. - Attribute - The bit mask of attributes to set for the load PE image. - -Returns: - - EFI_SUCCESS - The image was loaded into memory. - EFI_NOT_FOUND - The FilePath was not found. - EFI_INVALID_PARAMETER - One of the parameters has an invalid value. - EFI_UNSUPPORTED - The image type is not supported, or the device path cannot be - parsed to locate the proper protocol for loading the file. - EFI_OUT_OF_RESOURCES - Image was not loaded due to insufficient resources. ---*/ -{ - return CoreLoadImageCommon ( + Status = CoreLoadImageCommon ( TRUE, ParentImageHandle, FilePath, @@ -901,11 +1546,41 @@ Returns: EntryPoint, Attribute ); -} + Handle = NULL; + if (!EFI_ERROR (Status)) { + // + // ImageHandle will be valid only Status is success. + // + Handle = *ImageHandle; + } + + PERF_START (Handle, "LoadImage:", NULL, Tick); + PERF_END (Handle, "LoadImage:", NULL, 0); + return Status; +} +/** + Transfer control to a loaded image's entry point. + + @param ImageHandle Handle of image to be started. + @param ExitDataSize Pointer of the size to ExitData + @param ExitData Pointer to a pointer to a data buffer that + includes a Null-terminated string, + optionally followed by additional binary data. + The string is a description that the caller may + use to further indicate the reason for the + image's exit. + + @retval EFI_INVALID_PARAMETER Invalid parameter + @retval EFI_OUT_OF_RESOURCES No enough buffer to allocate + @retval EFI_SECURITY_VIOLATION The current platform policy specifies that the image should not be started. + @retval EFI_SUCCESS Successfully transfer control to the image's + entry point. + +**/ EFI_STATUS EFIAPI CoreStartImage ( @@ -913,48 +1588,42 @@ CoreStartImage ( OUT UINTN *ExitDataSize, OUT CHAR16 **ExitData OPTIONAL ) -/*++ - -Routine Description: - - Transfer control to a loaded image's entry point. - -Arguments: - - ImageHandle - Handle of image to be started. - - ExitDataSize - Pointer of the size to ExitData - - ExitData - Pointer to a pointer to a data buffer that includes a Null-terminated - Unicode string, optionally followed by additional binary data. The string - is a description that the caller may use to further indicate the reason for - the image's exit. - -Returns: - - EFI_INVALID_PARAMETER - Invalid parameter - - EFI_OUT_OF_RESOURCES - No enough buffer to allocate - - EFI_SUCCESS - Successfully transfer control to the image's entry point. - ---*/ { EFI_STATUS Status; LOADED_IMAGE_PRIVATE_DATA *Image; LOADED_IMAGE_PRIVATE_DATA *LastImage; UINT64 HandleDatabaseKey; UINTN SetJumpFlag; + UINT64 Tick; + EFI_HANDLE Handle; + + Tick = 0; + Handle = ImageHandle; Image = CoreLoadedImageInfo (ImageHandle); - if (Image == NULL_HANDLE || Image->Started) { + if (Image == NULL || Image->Started) { return EFI_INVALID_PARAMETER; } + if (EFI_ERROR (Image->LoadImageStatus)) { + return Image->LoadImageStatus; + } // - // Don't profile Objects or invalid start requests + // The image to be started must have the machine type supported by DxeCore. // - PERF_START (ImageHandle, START_IMAGE_TOK, NULL, 0); + if (!EFI_IMAGE_MACHINE_TYPE_SUPPORTED (Image->Machine)) { + // + // Do not ASSERT here, because image might be loaded via EFI_IMAGE_MACHINE_CROSS_TYPE_SUPPORTED + // But it can not be started. + // + DEBUG ((EFI_D_ERROR, "Image type %s can't be started ", GetMachineTypeName(Image->Machine))); + DEBUG ((EFI_D_ERROR, "on %s UEFI system.\n", GetMachineTypeName(mDxeCoreImageMachineType))); + return EFI_UNSUPPORTED; + } + + PERF_CODE ( + Tick = GetPerformanceCounter (); + ); // @@ -972,9 +1641,20 @@ Returns: // JumpContext must be aligned on a CPU specific boundary. // Overallocate the buffer and force the required alignment // - Image->JumpBuffer = CoreAllocateBootServicesPool (sizeof (BASE_LIBRARY_JUMP_BUFFER) + BASE_LIBRARY_JUMP_BUFFER_ALIGNMENT); + Image->JumpBuffer = AllocatePool (sizeof (BASE_LIBRARY_JUMP_BUFFER) + BASE_LIBRARY_JUMP_BUFFER_ALIGNMENT); if (Image->JumpBuffer == NULL) { - PERF_END (ImageHandle, START_IMAGE_TOK, NULL, 0); + // + // Image may be unloaded after return with failure, + // then ImageHandle may be invalid, so use NULL handle to record perf log. + // + PERF_START (NULL, "StartImage:", NULL, Tick); + PERF_END (NULL, "StartImage:", NULL, 0); + + // + // Pop the current start image context + // + mCurrentImage = LastImage; + return EFI_OUT_OF_RESOURCES; } Image->JumpContext = ALIGN_POINTER (Image->JumpBuffer, BASE_LIBRARY_JUMP_BUFFER_ALIGNMENT); @@ -984,7 +1664,8 @@ Returns: // The initial call to SetJump() must always return 0. // Subsequent calls to LongJump() cause a non-zero value to be returned by SetJump(). // - if (!SetJumpFlag) { + if (SetJumpFlag == 0) { + RegisterMemoryProfileImage (Image, (Image->ImageContext.ImageType == EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION ? EFI_FV_FILETYPE_APPLICATION : EFI_FV_FILETYPE_DRIVER)); // // Call the image's entry point // @@ -998,7 +1679,7 @@ Returns: // DEBUG_CODE_BEGIN (); if (EFI_ERROR (Image->Status)) { - DEBUG ((EFI_D_ERROR, "Error: Image at %10p start failed: %r\n", Image->Info.ImageBase, Image->Status)); + DEBUG ((DEBUG_ERROR, "Error: Image at %11p start failed: %r\n", Image->Info.ImageBase, Image->Status)); } DEBUG_CODE_END (); @@ -1022,9 +1703,17 @@ Returns: mCurrentImage = LastImage; // - // Go connect any handles that were created or modified while the image executed. + // UEFI Specification - StartImage() - EFI 1.10 Extension + // To maintain compatibility with UEFI drivers that are written to the EFI + // 1.02 Specification, StartImage() must monitor the handle database before + // and after each image is started. If any handles are created or modified + // when an image is started, then EFI_BOOT_SERVICES.ConnectController() must + // be called with the Recursive parameter set to TRUE for each of the newly + // created or modified handles before StartImage() returns. // - CoreConnectHandlesByKey (HandleDatabaseKey); + if (Image->Type != EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION) { + CoreConnectHandlesByKey (HandleDatabaseKey); + } // // Handle the image's returned ExitData @@ -1032,16 +1721,11 @@ Returns: DEBUG_CODE_BEGIN (); if (Image->ExitDataSize != 0 || Image->ExitData != NULL) { - DEBUG ( - (EFI_D_LOAD, - "StartImage: ExitDataSize %d, ExitData %x", - Image->ExitDataSize, - Image->ExitData) - ); + DEBUG ((DEBUG_LOAD, "StartImage: ExitDataSize %d, ExitData %p", (UINT32)Image->ExitDataSize, Image->ExitData)); if (Image->ExitData != NULL) { - DEBUG ((EFI_D_LOAD, " (%hs)", Image->ExitData)); + DEBUG ((DEBUG_LOAD, " (%hs)", Image->ExitData)); } - DEBUG ((EFI_D_LOAD, "\n")); + DEBUG ((DEBUG_LOAD, "\n")); } DEBUG_CODE_END (); @@ -1070,160 +1754,43 @@ Returns: // if (EFI_ERROR (Image->Status) || Image->Type == EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION) { CoreUnloadAndCloseImage (Image, TRUE); - } - - // - // Done - // - PERF_END (ImageHandle, START_IMAGE_TOK, NULL, 0); - return Status; -} - - -VOID -CoreUnloadAndCloseImage ( - IN LOADED_IMAGE_PRIVATE_DATA *Image, - IN BOOLEAN FreePage - ) -/*++ - -Routine Description: - - Unloads EFI image from memory. - -Arguments: - - Image - EFI image - FreePage - Free allocated pages - -Returns: - - None - ---*/ -{ - 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; - - if (Image->Ebc != NULL) { // - // If EBC protocol exists we must perform cleanups for this image. + // ImageHandle may be invalid after the image is unloaded, so use NULL handle to record perf log. // - Image->Ebc->UnloadImage (Image->Ebc, Image->Handle); - } - - // - // Unload image, free Image->ImageContext->ModHandle - // - PeCoffLoaderUnloadImage (&Image->ImageContext); - - // - // Free our references to the image handle - // - if (Image->Handle != NULL_HANDLE) { - - Status = CoreLocateHandleBuffer ( - AllHandles, - NULL, - NULL, - &HandleCount, - &HandleBuffer - ); - if (!EFI_ERROR (Status)) { - for (HandleIndex = 0; HandleIndex < HandleCount; HandleIndex++) { - Status = CoreProtocolsPerHandle ( - HandleBuffer[HandleIndex], - &ProtocolGuidArray, - &ArrayCount - ); - if (!EFI_ERROR (Status)) { - for (ProtocolIndex = 0; ProtocolIndex < ArrayCount; ProtocolIndex++) { - Status = CoreOpenProtocolInformation ( - HandleBuffer[HandleIndex], - ProtocolGuidArray[ProtocolIndex], - &OpenInfo, - &OpenInfoCount - ); - if (!EFI_ERROR (Status)) { - for (OpenInfoIndex = 0; OpenInfoIndex < OpenInfoCount; OpenInfoIndex++) { - if (OpenInfo[OpenInfoIndex].AgentHandle == Image->Handle) { - Status = CoreCloseProtocol ( - HandleBuffer[HandleIndex], - ProtocolGuidArray[ProtocolIndex], - Image->Handle, - OpenInfo[OpenInfoIndex].ControllerHandle - ); - } - } - if (OpenInfo != NULL) { - CoreFreePool(OpenInfo); - } - } - } - if (ProtocolGuidArray != NULL) { - CoreFreePool(ProtocolGuidArray); - } - } - } - if (HandleBuffer != NULL) { - CoreFreePool (HandleBuffer); - } - } - - CoreRemoveDebugImageInfoEntry (Image->Handle); - - Status = CoreUninstallProtocolInterface ( - Image->Handle, - &gEfiLoadedImageProtocolGuid, - &Image->Info - ); - } - - if (Image->RuntimeData != NULL) { - if (Image->RuntimeData->Link.ForwardLink != NULL) { - // - // Remove the Image from the Runtime Image list as we are about to Free it! - // - RemoveEntryList (&Image->RuntimeData->Link); - } - CoreFreePool (Image->RuntimeData); - } - - // - // Free the Image from memory - // - if ((Image->ImageBasePage != 0) && FreePage) { - CoreFreePages (Image->ImageBasePage, Image->NumberOfPages); + Handle = NULL; } // - // Done with the Image structure + // Done // - if (Image->Info.FilePath != NULL) { - CoreFreePool (Image->Info.FilePath); - } - - if (Image->DeviceHandleDevicePath != NULL) { - CoreFreePool (Image->DeviceHandleDevicePath); - } - - if (Image->FixupData != NULL) { - CoreFreePool (Image->FixupData); - } - - CoreFreePool (Image); + PERF_START (Handle, "StartImage:", NULL, Tick); + PERF_END (Handle, "StartImage:", NULL, 0); + return Status; } +/** + Terminates the currently loaded EFI image and returns control to boot services. - + @param ImageHandle Handle that identifies the image. This + parameter is passed to the image on entry. + @param Status The image's exit code. + @param ExitDataSize The size, in bytes, of ExitData. Ignored if + ExitStatus is EFI_SUCCESS. + @param ExitData Pointer to a data buffer that includes a + Null-terminated Unicode string, optionally + followed by additional binary data. The string + is a description that the caller may use to + further indicate the reason for the image's + exit. + + @retval EFI_INVALID_PARAMETER Image handle is NULL or it is not current + image. + @retval EFI_SUCCESS Successfully terminates the currently loaded + EFI image. + @retval EFI_ACCESS_DENIED Should never reach there. + @retval EFI_OUT_OF_RESOURCES Could not allocate pool + +**/ EFI_STATUS EFIAPI CoreExit ( @@ -1232,35 +1799,6 @@ CoreExit ( IN UINTN ExitDataSize, IN CHAR16 *ExitData OPTIONAL ) -/*++ - -Routine Description: - - Terminates the currently loaded EFI image and returns control to boot services. - -Arguments: - - ImageHandle - Handle that identifies the image. This parameter is passed to the image - on entry. - Status - The image's exit code. - ExitDataSize - The size, in bytes, of ExitData. Ignored if ExitStatus is - EFI_SUCCESS. - ExitData - Pointer to a data buffer that includes a Null-terminated Unicode string, - optionally followed by additional binary data. The string is a - description that the caller may use to further indicate the reason for - the image's exit. - -Returns: - - EFI_INVALID_PARAMETER - Image handle is NULL or it is not current image. - - EFI_SUCCESS - Successfully terminates the currently loaded EFI image. - - EFI_ACCESS_DENIED - Should never reach there. - - EFI_OUT_OF_RESOURCES - Could not allocate pool - ---*/ { LOADED_IMAGE_PRIVATE_DATA *Image; EFI_TPL OldTpl; @@ -1268,11 +1806,11 @@ Returns: // // Prevent possible reentrance to this function // for the same ImageHandle - // - OldTpl = CoreRaiseTpl (TPL_NOTIFY); - + // + OldTpl = CoreRaiseTpl (TPL_NOTIFY); + Image = CoreLoadedImageInfo (ImageHandle); - if (Image == NULL_HANDLE) { + if (Image == NULL) { Status = EFI_INVALID_PARAMETER; goto Done; } @@ -1290,7 +1828,7 @@ Returns: // Image has been started, verify this image can exit // if (Image != mCurrentImage) { - DEBUG ((EFI_D_LOAD|EFI_D_ERROR, "Exit: Image is not exitable image\n")); + DEBUG ((DEBUG_LOAD|DEBUG_ERROR, "Exit: Image is not exitable image\n")); Status = EFI_INVALID_PARAMETER; goto Done; } @@ -1305,7 +1843,7 @@ Returns: // if (ExitData != NULL) { Image->ExitDataSize = ExitDataSize; - Image->ExitData = CoreAllocateBootServicesPool (Image->ExitDataSize); + Image->ExitData = AllocatePool (Image->ExitDataSize); if (Image->ExitData == NULL) { Status = EFI_OUT_OF_RESOURCES; goto Done; @@ -1331,39 +1869,28 @@ Done: -EFI_STATUS -EFIAPI -CoreUnloadImage ( - IN EFI_HANDLE ImageHandle - ) -/*++ - -Routine Description: +/** Unloads an image. -Arguments: + @param ImageHandle Handle that identifies the image to be + unloaded. - ImageHandle - Handle that identifies the image to be unloaded. + @retval EFI_SUCCESS The image has been unloaded. + @retval EFI_UNSUPPORTED The image has been started, and does not support + unload. + @retval EFI_INVALID_PARAMPETER ImageHandle is not a valid image handle. -Returns: - - EFI_SUCCESS - The image has been unloaded. - EFI_UNSUPPORTED - The image has been sarted, and does not support unload. - EFI_INVALID_PARAMPETER - ImageHandle is not a valid image handle. - ---*/ +**/ +EFI_STATUS +EFIAPI +CoreUnloadImage ( + IN EFI_HANDLE ImageHandle + ) { EFI_STATUS Status; LOADED_IMAGE_PRIVATE_DATA *Image; - EFI_TPL OldTpl; - // - // Prevent possible reentrance to this function - // for the same ImageHandle - // - OldTpl = CoreRaiseTpl (TPL_NOTIFY); - Image = CoreLoadedImageInfo (ImageHandle); if (Image == NULL ) { // @@ -1398,38 +1925,28 @@ Returns: } Done: - CoreRestoreTpl (OldTpl); return Status; } + +/** + Unload the specified image. + + @param This Indicates the calling context. + @param ImageHandle The specified image handle. + + @retval EFI_INVALID_PARAMETER Image handle is NULL. + @retval EFI_UNSUPPORTED Attempt to unload an unsupported image. + @retval EFI_SUCCESS Image successfully unloaded. + +**/ EFI_STATUS EFIAPI CoreUnloadImageEx ( IN EFI_PE32_IMAGE_PROTOCOL *This, IN EFI_HANDLE ImageHandle ) -/*++ - -Routine Description: - - Unload the specified image. - -Arguments: - - This - Indicates the calling context. - - ImageHandle - The specified image handle. - -Returns: - - EFI_INVALID_PARAMETER - Image handle is NULL. - - EFI_UNSUPPORTED - Attempt to unload an unsupported image. - - EFI_SUCCESS - Image successfully unloaded. - ---*/ { return CoreUnloadImage (ImageHandle); }