]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdePkg BaseMemoryLib: Add C implementation of API IsZeroBuffer()
authorHao Wu <hao.a.wu@intel.com>
Wed, 17 Aug 2016 06:24:04 +0000 (14:24 +0800)
committerHao Wu <hao.a.wu@intel.com>
Mon, 22 Aug 2016 10:54:30 +0000 (18:54 +0800)
Add the implementation of API IsZeroBuffer() via C language for the
following library instances:
BaseMemoryLib
PeiMemoryLib
UefiMemoryLib

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>
Reviewed-by: Liming Gao <liming.gao@intel.com>
13 files changed:
MdePkg/Include/Library/BaseMemoryLib.h
MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf
MdePkg/Library/BaseMemoryLib/IsZeroBufferWrapper.c [new file with mode: 0644]
MdePkg/Library/BaseMemoryLib/MemLibGeneric.c
MdePkg/Library/BaseMemoryLib/MemLibInternals.h
MdePkg/Library/PeiMemoryLib/IsZeroBufferWrapper.c [new file with mode: 0644]
MdePkg/Library/PeiMemoryLib/MemLibGeneric.c
MdePkg/Library/PeiMemoryLib/MemLibInternals.h
MdePkg/Library/PeiMemoryLib/PeiMemoryLib.inf
MdePkg/Library/UefiMemoryLib/IsZeroBufferWrapper.c [new file with mode: 0644]
MdePkg/Library/UefiMemoryLib/MemLibGeneric.c
MdePkg/Library/UefiMemoryLib/MemLibInternals.h
MdePkg/Library/UefiMemoryLib/UefiMemoryLib.inf

index ed7fa00d499b63c49a674344ff2fb005f68009c2..0e565c15427ada29f788cb8c88b3826e55a98783 100644 (file)
@@ -463,4 +463,27 @@ IsZeroGuid (
   IN CONST GUID  *Guid\r
   );\r
 \r
+/**\r
+  Checks if the contents of a buffer are all zeros.\r
+\r
+  This function checks whether the contents of a buffer are all zeros. If the\r
+  contents are all zeros, return TRUE. Otherwise, return FALSE.\r
+\r
+  If Length > 0 and Buffer is NULL, then ASSERT().\r
+  If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
+\r
+  @param  Buffer      The pointer to the buffer to be checked.\r
+  @param  Length      The size of the buffer (in bytes) to be checked.\r
+\r
+  @retval TRUE        Contents of the buffer are all zeros.\r
+  @retval FALSE       Contents of the buffer are not all zeros.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+IsZeroBuffer (\r
+  IN CONST VOID  *Buffer,\r
+  IN UINTN       Length\r
+  );\r
+\r
 #endif\r
index 5dfab35968fe994db649993f81f1ea25960b7852..6d906e93faf32adeff38157556f8f57b52b2274c 100644 (file)
@@ -3,7 +3,7 @@
 #\r
 #  Base Memory Library implementation - no ASM.\r
 #\r
-#  Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>\r
+#  Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>\r
 #\r
 #  This program and the accompanying materials\r
 #  are licensed and made available under the terms and conditions of the BSD License\r
@@ -42,6 +42,7 @@
   SetMem16Wrapper.c\r
   SetMemWrapper.c\r
   CopyMemWrapper.c\r
+  IsZeroBufferWrapper.c\r
   MemLibGeneric.c\r
   MemLibGuid.c\r
   CopyMem.c\r
diff --git a/MdePkg/Library/BaseMemoryLib/IsZeroBufferWrapper.c b/MdePkg/Library/BaseMemoryLib/IsZeroBufferWrapper.c
new file mode 100644 (file)
index 0000000..c42c1aa
--- /dev/null
@@ -0,0 +1,54 @@
+/** @file\r
+  Implementation of IsZeroBuffer function.\r
+\r
+  The following BaseMemoryLib instances contain the same copy of this file:\r
+\r
+    BaseMemoryLib\r
+    BaseMemoryLibMmx\r
+    BaseMemoryLibSse2\r
+    BaseMemoryLibRepStr\r
+    BaseMemoryLibOptDxe\r
+    BaseMemoryLibOptPei\r
+    PeiMemoryLib\r
+    UefiMemoryLib\r
+\r
+  Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include "MemLibInternals.h"\r
+\r
+/**\r
+  Checks if the contents of a buffer are all zeros.\r
+\r
+  This function checks whether the contents of a buffer are all zeros. If the\r
+  contents are all zeros, return TRUE. Otherwise, return FALSE.\r
+\r
+  If Length > 0 and Buffer is NULL, then ASSERT().\r
+  If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
+\r
+  @param  Buffer      The pointer to the buffer to be checked.\r
+  @param  Length      The size of the buffer (in bytes) to be checked.\r
+\r
+  @retval TRUE        Contents of the buffer are all zeros.\r
+  @retval FALSE       Contents of the buffer are not all zeros.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+IsZeroBuffer (\r
+  IN CONST VOID  *Buffer,\r
+  IN UINTN       Length\r
+  )\r
+{\r
+  ASSERT (!(Buffer == NULL && Length > 0));\r
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer));\r
+  return InternalMemIsZeroBuffer (Buffer, Length);\r
+}\r
index a977c4aadc497667f955f97914572791c9ef909d..b058be8f7112007a21e1b2e3e07a1c9ee3f5815e 100644 (file)
@@ -6,7 +6,7 @@
     PeiMemoryLib\r
     UefiMemoryLib\r
 \r
-  Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
@@ -262,3 +262,32 @@ InternalMemScanMem64 (
   } while (--Length != 0);\r
   return NULL;\r
 }\r
+\r
+/**\r
+  Checks whether the contents of a buffer are all zeros.\r
+\r
+  @param  Buffer  The pointer to the buffer to be checked.\r
+  @param  Length  The size of the buffer (in bytes) to be checked.\r
+\r
+  @retval TRUE    Contents of the buffer are all zeros.\r
+  @retval FALSE   Contents of the buffer are not all zeros.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+InternalMemIsZeroBuffer (\r
+  IN CONST VOID  *Buffer,\r
+  IN UINTN       Length\r
+  )\r
+{\r
+  CONST UINT8 *BufferData;\r
+  UINTN       Index;\r
+\r
+  BufferData = Buffer;\r
+  for (Index = 0; Index < Length; Index++) {\r
+    if (BufferData[Index] != 0) {\r
+      return FALSE;\r
+    }\r
+  }\r
+  return TRUE;\r
+}\r
index 6f7583937f889413664642859ff87350d1888d68..7d8ecbe357582729aefb59aaaf23adc3cd8c3b17 100644 (file)
@@ -9,7 +9,7 @@
     BaseMemoryLibOptDxe\r
     BaseMemoryLibOptPei\r
 \r
-  Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
@@ -231,4 +231,21 @@ InternalMemScanMem64 (
   IN      UINT64                    Value\r
   );\r
 \r
+/**\r
+  Checks whether the contents of a buffer are all zeros.\r
+\r
+  @param  Buffer  The pointer to the buffer to be checked.\r
+  @param  Length  The size of the buffer (in bytes) to be checked.\r
+\r
+  @retval TRUE    Contents of the buffer are all zeros.\r
+  @retval FALSE   Contents of the buffer are not all zeros.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+InternalMemIsZeroBuffer (\r
+  IN CONST VOID  *Buffer,\r
+  IN UINTN       Length\r
+  );\r
+\r
 #endif\r
diff --git a/MdePkg/Library/PeiMemoryLib/IsZeroBufferWrapper.c b/MdePkg/Library/PeiMemoryLib/IsZeroBufferWrapper.c
new file mode 100644 (file)
index 0000000..c42c1aa
--- /dev/null
@@ -0,0 +1,54 @@
+/** @file\r
+  Implementation of IsZeroBuffer function.\r
+\r
+  The following BaseMemoryLib instances contain the same copy of this file:\r
+\r
+    BaseMemoryLib\r
+    BaseMemoryLibMmx\r
+    BaseMemoryLibSse2\r
+    BaseMemoryLibRepStr\r
+    BaseMemoryLibOptDxe\r
+    BaseMemoryLibOptPei\r
+    PeiMemoryLib\r
+    UefiMemoryLib\r
+\r
+  Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include "MemLibInternals.h"\r
+\r
+/**\r
+  Checks if the contents of a buffer are all zeros.\r
+\r
+  This function checks whether the contents of a buffer are all zeros. If the\r
+  contents are all zeros, return TRUE. Otherwise, return FALSE.\r
+\r
+  If Length > 0 and Buffer is NULL, then ASSERT().\r
+  If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
+\r
+  @param  Buffer      The pointer to the buffer to be checked.\r
+  @param  Length      The size of the buffer (in bytes) to be checked.\r
+\r
+  @retval TRUE        Contents of the buffer are all zeros.\r
+  @retval FALSE       Contents of the buffer are not all zeros.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+IsZeroBuffer (\r
+  IN CONST VOID  *Buffer,\r
+  IN UINTN       Length\r
+  )\r
+{\r
+  ASSERT (!(Buffer == NULL && Length > 0));\r
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer));\r
+  return InternalMemIsZeroBuffer (Buffer, Length);\r
+}\r
index 53f1cafa42adcddc101c11d7600ac56305703dd7..490b244097fc2dacbf56baae3d0b08f1cc15dc80 100644 (file)
@@ -6,7 +6,7 @@
     PeiMemoryLib\r
     UefiMemoryLib\r
 \r
-  Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
@@ -258,3 +258,32 @@ InternalMemScanMem64 (
   } while (--Length != 0);\r
   return NULL;\r
 }\r
+\r
+/**\r
+  Checks whether the contents of a buffer are all zeros.\r
+\r
+  @param  Buffer  The pointer to the buffer to be checked.\r
+  @param  Length  The size of the buffer (in bytes) to be checked.\r
+\r
+  @retval TRUE    Contents of the buffer are all zeros.\r
+  @retval FALSE   Contents of the buffer are not all zeros.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+InternalMemIsZeroBuffer (\r
+  IN CONST VOID  *Buffer,\r
+  IN UINTN       Length\r
+  )\r
+{\r
+  CONST UINT8 *BufferData;\r
+  UINTN       Index;\r
+\r
+  BufferData = Buffer;\r
+  for (Index = 0; Index < Length; Index++) {\r
+    if (BufferData[Index] != 0) {\r
+      return FALSE;\r
+    }\r
+  }\r
+  return TRUE;\r
+}\r
index 8a1e1dff904b6e1efb7b16cea73fd2c0153b8fe2..85b42922e330853e35bf56554173d13cd81a0486 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Declaration of internal functions for Base Memory Library.\r
 \r
-  Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
@@ -229,4 +229,21 @@ InternalMemScanMem64 (
   IN      UINT64                    Value\r
   );\r
 \r
+/**\r
+  Checks whether the contents of a buffer are all zeros.\r
+\r
+  @param  Buffer  The pointer to the buffer to be checked.\r
+  @param  Length  The size of the buffer (in bytes) to be checked.\r
+\r
+  @retval TRUE    Contents of the buffer are all zeros.\r
+  @retval FALSE   Contents of the buffer are not all zeros.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+InternalMemIsZeroBuffer (\r
+  IN CONST VOID  *Buffer,\r
+  IN UINTN       Length\r
+  );\r
+\r
 #endif\r
index 58af9d05af3bea93ff011427f6f89c733e353af8..56d584dad63625fbb272401c01c505c19ca2bf0a 100644 (file)
@@ -4,7 +4,7 @@
 # Base Memory Library implementation that uses PEI Services\r
 #  where possible for size reduction.\r
 #\r
-# Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>\r
 #\r
 #  This program and the accompanying materials\r
 #  are licensed and made available under the terms and conditions of the BSD License\r
@@ -42,6 +42,7 @@
   SetMem16Wrapper.c\r
   SetMemWrapper.c\r
   CopyMemWrapper.c\r
+  IsZeroBufferWrapper.c\r
   MemLibGeneric.c\r
   MemLibGuid.c\r
   MemLib.c\r
diff --git a/MdePkg/Library/UefiMemoryLib/IsZeroBufferWrapper.c b/MdePkg/Library/UefiMemoryLib/IsZeroBufferWrapper.c
new file mode 100644 (file)
index 0000000..c42c1aa
--- /dev/null
@@ -0,0 +1,54 @@
+/** @file\r
+  Implementation of IsZeroBuffer function.\r
+\r
+  The following BaseMemoryLib instances contain the same copy of this file:\r
+\r
+    BaseMemoryLib\r
+    BaseMemoryLibMmx\r
+    BaseMemoryLibSse2\r
+    BaseMemoryLibRepStr\r
+    BaseMemoryLibOptDxe\r
+    BaseMemoryLibOptPei\r
+    PeiMemoryLib\r
+    UefiMemoryLib\r
+\r
+  Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include "MemLibInternals.h"\r
+\r
+/**\r
+  Checks if the contents of a buffer are all zeros.\r
+\r
+  This function checks whether the contents of a buffer are all zeros. If the\r
+  contents are all zeros, return TRUE. Otherwise, return FALSE.\r
+\r
+  If Length > 0 and Buffer is NULL, then ASSERT().\r
+  If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().\r
+\r
+  @param  Buffer      The pointer to the buffer to be checked.\r
+  @param  Length      The size of the buffer (in bytes) to be checked.\r
+\r
+  @retval TRUE        Contents of the buffer are all zeros.\r
+  @retval FALSE       Contents of the buffer are not all zeros.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+IsZeroBuffer (\r
+  IN CONST VOID  *Buffer,\r
+  IN UINTN       Length\r
+  )\r
+{\r
+  ASSERT (!(Buffer == NULL && Length > 0));\r
+  ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer));\r
+  return InternalMemIsZeroBuffer (Buffer, Length);\r
+}\r
index 1ec8bf6bad402e56d5f40a6e4d60699cc8aa199e..da02b6c52f28b5ab9851ae5a72df3741b1a306a4 100644 (file)
@@ -6,7 +6,7 @@
     PeiMemoryLib\r
     UefiMemoryLib\r
 \r
-  Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
@@ -258,3 +258,32 @@ InternalMemScanMem64 (
   } while (--Length != 0);\r
   return NULL;\r
 }\r
+\r
+/**\r
+  Checks whether the contents of a buffer are all zeros.\r
+\r
+  @param  Buffer  The pointer to the buffer to be checked.\r
+  @param  Length  The size of the buffer (in bytes) to be checked.\r
+\r
+  @retval TRUE    Contents of the buffer are all zeros.\r
+  @retval FALSE   Contents of the buffer are not all zeros.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+InternalMemIsZeroBuffer (\r
+  IN CONST VOID  *Buffer,\r
+  IN UINTN       Length\r
+  )\r
+{\r
+  CONST UINT8 *BufferData;\r
+  UINTN       Index;\r
+\r
+  BufferData = Buffer;\r
+  for (Index = 0; Index < Length; Index++) {\r
+    if (BufferData[Index] != 0) {\r
+      return FALSE;\r
+    }\r
+  }\r
+  return TRUE;\r
+}\r
index 0443b508bb3bad8967d337df9fe35314e2cb10d1..cafbb4dd3035a619219e9d57a20c4485149b56ac 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Declaration of internal functions for Base Memory Library.\r
 \r
-  Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
@@ -229,4 +229,21 @@ InternalMemScanMem64 (
   IN      UINT64                    Value\r
   );\r
 \r
+/**\r
+  Checks whether the contents of a buffer are all zeros.\r
+\r
+  @param  Buffer  The pointer to the buffer to be checked.\r
+  @param  Length  The size of the buffer (in bytes) to be checked.\r
+\r
+  @retval TRUE    Contents of the buffer are all zeros.\r
+  @retval FALSE   Contents of the buffer are not all zeros.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+InternalMemIsZeroBuffer (\r
+  IN CONST VOID  *Buffer,\r
+  IN UINTN       Length\r
+  );\r
+\r
 #endif\r
index e82732f8b075284e1642c1dbef04d79125c03580..7382204f63d7dbde4fbcfae51a13f3838f2dbf7d 100644 (file)
@@ -4,7 +4,7 @@
 # Base Memory Library implementation that uses EFI Boot Services\r
 #  where possible for size reduction.\r
 #\r
-# Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>\r
 #\r
 #  This program and the accompanying materials\r
 #  are licensed and made available under the terms and conditions of the BSD License\r
@@ -42,6 +42,7 @@
   SetMem16Wrapper.c\r
   SetMemWrapper.c\r
   CopyMemWrapper.c\r
+  IsZeroBufferWrapper.c\r
   MemLibGeneric.c\r
   MemLibGuid.c\r
   MemLib.c\r