From: qhuang8 Date: Thu, 22 Jun 2006 06:08:00 +0000 (+0000) Subject: 1. UINTN & INTN issue for EBC architecture: X-Git-Tag: edk2-stable201903~25200 X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=commitdiff_plain;h=4ba61e5e2a1b3cec7faaad36c252738f6f57f8a6 1. UINTN & INTN issue for EBC architecture: The MAX_BIT of EBC will no longer be fixed to bit 63. It is defined as (1ULL << (sizeof (INTN) * 8 - 1)). Make EdkModulePkg & MdePkg EBC compiler clean: treat all EFI_STATUS error code as variable. 2. PrintLib Complete all missing ASSERT()s. Fix “\n” & “%\n” issue thanks to the clarification of MWG 0.56d. Adjust StatusString array to support EBC build. 3. BaseMemoryLib Adjust ASSERT () & function header of ComparaMem, SetMemXX, ScanMemXX to synchronize with MWG 0.56d. 4.SmbusLib Change Pec bit to bit 22 SmBusAddress to synchronize MWG 0.56d. Add ASSERT()s to check if length is illegal for SmBusBlockWrite() & SmBusProcessBlock() since it is 6 bit now. 5. PerformanceLib Rename “EdkDxePerformanceLib” & “EdkPeiPerformanceLib” to “DxePerformanceLib” & “PeiPerformanceLib” respectively. Synchronize the function header of GetPerformanceMeasurement() with MWG 0.56d. 6. BasePeCoffLoaderLib. Make PeCoffLoaderLoadImage () Assert() if ImageContext is NULL> Make PeCoffLoaderLoadImage () return RETURN_INVALID_PARAMETER if the ImageAddress in ImageContext is 0. Adjust some coding style. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@593 6f19259b-4bc3-4df7-8a09-765794883524 --- diff --git a/EdkModulePkg/Bus/Scsi/ScsiDisk/Dxe/ScsiDisk.c b/EdkModulePkg/Bus/Scsi/ScsiDisk/Dxe/ScsiDisk.c index 006cc73bcb..88c4c3aec8 100644 --- a/EdkModulePkg/Bus/Scsi/ScsiDisk/Dxe/ScsiDisk.c +++ b/EdkModulePkg/Bus/Scsi/ScsiDisk/Dxe/ScsiDisk.c @@ -874,43 +874,34 @@ Returns: &InquiryDataLength, FALSE ); - switch (Status) { - // - // no need to check HostAdapterStatus and TargetStatus - // - case EFI_SUCCESS: - case EFI_WARN_BUFFER_TOO_SMALL: + if ((Status == EFI_SUCCESS) || (Status == EFI_WARN_BUFFER_TOO_SMALL)) { + // + // no need to check HostAdapterStatus and TargetStatus + // ParseInquiryData (ScsiDiskDevice); return EFI_SUCCESS; - - case EFI_NOT_READY: + } else if (Status == EFI_NOT_READY) { + // + // no need to check HostAdapterStatus and TargetStatus + // *NeedRetry = TRUE; return EFI_DEVICE_ERROR; - - case EFI_INVALID_PARAMETER: - case EFI_UNSUPPORTED: + } else if ((Status == EFI_INVALID_PARAMETER) || (Status == EFI_UNSUPPORTED)) { + // + // no need to check HostAdapterStatus and TargetStatus + // *NeedRetry = FALSE; return EFI_DEVICE_ERROR; - + } // // go ahead to check HostAdapterStatus and TargetStatus // (EFI_TIMEOUT, EFI_DEVICE_ERROR) // - default: - break; - } - Status = CheckHostAdapterStatus (HostAdapterStatus); - switch (Status) { - case EFI_SUCCESS: - break; - - case EFI_TIMEOUT: - case EFI_NOT_READY: + if ((Status == EFI_TIMEOUT) || (Status == EFI_NOT_READY)) { *NeedRetry = TRUE; return EFI_DEVICE_ERROR; - - case EFI_DEVICE_ERROR: + } else if (Status == EFI_DEVICE_ERROR) { // // reset the scsi channel // @@ -920,19 +911,14 @@ Returns: } Status = CheckTargetStatus (TargetStatus); - switch (Status) { - case EFI_SUCCESS: - break; - - case EFI_NOT_READY: + if (Status == EFI_NOT_READY) { // // reset the scsi device // ScsiDiskDevice->ScsiIo->ResetDevice (ScsiDiskDevice->ScsiIo); *NeedRetry = TRUE; return EFI_DEVICE_ERROR; - - case EFI_DEVICE_ERROR: + } else if (Status == EFI_DEVICE_ERROR) { *NeedRetry = FALSE; return EFI_DEVICE_ERROR; } @@ -1022,37 +1008,27 @@ ScsiDiskTestUnitReady ( &HostAdapterStatus, &TargetStatus ); - switch (Status) { - // - // no need to check HostAdapterStatus and TargetStatus - // - case EFI_NOT_READY: + if (Status == EFI_NOT_READY) { + // + // no need to check HostAdapterStatus and TargetStatus + // *NeedRetry = TRUE; return EFI_DEVICE_ERROR; - - case EFI_INVALID_PARAMETER: - case EFI_UNSUPPORTED: + } else if ((Status == EFI_INVALID_PARAMETER) || (Status == EFI_UNSUPPORTED)) { + // + // no need to check HostAdapterStatus and TargetStatus + // *NeedRetry = FALSE; return EFI_DEVICE_ERROR; - + } // // go ahead to check HostAdapterStatus and TargetStatus // - default: - break; - } - Status = CheckHostAdapterStatus (HostAdapterStatus); - switch (Status) { - case EFI_SUCCESS: - break; - - case EFI_TIMEOUT: - case EFI_NOT_READY: + if ((Status == EFI_TIMEOUT) || (Status == EFI_NOT_READY)) { *NeedRetry = TRUE; return EFI_DEVICE_ERROR; - - case EFI_DEVICE_ERROR: + } else if (Status == EFI_DEVICE_ERROR) { // // reset the scsi channel // @@ -1062,19 +1038,14 @@ ScsiDiskTestUnitReady ( } Status = CheckTargetStatus (TargetStatus); - switch (Status) { - case EFI_SUCCESS: - break; - - case EFI_NOT_READY: + if (Status == EFI_NOT_READY) { // // reset the scsi device // ScsiDiskDevice->ScsiIo->ResetDevice (ScsiDiskDevice->ScsiIo); *NeedRetry = TRUE; return EFI_DEVICE_ERROR; - - case EFI_DEVICE_ERROR: + } else if (Status == EFI_DEVICE_ERROR) { *NeedRetry = FALSE; return EFI_DEVICE_ERROR; } @@ -1258,42 +1229,35 @@ Returns: &DataLength, FALSE ); - switch (CommandStatus) { - // - // no need to check HostAdapterStatus and TargetStatus - // - case EFI_SUCCESS: + if (CommandStatus == EFI_SUCCESS) { + // + // no need to check HostAdapterStatus and TargetStatus + // GetMediaInfo (ScsiDiskDevice, &CapacityData); return EFI_SUCCESS; - - case EFI_NOT_READY: + } else if (CommandStatus == EFI_NOT_READY) { + // + // no need to check HostAdapterStatus and TargetStatus + // *NeedRetry = TRUE; return EFI_DEVICE_ERROR; - - case EFI_INVALID_PARAMETER: - case EFI_UNSUPPORTED: + } else if ((CommandStatus == EFI_INVALID_PARAMETER) || (CommandStatus == EFI_UNSUPPORTED)) { + // + // no need to check HostAdapterStatus and TargetStatus + // *NeedRetry = FALSE; return EFI_DEVICE_ERROR; - + } // // go ahead to check HostAdapterStatus and TargetStatus // (EFI_TIMEOUT, EFI_DEVICE_ERROR, EFI_WARN_BUFFER_TOO_SMALL) // - default: - break; - } - + Status = CheckHostAdapterStatus (HostAdapterStatus); - switch (Status) { - case EFI_SUCCESS: - break; - - case EFI_TIMEOUT: - case EFI_NOT_READY: + if ((Status == EFI_TIMEOUT) || (Status == EFI_NOT_READY)) { *NeedRetry = TRUE; return EFI_DEVICE_ERROR; - - case EFI_DEVICE_ERROR: + } else if (Status == EFI_DEVICE_ERROR) { // // reset the scsi channel // @@ -1303,19 +1267,14 @@ Returns: } Status = CheckTargetStatus (TargetStatus); - switch (Status) { - case EFI_SUCCESS: - break; - - case EFI_NOT_READY: + if (Status == EFI_NOT_READY) { // // reset the scsi device // ScsiDiskDevice->ScsiIo->ResetDevice (ScsiDiskDevice->ScsiIo); *NeedRetry = TRUE; return EFI_DEVICE_ERROR; - - case EFI_DEVICE_ERROR: + } else if (Status == EFI_DEVICE_ERROR) { *NeedRetry = FALSE; return EFI_DEVICE_ERROR; } @@ -1506,40 +1465,20 @@ ScsiDiskRequestSenseKeys ( &HostAdapterStatus, &TargetStatus ); - switch (Status) { - - case EFI_SUCCESS: - - // - // fall through - // - case EFI_WARN_BUFFER_TOO_SMALL: + if ((Status == EFI_SUCCESS) || (Status == EFI_WARN_BUFFER_TOO_SMALL)) { FallStatus = EFI_SUCCESS; - break; - - case EFI_TIMEOUT: - - // - // fall through - // - case EFI_NOT_READY: + } else if ((Status == EFI_TIMEOUT) || (Status == EFI_NOT_READY)) { *NeedRetry = TRUE; FallStatus = EFI_DEVICE_ERROR; - break; - - case EFI_INVALID_PARAMETER: - case EFI_UNSUPPORTED: + } else if ((Status == EFI_INVALID_PARAMETER) || (Status == EFI_UNSUPPORTED)) { *NeedRetry = FALSE; FallStatus = EFI_DEVICE_ERROR; - break; - - case EFI_DEVICE_ERROR: + } else if (Status == EFI_DEVICE_ERROR) { if (AskResetIfError) { ScsiDiskDevice->ScsiIo->ResetDevice (ScsiDiskDevice->ScsiIo); } FallStatus = EFI_DEVICE_ERROR; - break; } if (EFI_ERROR (FallStatus)) { diff --git a/EdkModulePkg/Core/Dxe/Hand/locate.c b/EdkModulePkg/Core/Dxe/Hand/locate.c index faa4255c7e..54d72c30a2 100644 --- a/EdkModulePkg/Core/Dxe/Hand/locate.c +++ b/EdkModulePkg/Core/Dxe/Hand/locate.c @@ -702,15 +702,11 @@ Returns: // // Add code to correctly handle expected errors from CoreLocateHandle(). // - if (EFI_ERROR(Status)) { - switch (Status) { - case EFI_BUFFER_TOO_SMALL: - break; - case EFI_INVALID_PARAMETER: - return Status; - default: - return EFI_NOT_FOUND; + if (EFI_ERROR(Status) && Status != EFI_BUFFER_TOO_SMALL) { + if (Status != EFI_INVALID_PARAMETER) { + Status = EFI_NOT_FOUND; } + return Status; } *Buffer = CoreAllocateBootServicesPool (BufferSize); diff --git a/EdkModulePkg/Core/Pei/Dispatcher/Dispatcher.c b/EdkModulePkg/Core/Pei/Dispatcher/Dispatcher.c index 0bec576e6d..1eb5a4a020 100644 --- a/EdkModulePkg/Core/Pei/Dispatcher/Dispatcher.c +++ b/EdkModulePkg/Core/Pei/Dispatcher/Dispatcher.c @@ -448,12 +448,7 @@ Returns: // Check if the total number of PEIMs exceed the bitmap. // CurrentPeim is 0-based // - DEBUG_CODE ( - if (CurrentPeim > (sizeof (*DispatchedPeimBitMap) * 8 - 1)) { - ASSERT_EFI_ERROR (EFI_OUT_OF_RESOURCES); - } - ); - + ASSERT (CurrentPeim < (sizeof (*DispatchedPeimBitMap) * 8)); *DispatchedPeimBitMap |= (1 << CurrentPeim); return; } diff --git a/EdkModulePkg/EdkModulePkg.spd b/EdkModulePkg/EdkModulePkg.spd index da00472ce2..e2b9542e65 100644 --- a/EdkModulePkg/EdkModulePkg.spd +++ b/EdkModulePkg/EdkModulePkg.spd @@ -172,7 +172,7 @@ Library/EdkDxePeCoffLoaderFromHobLib/EdkDxePeCoffLoaderFromHobLib.msa - Library/EdkDxePerformanceLib/EdkDxePerformanceLib.msa + Library/DxePerformanceLib/DxePerformanceLib.msa Library/EdkDxePrintLib/EdkDxePrintLib.msa @@ -208,7 +208,7 @@ Library/EdkPeCoffLoaderX64Lib/EdkPeCoffLoaderX64Lib.msa - Library/EdkPeiPerformanceLib/EdkPeiPerformanceLib.msa + Library/PeiPerformanceLib/PeiPerformanceLib.msa Library/EdkRuntimeStatusCodeLib/BsDataHubStatusCode/BsDataHubStatusCode.msa diff --git a/EdkModulePkg/Library/DxeCorePerformanceLib/DxeCorePerformanceLib.c b/EdkModulePkg/Library/DxeCorePerformanceLib/DxeCorePerformanceLib.c index c75ab851f7..e4e7b3bb3b 100644 --- a/EdkModulePkg/Library/DxeCorePerformanceLib/DxeCorePerformanceLib.c +++ b/EdkModulePkg/Library/DxeCorePerformanceLib/DxeCorePerformanceLib.c @@ -532,34 +532,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/EdkModulePkg/Library/DxePerformanceLib/DxePerformanceLib.c b/EdkModulePkg/Library/DxePerformanceLib/DxePerformanceLib.c new file mode 100644 index 0000000000..8a3ac4053f --- /dev/null +++ b/EdkModulePkg/Library/DxePerformanceLib/DxePerformanceLib.c @@ -0,0 +1,228 @@ +/*++ + +Copyright (c) 2006, Intel Corporation +All rights reserved. This program and the accompanying materials +are licensed and made available under the terms and conditions of the BSD License +which accompanies this distribution. The full text of the license may be found at +http://opensource.org/licenses/bsd-license.php + +THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +Module Name: + + DxePerformanceLib.c + +Abstract: + + Performance Library + +--*/ + +STATIC PERFORMANCE_PROTOCOL *mPerformance = NULL; + +/** + The constructor function caches the pointer to Performance protocol. + + The constructor function locates Performance protocol from protocol database. + It will ASSERT() if that operation fails and it will always return EFI_SUCCESS. + + @param ImageHandle The firmware allocated handle for the EFI image. + @param SystemTable A pointer to the EFI System Table. + + @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS. + +**/ +EFI_STATUS +EFIAPI +PerformanceLibConstructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + + Status = gBS->LocateProtocol (&gPerformanceProtocolGuid, NULL, (VOID **) &mPerformance); + ASSERT_EFI_ERROR (Status); + ASSERT (mPerformance != NULL); + + return Status; +} + +/** + Creates a record for the beginning of a performance measurement. + + Creates a record that contains the Handle, Token, and Module. + If TimeStamp is not zero, then TimeStamp is added to the record as the start time. + If TimeStamp is zero, then this function reads the current time stamp + and adds that time stamp value to the record as the start time. + + @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 TimeStamp 64-bit time stamp. + + @retval RETURN_SUCCESS The start of the measurement was recorded. + @retval RETURN_OUT_OF_RESOURCES There are not enough resources to record the measurement. + +**/ +RETURN_STATUS +EFIAPI +StartPerformanceMeasurement ( + IN CONST VOID *Handle, OPTIONAL + IN CONST CHAR8 *Token, OPTIONAL + IN CONST CHAR8 *Module, OPTIONAL + IN UINT64 TimeStamp + ) +{ + EFI_STATUS Status; + + Status = mPerformance->StartGauge (Handle, Token, Module, TimeStamp); + + return (RETURN_STATUS) Status; +} + +/** + Fills in the end time of a performance measurement. + + 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 and TimeStamp is not zero, + then TimeStamp is added to the record as the end time. + If the record is found and TimeStamp is zero, then this function reads + the current time stamp and adds that time stamp value to the record as the end time. + If this function is called multiple times for the same record, then the end time is overwritten. + + @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 TimeStamp 64-bit time stamp. + + @retval RETURN_SUCCESS The end of the measurement was recorded. + @retval RETURN_NOT_FOUND The specified measurement record could not be found. + +**/ +RETURN_STATUS +EFIAPI +EndPerformanceMeasurement ( + IN CONST VOID *Handle, OPTIONAL + IN CONST CHAR8 *Token, OPTIONAL + IN CONST CHAR8 *Module, OPTIONAL + IN UINT64 TimeStamp + ) +{ + EFI_STATUS Status; + + Status = mPerformance->EndGauge (Handle, Token, Module, TimeStamp); + + return (RETURN_STATUS) Status; +} + +/** + Attempts to retrieve a performance measurement log entry from the performance measurement log. + + 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 ( + IN UINTN LogEntryKey, + OUT CONST VOID **Handle, + OUT CONST CHAR8 **Token, + OUT CONST CHAR8 **Module, + OUT UINT64 *StartTimeStamp, + OUT UINT64 *EndTimeStamp + ) +{ + EFI_STATUS Status; + GAUGE_DATA_ENTRY *GaugeData; + + ASSERT (Handle != NULL); + ASSERT (Token != NULL); + ASSERT (Module != NULL); + ASSERT (StartTimeStamp != NULL); + ASSERT (EndTimeStamp != NULL); + + Status = mPerformance->GetGauge (LogEntryKey++, &GaugeData); + + // + // Make sure that LogEntryKey is a valid log entry key, + // + ASSERT (Status != EFI_INVALID_PARAMETER); + + if (EFI_ERROR (Status)) { + // + // The LogEntryKey is the last entry (equals to the total entry number). + // + return 0; + } + + ASSERT (GaugeData != NULL); + + *Handle = (VOID *) (UINTN) GaugeData->Handle; + *Token = GaugeData->Token; + *Module = GaugeData->Module; + *StartTimeStamp = GaugeData->StartTimeStamp; + *EndTimeStamp = GaugeData->EndTimeStamp; + + return LogEntryKey; +} + +/** + Returns TRUE if the performance measurement macros are enabled. + + This function returns TRUE if the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of + PcdPerformanceLibraryPropertyMask is set. Otherwise FALSE is returned. + + @retval TRUE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of + PcdPerformanceLibraryPropertyMask is set. + @retval FALSE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of + PcdPerformanceLibraryPropertyMask is clear. + +**/ +BOOLEAN +EFIAPI +PerformanceMeasurementEnabled ( + VOID + ) +{ + return ((PcdGet8(PcdPerformanceLibraryPropertyMask) & PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED) != 0); +} diff --git a/EdkModulePkg/Library/DxePerformanceLib/DxePerformanceLib.mbd b/EdkModulePkg/Library/DxePerformanceLib/DxePerformanceLib.mbd new file mode 100644 index 0000000000..1d8df5409b --- /dev/null +++ b/EdkModulePkg/Library/DxePerformanceLib/DxePerformanceLib.mbd @@ -0,0 +1,29 @@ + + + + + DxePerformanceLib + 8B8B4CCC-65FC-41a5-8067-308B8E42CCF2 + EDK_RELEASE_VERSION 0x00020000 + FIX ME! + Copyright (c) 2006, Intel Corporation + + All rights reserved. This program and the accompanying materials + are licensed and made available under the terms and conditions of the BSD License + which accompanies this distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + + 2006-04-04 11:11 + + diff --git a/EdkModulePkg/Library/DxePerformanceLib/DxePerformanceLib.msa b/EdkModulePkg/Library/DxePerformanceLib/DxePerformanceLib.msa new file mode 100644 index 0000000000..d8696f24e7 --- /dev/null +++ b/EdkModulePkg/Library/DxePerformanceLib/DxePerformanceLib.msa @@ -0,0 +1,60 @@ + + + + + DxePerformanceLib + DXE_DRIVER + LIBRARY + 8B8B4CCC-65FC-41a5-8067-308B8E42CCF2 + EDK_RELEASE_VERSION 0x00020000 + Memory-only library functions with no library constructor/destructor + FIX ME! + Copyright (c) 2006, Intel Corporation + + All rights reserved. This program and the accompanying materials + are licensed and made available under the terms and conditions of the BSD License + which accompanies this distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + + 2006-04-04 11:11 + EFI_SPECIFICATION_VERSION 0x00000000 + + + PerformanceLib + DebugLib + UefiBootServicesTableLib + TimerLib + PcdLib + + + DxePerformanceLib.c + + + MdePkg + EdkModulePkg + + + Performance + + + + PerformanceLibConstructor + + + + + PcdPerformanceLibraryPropertyMask + + + diff --git a/EdkModulePkg/Library/DxePerformanceLib/build.xml b/EdkModulePkg/Library/DxePerformanceLib/build.xml new file mode 100644 index 0000000000..a663483133 --- /dev/null +++ b/EdkModulePkg/Library/DxePerformanceLib/build.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/EdkModulePkg/Library/PeiPerformanceLib/PeiPerformanceLib.c b/EdkModulePkg/Library/PeiPerformanceLib/PeiPerformanceLib.c new file mode 100644 index 0000000000..b97849fa35 --- /dev/null +++ b/EdkModulePkg/Library/PeiPerformanceLib/PeiPerformanceLib.c @@ -0,0 +1,330 @@ +/*++ + +Copyright (c) 2006, Intel Corporation +All rights reserved. This program and the accompanying materials +are licensed and made available under the terms and conditions of the BSD License +which accompanies this distribution. The full text of the license may be found at +http://opensource.org/licenses/bsd-license.php + +THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +Module Name: + + PeiPerformanceLib.c + +Abstract: + + Performance Library + +--*/ + +/** + Gets PEI the GUID HOB for PEI performance. + + This internal function searches for the GUID HOB for PEI performance. + If that GUID HOB is not found, it will build a new one. + It returns the data area of that GUID HOB to record performance log. + + @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. + + @retval The index of log entry in the array. + +**/ +PEI_PERFORMANCE_LOG_HEADER * +InternalGetPerformanceHobLog ( + VOID + ) +{ + EFI_HOB_GUID_TYPE *GuidHob; + PEI_PERFORMANCE_LOG_HEADER *PeiPerformanceLog; + UINTN PeiPerformanceLogSize; + + GuidHob = GetFirstGuidHob (&gPeiPerformanceHobGuid); + + if (GuidHob != NULL) { + // + // PEI Performance HOB was found, then return the existing one. + // + PeiPerformanceLog = GET_GUID_HOB_DATA (GuidHob); + } else { + // + // PEI Performance HOB was not found, then build one. + // + PeiPerformanceLogSize = sizeof (PEI_PERFORMANCE_LOG_HEADER) + + sizeof (PEI_PERFORMANCE_LOG_ENTRY) * MAX_PEI_PERFORMANCE_LOG_ENTRIES; + PeiPerformanceLog = BuildGuidHob (&gPeiPerformanceHobGuid, PeiPerformanceLogSize); + PeiPerformanceLog = ZeroMem (PeiPerformanceLog, PeiPerformanceLogSize); + } + + return PeiPerformanceLog; +} + +/** + Searches in the log array with keyword Handle, Token and Module. + + This internal function searches for the log entry in the log array. + If there is an entry that exactly matches the given key word triple + and its end time stamp is zero, then the index of that log entry is returned; + otherwise, the the number of log entries in the array is returned. + + @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. + + @retval The index of log entry in the array. + +**/ +UINT32 +InternalSearchForLogEntry ( + IN PEI_PERFORMANCE_LOG_HEADER *PeiPerformanceLog, + IN CONST VOID *Handle, OPTIONAL + IN CONST CHAR8 *Token, OPTIONAL + IN CONST CHAR8 *Module OPTIONAL + ) +{ + UINT32 Index; + UINT32 NumberOfEntries; + PEI_PERFORMANCE_LOG_ENTRY *LogEntryArray; + + + if (Token == NULL) { + Token = ""; + } + if (Module == NULL) { + Module = ""; + } + NumberOfEntries = PeiPerformanceLog->NumberOfEntries; + LogEntryArray = (PEI_PERFORMANCE_LOG_ENTRY *) (PeiPerformanceLog + 1); + + for (Index = 0; Index < NumberOfEntries; Index++) { + if ((LogEntryArray[Index].Handle == (EFI_PHYSICAL_ADDRESS) (UINTN) Handle) && + AsciiStrnCmp (LogEntryArray[Index].Token, Token, PEI_PERFORMANCE_STRING_LENGTH) == 0 && + AsciiStrnCmp (LogEntryArray[Index].Module, Module, PEI_PERFORMANCE_STRING_LENGTH) == 0 && + LogEntryArray[Index].EndTimeStamp == 0 + ) { + break; + } + } + return Index; +} + +/** + Creates a record for the beginning of a performance measurement. + + Creates a record that contains the Handle, Token, and Module. + If TimeStamp is not zero, then TimeStamp is added to the record as the start time. + If TimeStamp is zero, then this function reads the current time stamp + and adds that time stamp value to the record as the start time. + + @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 TimeStamp 64-bit time stamp. + + @retval RETURN_SUCCESS The start of the measurement was recorded. + @retval RETURN_OUT_OF_RESOURCES There are not enough resources to record the measurement. + +**/ +RETURN_STATUS +EFIAPI +StartPerformanceMeasurement ( + IN CONST VOID *Handle, OPTIONAL + IN CONST CHAR8 *Token, OPTIONAL + IN CONST CHAR8 *Module, OPTIONAL + IN UINT64 TimeStamp + ) +{ + PEI_PERFORMANCE_LOG_HEADER *PeiPerformanceLog; + PEI_PERFORMANCE_LOG_ENTRY *LogEntryArray; + UINT32 Index; + + PeiPerformanceLog = InternalGetPerformanceHobLog (); + + if (PeiPerformanceLog->NumberOfEntries >= MAX_PEI_PERFORMANCE_LOG_ENTRIES) { + return RETURN_OUT_OF_RESOURCES; + } + Index = PeiPerformanceLog->NumberOfEntries++; + LogEntryArray = (PEI_PERFORMANCE_LOG_ENTRY *) (PeiPerformanceLog + 1); + LogEntryArray[Index].Handle = (EFI_PHYSICAL_ADDRESS) (UINTN) Handle; + + if (Token != NULL) { + AsciiStrnCpy (LogEntryArray[Index].Token, Token, PEI_PERFORMANCE_STRING_LENGTH); + } + if (Module != NULL) { + AsciiStrnCpy (LogEntryArray[Index].Module, Module, PEI_PERFORMANCE_STRING_LENGTH); + } + + if (TimeStamp == 0) { + TimeStamp = GetPerformanceCounter (); + } + LogEntryArray[Index].StartTimeStamp = TimeStamp; + + return RETURN_SUCCESS; +} + +/** + Fills in the end time of a performance measurement. + + 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 and TimeStamp is not zero, + then TimeStamp is added to the record as the end time. + If the record is found and TimeStamp is zero, then this function reads + the current time stamp and adds that time stamp value to the record as the end time. + If this function is called multiple times for the same record, then the end time is overwritten. + + @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 TimeStamp 64-bit time stamp. + + @retval RETURN_SUCCESS The end of the measurement was recorded. + @retval RETURN_NOT_FOUND The specified measurement record could not be found. + +**/ +RETURN_STATUS +EFIAPI +EndPerformanceMeasurement ( + IN CONST VOID *Handle, OPTIONAL + IN CONST CHAR8 *Token, OPTIONAL + IN CONST CHAR8 *Module, OPTIONAL + IN UINT64 TimeStamp + ) +{ + PEI_PERFORMANCE_LOG_HEADER *PeiPerformanceLog; + PEI_PERFORMANCE_LOG_ENTRY *LogEntryArray; + UINT32 Index; + + if (TimeStamp == 0) { + TimeStamp = GetPerformanceCounter (); + } + + PeiPerformanceLog = InternalGetPerformanceHobLog (); + Index = InternalSearchForLogEntry (PeiPerformanceLog, Handle, Token, Module); + if (Index >= PeiPerformanceLog->NumberOfEntries) { + return RETURN_NOT_FOUND; + } + LogEntryArray = (PEI_PERFORMANCE_LOG_ENTRY *) (PeiPerformanceLog + 1); + LogEntryArray[Index].EndTimeStamp = TimeStamp; + + return RETURN_SUCCESS; +} + +/** + Attempts to retrieve a performance measurement log entry from the performance measurement log. + + 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 ( + IN UINTN LogEntryKey, + OUT CONST VOID **Handle, + OUT CONST CHAR8 **Token, + OUT CONST CHAR8 **Module, + OUT UINT64 *StartTimeStamp, + OUT UINT64 *EndTimeStamp + ) +{ + PEI_PERFORMANCE_LOG_HEADER *PeiPerformanceLog; + PEI_PERFORMANCE_LOG_ENTRY *CurrentLogEntry; + PEI_PERFORMANCE_LOG_ENTRY *LogEntryArray; + UINTN NumberOfEntries; + + ASSERT (Handle != NULL); + ASSERT (Token != NULL); + ASSERT (Module != NULL); + ASSERT (StartTimeStamp != NULL); + ASSERT (EndTimeStamp != NULL); + + PeiPerformanceLog = InternalGetPerformanceHobLog (); + + NumberOfEntries = (UINTN) (PeiPerformanceLog->NumberOfEntries); + LogEntryArray = (PEI_PERFORMANCE_LOG_ENTRY *) (PeiPerformanceLog + 1); + // + // Make sure that LogEntryKey is a valid log entry key. + // + ASSERT (LogEntryKey <= NumberOfEntries); + + if (LogEntryKey == NumberOfEntries) { + return 0; + } + + CurrentLogEntry = &(LogEntryArray[LogEntryKey++]); + + *Handle = (VOID *) (UINTN) (CurrentLogEntry->Handle); + *Token = CurrentLogEntry->Token; + *Module = CurrentLogEntry->Module; + *StartTimeStamp = CurrentLogEntry->StartTimeStamp; + *EndTimeStamp = CurrentLogEntry->EndTimeStamp; + + return LogEntryKey; +} + +/** + Returns TRUE if the performance measurement macros are enabled. + + This function returns TRUE if the PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of + PcdPerformanceLibraryPropertyMask is set. Otherwise FALSE is returned. + + @retval TRUE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of + PcdPerformanceLibraryPropertyMask is set. + @retval FALSE The PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED bit of + PcdPerformanceLibraryPropertyMask is clear. + +**/ +BOOLEAN +EFIAPI +PerformanceMeasurementEnabled ( + VOID + ) +{ + return ((PcdGet8(PcdPerformanceLibraryPropertyMask) & PERFORMANCE_LIBRARY_PROPERTY_MEASUREMENT_ENABLED) != 0); +} diff --git a/EdkModulePkg/Library/PeiPerformanceLib/PeiPerformanceLib.mbd b/EdkModulePkg/Library/PeiPerformanceLib/PeiPerformanceLib.mbd new file mode 100644 index 0000000000..8dba9c21c1 --- /dev/null +++ b/EdkModulePkg/Library/PeiPerformanceLib/PeiPerformanceLib.mbd @@ -0,0 +1,29 @@ + + + + + PeiPerformanceLib + F72DE735-B24F-4ef6-897F-70A85D01A047 + EDK_RELEASE_VERSION 0x00020000 + FIX ME! + Copyright (c) 2006, Intel Corporation + + All rights reserved. This program and the accompanying materials + are licensed and made available under the terms and conditions of the BSD License + which accompanies this distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + + 2006-04-04 11:12 + + diff --git a/EdkModulePkg/Library/PeiPerformanceLib/PeiPerformanceLib.msa b/EdkModulePkg/Library/PeiPerformanceLib/PeiPerformanceLib.msa new file mode 100644 index 0000000000..a80adce978 --- /dev/null +++ b/EdkModulePkg/Library/PeiPerformanceLib/PeiPerformanceLib.msa @@ -0,0 +1,59 @@ + + + + + PeiPerformanceLib + PEIM + LIBRARY + F72DE735-B24F-4ef6-897F-70A85D01A047 + EDK_RELEASE_VERSION 0x00020000 + Memory-only library functions with no library constructor/destructor + FIX ME! + Copyright (c) 2006, Intel Corporation + + All rights reserved. This program and the accompanying materials + are licensed and made available under the terms and conditions of the BSD License + which accompanies this distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + + 2006-04-04 11:12 + EFI_SPECIFICATION_VERSION 0x00000000 + + + PerformanceLib + DebugLib + HobLib + BaseLib + TimerLib + PcdLib + BaseMemoryLib + + + PeiPerformanceLib.c + + + MdePkg + EdkModulePkg + + + + PeiPerformanceHob + + + + + PcdPerformanceLibraryPropertyMask + + + diff --git a/EdkModulePkg/Library/PeiPerformanceLib/build.xml b/EdkModulePkg/Library/PeiPerformanceLib/build.xml new file mode 100644 index 0000000000..e0bd259b3a --- /dev/null +++ b/EdkModulePkg/Library/PeiPerformanceLib/build.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/EdkModulePkg/Universal/Network/PxeBc/Dxe/pxe_bc_udp.c b/EdkModulePkg/Universal/Network/PxeBc/Dxe/pxe_bc_udp.c index 7d782955c8..32768c05c6 100644 --- a/EdkModulePkg/Universal/Network/PxeBc/Dxe/pxe_bc_udp.c +++ b/EdkModulePkg/Universal/Network/PxeBc/Dxe/pxe_bc_udp.c @@ -463,12 +463,7 @@ Returns: } } - switch (StatCode) { - case EFI_SUCCESS: - case EFI_TIMEOUT: - break; - - default: + if ((StatCode != EFI_SUCCESS) && (StatCode != EFI_TIMEOUT)) { DEBUG ( (EFI_D_INFO, "\nUdpRead() Exit #3 %Xh %r", diff --git a/EdkModulePkg/Universal/Network/PxeBc/Dxe/pxe_loadfile.c b/EdkModulePkg/Universal/Network/PxeBc/Dxe/pxe_loadfile.c index 315c95a9f5..182462c02f 100644 --- a/EdkModulePkg/Universal/Network/PxeBc/Dxe/pxe_loadfile.c +++ b/EdkModulePkg/Universal/Network/PxeBc/Dxe/pxe_loadfile.c @@ -1456,15 +1456,12 @@ Returns: (VOID *) &LoadfilePtr->Private->CallbackProtocolPtr ); - switch (Status) { - case EFI_SUCCESS: + if (Status == EFI_SUCCESS) { // // There is already a callback routine. Do nothing. // DEBUG ((EFI_D_WARN, "\nLoadFile() BC callback exists.")); - break; - - case EFI_UNSUPPORTED: + } else if (Status == EFI_UNSUPPORTED) { // // No BaseCode Callback protocol found. Add our own. // @@ -1490,10 +1487,7 @@ Returns: &NewMakeCallback ); } - - break; - - default: + } else { DEBUG ((EFI_D_WARN, "\nLoadFile() Callback check status == %xh", Status)); } // @@ -1578,11 +1572,11 @@ Returns: DEBUG ((EFI_D_WARN, "\nBC.Loadfile() Status == %xh\n", Status)); - switch (Status) { - case EFI_SUCCESS: /* 0 */ + if (Status == EFI_SUCCESS) { + /* 0 */ return EFI_SUCCESS; - - case EFI_BUFFER_TOO_SMALL: /* 5 */ + } else if (Status == EFI_BUFFER_TOO_SMALL) { + /* 5 */ // // Error is only displayed when we are actually trying to // download the boot image. @@ -1590,104 +1584,81 @@ Returns: if (Buffer == NULL) { return EFI_BUFFER_TOO_SMALL; } - AsciiPrint ("\nPXE-E05: Download buffer is smaller than requested file.\n"); - break; - - case EFI_DEVICE_ERROR: /* 7 */ + } else if (Status == EFI_DEVICE_ERROR) { + /* 7 */ AsciiPrint ("\nPXE-E07: Network device error. Check network connection.\n"); - break; - - case EFI_OUT_OF_RESOURCES: /* 9 */ + } else if (Status == EFI_OUT_OF_RESOURCES) { + /* 9 */ AsciiPrint ("\nPXE-E09: Could not allocate I/O buffers.\n"); - break; - - case EFI_NO_MEDIA: /* 12 */ + } else if (Status == EFI_NO_MEDIA) { + /* 12 */ AsciiPrint ("\nPXE-E12: Could not detect network connection. Check cable.\n"); - break; - - case EFI_NO_RESPONSE: /* 16 */ + } else if (Status == EFI_NO_RESPONSE) { + /* 16 */ AsciiPrint ("\nPXE-E16: Valid PXE offer not received.\n"); - break; - - case EFI_TIMEOUT: /* 18 */ + } else if (Status == EFI_TIMEOUT) { + /* 18 */ AsciiPrint ("\nPXE-E18: Timeout. Server did not respond.\n"); - break; - - case EFI_ABORTED: /* 21 */ + } else if (Status == EFI_ABORTED) { + /* 21 */ AsciiPrint ("\nPXE-E21: Remote boot cancelled.\n"); - break; - - case EFI_ICMP_ERROR: /* 22 */ + } else if (Status == EFI_ICMP_ERROR) { + /* 22 */ AsciiPrint ("\nPXE-E22: Client received ICMP error from server.\n"); - if (LoadfilePtr->Private->EfiBc.Mode == NULL) { - break; - } - - if (!LoadfilePtr->Private->EfiBc.Mode->IcmpErrorReceived) { - break; - } + if ((LoadfilePtr->Private->EfiBc.Mode != NULL) && LoadfilePtr->Private->EfiBc.Mode->IcmpErrorReceived) { + AsciiPrint ( + "PXE-E98: Type: %xh Code: %xh ", + LoadfilePtr->Private->EfiBc.Mode->IcmpError.Type, + LoadfilePtr->Private->EfiBc.Mode->IcmpError.Code + ); - AsciiPrint ( - "PXE-E98: Type: %xh Code: %xh ", - LoadfilePtr->Private->EfiBc.Mode->IcmpError.Type, - LoadfilePtr->Private->EfiBc.Mode->IcmpError.Code - ); + switch (LoadfilePtr->Private->EfiBc.Mode->IcmpError.Type) { + case 0x03: + switch (LoadfilePtr->Private->EfiBc.Mode->IcmpError.Code) { + case 0x00: /* net unreachable */ + AsciiPrint ("Net unreachable"); + break; - switch (LoadfilePtr->Private->EfiBc.Mode->IcmpError.Type) { - case 0x03: - switch (LoadfilePtr->Private->EfiBc.Mode->IcmpError.Code) { - case 0x00: /* net unreachable */ - AsciiPrint ("Net unreachable"); - break; + case 0x01: /* host unreachable */ + AsciiPrint ("Host unreachable"); + break; - case 0x01: /* host unreachable */ - AsciiPrint ("Host unreachable"); - break; + case 0x02: /* protocol unreachable */ + AsciiPrint ("Protocol unreachable"); + break; - case 0x02: /* protocol unreachable */ - AsciiPrint ("Protocol unreachable"); - break; + case 0x03: /* port unreachable */ + AsciiPrint ("Port unreachable"); + break; - case 0x03: /* port unreachable */ - AsciiPrint ("Port unreachable"); - break; + case 0x04: /* Fragmentation needed */ + AsciiPrint ("Fragmentation needed"); + break; - case 0x04: /* Fragmentation needed */ - AsciiPrint ("Fragmentation needed"); - break; + case 0x05: /* Source route failed */ + AsciiPrint ("Source route failed"); + break; + } - case 0x05: /* Source route failed */ - AsciiPrint ("Source route failed"); break; } - break; + AsciiPrint ("\n"); } - - AsciiPrint ("\n"); - - break; - - case EFI_TFTP_ERROR: /* 23 */ + } else if (Status == EFI_TFTP_ERROR) { + /* 23 */ AsciiPrint ("\nPXE-E23: Client received TFTP error from server.\n"); - if (LoadfilePtr->Private->EfiBc.Mode == NULL) { - break; - } - - if (LoadfilePtr->Private->EfiBc.Mode->TftpErrorReceived) { + if ((LoadfilePtr->Private->EfiBc.Mode != NULL) && (LoadfilePtr->Private->EfiBc.Mode->TftpErrorReceived)) { AsciiPrint ( "PXE-E98: Code: %xh %a\n", LoadfilePtr->Private->EfiBc.Mode->TftpError.ErrorCode, LoadfilePtr->Private->EfiBc.Mode->TftpError.ErrorString ); } - - break; - - default: + } else { AsciiPrint ("\nPXE-E99: Unexpected network error: %xh\n", Status); } diff --git a/EdkModulePkg/Universal/Network/PxeDhcp4/Dxe/PxeDhcp4Run.c b/EdkModulePkg/Universal/Network/PxeDhcp4/Dxe/PxeDhcp4Run.c index 50f97a8915..8e015b2a3d 100644 --- a/EdkModulePkg/Universal/Network/PxeDhcp4/Dxe/PxeDhcp4Run.c +++ b/EdkModulePkg/Universal/Network/PxeDhcp4/Dxe/PxeDhcp4Run.c @@ -126,14 +126,9 @@ PxeDhcp4Run ( // efi_status = PxeDhcp4Init (This, timeout, &offers, &offer_list); - switch (efi_status) { - case EFI_NO_RESPONSE: - case EFI_TIMEOUT: - case EFI_SUCCESS: - break; - - case EFI_ABORTED: - default: + if ((efi_status != EFI_NO_RESPONSE) && + (efi_status != EFI_TIMEOUT) && + (efi_status != EFI_SUCCESS)) { return efi_status; } // 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); }