X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=MdePkg%2FLibrary%2FPeiMemoryLib%2FMemLibGeneric.c;h=ed18b5758283f59bfcc2395669fc740899080fbb;hb=32eb6739b961a5b4cc204b94220fa5ad15f79a9b;hp=ef7874877d238dc1f00020c92bb967ffb60b872e;hpb=19388d2960b2fe0347da23799e93ccc52f540214;p=mirror_edk2.git diff --git a/MdePkg/Library/PeiMemoryLib/MemLibGeneric.c b/MdePkg/Library/PeiMemoryLib/MemLibGeneric.c index ef7874877d..ed18b57582 100644 --- a/MdePkg/Library/PeiMemoryLib/MemLibGeneric.c +++ b/MdePkg/Library/PeiMemoryLib/MemLibGeneric.c @@ -6,11 +6,11 @@ PeiMemoryLib UefiMemoryLib - Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.
+ Copyright (c) 2006 - 2016, 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 + 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. @@ -22,11 +22,11 @@ /** 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 + @return Buffer. **/ VOID * @@ -37,20 +37,20 @@ 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 + @return Buffer. **/ VOID * @@ -61,20 +61,20 @@ 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 + @return Buffer. **/ VOID * @@ -85,19 +85,19 @@ InternalMemSetMem64 ( IN UINT64 Value ) { - do { - ((UINT64*)Buffer)[--Length] = Value; - } while (Length != 0); + for (; Length != 0; Length--) { + ((UINT64*)Buffer)[Length - 1] = Value; + } return Buffer; } /** Set Buffer to 0 for Size bytes. - @param Buffer Memory to set. - @param Length Number of bytes to set + @param Buffer The memory to set. + @param Length The number of bytes to set - @return Buffer + @return Buffer. **/ VOID * @@ -113,9 +113,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 +143,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 +163,7 @@ InternalMemScanMem8 ( Pointer = (CONST UINT8*)Buffer; do { if (*(Pointer++) == Value) { - return Pointer; + return --Pointer; } } while (--Length != 0); return NULL; @@ -173,11 +173,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 +193,7 @@ InternalMemScanMem16 ( Pointer = (CONST UINT16*)Buffer; do { if (*(Pointer++) == Value) { - return Pointer; + return --Pointer; } } while (--Length != 0); return NULL; @@ -203,11 +203,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 +223,7 @@ InternalMemScanMem32 ( Pointer = (CONST UINT32*)Buffer; do { if (*(Pointer++) == Value) { - return Pointer; + return --Pointer; } } while (--Length != 0); return NULL; @@ -233,11 +233,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 +253,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; +}