2008-05-21 03:40:12 +02:00
|
|
|
/** @file
|
2008-04-09 09:07:50 +02:00
|
|
|
Core image handling services to load and unload PeImage.
|
|
|
|
|
2011-02-12 02:29:17 +01:00
|
|
|
Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
|
2010-04-24 11:49:11 +02:00
|
|
|
This program and the accompanying materials
|
2007-07-04 12:51:54 +02:00
|
|
|
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
|
|
|
|
|
|
|
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|
|
|
|
2008-04-09 09:07:50 +02:00
|
|
|
**/
|
2007-07-04 12:51:54 +02:00
|
|
|
|
2008-08-27 16:29:23 +02:00
|
|
|
#include "DxeMain.h"
|
2008-09-23 09:35:34 +02:00
|
|
|
#include "Image.h"
|
|
|
|
|
2007-07-04 12:51:54 +02:00
|
|
|
//
|
|
|
|
// Module Globals
|
|
|
|
//
|
|
|
|
LOADED_IMAGE_PRIVATE_DATA *mCurrentImage = NULL;
|
|
|
|
|
2009-04-17 06:47:55 +02:00
|
|
|
LOAD_PE32_IMAGE_PRIVATE_DATA mLoadPe32PrivateData = {
|
|
|
|
LOAD_PE32_IMAGE_PRIVATE_DATA_SIGNATURE,
|
|
|
|
NULL,
|
|
|
|
{
|
|
|
|
CoreLoadImageEx,
|
|
|
|
CoreUnloadImageEx
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2007-07-04 12:51:54 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// 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
|
|
|
|
{
|
|
|
|
EFI_LOADED_IMAGE_INFORMATION_REVISION, // Revision
|
|
|
|
NULL, // Parent handle
|
|
|
|
NULL, // System handle
|
|
|
|
|
|
|
|
NULL, // Device handle
|
|
|
|
NULL, // File path
|
|
|
|
NULL, // Reserved
|
|
|
|
|
|
|
|
0, // LoadOptionsSize
|
|
|
|
NULL, // LoadOptions
|
|
|
|
|
|
|
|
NULL, // ImageBase
|
|
|
|
0, // ImageSize
|
|
|
|
EfiBootServicesCode, // ImageCodeType
|
|
|
|
EfiBootServicesData // ImageDataType
|
|
|
|
},
|
|
|
|
(EFI_PHYSICAL_ADDRESS)0, // ImageBasePage
|
|
|
|
0, // NumberOfPages
|
|
|
|
NULL, // FixupData
|
|
|
|
0, // Tpl
|
|
|
|
EFI_SUCCESS, // Status
|
|
|
|
0, // ExitDataSize
|
|
|
|
NULL, // ExitData
|
|
|
|
NULL, // JumpBuffer
|
|
|
|
NULL, // JumpContext
|
|
|
|
0, // Machine
|
|
|
|
NULL, // Ebc
|
|
|
|
NULL, // RuntimeData
|
2008-02-26 09:38:29 +01:00
|
|
|
NULL // LoadedImageDevicePath
|
2007-07-04 12:51:54 +02:00
|
|
|
};
|
2010-02-05 08:54:16 +01:00
|
|
|
//
|
|
|
|
// 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;
|
2007-07-04 12:51:54 +02:00
|
|
|
|
2008-05-09 09:08:30 +02:00
|
|
|
/**
|
2007-07-04 12:51:54 +02:00
|
|
|
Add the Image Services to EFI Boot Services Table and install the protocol
|
|
|
|
interfaces for this image.
|
|
|
|
|
2008-05-21 10:32:06 +02:00
|
|
|
@param HobStart The HOB to initialize
|
2007-07-04 12:51:54 +02:00
|
|
|
|
2008-05-09 09:08:30 +02:00
|
|
|
@return Status code.
|
2007-07-04 12:51:54 +02:00
|
|
|
|
2008-05-09 09:08:30 +02:00
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
CoreInitializeImageServices (
|
|
|
|
IN VOID *HobStart
|
|
|
|
)
|
2007-07-04 12:51:54 +02:00
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
LOADED_IMAGE_PRIVATE_DATA *Image;
|
|
|
|
EFI_PHYSICAL_ADDRESS DxeCoreImageBaseAddress;
|
|
|
|
UINT64 DxeCoreImageLength;
|
|
|
|
VOID *DxeCoreEntryPoint;
|
|
|
|
EFI_PEI_HOB_POINTERS DxeCoreHob;
|
2010-08-03 07:20:15 +02:00
|
|
|
|
2007-07-04 12:51:54 +02:00
|
|
|
//
|
|
|
|
// Searching for image hob
|
|
|
|
//
|
|
|
|
DxeCoreHob.Raw = HobStart;
|
|
|
|
while ((DxeCoreHob.Raw = GetNextHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, DxeCoreHob.Raw)) != NULL) {
|
|
|
|
if (CompareGuid (&DxeCoreHob.MemoryAllocationModule->MemoryAllocationHeader.Name, &gEfiHobMemoryAllocModuleGuid)) {
|
|
|
|
//
|
|
|
|
// Find Dxe Core HOB
|
|
|
|
//
|
|
|
|
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;
|
|
|
|
gDxeCoreFileName = &DxeCoreHob.MemoryAllocationModule->ModuleName;
|
2010-08-03 07:20:15 +02:00
|
|
|
|
2007-07-04 12:51:54 +02:00
|
|
|
//
|
|
|
|
// Initialize the fields for an internal driver
|
|
|
|
//
|
|
|
|
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;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Install the protocol interfaces for this image
|
|
|
|
//
|
|
|
|
Status = CoreInstallProtocolInterface (
|
|
|
|
&Image->Handle,
|
|
|
|
&gEfiLoadedImageProtocolGuid,
|
|
|
|
EFI_NATIVE_INTERFACE,
|
|
|
|
&Image->Info
|
|
|
|
);
|
|
|
|
ASSERT_EFI_ERROR (Status);
|
|
|
|
|
|
|
|
mCurrentImage = Image;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Fill in DXE globals
|
|
|
|
//
|
|
|
|
gDxeCoreImageHandle = Image->Handle;
|
|
|
|
gDxeCoreLoadedImage = &Image->Info;
|
|
|
|
|
2009-12-22 09:02:33 +01:00
|
|
|
if (FeaturePcdGet (PcdFrameworkCompatibilitySupport)) {
|
|
|
|
//
|
|
|
|
// Export DXE Core PE Loader functionality for backward compatibility.
|
|
|
|
//
|
|
|
|
Status = CoreInstallProtocolInterface (
|
2010-08-07 01:09:49 +02:00
|
|
|
&mLoadPe32PrivateData.Handle,
|
|
|
|
&gEfiLoadPeImageProtocolGuid,
|
|
|
|
EFI_NATIVE_INTERFACE,
|
|
|
|
&mLoadPe32PrivateData.Pe32Image
|
|
|
|
);
|
2009-12-22 09:02:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return Status;
|
2007-07-04 12:51:54 +02:00
|
|
|
}
|
|
|
|
|
2009-11-26 02:08:36 +01:00
|
|
|
/**
|
|
|
|
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
|
|
|
|
EFIAPI
|
|
|
|
CoreReadImageFile (
|
|
|
|
IN VOID *UserHandle,
|
|
|
|
IN UINTN Offset,
|
|
|
|
IN OUT UINTN *ReadSize,
|
|
|
|
OUT VOID *Buffer
|
|
|
|
)
|
|
|
|
{
|
|
|
|
UINTN EndPosition;
|
|
|
|
IMAGE_FILE_HANDLE *FHand;
|
|
|
|
|
|
|
|
FHand = (IMAGE_FILE_HANDLE *)UserHandle;
|
|
|
|
ASSERT (FHand->Signature == IMAGE_FILE_HANDLE_SIGNATURE);
|
|
|
|
|
|
|
|
//
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
CopyMem (Buffer, (CHAR8 *)FHand->Source + Offset, *ReadSize);
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
2010-02-05 08:54:16 +01:00
|
|
|
/**
|
|
|
|
To check memory usage bit map arry to figure out if the memory range the image will be loaded in is available or not. If
|
|
|
|
memory range is avaliable, the function will mark the correponding 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 addres 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 = (UINTN)EFI_SIZE_TO_PAGES((UINT32)(ImageBase - DxeCodeBase));
|
|
|
|
TopOffsetPageNumber = (UINTN)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 loadding address from image header assigned by build tool. This function only be called
|
|
|
|
when Loading module at Fixed address feature enabled.
|
2008-05-09 09:08:30 +02:00
|
|
|
|
2010-02-05 08:54:16 +01:00
|
|
|
@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 loadding address.
|
|
|
|
|
|
|
|
**/
|
|
|
|
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 = (UINTN)(
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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 fileds 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
|
|
|
|
//
|
2010-02-10 07:10:53 +01:00
|
|
|
if ((INT64)PcdGet64(PcdLoadModuleAtFixAddressEnable) < 0) {
|
2010-03-10 03:47:05 +01:00
|
|
|
ImageContext->ImageAddress = gLoadModuleAtFixAddressConfigurationTable.DxeCodeTopAddress + (INT64)(INTN)ImageContext->ImageAddress;
|
2010-02-05 08:54:16 +01:00
|
|
|
}
|
|
|
|
//
|
|
|
|
// Check if the memory range is avaliable.
|
|
|
|
//
|
|
|
|
Status = CheckAndMarkFixLoadingMemoryUsageBitMap (ImageContext->ImageAddress, (UINTN)(ImageContext->ImageSize + ImageContext->SectionAlignment));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
SectionHeaderOffset += sizeof (EFI_IMAGE_SECTION_HEADER);
|
|
|
|
}
|
2010-02-10 07:10:53 +01:00
|
|
|
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));
|
2010-02-05 08:54:16 +01:00
|
|
|
return Status;
|
|
|
|
}
|
2008-05-09 09:08:30 +02:00
|
|
|
/**
|
|
|
|
Loads, relocates, and invokes a PE/COFF image
|
|
|
|
|
2008-05-21 10:32:06 +02:00
|
|
|
@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
|
2008-05-09 09:08:30 +02:00
|
|
|
@retval EFI_BUFFER_TOO_SMALL Buffer for image is too small
|
|
|
|
|
|
|
|
**/
|
2007-07-04 12:51:54 +02:00
|
|
|
EFI_STATUS
|
|
|
|
CoreLoadPeImage (
|
2008-05-21 10:32:06 +02:00
|
|
|
IN BOOLEAN BootPolicy,
|
2007-07-04 12:51:54 +02:00
|
|
|
IN VOID *Pe32Handle,
|
|
|
|
IN LOADED_IMAGE_PRIVATE_DATA *Image,
|
|
|
|
IN EFI_PHYSICAL_ADDRESS DstBuffer OPTIONAL,
|
|
|
|
OUT EFI_PHYSICAL_ADDRESS *EntryPoint OPTIONAL,
|
|
|
|
IN UINT32 Attribute
|
|
|
|
)
|
|
|
|
{
|
2008-01-04 03:11:51 +01:00
|
|
|
EFI_STATUS Status;
|
|
|
|
BOOLEAN DstBufAlocated;
|
|
|
|
UINTN Size;
|
2007-07-04 12:51:54 +02:00
|
|
|
|
|
|
|
ZeroMem (&Image->ImageContext, sizeof (Image->ImageContext));
|
|
|
|
|
|
|
|
Image->ImageContext.Handle = Pe32Handle;
|
|
|
|
Image->ImageContext.ImageRead = (PE_COFF_LOADER_READ_FILE)CoreReadImageFile;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Get information about the image being loaded
|
|
|
|
//
|
2007-09-28 10:14:30 +02:00
|
|
|
Status = PeCoffLoaderGetImageInfo (&Image->ImageContext);
|
2007-07-04 12:51:54 +02:00
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!EFI_IMAGE_MACHINE_TYPE_SUPPORTED (Image->ImageContext.Machine)) {
|
2008-04-02 08:56:35 +02:00
|
|
|
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.
|
|
|
|
//
|
|
|
|
return EFI_UNSUPPORTED;
|
|
|
|
}
|
2007-07-04 12:51:54 +02:00
|
|
|
}
|
2008-05-21 10:32:06 +02:00
|
|
|
|
2007-09-29 05:16:49 +02:00
|
|
|
//
|
|
|
|
// 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;
|
|
|
|
}
|
2007-07-04 12:51:54 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Allocate memory of the correct memory type aligned on the required image boundry
|
|
|
|
//
|
|
|
|
DstBufAlocated = FALSE;
|
|
|
|
if (DstBuffer == 0) {
|
|
|
|
//
|
|
|
|
// Allocate Destination Buffer as caller did not pass it in
|
|
|
|
//
|
|
|
|
|
|
|
|
if (Image->ImageContext.SectionAlignment > EFI_PAGE_SIZE) {
|
|
|
|
Size = (UINTN)Image->ImageContext.ImageSize + Image->ImageContext.SectionAlignment;
|
|
|
|
} else {
|
|
|
|
Size = (UINTN)Image->ImageContext.ImageSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
Image->NumberOfPages = EFI_SIZE_TO_PAGES (Size);
|
|
|
|
|
|
|
|
//
|
|
|
|
// If the image relocations have not been stripped, then load at any address.
|
|
|
|
// Otherwise load at the address at which it was linked.
|
|
|
|
//
|
|
|
|
// Memory below 1MB should be treated reserved for CSM and there should be
|
|
|
|
// no modules whose preferred load addresses are below 1MB.
|
|
|
|
//
|
|
|
|
Status = EFI_OUT_OF_RESOURCES;
|
2010-02-05 08:54:16 +01:00
|
|
|
//
|
|
|
|
// If Loading Module At Fixed Address feature is enabled, the module should be loaded to
|
|
|
|
// a specified address.
|
|
|
|
//
|
2010-02-10 07:10:53 +01:00
|
|
|
if (PcdGet64(PcdLoadModuleAtFixAddressEnable) != 0 ) {
|
2010-02-05 08:54:16 +01:00
|
|
|
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
|
|
|
|
);
|
|
|
|
}
|
2007-07-04 12:51:54 +02:00
|
|
|
}
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
DstBufAlocated = TRUE;
|
|
|
|
} else {
|
|
|
|
//
|
|
|
|
// Caller provided the destination buffer
|
|
|
|
//
|
|
|
|
|
|
|
|
if (Image->ImageContext.RelocationsStripped && (Image->ImageContext.ImageAddress != DstBuffer)) {
|
|
|
|
//
|
|
|
|
// If the image relocations were stripped, and the caller provided a
|
|
|
|
// destination buffer address that does not match the address that the
|
|
|
|
// image is linked at, then the image cannot be loaded.
|
|
|
|
//
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
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->ImageContext.ImageAddress = DstBuffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
Image->ImageBasePage = Image->ImageContext.ImageAddress;
|
2008-09-23 09:16:46 +02:00
|
|
|
if (!Image->ImageContext.IsTeImage) {
|
2010-02-05 08:54:16 +01:00
|
|
|
Image->ImageContext.ImageAddress =
|
|
|
|
(Image->ImageContext.ImageAddress + Image->ImageContext.SectionAlignment - 1) &
|
|
|
|
~((UINTN)Image->ImageContext.SectionAlignment - 1);
|
2008-09-23 09:16:46 +02:00
|
|
|
}
|
2007-07-04 12:51:54 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Load the image from the file into the allocated memory
|
|
|
|
//
|
2007-09-28 10:14:30 +02:00
|
|
|
Status = PeCoffLoaderLoadImage (&Image->ImageContext);
|
2007-07-04 12:51:54 +02:00
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
goto Done;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// If this is a Runtime Driver, then allocate memory for the FixupData that
|
|
|
|
// is used to relocate the image when SetVirtualAddressMap() is called. The
|
|
|
|
// relocation is done by the Runtime AP.
|
|
|
|
//
|
2008-05-09 09:52:58 +02:00
|
|
|
if ((Attribute & EFI_LOAD_PE_IMAGE_ATTRIBUTE_RUNTIME_REGISTRATION) != 0) {
|
2007-07-04 12:51:54 +02:00
|
|
|
if (Image->ImageContext.ImageType == EFI_IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER) {
|
2008-08-27 16:29:23 +02:00
|
|
|
Image->ImageContext.FixupData = AllocateRuntimePool ((UINTN)(Image->ImageContext.FixupDataSize));
|
2007-07-04 12:51:54 +02:00
|
|
|
if (Image->ImageContext.FixupData == NULL) {
|
|
|
|
Status = EFI_OUT_OF_RESOURCES;
|
|
|
|
goto Done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Relocate the image in memory
|
|
|
|
//
|
2007-09-28 10:14:30 +02:00
|
|
|
Status = PeCoffLoaderRelocateImage (&Image->ImageContext);
|
2007-07-04 12:51:54 +02:00
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
goto Done;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Flush the Instruction Cache
|
|
|
|
//
|
|
|
|
InvalidateInstructionCacheRange ((VOID *)(UINTN)Image->ImageContext.ImageAddress, (UINTN)Image->ImageContext.ImageSize);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Copy the machine type from the context to the image private data. This
|
|
|
|
// is needed during image unload to know if we should call an EBC protocol
|
|
|
|
// to unload the image.
|
|
|
|
//
|
|
|
|
Image->Machine = Image->ImageContext.Machine;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Get the image entry point. If it's an EBC image, then call into the
|
|
|
|
// interpreter to create a thunk for the entry point and use the returned
|
|
|
|
// value for the entry point.
|
|
|
|
//
|
|
|
|
Image->EntryPoint = (EFI_IMAGE_ENTRY_POINT)(UINTN)Image->ImageContext.EntryPoint;
|
|
|
|
if (Image->ImageContext.Machine == EFI_IMAGE_MACHINE_EBC) {
|
|
|
|
//
|
|
|
|
// Locate the EBC interpreter protocol
|
|
|
|
//
|
|
|
|
Status = CoreLocateProtocol (&gEfiEbcProtocolGuid, NULL, (VOID **)&Image->Ebc);
|
2010-02-26 09:53:27 +01:00
|
|
|
if (EFI_ERROR(Status) || Image->Ebc == NULL) {
|
2008-05-21 10:32:06 +02:00
|
|
|
DEBUG ((DEBUG_LOAD | DEBUG_ERROR, "CoreLoadPeImage: There is no EBC interpreter for an EBC image.\n"));
|
2007-07-04 12:51:54 +02:00
|
|
|
goto Done;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Register a callback for flushing the instruction cache so that created
|
|
|
|
// thunks can be flushed.
|
|
|
|
//
|
|
|
|
Status = Image->Ebc->RegisterICacheFlush (Image->Ebc, (EBC_ICACHE_FLUSH)InvalidateInstructionCacheRange);
|
|
|
|
if (EFI_ERROR(Status)) {
|
|
|
|
goto Done;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Create a thunk for the image's entry point. This will be the new
|
|
|
|
// entry point for the image.
|
|
|
|
//
|
|
|
|
Status = Image->Ebc->CreateThunk (
|
|
|
|
Image->Ebc,
|
|
|
|
Image->Handle,
|
2008-07-18 11:50:09 +02:00
|
|
|
(VOID *)(UINTN) Image->ImageContext.EntryPoint,
|
|
|
|
(VOID **) &Image->EntryPoint
|
2007-07-04 12:51:54 +02:00
|
|
|
);
|
|
|
|
if (EFI_ERROR(Status)) {
|
|
|
|
goto Done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Fill in the image information for the Loaded Image Protocol
|
|
|
|
//
|
|
|
|
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);
|
2008-05-09 09:52:58 +02:00
|
|
|
if ((Attribute & EFI_LOAD_PE_IMAGE_ATTRIBUTE_RUNTIME_REGISTRATION) != 0) {
|
2007-07-04 12:51:54 +02:00
|
|
|
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.
|
|
|
|
//
|
2008-08-27 16:29:23 +02:00
|
|
|
Image->RuntimeData = AllocateRuntimePool (sizeof(EFI_RUNTIME_IMAGE_ENTRY));
|
2007-07-04 12:51:54 +02:00
|
|
|
if (Image->RuntimeData == NULL) {
|
|
|
|
goto Done;
|
|
|
|
}
|
|
|
|
Image->RuntimeData->ImageBase = Image->Info.ImageBase;
|
|
|
|
Image->RuntimeData->ImageSize = (UINT64) (Image->Info.ImageSize);
|
|
|
|
Image->RuntimeData->RelocationData = Image->ImageContext.FixupData;
|
|
|
|
Image->RuntimeData->Handle = Image->Handle;
|
|
|
|
InsertTailList (&gRuntime->ImageHead, &Image->RuntimeData->Link);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Fill in the entry point of the image if it is available
|
|
|
|
//
|
|
|
|
if (EntryPoint != NULL) {
|
|
|
|
*EntryPoint = Image->ImageContext.EntryPoint;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Print the load address and the PDB file name if it is available
|
|
|
|
//
|
|
|
|
|
|
|
|
DEBUG_CODE_BEGIN ();
|
|
|
|
|
|
|
|
UINTN Index;
|
|
|
|
UINTN StartIndex;
|
|
|
|
CHAR8 EfiFileName[256];
|
2008-05-21 10:32:06 +02:00
|
|
|
|
2008-07-24 04:54:45 +02:00
|
|
|
|
2008-07-18 11:50:09 +02:00
|
|
|
DEBUG ((DEBUG_INFO | DEBUG_LOAD,
|
2008-08-02 00:41:20 +02:00
|
|
|
"Loading driver at 0x%11p EntryPoint=0x%11p ",
|
2008-07-18 11:50:09 +02:00
|
|
|
(VOID *)(UINTN) Image->ImageContext.ImageAddress,
|
2008-12-06 00:26:01 +01:00
|
|
|
FUNCTION_ENTRY_POINT (Image->ImageContext.EntryPoint)));
|
2008-07-24 04:54:45 +02:00
|
|
|
|
2008-05-21 10:32:06 +02:00
|
|
|
|
2007-10-31 12:46:42 +01:00
|
|
|
//
|
2009-02-02 09:01:35 +01:00
|
|
|
// Print Module Name by Pdb file path.
|
|
|
|
// Windows and Unix style file path are all trimmed correctly.
|
2007-10-31 12:46:42 +01:00
|
|
|
//
|
2007-07-04 12:51:54 +02:00
|
|
|
if (Image->ImageContext.PdbPointer != NULL) {
|
|
|
|
StartIndex = 0;
|
|
|
|
for (Index = 0; Image->ImageContext.PdbPointer[Index] != 0; Index++) {
|
2009-02-02 09:01:35 +01:00
|
|
|
if ((Image->ImageContext.PdbPointer[Index] == '\\') || (Image->ImageContext.PdbPointer[Index] == '/')) {
|
2007-07-04 12:51:54 +02:00
|
|
|
StartIndex = Index + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//
|
|
|
|
// Copy the PDB file name to our temporary string, and replace .pdb with .efi
|
2009-02-02 09:01:35 +01:00
|
|
|
// 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.
|
2007-07-04 12:51:54 +02:00
|
|
|
//
|
2009-02-02 09:01:35 +01:00
|
|
|
for (Index = 0; Index < sizeof (EfiFileName) - 4; Index++) {
|
2007-07-04 12:51:54 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2009-02-02 09:01:35 +01:00
|
|
|
|
|
|
|
if (Index == sizeof (EfiFileName) - 4) {
|
|
|
|
EfiFileName[Index] = 0;
|
|
|
|
}
|
2008-05-09 09:08:30 +02:00
|
|
|
DEBUG ((DEBUG_INFO | DEBUG_LOAD, "%a", EfiFileName)); // &Image->ImageContext.PdbPointer[StartIndex]));
|
2007-07-04 12:51:54 +02:00
|
|
|
}
|
2008-05-09 09:08:30 +02:00
|
|
|
DEBUG ((DEBUG_INFO | DEBUG_LOAD, "\n"));
|
2007-07-04 12:51:54 +02:00
|
|
|
|
|
|
|
DEBUG_CODE_END ();
|
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
|
|
|
|
Done:
|
|
|
|
|
|
|
|
//
|
|
|
|
// Free memory.
|
|
|
|
//
|
|
|
|
|
|
|
|
if (DstBufAlocated) {
|
|
|
|
CoreFreePages (Image->ImageContext.ImageAddress, Image->NumberOfPages);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Image->ImageContext.FixupData != NULL) {
|
|
|
|
CoreFreePool (Image->ImageContext.FixupData);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-05-09 09:08:30 +02:00
|
|
|
/**
|
2007-07-04 12:51:54 +02:00
|
|
|
Get the image's private data from its handle.
|
|
|
|
|
2008-05-21 10:32:06 +02:00
|
|
|
@param ImageHandle The image handle
|
2007-07-04 12:51:54 +02:00
|
|
|
|
2008-05-09 09:08:30 +02:00
|
|
|
@return Return the image private data associated with ImageHandle.
|
2007-07-04 12:51:54 +02:00
|
|
|
|
2008-05-09 09:08:30 +02:00
|
|
|
**/
|
|
|
|
LOADED_IMAGE_PRIVATE_DATA *
|
|
|
|
CoreLoadedImageInfo (
|
|
|
|
IN EFI_HANDLE ImageHandle
|
|
|
|
)
|
2007-07-04 12:51:54 +02:00
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;
|
|
|
|
LOADED_IMAGE_PRIVATE_DATA *Image;
|
|
|
|
|
|
|
|
Status = CoreHandleProtocol (
|
|
|
|
ImageHandle,
|
|
|
|
&gEfiLoadedImageProtocolGuid,
|
|
|
|
(VOID **)&LoadedImage
|
|
|
|
);
|
|
|
|
if (!EFI_ERROR (Status)) {
|
|
|
|
Image = LOADED_IMAGE_PRIVATE_DATA_FROM_THIS (LoadedImage);
|
|
|
|
} else {
|
2008-07-18 11:50:09 +02:00
|
|
|
DEBUG ((DEBUG_LOAD, "CoreLoadedImageInfo: Not an ImageHandle %p\n", ImageHandle));
|
2007-07-04 12:51:54 +02:00
|
|
|
Image = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Image;
|
|
|
|
}
|
|
|
|
|
2008-05-09 09:08:30 +02:00
|
|
|
|
2008-09-09 07:36:40 +02:00
|
|
|
/**
|
|
|
|
Unloads EFI image from memory.
|
|
|
|
|
|
|
|
@param Image EFI image
|
|
|
|
@param FreePage Free allocated pages
|
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
CoreUnloadAndCloseImage (
|
|
|
|
IN LOADED_IMAGE_PRIVATE_DATA *Image,
|
|
|
|
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;
|
|
|
|
|
|
|
|
if (Image->Ebc != NULL) {
|
|
|
|
//
|
|
|
|
// If EBC protocol exists we must perform cleanups for this image.
|
|
|
|
//
|
|
|
|
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) {
|
|
|
|
|
|
|
|
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,
|
|
|
|
&gEfiLoadedImageDevicePathProtocolGuid,
|
|
|
|
Image->LoadedImageDevicePath
|
|
|
|
);
|
|
|
|
|
|
|
|
Status = CoreUninstallProtocolInterface (
|
|
|
|
Image->Handle,
|
|
|
|
&gEfiLoadedImageProtocolGuid,
|
|
|
|
&Image->Info
|
|
|
|
);
|
|
|
|
|
2009-04-22 04:06:58 +02:00
|
|
|
if (Image->ImageContext.HiiResourceData != 0) {
|
|
|
|
Status = CoreUninstallProtocolInterface (
|
|
|
|
Image->Handle,
|
|
|
|
&gEfiHiiPackageListProtocolGuid,
|
|
|
|
(VOID *) (UINTN) Image->ImageContext.HiiResourceData
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2008-09-09 07:36:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-05-09 09:08:30 +02:00
|
|
|
/**
|
|
|
|
Loads an EFI image into memory and returns a handle to the image.
|
|
|
|
|
2008-05-21 10:32:06 +02:00
|
|
|
@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
|
2008-05-09 09:08:30 +02:00
|
|
|
resources.
|
2011-02-12 02:29:17 +01:00
|
|
|
@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.
|
2008-05-09 09:08:30 +02:00
|
|
|
|
|
|
|
**/
|
2007-07-04 12:51:54 +02:00
|
|
|
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;
|
|
|
|
UINTN FilePathSize;
|
|
|
|
|
|
|
|
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) {
|
2008-05-09 09:08:30 +02:00
|
|
|
DEBUG((DEBUG_LOAD|DEBUG_ERROR, "LoadImageEx: Parent handle not an image handle\n"));
|
2007-07-04 12:51:54 +02:00
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
2009-11-26 02:08:36 +01:00
|
|
|
ZeroMem (&FHand, sizeof (IMAGE_FILE_HANDLE));
|
|
|
|
FHand.Signature = IMAGE_FILE_HANDLE_SIGNATURE;
|
2007-07-04 12:51:54 +02:00
|
|
|
OriginalFilePath = FilePath;
|
2009-11-26 02:08:36 +01:00
|
|
|
HandleFilePath = FilePath;
|
|
|
|
DeviceHandle = NULL;
|
|
|
|
Status = EFI_SUCCESS;
|
|
|
|
AuthenticationStatus = 0;
|
|
|
|
//
|
|
|
|
// If the caller passed a copy of the file, then just use it
|
|
|
|
//
|
|
|
|
if (SourceBuffer != NULL) {
|
|
|
|
FHand.Source = SourceBuffer;
|
|
|
|
FHand.SourceSize = SourceSize;
|
|
|
|
CoreLocateDevicePath (&gEfiDevicePathProtocolGuid, &HandleFilePath, &DeviceHandle);
|
|
|
|
if (SourceSize > 0) {
|
|
|
|
Status = EFI_SUCCESS;
|
|
|
|
} else {
|
|
|
|
Status = EFI_LOAD_ERROR;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (FilePath == NULL) {
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
//
|
|
|
|
// Get the source file buffer by its device path.
|
|
|
|
//
|
|
|
|
FHand.Source = GetFileBufferByFilePath (
|
|
|
|
BootPolicy,
|
|
|
|
FilePath,
|
|
|
|
&FHand.SourceSize,
|
|
|
|
&AuthenticationStatus
|
|
|
|
);
|
|
|
|
if (FHand.Source == NULL) {
|
2009-12-01 11:15:43 +01:00
|
|
|
Status = EFI_NOT_FOUND;
|
2009-11-26 02:08:36 +01:00
|
|
|
} else {
|
|
|
|
//
|
|
|
|
// Try to get the image device handle by checking the match protocol.
|
|
|
|
//
|
|
|
|
FHand.FreeBuffer = TRUE;
|
|
|
|
Status = CoreLocateDevicePath (&gEfiFirmwareVolume2ProtocolGuid, &HandleFilePath, &DeviceHandle);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-04 12:51:54 +02:00
|
|
|
if (Status == EFI_ALREADY_STARTED) {
|
|
|
|
Image = NULL;
|
|
|
|
goto Done;
|
|
|
|
} else if (EFI_ERROR (Status)) {
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Verify the Authentication Status through the Security Architectural Protocol
|
|
|
|
//
|
|
|
|
if ((gSecurity != NULL) && (OriginalFilePath != NULL)) {
|
|
|
|
SecurityStatus = gSecurity->FileAuthenticationState (
|
|
|
|
gSecurity,
|
|
|
|
AuthenticationStatus,
|
|
|
|
OriginalFilePath
|
|
|
|
);
|
|
|
|
if (EFI_ERROR (SecurityStatus) && SecurityStatus != EFI_SECURITY_VIOLATION) {
|
2011-06-10 05:05:40 +02:00
|
|
|
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;
|
|
|
|
}
|
2007-07-04 12:51:54 +02:00
|
|
|
Status = SecurityStatus;
|
|
|
|
Image = NULL;
|
|
|
|
goto Done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// Allocate a new image structure
|
|
|
|
//
|
2008-08-27 16:29:23 +02:00
|
|
|
Image = AllocateZeroPool (sizeof(LOADED_IMAGE_PRIVATE_DATA));
|
2007-07-04 12:51:54 +02:00
|
|
|
if (Image == NULL) {
|
|
|
|
return EFI_OUT_OF_RESOURCES;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Pull out just the file portion of the DevicePath for the LoadedImage FilePath
|
|
|
|
//
|
2007-11-09 08:26:24 +01:00
|
|
|
FilePath = OriginalFilePath;
|
2010-02-26 09:53:27 +01:00
|
|
|
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 );
|
|
|
|
}
|
2007-07-04 12:51:54 +02:00
|
|
|
}
|
|
|
|
//
|
|
|
|
// Initialize the fields for an internal driver
|
|
|
|
//
|
|
|
|
Image->Signature = LOADED_IMAGE_PRIVATE_DATA_SIGNATURE;
|
|
|
|
Image->Info.SystemTable = gDxeCoreST;
|
|
|
|
Image->Info.DeviceHandle = DeviceHandle;
|
2008-05-09 09:08:30 +02:00
|
|
|
Image->Info.Revision = EFI_LOADED_IMAGE_PROTOCOL_REVISION;
|
2008-08-27 16:29:23 +02:00
|
|
|
Image->Info.FilePath = DuplicateDevicePath (FilePath);
|
2007-07-04 12:51:54 +02:00
|
|
|
Image->Info.ParentHandle = ParentImageHandle;
|
|
|
|
|
2007-09-14 23:35:03 +02:00
|
|
|
|
2007-07-04 12:51:54 +02:00
|
|
|
if (NumberOfPages != NULL) {
|
|
|
|
Image->NumberOfPages = *NumberOfPages ;
|
|
|
|
} else {
|
|
|
|
Image->NumberOfPages = 0 ;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Install the protocol interfaces for this image
|
|
|
|
// don't fire notifications yet
|
|
|
|
//
|
|
|
|
Status = CoreInstallProtocolInterfaceNotify (
|
|
|
|
&Image->Handle,
|
|
|
|
&gEfiLoadedImageProtocolGuid,
|
|
|
|
EFI_NATIVE_INTERFACE,
|
|
|
|
&Image->Info,
|
|
|
|
FALSE
|
|
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
goto Done;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Load the image. If EntryPoint is Null, it will not be set.
|
|
|
|
//
|
2008-01-04 03:11:51 +01:00
|
|
|
Status = CoreLoadPeImage (BootPolicy, &FHand, Image, DstBuffer, EntryPoint, Attribute);
|
2007-07-04 12:51:54 +02:00
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
if ((Status == EFI_BUFFER_TOO_SMALL) || (Status == EFI_OUT_OF_RESOURCES)) {
|
|
|
|
if (NumberOfPages != NULL) {
|
|
|
|
*NumberOfPages = Image->NumberOfPages;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
goto Done;
|
|
|
|
}
|
|
|
|
|
2008-04-22 10:38:30 +02:00
|
|
|
if (NumberOfPages != NULL) {
|
|
|
|
*NumberOfPages = Image->NumberOfPages;
|
2008-05-21 10:32:06 +02:00
|
|
|
}
|
2008-04-22 10:38:30 +02:00
|
|
|
|
2007-07-04 12:51:54 +02:00
|
|
|
//
|
|
|
|
// Register the image in the Debug Image Info Table if the attribute is set
|
|
|
|
//
|
2008-05-09 09:52:58 +02:00
|
|
|
if ((Attribute & EFI_LOAD_PE_IMAGE_ATTRIBUTE_DEBUG_IMAGE_INFO_TABLE_REGISTRATION) != 0) {
|
2007-07-04 12:51:54 +02:00
|
|
|
CoreNewDebugImageInfoEntry (EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL, &Image->Info, Image->Handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
//Reinstall loaded image protocol to fire any notifications
|
|
|
|
//
|
|
|
|
Status = CoreReinstallProtocolInterface (
|
|
|
|
Image->Handle,
|
|
|
|
&gEfiLoadedImageProtocolGuid,
|
|
|
|
&Image->Info,
|
|
|
|
&Image->Info
|
|
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
goto Done;
|
|
|
|
}
|
|
|
|
|
2008-02-26 09:38:29 +01:00
|
|
|
//
|
|
|
|
// 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) {
|
2008-08-27 16:29:23 +02:00
|
|
|
Image->LoadedImageDevicePath = DuplicateDevicePath (OriginalFilePath);
|
2008-02-26 09:38:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// 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;
|
|
|
|
}
|
2007-07-04 12:51:54 +02:00
|
|
|
|
2009-04-22 04:06:58 +02:00
|
|
|
//
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-04 12:51:54 +02:00
|
|
|
//
|
|
|
|
// Success. Return the image handle
|
|
|
|
//
|
|
|
|
*ImageHandle = Image->Handle;
|
|
|
|
|
|
|
|
Done:
|
|
|
|
//
|
|
|
|
// All done accessing the source file
|
|
|
|
// If we allocated the Source buffer, free it
|
|
|
|
//
|
|
|
|
if (FHand.FreeBuffer) {
|
|
|
|
CoreFreePool (FHand.Source);
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// There was an error. If there's an Image structure, free it
|
|
|
|
//
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
if (Image != NULL) {
|
|
|
|
CoreUnloadAndCloseImage (Image, (BOOLEAN)(DstBuffer == 0));
|
|
|
|
}
|
|
|
|
} else if (EFI_ERROR (SecurityStatus)) {
|
|
|
|
Status = SecurityStatus;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-05-09 09:08:30 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
Loads an EFI image into memory and returns a handle to the image.
|
|
|
|
|
2008-05-21 10:32:06 +02:00
|
|
|
@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
|
2008-05-09 09:08:30 +02:00
|
|
|
resources.
|
2011-02-12 02:29:17 +01:00
|
|
|
@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.
|
2008-05-09 09:08:30 +02:00
|
|
|
|
|
|
|
**/
|
2007-07-04 12:51:54 +02:00
|
|
|
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
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
2008-10-30 05:03:59 +01:00
|
|
|
UINT64 Tick;
|
2007-07-04 12:51:54 +02:00
|
|
|
|
2008-10-30 05:03:59 +01:00
|
|
|
Tick = 0;
|
|
|
|
PERF_CODE (
|
|
|
|
Tick = GetPerformanceCounter ();
|
|
|
|
);
|
2007-07-04 12:51:54 +02:00
|
|
|
|
|
|
|
Status = CoreLoadImageCommon (
|
|
|
|
BootPolicy,
|
|
|
|
ParentImageHandle,
|
|
|
|
FilePath,
|
|
|
|
SourceBuffer,
|
|
|
|
SourceSize,
|
2008-04-08 22:59:38 +02:00
|
|
|
(EFI_PHYSICAL_ADDRESS) (UINTN) NULL,
|
2007-07-04 12:51:54 +02:00
|
|
|
NULL,
|
|
|
|
ImageHandle,
|
|
|
|
NULL,
|
|
|
|
EFI_LOAD_PE_IMAGE_ATTRIBUTE_RUNTIME_REGISTRATION | EFI_LOAD_PE_IMAGE_ATTRIBUTE_DEBUG_IMAGE_INFO_TABLE_REGISTRATION
|
|
|
|
);
|
|
|
|
|
2009-02-23 04:01:59 +01:00
|
|
|
PERF_START (*ImageHandle, "LoadImage:", NULL, Tick);
|
|
|
|
PERF_END (*ImageHandle, "LoadImage:", NULL, 0);
|
2007-07-04 12:51:54 +02:00
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-17 06:47:55 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
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.
|
2011-02-12 02:29:17 +01:00
|
|
|
@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.
|
2009-04-17 06:47:55 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
CoreLoadImageEx (
|
|
|
|
IN EFI_PE32_IMAGE_PROTOCOL *This,
|
|
|
|
IN EFI_HANDLE ParentImageHandle,
|
|
|
|
IN EFI_DEVICE_PATH_PROTOCOL *FilePath,
|
|
|
|
IN VOID *SourceBuffer OPTIONAL,
|
|
|
|
IN UINTN SourceSize,
|
|
|
|
IN EFI_PHYSICAL_ADDRESS DstBuffer OPTIONAL,
|
|
|
|
OUT UINTN *NumberOfPages OPTIONAL,
|
|
|
|
OUT EFI_HANDLE *ImageHandle,
|
|
|
|
OUT EFI_PHYSICAL_ADDRESS *EntryPoint OPTIONAL,
|
|
|
|
IN UINT32 Attribute
|
|
|
|
)
|
|
|
|
{
|
|
|
|
return CoreLoadImageCommon (
|
|
|
|
TRUE,
|
|
|
|
ParentImageHandle,
|
|
|
|
FilePath,
|
|
|
|
SourceBuffer,
|
|
|
|
SourceSize,
|
|
|
|
DstBuffer,
|
|
|
|
NumberOfPages,
|
|
|
|
ImageHandle,
|
|
|
|
EntryPoint,
|
|
|
|
Attribute
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-05-09 09:08:30 +02:00
|
|
|
/**
|
|
|
|
Transfer control to a loaded image's entry point.
|
|
|
|
|
2008-05-21 10:32:06 +02:00
|
|
|
@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
|
2011-02-12 02:29:17 +01:00
|
|
|
includes a Null-terminated string,
|
2008-05-21 10:32:06 +02:00
|
|
|
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_SUCCESS Successfully transfer control to the image's
|
2008-05-09 09:08:30 +02:00
|
|
|
entry point.
|
|
|
|
|
|
|
|
**/
|
2007-07-04 12:51:54 +02:00
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
CoreStartImage (
|
|
|
|
IN EFI_HANDLE ImageHandle,
|
|
|
|
OUT UINTN *ExitDataSize,
|
|
|
|
OUT CHAR16 **ExitData OPTIONAL
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
LOADED_IMAGE_PRIVATE_DATA *Image;
|
|
|
|
LOADED_IMAGE_PRIVATE_DATA *LastImage;
|
|
|
|
UINT64 HandleDatabaseKey;
|
|
|
|
UINTN SetJumpFlag;
|
|
|
|
|
|
|
|
Image = CoreLoadedImageInfo (ImageHandle);
|
2008-09-08 07:02:38 +02:00
|
|
|
if (Image == NULL || Image->Started) {
|
2007-07-04 12:51:54 +02:00
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
2009-09-17 03:57:24 +02:00
|
|
|
//
|
|
|
|
// The image to be started must have the machine type supported by DxeCore.
|
|
|
|
//
|
|
|
|
ASSERT (EFI_IMAGE_MACHINE_TYPE_SUPPORTED (Image->Machine));
|
2009-09-16 04:37:23 +02:00
|
|
|
if (!EFI_IMAGE_MACHINE_TYPE_SUPPORTED (Image->Machine)) {
|
|
|
|
return EFI_UNSUPPORTED;
|
|
|
|
}
|
|
|
|
|
2007-07-04 12:51:54 +02:00
|
|
|
//
|
|
|
|
// Don't profile Objects or invalid start requests
|
|
|
|
//
|
2009-02-23 04:01:59 +01:00
|
|
|
PERF_START (ImageHandle, "StartImage:", NULL, 0);
|
2007-07-04 12:51:54 +02:00
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// Push the current start image context, and
|
|
|
|
// link the current image to the head. This is the
|
|
|
|
// only image that can call Exit()
|
|
|
|
//
|
|
|
|
HandleDatabaseKey = CoreGetHandleDatabaseKey ();
|
|
|
|
LastImage = mCurrentImage;
|
|
|
|
mCurrentImage = Image;
|
|
|
|
Image->Tpl = gEfiCurrentTpl;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Set long jump for Exit() support
|
|
|
|
// JumpContext must be aligned on a CPU specific boundary.
|
|
|
|
// Overallocate the buffer and force the required alignment
|
|
|
|
//
|
2008-08-27 16:29:23 +02:00
|
|
|
Image->JumpBuffer = AllocatePool (sizeof (BASE_LIBRARY_JUMP_BUFFER) + BASE_LIBRARY_JUMP_BUFFER_ALIGNMENT);
|
2007-07-04 12:51:54 +02:00
|
|
|
if (Image->JumpBuffer == NULL) {
|
2009-02-23 04:01:59 +01:00
|
|
|
PERF_END (ImageHandle, "StartImage:", NULL, 0);
|
2007-07-04 12:51:54 +02:00
|
|
|
return EFI_OUT_OF_RESOURCES;
|
|
|
|
}
|
|
|
|
Image->JumpContext = ALIGN_POINTER (Image->JumpBuffer, BASE_LIBRARY_JUMP_BUFFER_ALIGNMENT);
|
|
|
|
|
|
|
|
SetJumpFlag = SetJump (Image->JumpContext);
|
|
|
|
//
|
|
|
|
// The initial call to SetJump() must always return 0.
|
|
|
|
// Subsequent calls to LongJump() cause a non-zero value to be returned by SetJump().
|
|
|
|
//
|
2008-05-09 09:52:58 +02:00
|
|
|
if (SetJumpFlag == 0) {
|
2007-07-04 12:51:54 +02:00
|
|
|
//
|
|
|
|
// Call the image's entry point
|
|
|
|
//
|
|
|
|
Image->Started = TRUE;
|
|
|
|
Image->Status = Image->EntryPoint (ImageHandle, Image->Info.SystemTable);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Add some debug information if the image returned with error.
|
|
|
|
// This make the user aware and check if the driver image have already released
|
|
|
|
// all the resource in this situation.
|
|
|
|
//
|
|
|
|
DEBUG_CODE_BEGIN ();
|
|
|
|
if (EFI_ERROR (Image->Status)) {
|
2008-08-02 00:41:20 +02:00
|
|
|
DEBUG ((DEBUG_ERROR, "Error: Image at %11p start failed: %r\n", Image->Info.ImageBase, Image->Status));
|
2007-07-04 12:51:54 +02:00
|
|
|
}
|
|
|
|
DEBUG_CODE_END ();
|
|
|
|
|
|
|
|
//
|
|
|
|
// If the image returns, exit it through Exit()
|
|
|
|
//
|
|
|
|
CoreExit (ImageHandle, Image->Status, 0, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Image has completed. Verify the tpl is the same
|
|
|
|
//
|
|
|
|
ASSERT (Image->Tpl == gEfiCurrentTpl);
|
|
|
|
CoreRestoreTpl (Image->Tpl);
|
|
|
|
|
|
|
|
CoreFreePool (Image->JumpBuffer);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Pop the current start image context
|
|
|
|
//
|
|
|
|
mCurrentImage = LastImage;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Go connect any handles that were created or modified while the image executed.
|
|
|
|
//
|
|
|
|
CoreConnectHandlesByKey (HandleDatabaseKey);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Handle the image's returned ExitData
|
|
|
|
//
|
|
|
|
DEBUG_CODE_BEGIN ();
|
|
|
|
if (Image->ExitDataSize != 0 || Image->ExitData != NULL) {
|
|
|
|
|
2008-12-18 09:48:36 +01:00
|
|
|
DEBUG ((DEBUG_LOAD, "StartImage: ExitDataSize %d, ExitData %p", (UINT32)Image->ExitDataSize, Image->ExitData));
|
2007-07-04 12:51:54 +02:00
|
|
|
if (Image->ExitData != NULL) {
|
2008-05-09 09:08:30 +02:00
|
|
|
DEBUG ((DEBUG_LOAD, " (%hs)", Image->ExitData));
|
2007-07-04 12:51:54 +02:00
|
|
|
}
|
2008-05-09 09:08:30 +02:00
|
|
|
DEBUG ((DEBUG_LOAD, "\n"));
|
2007-07-04 12:51:54 +02:00
|
|
|
}
|
|
|
|
DEBUG_CODE_END ();
|
|
|
|
|
|
|
|
//
|
|
|
|
// Return the exit data to the caller
|
|
|
|
//
|
|
|
|
if (ExitData != NULL && ExitDataSize != NULL) {
|
|
|
|
*ExitDataSize = Image->ExitDataSize;
|
|
|
|
*ExitData = Image->ExitData;
|
|
|
|
} else {
|
|
|
|
//
|
|
|
|
// Caller doesn't want the exit data, free it
|
|
|
|
//
|
|
|
|
CoreFreePool (Image->ExitData);
|
|
|
|
Image->ExitData = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Save the Status because Image will get destroyed if it is unloaded.
|
|
|
|
//
|
|
|
|
Status = Image->Status;
|
|
|
|
|
|
|
|
//
|
|
|
|
// 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) {
|
|
|
|
CoreUnloadAndCloseImage (Image, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Done
|
|
|
|
//
|
2009-02-23 04:01:59 +01:00
|
|
|
PERF_END (ImageHandle, "StartImage:", NULL, 0);
|
2007-07-04 12:51:54 +02:00
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2008-05-09 09:08:30 +02:00
|
|
|
/**
|
|
|
|
Terminates the currently loaded EFI image and returns control to boot services.
|
|
|
|
|
2008-05-21 10:32:06 +02:00
|
|
|
@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.
|
2008-05-09 09:08:30 +02:00
|
|
|
@retval EFI_OUT_OF_RESOURCES Could not allocate pool
|
|
|
|
|
|
|
|
**/
|
2007-07-04 12:51:54 +02:00
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
CoreExit (
|
|
|
|
IN EFI_HANDLE ImageHandle,
|
|
|
|
IN EFI_STATUS Status,
|
|
|
|
IN UINTN ExitDataSize,
|
|
|
|
IN CHAR16 *ExitData OPTIONAL
|
|
|
|
)
|
|
|
|
{
|
|
|
|
LOADED_IMAGE_PRIVATE_DATA *Image;
|
|
|
|
EFI_TPL OldTpl;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Prevent possible reentrance to this function
|
|
|
|
// for the same ImageHandle
|
2008-05-21 10:32:06 +02:00
|
|
|
//
|
|
|
|
OldTpl = CoreRaiseTpl (TPL_NOTIFY);
|
|
|
|
|
2007-07-04 12:51:54 +02:00
|
|
|
Image = CoreLoadedImageInfo (ImageHandle);
|
2008-09-08 07:02:38 +02:00
|
|
|
if (Image == NULL) {
|
2007-07-04 12:51:54 +02:00
|
|
|
Status = EFI_INVALID_PARAMETER;
|
|
|
|
goto Done;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Image->Started) {
|
|
|
|
//
|
|
|
|
// The image has not been started so just free its resources
|
|
|
|
//
|
|
|
|
CoreUnloadAndCloseImage (Image, TRUE);
|
|
|
|
Status = EFI_SUCCESS;
|
|
|
|
goto Done;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Image has been started, verify this image can exit
|
|
|
|
//
|
|
|
|
if (Image != mCurrentImage) {
|
2008-05-09 09:08:30 +02:00
|
|
|
DEBUG ((DEBUG_LOAD|DEBUG_ERROR, "Exit: Image is not exitable image\n"));
|
2007-07-04 12:51:54 +02:00
|
|
|
Status = EFI_INVALID_PARAMETER;
|
|
|
|
goto Done;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Set status
|
|
|
|
//
|
|
|
|
Image->Status = Status;
|
|
|
|
|
|
|
|
//
|
|
|
|
// If there's ExitData info, move it
|
|
|
|
//
|
|
|
|
if (ExitData != NULL) {
|
|
|
|
Image->ExitDataSize = ExitDataSize;
|
2008-08-27 16:29:23 +02:00
|
|
|
Image->ExitData = AllocatePool (Image->ExitDataSize);
|
2007-07-04 12:51:54 +02:00
|
|
|
if (Image->ExitData == NULL) {
|
|
|
|
Status = EFI_OUT_OF_RESOURCES;
|
|
|
|
goto Done;
|
|
|
|
}
|
|
|
|
CopyMem (Image->ExitData, ExitData, Image->ExitDataSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
CoreRestoreTpl (OldTpl);
|
|
|
|
//
|
|
|
|
// return to StartImage
|
|
|
|
//
|
|
|
|
LongJump (Image->JumpContext, (UINTN)-1);
|
|
|
|
|
|
|
|
//
|
|
|
|
// If we return from LongJump, then it is an error
|
|
|
|
//
|
|
|
|
ASSERT (FALSE);
|
|
|
|
Status = EFI_ACCESS_DENIED;
|
|
|
|
Done:
|
|
|
|
CoreRestoreTpl (OldTpl);
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-05-09 09:08:30 +02:00
|
|
|
/**
|
2007-07-04 12:51:54 +02:00
|
|
|
Unloads an image.
|
|
|
|
|
2008-05-21 10:32:06 +02:00
|
|
|
@param ImageHandle Handle that identifies the image to be
|
|
|
|
unloaded.
|
2007-07-04 12:51:54 +02:00
|
|
|
|
2008-05-21 10:32:06 +02:00
|
|
|
@retval EFI_SUCCESS The image has been unloaded.
|
|
|
|
@retval EFI_UNSUPPORTED The image has been sarted, and does not support
|
|
|
|
unload.
|
2008-05-09 09:08:30 +02:00
|
|
|
@retval EFI_INVALID_PARAMPETER ImageHandle is not a valid image handle.
|
2007-07-04 12:51:54 +02:00
|
|
|
|
2008-05-09 09:08:30 +02:00
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
CoreUnloadImage (
|
|
|
|
IN EFI_HANDLE ImageHandle
|
|
|
|
)
|
2007-07-04 12:51:54 +02:00
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
LOADED_IMAGE_PRIVATE_DATA *Image;
|
|
|
|
|
|
|
|
Image = CoreLoadedImageInfo (ImageHandle);
|
|
|
|
if (Image == NULL ) {
|
|
|
|
//
|
|
|
|
// The image handle is not valid
|
|
|
|
//
|
|
|
|
Status = EFI_INVALID_PARAMETER;
|
|
|
|
goto Done;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Image->Started) {
|
|
|
|
//
|
|
|
|
// The image has been started, request it to unload.
|
|
|
|
//
|
|
|
|
Status = EFI_UNSUPPORTED;
|
|
|
|
if (Image->Info.Unload != NULL) {
|
|
|
|
Status = Image->Info.Unload (ImageHandle);
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
//
|
|
|
|
// This Image hasn't been started, thus it can be unloaded
|
|
|
|
//
|
|
|
|
Status = EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!EFI_ERROR (Status)) {
|
|
|
|
//
|
|
|
|
// if the Image was not started or Unloaded O.K. then clean up
|
|
|
|
//
|
|
|
|
CoreUnloadAndCloseImage (Image, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
Done:
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2009-04-17 06:47:55 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
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
|
|
|
|
)
|
|
|
|
{
|
|
|
|
return CoreUnloadImage (ImageHandle);
|
|
|
|
}
|