]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Since PciXXXReadBuffer/PciXXXWriteBuffer does not check the alignment of user buffer...
authoryshang1 <yshang1@6f19259b-4bc3-4df7-8a09-765794883524>
Sat, 29 Dec 2007 02:26:26 +0000 (02:26 +0000)
committeryshang1 <yshang1@6f19259b-4bc3-4df7-8a09-765794883524>
Sat, 29 Dec 2007 02:26:26 +0000 (02:26 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@4447 6f19259b-4bc3-4df7-8a09-765794883524

MdePkg/Library/BasePciCf8Lib/PciLib.c
MdePkg/Library/BasePciExpressLib/PciLib.c

index d95f8366b1d9e1cce9dc5aa150b284becc8775a6..d61f80db6e1b28b21493de6d5cbfb0950dbaee28 100644 (file)
@@ -15,7 +15,7 @@
 \r
 #include <Base.h>\r
 \r
 \r
 #include <Base.h>\r
 \r
-\r
+#include <Library/BaseLib.h>\r
 #include <Library/PciCf8Lib.h>\r
 #include <Library/IoLib.h>\r
 #include <Library/DebugLib.h>\r
 #include <Library/PciCf8Lib.h>\r
 #include <Library/IoLib.h>\r
 #include <Library/DebugLib.h>\r
@@ -1301,7 +1301,8 @@ PciCf8ReadBuffer (
   OUT     VOID                      *Buffer\r
   )\r
 {\r
   OUT     VOID                      *Buffer\r
   )\r
 {\r
-  UINTN                             ReturnValue;\r
+  UINTN   ReturnValue;\r
+  UINTN   Value;\r
 \r
   ASSERT_INVALID_PCI_ADDRESS (StartAddress, 0);\r
   ASSERT (((StartAddress & 0xFFF) + Size) <= 0x100);\r
 \r
   ASSERT_INVALID_PCI_ADDRESS (StartAddress, 0);\r
   ASSERT (((StartAddress & 0xFFF) + Size) <= 0x100);\r
@@ -1331,7 +1332,9 @@ PciCf8ReadBuffer (
     //\r
     // Read a word if StartAddress is word aligned\r
     //\r
     //\r
     // Read a word if StartAddress is word aligned\r
     //\r
-    *(volatile UINT16 *)Buffer = PciCf8Read16 (StartAddress);\r
+    Value = (UINTN) PciCf8Read16 (StartAddress);\r
+    WriteUnaligned16 ((UINT16 *)Buffer, (UINT16) Value);\r
+\r
     StartAddress += sizeof (UINT16);\r
     Size -= sizeof (UINT16);\r
     Buffer = (UINT16*)Buffer + 1;\r
     StartAddress += sizeof (UINT16);\r
     Size -= sizeof (UINT16);\r
     Buffer = (UINT16*)Buffer + 1;\r
@@ -1341,7 +1344,8 @@ PciCf8ReadBuffer (
     //\r
     // Read as many double words as possible\r
     //\r
     //\r
     // Read as many double words as possible\r
     //\r
-    *(volatile UINT32 *)Buffer = PciCf8Read32 (StartAddress);\r
+    Value = (UINTN) PciCf8Read32 (StartAddress);\r
+    WriteUnaligned32 ((UINT32 *)Buffer, (UINT32) Value);\r
     StartAddress += sizeof (UINT32);\r
     Size -= sizeof (UINT32);\r
     Buffer = (UINT32*)Buffer + 1;\r
     StartAddress += sizeof (UINT32);\r
     Size -= sizeof (UINT32);\r
     Buffer = (UINT32*)Buffer + 1;\r
@@ -1351,7 +1355,8 @@ PciCf8ReadBuffer (
     //\r
     // Read the last remaining word if exist\r
     //\r
     //\r
     // Read the last remaining word if exist\r
     //\r
-    *(volatile UINT16 *)Buffer = PciCf8Read16 (StartAddress);\r
+    Value = (UINTN) PciCf8Read16 (StartAddress);\r
+    WriteUnaligned16 ((UINT16 *)Buffer, (UINT16) Value);\r
     StartAddress += sizeof (UINT16);\r
     Size -= sizeof (UINT16);\r
     Buffer = (UINT16*)Buffer + 1;\r
     StartAddress += sizeof (UINT16);\r
     Size -= sizeof (UINT16);\r
     Buffer = (UINT16*)Buffer + 1;\r
@@ -1400,7 +1405,7 @@ PciCf8WriteBuffer (
   IN      VOID                      *Buffer\r
   )\r
 {\r
   IN      VOID                      *Buffer\r
   )\r
 {\r
-  UINTN                             ReturnValue;\r
+  UINTN   ReturnValue;\r
 \r
   ASSERT_INVALID_PCI_ADDRESS (StartAddress, 0);\r
   ASSERT (((StartAddress & 0xFFF) + Size) <= 0x100);\r
 \r
   ASSERT_INVALID_PCI_ADDRESS (StartAddress, 0);\r
   ASSERT (((StartAddress & 0xFFF) + Size) <= 0x100);\r
@@ -1430,7 +1435,7 @@ PciCf8WriteBuffer (
     //\r
     // Write a word if StartAddress is word aligned\r
     //\r
     //\r
     // Write a word if StartAddress is word aligned\r
     //\r
-    PciCf8Write16 (StartAddress, *(UINT16*)Buffer);\r
+    PciCf8Write16 (StartAddress, ReadUnaligned16 ((UINT16*)Buffer));\r
     StartAddress += sizeof (UINT16);\r
     Size -= sizeof (UINT16);\r
     Buffer = (UINT16*)Buffer + 1;\r
     StartAddress += sizeof (UINT16);\r
     Size -= sizeof (UINT16);\r
     Buffer = (UINT16*)Buffer + 1;\r
@@ -1440,7 +1445,7 @@ PciCf8WriteBuffer (
     //\r
     // Write as many double words as possible\r
     //\r
     //\r
     // Write as many double words as possible\r
     //\r
-    PciCf8Write32 (StartAddress, *(UINT32*)Buffer);\r
+    PciCf8Write32 (StartAddress, ReadUnaligned32 ((UINT32*)Buffer));\r
     StartAddress += sizeof (UINT32);\r
     Size -= sizeof (UINT32);\r
     Buffer = (UINT32*)Buffer + 1;\r
     StartAddress += sizeof (UINT32);\r
     Size -= sizeof (UINT32);\r
     Buffer = (UINT32*)Buffer + 1;\r
@@ -1450,7 +1455,7 @@ PciCf8WriteBuffer (
     //\r
     // Write the last remaining word if exist\r
     //\r
     //\r
     // Write the last remaining word if exist\r
     //\r
-    PciCf8Write16 (StartAddress, *(UINT16*)Buffer);\r
+    PciCf8Write16 (StartAddress, ReadUnaligned16 ((UINT16*)Buffer));\r
     StartAddress += sizeof (UINT16);\r
     Size -= sizeof (UINT16);\r
     Buffer = (UINT16*)Buffer + 1;\r
     StartAddress += sizeof (UINT16);\r
     Size -= sizeof (UINT16);\r
     Buffer = (UINT16*)Buffer + 1;\r
index 9042dc4f84b076c1f981f11f3ed630de25a164d4..d368f674b522b12477247c444433637d921cf3e5 100644 (file)
@@ -21,7 +21,7 @@
 \r
 #include <Base.h>\r
 \r
 \r
 #include <Base.h>\r
 \r
-\r
+#include <Library/BaseLib.h>\r
 #include <Library/PciExpressLib.h>\r
 #include <Library/IoLib.h>\r
 #include <Library/DebugLib.h>\r
 #include <Library/PciExpressLib.h>\r
 #include <Library/IoLib.h>\r
 #include <Library/DebugLib.h>\r
@@ -1209,7 +1209,8 @@ PciExpressReadBuffer (
   OUT     VOID                      *Buffer\r
   )\r
 {\r
   OUT     VOID                      *Buffer\r
   )\r
 {\r
-  UINTN                             ReturnValue;\r
+  UINTN   ReturnValue;\r
+  UINTN   Value;\r
 \r
   ASSERT_INVALID_PCI_ADDRESS (StartAddress);\r
   ASSERT (((StartAddress & 0xFFF) + Size) <= 0x1000);\r
 \r
   ASSERT_INVALID_PCI_ADDRESS (StartAddress);\r
   ASSERT (((StartAddress & 0xFFF) + Size) <= 0x1000);\r
@@ -1239,7 +1240,9 @@ PciExpressReadBuffer (
     //\r
     // Read a word if StartAddress is word aligned\r
     //\r
     //\r
     // Read a word if StartAddress is word aligned\r
     //\r
-    *(volatile UINT16 *)Buffer = PciExpressRead16 (StartAddress);\r
+    Value = (UINTN) PciExpressRead16 (StartAddress);\r
+    WriteUnaligned16 ((UINT16 *) Buffer, (UINT16) Value);\r
+\r
     StartAddress += sizeof (UINT16);\r
     Size -= sizeof (UINT16);\r
     Buffer = (UINT16*)Buffer + 1;\r
     StartAddress += sizeof (UINT16);\r
     Size -= sizeof (UINT16);\r
     Buffer = (UINT16*)Buffer + 1;\r
@@ -1249,7 +1252,9 @@ PciExpressReadBuffer (
     //\r
     // Read as many double words as possible\r
     //\r
     //\r
     // Read as many double words as possible\r
     //\r
-    *(volatile UINT32 *)Buffer = PciExpressRead32 (StartAddress);\r
+    Value = (UINTN) PciExpressRead32 (StartAddress);\r
+    WriteUnaligned32 ((UINT32 *) Buffer, (UINT32) Value);\r
+\r
     StartAddress += sizeof (UINT32);\r
     Size -= sizeof (UINT32);\r
     Buffer = (UINT32*)Buffer + 1;\r
     StartAddress += sizeof (UINT32);\r
     Size -= sizeof (UINT32);\r
     Buffer = (UINT32*)Buffer + 1;\r
@@ -1259,7 +1264,8 @@ PciExpressReadBuffer (
     //\r
     // Read the last remaining word if exist\r
     //\r
     //\r
     // Read the last remaining word if exist\r
     //\r
-    *(volatile UINT16 *)Buffer = PciExpressRead16 (StartAddress);\r
+    Value = (UINTN) PciExpressRead16 (StartAddress);\r
+    WriteUnaligned16 ((UINT16 *) Buffer, (UINT16) Value);\r
     StartAddress += sizeof (UINT16);\r
     Size -= sizeof (UINT16);\r
     Buffer = (UINT16*)Buffer + 1;\r
     StartAddress += sizeof (UINT16);\r
     Size -= sizeof (UINT16);\r
     Buffer = (UINT16*)Buffer + 1;\r
@@ -1337,7 +1343,7 @@ PciExpressWriteBuffer (
     //\r
     // Write a word if StartAddress is word aligned\r
     //\r
     //\r
     // Write a word if StartAddress is word aligned\r
     //\r
-    PciExpressWrite16 (StartAddress, *(UINT16*)Buffer);\r
+    PciExpressWrite16 (StartAddress, ReadUnaligned16 ((UINT16*)Buffer));\r
     StartAddress += sizeof (UINT16);\r
     Size -= sizeof (UINT16);\r
     Buffer = (UINT16*)Buffer + 1;\r
     StartAddress += sizeof (UINT16);\r
     Size -= sizeof (UINT16);\r
     Buffer = (UINT16*)Buffer + 1;\r
@@ -1347,7 +1353,7 @@ PciExpressWriteBuffer (
     //\r
     // Write as many double words as possible\r
     //\r
     //\r
     // Write as many double words as possible\r
     //\r
-    PciExpressWrite32 (StartAddress, *(UINT32*)Buffer);\r
+    PciExpressWrite32 (StartAddress, ReadUnaligned32 ((UINT32*)Buffer));\r
     StartAddress += sizeof (UINT32);\r
     Size -= sizeof (UINT32);\r
     Buffer = (UINT32*)Buffer + 1;\r
     StartAddress += sizeof (UINT32);\r
     Size -= sizeof (UINT32);\r
     Buffer = (UINT32*)Buffer + 1;\r
@@ -1357,7 +1363,7 @@ PciExpressWriteBuffer (
     //\r
     // Write the last remaining word if exist\r
     //\r
     //\r
     // Write the last remaining word if exist\r
     //\r
-    PciExpressWrite16 (StartAddress, *(UINT16*)Buffer);\r
+    PciExpressWrite16 (StartAddress, ReadUnaligned16 ((UINT16*)Buffer));\r
     StartAddress += sizeof (UINT16);\r
     Size -= sizeof (UINT16);\r
     Buffer = (UINT16*)Buffer + 1;\r
     StartAddress += sizeof (UINT16);\r
     Size -= sizeof (UINT16);\r
     Buffer = (UINT16*)Buffer + 1;\r