From: Laszlo Ersek Date: Fri, 14 Nov 2014 10:23:21 +0000 (+0000) Subject: OvmfPg: flash driver: fix type of EFI_SIZE_TO_PAGES argument (VS2010) X-Git-Tag: edk2-stable201903~10628 X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=commitdiff_plain;h=1e62c89c3ae0da2eeabb37c5ab299b928ebbbb30 OvmfPg: flash driver: fix type of EFI_SIZE_TO_PAGES argument (VS2010) The MarkMemoryRangeForRuntimeAccess() function passes the Length parameter (of type UINT64) to the macro EFI_SIZE_TO_PAGES(). When building for the Ia32 platform, this violates the interface contract of the macro: [...] Passing in a parameter that is larger than UINTN may produce unexpected results. In addition, it trips up compilation by VS2010 for the Ia32 platform and the NOOPT target -- it generates calls to intrinsics, which are not allowed in edk2. Fix both issues with the following steps: (1) Demote the Length parameter of MarkMemoryRangeForRuntimeAccess() to UINTN. Even a UINT32 value is plenty for representing the size of the flash chip holding the variable store. Length parameter is used in the following contexts: - passed to gDS->RemoveMemorySpace() -- takes an UINT64 - passed to gDS->AddMemorySpace() -- ditto - passed to EFI_SIZE_TO_PAGES() -- requires an UINTN. This also guarantees that the return type of EFI_SIZE_TO_PAGES() will be UINTN, hence we can drop the outer cast. (2) The only caller of MarkMemoryRangeForRuntimeAccess() is FvbInitialize(). The latter function populates the local Length variable (passed to MarkMemoryRangeForRuntimeAccess()) from PcdGet32(PcdOvmfFirmwareFdSize). Therefore we can simply demote the local variable to UINTN in this function as well. - There's only one other use of Length in FvbInitialize(): it is passed to GetFvbInfo(). GetFvbInfo() takes an UINT64, so passing an UINTN is fine. Suggested-by: Scott Duplichan Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Laszlo Ersek Build-tested-by: Scott Duplichan Reviewed-by: Jordan Justen git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@16382 6f19259b-4bc3-4df7-8a09-765794883524 --- diff --git a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockService.c b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockService.c index b56ece3931..42060c84cf 100644 --- a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockService.c +++ b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FwBlockService.c @@ -895,7 +895,7 @@ STATIC EFI_STATUS MarkMemoryRangeForRuntimeAccess ( EFI_PHYSICAL_ADDRESS BaseAddress, - UINT64 Length + UINTN Length ) { EFI_STATUS Status; @@ -919,7 +919,7 @@ MarkMemoryRangeForRuntimeAccess ( Status = gBS->AllocatePages ( AllocateAddress, EfiRuntimeServicesData, - (UINTN) EFI_SIZE_TO_PAGES (Length), + EFI_SIZE_TO_PAGES (Length), &BaseAddress ); ASSERT_EFI_ERROR (Status); @@ -1026,7 +1026,7 @@ Returns: EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *OldFwbInterface; UINT32 MaxLbaSize; EFI_PHYSICAL_ADDRESS BaseAddress; - UINT64 Length; + UINTN Length; UINTN NumOfBlocks; EFI_EVENT VirtualAddressChangeEvent;