From 07a2097acd1f62bd9613e739a4227653970ab247 Mon Sep 17 00:00:00 2001 From: xli24 Date: Tue, 10 Mar 2009 05:49:58 +0000 Subject: [PATCH] Refine BaseMemoryTestLib to handle memory address at zero. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@7844 6f19259b-4bc3-4df7-8a09-765794883524 --- .../BaseMemoryTestLib/BaseMemoryTestLib.c | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/MdeModulePkg/Library/BaseMemoryTestLib/BaseMemoryTestLib.c b/MdeModulePkg/Library/BaseMemoryTestLib/BaseMemoryTestLib.c index 0b89d5960f..c939450bbd 100644 --- a/MdeModulePkg/Library/BaseMemoryTestLib/BaseMemoryTestLib.c +++ b/MdeModulePkg/Library/BaseMemoryTestLib/BaseMemoryTestLib.c @@ -39,6 +39,38 @@ UINT32 TestPattern[] = { 0xa5a5a5a5 }; +/** + Internal function to compare two memory buffers of a given length. + + This is the internal function to compare two memory buffers. We cannot + use CompareMem() in BaseLib, for that function ASSERT when buffer address + is zero. + + @param DestinationBuffer First memory buffer + @param SourceBuffer Second memory buffer + @param Length Length of DestinationBuffer and SourceBuffer memory + regions to compare. + + @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 +CompareMemoryWorker ( + IN CONST VOID *DestinationBuffer, + IN CONST VOID *SourceBuffer, + IN UINTN Length + ) +{ + while ((--Length != 0) && + (*(INT8*)DestinationBuffer == *(INT8*)SourceBuffer)) { + DestinationBuffer = (INT8*)DestinationBuffer + 1; + SourceBuffer = (INT8*)SourceBuffer + 1; + } + return (INTN)*(UINT8*)DestinationBuffer - (INTN)*(UINT8*)SourceBuffer; +} + /** Internal worker function for system memory range test. @@ -90,7 +122,7 @@ MemoryTestWorker ( // TempAddress = StartAddress; while ((UINTN) TempAddress < (UINTN) StartAddress + Length) { - if (CompareMem (TempAddress, TestPattern, sizeof (TestPattern)) != 0) { + if (CompareMemoryWorker (TempAddress, TestPattern, sizeof (TestPattern)) != 0) { // // Value read back does not equal to the value written, so error is detected. // -- 2.39.2