From 4ba61e5e2a1b3cec7faaad36c252738f6f57f8a6 Mon Sep 17 00:00:00 2001 From: qhuang8 Date: Thu, 22 Jun 2006 06:08:00 +0000 Subject: =?UTF-8?q?1.=20UINTN=20&=20INTN=20issue=20for=20EBC=20architectur?= =?UTF-8?q?e:=20=09The=20MAX=5FBIT=20of=20EBC=20will=20no=20longer=20be=20?= =?UTF-8?q?fixed=20to=20bit=2063.=20It=20is=20defined=20as=20(1ULL=20<<=20?= =?UTF-8?q?(sizeof=20(INTN)=20*=208=20-=201)).=20=09Make=20EdkModulePkg=20?= =?UTF-8?q?&=20MdePkg=20EBC=20compiler=20clean:=20treat=20all=20EFI=5FSTAT?= =?UTF-8?q?US=20error=20code=20as=20variable.=202.=20PrintLib=20=09Complet?= =?UTF-8?q?e=20all=20missing=20ASSERT()s.=20=09Fix=20=E2=80=9C\n=E2=80=9D?= =?UTF-8?q?=20&=20=E2=80=9C%\n=E2=80=9D=20issue=20thanks=20to=20the=20clar?= =?UTF-8?q?ification=20of=20MWG=200.56d.=20=09Adjust=20StatusString=20arra?= =?UTF-8?q?y=20to=20support=20EBC=20build.=203.=20BaseMemoryLib=20=09Adjus?= =?UTF-8?q?t=20ASSERT=20()=20&=20function=20header=20of=20ComparaMem,=20Se?= =?UTF-8?q?tMemXX,=20ScanMemXX=20to=20synchronize=20with=20MWG=200.56d.=20?= =?UTF-8?q?4.SmbusLib=20=09Change=20Pec=20bit=20to=20bit=2022=20SmBusAddre?= =?UTF-8?q?ss=20to=20synchronize=20MWG=200.56d.=20=09Add=20ASSERT()s=20to?= =?UTF-8?q?=20check=20if=20length=20is=20illegal=20for=20SmBusBlockWrite()?= =?UTF-8?q?=20&=20SmBusProcessBlock()=20since=20it=20is=206=20bit=20now.?= =?UTF-8?q?=205.=20PerformanceLib=20=09Rename=20=E2=80=9CEdkDxePerformance?= =?UTF-8?q?Lib=E2=80=9D=20&=20=E2=80=9CEdkPeiPerformanceLib=E2=80=9D=20to?= =?UTF-8?q?=20=E2=80=9CDxePerformanceLib=E2=80=9D=20&=20=E2=80=9CPeiPerfor?= =?UTF-8?q?manceLib=E2=80=9D=20respectively.=20=09Synchronize=20the=20func?= =?UTF-8?q?tion=20header=20of=20GetPerformanceMeasurement()=20with=20MWG?= =?UTF-8?q?=200.56d.=206.=20BasePeCoffLoaderLib.=20=09Make=20PeCoffLoaderL?= =?UTF-8?q?oadImage=20()=20Assert()=20if=20ImageContext=20is=20NULL>=20=09?= =?UTF-8?q?Make=20PeCoffLoaderLoadImage=20()=20return=20RETURN=5FINVALID?= =?UTF-8?q?=5FPARAMETER=20if=20the=20ImageAddress=20in=20ImageContext=20is?= =?UTF-8?q?=200.=20=09Adjust=20some=20coding=20style.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@593 6f19259b-4bc3-4df7-8a09-765794883524 --- MdePkg/Include/Ebc/ProcessorBind.h | 8 +- MdePkg/Include/Library/PeCoffLib.h | 69 ++++++++---- MdePkg/Include/Library/PerformanceLib.h | 53 ++++++---- MdePkg/Include/Library/SmbusLib.h | 29 +++--- MdePkg/Library/BaseMemoryLib/CompareMemWrapper.c | 40 +++---- MdePkg/Library/BaseMemoryLib/MemLibGeneric.c | 1 - MdePkg/Library/BaseMemoryLib/ScanMem16Wrapper.c | 38 ++++--- MdePkg/Library/BaseMemoryLib/ScanMem32Wrapper.c | 38 ++++--- MdePkg/Library/BaseMemoryLib/ScanMem64Wrapper.c | 38 ++++--- MdePkg/Library/BaseMemoryLib/ScanMem8Wrapper.c | 37 +++---- MdePkg/Library/BaseMemoryLib/SetMem16Wrapper.c | 15 +-- MdePkg/Library/BaseMemoryLib/SetMem32Wrapper.c | 15 +-- MdePkg/Library/BaseMemoryLib/SetMem64Wrapper.c | 15 +-- MdePkg/Library/BaseMemoryLib/SetMemWrapper.c | 23 ++-- .../Library/BaseMemoryLibMmx/CompareMemWrapper.c | 40 +++---- MdePkg/Library/BaseMemoryLibMmx/ScanMem16Wrapper.c | 38 ++++--- MdePkg/Library/BaseMemoryLibMmx/ScanMem32Wrapper.c | 38 ++++--- MdePkg/Library/BaseMemoryLibMmx/ScanMem64Wrapper.c | 38 ++++--- MdePkg/Library/BaseMemoryLibMmx/ScanMem8Wrapper.c | 37 +++---- MdePkg/Library/BaseMemoryLibMmx/SetMem16Wrapper.c | 15 +-- MdePkg/Library/BaseMemoryLibMmx/SetMem32Wrapper.c | 15 +-- MdePkg/Library/BaseMemoryLibMmx/SetMem64Wrapper.c | 15 +-- MdePkg/Library/BaseMemoryLibMmx/SetMemWrapper.c | 23 ++-- .../BaseMemoryLibRepStr/CompareMemWrapper.c | 40 +++---- .../Library/BaseMemoryLibRepStr/ScanMem16Wrapper.c | 38 ++++--- .../Library/BaseMemoryLibRepStr/ScanMem32Wrapper.c | 38 ++++--- .../Library/BaseMemoryLibRepStr/ScanMem64Wrapper.c | 38 ++++--- .../Library/BaseMemoryLibRepStr/ScanMem8Wrapper.c | 37 +++---- .../Library/BaseMemoryLibRepStr/SetMem16Wrapper.c | 15 +-- .../Library/BaseMemoryLibRepStr/SetMem32Wrapper.c | 15 +-- .../Library/BaseMemoryLibRepStr/SetMem64Wrapper.c | 15 +-- MdePkg/Library/BaseMemoryLibRepStr/SetMemWrapper.c | 23 ++-- .../Library/BaseMemoryLibSse2/CompareMemWrapper.c | 40 +++---- .../Library/BaseMemoryLibSse2/ScanMem16Wrapper.c | 38 ++++--- .../Library/BaseMemoryLibSse2/ScanMem32Wrapper.c | 38 ++++--- .../Library/BaseMemoryLibSse2/ScanMem64Wrapper.c | 38 ++++--- MdePkg/Library/BaseMemoryLibSse2/ScanMem8Wrapper.c | 37 +++---- MdePkg/Library/BaseMemoryLibSse2/SetMem16Wrapper.c | 15 +-- MdePkg/Library/BaseMemoryLibSse2/SetMem32Wrapper.c | 15 +-- MdePkg/Library/BaseMemoryLibSse2/SetMem64Wrapper.c | 15 +-- MdePkg/Library/BaseMemoryLibSse2/SetMemWrapper.c | 23 ++-- MdePkg/Library/BasePeCoffLib/BasePeCoff.c | 51 ++++----- MdePkg/Library/BasePeCoffLib/Ebc/PeCoffLoaderEx.c | 15 ++- MdePkg/Library/BasePeCoffLib/Ia32/PeCoffLoaderEx.c | 13 +-- MdePkg/Library/BasePeCoffLib/Ipf/PeCoffLoaderEx.c | 11 +- MdePkg/Library/BasePeCoffLib/x64/PeCoffLoaderEx.c | 11 +- .../BasePerformanceLibNull/PerformanceLib.c | 56 ++++++---- MdePkg/Library/BasePrintLib/PrintLib.c | 116 +++++++++++++-------- MdePkg/Library/BaseSmbusLib/SmbusLib.c | 55 +++++----- MdePkg/Library/DxeSmbusLib/InternalSmbusLib.h | 6 +- MdePkg/Library/DxeSmbusLib/SmbusLib.c | 38 ++++--- MdePkg/Library/PeiMemoryLib/CompareMemWrapper.c | 40 +++---- MdePkg/Library/PeiMemoryLib/MemLibGeneric.c | 1 - MdePkg/Library/PeiMemoryLib/ScanMem16Wrapper.c | 38 ++++--- MdePkg/Library/PeiMemoryLib/ScanMem32Wrapper.c | 38 ++++--- MdePkg/Library/PeiMemoryLib/ScanMem64Wrapper.c | 38 ++++--- MdePkg/Library/PeiMemoryLib/ScanMem8Wrapper.c | 37 +++---- MdePkg/Library/PeiMemoryLib/SetMem16Wrapper.c | 15 +-- MdePkg/Library/PeiMemoryLib/SetMem32Wrapper.c | 15 +-- MdePkg/Library/PeiMemoryLib/SetMem64Wrapper.c | 15 +-- MdePkg/Library/PeiMemoryLib/SetMemWrapper.c | 23 ++-- MdePkg/Library/PeiSmbusLib/InternalSmbusLib.h | 6 +- MdePkg/Library/PeiSmbusLib/SmbusLib.c | 38 ++++--- MdePkg/Library/UefiMemoryLib/CompareMemWrapper.c | 40 +++---- MdePkg/Library/UefiMemoryLib/MemLibGeneric.c | 1 - MdePkg/Library/UefiMemoryLib/ScanMem16Wrapper.c | 38 ++++--- MdePkg/Library/UefiMemoryLib/ScanMem32Wrapper.c | 38 ++++--- MdePkg/Library/UefiMemoryLib/ScanMem64Wrapper.c | 38 ++++--- MdePkg/Library/UefiMemoryLib/ScanMem8Wrapper.c | 37 +++---- MdePkg/Library/UefiMemoryLib/SetMem16Wrapper.c | 15 +-- MdePkg/Library/UefiMemoryLib/SetMem32Wrapper.c | 15 +-- MdePkg/Library/UefiMemoryLib/SetMem64Wrapper.c | 15 +-- MdePkg/Library/UefiMemoryLib/SetMemWrapper.c | 23 ++-- 73 files changed, 1087 insertions(+), 1045 deletions(-) (limited to 'MdePkg') diff --git a/MdePkg/Include/Ebc/ProcessorBind.h b/MdePkg/Include/Ebc/ProcessorBind.h index cef769241b..5a6e7dc9bb 100644 --- a/MdePkg/Include/Ebc/ProcessorBind.h +++ b/MdePkg/Include/Ebc/ProcessorBind.h @@ -54,15 +54,13 @@ typedef unsigned long UINTN; // // Scalable macro to set the most significant bit in a natural number // -#define MAX_BIT 0x8000000000000000ULL -#define MAX_2_BITS 0xC000000000000000ULL - +#define MAX_BIT (1ULL << (sizeof (INTN) * 8 - 1)) +#define MAX_2_BITS (3ULL << (sizeof (INTN) * 8 - 2)) // // Maximum legal EBC address // -#define MAX_ADDRESS 0xFFFFFFFFFFFFFFFFULL - +#define MAX_ADDRESS ((UINTN) ~0) // // Modifier to ensure that all protocol member functions and EFI intrinsics // use the correct C calling convention. All protocol member functions and diff --git a/MdePkg/Include/Library/PeCoffLib.h b/MdePkg/Include/Library/PeCoffLib.h index 08e8195a8a..0a68ae640f 100644 --- a/MdePkg/Include/Library/PeCoffLib.h +++ b/MdePkg/Include/Library/PeCoffLib.h @@ -75,15 +75,22 @@ typedef struct { /** - Retrieves information on a PE/COFF image + Retrieves information about a PE/COFF image. - @param ImageContext The context of the image being loaded + Computes the PeCoffHeaderOffset, ImageAddress, ImageSize, DestinationAddress, CodeView, + PdbPointer, RelocationsStripped, SectionAlignment, SizeOfHeaders, and DebugDirectoryEntryRva + fields of the ImageContext structure. If ImageContext is NULL, then return RETURN_INVALID_PARAMETER. + If the PE/COFF image accessed through the ImageRead service in the ImageContext structure is not + a supported PE/COFF image type, then return RETURN_UNSUPPORTED. If any errors occur while + computing the fields of ImageContext, then the error status is returned in the ImageError field of + ImageContext. - @retval EFI_SUCCESS The information on the PE/COFF image was collected. - @retval EFI_INVALID_PARAMETER ImageContext is NULL. - @retval EFI_UNSUPPORTED The PE/COFF image is not supported. - @retval Otherwise The error status from reading the PE/COFF image using the - ImageContext->ImageRead() function + @param ImageContext Pointer to the image context structure that describes the PE/COFF + image that needs to be examined by this function. + + @retval RETURN_SUCCESS The information on the PE/COFF image was collected. + @retval RETURN_INVALID_PARAMETER ImageContext is NULL. + @retval RETURN_UNSUPPORTED The PE/COFF image is not supported. **/ RETURN_STATUS @@ -94,13 +101,23 @@ PeCoffLoaderGetImageInfo ( ; /** - Relocates a PE/COFF image in memory + Applies relocation fixups to a PE/COFF image that was loaded with PeCoffLoaderLoadImage(). + + If the DestinationAddress field of ImageContext is 0, then use the ImageAddress field of + ImageContext as the relocation base address. Otherwise, use the DestinationAddress field + of ImageContext as the relocation base address. The caller must allocate the relocation + fixup log buffer and fill in the FixupData field of ImageContext prior to calling this function. + If ImageContext is NULL, then ASSERT(). - @param ImageContext Contains information on the loaded image to relocate + @param ImageContext Pointer to the image context structure that describes the PE/COFF + image that is being relocated. - @retval EFI_SUCCESS if the PE/COFF image was relocated - @retval EFI_LOAD_ERROR if the image is not a valid PE/COFF image - @retval EFI_UNSUPPORTED not support + @retval RETURN_SUCCESS The PE/COFF image was relocated. + Extended status information is in the ImageError field of ImageContext. + @retval RETURN_LOAD_ERROR The image in not a valid PE/COFF image. + Extended status information is in the ImageError field of ImageContext. + @retval RETURN_UNSUPPORTED A relocation record type is not supported. + Extended status information is in the ImageError field of ImageContext. **/ RETURN_STATUS @@ -111,14 +128,26 @@ PeCoffLoaderRelocateImage ( ; /** - Loads a PE/COFF image into memory - - @param ImageContext Contains information on image to load into memory - - @retval EFI_SUCCESS if the PE/COFF image was loaded - @retval EFI_BUFFER_TOO_SMALL if the caller did not provide a large enough buffer - @retval EFI_LOAD_ERROR if the image is a runtime driver with no relocations - @retval EFI_INVALID_PARAMETER if the image address is invalid + Loads a PE/COFF image into memory. + + Loads the PE/COFF image accessed through the ImageRead service of ImageContext into the buffer + specified by the ImageAddress and ImageSize fields of ImageContext. The caller must allocate + the load buffer and fill in the ImageAddress and ImageSize fields prior to calling this function. + The EntryPoint, FixupDataSize, CodeView, and PdbPointer fields of ImageContext are computed. + If ImageContext is NULL, then ASSERT(). + + @param ImageContext Pointer to the image context structure that describes the PE/COFF + image that is being loaded. + + @retval RETURN_SUCCESS The PE/COFF image was loaded into the buffer specified by + the ImageAddress and ImageSize fields of ImageContext. + Extended status information is in the ImageError field of ImageContext. + @retval RETURN_BUFFER_TOO_SMALL The caller did not provide a large enough buffer. + Extended status information is in the ImageError field of ImageContext. + @retval RETURN_LOAD_ERROR The PE/COFF image is an EFI Runtime image with no relocations. + Extended status information is in the ImageError field of ImageContext. + @retval RETURN_INVALID_PARAMETER The image address is invalid. + Extended status information is in the ImageError field of ImageContext. **/ RETURN_STATUS diff --git a/MdePkg/Include/Library/PerformanceLib.h b/MdePkg/Include/Library/PerformanceLib.h index 36564095e9..ca32d98b1d 100644 --- a/MdePkg/Include/Library/PerformanceLib.h +++ b/MdePkg/Include/Library/PerformanceLib.h @@ -84,31 +84,46 @@ EndPerformanceMeasurement ( ); /** - Retrieves a previously logged performance measurement. + Attempts to retrieve a performance measurement log entry from the performance measurement log. - Looks up the record that matches Handle, Token, and Module. - If the record can not be found then return RETURN_NOT_FOUND. - If the record is found then the start of the measurement is returned in StartTimeStamp, - and the end of the measurement is returned in EndTimeStamp. - - @param LogEntryKey The key for the previous performance measurement log entry. - If 0, then the first performance measurement log entry is retrieved. - @param Handle Pointer to environment specific context used - to identify the component being measured. - @param Token Pointer to a Null-terminated ASCII string - that identifies the component being measured. - @param Module Pointer to a Null-terminated ASCII string - that identifies the module being measured. - @param StartTimeStamp The 64-bit time stamp that was recorded when the measurement was started. - @param EndTimeStamp The 64-bit time stamp that was recorded when the measurement was ended. - - @return The key for the current performance log entry. + Attempts to retrieve the performance log entry specified by LogEntryKey. If LogEntryKey is + zero on entry, then an attempt is made to retrieve the first entry from the performance log, + and the key for the second entry in the log is returned. If the performance log is empty, + then no entry is retrieved and zero is returned. If LogEntryKey is not zero, then the performance + log entry associated with LogEntryKey is retrieved, and the key for the next entry in the log is + returned. If LogEntryKey is the key for the last entry in the log, then the last log entry is + retrieved and an implementation specific non-zero key value that specifies the end of the performance + log is returned. If LogEntryKey is equal this implementation specific non-zero key value, then no entry + is retrieved and zero is returned. In the cases where a performance log entry can be returned, + the log entry is returned in Handle, Token, Module, StartTimeStamp, and EndTimeStamp. + If LogEntryKey is not a valid log entry key for the performance measurement log, then ASSERT(). + If Handle is NULL, then ASSERT(). + If Token is NULL, then ASSERT(). + If Module is NULL, then ASSERT(). + If StartTimeStamp is NULL, then ASSERT(). + If EndTimeStamp is NULL, then ASSERT(). + + @param LogEntryKey On entry, the key of the performance measurement log entry to retrieve. + 0, then the first performance measurement log entry is retrieved. + On exit, the key of the next performance lof entry entry. + @param Handle Pointer to environment specific context used to identify the component + being measured. + @param Token Pointer to a Null-terminated ASCII string that identifies the component + being measured. + @param Module Pointer to a Null-terminated ASCII string that identifies the module + being measured. + @param StartTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement + was started. + @param EndTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement + was ended. + + @return The key for the next performance log entry (in general case). **/ UINTN EFIAPI GetPerformanceMeasurement ( - UINTN LogEntryKey, + IN UINTN LogEntryKey, OUT CONST VOID **Handle, OUT CONST CHAR8 **Token, OUT CONST CHAR8 **Module, diff --git a/MdePkg/Include/Library/SmbusLib.h b/MdePkg/Include/Library/SmbusLib.h index 484ab90144..6d214aaa8e 100644 --- a/MdePkg/Include/Library/SmbusLib.h +++ b/MdePkg/Include/Library/SmbusLib.h @@ -18,9 +18,9 @@ #define __SMBUS_LIB__ // -// PEC BIT is bit 21 in SMBUS address +// PEC BIT is bit 22 in SMBUS address // -#define SMBUS_LIB_PEC_BIT (1 << 21) +#define SMBUS_LIB_PEC_BIT (1 << 22) /** Macro that converts SMBUS slave address, SMBUS command, SMBUS data length, @@ -32,7 +32,7 @@ @param SlaveAddress SMBUS Slave Address. Range 0..127. @param Command SMBUS Command. Range 0..255. - @param Length SMBUS Data Length. Range 0..31. + @param Length SMBUS Data Length. Range 0..32. @param Pec TRUE if Packet Error Checking is enabled. Otherwise FALSE. **/ @@ -40,7 +40,7 @@ ( ((Pec) ? SMBUS_LIB_PEC_BIT: 0) | \ (((SlaveAddress) & 0x7f) << 1) | \ (((Command) & 0xff) << 8) | \ - (((Length) & 0x1f) << 16) \ + (((Length) & 0x3f) << 16) \ ) /** @@ -296,7 +296,7 @@ SmBusProcessCall ( Bytes are read from the SMBUS and stored in Buffer. The number of bytes read is returned, and will never return a value larger than 32-bytes. If Status is not NULL, then the status of the executed command is returned in Status. - It is the caller¡¯s responsibility to make sure Buffer is large enough for the total number of bytes read. + It is the caller's responsibility to make sure Buffer is large enough for the total number of bytes read. SMBUS supports a maximum transfer size of 32 bytes, so Buffer does not need to be any larger than 32 bytes. If Length in SmBusAddress is not zero, then ASSERT(). If Buffer is NULL, then ASSERT(). @@ -355,19 +355,19 @@ SmBusWriteBlock ( Executes an SMBUS block process call command on the SMBUS device specified by SmBusAddress. The SMBUS slave address, SMBUS command, and SMBUS length fields of SmBusAddress are required. - Bytes are written to the SMBUS from OutBuffer. Bytes are then read from the SMBUS into InBuffer. + Bytes are written to the SMBUS from WriteBuffer. Bytes are then read from the SMBUS into ReadBuffer. If Status is not NULL, then the status of the executed command is returned in Status. - It is the caller¡¯s responsibility to make sure InBuffer is large enough for the total number of bytes read. + It is the caller's responsibility to make sure ReadBuffer is large enough for the total number of bytes read. SMBUS supports a maximum transfer size of 32 bytes, so Buffer does not need to be any larger than 32 bytes. - If OutBuffer is NULL, then ASSERT(). - If InBuffer is NULL, then ASSERT(). + If Length in SmBusAddress is zero or greater than 32, then ASSERT(). + If WriteBuffer is NULL, then ASSERT(). + If ReadBuffer is NULL, then ASSERT(). If any reserved bits of SmBusAddress are set, then ASSERT(). - @param SmBusAddress Address that encodes the SMBUS Slave Address, SMBUS Command, SMBUS Data Length, and PEC. - @param OutBuffer Pointer to the buffer of bytes to write to the SMBUS. - @param InBuffer Pointer to the buffer of bytes to read from the SMBUS. + @param WriteBuffer Pointer to the buffer of bytes to write to the SMBUS. + @param ReadBuffer Pointer to the buffer of bytes to read from the SMBUS. @param Status Return status for the executed command. This is an optional parameter and may be NULL. @@ -378,10 +378,11 @@ UINTN EFIAPI SmBusBlockProcessCall ( IN UINTN SmBusAddress, - IN VOID *OutBuffer, - OUT VOID *InBuffer, + IN VOID *WriteBuffer, + OUT VOID *ReadBuffer, OUT RETURN_STATUS *Status OPTIONAL ) ; + #endif diff --git a/MdePkg/Library/BaseMemoryLib/CompareMemWrapper.c b/MdePkg/Library/BaseMemoryLib/CompareMemWrapper.c index c8199d8dc3..6081bbe1b7 100644 --- a/MdePkg/Library/BaseMemoryLib/CompareMemWrapper.c +++ b/MdePkg/Library/BaseMemoryLib/CompareMemWrapper.c @@ -26,26 +26,25 @@ #include "MemLibInternals.h" /** - Compares two memory buffers of a given length. + Compares the contents of two buffers. - This function compares Length bytes of SourceBuffer to Length bytes of - DestinationBuffer. If all Length bytes of the two buffers are identical, then - 0 is returned. Otherwise, the value returned is the first mismatched byte in - SourceBuffer subtracted from the first mismatched byte in DestinationBuffer. + This function compares Length bytes of SourceBuffer to Length bytes of DestinationBuffer. + If all Length bytes of the two buffers are identical, then 0 is returned. Otherwise, the + value returned is the first mismatched byte in SourceBuffer subtracted from the first + mismatched byte in DestinationBuffer. + If Length > 0 and DestinationBuffer is NULL and Length > 0, then ASSERT(). + If Length > 0 and SourceBuffer is NULL and Length > 0, then ASSERT(). + If Length is greater than (MAX_ADDRESS - DestinationBuffer + 1), then ASSERT(). + If Length is greater than (MAX_ADDRESS - SourceBuffer + 1), then ASSERT(). - If DestinationBuffer is NULL and Length > 0, then ASSERT(). - If SourceBuffer is NULL and Length > 0, then ASSERT(). - If Length is greater than (MAX_ADDRESS - DestinationBuffer + 1), then - ASSERT(). - If Length is greater than (MAX_ADDRESS - SourceBuffer + 1), then ASSERT(). - @param DestinationBuffer First memory buffer - @param SourceBuffer Second memory buffer - @param Length Length of DestinationBuffer and SourceBuffer memory - regions to compare + @param DestinationBuffer Pointer to the destination buffer to compare. + @param SourceBuffer Pointer to the source buffer to compare. + @param Length Number of bytes to compare. - @retval 0 if DestinationBuffer == SourceBuffer - @retval Non-zero if DestinationBuffer != SourceBuffer + @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 @@ -56,12 +55,13 @@ CompareMem ( IN UINTN Length ) { - ASSERT (DestinationBuffer != NULL); - ASSERT (SourceBuffer != NULL); - ASSERT (Length <= MAX_ADDRESS - (UINTN)DestinationBuffer + 1); - ASSERT (Length <= MAX_ADDRESS - (UINTN)SourceBuffer + 1); if (Length == 0) { return 0; } + ASSERT (DestinationBuffer != NULL); + ASSERT (SourceBuffer != NULL); + ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)DestinationBuffer)); + ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)SourceBuffer)); + return InternalMemCompareMem (DestinationBuffer, SourceBuffer, Length); } diff --git a/MdePkg/Library/BaseMemoryLib/MemLibGeneric.c b/MdePkg/Library/BaseMemoryLib/MemLibGeneric.c index bda1f4992f..53c4e4416b 100644 --- a/MdePkg/Library/BaseMemoryLib/MemLibGeneric.c +++ b/MdePkg/Library/BaseMemoryLib/MemLibGeneric.c @@ -132,7 +132,6 @@ InternalMemCompareMem ( IN UINTN Length ) { - ASSERT (Length > 0); while ((--Length != 0) && (*(INT8*)DestinationBuffer == *(INT8*)SourceBuffer)) { DestinationBuffer = (INT8*)DestinationBuffer + 1; diff --git a/MdePkg/Library/BaseMemoryLib/ScanMem16Wrapper.c b/MdePkg/Library/BaseMemoryLib/ScanMem16Wrapper.c index a17705db1d..d336d59641 100644 --- a/MdePkg/Library/BaseMemoryLib/ScanMem16Wrapper.c +++ b/MdePkg/Library/BaseMemoryLib/ScanMem16Wrapper.c @@ -26,25 +26,22 @@ #include "MemLibInternals.h" /** - Scans a target buffer for a 16-bit value, and returns a pointer to the - matching 16-bit value in the target buffer. + Scans a target buffer for a 16-bit value, and returns a pointer to the matching 16-bit value + in the target buffer. - This function searches target the buffer specified by Buffer and Length from - the lowest address to the highest address at 16-bit increments for a 16-bit - value that matches Value. If a match is found, then a pointer to the matching - value in the target buffer is returned. If no match is found, then NULL is - returned. If Length is 0, then NULL is returned. - - If Buffer is NULL, then ASSERT(). + This function searches target the buffer specified by Buffer and Length from the lowest + address to the highest address for a 16-bit value that matches Value. If a match is found, + then a pointer to the matching byte in the target buffer is returned. If no match is found, + then NULL is returned. If Length is 0, then NULL is returned. + If Length > 0 and Buffer is NULL, then ASSERT(). If Buffer is not aligned on a 16-bit boundary, then ASSERT(). - If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). + If Length is greater than (MAX_ADDRESS – Buffer + 1), then ASSERT(). - @param Buffer Pointer to the target buffer to scan. - @param Length Number of bytes in Buffer to scan. - @param Value Value to search for in the target buffer. + @param Buffer Pointer to the target buffer to scan. + @param Length Number of bytes in Buffer to scan. + @param Value Value to search for in the target buffer. - @return Pointer to the first occurrence. - @retval NULL if Length == 0 or Value was not found. + @return A pointer to the matching byte in the target buffer or NULL otherwise. **/ VOID * @@ -55,12 +52,13 @@ ScanMem16 ( IN UINT16 Value ) { + if (Length == 0) { + return NULL; + } + ASSERT (Buffer != NULL); ASSERT (((UINTN)Buffer & (sizeof (Value) - 1)) == 0); - ASSERT (Length <= MAX_ADDRESS + (UINTN)Buffer + 1); + ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer)); - if ((Length /= sizeof (Value)) == 0) { - return NULL; - } - return (VOID*)InternalMemScanMem16 (Buffer, Length, Value); + return (VOID*)InternalMemScanMem16 (Buffer, Length / sizeof (Value), Value); } diff --git a/MdePkg/Library/BaseMemoryLib/ScanMem32Wrapper.c b/MdePkg/Library/BaseMemoryLib/ScanMem32Wrapper.c index 67eb84d8ef..8de55945ce 100644 --- a/MdePkg/Library/BaseMemoryLib/ScanMem32Wrapper.c +++ b/MdePkg/Library/BaseMemoryLib/ScanMem32Wrapper.c @@ -26,25 +26,22 @@ #include "MemLibInternals.h" /** - Scans a target buffer for a 32-bit value, and returns a pointer to the - matching 32-bit value in the target buffer. + Scans a target buffer for a 32-bit value, and returns a pointer to the matching 32-bit value + in the target buffer. - This function searches target the buffer specified by Buffer and Length from - the lowest address to the highest address at 32-bit increments for a 32-bit - value that matches Value. If a match is found, then a pointer to the matching - value in the target buffer is returned. If no match is found, then NULL is - returned. If Length is 0, then NULL is returned. - - If Buffer is NULL, then ASSERT(). + This function searches target the buffer specified by Buffer and Length from the lowest + address to the highest address for a 32-bit value that matches Value. If a match is found, + then a pointer to the matching byte in the target buffer is returned. If no match is found, + then NULL is returned. If Length is 0, then NULL is returned. + If Length > 0 and Buffer is NULL, then ASSERT(). If Buffer is not aligned on a 32-bit boundary, then ASSERT(). - If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). + If Length is greater than (MAX_ADDRESS – Buffer + 1), then ASSERT(). - @param Buffer Pointer to the target buffer to scan. - @param Length Number of bytes in Buffer to scan. - @param Value Value to search for in the target buffer. + @param Buffer Pointer to the target buffer to scan. + @param Length Number of bytes in Buffer to scan. + @param Value Value to search for in the target buffer. - @return Pointer to the first occurrence or NULL if not found. - @retval NULL if Length == 0 or Value was not found. + @return A pointer to the matching byte in the target buffer or NULL otherwise. **/ VOID * @@ -55,12 +52,13 @@ ScanMem32 ( IN UINT32 Value ) { + if (Length == 0) { + return NULL; + } + ASSERT (Buffer != NULL); ASSERT (((UINTN)Buffer & (sizeof (Value) - 1)) == 0); - ASSERT (Length <= MAX_ADDRESS + (UINTN)Buffer + 1); + ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer)); - if ((Length /= sizeof (Value)) == 0) { - return NULL; - } - return (VOID*)InternalMemScanMem32 (Buffer, Length, Value); + return (VOID*)InternalMemScanMem32 (Buffer, Length / sizeof (Value), Value); } diff --git a/MdePkg/Library/BaseMemoryLib/ScanMem64Wrapper.c b/MdePkg/Library/BaseMemoryLib/ScanMem64Wrapper.c index c5f0762ebe..228c864b04 100644 --- a/MdePkg/Library/BaseMemoryLib/ScanMem64Wrapper.c +++ b/MdePkg/Library/BaseMemoryLib/ScanMem64Wrapper.c @@ -26,25 +26,22 @@ #include "MemLibInternals.h" /** - Scans a target buffer for a 64-bit value, and returns a pointer to the - matching 64-bit value in the target buffer. + Scans a target buffer for a 64-bit value, and returns a pointer to the matching 64-bit value + in the target buffer. - This function searches target the buffer specified by Buffer and Length from - the lowest address to the highest address at 64-bit increments for a 64-bit - value that matches Value. If a match is found, then a pointer to the matching - value in the target buffer is returned. If no match is found, then NULL is - returned. If Length is 0, then NULL is returned. - - If Buffer is NULL, then ASSERT(). + This function searches target the buffer specified by Buffer and Length from the lowest + address to the highest address for a 64-bit value that matches Value. If a match is found, + then a pointer to the matching byte in the target buffer is returned. If no match is found, + then NULL is returned. If Length is 0, then NULL is returned. + If Length > 0 and Buffer is NULL, then ASSERT(). If Buffer is not aligned on a 64-bit boundary, then ASSERT(). - If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). + If Length is greater than (MAX_ADDRESS – Buffer + 1), then ASSERT(). - @param Buffer Pointer to the target buffer to scan. - @param Length Number of bytes in Buffer to scan. - @param Value Value to search for in the target buffer. + @param Buffer Pointer to the target buffer to scan. + @param Length Number of bytes in Buffer to scan. + @param Value Value to search for in the target buffer. - @return Pointer to the first occurrence or NULL if not found. - @retval NULL if Length == 0 or Value was not found. + @return A pointer to the matching byte in the target buffer or NULL otherwise. **/ VOID * @@ -55,12 +52,13 @@ ScanMem64 ( IN UINT64 Value ) { + if (Length == 0) { + return NULL; + } + ASSERT (Buffer != NULL); ASSERT (((UINTN)Buffer & (sizeof (Value) - 1)) == 0); - ASSERT (Length <= MAX_ADDRESS + (UINTN)Buffer + 1); + ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer)); - if ((Length /= sizeof (Value)) == 0) { - return NULL; - } - return (VOID*)InternalMemScanMem64 (Buffer, Length, Value); + return (VOID*)InternalMemScanMem64 (Buffer, Length / sizeof (Value), Value); } diff --git a/MdePkg/Library/BaseMemoryLib/ScanMem8Wrapper.c b/MdePkg/Library/BaseMemoryLib/ScanMem8Wrapper.c index 9b817b1b0e..72a8078b81 100644 --- a/MdePkg/Library/BaseMemoryLib/ScanMem8Wrapper.c +++ b/MdePkg/Library/BaseMemoryLib/ScanMem8Wrapper.c @@ -26,24 +26,21 @@ #include "MemLibInternals.h" /** - Scans a target buffer for an 8-bit value, and returns a pointer to the - matching 8-bit value in the target buffer. + Scans a target buffer for an 8-bit value, and returns a pointer to the matching 8-bit value + in the target buffer. - This function searches target the buffer specified by Buffer and Length from - the lowest address to the highest address for an 8-bit value that matches - Value. If a match is found, then a pointer to the matching byte in the target - buffer is returned. If no match is found, then NULL is returned. If Length is - 0, then NULL is returned. + This function searches target the buffer specified by Buffer and Length from the lowest + address to the highest address for an 8-bit value that matches Value. If a match is found, + then a pointer to the matching byte in the target buffer is returned. If no match is found, + then NULL is returned. If Length is 0, then NULL is returned. + If Length > 0 and Buffer is NULL, then ASSERT(). + If Length is greater than (MAX_ADDRESS – Buffer + 1), then ASSERT(). - If Buffer is NULL, then ASSERT(). - If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). + @param Buffer Pointer to the target buffer to scan. + @param Length Number of bytes in Buffer to scan. + @param Value Value to search for in the target buffer. - @param Buffer Pointer to the target buffer to scan. - @param Length Number of bytes in Buffer to scan. - @param Value Value to search for in the target buffer. - - @return Pointer to the first occurrence or NULL if not found. - @retval NULL if Length == 0 or Value was not found. + @return A pointer to the matching byte in the target buffer or NULL otherwise. **/ VOID * @@ -54,11 +51,11 @@ ScanMem8 ( IN UINT8 Value ) { - ASSERT (Buffer != NULL); - ASSERT (Length <= MAX_ADDRESS + (UINTN)Buffer + 1); - - if ((Length /= sizeof (Value)) == 0) { + if (Length == 0) { return NULL; } - return (VOID*)InternalMemScanMem8 (Buffer, Length, Value); + ASSERT (Buffer != NULL); + ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer)); + + return (VOID*)InternalMemScanMem8 (Buffer, Length / sizeof (Value), Value); } diff --git a/MdePkg/Library/BaseMemoryLib/SetMem16Wrapper.c b/MdePkg/Library/BaseMemoryLib/SetMem16Wrapper.c index dea31608fe..fd3720cd51 100644 --- a/MdePkg/Library/BaseMemoryLib/SetMem16Wrapper.c +++ b/MdePkg/Library/BaseMemoryLib/SetMem16Wrapper.c @@ -32,7 +32,7 @@ Value, and returns Buffer. Value is repeated every 16-bits in for Length bytes of Buffer. - If Buffer is NULL and Length > 0, then ASSERT(). + If Length > 0 and Buffer is NULL and Length > 0, then ASSERT(). If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). If Buffer is not aligned on a 16-bit boundary, then ASSERT(). If Length is not aligned on a 16-bit boundary, then ASSERT(). @@ -52,13 +52,14 @@ SetMem16 ( IN UINT16 Value ) { - ASSERT (!(Buffer == NULL && Length > 0)); - ASSERT (Length <= MAX_ADDRESS - (UINTN)Buffer + 1); + if (Length == 0) { + return Buffer; + } + + ASSERT (Buffer != NULL); + ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer)); ASSERT ((((UINTN)Buffer) & (sizeof (Value) - 1)) == 0); ASSERT ((Length & (sizeof (Value) - 1)) == 0); - if ((Length /= sizeof (Value)) == 0) { - return Buffer; - } - return InternalMemSetMem16 (Buffer, Length, Value); + return InternalMemSetMem16 (Buffer, Length / sizeof (Value), Value); } diff --git a/MdePkg/Library/BaseMemoryLib/SetMem32Wrapper.c b/MdePkg/Library/BaseMemoryLib/SetMem32Wrapper.c index 1ae7acb013..77f1abda04 100644 --- a/MdePkg/Library/BaseMemoryLib/SetMem32Wrapper.c +++ b/MdePkg/Library/BaseMemoryLib/SetMem32Wrapper.c @@ -32,7 +32,7 @@ Value, and returns Buffer. Value is repeated every 32-bits in for Length bytes of Buffer. - If Buffer is NULL and Length > 0, then ASSERT(). + If Length > 0 and Buffer is NULL and Length > 0, then ASSERT(). If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). If Buffer is not aligned on a 32-bit boundary, then ASSERT(). If Length is not aligned on a 32-bit boundary, then ASSERT(). @@ -52,13 +52,14 @@ SetMem32 ( IN UINT32 Value ) { - ASSERT (!(Buffer == NULL && Length > 0)); - ASSERT (Length <= MAX_ADDRESS - (UINTN)Buffer + 1); + if (Length == 0) { + return Buffer; + } + + ASSERT (Buffer != NULL); + ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer)); ASSERT ((((UINTN)Buffer) & (sizeof (Value) - 1)) == 0); ASSERT ((Length & (sizeof (Value) - 1)) == 0); - if ((Length /= sizeof (Value)) == 0) { - return Buffer; - } - return InternalMemSetMem32 (Buffer, Length, Value); + return InternalMemSetMem32 (Buffer, Length / sizeof (Value), Value); } diff --git a/MdePkg/Library/BaseMemoryLib/SetMem64Wrapper.c b/MdePkg/Library/BaseMemoryLib/SetMem64Wrapper.c index 0128a2d6f1..f95b97ff87 100644 --- a/MdePkg/Library/BaseMemoryLib/SetMem64Wrapper.c +++ b/MdePkg/Library/BaseMemoryLib/SetMem64Wrapper.c @@ -32,7 +32,7 @@ Value, and returns Buffer. Value is repeated every 64-bits in for Length bytes of Buffer. - If Buffer is NULL and Length > 0, then ASSERT(). + If Length > 0 and Buffer is NULL and Length > 0, then ASSERT(). If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). If Buffer is not aligned on a 64-bit boundary, then ASSERT(). If Length is not aligned on a 64-bit boundary, then ASSERT(). @@ -52,13 +52,14 @@ SetMem64 ( IN UINT64 Value ) { - ASSERT (!(Buffer == NULL && Length > 0)); - ASSERT (Length <= MAX_ADDRESS - (UINTN)Buffer + 1); + if (Length == 0) { + return Buffer; + } + + ASSERT (Buffer != NULL); + ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer)); ASSERT ((((UINTN)Buffer) & (sizeof (Value) - 1)) == 0); ASSERT ((Length & (sizeof (Value) - 1)) == 0); - if ((Length /= sizeof (Value)) == 0) { - return Buffer; - } - return InternalMemSetMem64 (Buffer, Length, Value); + return InternalMemSetMem64 (Buffer, Length / sizeof (Value), Value); } diff --git a/MdePkg/Library/BaseMemoryLib/SetMemWrapper.c b/MdePkg/Library/BaseMemoryLib/SetMemWrapper.c index 0600dc289f..d0e8760ff6 100644 --- a/MdePkg/Library/BaseMemoryLib/SetMemWrapper.c +++ b/MdePkg/Library/BaseMemoryLib/SetMemWrapper.c @@ -26,30 +26,31 @@ #include "MemLibInternals.h" /** - Set Buffer to Value for Size bytes. + Fills a target buffer with a byte value, and returns the target buffer. This function fills Length bytes of Buffer with Value, and returns Buffer. + If Length is greater than (MAX_ADDRESS – Buffer + 1), then ASSERT(). - If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). + @param Buffer Memory to set. + @param Length Number of bytes to set + @param Value Value of the set operation. - @param Buffer Memory to set. - @param Size Number of bytes to set - @param Value Value of the set operation. - - @return Buffer + @return Buffer. **/ VOID * EFIAPI SetMem ( IN VOID *Buffer, - IN UINTN Size, + IN UINTN Length, IN UINT8 Value ) { - if (Size == 0) { + if (Length == 0) { return Buffer; } - ASSERT (Size - 1 <= MAX_ADDRESS - (UINTN)Buffer); - return InternalMemSetMem (Buffer, Size, Value); + + ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer)); + + return InternalMemSetMem (Buffer, Length, Value); } diff --git a/MdePkg/Library/BaseMemoryLibMmx/CompareMemWrapper.c b/MdePkg/Library/BaseMemoryLibMmx/CompareMemWrapper.c index c8199d8dc3..6081bbe1b7 100644 --- a/MdePkg/Library/BaseMemoryLibMmx/CompareMemWrapper.c +++ b/MdePkg/Library/BaseMemoryLibMmx/CompareMemWrapper.c @@ -26,26 +26,25 @@ #include "MemLibInternals.h" /** - Compares two memory buffers of a given length. + Compares the contents of two buffers. - This function compares Length bytes of SourceBuffer to Length bytes of - DestinationBuffer. If all Length bytes of the two buffers are identical, then - 0 is returned. Otherwise, the value returned is the first mismatched byte in - SourceBuffer subtracted from the first mismatched byte in DestinationBuffer. + This function compares Length bytes of SourceBuffer to Length bytes of DestinationBuffer. + If all Length bytes of the two buffers are identical, then 0 is returned. Otherwise, the + value returned is the first mismatched byte in SourceBuffer subtracted from the first + mismatched byte in DestinationBuffer. + If Length > 0 and DestinationBuffer is NULL and Length > 0, then ASSERT(). + If Length > 0 and SourceBuffer is NULL and Length > 0, then ASSERT(). + If Length is greater than (MAX_ADDRESS - DestinationBuffer + 1), then ASSERT(). + If Length is greater than (MAX_ADDRESS - SourceBuffer + 1), then ASSERT(). - If DestinationBuffer is NULL and Length > 0, then ASSERT(). - If SourceBuffer is NULL and Length > 0, then ASSERT(). - If Length is greater than (MAX_ADDRESS - DestinationBuffer + 1), then - ASSERT(). - If Length is greater than (MAX_ADDRESS - SourceBuffer + 1), then ASSERT(). - @param DestinationBuffer First memory buffer - @param SourceBuffer Second memory buffer - @param Length Length of DestinationBuffer and SourceBuffer memory - regions to compare + @param DestinationBuffer Pointer to the destination buffer to compare. + @param SourceBuffer Pointer to the source buffer to compare. + @param Length Number of bytes to compare. - @retval 0 if DestinationBuffer == SourceBuffer - @retval Non-zero if DestinationBuffer != SourceBuffer + @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 @@ -56,12 +55,13 @@ CompareMem ( IN UINTN Length ) { - ASSERT (DestinationBuffer != NULL); - ASSERT (SourceBuffer != NULL); - ASSERT (Length <= MAX_ADDRESS - (UINTN)DestinationBuffer + 1); - ASSERT (Length <= MAX_ADDRESS - (UINTN)SourceBuffer + 1); if (Length == 0) { return 0; } + ASSERT (DestinationBuffer != NULL); + ASSERT (SourceBuffer != NULL); + ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)DestinationBuffer)); + ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)SourceBuffer)); + return InternalMemCompareMem (DestinationBuffer, SourceBuffer, Length); } diff --git a/MdePkg/Library/BaseMemoryLibMmx/ScanMem16Wrapper.c b/MdePkg/Library/BaseMemoryLibMmx/ScanMem16Wrapper.c index a17705db1d..d336d59641 100644 --- a/MdePkg/Library/BaseMemoryLibMmx/ScanMem16Wrapper.c +++ b/MdePkg/Library/BaseMemoryLibMmx/ScanMem16Wrapper.c @@ -26,25 +26,22 @@ #include "MemLibInternals.h" /** - Scans a target buffer for a 16-bit value, and returns a pointer to the - matching 16-bit value in the target buffer. + Scans a target buffer for a 16-bit value, and returns a pointer to the matching 16-bit value + in the target buffer. - This function searches target the buffer specified by Buffer and Length from - the lowest address to the highest address at 16-bit increments for a 16-bit - value that matches Value. If a match is found, then a pointer to the matching - value in the target buffer is returned. If no match is found, then NULL is - returned. If Length is 0, then NULL is returned. - - If Buffer is NULL, then ASSERT(). + This function searches target the buffer specified by Buffer and Length from the lowest + address to the highest address for a 16-bit value that matches Value. If a match is found, + then a pointer to the matching byte in the target buffer is returned. If no match is found, + then NULL is returned. If Length is 0, then NULL is returned. + If Length > 0 and Buffer is NULL, then ASSERT(). If Buffer is not aligned on a 16-bit boundary, then ASSERT(). - If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). + If Length is greater than (MAX_ADDRESS – Buffer + 1), then ASSERT(). - @param Buffer Pointer to the target buffer to scan. - @param Length Number of bytes in Buffer to scan. - @param Value Value to search for in the target buffer. + @param Buffer Pointer to the target buffer to scan. + @param Length Number of bytes in Buffer to scan. + @param Value Value to search for in the target buffer. - @return Pointer to the first occurrence. - @retval NULL if Length == 0 or Value was not found. + @return A pointer to the matching byte in the target buffer or NULL otherwise. **/ VOID * @@ -55,12 +52,13 @@ ScanMem16 ( IN UINT16 Value ) { + if (Length == 0) { + return NULL; + } + ASSERT (Buffer != NULL); ASSERT (((UINTN)Buffer & (sizeof (Value) - 1)) == 0); - ASSERT (Length <= MAX_ADDRESS + (UINTN)Buffer + 1); + ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer)); - if ((Length /= sizeof (Value)) == 0) { - return NULL; - } - return (VOID*)InternalMemScanMem16 (Buffer, Length, Value); + return (VOID*)InternalMemScanMem16 (Buffer, Length / sizeof (Value), Value); } diff --git a/MdePkg/Library/BaseMemoryLibMmx/ScanMem32Wrapper.c b/MdePkg/Library/BaseMemoryLibMmx/ScanMem32Wrapper.c index 67eb84d8ef..8de55945ce 100644 --- a/MdePkg/Library/BaseMemoryLibMmx/ScanMem32Wrapper.c +++ b/MdePkg/Library/BaseMemoryLibMmx/ScanMem32Wrapper.c @@ -26,25 +26,22 @@ #include "MemLibInternals.h" /** - Scans a target buffer for a 32-bit value, and returns a pointer to the - matching 32-bit value in the target buffer. + Scans a target buffer for a 32-bit value, and returns a pointer to the matching 32-bit value + in the target buffer. - This function searches target the buffer specified by Buffer and Length from - the lowest address to the highest address at 32-bit increments for a 32-bit - value that matches Value. If a match is found, then a pointer to the matching - value in the target buffer is returned. If no match is found, then NULL is - returned. If Length is 0, then NULL is returned. - - If Buffer is NULL, then ASSERT(). + This function searches target the buffer specified by Buffer and Length from the lowest + address to the highest address for a 32-bit value that matches Value. If a match is found, + then a pointer to the matching byte in the target buffer is returned. If no match is found, + then NULL is returned. If Length is 0, then NULL is returned. + If Length > 0 and Buffer is NULL, then ASSERT(). If Buffer is not aligned on a 32-bit boundary, then ASSERT(). - If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). + If Length is greater than (MAX_ADDRESS – Buffer + 1), then ASSERT(). - @param Buffer Pointer to the target buffer to scan. - @param Length Number of bytes in Buffer to scan. - @param Value Value to search for in the target buffer. + @param Buffer Pointer to the target buffer to scan. + @param Length Number of bytes in Buffer to scan. + @param Value Value to search for in the target buffer. - @return Pointer to the first occurrence or NULL if not found. - @retval NULL if Length == 0 or Value was not found. + @return A pointer to the matching byte in the target buffer or NULL otherwise. **/ VOID * @@ -55,12 +52,13 @@ ScanMem32 ( IN UINT32 Value ) { + if (Length == 0) { + return NULL; + } + ASSERT (Buffer != NULL); ASSERT (((UINTN)Buffer & (sizeof (Value) - 1)) == 0); - ASSERT (Length <= MAX_ADDRESS + (UINTN)Buffer + 1); + ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer)); - if ((Length /= sizeof (Value)) == 0) { - return NULL; - } - return (VOID*)InternalMemScanMem32 (Buffer, Length, Value); + return (VOID*)InternalMemScanMem32 (Buffer, Length / sizeof (Value), Value); } diff --git a/MdePkg/Library/BaseMemoryLibMmx/ScanMem64Wrapper.c b/MdePkg/Library/BaseMemoryLibMmx/ScanMem64Wrapper.c index c5f0762ebe..228c864b04 100644 --- a/MdePkg/Library/BaseMemoryLibMmx/ScanMem64Wrapper.c +++ b/MdePkg/Library/BaseMemoryLibMmx/ScanMem64Wrapper.c @@ -26,25 +26,22 @@ #include "MemLibInternals.h" /** - Scans a target buffer for a 64-bit value, and returns a pointer to the - matching 64-bit value in the target buffer. + Scans a target buffer for a 64-bit value, and returns a pointer to the matching 64-bit value + in the target buffer. - This function searches target the buffer specified by Buffer and Length from - the lowest address to the highest address at 64-bit increments for a 64-bit - value that matches Value. If a match is found, then a pointer to the matching - value in the target buffer is returned. If no match is found, then NULL is - returned. If Length is 0, then NULL is returned. - - If Buffer is NULL, then ASSERT(). + This function searches target the buffer specified by Buffer and Length from the lowest + address to the highest address for a 64-bit value that matches Value. If a match is found, + then a pointer to the matching byte in the target buffer is returned. If no match is found, + then NULL is returned. If Length is 0, then NULL is returned. + If Length > 0 and Buffer is NULL, then ASSERT(). If Buffer is not aligned on a 64-bit boundary, then ASSERT(). - If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). + If Length is greater than (MAX_ADDRESS – Buffer + 1), then ASSERT(). - @param Buffer Pointer to the target buffer to scan. - @param Length Number of bytes in Buffer to scan. - @param Value Value to search for in the target buffer. + @param Buffer Pointer to the target buffer to scan. + @param Length Number of bytes in Buffer to scan. + @param Value Value to search for in the target buffer. - @return Pointer to the first occurrence or NULL if not found. - @retval NULL if Length == 0 or Value was not found. + @return A pointer to the matching byte in the target buffer or NULL otherwise. **/ VOID * @@ -55,12 +52,13 @@ ScanMem64 ( IN UINT64 Value ) { + if (Length == 0) { + return NULL; + } + ASSERT (Buffer != NULL); ASSERT (((UINTN)Buffer & (sizeof (Value) - 1)) == 0); - ASSERT (Length <= MAX_ADDRESS + (UINTN)Buffer + 1); + ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer)); - if ((Length /= sizeof (Value)) == 0) { - return NULL; - } - return (VOID*)InternalMemScanMem64 (Buffer, Length, Value); + return (VOID*)InternalMemScanMem64 (Buffer, Length / sizeof (Value), Value); } diff --git a/MdePkg/Library/BaseMemoryLibMmx/ScanMem8Wrapper.c b/MdePkg/Library/BaseMemoryLibMmx/ScanMem8Wrapper.c index 9b817b1b0e..72a8078b81 100644 --- a/MdePkg/Library/BaseMemoryLibMmx/ScanMem8Wrapper.c +++ b/MdePkg/Library/BaseMemoryLibMmx/ScanMem8Wrapper.c @@ -26,24 +26,21 @@ #include "MemLibInternals.h" /** - Scans a target buffer for an 8-bit value, and returns a pointer to the - matching 8-bit value in the target buffer. + Scans a target buffer for an 8-bit value, and returns a pointer to the matching 8-bit value + in the target buffer. - This function searches target the buffer specified by Buffer and Length from - the lowest address to the highest address for an 8-bit value that matches - Value. If a match is found, then a pointer to the matching byte in the target - buffer is returned. If no match is found, then NULL is returned. If Length is - 0, then NULL is returned. + This function searches target the buffer specified by Buffer and Length from the lowest + address to the highest address for an 8-bit value that matches Value. If a match is found, + then a pointer to the matching byte in the target buffer is returned. If no match is found, + then NULL is returned. If Length is 0, then NULL is returned. + If Length > 0 and Buffer is NULL, then ASSERT(). + If Length is greater than (MAX_ADDRESS – Buffer + 1), then ASSERT(). - If Buffer is NULL, then ASSERT(). - If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). + @param Buffer Pointer to the target buffer to scan. + @param Length Number of bytes in Buffer to scan. + @param Value Value to search for in the target buffer. - @param Buffer Pointer to the target buffer to scan. - @param Length Number of bytes in Buffer to scan. - @param Value Value to search for in the target buffer. - - @return Pointer to the first occurrence or NULL if not found. - @retval NULL if Length == 0 or Value was not found. + @return A pointer to the matching byte in the target buffer or NULL otherwise. **/ VOID * @@ -54,11 +51,11 @@ ScanMem8 ( IN UINT8 Value ) { - ASSERT (Buffer != NULL); - ASSERT (Length <= MAX_ADDRESS + (UINTN)Buffer + 1); - - if ((Length /= sizeof (Value)) == 0) { + if (Length == 0) { return NULL; } - return (VOID*)InternalMemScanMem8 (Buffer, Length, Value); + ASSERT (Buffer != NULL); + ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer)); + + return (VOID*)InternalMemScanMem8 (Buffer, Length / sizeof (Value), Value); } diff --git a/MdePkg/Library/BaseMemoryLibMmx/SetMem16Wrapper.c b/MdePkg/Library/BaseMemoryLibMmx/SetMem16Wrapper.c index dea31608fe..fd3720cd51 100644 --- a/MdePkg/Library/BaseMemoryLibMmx/SetMem16Wrapper.c +++ b/MdePkg/Library/BaseMemoryLibMmx/SetMem16Wrapper.c @@ -32,7 +32,7 @@ Value, and returns Buffer. Value is repeated every 16-bits in for Length bytes of Buffer. - If Buffer is NULL and Length > 0, then ASSERT(). + If Length > 0 and Buffer is NULL and Length > 0, then ASSERT(). If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). If Buffer is not aligned on a 16-bit boundary, then ASSERT(). If Length is not aligned on a 16-bit boundary, then ASSERT(). @@ -52,13 +52,14 @@ SetMem16 ( IN UINT16 Value ) { - ASSERT (!(Buffer == NULL && Length > 0)); - ASSERT (Length <= MAX_ADDRESS - (UINTN)Buffer + 1); + if (Length == 0) { + return Buffer; + } + + ASSERT (Buffer != NULL); + ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer)); ASSERT ((((UINTN)Buffer) & (sizeof (Value) - 1)) == 0); ASSERT ((Length & (sizeof (Value) - 1)) == 0); - if ((Length /= sizeof (Value)) == 0) { - return Buffer; - } - return InternalMemSetMem16 (Buffer, Length, Value); + return InternalMemSetMem16 (Buffer, Length / sizeof (Value), Value); } diff --git a/MdePkg/Library/BaseMemoryLibMmx/SetMem32Wrapper.c b/MdePkg/Library/BaseMemoryLibMmx/SetMem32Wrapper.c index 1ae7acb013..77f1abda04 100644 --- a/MdePkg/Library/BaseMemoryLibMmx/SetMem32Wrapper.c +++ b/MdePkg/Library/BaseMemoryLibMmx/SetMem32Wrapper.c @@ -32,7 +32,7 @@ Value, and returns Buffer. Value is repeated every 32-bits in for Length bytes of Buffer. - If Buffer is NULL and Length > 0, then ASSERT(). + If Length > 0 and Buffer is NULL and Length > 0, then ASSERT(). If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). If Buffer is not aligned on a 32-bit boundary, then ASSERT(). If Length is not aligned on a 32-bit boundary, then ASSERT(). @@ -52,13 +52,14 @@ SetMem32 ( IN UINT32 Value ) { - ASSERT (!(Buffer == NULL && Length > 0)); - ASSERT (Length <= MAX_ADDRESS - (UINTN)Buffer + 1); + if (Length == 0) { + return Buffer; + } + + ASSERT (Buffer != NULL); + ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer)); ASSERT ((((UINTN)Buffer) & (sizeof (Value) - 1)) == 0); ASSERT ((Length & (sizeof (Value) - 1)) == 0); - if ((Length /= sizeof (Value)) == 0) { - return Buffer; - } - return InternalMemSetMem32 (Buffer, Length, Value); + return InternalMemSetMem32 (Buffer, Length / sizeof (Value), Value); } diff --git a/MdePkg/Library/BaseMemoryLibMmx/SetMem64Wrapper.c b/MdePkg/Library/BaseMemoryLibMmx/SetMem64Wrapper.c index 0128a2d6f1..f95b97ff87 100644 --- a/MdePkg/Library/BaseMemoryLibMmx/SetMem64Wrapper.c +++ b/MdePkg/Library/BaseMemoryLibMmx/SetMem64Wrapper.c @@ -32,7 +32,7 @@ Value, and returns Buffer. Value is repeated every 64-bits in for Length bytes of Buffer. - If Buffer is NULL and Length > 0, then ASSERT(). + If Length > 0 and Buffer is NULL and Length > 0, then ASSERT(). If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). If Buffer is not aligned on a 64-bit boundary, then ASSERT(). If Length is not aligned on a 64-bit boundary, then ASSERT(). @@ -52,13 +52,14 @@ SetMem64 ( IN UINT64 Value ) { - ASSERT (!(Buffer == NULL && Length > 0)); - ASSERT (Length <= MAX_ADDRESS - (UINTN)Buffer + 1); + if (Length == 0) { + return Buffer; + } + + ASSERT (Buffer != NULL); + ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer)); ASSERT ((((UINTN)Buffer) & (sizeof (Value) - 1)) == 0); ASSERT ((Length & (sizeof (Value) - 1)) == 0); - if ((Length /= sizeof (Value)) == 0) { - return Buffer; - } - return InternalMemSetMem64 (Buffer, Length, Value); + return InternalMemSetMem64 (Buffer, Length / sizeof (Value), Value); } diff --git a/MdePkg/Library/BaseMemoryLibMmx/SetMemWrapper.c b/MdePkg/Library/BaseMemoryLibMmx/SetMemWrapper.c index 0600dc289f..d0e8760ff6 100644 --- a/MdePkg/Library/BaseMemoryLibMmx/SetMemWrapper.c +++ b/MdePkg/Library/BaseMemoryLibMmx/SetMemWrapper.c @@ -26,30 +26,31 @@ #include "MemLibInternals.h" /** - Set Buffer to Value for Size bytes. + Fills a target buffer with a byte value, and returns the target buffer. This function fills Length bytes of Buffer with Value, and returns Buffer. + If Length is greater than (MAX_ADDRESS – Buffer + 1), then ASSERT(). - If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). + @param Buffer Memory to set. + @param Length Number of bytes to set + @param Value Value of the set operation. - @param Buffer Memory to set. - @param Size Number of bytes to set - @param Value Value of the set operation. - - @return Buffer + @return Buffer. **/ VOID * EFIAPI SetMem ( IN VOID *Buffer, - IN UINTN Size, + IN UINTN Length, IN UINT8 Value ) { - if (Size == 0) { + if (Length == 0) { return Buffer; } - ASSERT (Size - 1 <= MAX_ADDRESS - (UINTN)Buffer); - return InternalMemSetMem (Buffer, Size, Value); + + ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer)); + + return InternalMemSetMem (Buffer, Length, Value); } diff --git a/MdePkg/Library/BaseMemoryLibRepStr/CompareMemWrapper.c b/MdePkg/Library/BaseMemoryLibRepStr/CompareMemWrapper.c index c8199d8dc3..6081bbe1b7 100644 --- a/MdePkg/Library/BaseMemoryLibRepStr/CompareMemWrapper.c +++ b/MdePkg/Library/BaseMemoryLibRepStr/CompareMemWrapper.c @@ -26,26 +26,25 @@ #include "MemLibInternals.h" /** - Compares two memory buffers of a given length. + Compares the contents of two buffers. - This function compares Length bytes of SourceBuffer to Length bytes of - DestinationBuffer. If all Length bytes of the two buffers are identical, then - 0 is returned. Otherwise, the value returned is the first mismatched byte in - SourceBuffer subtracted from the first mismatched byte in DestinationBuffer. + This function compares Length bytes of SourceBuffer to Length bytes of DestinationBuffer. + If all Length bytes of the two buffers are identical, then 0 is returned. Otherwise, the + value returned is the first mismatched byte in SourceBuffer subtracted from the first + mismatched byte in DestinationBuffer. + If Length > 0 and DestinationBuffer is NULL and Length > 0, then ASSERT(). + If Length > 0 and SourceBuffer is NULL and Length > 0, then ASSERT(). + If Length is greater than (MAX_ADDRESS - DestinationBuffer + 1), then ASSERT(). + If Length is greater than (MAX_ADDRESS - SourceBuffer + 1), then ASSERT(). - If DestinationBuffer is NULL and Length > 0, then ASSERT(). - If SourceBuffer is NULL and Length > 0, then ASSERT(). - If Length is greater than (MAX_ADDRESS - DestinationBuffer + 1), then - ASSERT(). - If Length is greater than (MAX_ADDRESS - SourceBuffer + 1), then ASSERT(). - @param DestinationBuffer First memory buffer - @param SourceBuffer Second memory buffer - @param Length Length of DestinationBuffer and SourceBuffer memory - regions to compare + @param DestinationBuffer Pointer to the destination buffer to compare. + @param SourceBuffer Pointer to the source buffer to compare. + @param Length Number of bytes to compare. - @retval 0 if DestinationBuffer == SourceBuffer - @retval Non-zero if DestinationBuffer != SourceBuffer + @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 @@ -56,12 +55,13 @@ CompareMem ( IN UINTN Length ) { - ASSERT (DestinationBuffer != NULL); - ASSERT (SourceBuffer != NULL); - ASSERT (Length <= MAX_ADDRESS - (UINTN)DestinationBuffer + 1); - ASSERT (Length <= MAX_ADDRESS - (UINTN)SourceBuffer + 1); if (Length == 0) { return 0; } + ASSERT (DestinationBuffer != NULL); + ASSERT (SourceBuffer != NULL); + ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)DestinationBuffer)); + ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)SourceBuffer)); + return InternalMemCompareMem (DestinationBuffer, SourceBuffer, Length); } diff --git a/MdePkg/Library/BaseMemoryLibRepStr/ScanMem16Wrapper.c b/MdePkg/Library/BaseMemoryLibRepStr/ScanMem16Wrapper.c index a17705db1d..d336d59641 100644 --- a/MdePkg/Library/BaseMemoryLibRepStr/ScanMem16Wrapper.c +++ b/MdePkg/Library/BaseMemoryLibRepStr/ScanMem16Wrapper.c @@ -26,25 +26,22 @@ #include "MemLibInternals.h" /** - Scans a target buffer for a 16-bit value, and returns a pointer to the - matching 16-bit value in the target buffer. + Scans a target buffer for a 16-bit value, and returns a pointer to the matching 16-bit value + in the target buffer. - This function searches target the buffer specified by Buffer and Length from - the lowest address to the highest address at 16-bit increments for a 16-bit - value that matches Value. If a match is found, then a pointer to the matching - value in the target buffer is returned. If no match is found, then NULL is - returned. If Length is 0, then NULL is returned. - - If Buffer is NULL, then ASSERT(). + This function searches target the buffer specified by Buffer and Length from the lowest + address to the highest address for a 16-bit value that matches Value. If a match is found, + then a pointer to the matching byte in the target buffer is returned. If no match is found, + then NULL is returned. If Length is 0, then NULL is returned. + If Length > 0 and Buffer is NULL, then ASSERT(). If Buffer is not aligned on a 16-bit boundary, then ASSERT(). - If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). + If Length is greater than (MAX_ADDRESS – Buffer + 1), then ASSERT(). - @param Buffer Pointer to the target buffer to scan. - @param Length Number of bytes in Buffer to scan. - @param Value Value to search for in the target buffer. + @param Buffer Pointer to the target buffer to scan. + @param Length Number of bytes in Buffer to scan. + @param Value Value to search for in the target buffer. - @return Pointer to the first occurrence. - @retval NULL if Length == 0 or Value was not found. + @return A pointer to the matching byte in the target buffer or NULL otherwise. **/ VOID * @@ -55,12 +52,13 @@ ScanMem16 ( IN UINT16 Value ) { + if (Length == 0) { + return NULL; + } + ASSERT (Buffer != NULL); ASSERT (((UINTN)Buffer & (sizeof (Value) - 1)) == 0); - ASSERT (Length <= MAX_ADDRESS + (UINTN)Buffer + 1); + ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer)); - if ((Length /= sizeof (Value)) == 0) { - return NULL; - } - return (VOID*)InternalMemScanMem16 (Buffer, Length, Value); + return (VOID*)InternalMemScanMem16 (Buffer, Length / sizeof (Value), Value); } diff --git a/MdePkg/Library/BaseMemoryLibRepStr/ScanMem32Wrapper.c b/MdePkg/Library/BaseMemoryLibRepStr/ScanMem32Wrapper.c index 67eb84d8ef..8de55945ce 100644 --- a/MdePkg/Library/BaseMemoryLibRepStr/ScanMem32Wrapper.c +++ b/MdePkg/Library/BaseMemoryLibRepStr/ScanMem32Wrapper.c @@ -26,25 +26,22 @@ #include "MemLibInternals.h" /** - Scans a target buffer for a 32-bit value, and returns a pointer to the - matching 32-bit value in the target buffer. + Scans a target buffer for a 32-bit value, and returns a pointer to the matching 32-bit value + in the target buffer. - This function searches target the buffer specified by Buffer and Length from - the lowest address to the highest address at 32-bit increments for a 32-bit - value that matches Value. If a match is found, then a pointer to the matching - value in the target buffer is returned. If no match is found, then NULL is - returned. If Length is 0, then NULL is returned. - - If Buffer is NULL, then ASSERT(). + This function searches target the buffer specified by Buffer and Length from the lowest + address to the highest address for a 32-bit value that matches Value. If a match is found, + then a pointer to the matching byte in the target buffer is returned. If no match is found, + then NULL is returned. If Length is 0, then NULL is returned. + If Length > 0 and Buffer is NULL, then ASSERT(). If Buffer is not aligned on a 32-bit boundary, then ASSERT(). - If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). + If Length is greater than (MAX_ADDRESS – Buffer + 1), then ASSERT(). - @param Buffer Pointer to the target buffer to scan. - @param Length Number of bytes in Buffer to scan. - @param Value Value to search for in the target buffer. + @param Buffer Pointer to the target buffer to scan. + @param Length Number of bytes in Buffer to scan. + @param Value Value to search for in the target buffer. - @return Pointer to the first occurrence or NULL if not found. - @retval NULL if Length == 0 or Value was not found. + @return A pointer to the matching byte in the target buffer or NULL otherwise. **/ VOID * @@ -55,12 +52,13 @@ ScanMem32 ( IN UINT32 Value ) { + if (Length == 0) { + return NULL; + } + ASSERT (Buffer != NULL); ASSERT (((UINTN)Buffer & (sizeof (Value) - 1)) == 0); - ASSERT (Length <= MAX_ADDRESS + (UINTN)Buffer + 1); + ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer)); - if ((Length /= sizeof (Value)) == 0) { - return NULL; - } - return (VOID*)InternalMemScanMem32 (Buffer, Length, Value); + return (VOID*)InternalMemScanMem32 (Buffer, Length / sizeof (Value), Value); } diff --git a/MdePkg/Library/BaseMemoryLibRepStr/ScanMem64Wrapper.c b/MdePkg/Library/BaseMemoryLibRepStr/ScanMem64Wrapper.c index c5f0762ebe..228c864b04 100644 --- a/MdePkg/Library/BaseMemoryLibRepStr/ScanMem64Wrapper.c +++ b/MdePkg/Library/BaseMemoryLibRepStr/ScanMem64Wrapper.c @@ -26,25 +26,22 @@ #include "MemLibInternals.h" /** - Scans a target buffer for a 64-bit value, and returns a pointer to the - matching 64-bit value in the target buffer. + Scans a target buffer for a 64-bit value, and returns a pointer to the matching 64-bit value + in the target buffer. - This function searches target the buffer specified by Buffer and Length from - the lowest address to the highest address at 64-bit increments for a 64-bit - value that matches Value. If a match is found, then a pointer to the matching - value in the target buffer is returned. If no match is found, then NULL is - returned. If Length is 0, then NULL is returned. - - If Buffer is NULL, then ASSERT(). + This function searches target the buffer specified by Buffer and Length from the lowest + address to the highest address for a 64-bit value that matches Value. If a match is found, + then a pointer to the matching byte in the target buffer is returned. If no match is found, + then NULL is returned. If Length is 0, then NULL is returned. + If Length > 0 and Buffer is NULL, then ASSERT(). If Buffer is not aligned on a 64-bit boundary, then ASSERT(). - If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). + If Length is greater than (MAX_ADDRESS – Buffer + 1), then ASSERT(). - @param Buffer Pointer to the target buffer to scan. - @param Length Number of bytes in Buffer to scan. - @param Value Value to search for in the target buffer. + @param Buffer Pointer to the target buffer to scan. + @param Length Number of bytes in Buffer to scan. + @param Value Value to search for in the target buffer. - @return Pointer to the first occurrence or NULL if not found. - @retval NULL if Length == 0 or Value was not found. + @return A pointer to the matching byte in the target buffer or NULL otherwise. **/ VOID * @@ -55,12 +52,13 @@ ScanMem64 ( IN UINT64 Value ) { + if (Length == 0) { + return NULL; + } + ASSERT (Buffer != NULL); ASSERT (((UINTN)Buffer & (sizeof (Value) - 1)) == 0); - ASSERT (Length <= MAX_ADDRESS + (UINTN)Buffer + 1); + ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer)); - if ((Length /= sizeof (Value)) == 0) { - return NULL; - } - return (VOID*)InternalMemScanMem64 (Buffer, Length, Value); + return (VOID*)InternalMemScanMem64 (Buffer, Length / sizeof (Value), Value); } diff --git a/MdePkg/Library/BaseMemoryLibRepStr/ScanMem8Wrapper.c b/MdePkg/Library/BaseMemoryLibRepStr/ScanMem8Wrapper.c index 9b817b1b0e..72a8078b81 100644 --- a/MdePkg/Library/BaseMemoryLibRepStr/ScanMem8Wrapper.c +++ b/MdePkg/Library/BaseMemoryLibRepStr/ScanMem8Wrapper.c @@ -26,24 +26,21 @@ #include "MemLibInternals.h" /** - Scans a target buffer for an 8-bit value, and returns a pointer to the - matching 8-bit value in the target buffer. + Scans a target buffer for an 8-bit value, and returns a pointer to the matching 8-bit value + in the target buffer. - This function searches target the buffer specified by Buffer and Length from - the lowest address to the highest address for an 8-bit value that matches - Value. If a match is found, then a pointer to the matching byte in the target - buffer is returned. If no match is found, then NULL is returned. If Length is - 0, then NULL is returned. + This function searches target the buffer specified by Buffer and Length from the lowest + address to the highest address for an 8-bit value that matches Value. If a match is found, + then a pointer to the matching byte in the target buffer is returned. If no match is found, + then NULL is returned. If Length is 0, then NULL is returned. + If Length > 0 and Buffer is NULL, then ASSERT(). + If Length is greater than (MAX_ADDRESS – Buffer + 1), then ASSERT(). - If Buffer is NULL, then ASSERT(). - If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). + @param Buffer Pointer to the target buffer to scan. + @param Length Number of bytes in Buffer to scan. + @param Value Value to search for in the target buffer. - @param Buffer Pointer to the target buffer to scan. - @param Length Number of bytes in Buffer to scan. - @param Value Value to search for in the target buffer. - - @return Pointer to the first occurrence or NULL if not found. - @retval NULL if Length == 0 or Value was not found. + @return A pointer to the matching byte in the target buffer or NULL otherwise. **/ VOID * @@ -54,11 +51,11 @@ ScanMem8 ( IN UINT8 Value ) { - ASSERT (Buffer != NULL); - ASSERT (Length <= MAX_ADDRESS + (UINTN)Buffer + 1); - - if ((Length /= sizeof (Value)) == 0) { + if (Length == 0) { return NULL; } - return (VOID*)InternalMemScanMem8 (Buffer, Length, Value); + ASSERT (Buffer != NULL); + ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer)); + + return (VOID*)InternalMemScanMem8 (Buffer, Length / sizeof (Value), Value); } diff --git a/MdePkg/Library/BaseMemoryLibRepStr/SetMem16Wrapper.c b/MdePkg/Library/BaseMemoryLibRepStr/SetMem16Wrapper.c index dea31608fe..fd3720cd51 100644 --- a/MdePkg/Library/BaseMemoryLibRepStr/SetMem16Wrapper.c +++ b/MdePkg/Library/BaseMemoryLibRepStr/SetMem16Wrapper.c @@ -32,7 +32,7 @@ Value, and returns Buffer. Value is repeated every 16-bits in for Length bytes of Buffer. - If Buffer is NULL and Length > 0, then ASSERT(). + If Length > 0 and Buffer is NULL and Length > 0, then ASSERT(). If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). If Buffer is not aligned on a 16-bit boundary, then ASSERT(). If Length is not aligned on a 16-bit boundary, then ASSERT(). @@ -52,13 +52,14 @@ SetMem16 ( IN UINT16 Value ) { - ASSERT (!(Buffer == NULL && Length > 0)); - ASSERT (Length <= MAX_ADDRESS - (UINTN)Buffer + 1); + if (Length == 0) { + return Buffer; + } + + ASSERT (Buffer != NULL); + ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer)); ASSERT ((((UINTN)Buffer) & (sizeof (Value) - 1)) == 0); ASSERT ((Length & (sizeof (Value) - 1)) == 0); - if ((Length /= sizeof (Value)) == 0) { - return Buffer; - } - return InternalMemSetMem16 (Buffer, Length, Value); + return InternalMemSetMem16 (Buffer, Length / sizeof (Value), Value); } diff --git a/MdePkg/Library/BaseMemoryLibRepStr/SetMem32Wrapper.c b/MdePkg/Library/BaseMemoryLibRepStr/SetMem32Wrapper.c index 1ae7acb013..77f1abda04 100644 --- a/MdePkg/Library/BaseMemoryLibRepStr/SetMem32Wrapper.c +++ b/MdePkg/Library/BaseMemoryLibRepStr/SetMem32Wrapper.c @@ -32,7 +32,7 @@ Value, and returns Buffer. Value is repeated every 32-bits in for Length bytes of Buffer. - If Buffer is NULL and Length > 0, then ASSERT(). + If Length > 0 and Buffer is NULL and Length > 0, then ASSERT(). If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). If Buffer is not aligned on a 32-bit boundary, then ASSERT(). If Length is not aligned on a 32-bit boundary, then ASSERT(). @@ -52,13 +52,14 @@ SetMem32 ( IN UINT32 Value ) { - ASSERT (!(Buffer == NULL && Length > 0)); - ASSERT (Length <= MAX_ADDRESS - (UINTN)Buffer + 1); + if (Length == 0) { + return Buffer; + } + + ASSERT (Buffer != NULL); + ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer)); ASSERT ((((UINTN)Buffer) & (sizeof (Value) - 1)) == 0); ASSERT ((Length & (sizeof (Value) - 1)) == 0); - if ((Length /= sizeof (Value)) == 0) { - return Buffer; - } - return InternalMemSetMem32 (Buffer, Length, Value); + return InternalMemSetMem32 (Buffer, Length / sizeof (Value), Value); } diff --git a/MdePkg/Library/BaseMemoryLibRepStr/SetMem64Wrapper.c b/MdePkg/Library/BaseMemoryLibRepStr/SetMem64Wrapper.c index 0128a2d6f1..f95b97ff87 100644 --- a/MdePkg/Library/BaseMemoryLibRepStr/SetMem64Wrapper.c +++ b/MdePkg/Library/BaseMemoryLibRepStr/SetMem64Wrapper.c @@ -32,7 +32,7 @@ Value, and returns Buffer. Value is repeated every 64-bits in for Length bytes of Buffer. - If Buffer is NULL and Length > 0, then ASSERT(). + If Length > 0 and Buffer is NULL and Length > 0, then ASSERT(). If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). If Buffer is not aligned on a 64-bit boundary, then ASSERT(). If Length is not aligned on a 64-bit boundary, then ASSERT(). @@ -52,13 +52,14 @@ SetMem64 ( IN UINT64 Value ) { - ASSERT (!(Buffer == NULL && Length > 0)); - ASSERT (Length <= MAX_ADDRESS - (UINTN)Buffer + 1); + if (Length == 0) { + return Buffer; + } + + ASSERT (Buffer != NULL); + ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer)); ASSERT ((((UINTN)Buffer) & (sizeof (Value) - 1)) == 0); ASSERT ((Length & (sizeof (Value) - 1)) == 0); - if ((Length /= sizeof (Value)) == 0) { - return Buffer; - } - return InternalMemSetMem64 (Buffer, Length, Value); + return InternalMemSetMem64 (Buffer, Length / sizeof (Value), Value); } diff --git a/MdePkg/Library/BaseMemoryLibRepStr/SetMemWrapper.c b/MdePkg/Library/BaseMemoryLibRepStr/SetMemWrapper.c index 0600dc289f..d0e8760ff6 100644 --- a/MdePkg/Library/BaseMemoryLibRepStr/SetMemWrapper.c +++ b/MdePkg/Library/BaseMemoryLibRepStr/SetMemWrapper.c @@ -26,30 +26,31 @@ #include "MemLibInternals.h" /** - Set Buffer to Value for Size bytes. + Fills a target buffer with a byte value, and returns the target buffer. This function fills Length bytes of Buffer with Value, and returns Buffer. + If Length is greater than (MAX_ADDRESS – Buffer + 1), then ASSERT(). - If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). + @param Buffer Memory to set. + @param Length Number of bytes to set + @param Value Value of the set operation. - @param Buffer Memory to set. - @param Size Number of bytes to set - @param Value Value of the set operation. - - @return Buffer + @return Buffer. **/ VOID * EFIAPI SetMem ( IN VOID *Buffer, - IN UINTN Size, + IN UINTN Length, IN UINT8 Value ) { - if (Size == 0) { + if (Length == 0) { return Buffer; } - ASSERT (Size - 1 <= MAX_ADDRESS - (UINTN)Buffer); - return InternalMemSetMem (Buffer, Size, Value); + + ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer)); + + return InternalMemSetMem (Buffer, Length, Value); } diff --git a/MdePkg/Library/BaseMemoryLibSse2/CompareMemWrapper.c b/MdePkg/Library/BaseMemoryLibSse2/CompareMemWrapper.c index c8199d8dc3..6081bbe1b7 100644 --- a/MdePkg/Library/BaseMemoryLibSse2/CompareMemWrapper.c +++ b/MdePkg/Library/BaseMemoryLibSse2/CompareMemWrapper.c @@ -26,26 +26,25 @@ #include "MemLibInternals.h" /** - Compares two memory buffers of a given length. + Compares the contents of two buffers. - This function compares Length bytes of SourceBuffer to Length bytes of - DestinationBuffer. If all Length bytes of the two buffers are identical, then - 0 is returned. Otherwise, the value returned is the first mismatched byte in - SourceBuffer subtracted from the first mismatched byte in DestinationBuffer. + This function compares Length bytes of SourceBuffer to Length bytes of DestinationBuffer. + If all Length bytes of the two buffers are identical, then 0 is returned. Otherwise, the + value returned is the first mismatched byte in SourceBuffer subtracted from the first + mismatched byte in DestinationBuffer. + If Length > 0 and DestinationBuffer is NULL and Length > 0, then ASSERT(). + If Length > 0 and SourceBuffer is NULL and Length > 0, then ASSERT(). + If Length is greater than (MAX_ADDRESS - DestinationBuffer + 1), then ASSERT(). + If Length is greater than (MAX_ADDRESS - SourceBuffer + 1), then ASSERT(). - If DestinationBuffer is NULL and Length > 0, then ASSERT(). - If SourceBuffer is NULL and Length > 0, then ASSERT(). - If Length is greater than (MAX_ADDRESS - DestinationBuffer + 1), then - ASSERT(). - If Length is greater than (MAX_ADDRESS - SourceBuffer + 1), then ASSERT(). - @param DestinationBuffer First memory buffer - @param SourceBuffer Second memory buffer - @param Length Length of DestinationBuffer and SourceBuffer memory - regions to compare + @param DestinationBuffer Pointer to the destination buffer to compare. + @param SourceBuffer Pointer to the source buffer to compare. + @param Length Number of bytes to compare. - @retval 0 if DestinationBuffer == SourceBuffer - @retval Non-zero if DestinationBuffer != SourceBuffer + @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 @@ -56,12 +55,13 @@ CompareMem ( IN UINTN Length ) { - ASSERT (DestinationBuffer != NULL); - ASSERT (SourceBuffer != NULL); - ASSERT (Length <= MAX_ADDRESS - (UINTN)DestinationBuffer + 1); - ASSERT (Length <= MAX_ADDRESS - (UINTN)SourceBuffer + 1); if (Length == 0) { return 0; } + ASSERT (DestinationBuffer != NULL); + ASSERT (SourceBuffer != NULL); + ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)DestinationBuffer)); + ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)SourceBuffer)); + return InternalMemCompareMem (DestinationBuffer, SourceBuffer, Length); } diff --git a/MdePkg/Library/BaseMemoryLibSse2/ScanMem16Wrapper.c b/MdePkg/Library/BaseMemoryLibSse2/ScanMem16Wrapper.c index a17705db1d..d336d59641 100644 --- a/MdePkg/Library/BaseMemoryLibSse2/ScanMem16Wrapper.c +++ b/MdePkg/Library/BaseMemoryLibSse2/ScanMem16Wrapper.c @@ -26,25 +26,22 @@ #include "MemLibInternals.h" /** - Scans a target buffer for a 16-bit value, and returns a pointer to the - matching 16-bit value in the target buffer. + Scans a target buffer for a 16-bit value, and returns a pointer to the matching 16-bit value + in the target buffer. - This function searches target the buffer specified by Buffer and Length from - the lowest address to the highest address at 16-bit increments for a 16-bit - value that matches Value. If a match is found, then a pointer to the matching - value in the target buffer is returned. If no match is found, then NULL is - returned. If Length is 0, then NULL is returned. - - If Buffer is NULL, then ASSERT(). + This function searches target the buffer specified by Buffer and Length from the lowest + address to the highest address for a 16-bit value that matches Value. If a match is found, + then a pointer to the matching byte in the target buffer is returned. If no match is found, + then NULL is returned. If Length is 0, then NULL is returned. + If Length > 0 and Buffer is NULL, then ASSERT(). If Buffer is not aligned on a 16-bit boundary, then ASSERT(). - If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). + If Length is greater than (MAX_ADDRESS – Buffer + 1), then ASSERT(). - @param Buffer Pointer to the target buffer to scan. - @param Length Number of bytes in Buffer to scan. - @param Value Value to search for in the target buffer. + @param Buffer Pointer to the target buffer to scan. + @param Length Number of bytes in Buffer to scan. + @param Value Value to search for in the target buffer. - @return Pointer to the first occurrence. - @retval NULL if Length == 0 or Value was not found. + @return A pointer to the matching byte in the target buffer or NULL otherwise. **/ VOID * @@ -55,12 +52,13 @@ ScanMem16 ( IN UINT16 Value ) { + if (Length == 0) { + return NULL; + } + ASSERT (Buffer != NULL); ASSERT (((UINTN)Buffer & (sizeof (Value) - 1)) == 0); - ASSERT (Length <= MAX_ADDRESS + (UINTN)Buffer + 1); + ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer)); - if ((Length /= sizeof (Value)) == 0) { - return NULL; - } - return (VOID*)InternalMemScanMem16 (Buffer, Length, Value); + return (VOID*)InternalMemScanMem16 (Buffer, Length / sizeof (Value), Value); } diff --git a/MdePkg/Library/BaseMemoryLibSse2/ScanMem32Wrapper.c b/MdePkg/Library/BaseMemoryLibSse2/ScanMem32Wrapper.c index 67eb84d8ef..8de55945ce 100644 --- a/MdePkg/Library/BaseMemoryLibSse2/ScanMem32Wrapper.c +++ b/MdePkg/Library/BaseMemoryLibSse2/ScanMem32Wrapper.c @@ -26,25 +26,22 @@ #include "MemLibInternals.h" /** - Scans a target buffer for a 32-bit value, and returns a pointer to the - matching 32-bit value in the target buffer. + Scans a target buffer for a 32-bit value, and returns a pointer to the matching 32-bit value + in the target buffer. - This function searches target the buffer specified by Buffer and Length from - the lowest address to the highest address at 32-bit increments for a 32-bit - value that matches Value. If a match is found, then a pointer to the matching - value in the target buffer is returned. If no match is found, then NULL is - returned. If Length is 0, then NULL is returned. - - If Buffer is NULL, then ASSERT(). + This function searches target the buffer specified by Buffer and Length from the lowest + address to the highest address for a 32-bit value that matches Value. If a match is found, + then a pointer to the matching byte in the target buffer is returned. If no match is found, + then NULL is returned. If Length is 0, then NULL is returned. + If Length > 0 and Buffer is NULL, then ASSERT(). If Buffer is not aligned on a 32-bit boundary, then ASSERT(). - If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). + If Length is greater than (MAX_ADDRESS – Buffer + 1), then ASSERT(). - @param Buffer Pointer to the target buffer to scan. - @param Length Number of bytes in Buffer to scan. - @param Value Value to search for in the target buffer. + @param Buffer Pointer to the target buffer to scan. + @param Length Number of bytes in Buffer to scan. + @param Value Value to search for in the target buffer. - @return Pointer to the first occurrence or NULL if not found. - @retval NULL if Length == 0 or Value was not found. + @return A pointer to the matching byte in the target buffer or NULL otherwise. **/ VOID * @@ -55,12 +52,13 @@ ScanMem32 ( IN UINT32 Value ) { + if (Length == 0) { + return NULL; + } + ASSERT (Buffer != NULL); ASSERT (((UINTN)Buffer & (sizeof (Value) - 1)) == 0); - ASSERT (Length <= MAX_ADDRESS + (UINTN)Buffer + 1); + ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer)); - if ((Length /= sizeof (Value)) == 0) { - return NULL; - } - return (VOID*)InternalMemScanMem32 (Buffer, Length, Value); + return (VOID*)InternalMemScanMem32 (Buffer, Length / sizeof (Value), Value); } diff --git a/MdePkg/Library/BaseMemoryLibSse2/ScanMem64Wrapper.c b/MdePkg/Library/BaseMemoryLibSse2/ScanMem64Wrapper.c index c5f0762ebe..228c864b04 100644 --- a/MdePkg/Library/BaseMemoryLibSse2/ScanMem64Wrapper.c +++ b/MdePkg/Library/BaseMemoryLibSse2/ScanMem64Wrapper.c @@ -26,25 +26,22 @@ #include "MemLibInternals.h" /** - Scans a target buffer for a 64-bit value, and returns a pointer to the - matching 64-bit value in the target buffer. + Scans a target buffer for a 64-bit value, and returns a pointer to the matching 64-bit value + in the target buffer. - This function searches target the buffer specified by Buffer and Length from - the lowest address to the highest address at 64-bit increments for a 64-bit - value that matches Value. If a match is found, then a pointer to the matching - value in the target buffer is returned. If no match is found, then NULL is - returned. If Length is 0, then NULL is returned. - - If Buffer is NULL, then ASSERT(). + This function searches target the buffer specified by Buffer and Length from the lowest + address to the highest address for a 64-bit value that matches Value. If a match is found, + then a pointer to the matching byte in the target buffer is returned. If no match is found, + then NULL is returned. If Length is 0, then NULL is returned. + If Length > 0 and Buffer is NULL, then ASSERT(). If Buffer is not aligned on a 64-bit boundary, then ASSERT(). - If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). + If Length is greater than (MAX_ADDRESS – Buffer + 1), then ASSERT(). - @param Buffer Pointer to the target buffer to scan. - @param Length Number of bytes in Buffer to scan. - @param Value Value to search for in the target buffer. + @param Buffer Pointer to the target buffer to scan. + @param Length Number of bytes in Buffer to scan. + @param Value Value to search for in the target buffer. - @return Pointer to the first occurrence or NULL if not found. - @retval NULL if Length == 0 or Value was not found. + @return A pointer to the matching byte in the target buffer or NULL otherwise. **/ VOID * @@ -55,12 +52,13 @@ ScanMem64 ( IN UINT64 Value ) { + if (Length == 0) { + return NULL; + } + ASSERT (Buffer != NULL); ASSERT (((UINTN)Buffer & (sizeof (Value) - 1)) == 0); - ASSERT (Length <= MAX_ADDRESS + (UINTN)Buffer + 1); + ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer)); - if ((Length /= sizeof (Value)) == 0) { - return NULL; - } - return (VOID*)InternalMemScanMem64 (Buffer, Length, Value); + return (VOID*)InternalMemScanMem64 (Buffer, Length / sizeof (Value), Value); } diff --git a/MdePkg/Library/BaseMemoryLibSse2/ScanMem8Wrapper.c b/MdePkg/Library/BaseMemoryLibSse2/ScanMem8Wrapper.c index 9b817b1b0e..72a8078b81 100644 --- a/MdePkg/Library/BaseMemoryLibSse2/ScanMem8Wrapper.c +++ b/MdePkg/Library/BaseMemoryLibSse2/ScanMem8Wrapper.c @@ -26,24 +26,21 @@ #include "MemLibInternals.h" /** - Scans a target buffer for an 8-bit value, and returns a pointer to the - matching 8-bit value in the target buffer. + Scans a target buffer for an 8-bit value, and returns a pointer to the matching 8-bit value + in the target buffer. - This function searches target the buffer specified by Buffer and Length from - the lowest address to the highest address for an 8-bit value that matches - Value. If a match is found, then a pointer to the matching byte in the target - buffer is returned. If no match is found, then NULL is returned. If Length is - 0, then NULL is returned. + This function searches target the buffer specified by Buffer and Length from the lowest + address to the highest address for an 8-bit value that matches Value. If a match is found, + then a pointer to the matching byte in the target buffer is returned. If no match is found, + then NULL is returned. If Length is 0, then NULL is returned. + If Length > 0 and Buffer is NULL, then ASSERT(). + If Length is greater than (MAX_ADDRESS – Buffer + 1), then ASSERT(). - If Buffer is NULL, then ASSERT(). - If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). + @param Buffer Pointer to the target buffer to scan. + @param Length Number of bytes in Buffer to scan. + @param Value Value to search for in the target buffer. - @param Buffer Pointer to the target buffer to scan. - @param Length Number of bytes in Buffer to scan. - @param Value Value to search for in the target buffer. - - @return Pointer to the first occurrence or NULL if not found. - @retval NULL if Length == 0 or Value was not found. + @return A pointer to the matching byte in the target buffer or NULL otherwise. **/ VOID * @@ -54,11 +51,11 @@ ScanMem8 ( IN UINT8 Value ) { - ASSERT (Buffer != NULL); - ASSERT (Length <= MAX_ADDRESS + (UINTN)Buffer + 1); - - if ((Length /= sizeof (Value)) == 0) { + if (Length == 0) { return NULL; } - return (VOID*)InternalMemScanMem8 (Buffer, Length, Value); + ASSERT (Buffer != NULL); + ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer)); + + return (VOID*)InternalMemScanMem8 (Buffer, Length / sizeof (Value), Value); } diff --git a/MdePkg/Library/BaseMemoryLibSse2/SetMem16Wrapper.c b/MdePkg/Library/BaseMemoryLibSse2/SetMem16Wrapper.c index dea31608fe..fd3720cd51 100644 --- a/MdePkg/Library/BaseMemoryLibSse2/SetMem16Wrapper.c +++ b/MdePkg/Library/BaseMemoryLibSse2/SetMem16Wrapper.c @@ -32,7 +32,7 @@ Value, and returns Buffer. Value is repeated every 16-bits in for Length bytes of Buffer. - If Buffer is NULL and Length > 0, then ASSERT(). + If Length > 0 and Buffer is NULL and Length > 0, then ASSERT(). If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). If Buffer is not aligned on a 16-bit boundary, then ASSERT(). If Length is not aligned on a 16-bit boundary, then ASSERT(). @@ -52,13 +52,14 @@ SetMem16 ( IN UINT16 Value ) { - ASSERT (!(Buffer == NULL && Length > 0)); - ASSERT (Length <= MAX_ADDRESS - (UINTN)Buffer + 1); + if (Length == 0) { + return Buffer; + } + + ASSERT (Buffer != NULL); + ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer)); ASSERT ((((UINTN)Buffer) & (sizeof (Value) - 1)) == 0); ASSERT ((Length & (sizeof (Value) - 1)) == 0); - if ((Length /= sizeof (Value)) == 0) { - return Buffer; - } - return InternalMemSetMem16 (Buffer, Length, Value); + return InternalMemSetMem16 (Buffer, Length / sizeof (Value), Value); } diff --git a/MdePkg/Library/BaseMemoryLibSse2/SetMem32Wrapper.c b/MdePkg/Library/BaseMemoryLibSse2/SetMem32Wrapper.c index 1ae7acb013..77f1abda04 100644 --- a/MdePkg/Library/BaseMemoryLibSse2/SetMem32Wrapper.c +++ b/MdePkg/Library/BaseMemoryLibSse2/SetMem32Wrapper.c @@ -32,7 +32,7 @@ Value, and returns Buffer. Value is repeated every 32-bits in for Length bytes of Buffer. - If Buffer is NULL and Length > 0, then ASSERT(). + If Length > 0 and Buffer is NULL and Length > 0, then ASSERT(). If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). If Buffer is not aligned on a 32-bit boundary, then ASSERT(). If Length is not aligned on a 32-bit boundary, then ASSERT(). @@ -52,13 +52,14 @@ SetMem32 ( IN UINT32 Value ) { - ASSERT (!(Buffer == NULL && Length > 0)); - ASSERT (Length <= MAX_ADDRESS - (UINTN)Buffer + 1); + if (Length == 0) { + return Buffer; + } + + ASSERT (Buffer != NULL); + ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer)); ASSERT ((((UINTN)Buffer) & (sizeof (Value) - 1)) == 0); ASSERT ((Length & (sizeof (Value) - 1)) == 0); - if ((Length /= sizeof (Value)) == 0) { - return Buffer; - } - return InternalMemSetMem32 (Buffer, Length, Value); + return InternalMemSetMem32 (Buffer, Length / sizeof (Value), Value); } diff --git a/MdePkg/Library/BaseMemoryLibSse2/SetMem64Wrapper.c b/MdePkg/Library/BaseMemoryLibSse2/SetMem64Wrapper.c index 0128a2d6f1..f95b97ff87 100644 --- a/MdePkg/Library/BaseMemoryLibSse2/SetMem64Wrapper.c +++ b/MdePkg/Library/BaseMemoryLibSse2/SetMem64Wrapper.c @@ -32,7 +32,7 @@ Value, and returns Buffer. Value is repeated every 64-bits in for Length bytes of Buffer. - If Buffer is NULL and Length > 0, then ASSERT(). + If Length > 0 and Buffer is NULL and Length > 0, then ASSERT(). If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). If Buffer is not aligned on a 64-bit boundary, then ASSERT(). If Length is not aligned on a 64-bit boundary, then ASSERT(). @@ -52,13 +52,14 @@ SetMem64 ( IN UINT64 Value ) { - ASSERT (!(Buffer == NULL && Length > 0)); - ASSERT (Length <= MAX_ADDRESS - (UINTN)Buffer + 1); + if (Length == 0) { + return Buffer; + } + + ASSERT (Buffer != NULL); + ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer)); ASSERT ((((UINTN)Buffer) & (sizeof (Value) - 1)) == 0); ASSERT ((Length & (sizeof (Value) - 1)) == 0); - if ((Length /= sizeof (Value)) == 0) { - return Buffer; - } - return InternalMemSetMem64 (Buffer, Length, Value); + return InternalMemSetMem64 (Buffer, Length / sizeof (Value), Value); } diff --git a/MdePkg/Library/BaseMemoryLibSse2/SetMemWrapper.c b/MdePkg/Library/BaseMemoryLibSse2/SetMemWrapper.c index 0600dc289f..d0e8760ff6 100644 --- a/MdePkg/Library/BaseMemoryLibSse2/SetMemWrapper.c +++ b/MdePkg/Library/BaseMemoryLibSse2/SetMemWrapper.c @@ -26,30 +26,31 @@ #include "MemLibInternals.h" /** - Set Buffer to Value for Size bytes. + Fills a target buffer with a byte value, and returns the target buffer. This function fills Length bytes of Buffer with Value, and returns Buffer. + If Length is greater than (MAX_ADDRESS – Buffer + 1), then ASSERT(). - If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). + @param Buffer Memory to set. + @param Length Number of bytes to set + @param Value Value of the set operation. - @param Buffer Memory to set. - @param Size Number of bytes to set - @param Value Value of the set operation. - - @return Buffer + @return Buffer. **/ VOID * EFIAPI SetMem ( IN VOID *Buffer, - IN UINTN Size, + IN UINTN Length, IN UINT8 Value ) { - if (Size == 0) { + if (Length == 0) { return Buffer; } - ASSERT (Size - 1 <= MAX_ADDRESS - (UINTN)Buffer); - return InternalMemSetMem (Buffer, Size, Value); + + ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer)); + + return InternalMemSetMem (Buffer, Length, Value); } diff --git a/MdePkg/Library/BasePeCoffLib/BasePeCoff.c b/MdePkg/Library/BasePeCoffLib/BasePeCoff.c index e91e9a6c2f..32a70c00c4 100644 --- a/MdePkg/Library/BasePeCoffLib/BasePeCoff.c +++ b/MdePkg/Library/BasePeCoffLib/BasePeCoff.c @@ -14,32 +14,17 @@ **/ +/** + Performs an Itanium-based specific relocation fixup. + @param Reloc Pointer to the relocation record. + @param Fixup Pointer to the address to fix up. + @param FixupData Pointer to a buffer to log the fixups. + @param Adjust The offset to adjust the fixup. + @return Status code. -STATIC -RETURN_STATUS -PeCoffLoaderGetPeHeader ( - IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext, - OUT EFI_IMAGE_NT_HEADERS *PeHdr, - OUT EFI_TE_IMAGE_HEADER *TeHdr - ); - -STATIC -RETURN_STATUS -PeCoffLoaderCheckImageType ( - IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext, - IN EFI_IMAGE_NT_HEADERS *PeHdr, - IN EFI_TE_IMAGE_HEADER *TeHdr - ); - -STATIC -VOID * -PeCoffLoaderImageAddress ( - IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext, - IN UINTN Address - ); - +**/ RETURN_STATUS PeCoffLoaderRelocateImageEx ( IN UINT16 *Reloc, @@ -193,11 +178,9 @@ PeCoffLoaderCheckImageType ( @param ImageContext Pointer to the image context structure that describes the PE/COFF image that needs to be examined by this function. - @retval RETURN_SUCCESS The information on the PE/COFF image was collected. - @retval RETURN_INVALID_PARAMETER ImageContext is NULL. - @retval RETURN_UNSUPPORTED The PE/COFF image is not supported. - @retval Others The error status from reading the PE/COFF image - using the ImageContext->ImageRead() function. + @retval RETURN_SUCCESS The information on the PE/COFF image was collected. + @retval RETURN_INVALID_PARAMETER ImageContext is NULL. + @retval RETURN_UNSUPPORTED The PE/COFF image is not supported. **/ RETURN_STATUS @@ -687,6 +670,7 @@ PeCoffLoaderRelocateImage ( specified by the ImageAddress and ImageSize fields of ImageContext. The caller must allocate the load buffer and fill in the ImageAddress and ImageSize fields prior to calling this function. The EntryPoint, FixupDataSize, CodeView, and PdbPointer fields of ImageContext are computed. + If ImageContext is NULL, then ASSERT(). @param ImageContext Pointer to the image context structure that describes the PE/COFF image that is being loaded. @@ -724,8 +708,11 @@ PeCoffLoaderLoadImage ( UINTN Size; UINT32 TempDebugEntryRva; + ASSERT (ImageContext != NULL); + PeHdr = NULL; TeHdr = NULL; + // // Assume success // @@ -750,7 +737,13 @@ PeCoffLoaderLoadImage ( ImageContext->ImageError = IMAGE_ERROR_INVALID_IMAGE_SIZE; return RETURN_BUFFER_TOO_SMALL; } - + if (ImageContext->ImageAddress == 0) { + // + // Image cannot be loaded into 0 address. + // + ImageContext->ImageError = IMAGE_ERROR_INVALID_IMAGE_ADDRESS; + return RETURN_INVALID_PARAMETER; + } // // If there's no relocations, then make sure it's not a runtime driver, // and that it's being loaded at the linked address. diff --git a/MdePkg/Library/BasePeCoffLib/Ebc/PeCoffLoaderEx.c b/MdePkg/Library/BasePeCoffLib/Ebc/PeCoffLoaderEx.c index 6cfc566bd4..fe41ac03bd 100644 --- a/MdePkg/Library/BasePeCoffLib/Ebc/PeCoffLoaderEx.c +++ b/MdePkg/Library/BasePeCoffLib/Ebc/PeCoffLoaderEx.c @@ -18,17 +18,14 @@ /** - Performs an IA-32 specific relocation fixup. + Performs an EBC specific relocation fixup. - @param Reloc Pointer to the relocation record. + @param Reloc Pointer to the relocation record. + @param Fixup Pointer to the address to fix up. + @param FixupData Pointer to a buffer to log the fixups. + @param Adjust The offset to adjust the fixup. - @param Fixup Pointer to the address to fix up. - - @param FixupData Pointer to a buffer to log the fixups. - - @param Adjust The offset to adjust the fixup. - - @retval EFI_UNSUPPORTED Unsupported now. + @retval EFI_UNSUPPORTED Unsupported now. **/ RETURN_STATUS diff --git a/MdePkg/Library/BasePeCoffLib/Ia32/PeCoffLoaderEx.c b/MdePkg/Library/BasePeCoffLib/Ia32/PeCoffLoaderEx.c index 4ee64c2b36..9a2b2a04dd 100644 --- a/MdePkg/Library/BasePeCoffLib/Ia32/PeCoffLoaderEx.c +++ b/MdePkg/Library/BasePeCoffLib/Ia32/PeCoffLoaderEx.c @@ -21,15 +21,12 @@ /** Performs an IA-32 specific relocation fixup. - @param Reloc Pointer to the relocation record. + @param Reloc Pointer to the relocation record. + @param Fixup Pointer to the address to fix up. + @param FixupData Pointer to a buffer to log the fixups. + @param Adjust The offset to adjust the fixup. - @param Fixup Pointer to the address to fix up. - - @param FixupData Pointer to a buffer to log the fixups. - - @param Adjust The offset to adjust the fixup. - - @retval EFI_UNSUPPORTED Unsupported now. + @retval EFI_UNSUPPORTED Unsupported now. **/ RETURN_STATUS diff --git a/MdePkg/Library/BasePeCoffLib/Ipf/PeCoffLoaderEx.c b/MdePkg/Library/BasePeCoffLib/Ipf/PeCoffLoaderEx.c index d35231e9cd..57c6555408 100644 --- a/MdePkg/Library/BasePeCoffLib/Ipf/PeCoffLoaderEx.c +++ b/MdePkg/Library/BasePeCoffLib/Ipf/PeCoffLoaderEx.c @@ -68,13 +68,10 @@ /** Performs an Itanium-based specific relocation fixup. - @param Reloc Pointer to the relocation record. - - @param Fixup Pointer to the address to fix up. - - @param FixupData Pointer to a buffer to log the fixups. - - @param Adjust The offset to adjust the fixup. + @param Reloc Pointer to the relocation record. + @param Fixup Pointer to the address to fix up. + @param FixupData Pointer to a buffer to log the fixups. + @param Adjust The offset to adjust the fixup. @return Status code. diff --git a/MdePkg/Library/BasePeCoffLib/x64/PeCoffLoaderEx.c b/MdePkg/Library/BasePeCoffLib/x64/PeCoffLoaderEx.c index 7648447f71..db7eead97d 100644 --- a/MdePkg/Library/BasePeCoffLib/x64/PeCoffLoaderEx.c +++ b/MdePkg/Library/BasePeCoffLib/x64/PeCoffLoaderEx.c @@ -14,16 +14,13 @@ **/ - - - /** Performs an x64 specific relocation fixup. - @param Reloc Pointer to the relocation record - @param Fixup Pointer to the address to fix up - @param FixupData Pointer to a buffer to log the fixups - @param Adjust The offset to adjust the fixup + @param Reloc Pointer to the relocation record + @param Fixup Pointer to the address to fix up + @param FixupData Pointer to a buffer to log the fixups + @param Adjust The offset to adjust the fixup **/ RETURN_STATUS diff --git a/MdePkg/Library/BasePerformanceLibNull/PerformanceLib.c b/MdePkg/Library/BasePerformanceLibNull/PerformanceLib.c index 01226cbb02..ec88d848ae 100644 --- a/MdePkg/Library/BasePerformanceLibNull/PerformanceLib.c +++ b/MdePkg/Library/BasePerformanceLibNull/PerformanceLib.c @@ -82,34 +82,46 @@ EndPerformanceMeasurement ( } /** - Retrieves a previously logged performance measurement. + Attempts to retrieve a performance measurement log entry from the performance measurement log. - Retrieves the performance log entry from the performance log - that immediately follows the log entry specified by LogEntryKey. - If LogEntryKey is zero, then the first entry from the performance log is returned. - If the log entry specified by LogEntryKey is the last entry in the performance log, - then 0 is returned. Otherwise, the performance log entry is returned in Handle, - Token, Module, StartTimeStamp, and EndTimeStamp. - The key for the current performance log entry is returned. - - @param LogEntryKey The key for the previous performance measurement log entry. - If 0, then the first performance measurement log entry is retrieved. - @param Handle Pointer to environment specific context used - to identify the component being measured. - @param Token Pointer to a Null-terminated ASCII string - that identifies the component being measured. - @param Module Pointer to a Null-terminated ASCII string - that identifies the module being measured. - @param StartTimeStamp The 64-bit time stamp that was recorded when the measurement was started. - @param EndTimeStamp The 64-bit time stamp that was recorded when the measurement was ended. - - @return The key for the current performance log entry. + Attempts to retrieve the performance log entry specified by LogEntryKey. If LogEntryKey is + zero on entry, then an attempt is made to retrieve the first entry from the performance log, + and the key for the second entry in the log is returned. If the performance log is empty, + then no entry is retrieved and zero is returned. If LogEntryKey is not zero, then the performance + log entry associated with LogEntryKey is retrieved, and the key for the next entry in the log is + returned. If LogEntryKey is the key for the last entry in the log, then the last log entry is + retrieved and an implementation specific non-zero key value that specifies the end of the performance + log is returned. If LogEntryKey is equal this implementation specific non-zero key value, then no entry + is retrieved and zero is returned. In the cases where a performance log entry can be returned, + the log entry is returned in Handle, Token, Module, StartTimeStamp, and EndTimeStamp. + If LogEntryKey is not a valid log entry key for the performance measurement log, then ASSERT(). + If Handle is NULL, then ASSERT(). + If Token is NULL, then ASSERT(). + If Module is NULL, then ASSERT(). + If StartTimeStamp is NULL, then ASSERT(). + If EndTimeStamp is NULL, then ASSERT(). + + @param LogEntryKey On entry, the key of the performance measurement log entry to retrieve. + 0, then the first performance measurement log entry is retrieved. + On exit, the key of the next performance lof entry entry. + @param Handle Pointer to environment specific context used to identify the component + being measured. + @param Token Pointer to a Null-terminated ASCII string that identifies the component + being measured. + @param Module Pointer to a Null-terminated ASCII string that identifies the module + being measured. + @param StartTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement + was started. + @param EndTimeStamp Pointer to the 64-bit time stamp that was recorded when the measurement + was ended. + + @return The key for the next performance log entry (in general case). **/ UINTN EFIAPI GetPerformanceMeasurement ( - UINTN LogEntryKey, + IN UINTN LogEntryKey, OUT CONST VOID **Handle, OUT CONST CHAR8 **Token, OUT CONST CHAR8 **Module, diff --git a/MdePkg/Library/BasePrintLib/PrintLib.c b/MdePkg/Library/BasePrintLib/PrintLib.c index e940bedb34..0a8c22ed16 100644 --- a/MdePkg/Library/BasePrintLib/PrintLib.c +++ b/MdePkg/Library/BasePrintLib/PrintLib.c @@ -16,45 +16,41 @@ #include "PrintLibInternal.h" -typedef struct { - RETURN_STATUS Status; - CHAR8 *String; -} STATUS_LOOKUP_TABLE_ENTRY; - -static CONST STATUS_LOOKUP_TABLE_ENTRY StatusString[] = { - { RETURN_SUCCESS, "Success" }, - { RETURN_LOAD_ERROR, "Load Error" }, - { RETURN_INVALID_PARAMETER, "Invalid Parameter" }, - { RETURN_UNSUPPORTED, "Unsupported" }, - { RETURN_BAD_BUFFER_SIZE, "Bad Buffer Size" }, - { RETURN_BUFFER_TOO_SMALL, "Buffer Too Small" }, - { RETURN_NOT_READY, "Not Ready" }, - { RETURN_DEVICE_ERROR, "Device Error" }, - { RETURN_WRITE_PROTECTED, "Write Protected" }, - { RETURN_OUT_OF_RESOURCES, "Out of Resources" }, - { RETURN_VOLUME_CORRUPTED, "Volume Corrupt" }, - { RETURN_VOLUME_FULL, "Volume Full" }, - { RETURN_NO_MEDIA, "No Media" }, - { RETURN_MEDIA_CHANGED, "Media changed" }, - { RETURN_NOT_FOUND, "Not Found" }, - { RETURN_ACCESS_DENIED, "Access Denied" }, - { RETURN_NO_RESPONSE, "No Response" }, - { RETURN_NO_MAPPING, "No mapping" }, - { RETURN_TIMEOUT, "Time out" }, - { RETURN_NOT_STARTED, "Not started" }, - { RETURN_ALREADY_STARTED, "Already started" }, - { RETURN_ABORTED, "Aborted" }, - { RETURN_ICMP_ERROR, "ICMP Error" }, - { RETURN_TFTP_ERROR, "TFTP Error" }, - { RETURN_PROTOCOL_ERROR, "Protocol Error" }, - { RETURN_WARN_UNKNOWN_GLYPH, "Warning Unknown Glyph" }, - { RETURN_WARN_DELETE_FAILURE, "Warning Delete Failure" }, - { RETURN_WARN_WRITE_FAILURE, "Warning Write Failure" }, - { RETURN_WARN_BUFFER_TOO_SMALL, "Warning Buffer Too Small" }, - { 0, NULL } +#define WARNING_STATUS_NUMBER 4 +#define ERROR_STATUS_NUMBER 24 + +STATIC CONST CHAR8 *StatusString [] = { + "Success", // RETURN_SUCCESS = 0 + "Warning Unknown Glyph", // RETURN_WARN_UNKNOWN_GLYPH = 1 + "Warning Delete Failure", // RETURN_WARN_DELETE_FAILURE = 2 + "Warning Write Failure", // RETURN_WARN_WRITE_FAILURE = 3 + "Warning Buffer Too Small", // RETURN_WARN_BUFFER_TOO_SMALL = 4 + "Load Error", // RETURN_LOAD_ERROR = 1 | MAX_BIT + "Invalid Parameter", // RETURN_INVALID_PARAMETER = 2 | MAX_BIT + "Unsupported", // RETURN_UNSUPPORTED = 3 | MAX_BIT + "Bad Buffer Size", // RETURN_BAD_BUFFER_SIZE = 4 | MAX_BIT + "Buffer Too Small", // RETURN_BUFFER_TOO_SMALL, = 5 | MAX_BIT + "Not Ready", // RETURN_NOT_READY = 6 | MAX_BIT + "Device Error", // RETURN_DEVICE_ERROR = 7 | MAX_BIT + "Write Protected", // RETURN_WRITE_PROTECTED = 8 | MAX_BIT + "Out of Resources", // RETURN_OUT_OF_RESOURCES = 9 | MAX_BIT + "Volume Corrupt", // RETURN_VOLUME_CORRUPTED = 10 | MAX_BIT + "Volume Full", // RETURN_VOLUME_FULL = 11 | MAX_BIT + "No Media", // RETURN_NO_MEDIA = 12 | MAX_BIT + "Media changed", // RETURN_MEDIA_CHANGED = 13 | MAX_BIT + "Not Found", // RETURN_NOT_FOUND = 14 | MAX_BIT + "Access Denied", // RETURN_ACCESS_DENIED = 15 | MAX_BIT + "No Response", // RETURN_NO_RESPONSE = 16 | MAX_BIT + "No mapping", // RETURN_NO_MAPPING = 17 | MAX_BIT + "Time out", // RETURN_TIMEOUT = 18 | MAX_BIT + "Not started", // RETURN_NOT_STARTED = 19 | MAX_BIT + "Already started", // RETURN_ALREADY_STARTED = 20 | MAX_BIT + "Aborted", // RETURN_ABORTED = 21 | MAX_BIT + "ICMP Error", // RETURN_ICMP_ERROR = 22 | MAX_BIT + "TFTP Error", // RETURN_TFTP_ERROR = 23 | MAX_BIT + "Protocol Error" // RETURN_PROTOCOL_ERROR = 24 | MAX_BIT }; - /** Worker function that produces a Null-terminated string in an output buffer based on a Null-terminated format string and a VA_LIST argument list. @@ -92,7 +88,7 @@ BasePrintLibVSPrint ( UINTN Width; UINTN Precision; INT64 Value; - CHAR8 *ArgumentString; + CONST CHAR8 *ArgumentString; UINTN Character; GUID *TmpGuid; TIME *TmpTime; @@ -113,7 +109,6 @@ BasePrintLibVSPrint ( return 0; } ASSERT (Buffer != NULL); - ASSERT (Format != NULL); OriginalBuffer = Buffer; @@ -123,9 +118,19 @@ BasePrintLibVSPrint ( BytesPerOutputCharacter = 1; } if ((Flags & FORMAT_UNICODE) != 0) { + // + // Make sure format string cannot contain more than PcdMaximumUnicodeStringLength + // Unicode characters if PcdMaximumUnicodeStringLength is not zero. + // + ASSERT (StrSize ((CHAR16 *) Format) != 0); BytesPerFormatCharacter = 2; FormatMask = 0xffff; } else { + // + // Make sure format string cannot contain more than PcdMaximumUnicodeStringLength + // Ascii characters if PcdMaximumUnicodeStringLength is not zero. + // + ASSERT (AsciiStrSize (Format) != 0); BytesPerFormatCharacter = 1; FormatMask = 0xff; } @@ -381,9 +386,18 @@ BasePrintLibVSPrint ( case 'r': Status = VA_ARG (Marker, RETURN_STATUS); ArgumentString = ValueBuffer; - for (Index = 0; StatusString[Index].String != NULL; Index++) { - if (Status == StatusString[Index].Status) { - ArgumentString = StatusString[Index].String; + if (RETURN_ERROR (Status)) { + // + // Clear error bit + // + Index = Status & ~MAX_BIT; + if (Index > 0 && Index <= ERROR_STATUS_NUMBER) { + ArgumentString = StatusString [Index + WARNING_STATUS_NUMBER]; + } + } else { + Index = Status; + if (Index <= WARNING_STATUS_NUMBER) { + ArgumentString = StatusString [Index]; } } if (ArgumentString == ValueBuffer) { @@ -392,7 +406,7 @@ BasePrintLibVSPrint ( break; case '\n': - ArgumentString = "\r\n"; + ArgumentString = "\n\r"; break; case '%': @@ -405,6 +419,11 @@ BasePrintLibVSPrint ( break; } break; + + case '\n': + ArgumentString = "\n\r"; + break; + default: ArgumentString = (CHAR8 *)&FormatCharacter; Flags |= ARGUMENT_UNICODE; @@ -521,7 +540,18 @@ BasePrintLibVSPrint ( // Null terminate the Unicode or ASCII string // Buffer = BasePrintLibFillBuffer (Buffer, 1, 0, BytesPerOutputCharacter); + // + // Make sure output buffer cannot contain more than PcdMaximumUnicodeStringLength + // Unicode characters if PcdMaximumUnicodeStringLength is not zero. + // + ASSERT ((((Flags & OUTPUT_UNICODE) == 0)) || (StrSize ((CHAR16 *) OriginalBuffer) != 0)); + // + // Make sure output buffer cannot contain more than PcdMaximumUnicodeStringLength + // Ascii characters if PcdMaximumUnicodeStringLength is not zero. + // + ASSERT ((((Flags & OUTPUT_UNICODE) != 0)) || (AsciiStrSize (OriginalBuffer) != 0)); + return ((Buffer - OriginalBuffer) / BytesPerOutputCharacter); } diff --git a/MdePkg/Library/BaseSmbusLib/SmbusLib.c b/MdePkg/Library/BaseSmbusLib/SmbusLib.c index 29c09e730e..39fa7e6f37 100644 --- a/MdePkg/Library/BaseSmbusLib/SmbusLib.c +++ b/MdePkg/Library/BaseSmbusLib/SmbusLib.c @@ -18,9 +18,9 @@ #define SMBUS_LIB_SLAVE_ADDRESS(SmBusAddress) (((SmBusAddress) >> 1) & 0x7f) #define SMBUS_LIB_COMMAND(SmBusAddress) (((SmBusAddress) >> 8) & 0xff) -#define SMBUS_LIB_LENGTH(SmBusAddress) (((SmBusAddress) >> 16) & 0x1f) +#define SMBUS_LIB_LENGTH(SmBusAddress) (((SmBusAddress) >> 16) & 0x3f) #define SMBUS_LIB_PEC(SmBusAddress) ((BOOLEAN) (((SmBusAddress) & SMBUS_LIB_PEC_BIT) != 0)) -#define SMBUS_LIB_RESEARVED(SmBusAddress) ((SmBusAddress) & ~(((1 << 21) - 2) | SMBUS_LIB_PEC_BIT)) +#define SMBUS_LIB_RESEARVED(SmBusAddress) ((SmBusAddress) & ~(((1 << 22) - 2) | SMBUS_LIB_PEC_BIT)) // // Replaced by PCD @@ -639,14 +639,14 @@ SmBusProcessCall ( Bytes are read from the SMBUS and stored in Buffer. The number of bytes read is returned, and will never return a value larger than 32-bytes. If Status is not NULL, then the status of the executed command is returned in Status. - It is the caller¡¯s responsibility to make sure Buffer is large enough for the total number of bytes read. + It is the caller's responsibility to make sure Buffer is large enough for the total number of bytes read. SMBUS supports a maximum transfer size of 32 bytes, so Buffer does not need to be any larger than 32 bytes. @param HostControl The value of Host Control Register to set. @param SmBusAddress Address that encodes the SMBUS Slave Address, SMBUS Command, SMBUS Data Length, and PEC. - @param OutBuffer Pointer to the buffer of bytes to write to the SMBUS. - @param InBuffer Pointer to the buffer of bytes to read from the SMBUS. + @param WriteBuffer Pointer to the buffer of bytes to write to the SMBUS. + @param ReadBuffer Pointer to the buffer of bytes to read from the SMBUS. @param Status Return status for the executed command. This is an optional parameter and may be NULL. @@ -657,8 +657,8 @@ UINTN InternalSmBusBlock ( IN UINT8 HostControl, IN UINTN SmBusAddress, - IN UINT8 *OutBuffer, - OUT UINT8 *InBuffer, + IN UINT8 *WriteBuffer, + OUT UINT8 *ReadBuffer, OUT RETURN_STATUS *Status ) { @@ -667,7 +667,7 @@ InternalSmBusBlock ( UINTN BytesCount; UINT8 AuxiliaryControl; - BytesCount = SMBUS_LIB_LENGTH (SmBusAddress) + 1; + BytesCount = SMBUS_LIB_LENGTH (SmBusAddress); ReturnStatus = InternalSmBusAcquire (); if (RETURN_ERROR (ReturnStatus)) { @@ -684,9 +684,9 @@ InternalSmBusBlock ( InternalSmBusIoWrite8 (SMBUS_R_HST_D0, (UINT8) BytesCount); - if (OutBuffer != NULL) { + if (WriteBuffer != NULL) { for (Index = 0; Index < BytesCount; Index++) { - InternalSmBusIoWrite8 (SMBUS_R_HOST_BLOCK_DB, OutBuffer[Index]); + InternalSmBusIoWrite8 (SMBUS_R_HOST_BLOCK_DB, WriteBuffer[Index]); } } // @@ -711,9 +711,9 @@ InternalSmBusBlock ( } BytesCount = InternalSmBusIoRead8 (SMBUS_R_HST_D0); - if (InBuffer != NULL) { + if (ReadBuffer != NULL) { for (Index = 0; Index < BytesCount; Index++) { - InBuffer[Index] = InternalSmBusIoRead8 (SMBUS_R_HOST_BLOCK_DB); + ReadBuffer[Index] = InternalSmBusIoRead8 (SMBUS_R_HOST_BLOCK_DB); } } @@ -738,7 +738,7 @@ Done: Bytes are read from the SMBUS and stored in Buffer. The number of bytes read is returned, and will never return a value larger than 32-bytes. If Status is not NULL, then the status of the executed command is returned in Status. - It is the caller¡¯s responsibility to make sure Buffer is large enough for the total number of bytes read. + It is the caller's responsibility to make sure Buffer is large enough for the total number of bytes read. SMBUS supports a maximum transfer size of 32 bytes, so Buffer does not need to be any larger than 32 bytes. If Length in SmBusAddress is not zero, then ASSERT(). If Buffer is NULL, then ASSERT(). @@ -804,6 +804,8 @@ SmBusWriteBlock ( ) { ASSERT (Buffer != NULL); + ASSERT (SMBUS_LIB_LENGTH (SmBusAddress) >= 1); + ASSERT (SMBUS_LIB_LENGTH (SmBusAddress) <= 32); ASSERT (SMBUS_LIB_RESEARVED (SmBusAddress) == 0); return InternalSmBusBlock ( @@ -820,18 +822,19 @@ SmBusWriteBlock ( Executes an SMBUS block process call command on the SMBUS device specified by SmBusAddress. The SMBUS slave address, SMBUS command, and SMBUS length fields of SmBusAddress are required. - Bytes are written to the SMBUS from OutBuffer. Bytes are then read from the SMBUS into InBuffer. + Bytes are written to the SMBUS from WriteBuffer. Bytes are then read from the SMBUS into ReadBuffer. If Status is not NULL, then the status of the executed command is returned in Status. - It is the caller¡¯s responsibility to make sure InBuffer is large enough for the total number of bytes read. + It is the caller's responsibility to make sure ReadBuffer is large enough for the total number of bytes read. SMBUS supports a maximum transfer size of 32 bytes, so Buffer does not need to be any larger than 32 bytes. - If OutBuffer is NULL, then ASSERT(). - If InBuffer is NULL, then ASSERT(). + If Length in SmBusAddress is zero or greater than 32, then ASSERT(). + If WriteBuffer is NULL, then ASSERT(). + If ReadBuffer is NULL, then ASSERT(). If any reserved bits of SmBusAddress are set, then ASSERT(). @param SmBusAddress Address that encodes the SMBUS Slave Address, SMBUS Command, SMBUS Data Length, and PEC. - @param OutBuffer Pointer to the buffer of bytes to write to the SMBUS. - @param InBuffer Pointer to the buffer of bytes to read from the SMBUS. + @param WriteBuffer Pointer to the buffer of bytes to write to the SMBUS. + @param ReadBuffer Pointer to the buffer of bytes to read from the SMBUS. @param Status Return status for the executed command. This is an optional parameter and may be NULL. @@ -842,20 +845,22 @@ UINTN EFIAPI SmBusBlockProcessCall ( IN UINTN SmBusAddress, - IN VOID *OutBuffer, - OUT VOID *InBuffer, + IN VOID *WriteBuffer, + OUT VOID *ReadBuffer, OUT RETURN_STATUS *Status OPTIONAL ) { - ASSERT (InBuffer != NULL); - ASSERT (OutBuffer != NULL); + ASSERT (WriteBuffer != NULL); + ASSERT (ReadBuffer != NULL); + ASSERT (SMBUS_LIB_LENGTH (SmBusAddress) >= 1); + ASSERT (SMBUS_LIB_LENGTH (SmBusAddress) <= 32); ASSERT (SMBUS_LIB_RESEARVED (SmBusAddress) == 0); return InternalSmBusBlock ( SMBUS_V_SMB_CMD_BLOCK_PROCESS, SmBusAddress | SMBUS_B_WRITE, - OutBuffer, - InBuffer, + WriteBuffer, + ReadBuffer, Status ); } diff --git a/MdePkg/Library/DxeSmbusLib/InternalSmbusLib.h b/MdePkg/Library/DxeSmbusLib/InternalSmbusLib.h index bd6d57f2d3..47c00a7306 100644 --- a/MdePkg/Library/DxeSmbusLib/InternalSmbusLib.h +++ b/MdePkg/Library/DxeSmbusLib/InternalSmbusLib.h @@ -11,8 +11,6 @@ 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: SmbusLib.c - **/ #ifndef __INTERNAL_SMBUS_LIB_H @@ -20,9 +18,9 @@ Module Name: SmbusLib.c #define SMBUS_LIB_SLAVE_ADDRESS(SmBusAddress) (((SmBusAddress) >> 1) & 0x7f) #define SMBUS_LIB_COMMAND(SmBusAddress) (((SmBusAddress) >> 8) & 0xff) -#define SMBUS_LIB_LENGTH(SmBusAddress) (((SmBusAddress) >> 16) & 0x1f) +#define SMBUS_LIB_LENGTH(SmBusAddress) (((SmBusAddress) >> 16) & 0x3f) #define SMBUS_LIB_PEC(SmBusAddress) ((BOOLEAN) (((SmBusAddress) & SMBUS_LIB_PEC_BIT) != 0)) -#define SMBUS_LIB_RESEARVED(SmBusAddress) ((SmBusAddress) & ~(((1 << 21) - 2) | SMBUS_LIB_PEC_BIT)) +#define SMBUS_LIB_RESEARVED(SmBusAddress) ((SmBusAddress) & ~(((1 << 22) - 2) | SMBUS_LIB_PEC_BIT)) // // Declaration for internal functions diff --git a/MdePkg/Library/DxeSmbusLib/SmbusLib.c b/MdePkg/Library/DxeSmbusLib/SmbusLib.c index e71f11bef8..93fadb6598 100644 --- a/MdePkg/Library/DxeSmbusLib/SmbusLib.c +++ b/MdePkg/Library/DxeSmbusLib/SmbusLib.c @@ -350,7 +350,7 @@ SmBusProcessCall ( Bytes are read from the SMBUS and stored in Buffer. The number of bytes read is returned, and will never return a value larger than 32-bytes. If Status is not NULL, then the status of the executed command is returned in Status. - It is the caller¡¯s responsibility to make sure Buffer is large enough for the total number of bytes read. + It is the caller's responsibility to make sure Buffer is large enough for the total number of bytes read. SMBUS supports a maximum transfer size of 32 bytes, so Buffer does not need to be any larger than 32 bytes. If Length in SmBusAddress is not zero, then ASSERT(). If Buffer is NULL, then ASSERT(). @@ -412,9 +412,11 @@ SmBusWriteBlock ( UINTN Length; ASSERT (Buffer != NULL); + ASSERT (SMBUS_LIB_LENGTH (SmBusAddress) >= 1); + ASSERT (SMBUS_LIB_LENGTH (SmBusAddress) <= 32); ASSERT (SMBUS_LIB_RESEARVED (SmBusAddress) == 0); - Length = SMBUS_LIB_LENGTH (SmBusAddress) + 1; + Length = SMBUS_LIB_LENGTH (SmBusAddress); return InternalSmBusExec (EfiSmbusWriteBlock, SmBusAddress, Length, Buffer, Status); } @@ -423,19 +425,19 @@ SmBusWriteBlock ( Executes an SMBUS block process call command on the SMBUS device specified by SmBusAddress. The SMBUS slave address, SMBUS command, and SMBUS length fields of SmBusAddress are required. - Bytes are written to the SMBUS from OutBuffer. Bytes are then read from the SMBUS into InBuffer. + Bytes are written to the SMBUS from WriteBuffer. Bytes are then read from the SMBUS into ReadBuffer. If Status is not NULL, then the status of the executed command is returned in Status. - It is the caller¡¯s responsibility to make sure InBuffer is large enough for the total number of bytes read. + It is the caller's responsibility to make sure ReadBuffer is large enough for the total number of bytes read. SMBUS supports a maximum transfer size of 32 bytes, so Buffer does not need to be any larger than 32 bytes. - If OutBuffer is NULL, then ASSERT(). - If InBuffer is NULL, then ASSERT(). + If Length in SmBusAddress is zero or greater than 32, then ASSERT(). + If WriteBuffer is NULL, then ASSERT(). + If ReadBuffer is NULL, then ASSERT(). If any reserved bits of SmBusAddress are set, then ASSERT(). - @param SmBusAddress Address that encodes the SMBUS Slave Address, SMBUS Command, SMBUS Data Length, and PEC. - @param OutBuffer Pointer to the buffer of bytes to write to the SMBUS. - @param InBuffer Pointer to the buffer of bytes to read from the SMBUS. + @param WriteBuffer Pointer to the buffer of bytes to write to the SMBUS. + @param ReadBuffer Pointer to the buffer of bytes to read from the SMBUS. @param Status Return status for the executed command. This is an optional parameter and may be NULL. @@ -446,21 +448,23 @@ UINTN EFIAPI SmBusBlockProcessCall ( IN UINTN SmBusAddress, - IN VOID *OutBuffer, - OUT VOID *InBuffer, + IN VOID *WriteBuffer, + OUT VOID *ReadBuffer, OUT RETURN_STATUS *Status OPTIONAL ) { UINTN Length; - ASSERT (InBuffer != NULL); - ASSERT (OutBuffer != NULL); + ASSERT (WriteBuffer != NULL); + ASSERT (ReadBuffer != NULL); + ASSERT (SMBUS_LIB_LENGTH (SmBusAddress) >= 1); + ASSERT (SMBUS_LIB_LENGTH (SmBusAddress) <= 32); ASSERT (SMBUS_LIB_RESEARVED (SmBusAddress) == 0); - Length = SMBUS_LIB_LENGTH (SmBusAddress) + 1; + Length = SMBUS_LIB_LENGTH (SmBusAddress); // - // Assuming that InBuffer is large enough to save another memory copy. + // Assuming that ReadBuffer is large enough to save another memory copy. // - InBuffer = CopyMem (InBuffer, OutBuffer, Length); - return InternalSmBusExec (EfiSmbusBWBRProcessCall, SmBusAddress, Length, InBuffer, Status); + ReadBuffer = CopyMem (ReadBuffer, WriteBuffer, Length); + return InternalSmBusExec (EfiSmbusBWBRProcessCall, SmBusAddress, Length, ReadBuffer, Status); } diff --git a/MdePkg/Library/PeiMemoryLib/CompareMemWrapper.c b/MdePkg/Library/PeiMemoryLib/CompareMemWrapper.c index c8199d8dc3..6081bbe1b7 100644 --- a/MdePkg/Library/PeiMemoryLib/CompareMemWrapper.c +++ b/MdePkg/Library/PeiMemoryLib/CompareMemWrapper.c @@ -26,26 +26,25 @@ #include "MemLibInternals.h" /** - Compares two memory buffers of a given length. + Compares the contents of two buffers. - This function compares Length bytes of SourceBuffer to Length bytes of - DestinationBuffer. If all Length bytes of the two buffers are identical, then - 0 is returned. Otherwise, the value returned is the first mismatched byte in - SourceBuffer subtracted from the first mismatched byte in DestinationBuffer. + This function compares Length bytes of SourceBuffer to Length bytes of DestinationBuffer. + If all Length bytes of the two buffers are identical, then 0 is returned. Otherwise, the + value returned is the first mismatched byte in SourceBuffer subtracted from the first + mismatched byte in DestinationBuffer. + If Length > 0 and DestinationBuffer is NULL and Length > 0, then ASSERT(). + If Length > 0 and SourceBuffer is NULL and Length > 0, then ASSERT(). + If Length is greater than (MAX_ADDRESS - DestinationBuffer + 1), then ASSERT(). + If Length is greater than (MAX_ADDRESS - SourceBuffer + 1), then ASSERT(). - If DestinationBuffer is NULL and Length > 0, then ASSERT(). - If SourceBuffer is NULL and Length > 0, then ASSERT(). - If Length is greater than (MAX_ADDRESS - DestinationBuffer + 1), then - ASSERT(). - If Length is greater than (MAX_ADDRESS - SourceBuffer + 1), then ASSERT(). - @param DestinationBuffer First memory buffer - @param SourceBuffer Second memory buffer - @param Length Length of DestinationBuffer and SourceBuffer memory - regions to compare + @param DestinationBuffer Pointer to the destination buffer to compare. + @param SourceBuffer Pointer to the source buffer to compare. + @param Length Number of bytes to compare. - @retval 0 if DestinationBuffer == SourceBuffer - @retval Non-zero if DestinationBuffer != SourceBuffer + @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 @@ -56,12 +55,13 @@ CompareMem ( IN UINTN Length ) { - ASSERT (DestinationBuffer != NULL); - ASSERT (SourceBuffer != NULL); - ASSERT (Length <= MAX_ADDRESS - (UINTN)DestinationBuffer + 1); - ASSERT (Length <= MAX_ADDRESS - (UINTN)SourceBuffer + 1); if (Length == 0) { return 0; } + ASSERT (DestinationBuffer != NULL); + ASSERT (SourceBuffer != NULL); + ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)DestinationBuffer)); + ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)SourceBuffer)); + return InternalMemCompareMem (DestinationBuffer, SourceBuffer, Length); } diff --git a/MdePkg/Library/PeiMemoryLib/MemLibGeneric.c b/MdePkg/Library/PeiMemoryLib/MemLibGeneric.c index bda1f4992f..53c4e4416b 100644 --- a/MdePkg/Library/PeiMemoryLib/MemLibGeneric.c +++ b/MdePkg/Library/PeiMemoryLib/MemLibGeneric.c @@ -132,7 +132,6 @@ InternalMemCompareMem ( IN UINTN Length ) { - ASSERT (Length > 0); while ((--Length != 0) && (*(INT8*)DestinationBuffer == *(INT8*)SourceBuffer)) { DestinationBuffer = (INT8*)DestinationBuffer + 1; diff --git a/MdePkg/Library/PeiMemoryLib/ScanMem16Wrapper.c b/MdePkg/Library/PeiMemoryLib/ScanMem16Wrapper.c index a17705db1d..d336d59641 100644 --- a/MdePkg/Library/PeiMemoryLib/ScanMem16Wrapper.c +++ b/MdePkg/Library/PeiMemoryLib/ScanMem16Wrapper.c @@ -26,25 +26,22 @@ #include "MemLibInternals.h" /** - Scans a target buffer for a 16-bit value, and returns a pointer to the - matching 16-bit value in the target buffer. + Scans a target buffer for a 16-bit value, and returns a pointer to the matching 16-bit value + in the target buffer. - This function searches target the buffer specified by Buffer and Length from - the lowest address to the highest address at 16-bit increments for a 16-bit - value that matches Value. If a match is found, then a pointer to the matching - value in the target buffer is returned. If no match is found, then NULL is - returned. If Length is 0, then NULL is returned. - - If Buffer is NULL, then ASSERT(). + This function searches target the buffer specified by Buffer and Length from the lowest + address to the highest address for a 16-bit value that matches Value. If a match is found, + then a pointer to the matching byte in the target buffer is returned. If no match is found, + then NULL is returned. If Length is 0, then NULL is returned. + If Length > 0 and Buffer is NULL, then ASSERT(). If Buffer is not aligned on a 16-bit boundary, then ASSERT(). - If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). + If Length is greater than (MAX_ADDRESS – Buffer + 1), then ASSERT(). - @param Buffer Pointer to the target buffer to scan. - @param Length Number of bytes in Buffer to scan. - @param Value Value to search for in the target buffer. + @param Buffer Pointer to the target buffer to scan. + @param Length Number of bytes in Buffer to scan. + @param Value Value to search for in the target buffer. - @return Pointer to the first occurrence. - @retval NULL if Length == 0 or Value was not found. + @return A pointer to the matching byte in the target buffer or NULL otherwise. **/ VOID * @@ -55,12 +52,13 @@ ScanMem16 ( IN UINT16 Value ) { + if (Length == 0) { + return NULL; + } + ASSERT (Buffer != NULL); ASSERT (((UINTN)Buffer & (sizeof (Value) - 1)) == 0); - ASSERT (Length <= MAX_ADDRESS + (UINTN)Buffer + 1); + ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer)); - if ((Length /= sizeof (Value)) == 0) { - return NULL; - } - return (VOID*)InternalMemScanMem16 (Buffer, Length, Value); + return (VOID*)InternalMemScanMem16 (Buffer, Length / sizeof (Value), Value); } diff --git a/MdePkg/Library/PeiMemoryLib/ScanMem32Wrapper.c b/MdePkg/Library/PeiMemoryLib/ScanMem32Wrapper.c index 67eb84d8ef..8de55945ce 100644 --- a/MdePkg/Library/PeiMemoryLib/ScanMem32Wrapper.c +++ b/MdePkg/Library/PeiMemoryLib/ScanMem32Wrapper.c @@ -26,25 +26,22 @@ #include "MemLibInternals.h" /** - Scans a target buffer for a 32-bit value, and returns a pointer to the - matching 32-bit value in the target buffer. + Scans a target buffer for a 32-bit value, and returns a pointer to the matching 32-bit value + in the target buffer. - This function searches target the buffer specified by Buffer and Length from - the lowest address to the highest address at 32-bit increments for a 32-bit - value that matches Value. If a match is found, then a pointer to the matching - value in the target buffer is returned. If no match is found, then NULL is - returned. If Length is 0, then NULL is returned. - - If Buffer is NULL, then ASSERT(). + This function searches target the buffer specified by Buffer and Length from the lowest + address to the highest address for a 32-bit value that matches Value. If a match is found, + then a pointer to the matching byte in the target buffer is returned. If no match is found, + then NULL is returned. If Length is 0, then NULL is returned. + If Length > 0 and Buffer is NULL, then ASSERT(). If Buffer is not aligned on a 32-bit boundary, then ASSERT(). - If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). + If Length is greater than (MAX_ADDRESS – Buffer + 1), then ASSERT(). - @param Buffer Pointer to the target buffer to scan. - @param Length Number of bytes in Buffer to scan. - @param Value Value to search for in the target buffer. + @param Buffer Pointer to the target buffer to scan. + @param Length Number of bytes in Buffer to scan. + @param Value Value to search for in the target buffer. - @return Pointer to the first occurrence or NULL if not found. - @retval NULL if Length == 0 or Value was not found. + @return A pointer to the matching byte in the target buffer or NULL otherwise. **/ VOID * @@ -55,12 +52,13 @@ ScanMem32 ( IN UINT32 Value ) { + if (Length == 0) { + return NULL; + } + ASSERT (Buffer != NULL); ASSERT (((UINTN)Buffer & (sizeof (Value) - 1)) == 0); - ASSERT (Length <= MAX_ADDRESS + (UINTN)Buffer + 1); + ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer)); - if ((Length /= sizeof (Value)) == 0) { - return NULL; - } - return (VOID*)InternalMemScanMem32 (Buffer, Length, Value); + return (VOID*)InternalMemScanMem32 (Buffer, Length / sizeof (Value), Value); } diff --git a/MdePkg/Library/PeiMemoryLib/ScanMem64Wrapper.c b/MdePkg/Library/PeiMemoryLib/ScanMem64Wrapper.c index c5f0762ebe..228c864b04 100644 --- a/MdePkg/Library/PeiMemoryLib/ScanMem64Wrapper.c +++ b/MdePkg/Library/PeiMemoryLib/ScanMem64Wrapper.c @@ -26,25 +26,22 @@ #include "MemLibInternals.h" /** - Scans a target buffer for a 64-bit value, and returns a pointer to the - matching 64-bit value in the target buffer. + Scans a target buffer for a 64-bit value, and returns a pointer to the matching 64-bit value + in the target buffer. - This function searches target the buffer specified by Buffer and Length from - the lowest address to the highest address at 64-bit increments for a 64-bit - value that matches Value. If a match is found, then a pointer to the matching - value in the target buffer is returned. If no match is found, then NULL is - returned. If Length is 0, then NULL is returned. - - If Buffer is NULL, then ASSERT(). + This function searches target the buffer specified by Buffer and Length from the lowest + address to the highest address for a 64-bit value that matches Value. If a match is found, + then a pointer to the matching byte in the target buffer is returned. If no match is found, + then NULL is returned. If Length is 0, then NULL is returned. + If Length > 0 and Buffer is NULL, then ASSERT(). If Buffer is not aligned on a 64-bit boundary, then ASSERT(). - If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). + If Length is greater than (MAX_ADDRESS – Buffer + 1), then ASSERT(). - @param Buffer Pointer to the target buffer to scan. - @param Length Number of bytes in Buffer to scan. - @param Value Value to search for in the target buffer. + @param Buffer Pointer to the target buffer to scan. + @param Length Number of bytes in Buffer to scan. + @param Value Value to search for in the target buffer. - @return Pointer to the first occurrence or NULL if not found. - @retval NULL if Length == 0 or Value was not found. + @return A pointer to the matching byte in the target buffer or NULL otherwise. **/ VOID * @@ -55,12 +52,13 @@ ScanMem64 ( IN UINT64 Value ) { + if (Length == 0) { + return NULL; + } + ASSERT (Buffer != NULL); ASSERT (((UINTN)Buffer & (sizeof (Value) - 1)) == 0); - ASSERT (Length <= MAX_ADDRESS + (UINTN)Buffer + 1); + ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer)); - if ((Length /= sizeof (Value)) == 0) { - return NULL; - } - return (VOID*)InternalMemScanMem64 (Buffer, Length, Value); + return (VOID*)InternalMemScanMem64 (Buffer, Length / sizeof (Value), Value); } diff --git a/MdePkg/Library/PeiMemoryLib/ScanMem8Wrapper.c b/MdePkg/Library/PeiMemoryLib/ScanMem8Wrapper.c index 9b817b1b0e..72a8078b81 100644 --- a/MdePkg/Library/PeiMemoryLib/ScanMem8Wrapper.c +++ b/MdePkg/Library/PeiMemoryLib/ScanMem8Wrapper.c @@ -26,24 +26,21 @@ #include "MemLibInternals.h" /** - Scans a target buffer for an 8-bit value, and returns a pointer to the - matching 8-bit value in the target buffer. + Scans a target buffer for an 8-bit value, and returns a pointer to the matching 8-bit value + in the target buffer. - This function searches target the buffer specified by Buffer and Length from - the lowest address to the highest address for an 8-bit value that matches - Value. If a match is found, then a pointer to the matching byte in the target - buffer is returned. If no match is found, then NULL is returned. If Length is - 0, then NULL is returned. + This function searches target the buffer specified by Buffer and Length from the lowest + address to the highest address for an 8-bit value that matches Value. If a match is found, + then a pointer to the matching byte in the target buffer is returned. If no match is found, + then NULL is returned. If Length is 0, then NULL is returned. + If Length > 0 and Buffer is NULL, then ASSERT(). + If Length is greater than (MAX_ADDRESS – Buffer + 1), then ASSERT(). - If Buffer is NULL, then ASSERT(). - If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). + @param Buffer Pointer to the target buffer to scan. + @param Length Number of bytes in Buffer to scan. + @param Value Value to search for in the target buffer. - @param Buffer Pointer to the target buffer to scan. - @param Length Number of bytes in Buffer to scan. - @param Value Value to search for in the target buffer. - - @return Pointer to the first occurrence or NULL if not found. - @retval NULL if Length == 0 or Value was not found. + @return A pointer to the matching byte in the target buffer or NULL otherwise. **/ VOID * @@ -54,11 +51,11 @@ ScanMem8 ( IN UINT8 Value ) { - ASSERT (Buffer != NULL); - ASSERT (Length <= MAX_ADDRESS + (UINTN)Buffer + 1); - - if ((Length /= sizeof (Value)) == 0) { + if (Length == 0) { return NULL; } - return (VOID*)InternalMemScanMem8 (Buffer, Length, Value); + ASSERT (Buffer != NULL); + ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer)); + + return (VOID*)InternalMemScanMem8 (Buffer, Length / sizeof (Value), Value); } diff --git a/MdePkg/Library/PeiMemoryLib/SetMem16Wrapper.c b/MdePkg/Library/PeiMemoryLib/SetMem16Wrapper.c index dea31608fe..fd3720cd51 100644 --- a/MdePkg/Library/PeiMemoryLib/SetMem16Wrapper.c +++ b/MdePkg/Library/PeiMemoryLib/SetMem16Wrapper.c @@ -32,7 +32,7 @@ Value, and returns Buffer. Value is repeated every 16-bits in for Length bytes of Buffer. - If Buffer is NULL and Length > 0, then ASSERT(). + If Length > 0 and Buffer is NULL and Length > 0, then ASSERT(). If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). If Buffer is not aligned on a 16-bit boundary, then ASSERT(). If Length is not aligned on a 16-bit boundary, then ASSERT(). @@ -52,13 +52,14 @@ SetMem16 ( IN UINT16 Value ) { - ASSERT (!(Buffer == NULL && Length > 0)); - ASSERT (Length <= MAX_ADDRESS - (UINTN)Buffer + 1); + if (Length == 0) { + return Buffer; + } + + ASSERT (Buffer != NULL); + ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer)); ASSERT ((((UINTN)Buffer) & (sizeof (Value) - 1)) == 0); ASSERT ((Length & (sizeof (Value) - 1)) == 0); - if ((Length /= sizeof (Value)) == 0) { - return Buffer; - } - return InternalMemSetMem16 (Buffer, Length, Value); + return InternalMemSetMem16 (Buffer, Length / sizeof (Value), Value); } diff --git a/MdePkg/Library/PeiMemoryLib/SetMem32Wrapper.c b/MdePkg/Library/PeiMemoryLib/SetMem32Wrapper.c index 1ae7acb013..77f1abda04 100644 --- a/MdePkg/Library/PeiMemoryLib/SetMem32Wrapper.c +++ b/MdePkg/Library/PeiMemoryLib/SetMem32Wrapper.c @@ -32,7 +32,7 @@ Value, and returns Buffer. Value is repeated every 32-bits in for Length bytes of Buffer. - If Buffer is NULL and Length > 0, then ASSERT(). + If Length > 0 and Buffer is NULL and Length > 0, then ASSERT(). If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). If Buffer is not aligned on a 32-bit boundary, then ASSERT(). If Length is not aligned on a 32-bit boundary, then ASSERT(). @@ -52,13 +52,14 @@ SetMem32 ( IN UINT32 Value ) { - ASSERT (!(Buffer == NULL && Length > 0)); - ASSERT (Length <= MAX_ADDRESS - (UINTN)Buffer + 1); + if (Length == 0) { + return Buffer; + } + + ASSERT (Buffer != NULL); + ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer)); ASSERT ((((UINTN)Buffer) & (sizeof (Value) - 1)) == 0); ASSERT ((Length & (sizeof (Value) - 1)) == 0); - if ((Length /= sizeof (Value)) == 0) { - return Buffer; - } - return InternalMemSetMem32 (Buffer, Length, Value); + return InternalMemSetMem32 (Buffer, Length / sizeof (Value), Value); } diff --git a/MdePkg/Library/PeiMemoryLib/SetMem64Wrapper.c b/MdePkg/Library/PeiMemoryLib/SetMem64Wrapper.c index 0128a2d6f1..f95b97ff87 100644 --- a/MdePkg/Library/PeiMemoryLib/SetMem64Wrapper.c +++ b/MdePkg/Library/PeiMemoryLib/SetMem64Wrapper.c @@ -32,7 +32,7 @@ Value, and returns Buffer. Value is repeated every 64-bits in for Length bytes of Buffer. - If Buffer is NULL and Length > 0, then ASSERT(). + If Length > 0 and Buffer is NULL and Length > 0, then ASSERT(). If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). If Buffer is not aligned on a 64-bit boundary, then ASSERT(). If Length is not aligned on a 64-bit boundary, then ASSERT(). @@ -52,13 +52,14 @@ SetMem64 ( IN UINT64 Value ) { - ASSERT (!(Buffer == NULL && Length > 0)); - ASSERT (Length <= MAX_ADDRESS - (UINTN)Buffer + 1); + if (Length == 0) { + return Buffer; + } + + ASSERT (Buffer != NULL); + ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer)); ASSERT ((((UINTN)Buffer) & (sizeof (Value) - 1)) == 0); ASSERT ((Length & (sizeof (Value) - 1)) == 0); - if ((Length /= sizeof (Value)) == 0) { - return Buffer; - } - return InternalMemSetMem64 (Buffer, Length, Value); + return InternalMemSetMem64 (Buffer, Length / sizeof (Value), Value); } diff --git a/MdePkg/Library/PeiMemoryLib/SetMemWrapper.c b/MdePkg/Library/PeiMemoryLib/SetMemWrapper.c index 0600dc289f..d0e8760ff6 100644 --- a/MdePkg/Library/PeiMemoryLib/SetMemWrapper.c +++ b/MdePkg/Library/PeiMemoryLib/SetMemWrapper.c @@ -26,30 +26,31 @@ #include "MemLibInternals.h" /** - Set Buffer to Value for Size bytes. + Fills a target buffer with a byte value, and returns the target buffer. This function fills Length bytes of Buffer with Value, and returns Buffer. + If Length is greater than (MAX_ADDRESS – Buffer + 1), then ASSERT(). - If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). + @param Buffer Memory to set. + @param Length Number of bytes to set + @param Value Value of the set operation. - @param Buffer Memory to set. - @param Size Number of bytes to set - @param Value Value of the set operation. - - @return Buffer + @return Buffer. **/ VOID * EFIAPI SetMem ( IN VOID *Buffer, - IN UINTN Size, + IN UINTN Length, IN UINT8 Value ) { - if (Size == 0) { + if (Length == 0) { return Buffer; } - ASSERT (Size - 1 <= MAX_ADDRESS - (UINTN)Buffer); - return InternalMemSetMem (Buffer, Size, Value); + + ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer)); + + return InternalMemSetMem (Buffer, Length, Value); } diff --git a/MdePkg/Library/PeiSmbusLib/InternalSmbusLib.h b/MdePkg/Library/PeiSmbusLib/InternalSmbusLib.h index bd6d57f2d3..47c00a7306 100644 --- a/MdePkg/Library/PeiSmbusLib/InternalSmbusLib.h +++ b/MdePkg/Library/PeiSmbusLib/InternalSmbusLib.h @@ -11,8 +11,6 @@ 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: SmbusLib.c - **/ #ifndef __INTERNAL_SMBUS_LIB_H @@ -20,9 +18,9 @@ Module Name: SmbusLib.c #define SMBUS_LIB_SLAVE_ADDRESS(SmBusAddress) (((SmBusAddress) >> 1) & 0x7f) #define SMBUS_LIB_COMMAND(SmBusAddress) (((SmBusAddress) >> 8) & 0xff) -#define SMBUS_LIB_LENGTH(SmBusAddress) (((SmBusAddress) >> 16) & 0x1f) +#define SMBUS_LIB_LENGTH(SmBusAddress) (((SmBusAddress) >> 16) & 0x3f) #define SMBUS_LIB_PEC(SmBusAddress) ((BOOLEAN) (((SmBusAddress) & SMBUS_LIB_PEC_BIT) != 0)) -#define SMBUS_LIB_RESEARVED(SmBusAddress) ((SmBusAddress) & ~(((1 << 21) - 2) | SMBUS_LIB_PEC_BIT)) +#define SMBUS_LIB_RESEARVED(SmBusAddress) ((SmBusAddress) & ~(((1 << 22) - 2) | SMBUS_LIB_PEC_BIT)) // // Declaration for internal functions diff --git a/MdePkg/Library/PeiSmbusLib/SmbusLib.c b/MdePkg/Library/PeiSmbusLib/SmbusLib.c index e71f11bef8..93fadb6598 100644 --- a/MdePkg/Library/PeiSmbusLib/SmbusLib.c +++ b/MdePkg/Library/PeiSmbusLib/SmbusLib.c @@ -350,7 +350,7 @@ SmBusProcessCall ( Bytes are read from the SMBUS and stored in Buffer. The number of bytes read is returned, and will never return a value larger than 32-bytes. If Status is not NULL, then the status of the executed command is returned in Status. - It is the caller¡¯s responsibility to make sure Buffer is large enough for the total number of bytes read. + It is the caller's responsibility to make sure Buffer is large enough for the total number of bytes read. SMBUS supports a maximum transfer size of 32 bytes, so Buffer does not need to be any larger than 32 bytes. If Length in SmBusAddress is not zero, then ASSERT(). If Buffer is NULL, then ASSERT(). @@ -412,9 +412,11 @@ SmBusWriteBlock ( UINTN Length; ASSERT (Buffer != NULL); + ASSERT (SMBUS_LIB_LENGTH (SmBusAddress) >= 1); + ASSERT (SMBUS_LIB_LENGTH (SmBusAddress) <= 32); ASSERT (SMBUS_LIB_RESEARVED (SmBusAddress) == 0); - Length = SMBUS_LIB_LENGTH (SmBusAddress) + 1; + Length = SMBUS_LIB_LENGTH (SmBusAddress); return InternalSmBusExec (EfiSmbusWriteBlock, SmBusAddress, Length, Buffer, Status); } @@ -423,19 +425,19 @@ SmBusWriteBlock ( Executes an SMBUS block process call command on the SMBUS device specified by SmBusAddress. The SMBUS slave address, SMBUS command, and SMBUS length fields of SmBusAddress are required. - Bytes are written to the SMBUS from OutBuffer. Bytes are then read from the SMBUS into InBuffer. + Bytes are written to the SMBUS from WriteBuffer. Bytes are then read from the SMBUS into ReadBuffer. If Status is not NULL, then the status of the executed command is returned in Status. - It is the caller¡¯s responsibility to make sure InBuffer is large enough for the total number of bytes read. + It is the caller's responsibility to make sure ReadBuffer is large enough for the total number of bytes read. SMBUS supports a maximum transfer size of 32 bytes, so Buffer does not need to be any larger than 32 bytes. - If OutBuffer is NULL, then ASSERT(). - If InBuffer is NULL, then ASSERT(). + If Length in SmBusAddress is zero or greater than 32, then ASSERT(). + If WriteBuffer is NULL, then ASSERT(). + If ReadBuffer is NULL, then ASSERT(). If any reserved bits of SmBusAddress are set, then ASSERT(). - @param SmBusAddress Address that encodes the SMBUS Slave Address, SMBUS Command, SMBUS Data Length, and PEC. - @param OutBuffer Pointer to the buffer of bytes to write to the SMBUS. - @param InBuffer Pointer to the buffer of bytes to read from the SMBUS. + @param WriteBuffer Pointer to the buffer of bytes to write to the SMBUS. + @param ReadBuffer Pointer to the buffer of bytes to read from the SMBUS. @param Status Return status for the executed command. This is an optional parameter and may be NULL. @@ -446,21 +448,23 @@ UINTN EFIAPI SmBusBlockProcessCall ( IN UINTN SmBusAddress, - IN VOID *OutBuffer, - OUT VOID *InBuffer, + IN VOID *WriteBuffer, + OUT VOID *ReadBuffer, OUT RETURN_STATUS *Status OPTIONAL ) { UINTN Length; - ASSERT (InBuffer != NULL); - ASSERT (OutBuffer != NULL); + ASSERT (WriteBuffer != NULL); + ASSERT (ReadBuffer != NULL); + ASSERT (SMBUS_LIB_LENGTH (SmBusAddress) >= 1); + ASSERT (SMBUS_LIB_LENGTH (SmBusAddress) <= 32); ASSERT (SMBUS_LIB_RESEARVED (SmBusAddress) == 0); - Length = SMBUS_LIB_LENGTH (SmBusAddress) + 1; + Length = SMBUS_LIB_LENGTH (SmBusAddress); // - // Assuming that InBuffer is large enough to save another memory copy. + // Assuming that ReadBuffer is large enough to save another memory copy. // - InBuffer = CopyMem (InBuffer, OutBuffer, Length); - return InternalSmBusExec (EfiSmbusBWBRProcessCall, SmBusAddress, Length, InBuffer, Status); + ReadBuffer = CopyMem (ReadBuffer, WriteBuffer, Length); + return InternalSmBusExec (EfiSmbusBWBRProcessCall, SmBusAddress, Length, ReadBuffer, Status); } diff --git a/MdePkg/Library/UefiMemoryLib/CompareMemWrapper.c b/MdePkg/Library/UefiMemoryLib/CompareMemWrapper.c index c8199d8dc3..6081bbe1b7 100644 --- a/MdePkg/Library/UefiMemoryLib/CompareMemWrapper.c +++ b/MdePkg/Library/UefiMemoryLib/CompareMemWrapper.c @@ -26,26 +26,25 @@ #include "MemLibInternals.h" /** - Compares two memory buffers of a given length. + Compares the contents of two buffers. - This function compares Length bytes of SourceBuffer to Length bytes of - DestinationBuffer. If all Length bytes of the two buffers are identical, then - 0 is returned. Otherwise, the value returned is the first mismatched byte in - SourceBuffer subtracted from the first mismatched byte in DestinationBuffer. + This function compares Length bytes of SourceBuffer to Length bytes of DestinationBuffer. + If all Length bytes of the two buffers are identical, then 0 is returned. Otherwise, the + value returned is the first mismatched byte in SourceBuffer subtracted from the first + mismatched byte in DestinationBuffer. + If Length > 0 and DestinationBuffer is NULL and Length > 0, then ASSERT(). + If Length > 0 and SourceBuffer is NULL and Length > 0, then ASSERT(). + If Length is greater than (MAX_ADDRESS - DestinationBuffer + 1), then ASSERT(). + If Length is greater than (MAX_ADDRESS - SourceBuffer + 1), then ASSERT(). - If DestinationBuffer is NULL and Length > 0, then ASSERT(). - If SourceBuffer is NULL and Length > 0, then ASSERT(). - If Length is greater than (MAX_ADDRESS - DestinationBuffer + 1), then - ASSERT(). - If Length is greater than (MAX_ADDRESS - SourceBuffer + 1), then ASSERT(). - @param DestinationBuffer First memory buffer - @param SourceBuffer Second memory buffer - @param Length Length of DestinationBuffer and SourceBuffer memory - regions to compare + @param DestinationBuffer Pointer to the destination buffer to compare. + @param SourceBuffer Pointer to the source buffer to compare. + @param Length Number of bytes to compare. - @retval 0 if DestinationBuffer == SourceBuffer - @retval Non-zero if DestinationBuffer != SourceBuffer + @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 @@ -56,12 +55,13 @@ CompareMem ( IN UINTN Length ) { - ASSERT (DestinationBuffer != NULL); - ASSERT (SourceBuffer != NULL); - ASSERT (Length <= MAX_ADDRESS - (UINTN)DestinationBuffer + 1); - ASSERT (Length <= MAX_ADDRESS - (UINTN)SourceBuffer + 1); if (Length == 0) { return 0; } + ASSERT (DestinationBuffer != NULL); + ASSERT (SourceBuffer != NULL); + ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)DestinationBuffer)); + ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)SourceBuffer)); + return InternalMemCompareMem (DestinationBuffer, SourceBuffer, Length); } diff --git a/MdePkg/Library/UefiMemoryLib/MemLibGeneric.c b/MdePkg/Library/UefiMemoryLib/MemLibGeneric.c index bda1f4992f..53c4e4416b 100644 --- a/MdePkg/Library/UefiMemoryLib/MemLibGeneric.c +++ b/MdePkg/Library/UefiMemoryLib/MemLibGeneric.c @@ -132,7 +132,6 @@ InternalMemCompareMem ( IN UINTN Length ) { - ASSERT (Length > 0); while ((--Length != 0) && (*(INT8*)DestinationBuffer == *(INT8*)SourceBuffer)) { DestinationBuffer = (INT8*)DestinationBuffer + 1; diff --git a/MdePkg/Library/UefiMemoryLib/ScanMem16Wrapper.c b/MdePkg/Library/UefiMemoryLib/ScanMem16Wrapper.c index a17705db1d..d336d59641 100644 --- a/MdePkg/Library/UefiMemoryLib/ScanMem16Wrapper.c +++ b/MdePkg/Library/UefiMemoryLib/ScanMem16Wrapper.c @@ -26,25 +26,22 @@ #include "MemLibInternals.h" /** - Scans a target buffer for a 16-bit value, and returns a pointer to the - matching 16-bit value in the target buffer. + Scans a target buffer for a 16-bit value, and returns a pointer to the matching 16-bit value + in the target buffer. - This function searches target the buffer specified by Buffer and Length from - the lowest address to the highest address at 16-bit increments for a 16-bit - value that matches Value. If a match is found, then a pointer to the matching - value in the target buffer is returned. If no match is found, then NULL is - returned. If Length is 0, then NULL is returned. - - If Buffer is NULL, then ASSERT(). + This function searches target the buffer specified by Buffer and Length from the lowest + address to the highest address for a 16-bit value that matches Value. If a match is found, + then a pointer to the matching byte in the target buffer is returned. If no match is found, + then NULL is returned. If Length is 0, then NULL is returned. + If Length > 0 and Buffer is NULL, then ASSERT(). If Buffer is not aligned on a 16-bit boundary, then ASSERT(). - If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). + If Length is greater than (MAX_ADDRESS – Buffer + 1), then ASSERT(). - @param Buffer Pointer to the target buffer to scan. - @param Length Number of bytes in Buffer to scan. - @param Value Value to search for in the target buffer. + @param Buffer Pointer to the target buffer to scan. + @param Length Number of bytes in Buffer to scan. + @param Value Value to search for in the target buffer. - @return Pointer to the first occurrence. - @retval NULL if Length == 0 or Value was not found. + @return A pointer to the matching byte in the target buffer or NULL otherwise. **/ VOID * @@ -55,12 +52,13 @@ ScanMem16 ( IN UINT16 Value ) { + if (Length == 0) { + return NULL; + } + ASSERT (Buffer != NULL); ASSERT (((UINTN)Buffer & (sizeof (Value) - 1)) == 0); - ASSERT (Length <= MAX_ADDRESS + (UINTN)Buffer + 1); + ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer)); - if ((Length /= sizeof (Value)) == 0) { - return NULL; - } - return (VOID*)InternalMemScanMem16 (Buffer, Length, Value); + return (VOID*)InternalMemScanMem16 (Buffer, Length / sizeof (Value), Value); } diff --git a/MdePkg/Library/UefiMemoryLib/ScanMem32Wrapper.c b/MdePkg/Library/UefiMemoryLib/ScanMem32Wrapper.c index 67eb84d8ef..8de55945ce 100644 --- a/MdePkg/Library/UefiMemoryLib/ScanMem32Wrapper.c +++ b/MdePkg/Library/UefiMemoryLib/ScanMem32Wrapper.c @@ -26,25 +26,22 @@ #include "MemLibInternals.h" /** - Scans a target buffer for a 32-bit value, and returns a pointer to the - matching 32-bit value in the target buffer. + Scans a target buffer for a 32-bit value, and returns a pointer to the matching 32-bit value + in the target buffer. - This function searches target the buffer specified by Buffer and Length from - the lowest address to the highest address at 32-bit increments for a 32-bit - value that matches Value. If a match is found, then a pointer to the matching - value in the target buffer is returned. If no match is found, then NULL is - returned. If Length is 0, then NULL is returned. - - If Buffer is NULL, then ASSERT(). + This function searches target the buffer specified by Buffer and Length from the lowest + address to the highest address for a 32-bit value that matches Value. If a match is found, + then a pointer to the matching byte in the target buffer is returned. If no match is found, + then NULL is returned. If Length is 0, then NULL is returned. + If Length > 0 and Buffer is NULL, then ASSERT(). If Buffer is not aligned on a 32-bit boundary, then ASSERT(). - If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). + If Length is greater than (MAX_ADDRESS – Buffer + 1), then ASSERT(). - @param Buffer Pointer to the target buffer to scan. - @param Length Number of bytes in Buffer to scan. - @param Value Value to search for in the target buffer. + @param Buffer Pointer to the target buffer to scan. + @param Length Number of bytes in Buffer to scan. + @param Value Value to search for in the target buffer. - @return Pointer to the first occurrence or NULL if not found. - @retval NULL if Length == 0 or Value was not found. + @return A pointer to the matching byte in the target buffer or NULL otherwise. **/ VOID * @@ -55,12 +52,13 @@ ScanMem32 ( IN UINT32 Value ) { + if (Length == 0) { + return NULL; + } + ASSERT (Buffer != NULL); ASSERT (((UINTN)Buffer & (sizeof (Value) - 1)) == 0); - ASSERT (Length <= MAX_ADDRESS + (UINTN)Buffer + 1); + ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer)); - if ((Length /= sizeof (Value)) == 0) { - return NULL; - } - return (VOID*)InternalMemScanMem32 (Buffer, Length, Value); + return (VOID*)InternalMemScanMem32 (Buffer, Length / sizeof (Value), Value); } diff --git a/MdePkg/Library/UefiMemoryLib/ScanMem64Wrapper.c b/MdePkg/Library/UefiMemoryLib/ScanMem64Wrapper.c index c5f0762ebe..228c864b04 100644 --- a/MdePkg/Library/UefiMemoryLib/ScanMem64Wrapper.c +++ b/MdePkg/Library/UefiMemoryLib/ScanMem64Wrapper.c @@ -26,25 +26,22 @@ #include "MemLibInternals.h" /** - Scans a target buffer for a 64-bit value, and returns a pointer to the - matching 64-bit value in the target buffer. + Scans a target buffer for a 64-bit value, and returns a pointer to the matching 64-bit value + in the target buffer. - This function searches target the buffer specified by Buffer and Length from - the lowest address to the highest address at 64-bit increments for a 64-bit - value that matches Value. If a match is found, then a pointer to the matching - value in the target buffer is returned. If no match is found, then NULL is - returned. If Length is 0, then NULL is returned. - - If Buffer is NULL, then ASSERT(). + This function searches target the buffer specified by Buffer and Length from the lowest + address to the highest address for a 64-bit value that matches Value. If a match is found, + then a pointer to the matching byte in the target buffer is returned. If no match is found, + then NULL is returned. If Length is 0, then NULL is returned. + If Length > 0 and Buffer is NULL, then ASSERT(). If Buffer is not aligned on a 64-bit boundary, then ASSERT(). - If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). + If Length is greater than (MAX_ADDRESS – Buffer + 1), then ASSERT(). - @param Buffer Pointer to the target buffer to scan. - @param Length Number of bytes in Buffer to scan. - @param Value Value to search for in the target buffer. + @param Buffer Pointer to the target buffer to scan. + @param Length Number of bytes in Buffer to scan. + @param Value Value to search for in the target buffer. - @return Pointer to the first occurrence or NULL if not found. - @retval NULL if Length == 0 or Value was not found. + @return A pointer to the matching byte in the target buffer or NULL otherwise. **/ VOID * @@ -55,12 +52,13 @@ ScanMem64 ( IN UINT64 Value ) { + if (Length == 0) { + return NULL; + } + ASSERT (Buffer != NULL); ASSERT (((UINTN)Buffer & (sizeof (Value) - 1)) == 0); - ASSERT (Length <= MAX_ADDRESS + (UINTN)Buffer + 1); + ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer)); - if ((Length /= sizeof (Value)) == 0) { - return NULL; - } - return (VOID*)InternalMemScanMem64 (Buffer, Length, Value); + return (VOID*)InternalMemScanMem64 (Buffer, Length / sizeof (Value), Value); } diff --git a/MdePkg/Library/UefiMemoryLib/ScanMem8Wrapper.c b/MdePkg/Library/UefiMemoryLib/ScanMem8Wrapper.c index 9b817b1b0e..72a8078b81 100644 --- a/MdePkg/Library/UefiMemoryLib/ScanMem8Wrapper.c +++ b/MdePkg/Library/UefiMemoryLib/ScanMem8Wrapper.c @@ -26,24 +26,21 @@ #include "MemLibInternals.h" /** - Scans a target buffer for an 8-bit value, and returns a pointer to the - matching 8-bit value in the target buffer. + Scans a target buffer for an 8-bit value, and returns a pointer to the matching 8-bit value + in the target buffer. - This function searches target the buffer specified by Buffer and Length from - the lowest address to the highest address for an 8-bit value that matches - Value. If a match is found, then a pointer to the matching byte in the target - buffer is returned. If no match is found, then NULL is returned. If Length is - 0, then NULL is returned. + This function searches target the buffer specified by Buffer and Length from the lowest + address to the highest address for an 8-bit value that matches Value. If a match is found, + then a pointer to the matching byte in the target buffer is returned. If no match is found, + then NULL is returned. If Length is 0, then NULL is returned. + If Length > 0 and Buffer is NULL, then ASSERT(). + If Length is greater than (MAX_ADDRESS – Buffer + 1), then ASSERT(). - If Buffer is NULL, then ASSERT(). - If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). + @param Buffer Pointer to the target buffer to scan. + @param Length Number of bytes in Buffer to scan. + @param Value Value to search for in the target buffer. - @param Buffer Pointer to the target buffer to scan. - @param Length Number of bytes in Buffer to scan. - @param Value Value to search for in the target buffer. - - @return Pointer to the first occurrence or NULL if not found. - @retval NULL if Length == 0 or Value was not found. + @return A pointer to the matching byte in the target buffer or NULL otherwise. **/ VOID * @@ -54,11 +51,11 @@ ScanMem8 ( IN UINT8 Value ) { - ASSERT (Buffer != NULL); - ASSERT (Length <= MAX_ADDRESS + (UINTN)Buffer + 1); - - if ((Length /= sizeof (Value)) == 0) { + if (Length == 0) { return NULL; } - return (VOID*)InternalMemScanMem8 (Buffer, Length, Value); + ASSERT (Buffer != NULL); + ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer)); + + return (VOID*)InternalMemScanMem8 (Buffer, Length / sizeof (Value), Value); } diff --git a/MdePkg/Library/UefiMemoryLib/SetMem16Wrapper.c b/MdePkg/Library/UefiMemoryLib/SetMem16Wrapper.c index dea31608fe..fd3720cd51 100644 --- a/MdePkg/Library/UefiMemoryLib/SetMem16Wrapper.c +++ b/MdePkg/Library/UefiMemoryLib/SetMem16Wrapper.c @@ -32,7 +32,7 @@ Value, and returns Buffer. Value is repeated every 16-bits in for Length bytes of Buffer. - If Buffer is NULL and Length > 0, then ASSERT(). + If Length > 0 and Buffer is NULL and Length > 0, then ASSERT(). If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). If Buffer is not aligned on a 16-bit boundary, then ASSERT(). If Length is not aligned on a 16-bit boundary, then ASSERT(). @@ -52,13 +52,14 @@ SetMem16 ( IN UINT16 Value ) { - ASSERT (!(Buffer == NULL && Length > 0)); - ASSERT (Length <= MAX_ADDRESS - (UINTN)Buffer + 1); + if (Length == 0) { + return Buffer; + } + + ASSERT (Buffer != NULL); + ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer)); ASSERT ((((UINTN)Buffer) & (sizeof (Value) - 1)) == 0); ASSERT ((Length & (sizeof (Value) - 1)) == 0); - if ((Length /= sizeof (Value)) == 0) { - return Buffer; - } - return InternalMemSetMem16 (Buffer, Length, Value); + return InternalMemSetMem16 (Buffer, Length / sizeof (Value), Value); } diff --git a/MdePkg/Library/UefiMemoryLib/SetMem32Wrapper.c b/MdePkg/Library/UefiMemoryLib/SetMem32Wrapper.c index 1ae7acb013..77f1abda04 100644 --- a/MdePkg/Library/UefiMemoryLib/SetMem32Wrapper.c +++ b/MdePkg/Library/UefiMemoryLib/SetMem32Wrapper.c @@ -32,7 +32,7 @@ Value, and returns Buffer. Value is repeated every 32-bits in for Length bytes of Buffer. - If Buffer is NULL and Length > 0, then ASSERT(). + If Length > 0 and Buffer is NULL and Length > 0, then ASSERT(). If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). If Buffer is not aligned on a 32-bit boundary, then ASSERT(). If Length is not aligned on a 32-bit boundary, then ASSERT(). @@ -52,13 +52,14 @@ SetMem32 ( IN UINT32 Value ) { - ASSERT (!(Buffer == NULL && Length > 0)); - ASSERT (Length <= MAX_ADDRESS - (UINTN)Buffer + 1); + if (Length == 0) { + return Buffer; + } + + ASSERT (Buffer != NULL); + ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer)); ASSERT ((((UINTN)Buffer) & (sizeof (Value) - 1)) == 0); ASSERT ((Length & (sizeof (Value) - 1)) == 0); - if ((Length /= sizeof (Value)) == 0) { - return Buffer; - } - return InternalMemSetMem32 (Buffer, Length, Value); + return InternalMemSetMem32 (Buffer, Length / sizeof (Value), Value); } diff --git a/MdePkg/Library/UefiMemoryLib/SetMem64Wrapper.c b/MdePkg/Library/UefiMemoryLib/SetMem64Wrapper.c index 0128a2d6f1..f95b97ff87 100644 --- a/MdePkg/Library/UefiMemoryLib/SetMem64Wrapper.c +++ b/MdePkg/Library/UefiMemoryLib/SetMem64Wrapper.c @@ -32,7 +32,7 @@ Value, and returns Buffer. Value is repeated every 64-bits in for Length bytes of Buffer. - If Buffer is NULL and Length > 0, then ASSERT(). + If Length > 0 and Buffer is NULL and Length > 0, then ASSERT(). If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). If Buffer is not aligned on a 64-bit boundary, then ASSERT(). If Length is not aligned on a 64-bit boundary, then ASSERT(). @@ -52,13 +52,14 @@ SetMem64 ( IN UINT64 Value ) { - ASSERT (!(Buffer == NULL && Length > 0)); - ASSERT (Length <= MAX_ADDRESS - (UINTN)Buffer + 1); + if (Length == 0) { + return Buffer; + } + + ASSERT (Buffer != NULL); + ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer)); ASSERT ((((UINTN)Buffer) & (sizeof (Value) - 1)) == 0); ASSERT ((Length & (sizeof (Value) - 1)) == 0); - if ((Length /= sizeof (Value)) == 0) { - return Buffer; - } - return InternalMemSetMem64 (Buffer, Length, Value); + return InternalMemSetMem64 (Buffer, Length / sizeof (Value), Value); } diff --git a/MdePkg/Library/UefiMemoryLib/SetMemWrapper.c b/MdePkg/Library/UefiMemoryLib/SetMemWrapper.c index 0600dc289f..d0e8760ff6 100644 --- a/MdePkg/Library/UefiMemoryLib/SetMemWrapper.c +++ b/MdePkg/Library/UefiMemoryLib/SetMemWrapper.c @@ -26,30 +26,31 @@ #include "MemLibInternals.h" /** - Set Buffer to Value for Size bytes. + Fills a target buffer with a byte value, and returns the target buffer. This function fills Length bytes of Buffer with Value, and returns Buffer. + If Length is greater than (MAX_ADDRESS – Buffer + 1), then ASSERT(). - If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). + @param Buffer Memory to set. + @param Length Number of bytes to set + @param Value Value of the set operation. - @param Buffer Memory to set. - @param Size Number of bytes to set - @param Value Value of the set operation. - - @return Buffer + @return Buffer. **/ VOID * EFIAPI SetMem ( IN VOID *Buffer, - IN UINTN Size, + IN UINTN Length, IN UINT8 Value ) { - if (Size == 0) { + if (Length == 0) { return Buffer; } - ASSERT (Size - 1 <= MAX_ADDRESS - (UINTN)Buffer); - return InternalMemSetMem (Buffer, Size, Value); + + ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer)); + + return InternalMemSetMem (Buffer, Length, Value); } -- cgit v1.2.3