From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mout02.posteo.de (mout02.posteo.de [185.67.36.66]) by mx.groups.io with SMTP id smtpd.web11.5562.1628585607230622119 for ; Tue, 10 Aug 2021 01:53:28 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@posteo.de header.s=2017 header.b=MZyr979p; spf=pass (domain: posteo.de, ip: 185.67.36.66, mailfrom: mhaeuser@posteo.de) Received: from submission (posteo.de [89.146.220.130]) by mout02.posteo.de (Postfix) with ESMTPS id 001A1240109 for ; Tue, 10 Aug 2021 10:53:24 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.de; s=2017; t=1628585605; bh=uCXRKyEEvExoSQ/Zdu02pN9FEBRmNh8DBJBPP2deTVc=; h=Subject:To:Cc:From:Date:From; b=MZyr979pHAcIiXsv9dISKcIcUr2eVBgQEW9QRziRAGAausZeiBcyZiEvSNwFH1t+G 9x/3dTSqaw3M0TQOTefOxmqkKeX6UA2r48FyiXoL6qYanEATuCvSP6hLIDI16dkPrs brUOwg6q3mPjH4It5+uotPgu2fBBqKwqjb0ZOtpOGuTcSjHXR6L+Q4rpD9daVheFw7 ZcBBv9gBoAPL8dI+cnbFP5QNCSjNtxNnXYp4pFPFyTkgOy2xzW5fHhNuw95KmCWSA3 UvSpXYBbfJDOPORIgFFCfs8J6EGLF9eDqzbbwXnSuJDPDeyU61LjO1bIB93ueOfAR1 Do10T9EJuZ3mQ== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4GkRYt6p2tz9rxH; Tue, 10 Aug 2021 10:53:22 +0200 (CEST) Subject: Re: [edk2-devel] [PATCH v2 1/2] MdePkg/BaseLib: Fix unaligned API prototypes To: devel@edk2.groups.io, afish@apple.com, Mike Kinney Cc: Liming Gao , "Liu, Zhiguang" , Vitaly Cheptsov References: From: =?UTF-8?B?TWFydmluIEjDpHVzZXI=?= Message-ID: <54883a88-199b-2ba7-3d18-db02636358c7@posteo.de> Date: Tue, 10 Aug 2021 08:53:22 +0000 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: quoted-printable On 09/08/2021 23:32, Andrew Fish via groups.io wrote: > > >> On Aug 9, 2021, at 9:15 AM, Michael D Kinney=20 >> > wrote: >> >> Hi Marvin, >> >> Can you provide an example of which C compiler is flagging this as >> an error and what error message is generated. >> >> Please enter a BZ with this background information and add link to the >> BZ in the commit message. >> >> This is a change to the BaseLib class, so we need to make sure there >> are no impacts to any existing code. =C2=A0I looks like a safe change >> because changing from a pointer to a fixed size type to VOID * >> should be compatible. =C2=A0Please add that analysis to the background >> in the BZ as well. >> > > MIke, > > I want to say we had a discussion about this years ago? I don=E2=80=99t= =20 > remember the outcome. > > Dereferencing a misaligned pointer is UB (Undefined Behavior) in C=20 > [1], but historically x86 compilers have let it slide. > > I think the situation we are in is the BaseLib functions don=E2=80=99t co= ntain=20 > UB, but it is UB for the caller to use the returned pointer directly. They do contain UB, inherently from the combination of their prototype=20 and their usage. Please refer to the new BZ added for V2:=20 https://bugzilla.tianocore.org/show_bug.cgi?id=3D3542 I could only speculate why UBsan does not check cast safety... To be fair, I don't know a real-world platform that has issues with this=20 UB, but the fix is simple enough in my opinion. Actually, enabling "-Wcast-align" some day would be great either way. :) Best regards, Marvin > > Here is a simple example with clang UndefinedBehaviorSanitizer (UBSan)=C2= =A0. > > ~/work/Compiler>cat ub.c > #include > > #define EFIAPI > #define IN > #define OUT > > typedef unsigned char UINT8; > typedef unsigned short UINT16; > > UINT16 > EFIAPI > WriteUnaligned16 ( > =C2=A0 OUT UINT16=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 *Buffer, > =C2=A0 IN=C2=A0 UINT16=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 Value > =C2=A0 ) > { > =C2=A0 // ASSERT (Buffer !=3D NULL); > > =C2=A0 ((volatile UINT8*)Buffer)[0] =3D (UINT8)Value; > =C2=A0 ((volatile UINT8*)Buffer)[1] =3D (UINT8)(Value >> 8); > > =C2=A0 return Value; > } > > > int main() > { > UINT8 *buffer =3D malloc(64); > UINT16 *pointer =3D (UINT16 *)(buffer + 1); > > > WriteUnaligned16 (pointer, 42); > > > // *pointer =3D 42; // Error: misaligned integer pointer assignment > return *pointer; > } > ~/work/Compiler>clang -fsanitize=3Dundefined=C2=A0 ub.c > ~/work/Compiler>./a.out > *ub.c:34:9:**runtime error: **load of misaligned address=20 > 0x7feac6405aa1 for type 'UINT16' (aka 'unsigned short'), which=20 > requires 2 byte alignment* > *0x7feac6405aa1: note: *pointer points here > =C2=A000 00 00=C2=A0 64 2a 00 79 6d 28 52 54=C2=A0 4c 44 5f 44 45 46 41 5= 5=C2=A0 4c 54 2c=20 > 20 73 77 69 66=C2=A0 74 5f 64 65 6d > *=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ^ * > SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ub.c:34:9 in > > FYI line 39 is `return *pointer`and 42 is 0x2A. So reading an writing=20 > to *pointer is UB. > > > As you can see in [1] the general advice is to take code that looks like: > int8_t *buffer =3D malloc(64);int32_t *pointer =3D (int32_t *)(buffer += =20 > 1);*pointer =3D 42; // Error: misaligned integer pointer assignment > And replace it with; > int8_t *buffer =3D malloc(64);int32_t value =3D 42;memcpy(buffer + 1,=20 > &value, sizeof(int32_t)); // Correct > > But in these cases the result is in a byte aligned buffer=E2=80=A6. > > [1] https://developer.apple.com/documentation/xcode/misaligned-pointer=20 > > > Thanks, > > Andrew Fish > >> Thanks, >> >> Mike >> >> >>> -----Original Message----- >>> From: Marvin H=C3=A4user > >>> Sent: Monday, August 9, 2021 2:51 AM >>> To:devel@edk2.groups.io >>> Cc: Kinney, Michael D >> >; Liming Gao=20 >>> >; Liu,=20 >>> Zhiguang >>> >; Vitaly=20 >>> Cheptsov > >>> Subject: [PATCH v2 1/2] MdePkg/BaseLib: Fix unaligned API prototypes >>> >>> C prohibits not only dereferencing but also casting to unaligned >>> pointers. Thus, the current set of unaligned APIs cannot be called >>> safely. Update their prototypes to take VOID * pointers, which must >>> be able to represent any valid pointer. >>> >>> Cc: Michael D Kinney >> > >>> Cc: Liming Gao >> > >>> Cc: Zhiguang Liu >> > >>> Cc: Vitaly Cheptsov >> > >>> Signed-off-by: Marvin H=C3=A4user >> > >>> --- >>> MdePkg/Library/BaseLib/Arm/Unaligned.c | 14 ++++----- >>> MdePkg/Library/BaseLib/Unaligned.c =C2=A0=C2=A0=C2=A0=C2=A0| 32 +++++++= +++---------- >>> MdePkg/Include/Library/BaseLib.h =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0| = 16 +++++----- >>> 3 files changed, 31 insertions(+), 31 deletions(-) >>> >>> diff --git a/MdePkg/Library/BaseLib/Arm/Unaligned.c=20 >>> b/MdePkg/Library/BaseLib/Arm/Unaligned.c >>> index e9934e7003cb..57f19fc44e0b 100644 >>> --- a/MdePkg/Library/BaseLib/Arm/Unaligned.c >>> +++ b/MdePkg/Library/BaseLib/Arm/Unaligned.c >>> @@ -59,7 +59,7 @@ ReadUnaligned16 ( >>> UINT16 >>> >>> EFIAPI >>> >>> WriteUnaligned16 ( >>> >>> - =C2=A0OUT UINT16 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0*Buffer, >>> >>> + =C2=A0OUT VOID =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0*Bu= ffer, >>> >>> =C2=A0=C2=A0IN =C2=A0UINT16 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0Val= ue >>> >>> =C2=A0=C2=A0) >>> >>> { >>> >>> @@ -87,7 +87,7 @@ WriteUnaligned16 ( >>> UINT32 >>> >>> EFIAPI >>> >>> ReadUnaligned24 ( >>> >>> - =C2=A0IN CONST UINT32 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0*Buffer >>> >>> + =C2=A0IN CONST VOID =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0*Buffer >>> >>> =C2=A0=C2=A0) >>> >>> { >>> >>> =C2=A0=C2=A0ASSERT (Buffer !=3D NULL); >>> >>> @@ -116,7 +116,7 @@ ReadUnaligned24 ( >>> UINT32 >>> >>> EFIAPI >>> >>> WriteUnaligned24 ( >>> >>> - =C2=A0OUT UINT32 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0*Buffer, >>> >>> + =C2=A0OUT VOID =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0*Bu= ffer, >>> >>> =C2=A0=C2=A0IN =C2=A0UINT32 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0Val= ue >>> >>> =C2=A0=C2=A0) >>> >>> { >>> >>> @@ -143,7 +143,7 @@ WriteUnaligned24 ( >>> UINT32 >>> >>> EFIAPI >>> >>> ReadUnaligned32 ( >>> >>> - =C2=A0IN CONST UINT32 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0*Buffer >>> >>> + =C2=A0IN CONST VOID =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0*Buffer >>> >>> =C2=A0=C2=A0) >>> >>> { >>> >>> =C2=A0=C2=A0UINT16 =C2=A0LowerBytes; >>> >>> @@ -175,7 +175,7 @@ ReadUnaligned32 ( >>> UINT32 >>> >>> EFIAPI >>> >>> WriteUnaligned32 ( >>> >>> - =C2=A0OUT UINT32 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0*Buffer, >>> >>> + =C2=A0OUT VOID =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0*Bu= ffer, >>> >>> =C2=A0=C2=A0IN =C2=A0UINT32 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0Val= ue >>> >>> =C2=A0=C2=A0) >>> >>> { >>> >>> @@ -202,7 +202,7 @@ WriteUnaligned32 ( >>> UINT64 >>> >>> EFIAPI >>> >>> ReadUnaligned64 ( >>> >>> - =C2=A0IN CONST UINT64 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0*Buffer >>> >>> + =C2=A0IN CONST VOID =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0*Buffer >>> >>> =C2=A0=C2=A0) >>> >>> { >>> >>> =C2=A0=C2=A0UINT32 =C2=A0LowerBytes; >>> >>> @@ -234,7 +234,7 @@ ReadUnaligned64 ( >>> UINT64 >>> >>> EFIAPI >>> >>> WriteUnaligned64 ( >>> >>> - =C2=A0OUT UINT64 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0*Buffer, >>> >>> + =C2=A0OUT VOID =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0*Bu= ffer, >>> >>> =C2=A0=C2=A0IN =C2=A0UINT64 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0Val= ue >>> >>> =C2=A0=C2=A0) >>> >>> { >>> >>> diff --git a/MdePkg/Library/BaseLib/Unaligned.c=20 >>> b/MdePkg/Library/BaseLib/Unaligned.c >>> index a419cb85e53c..3041adcde606 100644 >>> --- a/MdePkg/Library/BaseLib/Unaligned.c >>> +++ b/MdePkg/Library/BaseLib/Unaligned.c >>> @@ -26,12 +26,12 @@ >>> UINT16 >>> >>> EFIAPI >>> >>> ReadUnaligned16 ( >>> >>> - =C2=A0IN CONST UINT16 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0*Buffer >>> >>> + =C2=A0IN CONST VOID =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0*Buffer >>> >>> =C2=A0=C2=A0) >>> >>> { >>> >>> =C2=A0=C2=A0ASSERT (Buffer !=3D NULL); >>> >>> >>> >>> - =C2=A0return *Buffer; >>> >>> + =C2=A0return *(CONST UINT16 *) Buffer; >>> >>> } >>> >>> >>> >>> /** >>> >>> @@ -52,13 +52,13 @@ ReadUnaligned16 ( >>> UINT16 >>> >>> EFIAPI >>> >>> WriteUnaligned16 ( >>> >>> - =C2=A0OUT UINT16 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0*Buffer, >>> >>> + =C2=A0OUT VOID =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0*Bu= ffer, >>> >>> =C2=A0=C2=A0IN =C2=A0UINT16 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0Val= ue >>> >>> =C2=A0=C2=A0) >>> >>> { >>> >>> =C2=A0=C2=A0ASSERT (Buffer !=3D NULL); >>> >>> >>> >>> - =C2=A0return *Buffer =3D Value; >>> >>> + =C2=A0return *(UINT16 *) Buffer =3D Value; >>> >>> } >>> >>> >>> >>> /** >>> >>> @@ -77,12 +77,12 @@ WriteUnaligned16 ( >>> UINT32 >>> >>> EFIAPI >>> >>> ReadUnaligned24 ( >>> >>> - =C2=A0IN CONST UINT32 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0*Buffer >>> >>> + =C2=A0IN CONST VOID =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0*Buffer >>> >>> =C2=A0=C2=A0) >>> >>> { >>> >>> =C2=A0=C2=A0ASSERT (Buffer !=3D NULL); >>> >>> >>> >>> - =C2=A0return *Buffer & 0xffffff; >>> >>> + =C2=A0return *(CONST UINT32 *) Buffer & 0xffffff; >>> >>> } >>> >>> >>> >>> /** >>> >>> @@ -103,13 +103,13 @@ ReadUnaligned24 ( >>> UINT32 >>> >>> EFIAPI >>> >>> WriteUnaligned24 ( >>> >>> - =C2=A0OUT UINT32 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0*Buffer, >>> >>> + =C2=A0OUT VOID =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0*Bu= ffer, >>> >>> =C2=A0=C2=A0IN =C2=A0UINT32 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0Val= ue >>> >>> =C2=A0=C2=A0) >>> >>> { >>> >>> =C2=A0=C2=A0ASSERT (Buffer !=3D NULL); >>> >>> >>> >>> - =C2=A0*Buffer =3D BitFieldWrite32 (*Buffer, 0, 23, Value); >>> >>> + =C2=A0*(UINT32 *) Buffer =3D BitFieldWrite32 (*(CONST UINT32 *) Buffe= r,=20 >>> 0, 23, Value); >>> >>> =C2=A0=C2=A0return Value; >>> >>> } >>> >>> >>> >>> @@ -129,12 +129,12 @@ WriteUnaligned24 ( >>> UINT32 >>> >>> EFIAPI >>> >>> ReadUnaligned32 ( >>> >>> - =C2=A0IN CONST UINT32 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0*Buffer >>> >>> + =C2=A0IN CONST VOID =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0*Buffer >>> >>> =C2=A0=C2=A0) >>> >>> { >>> >>> =C2=A0=C2=A0ASSERT (Buffer !=3D NULL); >>> >>> >>> >>> - =C2=A0return *Buffer; >>> >>> + =C2=A0return *(CONST UINT32 *) Buffer; >>> >>> } >>> >>> >>> >>> /** >>> >>> @@ -155,13 +155,13 @@ ReadUnaligned32 ( >>> UINT32 >>> >>> EFIAPI >>> >>> WriteUnaligned32 ( >>> >>> - =C2=A0OUT UINT32 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0*Buffer, >>> >>> + =C2=A0OUT VOID =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0*Bu= ffer, >>> >>> =C2=A0=C2=A0IN =C2=A0UINT32 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0Val= ue >>> >>> =C2=A0=C2=A0) >>> >>> { >>> >>> =C2=A0=C2=A0ASSERT (Buffer !=3D NULL); >>> >>> >>> >>> - =C2=A0return *Buffer =3D Value; >>> >>> + =C2=A0return *(UINT32 *) Buffer =3D Value; >>> >>> } >>> >>> >>> >>> /** >>> >>> @@ -180,12 +180,12 @@ WriteUnaligned32 ( >>> UINT64 >>> >>> EFIAPI >>> >>> ReadUnaligned64 ( >>> >>> - =C2=A0IN CONST UINT64 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0*Buffer >>> >>> + =C2=A0IN CONST VOID =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0*Buffer >>> >>> =C2=A0=C2=A0) >>> >>> { >>> >>> =C2=A0=C2=A0ASSERT (Buffer !=3D NULL); >>> >>> >>> >>> - =C2=A0return *Buffer; >>> >>> + =C2=A0return *(CONST UINT64 *) Buffer; >>> >>> } >>> >>> >>> >>> /** >>> >>> @@ -206,11 +206,11 @@ ReadUnaligned64 ( >>> UINT64 >>> >>> EFIAPI >>> >>> WriteUnaligned64 ( >>> >>> - =C2=A0OUT UINT64 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0*Buffer, >>> >>> + =C2=A0OUT VOID =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0*Bu= ffer, >>> >>> =C2=A0=C2=A0IN =C2=A0UINT64 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0Val= ue >>> >>> =C2=A0=C2=A0) >>> >>> { >>> >>> =C2=A0=C2=A0ASSERT (Buffer !=3D NULL); >>> >>> >>> >>> - =C2=A0return *Buffer =3D Value; >>> >>> + =C2=A0return *(UINT64 *) Buffer =3D Value; >>> >>> } >>> >>> diff --git a/MdePkg/Include/Library/BaseLib.h=20 >>> b/MdePkg/Include/Library/BaseLib.h >>> index 2452c1d92e51..4d30f0539c6b 100644 >>> --- a/MdePkg/Include/Library/BaseLib.h >>> +++ b/MdePkg/Include/Library/BaseLib.h >>> @@ -3420,7 +3420,7 @@ DivS64x64Remainder ( >>> UINT16 >>> >>> EFIAPI >>> >>> ReadUnaligned16 ( >>> >>> - =C2=A0IN CONST UINT16 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0*Buffer >>> >>> + =C2=A0IN CONST VOID =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0*Buffer >>> >>> =C2=A0=C2=A0); >>> >>> >>> >>> >>> >>> @@ -3442,7 +3442,7 @@ ReadUnaligned16 ( >>> UINT16 >>> >>> EFIAPI >>> >>> WriteUnaligned16 ( >>> >>> - =C2=A0OUT UINT16 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0*Buffer, >>> >>> + =C2=A0OUT VOID =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0*Bu= ffer, >>> >>> =C2=A0=C2=A0IN =C2=A0UINT16 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0Val= ue >>> >>> =C2=A0=C2=A0); >>> >>> >>> >>> @@ -3463,7 +3463,7 @@ WriteUnaligned16 ( >>> UINT32 >>> >>> EFIAPI >>> >>> ReadUnaligned24 ( >>> >>> - =C2=A0IN CONST UINT32 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0*Buffer >>> >>> + =C2=A0IN CONST VOID =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0*Buffer >>> >>> =C2=A0=C2=A0); >>> >>> >>> >>> >>> >>> @@ -3485,7 +3485,7 @@ ReadUnaligned24 ( >>> UINT32 >>> >>> EFIAPI >>> >>> WriteUnaligned24 ( >>> >>> - =C2=A0OUT UINT32 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0*Buffer, >>> >>> + =C2=A0OUT VOID =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0*Bu= ffer, >>> >>> =C2=A0=C2=A0IN =C2=A0UINT32 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0Val= ue >>> >>> =C2=A0=C2=A0); >>> >>> >>> >>> @@ -3506,7 +3506,7 @@ WriteUnaligned24 ( >>> UINT32 >>> >>> EFIAPI >>> >>> ReadUnaligned32 ( >>> >>> - =C2=A0IN CONST UINT32 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0*Buffer >>> >>> + =C2=A0IN CONST VOID =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0*Buffer >>> >>> =C2=A0=C2=A0); >>> >>> >>> >>> >>> >>> @@ -3528,7 +3528,7 @@ ReadUnaligned32 ( >>> UINT32 >>> >>> EFIAPI >>> >>> WriteUnaligned32 ( >>> >>> - =C2=A0OUT UINT32 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0*Buffer, >>> >>> + =C2=A0OUT VOID =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0*Bu= ffer, >>> >>> =C2=A0=C2=A0IN =C2=A0UINT32 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0Val= ue >>> >>> =C2=A0=C2=A0); >>> >>> >>> >>> @@ -3549,7 +3549,7 @@ WriteUnaligned32 ( >>> UINT64 >>> >>> EFIAPI >>> >>> ReadUnaligned64 ( >>> >>> - =C2=A0IN CONST UINT64 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0*Buffer >>> >>> + =C2=A0IN CONST VOID =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0*Buffer >>> >>> =C2=A0=C2=A0); >>> >>> >>> >>> >>> >>> @@ -3571,7 +3571,7 @@ ReadUnaligned64 ( >>> UINT64 >>> >>> EFIAPI >>> >>> WriteUnaligned64 ( >>> >>> - =C2=A0OUT UINT64 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0*Buffer, >>> >>> + =C2=A0OUT VOID =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0*Bu= ffer, >>> >>> =C2=A0=C2=A0IN =C2=A0UINT64 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0Val= ue >>> >>> =C2=A0=C2=A0); >>> >>> >>> >>> -- >>> 2.31.1 >> >> >> > >=20