public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Laszlo Ersek <lersek@redhat.com>
To: Jeff Fan <jeff.fan@intel.com>, edk2-devel@ml01.01.org
Cc: Andrew Fish <afish@apple.com>, Feng Tian <feng.tian@intel.com>,
	Michael D Kinney <michael.d.kinney@intel.com>
Subject: Re: [PATCH v2] UefiCpuPkg/SecCore: Correct print format for stack information
Date: Wed, 16 Nov 2016 17:23:06 +0100	[thread overview]
Message-ID: <b78ea580-ce41-2f26-705a-49c8f5a76f11@redhat.com> (raw)
In-Reply-To: <20161116075506.9008-1-jeff.fan@intel.com>

On 11/16/16 08:55, Jeff Fan wrote:
> v2:
>   Per Laszlo and Andrew's comments at
>     https://lists.01.org/pipermail/edk2-devel/2016-November/004759.html
>   SecCoreData->StackBase is VOID * type. We should use %p to dump VOID * type.
>   SecCoreData->StackSize is UINTN type, but %x only could print unsinged-int
>   type. We will cast it to UINT32 firstly and then use %x to print it.
> 
> Cc: Laszlo Ersek <lersek@redhat.com>
> Cc: Andrew Fish <afish@apple.com>
> Cc: Feng Tian <feng.tian@intel.com>
> Cc: Michael D Kinney <michael.d.kinney@intel.com>
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Jeff Fan <jeff.fan@intel.com>
> ---
>  UefiCpuPkg/SecCore/SecMain.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/UefiCpuPkg/SecCore/SecMain.c b/UefiCpuPkg/SecCore/SecMain.c
> index 2ebbc22..077d0db 100644
> --- a/UefiCpuPkg/SecCore/SecMain.c
> +++ b/UefiCpuPkg/SecCore/SecMain.c
> @@ -239,10 +239,10 @@ SecStartupPhase2(
>  
>    DEBUG ((
>      DEBUG_INFO,
> -    "%a() Stack Base: 0x%lx, Stack Size: 0x%lx\n",
> +    "%a() Stack Base: 0x%p, Stack Size: 0x%x\n",
>      __FUNCTION__,
>      SecCoreData->StackBase,
> -    SecCoreData->StackSize
> +    (UINT32) SecCoreData->StackSize
>      ));
>  
>    //
> 

In the general case, I like to print UINTN values by:
- converting them to UINT64,
- printing them with %Lx (or %Lu).

This works reliably regardless of 32-bit vs. 64-bit.

However, I see that a stack size larger than MAX_UINT32 (~4GB) is quite
unlikely even for a 64-bit SEC phase :) Thus, the UINT32 cast won't
cause actual truncation.

Reviewed-by: Laszlo Ersek <lersek@redhat.com>

Thanks
Laszlo


      reply	other threads:[~2016-11-16 16:23 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-16  7:55 [PATCH v2] UefiCpuPkg/SecCore: Correct print format for stack information Jeff Fan
2016-11-16 16:23 ` Laszlo Ersek [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=b78ea580-ce41-2f26-705a-49c8f5a76f11@redhat.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