From patchwork Thu May 12 22:22:20 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leif Lindholm X-Patchwork-Id: 67706 Delivered-To: patch@linaro.org Received: by 10.140.92.199 with SMTP id b65csp982625qge; Thu, 12 May 2016 15:22:30 -0700 (PDT) X-Received: by 10.66.241.73 with SMTP id wg9mr17353650pac.91.1463091750619; Thu, 12 May 2016 15:22:30 -0700 (PDT) Return-Path: Received: from ml01.01.org (ml01.01.org. [2001:19d0:306:5::1]) by mx.google.com with ESMTPS id lc4si20223278pab.144.2016.05.12.15.22.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 12 May 2016 15:22:30 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) client-ip=2001:19d0:306:5::1; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 686C61A1F9B; Thu, 12 May 2016 15:22:31 -0700 (PDT) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received: from mail-wm0-x230.google.com (mail-wm0-x230.google.com [IPv6:2a00:1450:400c:c09::230]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 249AD1A1E17 for ; Thu, 12 May 2016 15:22:29 -0700 (PDT) Received: by mail-wm0-x230.google.com with SMTP id v200so380491wmv.1 for ; Thu, 12 May 2016 15:22:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=ahUyxDbzKC4xaGLwq5o6lfI5FcecJVs2FicEGdB+CcM=; b=RfNbtq4txsp1lyWf1mQETg0gJxBAhI8RhWtJUJY5PYHeE5lIOrkilGq1imjUgxKGLr G5cXw78x/rkIHqRfcxnnucjsdeCCM78pNizz5GTwIh0lnyC8wdsFkYLGaP5jiRpAmv8R z81+UqU72OE7vtPxlke9dTsk6pI/3O5wXnpcc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=ahUyxDbzKC4xaGLwq5o6lfI5FcecJVs2FicEGdB+CcM=; b=fv6eDynIfRjGc5L27/1mbAlgxVRTx3P78Oyk09AOhS20h3GQOgCNKT6LjvaUELbeEr +NyeLgELPDMf9kU9DN7j4XKaAbdhPd+vlEn6Mbx4ijtwzn3j3CUFBFL6SDQy9Kezzsgj IkfpkiCU2xASlashPPjG4UUEazoP7q22xRNvUL8kZY3NCWhwQAxIblFRglI5TX0Dhwc9 gGZ/889nR5X2y5nEDtX34YQvBI5GkVZS/xvQQLV1OWSc1Mz5p9Y7g76pa3oxihwKirfY D0+7hMtUT+pb5c9o/3lvJ/iKiqBa1k2S4JImbO/WHHlkAyaJnPEJd6e3s/UxfgDMejEG UvpA== X-Gm-Message-State: AOPr4FWhI+8q3+ElMa242vENDlxOf5SQtANADIW8vRuvlp+lV17dFNrL2/sebaFP+il7t7St X-Received: by 10.28.168.133 with SMTP id r127mr95593wme.9.1463091746051; Thu, 12 May 2016 15:22:26 -0700 (PDT) Received: from mohikan.mushroom.smurfnet.nu (cpc92308-cmbg19-2-0-cust814.5-4.cable.virginm.net. [82.24.251.47]) by smtp.gmail.com with ESMTPSA id b15sm141288wmd.1.2016.05.12.15.22.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 12 May 2016 15:22:25 -0700 (PDT) From: Leif Lindholm To: edk2-devel@lists.01.org Date: Thu, 12 May 2016 23:22:20 +0100 Message-Id: <1463091740-1015-1-git-send-email-leif.lindholm@linaro.org> X-Mailer: git-send-email 2.1.4 Subject: [edk2] [RFC] MdePkg: BaseLib: don't use aligned pointers for unaligned accessors X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Michael D Kinney , Liming Gao , Ard Biesheuvel MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" The ReadUnaligned##/WriteUnaligned## functions provide a portable way of accessing potentially unaligned locations, but the prototypes in BaseLib.h all specify strictly aligned pointers. Change the prototypes as well as the implementations across Ia32/X64, ARM/AArch64 and IPF to use VOID * pointers instead. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Leif Lindholm --- Built and tested for ArmVirtPkg for AArch64/ARM DEBUG/RELEASE. Build tested only for OvmfPkg for Ia32/X64 DEBUG/RELEASE. Not tested at all for IPF. I am not entirely convinced by the BitFieldWrite32 logic in WriteUnaligned24, but this patch is not the place to fix this. I am also not convinced there is much point in keeping separate implementations for IPF and ARM* - the optimization issues mentioned in the git log could even have been affected by the incorrect pointer types. This is the first patch triggered by my CLANG -Weverything exercises earlier this year. More to come. MdePkg/Include/Library/BaseLib.h | 16 ++++++------ MdePkg/Library/BaseLib/Arm/Unaligned.c | 16 ++++++------ MdePkg/Library/BaseLib/Ipf/Unaligned.c | 16 ++++++------ MdePkg/Library/BaseLib/Unaligned.c | 48 ++++++++++++++++++++++------------ 4 files changed, 56 insertions(+), 40 deletions(-) -- 2.1.4 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel diff --git a/MdePkg/Include/Library/BaseLib.h b/MdePkg/Include/Library/BaseLib.h index c41fa78..133656a 100644 --- a/MdePkg/Include/Library/BaseLib.h +++ b/MdePkg/Include/Library/BaseLib.h @@ -2549,7 +2549,7 @@ DivS64x64Remainder ( UINT16 EFIAPI ReadUnaligned16 ( - IN CONST UINT16 *Buffer + IN CONST VOID *Buffer ); @@ -2571,7 +2571,7 @@ ReadUnaligned16 ( UINT16 EFIAPI WriteUnaligned16 ( - OUT UINT16 *Buffer, + OUT VOID *Buffer, IN UINT16 Value ); @@ -2592,7 +2592,7 @@ WriteUnaligned16 ( UINT32 EFIAPI ReadUnaligned24 ( - IN CONST UINT32 *Buffer + IN CONST VOID *Buffer ); @@ -2614,7 +2614,7 @@ ReadUnaligned24 ( UINT32 EFIAPI WriteUnaligned24 ( - OUT UINT32 *Buffer, + OUT VOID *Buffer, IN UINT32 Value ); @@ -2635,7 +2635,7 @@ WriteUnaligned24 ( UINT32 EFIAPI ReadUnaligned32 ( - IN CONST UINT32 *Buffer + IN CONST VOID *Buffer ); @@ -2657,7 +2657,7 @@ ReadUnaligned32 ( UINT32 EFIAPI WriteUnaligned32 ( - OUT UINT32 *Buffer, + OUT VOID *Buffer, IN UINT32 Value ); @@ -2678,7 +2678,7 @@ WriteUnaligned32 ( UINT64 EFIAPI ReadUnaligned64 ( - IN CONST UINT64 *Buffer + IN CONST VOID *Buffer ); @@ -2700,7 +2700,7 @@ ReadUnaligned64 ( UINT64 EFIAPI WriteUnaligned64 ( - OUT UINT64 *Buffer, + OUT VOID *Buffer, IN UINT64 Value ); diff --git a/MdePkg/Library/BaseLib/Arm/Unaligned.c b/MdePkg/Library/BaseLib/Arm/Unaligned.c index 34f1732..ef9efbc 100644 --- a/MdePkg/Library/BaseLib/Arm/Unaligned.c +++ b/MdePkg/Library/BaseLib/Arm/Unaligned.c @@ -33,7 +33,7 @@ UINT16 EFIAPI ReadUnaligned16 ( - IN CONST UINT16 *Buffer + IN CONST VOID *Buffer ) { volatile UINT8 LowerByte; @@ -65,7 +65,7 @@ ReadUnaligned16 ( UINT16 EFIAPI WriteUnaligned16 ( - OUT UINT16 *Buffer, + OUT VOID *Buffer, IN UINT16 Value ) { @@ -93,7 +93,7 @@ WriteUnaligned16 ( UINT32 EFIAPI ReadUnaligned24 ( - IN CONST UINT32 *Buffer + IN CONST VOID *Buffer ) { ASSERT (Buffer != NULL); @@ -122,7 +122,7 @@ ReadUnaligned24 ( UINT32 EFIAPI WriteUnaligned24 ( - OUT UINT32 *Buffer, + OUT VOID *Buffer, IN UINT32 Value ) { @@ -149,7 +149,7 @@ WriteUnaligned24 ( UINT32 EFIAPI ReadUnaligned32 ( - IN CONST UINT32 *Buffer + IN CONST VOID *Buffer ) { UINT16 LowerBytes; @@ -181,7 +181,7 @@ ReadUnaligned32 ( UINT32 EFIAPI WriteUnaligned32 ( - OUT UINT32 *Buffer, + OUT VOID *Buffer, IN UINT32 Value ) { @@ -208,7 +208,7 @@ WriteUnaligned32 ( UINT64 EFIAPI ReadUnaligned64 ( - IN CONST UINT64 *Buffer + IN CONST VOID *Buffer ) { UINT32 LowerBytes; @@ -240,7 +240,7 @@ ReadUnaligned64 ( UINT64 EFIAPI WriteUnaligned64 ( - OUT UINT64 *Buffer, + OUT VOID *Buffer, IN UINT64 Value ) { diff --git a/MdePkg/Library/BaseLib/Ipf/Unaligned.c b/MdePkg/Library/BaseLib/Ipf/Unaligned.c index 7d0d8dd..5ba8029 100644 --- a/MdePkg/Library/BaseLib/Ipf/Unaligned.c +++ b/MdePkg/Library/BaseLib/Ipf/Unaligned.c @@ -30,7 +30,7 @@ UINT16 EFIAPI ReadUnaligned16 ( - IN CONST UINT16 *Buffer + IN CONST VOID *Buffer ) { ASSERT (Buffer != NULL); @@ -56,7 +56,7 @@ ReadUnaligned16 ( UINT16 EFIAPI WriteUnaligned16 ( - OUT UINT16 *Buffer, + OUT VOID *Buffer, IN UINT16 Value ) { @@ -84,7 +84,7 @@ WriteUnaligned16 ( UINT32 EFIAPI ReadUnaligned24 ( - IN CONST UINT32 *Buffer + IN CONST VOID *Buffer ) { ASSERT (Buffer != NULL); @@ -113,7 +113,7 @@ ReadUnaligned24 ( UINT32 EFIAPI WriteUnaligned24 ( - OUT UINT32 *Buffer, + OUT VOID *Buffer, IN UINT32 Value ) { @@ -140,7 +140,7 @@ WriteUnaligned24 ( UINT32 EFIAPI ReadUnaligned32 ( - IN CONST UINT32 *Buffer + IN CONST VOID *Buffer ) { UINT16 LowerBytes; @@ -172,7 +172,7 @@ ReadUnaligned32 ( UINT32 EFIAPI WriteUnaligned32 ( - OUT UINT32 *Buffer, + OUT VOID *Buffer, IN UINT32 Value ) { @@ -199,7 +199,7 @@ WriteUnaligned32 ( UINT64 EFIAPI ReadUnaligned64 ( - IN CONST UINT64 *Buffer + IN CONST VOID *Buffer ) { UINT32 LowerBytes; @@ -231,7 +231,7 @@ ReadUnaligned64 ( UINT64 EFIAPI WriteUnaligned64 ( - OUT UINT64 *Buffer, + OUT VOID *Buffer, IN UINT64 Value ) { diff --git a/MdePkg/Library/BaseLib/Unaligned.c b/MdePkg/Library/BaseLib/Unaligned.c index 68dafa6..ed58861 100644 --- a/MdePkg/Library/BaseLib/Unaligned.c +++ b/MdePkg/Library/BaseLib/Unaligned.c @@ -32,12 +32,14 @@ UINT16 EFIAPI ReadUnaligned16 ( - IN CONST UINT16 *Buffer + IN CONST VOID *Buffer ) { + CONST UINT16 *Input = Buffer; + ASSERT (Buffer != NULL); - return *Buffer; + return *Input; } /** @@ -58,13 +60,15 @@ ReadUnaligned16 ( UINT16 EFIAPI WriteUnaligned16 ( - OUT UINT16 *Buffer, + OUT VOID *Buffer, IN UINT16 Value ) { + UINT16 *Output = Buffer; + ASSERT (Buffer != NULL); - return *Buffer = Value; + return *Output = Value; } /** @@ -83,12 +87,14 @@ WriteUnaligned16 ( UINT32 EFIAPI ReadUnaligned24 ( - IN CONST UINT32 *Buffer + IN CONST VOID *Buffer ) { + CONST UINT32 *Input = Buffer; + ASSERT (Buffer != NULL); - return *Buffer & 0xffffff; + return *Input & 0xffffff; } /** @@ -109,13 +115,15 @@ ReadUnaligned24 ( UINT32 EFIAPI WriteUnaligned24 ( - OUT UINT32 *Buffer, + OUT VOID *Buffer, IN UINT32 Value ) { + UINT32 *Output = Buffer; + ASSERT (Buffer != NULL); - *Buffer = BitFieldWrite32 (*Buffer, 0, 23, Value); + *Output = BitFieldWrite32 (*Output, 0, 23, Value); return Value; } @@ -135,12 +143,14 @@ WriteUnaligned24 ( UINT32 EFIAPI ReadUnaligned32 ( - IN CONST UINT32 *Buffer + IN CONST VOID *Buffer ) { + CONST UINT32 *Input = Buffer; + ASSERT (Buffer != NULL); - return *Buffer; + return *Input; } /** @@ -161,13 +171,15 @@ ReadUnaligned32 ( UINT32 EFIAPI WriteUnaligned32 ( - OUT UINT32 *Buffer, + OUT VOID *Buffer, IN UINT32 Value ) { + UINT32 *Output = Buffer; + ASSERT (Buffer != NULL); - return *Buffer = Value; + return *Output = Value; } /** @@ -186,12 +198,14 @@ WriteUnaligned32 ( UINT64 EFIAPI ReadUnaligned64 ( - IN CONST UINT64 *Buffer + IN CONST VOID *Buffer ) { + CONST UINT64 *Input = Buffer; + ASSERT (Buffer != NULL); - return *Buffer; + return *Input; } /** @@ -212,11 +226,13 @@ ReadUnaligned64 ( UINT64 EFIAPI WriteUnaligned64 ( - OUT UINT64 *Buffer, + OUT VOID *Buffer, IN UINT64 Value ) { + UINT64 *Output = Buffer; + ASSERT (Buffer != NULL); - return *Buffer = Value; + return *Output = Value; }