X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=MdePkg%2FLibrary%2FUefiMemoryLib%2FMemLibGeneric.c;h=f1efdbb413d1dc10971b039e5488f952c586c1bc;hb=41bfaffd13094d9042110091e6c37adf20c4032c;hp=ef9f358a7950b5eef35877b349b822d3dd5355bf;hpb=878ddf1fc3540a715f63594ed22b6929e881afb4;p=mirror_edk2.git diff --git a/MdePkg/Library/UefiMemoryLib/MemLibGeneric.c b/MdePkg/Library/UefiMemoryLib/MemLibGeneric.c index ef9f358a79..f1efdbb413 100644 --- a/MdePkg/Library/UefiMemoryLib/MemLibGeneric.c +++ b/MdePkg/Library/UefiMemoryLib/MemLibGeneric.c @@ -1,49 +1,30 @@ /** @file Architecture Independent Base Memory Library Implementation. - Copyright (c) 2006, Intel Corporation
- All rights reserved. This program and the accompanying materials + The following BaseMemoryLib instances contain the same copy of this file: + BaseMemoryLib + PeiMemoryLib + UefiMemoryLib + + 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. - Module Name: MemLibGeneric.c - - The following BaseMemoryLib instances share the same version of this file: - - BaseMemoryLib - PeiMemoryLib - UefiMemoryLib - **/ -/** - Set Buffer to Value for Size bytes. - - @param Buffer Memory to set. - @param Size Number of bytes to set - @param Value Value of the set operation. - - @return Buffer - -**/ -VOID * -EFIAPI -InternalMemSetMem ( - OUT VOID *Buffer, - IN UINTN Length, - IN UINT8 Value - ); +#include "MemLibInternals.h" /** 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 Number of bytes in Buffer 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 @@ -56,18 +37,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 Number of bytes in Buffer 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 @@ -80,18 +61,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 Number of bytes in Buffer 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 @@ -104,9 +85,9 @@ InternalMemSetMem64 ( IN UINT64 Value ) { - do { - ((UINT64*)Buffer)[--Length] = Value; - } while (Length != 0); + for (; Length != 0; Length--) { + ((UINT64*)Buffer)[Length - 1] = Value; + } return Buffer; } @@ -114,7 +95,7 @@ InternalMemSetMem64 ( Set Buffer to 0 for Size bytes. @param Buffer Memory to set. - @param Size Number of bytes to set + @param Length The number of bytes to set @return Buffer @@ -132,12 +113,14 @@ 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. - @retval 0 if MemOne == MemTwo + @return 0 All Length bytes of the two buffers are identical. + @retval Non-zero The first mismatched byte in SourceBuffer subtracted from the first + mismatched byte in DestinationBuffer. **/ INTN @@ -148,7 +131,6 @@ InternalMemCompareMem ( IN UINTN Length ) { - ASSERT (Length > 0); while ((--Length != 0) && (*(INT8*)DestinationBuffer == *(INT8*)SourceBuffer)) { DestinationBuffer = (INT8*)DestinationBuffer + 1; @@ -161,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 Number of bytes in Buffer 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 * @@ -178,11 +160,10 @@ InternalMemScanMem8 ( { CONST UINT8 *Pointer; - ASSERT (Length > 0); Pointer = (CONST UINT8*)Buffer; do { if (*(Pointer++) == Value) { - return Pointer; + return --Pointer; } } while (--Length != 0); return NULL; @@ -192,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 Number of bytes in Buffer 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 * @@ -209,11 +190,10 @@ InternalMemScanMem16 ( { CONST UINT16 *Pointer; - ASSERT (Length > 0); Pointer = (CONST UINT16*)Buffer; do { if (*(Pointer++) == Value) { - return Pointer; + return --Pointer; } } while (--Length != 0); return NULL; @@ -223,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 Number of bytes in Buffer 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 * @@ -240,11 +220,10 @@ InternalMemScanMem32 ( { CONST UINT32 *Pointer; - ASSERT (Length > 0); Pointer = (CONST UINT32*)Buffer; do { if (*(Pointer++) == Value) { - return Pointer; + return --Pointer; } } while (--Length != 0); return NULL; @@ -254,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 Number of bytes in Buffer 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 * @@ -271,12 +250,40 @@ InternalMemScanMem64 ( { CONST UINT64 *Pointer; - ASSERT (Length > 0); 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; +}