public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Liming Gao" <liming.gao@intel.com>
To: "Kinney, Michael D" <michael.d.kinney@intel.com>,
	"devel@edk2.groups.io" <devel@edk2.groups.io>
Cc: Sean Brogan <sean.brogan@microsoft.com>,
	Bret Barkelew <Bret.Barkelew@microsoft.com>
Subject: Re: [Patch] MdePkg/BaseSafeIntLib: Fix VS20xx IA32 link failures
Date: Thu, 13 Feb 2020 00:52:07 +0000	[thread overview]
Message-ID: <b83197701b814cfa84d14f3e28725279@intel.com> (raw)
In-Reply-To: <20200212224511.27164-1-michael.d.kinney@intel.com>

Reviewed-by: Liming Gao <liming.gao@intel.com>

> -----Original Message-----
> From: Kinney, Michael D <michael.d.kinney@intel.com>
> Sent: Thursday, February 13, 2020 6:45 AM
> To: devel@edk2.groups.io
> Cc: Gao, Liming <liming.gao@intel.com>; Sean Brogan <sean.brogan@microsoft.com>; Bret Barkelew <Bret.Barkelew@microsoft.com>
> Subject: [Patch] MdePkg/BaseSafeIntLib: Fix VS20xx IA32 link failures
> 
> https://bugzilla.tianocore.org/show_bug.cgi?id=2525
> 
> SafeUint64Mult() looks for 64-bit overflows and performs
> several 32-bit multiples with 64-bit results to check for
> all possible overflow conditions.  IA32 builds using VS20xx
> with optimizations enabled are producing a reference to
> the _allmull intrinsic.
> 
> The fix is to use MultU64x64() instead of '*' for
> these operations.  These are safe because the inputs
> are guaranteed to have the upper 32-bits clear, which
> means MultU64x64() can never overflow with those inputs.
> 
> Cc: Liming Gao <liming.gao@intel.com>
> Cc: Sean Brogan <sean.brogan@microsoft.com>
> Cc: Bret Barkelew <Bret.Barkelew@microsoft.com>
> Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
> ---
>  MdePkg/Library/BaseSafeIntLib/SafeIntLib.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/MdePkg/Library/BaseSafeIntLib/SafeIntLib.c b/MdePkg/Library/BaseSafeIntLib/SafeIntLib.c
> index 0f6be6e064..eec8ac1ffd 100644
> --- a/MdePkg/Library/BaseSafeIntLib/SafeIntLib.c
> +++ b/MdePkg/Library/BaseSafeIntLib/SafeIntLib.c
> @@ -3380,14 +3380,14 @@ SafeUint64Mult (
>        //
>        // a * d must be less than 2^32 or there would be bits set in the high 64-bits
>        //
> -      ProductAD = (((UINT64)DwordA) *(UINT64)DwordD);
> +      ProductAD = MultU64x64 ((UINT64)DwordA, (UINT64)DwordD);
>        if ((ProductAD & 0xffffffff00000000) == 0) {
>          DwordB = (UINT32)Multiplicand;
> 
>          //
>          // b * c must be less than 2^32 or there would be bits set in the high 64-bits
>          //
> -        ProductBC = (((UINT64)DwordB) *(UINT64)DwordC);
> +        ProductBC = MultU64x64 ((UINT64)DwordB, (UINT64)DwordC);
>          if ((ProductBC & 0xffffffff00000000) == 0) {
>            //
>            // now sum them all up checking for overflow.
> @@ -3397,7 +3397,7 @@ SafeUint64Mult (
>              //
>              // b * d
>              //
> -            ProductBD = (((UINT64)DwordB) *(UINT64)DwordD);
> +            ProductBD = MultU64x64 ((UINT64)DwordB, (UINT64)DwordD);
> 
>              if (!RETURN_ERROR (SafeUint64Add (UnsignedResult, ProductBD, &UnsignedResult))) {
>                *Result = UnsignedResult;
> --
> 2.21.0.windows.1


      parent reply	other threads:[~2020-02-13  0:52 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-12 22:45 [Patch] MdePkg/BaseSafeIntLib: Fix VS20xx IA32 link failures Michael D Kinney
2020-02-12 22:46 ` [EXTERNAL] " Bret Barkelew
2020-02-13  0:52 ` Liming Gao [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b83197701b814cfa84d14f3e28725279@intel.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox