diff options
author | qhuang8 <qhuang8@6f19259b-4bc3-4df7-8a09-765794883524> | 2006-06-22 06:08:00 +0000 |
---|---|---|
committer | qhuang8 <qhuang8@6f19259b-4bc3-4df7-8a09-765794883524> | 2006-06-22 06:08:00 +0000 |
commit | 4ba61e5e2a1b3cec7faaad36c252738f6f57f8a6 (patch) | |
tree | ee885b41f6738849dbe28aa291c2e4df0d1fb98f /MdePkg/Library | |
parent | f7c3054530a4603d3d611e7433ed8768a6076909 (diff) | |
download | edk2-platforms-4ba61e5e2a1b3cec7faaad36c252738f6f57f8a6.tar.xz |
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
Diffstat (limited to 'MdePkg/Library')
69 files changed, 986 insertions, 987 deletions
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 callers 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 callers 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 callers 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 callers 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 callers 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 callers 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 callers 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);
}
|