X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FCore%2FDxe%2FDispatcher%2FDispatcher.c;fp=MdeModulePkg%2FCore%2FDxe%2FDispatcher%2FDispatcher.c;h=c7b9224c0e33301e111d48f9b9407c03ac5b8572;hp=5eee71bb2cd33ce6fd10dd72c183d76db9239b4d;hb=5d0b4eb453bb0359487450e26884eebb8b452ff4;hpb=56c909f3b388753dce53f8ba0061236916dbb220 diff --git a/MdeModulePkg/Core/Dxe/Dispatcher/Dispatcher.c b/MdeModulePkg/Core/Dxe/Dispatcher/Dispatcher.c index 5eee71bb2c..c7b9224c0e 100644 --- a/MdeModulePkg/Core/Dxe/Dispatcher/Dispatcher.c +++ b/MdeModulePkg/Core/Dxe/Dispatcher/Dispatcher.c @@ -1023,32 +1023,38 @@ CoreProcessFvImageFile ( // can be aligned on any power-of-two boundary. A weakly aligned volume can not be moved from // its initial linked location and maintain its alignment. // - if ((FvHeader->Attributes & EFI_FVB2_WEAK_ALIGNMENT) != EFI_FVB2_WEAK_ALIGNMENT) { + if ((ReadUnaligned32 (&FvHeader->Attributes) & EFI_FVB2_WEAK_ALIGNMENT) != EFI_FVB2_WEAK_ALIGNMENT) { // // Get FvHeader alignment // - FvAlignment = 1 << ((FvHeader->Attributes & EFI_FVB2_ALIGNMENT) >> 16); + FvAlignment = 1 << ((ReadUnaligned32 (&FvHeader->Attributes) & EFI_FVB2_ALIGNMENT) >> 16); // // FvAlignment must be greater than or equal to 8 bytes of the minimum FFS alignment value. // if (FvAlignment < 8) { FvAlignment = 8; } + // - // Allocate the aligned buffer for the FvImage. + // Check FvImage alignment. // - AlignedBuffer = AllocateAlignedPages (EFI_SIZE_TO_PAGES (BufferSize), (UINTN) FvAlignment); - if (AlignedBuffer == NULL) { - FreePool (Buffer); - return EFI_OUT_OF_RESOURCES; - } else { + if ((UINTN) FvHeader % FvAlignment != 0) { // - // Move FvImage into the aligned buffer and release the original buffer. + // Allocate the aligned buffer for the FvImage. // - CopyMem (AlignedBuffer, Buffer, BufferSize); - FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *) AlignedBuffer; - CoreFreePool (Buffer); - Buffer = NULL; + AlignedBuffer = AllocateAlignedPages (EFI_SIZE_TO_PAGES (BufferSize), (UINTN) FvAlignment); + if (AlignedBuffer == NULL) { + FreePool (Buffer); + return EFI_OUT_OF_RESOURCES; + } else { + // + // Move FvImage into the aligned buffer and release the original buffer. + // + CopyMem (AlignedBuffer, Buffer, BufferSize); + FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *) AlignedBuffer; + CoreFreePool (Buffer); + Buffer = NULL; + } } } //