public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Gao, Liming" <liming.gao@intel.com>
To: "Long, Qin" <qin.long@intel.com>,
	"edk2-devel@lists.01.org" <edk2-devel@lists.01.org>
Subject: Re: [Patch] MdePkg/BaseLib: Add one wrapper on RdRand access for parameter check.
Date: Tue, 15 Nov 2016 05:17:34 +0000	[thread overview]
Message-ID: <4A89E2EF3DFEDB4C8BFDE51014F606A14B4B20EB@shsmsx102.ccr.corp.intel.com> (raw)
In-Reply-To: <20161104080256.10728-1-qin.long@intel.com>

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

> -----Original Message-----
> From: Long, Qin
> Sent: Friday, November 04, 2016 4:03 PM
> To: edk2-devel@lists.01.org; Gao, Liming <liming.gao@intel.com>
> Subject: [Patch] MdePkg/BaseLib: Add one wrapper on RdRand access for
> parameter check.
> 
> Add one wrapper implementation over assembly RdRand access to check
> possible NULL parameter, for better alignment with comment description.
> 
> Cc: Liming Gao <liming.gao@intel.com>
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Qin Long <qin.long@intel.com>
> ---
>  MdePkg/Library/BaseLib/BaseLib.inf        |  2 +
>  MdePkg/Library/BaseLib/BaseLibInternals.h | 48 ++++++++++++++++++-
>  MdePkg/Library/BaseLib/Ia32/RdRand.S      | 20 ++++----
>  MdePkg/Library/BaseLib/Ia32/RdRand.asm    | 20 ++++----
>  MdePkg/Library/BaseLib/Ia32/RdRand.nasm   | 20 ++++----
>  MdePkg/Library/BaseLib/X64/RdRand.S       | 20 ++++----
>  MdePkg/Library/BaseLib/X64/RdRand.asm     | 20 ++++----
>  MdePkg/Library/BaseLib/X64/RdRand.nasm    | 20 ++++----
>  MdePkg/Library/BaseLib/X86RdRand.c        | 79
> +++++++++++++++++++++++++++++++
>  9 files changed, 188 insertions(+), 61 deletions(-)
>  create mode 100644 MdePkg/Library/BaseLib/X86RdRand.c
> 
> diff --git a/MdePkg/Library/BaseLib/BaseLib.inf
> b/MdePkg/Library/BaseLib/BaseLib.inf
> index 1ffe870..320ac45 100644
> --- a/MdePkg/Library/BaseLib/BaseLib.inf
> +++ b/MdePkg/Library/BaseLib/BaseLib.inf
> @@ -428,6 +428,7 @@
>    X86EnablePaging32.c
>    X86DisablePaging64.c
>    X86DisablePaging32.c
> +  X86RdRand.c
> 
>  [Sources.X64]
>    X64/Thunk16.nasm
> @@ -752,6 +753,7 @@
>    X86EnablePaging32.c
>    X86DisablePaging64.c
>    X86DisablePaging32.c
> +  X86RdRand.c
>    X64/GccInline.c | GCC
>    X64/Thunk16.S | XCODE
>    X64/SwitchStack.nasm| GCC
> diff --git a/MdePkg/Library/BaseLib/BaseLibInternals.h
> b/MdePkg/Library/BaseLib/BaseLibInternals.h
> index fe416a0..a8f712b 100644
> --- a/MdePkg/Library/BaseLib/BaseLibInternals.h
> +++ b/MdePkg/Library/BaseLib/BaseLibInternals.h
> @@ -1,7 +1,7 @@
>  /** @file
>    Declaration of internal functions in BaseLib.
> 
> -  Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
> +  Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
>    This program and the accompanying materials
>    are licensed and made available under the terms and conditions of the BSD
> License
>    which accompanies this distribution.  The full text of the license may be
> found at
> @@ -728,6 +728,52 @@ InternalX86DisablePaging64 (
>    IN      UINT32                    NewStack
>    );
> 
> +/**
> +  Generates a 16-bit random number through RDRAND instruction.
> +
> +  @param[out]  Rand     Buffer pointer to store the random result.
> +
> +  @retval TRUE          RDRAND call was successful.
> +  @retval FALSE         Failed attempts to call RDRAND.
> +
> + **/
> +BOOLEAN
> +EFIAPI
> +InternalX86RdRand16 (
> +  OUT     UINT16                    *Rand
> +  );
> +
> +/**
> +  Generates a 32-bit random number through RDRAND instruction.
> +
> +  @param[out]  Rand     Buffer pointer to store the random result.
> +
> +  @retval TRUE          RDRAND call was successful.
> +  @retval FALSE         Failed attempts to call RDRAND.
> +
> +**/
> +BOOLEAN
> +EFIAPI
> +InternalX86RdRand32 (
> +  OUT     UINT32                    *Rand
> +  );
> +
> +/**
> +  Generates a 64-bit random number through RDRAND instruction.
> +
> +
> +  @param[out]  Rand     Buffer pointer to store the random result.
> +
> +  @retval TRUE          RDRAND call was successful.
> +  @retval FALSE         Failed attempts to call RDRAND.
> +
> +**/
> +BOOLEAN
> +EFIAPI
> +InternalX86RdRand64  (
> +  OUT     UINT64                    *Rand
> +  );
> +
> 
>  #elif defined (MDE_CPU_IPF)
>  //
> diff --git a/MdePkg/Library/BaseLib/Ia32/RdRand.S
> b/MdePkg/Library/BaseLib/Ia32/RdRand.S
> index 503f65a..d00075a 100644
> --- a/MdePkg/Library/BaseLib/Ia32/RdRand.S
> +++ b/MdePkg/Library/BaseLib/Ia32/RdRand.S
> @@ -1,5 +1,5 @@
>  #------------------------------------------------------------------------------ ;
> -# Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
> +# Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>
>  # This program and the accompanying materials
>  # are licensed and made available under the terms and conditions of the BSD
> License
>  # which accompanies this distribution.  The full text of the license may be
> found at
> @@ -24,10 +24,10 @@
>  //  Generates a 16 bit random number through RDRAND instruction.
>  //  Return TRUE if Rand generated successfully, or FALSE if not.
>  //
> -//  BOOLEAN EFIAPI AsmRdRand16 (UINT16 *Rand);
> +//  BOOLEAN EFIAPI InternalX86RdRand16 (UINT16 *Rand);
>  //------------------------------------------------------------------------------
> -ASM_GLOBAL ASM_PFX(AsmRdRand16)
> -ASM_PFX(AsmRdRand16):
> +ASM_GLOBAL ASM_PFX(InternalX86RdRand16)
> +ASM_PFX(InternalX86RdRand16):
>      .byte  0x0f, 0xc7, 0xf0        // rdrand r16: "0f c7 /6  ModRM:r/m(w)"
>      jc     rn16_ok                 // jmp if CF=1
>      xor    %eax, %eax              // reg=0 if CF=0
> @@ -42,10 +42,10 @@ rn16_ok:
>  //  Generates a 32 bit random number through RDRAND instruction.
>  //  Return TRUE if Rand generated successfully, or FALSE if not.
>  //
> -//  BOOLEAN EFIAPI AsmRdRand32 (UINT32 *Rand);
> +//  BOOLEAN EFIAPI InternalX86RdRand32 (UINT32 *Rand);
>  //------------------------------------------------------------------------------
> -ASM_GLOBAL ASM_PFX(AsmRdRand32)
> -ASM_PFX(AsmRdRand32):
> +ASM_GLOBAL ASM_PFX(InternalX86RdRand32)
> +ASM_PFX(InternalX86RdRand32):
>      .byte  0x0f, 0xc7, 0xf0        // rdrand r32: "0f c7 /6  ModRM:r/m(w)"
>      jc     rn32_ok                 // jmp if CF=1
>      xor    %eax, %eax              // reg=0 if CF=0
> @@ -60,10 +60,10 @@ rn32_ok:
>  //  Generates a 64 bit random number through RDRAND instruction.
>  //  Return TRUE if Rand generated successfully, or FALSE if not.
>  //
> -//  BOOLEAN EFIAPI AsmRdRand64 (UINT64 *Rand);
> +//  BOOLEAN EFIAPI InternalX86RdRand64 (UINT64 *Rand);
>  //------------------------------------------------------------------------------
> -ASM_GLOBAL ASM_PFX(AsmRdRand64)
> -ASM_PFX(AsmRdRand64):
> +ASM_GLOBAL ASM_PFX(InternalX86RdRand64)
> +ASM_PFX(InternalX86RdRand64):
>      .byte  0x0f, 0xc7, 0xf0        // rdrand r32: "0f c7 /6  ModRM:r/m(w)"
>      jnc    rn64_ret                // jmp if CF=0
>      mov    0x4(%esp), %edx
> diff --git a/MdePkg/Library/BaseLib/Ia32/RdRand.asm
> b/MdePkg/Library/BaseLib/Ia32/RdRand.asm
> index 21349b0..cb4e811 100644
> --- a/MdePkg/Library/BaseLib/Ia32/RdRand.asm
> +++ b/MdePkg/Library/BaseLib/Ia32/RdRand.asm
> @@ -1,6 +1,6 @@
>  ;------------------------------------------------------------------------------
>  ;
> -; Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
> +; Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>
>  ; This program and the accompanying materials
>  ; are licensed and made available under the terms and conditions of the BSD
> License
>  ; which accompanies this distribution.  The full text of the license may be
> found at
> @@ -30,9 +30,9 @@
>  ;  Generates a 16 bit random number through RDRAND instruction.
>  ;  Return TRUE if Rand generated successfully, or FALSE if not.
>  ;
> -;  BOOLEAN EFIAPI AsmRdRand16 (UINT16 *Rand);
> +;  BOOLEAN EFIAPI InternalX86RdRand16 (UINT16 *Rand);
>  ;------------------------------------------------------------------------------
> -AsmRdRand16  PROC
> +InternalX86RdRand16  PROC
>      ; rdrand   ax                  ; generate a 16 bit RN into ax
>                                     ; CF=1 if RN generated ok, otherwise CF=0
>      db     0fh, 0c7h, 0f0h         ; rdrand r16: "0f c7 /6  ModRM:r/m(w)"
> @@ -44,15 +44,15 @@ rn16_ok:
>      mov    [edx], ax
>      mov    eax,  1
>      ret
> -AsmRdRand16 ENDP
> +InternalX86RdRand16 ENDP
> 
>  ;------------------------------------------------------------------------------
>  ;  Generates a 32 bit random number through RDRAND instruction.
>  ;  Return TRUE if Rand generated successfully, or FALSE if not.
>  ;
> -;  BOOLEAN EFIAPI AsmRdRand32 (UINT32 *Rand);
> +;  BOOLEAN EFIAPI InternalX86RdRand32 (UINT32 *Rand);
>  ;------------------------------------------------------------------------------
> -AsmRdRand32  PROC
> +InternalX86RdRand32  PROC
>      ; rdrand   eax                 ; generate a 32 bit RN into eax
>                                     ; CF=1 if RN generated ok, otherwise CF=0
>      db     0fh, 0c7h, 0f0h         ; rdrand r32: "0f c7 /6  ModRM:r/m(w)"
> @@ -64,15 +64,15 @@ rn32_ok:
>      mov    [edx], eax
>      mov    eax,  1
>      ret
> -AsmRdRand32 ENDP
> +InternalX86RdRand32 ENDP
> 
>  ;------------------------------------------------------------------------------
>  ;  Generates a 64 bit random number through RDRAND instruction.
>  ;  Return TRUE if Rand generated successfully, or FALSE if not.
>  ;
> -;  BOOLEAN EFIAPI AsmRdRand64 (UINT64 *Rand);
> +;  BOOLEAN EFIAPI InternalX86RdRand64 (UINT64 *Rand);
>  ;------------------------------------------------------------------------------
> -AsmRdRand64  PROC
> +InternalX86RdRand64  PROC
>      ; rdrand   eax                 ; generate a 32 bit RN into eax
>                                     ; CF=1 if RN generated ok, otherwise CF=0
>      db     0fh, 0c7h, 0f0h         ; rdrand r32: "0f c7 /6  ModRM:r/m(w)"
> @@ -89,6 +89,6 @@ AsmRdRand64  PROC
>  rn64_ret:
>      xor    eax, eax
>      ret                            ; return with failure status
> -AsmRdRand64 ENDP
> +InternalX86RdRand64 ENDP
> 
>      END
> diff --git a/MdePkg/Library/BaseLib/Ia32/RdRand.nasm
> b/MdePkg/Library/BaseLib/Ia32/RdRand.nasm
> index 1365dfc..64e8cdb 100644
> --- a/MdePkg/Library/BaseLib/Ia32/RdRand.nasm
> +++ b/MdePkg/Library/BaseLib/Ia32/RdRand.nasm
> @@ -1,6 +1,6 @@
>  ;------------------------------------------------------------------------------
>  ;
> -; Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
> +; Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>
>  ; This program and the accompanying materials
>  ; are licensed and made available under the terms and conditions of the BSD
> License
>  ; which accompanies this distribution.  The full text of the license may be
> found at
> @@ -27,10 +27,10 @@ SECTION .text
>  ;  Generates a 16 bit random number through RDRAND instruction.
>  ;  Return TRUE if Rand generated successfully, or FALSE if not.
>  ;
> -;  BOOLEAN EFIAPI AsmRdRand16 (UINT16 *Rand);
> +;  BOOLEAN EFIAPI InternalX86RdRand16 (UINT16 *Rand);
>  ;------------------------------------------------------------------------------
> -global ASM_PFX(AsmRdRand16)
> -ASM_PFX(AsmRdRand16):
> +global ASM_PFX(InternalX86RdRand16)
> +ASM_PFX(InternalX86RdRand16):
>      ; rdrand   ax                  ; generate a 16 bit RN into ax
>                                     ; CF=1 if RN generated ok, otherwise CF=0
>      db     0xf, 0xc7, 0xf0         ; rdrand r16: "0f c7 /6  ModRM:r/m(w)"
> @@ -47,10 +47,10 @@ rn16_ok:
>  ;  Generates a 32 bit random number through RDRAND instruction.
>  ;  Return TRUE if Rand generated successfully, or FALSE if not.
>  ;
> -;  BOOLEAN EFIAPI AsmRdRand32 (UINT32 *Rand);
> +;  BOOLEAN EFIAPI InternalX86RdRand32 (UINT32 *Rand);
>  ;------------------------------------------------------------------------------
> -global ASM_PFX(AsmRdRand32)
> -ASM_PFX(AsmRdRand32):
> +global ASM_PFX(InternalX86RdRand32)
> +ASM_PFX(InternalX86RdRand32):
>      ; rdrand   eax                 ; generate a 32 bit RN into eax
>                                     ; CF=1 if RN generated ok, otherwise CF=0
>      db     0xf, 0xc7, 0xf0         ; rdrand r32: "0f c7 /6  ModRM:r/m(w)"
> @@ -67,10 +67,10 @@ rn32_ok:
>  ;  Generates a 64 bit random number through RDRAND instruction.
>  ;  Return TRUE if Rand generated successfully, or FALSE if not.
>  ;
> -;  BOOLEAN EFIAPI AsmRdRand64 (UINT64 *Rand);
> +;  BOOLEAN EFIAPI InternalX86RdRand64 (UINT64 *Rand);
>  ;------------------------------------------------------------------------------
> -global ASM_PFX(AsmRdRand64)
> -ASM_PFX(AsmRdRand64):
> +global ASM_PFX(InternalX86RdRand64)
> +ASM_PFX(InternalX86RdRand64):
>      ; rdrand   eax                 ; generate a 32 bit RN into eax
>                                     ; CF=1 if RN generated ok, otherwise CF=0
>      db     0xf, 0xc7, 0xf0         ; rdrand r32: "0f c7 /6  ModRM:r/m(w)"
> diff --git a/MdePkg/Library/BaseLib/X64/RdRand.S
> b/MdePkg/Library/BaseLib/X64/RdRand.S
> index 49b50e6..55724c0 100644
> --- a/MdePkg/Library/BaseLib/X64/RdRand.S
> +++ b/MdePkg/Library/BaseLib/X64/RdRand.S
> @@ -1,5 +1,5 @@
>  #------------------------------------------------------------------------------ ;
> -# Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
> +# Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>
>  # This program and the accompanying materials
>  # are licensed and made available under the terms and conditions of the BSD
> License
>  # which accompanies this distribution.  The full text of the license may be
> found at
> @@ -24,10 +24,10 @@
>  //  Generates a 16 bit random number through RDRAND instruction.
>  //  Return TRUE if Rand generated successfully, or FALSE if not.
>  //
> -//  BOOLEAN EFIAPI AsmRdRand16 (UINT16 *Rand);
> +//  BOOLEAN EFIAPI InternalX86RdRand16 (UINT16 *Rand);
>  //------------------------------------------------------------------------------
> -ASM_GLOBAL ASM_PFX(AsmRdRand16)
> -ASM_PFX(AsmRdRand16):
> +ASM_GLOBAL ASM_PFX(InternalX86RdRand16)
> +ASM_PFX(InternalX86RdRand16):
>      .byte  0x0f, 0xc7, 0xf0        // rdrand r16: "0f c7 /6  ModRM:r/m(w)"
>      jc     rn16_ok                 // jmp if CF=1
>      xor    %rax, %rax              // reg=0 if CF=0
> @@ -41,10 +41,10 @@ rn16_ok:
>  //  Generates a 32 bit random number through RDRAND instruction.
>  //  Return TRUE if Rand generated successfully, or FALSE if not.
>  //
> -//  BOOLEAN EFIAPI AsmRdRand32 (UINT32 *Rand);
> +//  BOOLEAN EFIAPI InternalX86RdRand32 (UINT32 *Rand);
>  //------------------------------------------------------------------------------
> -ASM_GLOBAL ASM_PFX(AsmRdRand32)
> -ASM_PFX(AsmRdRand32):
> +ASM_GLOBAL ASM_PFX(InternalX86RdRand32)
> +ASM_PFX(InternalX86RdRand32):
>      .byte  0x0f, 0xc7, 0xf0        // rdrand r32: "0f c7 /6  ModRM:r/m(w)"
>      jc     rn32_ok                 // jmp if CF=1
>      xor    %rax, %rax              // reg=0 if CF=0
> @@ -58,10 +58,10 @@ rn32_ok:
>  //  Generates a 64 bit random number through RDRAND instruction.
>  //  Return TRUE if Rand generated successfully, or FALSE if not.
>  //
> -//  BOOLEAN EFIAPI AsmRdRand64 (UINT64 *Rand);
> +//  BOOLEAN EFIAPI InternalX86RdRand64 (UINT64 *Rand);
>  //------------------------------------------------------------------------------
> -ASM_GLOBAL ASM_PFX(AsmRdRand64)
> -ASM_PFX(AsmRdRand64):
> +ASM_GLOBAL ASM_PFX(InternalX86RdRand64)
> +ASM_PFX(InternalX86RdRand64):
>      .byte  0x48, 0x0f, 0xc7, 0xf0  // rdrand r64: "REX.W + 0f c7 /6
> ModRM:r/m(w)"
>      jc     rn64_ok                 // jmp if CF=1
>      xor    %rax, %rax              // reg=0 if CF=0
> diff --git a/MdePkg/Library/BaseLib/X64/RdRand.asm
> b/MdePkg/Library/BaseLib/X64/RdRand.asm
> index 370cdb6..8e2074e 100644
> --- a/MdePkg/Library/BaseLib/X64/RdRand.asm
> +++ b/MdePkg/Library/BaseLib/X64/RdRand.asm
> @@ -1,6 +1,6 @@
>  ;------------------------------------------------------------------------------
>  ;
> -; Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
> +; Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>
>  ; This program and the accompanying materials
>  ; are licensed and made available under the terms and conditions of the BSD
> License
>  ; which accompanies this distribution.  The full text of the license may be
> found at
> @@ -27,9 +27,9 @@
>  ;  Generates a 16 bit random number through RDRAND instruction.
>  ;  Return TRUE if Rand generated successfully, or FALSE if not.
>  ;
> -;  BOOLEAN EFIAPI AsmRdRand16 (UINT16 *Rand);
> +;  BOOLEAN EFIAPI InternalX86RdRand16 (UINT16 *Rand);
>  ;------------------------------------------------------------------------------
> -AsmRdRand16  PROC
> +InternalX86RdRand16  PROC
>      ; rdrand   ax                  ; generate a 16 bit RN into eax,
>                                     ; CF=1 if RN generated ok, otherwise CF=0
>      db     0fh, 0c7h, 0f0h         ; rdrand r16: "0f c7 /6  ModRM:r/m(w)"
> @@ -40,15 +40,15 @@ rn16_ok:
>      mov    [rcx], ax
>      mov    rax,  1
>      ret
> -AsmRdRand16 ENDP
> +InternalX86RdRand16 ENDP
> 
>  ;------------------------------------------------------------------------------
>  ;  Generates a 32 bit random number through RDRAND instruction.
>  ;  Return TRUE if Rand generated successfully, or FALSE if not.
>  ;
> -;  BOOLEAN EFIAPI AsmRdRand32 (UINT32 *Rand);
> +;  BOOLEAN EFIAPI InternalX86RdRand32 (UINT32 *Rand);
>  ;------------------------------------------------------------------------------
> -AsmRdRand32  PROC
> +InternalX86RdRand32  PROC
>      ; rdrand   eax                 ; generate a 32 bit RN into eax,
>                                     ; CF=1 if RN generated ok, otherwise CF=0
>      db     0fh, 0c7h, 0f0h         ; rdrand r32: "0f c7 /6  ModRM:r/m(w)"
> @@ -59,15 +59,15 @@ rn32_ok:
>      mov    [rcx], eax
>      mov    rax,  1
>      ret
> -AsmRdRand32 ENDP
> +InternalX86RdRand32 ENDP
> 
>  ;------------------------------------------------------------------------------
>  ;  Generates a 64 bit random number through one RDRAND instruction.
>  ;  Return TRUE if Rand generated successfully, or FALSE if not.
>  ;
> -;  BOOLEAN EFIAPI AsmRdRand64 (UINT64 *Random);
> +;  BOOLEAN EFIAPI InternalX86RdRand64 (UINT64 *Random);
>  ;------------------------------------------------------------------------------
> -AsmRdRand64  PROC
> +InternalX86RdRand64  PROC
>      ; rdrand   rax                 ; generate a 64 bit RN into rax,
>                                     ; CF=1 if RN generated ok, otherwise CF=0
>      db     048h, 0fh, 0c7h, 0f0h   ; rdrand r64: "REX.W + 0f c7 /6 ModRM:r/m(w)"
> @@ -78,6 +78,6 @@ rn64_ok:
>      mov    [rcx], rax
>      mov    rax, 1
>      ret
> -AsmRdRand64 ENDP
> +InternalX86RdRand64 ENDP
> 
>      END
> diff --git a/MdePkg/Library/BaseLib/X64/RdRand.nasm
> b/MdePkg/Library/BaseLib/X64/RdRand.nasm
> index f6d83a3..b9050d2 100644
> --- a/MdePkg/Library/BaseLib/X64/RdRand.nasm
> +++ b/MdePkg/Library/BaseLib/X64/RdRand.nasm
> @@ -1,6 +1,6 @@
>  ;------------------------------------------------------------------------------
>  ;
> -; Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
> +; Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>
>  ; This program and the accompanying materials
>  ; are licensed and made available under the terms and conditions of the BSD
> License
>  ; which accompanies this distribution.  The full text of the license may be
> found at
> @@ -28,10 +28,10 @@
>  ;  Generates a 16 bit random number through RDRAND instruction.
>  ;  Return TRUE if Rand generated successfully, or FALSE if not.
>  ;
> -;  BOOLEAN EFIAPI AsmRdRand16 (UINT16 *Rand);
> +;  BOOLEAN EFIAPI InternalX86RdRand16 (UINT16 *Rand);
>  ;------------------------------------------------------------------------------
> -global ASM_PFX(AsmRdRand16)
> -ASM_PFX(AsmRdRand16):
> +global ASM_PFX(InternalX86RdRand16)
> +ASM_PFX(InternalX86RdRand16):
>      ; rdrand   ax                  ; generate a 16 bit RN into eax,
>                                     ; CF=1 if RN generated ok, otherwise CF=0
>      db     0xf, 0xc7, 0xf0         ; rdrand r16: "0f c7 /6  ModRM:r/m(w)"
> @@ -47,10 +47,10 @@ rn16_ok:
>  ;  Generates a 32 bit random number through RDRAND instruction.
>  ;  Return TRUE if Rand generated successfully, or FALSE if not.
>  ;
> -;  BOOLEAN EFIAPI AsmRdRand32 (UINT32 *Rand);
> +;  BOOLEAN EFIAPI InternalX86RdRand32 (UINT32 *Rand);
>  ;------------------------------------------------------------------------------
> -global ASM_PFX(AsmRdRand32)
> -ASM_PFX(AsmRdRand32):
> +global ASM_PFX(InternalX86RdRand32)
> +ASM_PFX(InternalX86RdRand32):
>      ; rdrand   eax                 ; generate a 32 bit RN into eax,
>                                     ; CF=1 if RN generated ok, otherwise CF=0
>      db     0xf, 0xc7, 0xf0         ; rdrand r32: "0f c7 /6  ModRM:r/m(w)"
> @@ -66,10 +66,10 @@ rn32_ok:
>  ;  Generates a 64 bit random number through one RDRAND instruction.
>  ;  Return TRUE if Rand generated successfully, or FALSE if not.
>  ;
> -;  BOOLEAN EFIAPI AsmRdRand64 (UINT64 *Random);
> +;  BOOLEAN EFIAPI InternalX86RdRand64 (UINT64 *Random);
>  ;------------------------------------------------------------------------------
> -global ASM_PFX(AsmRdRand64)
> -ASM_PFX(AsmRdRand64):
> +global ASM_PFX(InternalX86RdRand64)
> +ASM_PFX(InternalX86RdRand64):
>      ; rdrand   rax                 ; generate a 64 bit RN into rax,
>                                     ; CF=1 if RN generated ok, otherwise CF=0
>      db     0x48, 0xf, 0xc7, 0xf0   ; rdrand r64: "REX.W + 0f c7 /6 ModRM:r/m(w)"
> diff --git a/MdePkg/Library/BaseLib/X86RdRand.c
> b/MdePkg/Library/BaseLib/X86RdRand.c
> new file mode 100644
> index 0000000..36d5457
> --- /dev/null
> +++ b/MdePkg/Library/BaseLib/X86RdRand.c
> @@ -0,0 +1,79 @@
> +/** @file
> +  IA-32/x64 AsmRdRandxx()
> +  Generates random number through CPU RdRand instruction.
> +
> +  Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>
> +  This program and the accompanying materials
> +  are licensed and made available under the terms and conditions of the BSD
> License
> +  which accompanies this distribution.  The full text of the license may be
> found at
> +  http://opensource.org/licenses/bsd-license.php.
> +
> +  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS"
> BASIS,
> +  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER
> EXPRESS OR IMPLIED.
> +
> +**/
> +
> +#include "BaseLibInternals.h"
> +
> +/**
> +  Generates a 16-bit random number through RDRAND instruction.
> +
> +  if Rand is NULL, then ASSERT().
> +
> +  @param[out]  Rand     Buffer pointer to store the random result.
> +
> +  @retval TRUE          RDRAND call was successful.
> +  @retval FALSE         Failed attempts to call RDRAND.
> +
> + **/
> +BOOLEAN
> +EFIAPI
> +AsmRdRand16 (
> +  OUT     UINT16                    *Rand
> +  )
> +{
> +  ASSERT (Rand != NULL);
> +  return InternalX86RdRand16 (Rand);
> +}
> +
> +/**
> +  Generates a 32-bit random number through RDRAND instruction.
> +
> +  if Rand is NULL, then ASSERT().
> +
> +  @param[out]  Rand     Buffer pointer to store the random result.
> +
> +  @retval TRUE          RDRAND call was successful.
> +  @retval FALSE         Failed attempts to call RDRAND.
> +
> +**/
> +BOOLEAN
> +EFIAPI
> +AsmRdRand32 (
> +  OUT     UINT32                    *Rand
> +  )
> +{
> +  ASSERT (Rand != NULL);
> +  return InternalX86RdRand32 (Rand);
> +}
> +
> +/**
> +  Generates a 64-bit random number through RDRAND instruction.
> +
> +  if Rand is NULL, then ASSERT().
> +
> +  @param[out]  Rand     Buffer pointer to store the random result.
> +
> +  @retval TRUE          RDRAND call was successful.
> +  @retval FALSE         Failed attempts to call RDRAND.
> +
> +**/
> +BOOLEAN
> +EFIAPI
> +AsmRdRand64  (
> +  OUT     UINT64                    *Rand
> +  )
> +{
> +  ASSERT (Rand != NULL);
> +  return InternalX86RdRand64 (Rand);
> +}
> --
> 2.10.1.windows.1



      reply	other threads:[~2016-11-15  5:17 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-04  8:02 [Patch] MdePkg/BaseLib: Add one wrapper on RdRand access for parameter check Qin Long
2016-11-15  5:17 ` Gao, Liming [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=4A89E2EF3DFEDB4C8BFDE51014F606A14B4B20EB@shsmsx102.ccr.corp.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