]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/FileExplorerLib: avoid packed struct for program data
authorArd Biesheuvel <ard.biesheuvel@linaro.org>
Sat, 8 Dec 2018 10:24:31 +0000 (11:24 +0100)
committerArd Biesheuvel <ard.biesheuvel@linaro.org>
Tue, 11 Dec 2018 12:14:28 +0000 (13:14 +0100)
Struct packing is only necessary for data structures whose in-memory
representation is covered by the PI or UEFI specs, and may deviate
from the ordinary C rules for alignment.

So in case of FileExplorerLib, this applies to the device path struct
only, and other structures used to carry program data should not be
packed, or we may end up with alignment faults on architectures such
as ARM, which don't permit load/store double or multiple instructions
to access memory locations that are not 32-bit aligned.

E.g., the following call in FileExplorerLibConstructor()

  InitializeListHead (&gFileExplorerPrivate.FsOptionMenu->Head);

which is emitted as follows for 32-bit ARM/Thumb2 by Clang-5.0

    3de0:       b510            push    {r4, lr}
    3de2:       4604            mov     r4, r0
    ...
    3de8:       e9c4 4400       strd    r4, r4, [r4]
    3dec:       bd10            pop     {r4, pc}

will perform a double-word store on the first argument, passed in
register r0, assuming that the pointer type of the argument is
enough to guarantee that the value is suitably aligned.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Hao Wu <hao.a.wu@intel.com>
MdeModulePkg/Library/FileExplorerLib/FileExplorer.h

index bf1450dbd5813eafa97289ed05eb9a7d4aaa3ee7..603185abe4b1214d2d6440baf178964e18768072 100644 (file)
@@ -51,6 +51,8 @@ typedef struct {
   EFI_DEVICE_PATH_PROTOCOL       End;\r
 } HII_VENDOR_DEVICE_PATH;\r
 \r
+#pragma pack()\r
+\r
 typedef struct {\r
   EFI_HANDLE                        DeviceHandle;\r
   EFI_DEVICE_PATH_PROTOCOL          *DevicePath;\r
@@ -100,8 +102,6 @@ typedef struct {
 \r
 #define FILE_EXPLORER_PRIVATE_FROM_THIS(a)  CR (a, FILE_EXPLORER_CALLBACK_DATA, FeConfigAccess, FILE_EXPLORER_CALLBACK_DATA_SIGNATURE)\r
 \r
-#pragma pack()\r
-\r
 extern UINT8    FileExplorerVfrBin[];\r
 \r
 #define MENU_OPTION_SIGNATURE      SIGNATURE_32 ('m', 'e', 'n', 'u')\r