]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Refine BaseMemoryTestLib to handle memory address at zero.
authorxli24 <xli24@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 10 Mar 2009 05:49:58 +0000 (05:49 +0000)
committerxli24 <xli24@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 10 Mar 2009 05:49:58 +0000 (05:49 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@7844 6f19259b-4bc3-4df7-8a09-765794883524

MdeModulePkg/Library/BaseMemoryTestLib/BaseMemoryTestLib.c

index 0b89d5960f5c41aafa4a60b289a6489f0d93d41e..c939450bbd450db69d1a054c8158d864db28c108 100644 (file)
@@ -39,6 +39,38 @@ UINT32 TestPattern[] = {
   0xa5a5a5a5\r
 };\r
 \r
+/**\r
+  Internal function to compare two memory buffers of a given length.\r
+\r
+  This is the internal function to compare two memory buffers. We cannot\r
+  use CompareMem() in BaseLib, for that function ASSERT when buffer address\r
+  is zero.\r
+\r
+  @param  DestinationBuffer First memory buffer\r
+  @param  SourceBuffer      Second memory buffer\r
+  @param  Length            Length of DestinationBuffer and SourceBuffer memory\r
+                            regions to compare.\r
+\r
+  @return 0                 All Length bytes of the two buffers are identical.\r
+  @retval Non-zero          The first mismatched byte in SourceBuffer subtracted from the first\r
+                            mismatched byte in DestinationBuffer.\r
+\r
+**/\r
+INTN\r
+CompareMemoryWorker (\r
+  IN      CONST VOID                *DestinationBuffer,\r
+  IN      CONST VOID                *SourceBuffer,\r
+  IN      UINTN                     Length\r
+  )\r
+{\r
+  while ((--Length != 0) &&\r
+         (*(INT8*)DestinationBuffer == *(INT8*)SourceBuffer)) {\r
+    DestinationBuffer = (INT8*)DestinationBuffer + 1;\r
+    SourceBuffer = (INT8*)SourceBuffer + 1;\r
+  }\r
+  return (INTN)*(UINT8*)DestinationBuffer - (INTN)*(UINT8*)SourceBuffer;\r
+}\r
+\r
 /**\r
   Internal worker function for system memory range test.\r
 \r
@@ -90,7 +122,7 @@ MemoryTestWorker (
   //\r
   TempAddress = StartAddress;\r
   while ((UINTN) TempAddress < (UINTN) StartAddress + Length) {\r
-    if (CompareMem (TempAddress, TestPattern, sizeof (TestPattern)) != 0) {\r
+    if (CompareMemoryWorker (TempAddress, TestPattern, sizeof (TestPattern)) != 0) {\r
       //\r
       // Value read back does not equal to the value written, so error is detected.\r
       //\r