According to \edk2\MdePkg\Include\X64\ProcessorBind.h

for X64 'UINTN' type has a length of 8 bytes:

typedef UINT64  UINTN;

and 'int' is 32-bit value:

typedef unsigned int        UINT32;

, so debug macros like in CpuConvertPagesToUncachedVirtualAddress() function 
(\edk2\OvmfPkg\BlockMmioToBlockIoDxe\BlockIo.c):

EFI_STATUS
EFIAPI
BlockIoReadBlocks (
  IN EFI_BLOCK_IO_PROTOCOL    *This,
  IN UINT32                   MediaId,
  IN EFI_LBA                  Lba,
  IN UINTN                    BufferSize,
  OUT VOID                    *Buffer
  )
{
  DEBUG ((EFI_D_INFO, "BlockIo (MMIO) ReadBlocks: lba=0x%lx, size=0x%x\n", Lba, 
BufferSize));
...

using '%x' format for UINTN BufferSize will result in truncation to 32-bit 
value.
In some cases '%x' for UINTN can produce wrong output if this UINTN number is 
specified as not the last parameter.

This happens because 'int' type is still 32-bit value & it's used in 
BasePrintLibSPrintMarker() function 
(\edk2\MdePkg\Library\BasePrintLib\PrintLibInternal.c):
Line #543:
      case 'd':
        if ((Flags & LONG_TYPE) == 0) {
          //
          // 'd','x', and 'X' that are not preceded by 'l' or 'L' are assumed 
to be type "int".
          // This assumption is made so the format string definition is 
compatible with the ANSI C
          // Specification for formatted strings.  It is recommended that the 
Base Types be used
          // everywhere, but in this one case, compliance with ANSI C is more 
important, and
          // provides an implementation that is compatible with that largest 
possible set of CPU
          // architectures.  This is why the type "int" is used in this one 
case.
          //
          if (BaseListMarker == NULL) {
            Value = VA_ARG (VaListMarker, int);
          } else {
            Value = BASE_ARG (BaseListMarker, int);
          }

& line #588:
          if ((Flags & LONG_TYPE) == 0 && Value < 0) {
            //
            // 'd','x', and 'X' that are not preceded by 'l' or 'L' are assumed 
to be type "int".
            // This assumption is made so the format string definition is 
compatible with the ANSI C
            // Specification for formatted strings.  It is recommended that the 
Base Types be used
            // everywhere, but in this one case, compliance with ANSI C is more 
important, and
            // provides an implementation that is compatible with that largest 
possible set of CPU
            // architectures.  This is why the type "unsigned int" is used in 
this one case.
            //
            Value = (unsigned int)Value;

Any comments on that?

Alexei.



-- IMPORTANT NOTICE: The contents of this email and any attachments are 
confidential and may also be privileged. If you are not the intended recipient, 
please notify the sender immediately and do not disclose the contents to any 
other person, use it for any purpose, or store or copy the information in any 
medium. Thank you.

ARM Limited, Registered office 110 Fulbourn Road, Cambridge CB1 9NJ, Registered 
in England & Wales, Company No: 2557590
ARM Holdings plc, Registered office 110 Fulbourn Road, Cambridge CB1 9NJ, 
Registered in England & Wales, Company No: 2548782
------------------------------------------------------------------------------
Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
Discover the easy way to master current and previous Microsoft technologies
and advance your career. Get an incredible 1,500+ hours of step-by-step
tutorial videos with LearnDevNow. Subscribe today and save!
http://pubads.g.doubleclick.net/gampad/clk?id=58041391&iu=/4140/ostg.clktrk
_______________________________________________
edk2-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-devel

Reply via email to