]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Fixed some alignment faults in IPF platform
authorydong10 <ydong10@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 25 Jan 2013 02:00:22 +0000 (02:00 +0000)
committerydong10 <ydong10@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 25 Jan 2013 02:00:22 +0000 (02:00 +0000)
Signed-off-by: Eric Dong <eric.dong@intel.com>
Reviewed-by: Carsey Jaben <jaben.carsey@intel.com>
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@14081 6f19259b-4bc3-4df7-8a09-765794883524

ShellPkg/Library/UefiShellDebug1CommandsLib/SmbiosView/PrintInfo.c
ShellPkg/Library/UefiShellLib/UefiShellLib.c

index 3aea96b6e09ac49a6d9962d06ef0db0cf5ce381d..9ae5a0c7419049b4a00424b51cdfa7fcc8a65f2f 100644 (file)
@@ -249,7 +249,7 @@ SmbiosPrintStructure (
     PRINT_PENDING_STRING (Struct, Type0, BiosReleaseDate);\r
     ShellPrintHiiEx(-1,-1,NULL,STRING_TOKEN (STR_SMBIOSVIEW_PRINTINFO_BIOS_SIZE), gShellDebug1HiiHandle, 64 * (Struct->Type0->BiosSize + 1));\r
 \r
-    DisplayBiosCharacteristics (*(UINT64 *) &(Struct->Type0->BiosCharacteristics), Option);\r
+    DisplayBiosCharacteristics (ReadUnaligned64 ((UINT64 *) (UINTN) &(Struct->Type0->BiosCharacteristics)), Option);\r
 \r
     if (Struct->Hdr->Length > 0x12) {\r
       DisplayBiosCharacteristicsExt1 (Struct->Type0->BIOSCharacteristicsExtensionBytes[0], Option);\r
@@ -416,7 +416,7 @@ SmbiosPrintStructure (
     PRINT_STRUCT_VALUE_H (Struct, Type7, InstalledSize);\r
     PRINT_STRUCT_VALUE_H (Struct, Type7, SupportedSRAMType);\r
     PRINT_STRUCT_VALUE_H (Struct, Type7, CurrentSRAMType);\r
-    DisplayCacheSRAMType (*(UINT16 *) &(Struct->Type7->CurrentSRAMType), Option);\r
+    DisplayCacheSRAMType (ReadUnaligned16 ((UINT16 *) (UINTN) &(Struct->Type7->CurrentSRAMType)), Option);\r
     PRINT_STRUCT_VALUE_H (Struct, Type7, CacheSpeed);\r
     DisplayCacheErrCorrectingType (Struct->Type7->ErrorCorrectionType, Option);\r
     DisplayCacheSystemCacheType (Struct->Type7->SystemCacheType, Option);\r
@@ -633,7 +633,7 @@ SmbiosPrintStructure (
     PRINT_PENDING_STRING (Struct, Type17, DeviceLocator);\r
     PRINT_PENDING_STRING (Struct, Type17, BankLocator);\r
     DisplayMemoryDeviceType (Struct->Type17->MemoryType, Option);\r
-    DisplayMemoryDeviceTypeDetail (*(UINT16 *) &(Struct->Type17->TypeDetail), Option);\r
+    DisplayMemoryDeviceTypeDetail (ReadUnaligned16 ((UINT16 *) (UINTN) &(Struct->Type17->TypeDetail)), Option);\r
     PRINT_STRUCT_VALUE_H (Struct, Type17, Speed);\r
     PRINT_PENDING_STRING (Struct, Type17, Manufacturer);\r
     PRINT_PENDING_STRING (Struct, Type17, SerialNumber);\r
index 222bd98acd078b9cf4a980aedfea2f3ea34aa659..103ddfbd5d9790e72fcef76be637354a3818458f 100644 (file)
@@ -486,6 +486,8 @@ ShellOpenFileByDevicePath(
   EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *EfiSimpleFileSystemProtocol;\r
   EFI_FILE_PROTOCOL               *Handle1;\r
   EFI_FILE_PROTOCOL               *Handle2;\r
+  CHAR16                          *FnafPathName;\r
+  UINTN                           PathLen;\r
 \r
   if (FilePath == NULL || FileHandle == NULL || DeviceHandle == NULL) {\r
     return (EFI_INVALID_PARAMETER);\r
@@ -551,13 +553,36 @@ ShellOpenFileByDevicePath(
     Handle2  = Handle1;\r
     Handle1 = NULL;\r
 \r
+    //\r
+    // File Name Alignment Fix (FNAF)\r
+    // Handle2->Open may be incapable of handling a unaligned CHAR16 data.\r
+    // The structure pointed to by FilePath may be not CHAR16 aligned.\r
+    // This code copies the potentially unaligned PathName data from the\r
+    // FilePath structure to the aligned FnafPathName for use in the\r
+    // calls to Handl2->Open.\r
+    //\r
+\r
+    //\r
+    // Determine length of PathName, in bytes.\r
+    //\r
+    PathLen = DevicePathNodeLength (*FilePath) - SIZE_OF_FILEPATH_DEVICE_PATH;\r
+\r
+    //\r
+    // Allocate memory for the aligned copy of the string Extra allocation is to allow for forced alignment\r
+    // Copy bytes from possibly unaligned location to aligned location\r
+    //\r
+    FnafPathName = AllocateCopyPool(PathLen, (UINT8 *)((FILEPATH_DEVICE_PATH*)*FilePath)->PathName);\r
+    if (FnafPathName == NULL) {\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+\r
     //\r
     // Try to test opening an existing file\r
     //\r
     Status = Handle2->Open (\r
                           Handle2,\r
                           &Handle1,\r
-                          ((FILEPATH_DEVICE_PATH*)*FilePath)->PathName,\r
+                          FnafPathName,\r
                           OpenMode &~EFI_FILE_MODE_CREATE,\r
                           0\r
                          );\r
@@ -569,11 +594,17 @@ ShellOpenFileByDevicePath(
       Status = Handle2->Open (\r
                             Handle2,\r
                             &Handle1,\r
-                            ((FILEPATH_DEVICE_PATH*)*FilePath)->PathName,\r
+                            FnafPathName,\r
                             OpenMode,\r
                             Attributes\r
                            );\r
     }\r
+\r
+    //\r
+    // Free the alignment buffer\r
+    //\r
+    FreePool(FnafPathName);\r
+\r
     //\r
     // Close the last node\r
     //\r