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
This commit is contained in:
xli24 2009-03-10 05:49:58 +00:00
parent 28af9a489d
commit 07a2097acd
1 changed files with 33 additions and 1 deletions

View File

@ -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.
//