X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=MdePkg%2FLibrary%2FUefiMemoryLib%2FMemLibGeneric.c;h=73ef0d92d1ca12426b4d694950c5ed1b26b56b53;hb=9344f0921518309295da89c221d10cbead8531aa;hp=e9e0f171ba0e9188ee2aee2069939c8a20716fe9;hpb=1fef058f4b8fefc455bb171e4908c3e835b1b492;p=mirror_edk2.git
diff --git a/MdePkg/Library/UefiMemoryLib/MemLibGeneric.c b/MdePkg/Library/UefiMemoryLib/MemLibGeneric.c
index e9e0f171ba..73ef0d92d1 100644
--- a/MdePkg/Library/UefiMemoryLib/MemLibGeneric.c
+++ b/MdePkg/Library/UefiMemoryLib/MemLibGeneric.c
@@ -6,14 +6,8 @@
PeiMemoryLib
UefiMemoryLib
- Copyright (c) 2006 - 2009, Intel Corporation
- All rights reserved. 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.
+ Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent
**/
@@ -22,9 +16,9 @@
/**
Fills a target buffer with a 16-bit value, and returns the target buffer.
- @param Buffer Pointer to the target buffer to fill.
- @param Length Count of 16-bit value to fill.
- @param Value Value with which to fill Length bytes of Buffer.
+ @param Buffer The pointer to the target buffer to fill.
+ @param Length The count of 16-bit value to fill.
+ @param Value The value with which to fill Length bytes of Buffer.
@return Buffer
@@ -37,18 +31,18 @@ InternalMemSetMem16 (
IN UINT16 Value
)
{
- do {
- ((UINT16*)Buffer)[--Length] = Value;
- } while (Length != 0);
+ for (; Length != 0; Length--) {
+ ((UINT16*)Buffer)[Length - 1] = Value;
+ }
return Buffer;
}
/**
Fills a target buffer with a 32-bit value, and returns the target buffer.
- @param Buffer Pointer to the target buffer to fill.
- @param Length Count of 32-bit value to fill.
- @param Value Value with which to fill Length bytes of Buffer.
+ @param Buffer The pointer to the target buffer to fill.
+ @param Length The count of 32-bit value to fill.
+ @param Value The value with which to fill Length bytes of Buffer.
@return Buffer
@@ -61,18 +55,18 @@ InternalMemSetMem32 (
IN UINT32 Value
)
{
- do {
- ((UINT32*)Buffer)[--Length] = Value;
- } while (Length != 0);
+ for (; Length != 0; Length--) {
+ ((UINT32*)Buffer)[Length - 1] = Value;
+ }
return Buffer;
}
/**
Fills a target buffer with a 64-bit value, and returns the target buffer.
- @param Buffer Pointer to the target buffer to fill.
- @param Length Count of 64-bit value to fill.
- @param Value Value with which to fill Length bytes of Buffer.
+ @param Buffer The pointer to the target buffer to fill.
+ @param Length The count of 64-bit value to fill.
+ @param Value The value with which to fill Length bytes of Buffer.
@return Buffer
@@ -85,9 +79,9 @@ InternalMemSetMem64 (
IN UINT64 Value
)
{
- do {
- ((UINT64*)Buffer)[--Length] = Value;
- } while (Length != 0);
+ for (; Length != 0; Length--) {
+ ((UINT64*)Buffer)[Length - 1] = Value;
+ }
return Buffer;
}
@@ -95,7 +89,7 @@ InternalMemSetMem64 (
Set Buffer to 0 for Size bytes.
@param Buffer Memory to set.
- @param Length Number of bytes to set
+ @param Length The number of bytes to set
@return Buffer
@@ -113,9 +107,9 @@ InternalMemZeroMem (
/**
Compares two memory buffers of a given length.
- @param DestinationBuffer First memory buffer
- @param SourceBuffer Second memory buffer
- @param Length Length of DestinationBuffer and SourceBuffer memory
+ @param DestinationBuffer The first memory buffer
+ @param SourceBuffer The second memory buffer
+ @param Length The length of DestinationBuffer and SourceBuffer memory
regions to compare. Must be non-zero.
@return 0 All Length bytes of the two buffers are identical.
@@ -143,11 +137,11 @@ InternalMemCompareMem (
Scans a target buffer for an 8-bit value, and returns a pointer to the
matching 8-bit value in the target buffer.
- @param Buffer Pointer to the target buffer to scan.
- @param Length Count of 8-bit value to scan. Must be non-zero.
- @param Value Value to search for in the target buffer.
+ @param Buffer The pointer to the target buffer to scan.
+ @param Length The count of 8-bit value to scan. Must be non-zero.
+ @param Value The value to search for in the target buffer.
- @return Pointer to the first occurrence or NULL if not found.
+ @return The pointer to the first occurrence or NULL if not found.
**/
CONST VOID *
@@ -163,7 +157,7 @@ InternalMemScanMem8 (
Pointer = (CONST UINT8*)Buffer;
do {
if (*(Pointer++) == Value) {
- return Pointer;
+ return --Pointer;
}
} while (--Length != 0);
return NULL;
@@ -173,11 +167,11 @@ InternalMemScanMem8 (
Scans a target buffer for a 16-bit value, and returns a pointer to the
matching 16-bit value in the target buffer.
- @param Buffer Pointer to the target buffer to scan.
- @param Length Count of 16-bit value to scan. Must be non-zero.
- @param Value Value to search for in the target buffer.
+ @param Buffer The pointer to the target buffer to scan.
+ @param Length The count of 16-bit value to scan. Must be non-zero.
+ @param Value The value to search for in the target buffer.
- @return Pointer to the first occurrence or NULL if not found.
+ @return The pointer to the first occurrence or NULL if not found.
**/
CONST VOID *
@@ -193,7 +187,7 @@ InternalMemScanMem16 (
Pointer = (CONST UINT16*)Buffer;
do {
if (*(Pointer++) == Value) {
- return Pointer;
+ return --Pointer;
}
} while (--Length != 0);
return NULL;
@@ -203,11 +197,11 @@ InternalMemScanMem16 (
Scans a target buffer for a 32-bit value, and returns a pointer to the
matching 32-bit value in the target buffer.
- @param Buffer Pointer to the target buffer to scan.
- @param Length Count of 32-bit value to scan. Must be non-zero.
- @param Value Value to search for in the target buffer.
+ @param Buffer The pointer to the target buffer to scan.
+ @param Length The count of 32-bit value to scan. Must be non-zero.
+ @param Value The value to search for in the target buffer.
- @return Pointer to the first occurrence or NULL if not found.
+ @return The pointer to the first occurrence or NULL if not found.
**/
CONST VOID *
@@ -223,7 +217,7 @@ InternalMemScanMem32 (
Pointer = (CONST UINT32*)Buffer;
do {
if (*(Pointer++) == Value) {
- return Pointer;
+ return --Pointer;
}
} while (--Length != 0);
return NULL;
@@ -233,11 +227,11 @@ InternalMemScanMem32 (
Scans a target buffer for a 64-bit value, and returns a pointer to the
matching 64-bit value in the target buffer.
- @param Buffer Pointer to the target buffer to scan.
- @param Length Count of 64-bit value to scan. Must be non-zero.
- @param Value Value to search for in the target buffer.
+ @param Buffer The pointer to the target buffer to scan.
+ @param Length The count of 64-bit value to scan. Must be non-zero.
+ @param Value The value to search for in the target buffer.
- @return Pointer to the first occurrence or NULL if not found.
+ @return The pointer to the first occurrence or NULL if not found.
**/
CONST VOID *
@@ -253,8 +247,37 @@ InternalMemScanMem64 (
Pointer = (CONST UINT64*)Buffer;
do {
if (*(Pointer++) == Value) {
- return Pointer;
+ return --Pointer;
}
} while (--Length != 0);
return NULL;
}
+
+/**
+ Checks whether the contents of a buffer are all zeros.
+
+ @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
+InternalMemIsZeroBuffer (
+ IN CONST VOID *Buffer,
+ IN UINTN Length
+ )
+{
+ CONST UINT8 *BufferData;
+ UINTN Index;
+
+ BufferData = Buffer;
+ for (Index = 0; Index < Length; Index++) {
+ if (BufferData[Index] != 0) {
+ return FALSE;
+ }
+ }
+ return TRUE;
+}