public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Hao Wu <hao.a.wu@intel.com>
To: edk2-devel@lists.01.org
Cc: Hao Wu <hao.a.wu@intel.com>,
	Michael D Kinney <michael.d.kinney@intel.com>,
	Liming Gao <liming.gao@intel.com>,
	Jiewen Yao <jiewen.yao@intel.com>
Subject: [PATCH 2/3] MdePkg BaseMemoryLib: Add implementation of API IsZeroBuffer()
Date: Thu,  4 Aug 2016 09:24:29 +0800	[thread overview]
Message-ID: <1470273870-14376-3-git-send-email-hao.a.wu@intel.com> (raw)
In-Reply-To: <1470273870-14376-1-git-send-email-hao.a.wu@intel.com>

Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Hao Wu <hao.a.wu@intel.com>
---
 MdePkg/Include/Library/BaseMemoryLib.h             | 23 ++++++++
 MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf     |  1 +
 MdePkg/Library/BaseMemoryLib/IsZeroBuffer.c        | 65 ++++++++++++++++++++++
 .../Library/BaseMemoryLibMmx/BaseMemoryLibMmx.inf  |  1 +
 MdePkg/Library/BaseMemoryLibMmx/IsZeroBuffer.c     | 65 ++++++++++++++++++++++
 .../BaseMemoryLibOptDxe/BaseMemoryLibOptDxe.inf    |  2 +
 MdePkg/Library/BaseMemoryLibOptDxe/IsZeroBuffer.c  | 65 ++++++++++++++++++++++
 .../BaseMemoryLibOptPei/BaseMemoryLibOptPei.inf    |  2 +
 MdePkg/Library/BaseMemoryLibOptPei/IsZeroBuffer.c  | 65 ++++++++++++++++++++++
 .../BaseMemoryLibRepStr/BaseMemoryLibRepStr.inf    |  1 +
 MdePkg/Library/BaseMemoryLibRepStr/IsZeroBuffer.c  | 65 ++++++++++++++++++++++
 .../BaseMemoryLibSse2/BaseMemoryLibSse2.inf        |  1 +
 MdePkg/Library/BaseMemoryLibSse2/IsZeroBuffer.c    | 65 ++++++++++++++++++++++
 MdePkg/Library/PeiMemoryLib/IsZeroBuffer.c         | 65 ++++++++++++++++++++++
 MdePkg/Library/PeiMemoryLib/PeiMemoryLib.inf       |  1 +
 MdePkg/Library/UefiMemoryLib/IsZeroBuffer.c        | 65 ++++++++++++++++++++++
 MdePkg/Library/UefiMemoryLib/UefiMemoryLib.inf     |  1 +
 17 files changed, 553 insertions(+)
 create mode 100644 MdePkg/Library/BaseMemoryLib/IsZeroBuffer.c
 create mode 100644 MdePkg/Library/BaseMemoryLibMmx/IsZeroBuffer.c
 create mode 100644 MdePkg/Library/BaseMemoryLibOptDxe/IsZeroBuffer.c
 create mode 100644 MdePkg/Library/BaseMemoryLibOptPei/IsZeroBuffer.c
 create mode 100644 MdePkg/Library/BaseMemoryLibRepStr/IsZeroBuffer.c
 create mode 100644 MdePkg/Library/BaseMemoryLibSse2/IsZeroBuffer.c
 create mode 100644 MdePkg/Library/PeiMemoryLib/IsZeroBuffer.c
 create mode 100644 MdePkg/Library/UefiMemoryLib/IsZeroBuffer.c

diff --git a/MdePkg/Include/Library/BaseMemoryLib.h b/MdePkg/Include/Library/BaseMemoryLib.h
index 5a57dee..1338c27 100644
--- a/MdePkg/Include/Library/BaseMemoryLib.h
+++ b/MdePkg/Include/Library/BaseMemoryLib.h
@@ -463,4 +463,27 @@ IsZeroGuid (
   IN CONST GUID  *Guid
   );
 
+/**
+  Checks if the contents of a buffer are all zeros.
+
+  This function checks whether the contents of a buffer are all zeros. If the
+  contents are all zeros, return TRUE. Otherwise, return FALSE.
+
+  If Length > 0 and Buffer is NULL, then ASSERT().
+  If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
+
+  @param  Buffer      The pointer to the buffer to be checked.
+  @param  Length      The size of the buffer (in bytes) to be checked.
+
+  @retval TRUE        Contents of the buffer are all zeros.
+  @retval FALSE       Contents of the buffer are not all zeros.
+
+**/
+BOOLEAN
+EFIAPI
+IsZeroBuffer (
+  IN CONST VOID  *Buffer,
+  IN UINTN       Length
+  );
+
 #endif
diff --git a/MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf b/MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf
index 5dfab35..51b4d16 100644
--- a/MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf
+++ b/MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf
@@ -45,6 +45,7 @@
   MemLibGeneric.c
   MemLibGuid.c
   CopyMem.c
+  IsZeroBuffer.c
   MemLibInternals.h
 
 [Packages]
diff --git a/MdePkg/Library/BaseMemoryLib/IsZeroBuffer.c b/MdePkg/Library/BaseMemoryLib/IsZeroBuffer.c
new file mode 100644
index 0000000..fda0c7c
--- /dev/null
+++ b/MdePkg/Library/BaseMemoryLib/IsZeroBuffer.c
@@ -0,0 +1,65 @@
+/** @file
+  Implementation of IsZeroBuffer function.
+
+  The following BaseMemoryLib instances contain the same copy of this file:
+
+    BaseMemoryLib
+    BaseMemoryLibMmx
+    BaseMemoryLibSse2
+    BaseMemoryLibRepStr
+    BaseMemoryLibOptDxe
+    BaseMemoryLibOptPei
+    PeiMemoryLib
+    UefiMemoryLib
+
+  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 <Base.h>
+#include <Library/DebugLib.h>
+
+/**
+  Checks if the contents of a buffer are all zeros.
+
+  This function checks whether the contents of a buffer are all zeros. If the
+  contents are all zeros, return TRUE. Otherwise, return FALSE.
+
+  If Length > 0 and Buffer is NULL, then ASSERT().
+  If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
+
+  @param  Buffer      The pointer to the buffer to be checked.
+  @param  Length      The size of the buffer (in bytes) to be checked.
+
+  @retval TRUE        Contents of the buffer are all zeros.
+  @retval FALSE       Contents of the buffer are not all zeros.
+
+**/
+BOOLEAN
+EFIAPI
+IsZeroBuffer (
+  IN CONST VOID  *Buffer,
+  IN UINTN       Length
+  )
+{
+  CONST UINT8 *BufferData;
+  UINTN       Index;
+
+  ASSERT (!(Buffer == NULL && Length > 0));
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer));
+
+  BufferData = Buffer;
+  for (Index = 0; Index < Length; Index++) {
+    if (BufferData[Index] != 0) {
+      return FALSE;
+    }
+  }
+  return TRUE;
+}
diff --git a/MdePkg/Library/BaseMemoryLibMmx/BaseMemoryLibMmx.inf b/MdePkg/Library/BaseMemoryLibMmx/BaseMemoryLibMmx.inf
index a609073..59261f9 100644
--- a/MdePkg/Library/BaseMemoryLibMmx/BaseMemoryLibMmx.inf
+++ b/MdePkg/Library/BaseMemoryLibMmx/BaseMemoryLibMmx.inf
@@ -47,6 +47,7 @@
   SetMemWrapper.c
   CopyMemWrapper.c
   MemLibGuid.c
+  IsZeroBuffer.c
   MemLibInternals.h
 
 [Sources.Ia32]
diff --git a/MdePkg/Library/BaseMemoryLibMmx/IsZeroBuffer.c b/MdePkg/Library/BaseMemoryLibMmx/IsZeroBuffer.c
new file mode 100644
index 0000000..fda0c7c
--- /dev/null
+++ b/MdePkg/Library/BaseMemoryLibMmx/IsZeroBuffer.c
@@ -0,0 +1,65 @@
+/** @file
+  Implementation of IsZeroBuffer function.
+
+  The following BaseMemoryLib instances contain the same copy of this file:
+
+    BaseMemoryLib
+    BaseMemoryLibMmx
+    BaseMemoryLibSse2
+    BaseMemoryLibRepStr
+    BaseMemoryLibOptDxe
+    BaseMemoryLibOptPei
+    PeiMemoryLib
+    UefiMemoryLib
+
+  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 <Base.h>
+#include <Library/DebugLib.h>
+
+/**
+  Checks if the contents of a buffer are all zeros.
+
+  This function checks whether the contents of a buffer are all zeros. If the
+  contents are all zeros, return TRUE. Otherwise, return FALSE.
+
+  If Length > 0 and Buffer is NULL, then ASSERT().
+  If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
+
+  @param  Buffer      The pointer to the buffer to be checked.
+  @param  Length      The size of the buffer (in bytes) to be checked.
+
+  @retval TRUE        Contents of the buffer are all zeros.
+  @retval FALSE       Contents of the buffer are not all zeros.
+
+**/
+BOOLEAN
+EFIAPI
+IsZeroBuffer (
+  IN CONST VOID  *Buffer,
+  IN UINTN       Length
+  )
+{
+  CONST UINT8 *BufferData;
+  UINTN       Index;
+
+  ASSERT (!(Buffer == NULL && Length > 0));
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer));
+
+  BufferData = Buffer;
+  for (Index = 0; Index < Length; Index++) {
+    if (BufferData[Index] != 0) {
+      return FALSE;
+    }
+  }
+  return TRUE;
+}
diff --git a/MdePkg/Library/BaseMemoryLibOptDxe/BaseMemoryLibOptDxe.inf b/MdePkg/Library/BaseMemoryLibOptDxe/BaseMemoryLibOptDxe.inf
index e637034..a75270b 100644
--- a/MdePkg/Library/BaseMemoryLibOptDxe/BaseMemoryLibOptDxe.inf
+++ b/MdePkg/Library/BaseMemoryLibOptDxe/BaseMemoryLibOptDxe.inf
@@ -90,6 +90,7 @@
   SetMemWrapper.c
   CopyMemWrapper.c
   MemLibGuid.c
+  IsZeroBuffer.c
 
 [Sources.X64]
   X64/ScanMem64.nasm
@@ -137,6 +138,7 @@
   SetMemWrapper.c
   CopyMemWrapper.c
   MemLibGuid.c
+  IsZeroBuffer.c
 
 [Packages]
   MdePkg/MdePkg.dec
diff --git a/MdePkg/Library/BaseMemoryLibOptDxe/IsZeroBuffer.c b/MdePkg/Library/BaseMemoryLibOptDxe/IsZeroBuffer.c
new file mode 100644
index 0000000..fda0c7c
--- /dev/null
+++ b/MdePkg/Library/BaseMemoryLibOptDxe/IsZeroBuffer.c
@@ -0,0 +1,65 @@
+/** @file
+  Implementation of IsZeroBuffer function.
+
+  The following BaseMemoryLib instances contain the same copy of this file:
+
+    BaseMemoryLib
+    BaseMemoryLibMmx
+    BaseMemoryLibSse2
+    BaseMemoryLibRepStr
+    BaseMemoryLibOptDxe
+    BaseMemoryLibOptPei
+    PeiMemoryLib
+    UefiMemoryLib
+
+  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 <Base.h>
+#include <Library/DebugLib.h>
+
+/**
+  Checks if the contents of a buffer are all zeros.
+
+  This function checks whether the contents of a buffer are all zeros. If the
+  contents are all zeros, return TRUE. Otherwise, return FALSE.
+
+  If Length > 0 and Buffer is NULL, then ASSERT().
+  If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
+
+  @param  Buffer      The pointer to the buffer to be checked.
+  @param  Length      The size of the buffer (in bytes) to be checked.
+
+  @retval TRUE        Contents of the buffer are all zeros.
+  @retval FALSE       Contents of the buffer are not all zeros.
+
+**/
+BOOLEAN
+EFIAPI
+IsZeroBuffer (
+  IN CONST VOID  *Buffer,
+  IN UINTN       Length
+  )
+{
+  CONST UINT8 *BufferData;
+  UINTN       Index;
+
+  ASSERT (!(Buffer == NULL && Length > 0));
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer));
+
+  BufferData = Buffer;
+  for (Index = 0; Index < Length; Index++) {
+    if (BufferData[Index] != 0) {
+      return FALSE;
+    }
+  }
+  return TRUE;
+}
diff --git a/MdePkg/Library/BaseMemoryLibOptPei/BaseMemoryLibOptPei.inf b/MdePkg/Library/BaseMemoryLibOptPei/BaseMemoryLibOptPei.inf
index ff60e9e..bd915eb 100644
--- a/MdePkg/Library/BaseMemoryLibOptPei/BaseMemoryLibOptPei.inf
+++ b/MdePkg/Library/BaseMemoryLibOptPei/BaseMemoryLibOptPei.inf
@@ -90,6 +90,7 @@
   SetMemWrapper.c
   CopyMemWrapper.c
   MemLibGuid.c
+  IsZeroBuffer.c
 
 [Sources.X64]
   X64/ScanMem64.nasm
@@ -137,6 +138,7 @@
   SetMemWrapper.c
   CopyMemWrapper.c
   MemLibGuid.c
+  IsZeroBuffer.c
 
 
 [Packages]
diff --git a/MdePkg/Library/BaseMemoryLibOptPei/IsZeroBuffer.c b/MdePkg/Library/BaseMemoryLibOptPei/IsZeroBuffer.c
new file mode 100644
index 0000000..fda0c7c
--- /dev/null
+++ b/MdePkg/Library/BaseMemoryLibOptPei/IsZeroBuffer.c
@@ -0,0 +1,65 @@
+/** @file
+  Implementation of IsZeroBuffer function.
+
+  The following BaseMemoryLib instances contain the same copy of this file:
+
+    BaseMemoryLib
+    BaseMemoryLibMmx
+    BaseMemoryLibSse2
+    BaseMemoryLibRepStr
+    BaseMemoryLibOptDxe
+    BaseMemoryLibOptPei
+    PeiMemoryLib
+    UefiMemoryLib
+
+  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 <Base.h>
+#include <Library/DebugLib.h>
+
+/**
+  Checks if the contents of a buffer are all zeros.
+
+  This function checks whether the contents of a buffer are all zeros. If the
+  contents are all zeros, return TRUE. Otherwise, return FALSE.
+
+  If Length > 0 and Buffer is NULL, then ASSERT().
+  If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
+
+  @param  Buffer      The pointer to the buffer to be checked.
+  @param  Length      The size of the buffer (in bytes) to be checked.
+
+  @retval TRUE        Contents of the buffer are all zeros.
+  @retval FALSE       Contents of the buffer are not all zeros.
+
+**/
+BOOLEAN
+EFIAPI
+IsZeroBuffer (
+  IN CONST VOID  *Buffer,
+  IN UINTN       Length
+  )
+{
+  CONST UINT8 *BufferData;
+  UINTN       Index;
+
+  ASSERT (!(Buffer == NULL && Length > 0));
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer));
+
+  BufferData = Buffer;
+  for (Index = 0; Index < Length; Index++) {
+    if (BufferData[Index] != 0) {
+      return FALSE;
+    }
+  }
+  return TRUE;
+}
diff --git a/MdePkg/Library/BaseMemoryLibRepStr/BaseMemoryLibRepStr.inf b/MdePkg/Library/BaseMemoryLibRepStr/BaseMemoryLibRepStr.inf
index 9d7ce4b..aac7865 100644
--- a/MdePkg/Library/BaseMemoryLibRepStr/BaseMemoryLibRepStr.inf
+++ b/MdePkg/Library/BaseMemoryLibRepStr/BaseMemoryLibRepStr.inf
@@ -44,6 +44,7 @@
   SetMemWrapper.c
   CopyMemWrapper.c
   MemLibGuid.c
+  IsZeroBuffer.c
 
 [Sources.Ia32]
   Ia32/ScanMem64.nasm
diff --git a/MdePkg/Library/BaseMemoryLibRepStr/IsZeroBuffer.c b/MdePkg/Library/BaseMemoryLibRepStr/IsZeroBuffer.c
new file mode 100644
index 0000000..fda0c7c
--- /dev/null
+++ b/MdePkg/Library/BaseMemoryLibRepStr/IsZeroBuffer.c
@@ -0,0 +1,65 @@
+/** @file
+  Implementation of IsZeroBuffer function.
+
+  The following BaseMemoryLib instances contain the same copy of this file:
+
+    BaseMemoryLib
+    BaseMemoryLibMmx
+    BaseMemoryLibSse2
+    BaseMemoryLibRepStr
+    BaseMemoryLibOptDxe
+    BaseMemoryLibOptPei
+    PeiMemoryLib
+    UefiMemoryLib
+
+  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 <Base.h>
+#include <Library/DebugLib.h>
+
+/**
+  Checks if the contents of a buffer are all zeros.
+
+  This function checks whether the contents of a buffer are all zeros. If the
+  contents are all zeros, return TRUE. Otherwise, return FALSE.
+
+  If Length > 0 and Buffer is NULL, then ASSERT().
+  If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
+
+  @param  Buffer      The pointer to the buffer to be checked.
+  @param  Length      The size of the buffer (in bytes) to be checked.
+
+  @retval TRUE        Contents of the buffer are all zeros.
+  @retval FALSE       Contents of the buffer are not all zeros.
+
+**/
+BOOLEAN
+EFIAPI
+IsZeroBuffer (
+  IN CONST VOID  *Buffer,
+  IN UINTN       Length
+  )
+{
+  CONST UINT8 *BufferData;
+  UINTN       Index;
+
+  ASSERT (!(Buffer == NULL && Length > 0));
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer));
+
+  BufferData = Buffer;
+  for (Index = 0; Index < Length; Index++) {
+    if (BufferData[Index] != 0) {
+      return FALSE;
+    }
+  }
+  return TRUE;
+}
diff --git a/MdePkg/Library/BaseMemoryLibSse2/BaseMemoryLibSse2.inf b/MdePkg/Library/BaseMemoryLibSse2/BaseMemoryLibSse2.inf
index a78d823..2919827 100644
--- a/MdePkg/Library/BaseMemoryLibSse2/BaseMemoryLibSse2.inf
+++ b/MdePkg/Library/BaseMemoryLibSse2/BaseMemoryLibSse2.inf
@@ -43,6 +43,7 @@
   SetMemWrapper.c
   CopyMemWrapper.c
   MemLibGuid.c
+  IsZeroBuffer.c
 
 [Sources.Ia32]
   Ia32/ScanMem64.nasm
diff --git a/MdePkg/Library/BaseMemoryLibSse2/IsZeroBuffer.c b/MdePkg/Library/BaseMemoryLibSse2/IsZeroBuffer.c
new file mode 100644
index 0000000..6a3a2c1
--- /dev/null
+++ b/MdePkg/Library/BaseMemoryLibSse2/IsZeroBuffer.c
@@ -0,0 +1,65 @@
+/** @file
+  Implementation of IsZeroBuffer function.
+
+  The following BaseMemoryLib instances contain the same copy of this file:
+
+    BaseMemoryLib
+    BaseMemoryLibMmx
+    BaseMemoryLibSse2
+    BaseMemoryLibRepStr
+    BaseMemoryLibOptDxe
+    BaseMemoryLibOptPei
+    PeiMemoryLib
+    UefiMemoryLib
+
+  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 <Base.h>
+#include <Library/DebugLib.h>
+
+/**
+  Checks if the contents of a buffer are all zeros.
+
+  This function checks whether the contents of a buffer are all zeros. If the
+  contents are all zeros, return TRUE. Otherwise, return FALSE.
+
+  If Length > 0 and Buffer is NULL, then ASSERT().
+  If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
+
+  @param  Buffer      The pointer to the buffer to be checked.
+  @param  Length      The size of the buffer (in bytes) to be checked.
+
+  @retval TRUE        Contents of the buffer are all zeros.
+  @retval FALSE       Contents of the buffer are not all zeros.
+
+**/
+BOOLEAN
+EFIAPI
+IsZeroBuffer (
+  IN CONST VOID  *Buffer,
+  IN UINTN       Length
+  )
+{
+  CONST UINT8 *BufferData;
+  UINTN       Index;
+
+  ASSERT (!(Buffer == NULL && Length > 0));
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer));
+  
+  BufferData = Buffer;
+  for (Index = 0; Index < Length; Index++) {
+    if (BufferData[Index] != 0) {
+      return FALSE;
+    }
+  }
+  return TRUE;
+}
diff --git a/MdePkg/Library/PeiMemoryLib/IsZeroBuffer.c b/MdePkg/Library/PeiMemoryLib/IsZeroBuffer.c
new file mode 100644
index 0000000..fda0c7c
--- /dev/null
+++ b/MdePkg/Library/PeiMemoryLib/IsZeroBuffer.c
@@ -0,0 +1,65 @@
+/** @file
+  Implementation of IsZeroBuffer function.
+
+  The following BaseMemoryLib instances contain the same copy of this file:
+
+    BaseMemoryLib
+    BaseMemoryLibMmx
+    BaseMemoryLibSse2
+    BaseMemoryLibRepStr
+    BaseMemoryLibOptDxe
+    BaseMemoryLibOptPei
+    PeiMemoryLib
+    UefiMemoryLib
+
+  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 <Base.h>
+#include <Library/DebugLib.h>
+
+/**
+  Checks if the contents of a buffer are all zeros.
+
+  This function checks whether the contents of a buffer are all zeros. If the
+  contents are all zeros, return TRUE. Otherwise, return FALSE.
+
+  If Length > 0 and Buffer is NULL, then ASSERT().
+  If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
+
+  @param  Buffer      The pointer to the buffer to be checked.
+  @param  Length      The size of the buffer (in bytes) to be checked.
+
+  @retval TRUE        Contents of the buffer are all zeros.
+  @retval FALSE       Contents of the buffer are not all zeros.
+
+**/
+BOOLEAN
+EFIAPI
+IsZeroBuffer (
+  IN CONST VOID  *Buffer,
+  IN UINTN       Length
+  )
+{
+  CONST UINT8 *BufferData;
+  UINTN       Index;
+
+  ASSERT (!(Buffer == NULL && Length > 0));
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer));
+
+  BufferData = Buffer;
+  for (Index = 0; Index < Length; Index++) {
+    if (BufferData[Index] != 0) {
+      return FALSE;
+    }
+  }
+  return TRUE;
+}
diff --git a/MdePkg/Library/PeiMemoryLib/PeiMemoryLib.inf b/MdePkg/Library/PeiMemoryLib/PeiMemoryLib.inf
index 58af9d0..9760639 100644
--- a/MdePkg/Library/PeiMemoryLib/PeiMemoryLib.inf
+++ b/MdePkg/Library/PeiMemoryLib/PeiMemoryLib.inf
@@ -45,6 +45,7 @@
   MemLibGeneric.c
   MemLibGuid.c
   MemLib.c
+  IsZeroBuffer.c
   MemLibInternals.h
 
 
diff --git a/MdePkg/Library/UefiMemoryLib/IsZeroBuffer.c b/MdePkg/Library/UefiMemoryLib/IsZeroBuffer.c
new file mode 100644
index 0000000..fda0c7c
--- /dev/null
+++ b/MdePkg/Library/UefiMemoryLib/IsZeroBuffer.c
@@ -0,0 +1,65 @@
+/** @file
+  Implementation of IsZeroBuffer function.
+
+  The following BaseMemoryLib instances contain the same copy of this file:
+
+    BaseMemoryLib
+    BaseMemoryLibMmx
+    BaseMemoryLibSse2
+    BaseMemoryLibRepStr
+    BaseMemoryLibOptDxe
+    BaseMemoryLibOptPei
+    PeiMemoryLib
+    UefiMemoryLib
+
+  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 <Base.h>
+#include <Library/DebugLib.h>
+
+/**
+  Checks if the contents of a buffer are all zeros.
+
+  This function checks whether the contents of a buffer are all zeros. If the
+  contents are all zeros, return TRUE. Otherwise, return FALSE.
+
+  If Length > 0 and Buffer is NULL, then ASSERT().
+  If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
+
+  @param  Buffer      The pointer to the buffer to be checked.
+  @param  Length      The size of the buffer (in bytes) to be checked.
+
+  @retval TRUE        Contents of the buffer are all zeros.
+  @retval FALSE       Contents of the buffer are not all zeros.
+
+**/
+BOOLEAN
+EFIAPI
+IsZeroBuffer (
+  IN CONST VOID  *Buffer,
+  IN UINTN       Length
+  )
+{
+  CONST UINT8 *BufferData;
+  UINTN       Index;
+
+  ASSERT (!(Buffer == NULL && Length > 0));
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer));
+
+  BufferData = Buffer;
+  for (Index = 0; Index < Length; Index++) {
+    if (BufferData[Index] != 0) {
+      return FALSE;
+    }
+  }
+  return TRUE;
+}
diff --git a/MdePkg/Library/UefiMemoryLib/UefiMemoryLib.inf b/MdePkg/Library/UefiMemoryLib/UefiMemoryLib.inf
index e82732f..2ea7875 100644
--- a/MdePkg/Library/UefiMemoryLib/UefiMemoryLib.inf
+++ b/MdePkg/Library/UefiMemoryLib/UefiMemoryLib.inf
@@ -45,6 +45,7 @@
   MemLibGeneric.c
   MemLibGuid.c
   MemLib.c
+  IsZeroBuffer.c
   MemLibInternals.h
 
 
-- 
1.9.5.msysgit.0



  parent reply	other threads:[~2016-08-04  1:24 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-04  1:24 [PATCH 0/3] Add APIs IsZeroBuffer and IsZeroGuid in BaseMemoryLib Hao Wu
2016-08-04  1:24 ` [PATCH 1/3] MdePkg BaseMemoryLib: Add implementation of API IsZeroGuid() Hao Wu
2016-08-04  1:24 ` Hao Wu [this message]
2016-08-04  1:24 ` [PATCH 3/3] SecurityPkg Tcg2: Remove internal implementation of IsZeroBuffer() Hao Wu
2016-08-04 13:28   ` Zhang, Chao B
2016-08-04  8:07 ` [PATCH 0/3] Add APIs IsZeroBuffer and IsZeroGuid in BaseMemoryLib Laszlo Ersek
2016-08-04  8:44   ` Wu, Hao A

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=1470273870-14376-3-git-send-email-hao.a.wu@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