X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FCore%2FDxe%2FImage%2FImage.c;h=e51a9fe1743b8391e2d7bbf5c0341f84ffec7e4a;hp=04f8368a1c2c51449b24559c863290dee28295ce;hb=28186d45660c92b8d98b8b19b5f8e6ff71ea5fba;hpb=d2fbaaab17945b59ca66bcd2f72e26ba3361e1d0 diff --git a/MdeModulePkg/Core/Dxe/Image/Image.c b/MdeModulePkg/Core/Dxe/Image/Image.c index 04f8368a1c..e51a9fe174 100644 --- a/MdeModulePkg/Core/Dxe/Image/Image.c +++ b/MdeModulePkg/Core/Dxe/Image/Image.c @@ -1,8 +1,8 @@ /** @file Core image handling services to load and unload PeImage. -Copyright (c) 2006 - 2010, Intel Corporation.
-All rights reserved. This program and the accompanying materials +Copyright (c) 2006 - 2012, 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 @@ -77,6 +77,46 @@ LOADED_IMAGE_PRIVATE_DATA mCorePrivateImage = { // GLOBAL_REMOVE_IF_UNREFERENCED UINT64 *mDxeCodeMemoryRangeUsageBitMap=NULL; +typedef struct { + UINT16 MachineType; + CHAR16 *MachineTypeName; +} MACHINE_TYPE_INFO; + +// +// 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"} +}; + +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; + } + } + + return L""; +} + /** Add the Image Services to EFI Boot Services Table and install the protocol interfaces for this image. @@ -97,6 +137,7 @@ CoreInitializeImageServices ( UINT64 DxeCoreImageLength; VOID *DxeCoreEntryPoint; EFI_PEI_HOB_POINTERS DxeCoreHob; + // // Searching for image hob // @@ -116,6 +157,7 @@ CoreInitializeImageServices ( DxeCoreImageLength = DxeCoreHob.MemoryAllocationModule->MemoryAllocationHeader.MemoryLength; DxeCoreEntryPoint = (VOID *) (UINTN) DxeCoreHob.MemoryAllocationModule->EntryPoint; gDxeCoreFileName = &DxeCoreHob.MemoryAllocationModule->ModuleName; + // // Initialize the fields for an internal driver // @@ -145,6 +187,7 @@ CoreInitializeImageServices ( // // Fill in DXE globals // + mDxeCoreImageMachineType = PeCoffLoaderGetMachineType (Image->Info.ImageBase); gDxeCoreImageHandle = Image->Handle; gDxeCoreLoadedImage = &Image->Info; @@ -153,11 +196,11 @@ CoreInitializeImageServices ( // Export DXE Core PE Loader functionality for backward compatibility. // Status = CoreInstallProtocolInterface ( - &mLoadPe32PrivateData.Handle, - &gEfiLoadPeImageProtocolGuid, - EFI_NATIVE_INTERFACE, - &mLoadPe32PrivateData.Pe32Image - ); + &mLoadPe32PrivateData.Handle, + &gEfiLoadPeImageProtocolGuid, + EFI_NATIVE_INTERFACE, + &mLoadPe32PrivateData.Pe32Image + ); } return Status; @@ -189,6 +232,14 @@ CoreReadImageFile ( UINTN EndPosition; IMAGE_FILE_HANDLE *FHand; + if (UserHandle == NULL || ReadSize == NULL || Buffer == NULL) { + return EFI_INVALID_PARAMETER; + } + + if (MAX_ADDRESS - Offset < *ReadSize) { + return EFI_INVALID_PARAMETER; + } + FHand = (IMAGE_FILE_HANDLE *)UserHandle; ASSERT (FHand->Signature == IMAGE_FILE_HANDLE_SIGNATURE); @@ -356,7 +407,7 @@ GetPeCoffImageFixLoadingAssignedAddress( // relative to top address // if ((INT64)PcdGet64(PcdLoadModuleAtFixAddressEnable) < 0) { - ImageContext->ImageAddress = gLoadModuleAtFixAddressConfigurationTable.DxeCodeTopAddress + (INT64)ImageContext->ImageAddress; + ImageContext->ImageAddress = gLoadModuleAtFixAddressConfigurationTable.DxeCodeTopAddress + (INT64)(INTN)ImageContext->ImageAddress; } // // Check if the memory range is avaliable. @@ -424,6 +475,8 @@ CoreLoadPeImage ( // The PE/COFF loader can support loading image types that can be executed. // If we loaded an image type that we can not execute return EFI_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; } } @@ -957,6 +1010,14 @@ CoreUnloadAndCloseImage ( 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 @@ -1076,6 +1137,13 @@ CoreLoadImageCommon ( OriginalFilePath ); 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; @@ -1227,7 +1295,6 @@ Done: if (EFI_ERROR (Status)) { if (Image != NULL) { CoreUnloadAndCloseImage (Image, (BOOLEAN)(DstBuffer == 0)); - *ImageHandle = NULL; } } else if (EFI_ERROR (SecurityStatus)) { Status = SecurityStatus; @@ -1263,6 +1330,14 @@ Done: 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 @@ -1332,6 +1407,14 @@ CoreLoadImage ( 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 @@ -1370,7 +1453,7 @@ CoreLoadImageEx ( @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 Unicode string, + 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 @@ -1404,8 +1487,13 @@ CoreStartImage ( // // 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)) { + // + // 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; }