X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=MdeModulePkg%2FCore%2FDxe%2FImage%2FImage.c;h=7e5cea7b76ad2d27a861e59f52d51c8f72febb4f;hb=6320fa42c9216930926da7cef1bb726fe04699c3;hp=36893d9650ad38119ed7fa07aa66c619430503a0;hpb=7df7393feb90e87c32f5473af14eec7562b09ce3;p=mirror_edk2.git diff --git a/MdeModulePkg/Core/Dxe/Image/Image.c b/MdeModulePkg/Core/Dxe/Image/Image.c index 36893d9650..7e5cea7b76 100644 --- a/MdeModulePkg/Core/Dxe/Image/Image.c +++ b/MdeModulePkg/Core/Dxe/Image/Image.c @@ -1,7 +1,7 @@ /** @file Core image handling services to load and unload PeImage. -Copyright (c) 2006 - 2008, Intel Corporation.
+Copyright (c) 2006 - 2009, 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 @@ -144,17 +144,64 @@ CoreInitializeImageServices ( gDxeCoreImageHandle = Image->Handle; gDxeCoreLoadedImage = &Image->Info; + if (FeaturePcdGet (PcdFrameworkCompatibilitySupport)) { + // + // Export DXE Core PE Loader functionality for backward compatibility. + // + Status = CoreInstallProtocolInterface ( + &mLoadPe32PrivateData.Handle, + &gEfiLoadPeImageProtocolGuid, + EFI_NATIVE_INTERFACE, + &mLoadPe32PrivateData.Pe32Image + ); + } + + 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 +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); + // - // Export DXE Core PE Loader functionality + // Move data from our local copy of the file // - return CoreInstallProtocolInterface ( - &mLoadPe32PrivateData.Handle, - &gEfiLoadPeImageProtocolGuid, - EFI_NATIVE_INTERFACE, - &mLoadPe32PrivateData.Pe32Image - ); -} + 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; +} /** Loads, relocates, and invokes a PE/COFF image @@ -190,11 +237,7 @@ CoreLoadPeImage ( EFI_STATUS Status; BOOLEAN DstBufAlocated; UINTN Size; - UINTN LinkTimeBase; - EFI_TCG_PLATFORM_PROTOCOL *TcgPlatformProtocol; - IMAGE_FILE_HANDLE *FHandle; - FHandle = NULL; ZeroMem (&Image->ImageContext, sizeof (Image->ImageContext)); Image->ImageContext.Handle = Pe32Handle; @@ -239,10 +282,6 @@ CoreLoadPeImage ( Image->ImageContext.ImageError = IMAGE_ERROR_INVALID_SUBSYSTEM; return EFI_UNSUPPORTED; } - // - // Get the image base address in the original PeImage. - // - LinkTimeBase = (UINTN) Image->ImageContext.ImageAddress; // // Allocate memory of the correct memory type aligned on the required image boundry @@ -344,29 +383,6 @@ CoreLoadPeImage ( } } - // - // Measure the image before applying fixup - // - Status = CoreLocateProtocol ( - &gEfiTcgPlatformProtocolGuid, - NULL, - (VOID **) &TcgPlatformProtocol - ); - if (!EFI_ERROR (Status)) { - FHandle = (IMAGE_FILE_HANDLE *) Image->ImageContext.Handle; - Status = TcgPlatformProtocol->MeasurePeImage ( - BootPolicy, - (EFI_PHYSICAL_ADDRESS) (UINTN) FHandle->Source, - FHandle->SourceSize, - LinkTimeBase, - Image->ImageContext.ImageType, - Image->Info.DeviceHandle, - Image->Info.FilePath - ); - - ASSERT_EFI_ERROR (Status); - } - // // Relocate the image in memory // @@ -477,19 +493,22 @@ CoreLoadPeImage ( // - // 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] = '.'; @@ -502,6 +521,10 @@ CoreLoadPeImage ( break; } } + + if (Index == sizeof (EfiFileName) - 4) { + EfiFileName[Index] = 0; + } DEBUG ((DEBUG_INFO | DEBUG_LOAD, "%a", EfiFileName)); // &Image->ImageContext.PdbPointer[StartIndex])); } DEBUG ((DEBUG_INFO | DEBUG_LOAD, "\n")); @@ -665,6 +688,14 @@ CoreUnloadAndCloseImage ( &Image->Info ); + if (Image->ImageContext.HiiResourceData != 0) { + Status = CoreUninstallProtocolInterface ( + Image->Handle, + &gEfiHiiPackageListProtocolGuid, + (VOID *) (UINTN) Image->ImageContext.HiiResourceData + ); + } + } if (Image->RuntimeData != NULL) { @@ -782,19 +813,63 @@ CoreLoadImageCommon ( return EFI_INVALID_PARAMETER; } - // - // Get simple read access to the source file - // + ZeroMem (&FHand, sizeof (IMAGE_FILE_HANDLE)); + FHand.Signature = IMAGE_FILE_HANDLE_SIGNATURE; OriginalFilePath = FilePath; - Status = CoreOpenImageFile ( - BootPolicy, - SourceBuffer, - SourceSize, - &FilePath, - &DeviceHandle, - &FHand, - &AuthenticationStatus - ); + 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) { + Status = EFI_NOT_FOUND; + } 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); + } + } + } + } + } + if (Status == EFI_ALREADY_STARTED) { Image = NULL; goto Done; @@ -927,6 +1002,21 @@ CoreLoadImageCommon ( 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; + } + } + // // Success. Return the image handle // @@ -1017,8 +1107,8 @@ CoreLoadImage ( EFI_LOAD_PE_IMAGE_ATTRIBUTE_RUNTIME_REGISTRATION | EFI_LOAD_PE_IMAGE_ATTRIBUTE_DEBUG_IMAGE_INFO_TABLE_REGISTRATION ); - PERF_START (*ImageHandle, LOAD_IMAGE_TOK, NULL, Tick); - PERF_END (*ImageHandle, LOAD_IMAGE_TOK, NULL, 0); + PERF_START (*ImageHandle, "LoadImage:", NULL, Tick); + PERF_END (*ImageHandle, "LoadImage:", NULL, 0); return Status; } @@ -1121,10 +1211,18 @@ CoreStartImage ( return EFI_INVALID_PARAMETER; } + // + // The image to be started must have the machine type supported by DxeCore. + // + ASSERT (EFI_IMAGE_MACHINE_TYPE_SUPPORTED (Image->Machine)); + if (!EFI_IMAGE_MACHINE_TYPE_SUPPORTED (Image->Machine)) { + return EFI_UNSUPPORTED; + } + // // Don't profile Objects or invalid start requests // - PERF_START (ImageHandle, START_IMAGE_TOK, NULL, 0); + PERF_START (ImageHandle, "StartImage:", NULL, 0); // @@ -1144,7 +1242,7 @@ CoreStartImage ( // 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); + PERF_END (ImageHandle, "StartImage:", NULL, 0); return EFI_OUT_OF_RESOURCES; } Image->JumpContext = ALIGN_POINTER (Image->JumpBuffer, BASE_LIBRARY_JUMP_BUFFER_ALIGNMENT); @@ -1240,7 +1338,7 @@ CoreStartImage ( // // Done // - PERF_END (ImageHandle, START_IMAGE_TOK, NULL, 0); + PERF_END (ImageHandle, "StartImage:", NULL, 0); return Status; }