From nobody Mon Feb 9 12:26:34 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+62549+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 159474877661490.54499934250953; Tue, 14 Jul 2020 10:46:16 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id eFgjYY1788612xVN5wOen99F; Tue, 14 Jul 2020 10:46:16 -0700 X-Received: from EUR05-AM6-obe.outbound.protection.outlook.com (EUR05-AM6-obe.outbound.protection.outlook.com [40.107.22.53]) by mx.groups.io with SMTP id smtpd.web12.1962.1594748774154536354 for ; Tue, 14 Jul 2020 10:46:14 -0700 X-Received: from AM5PR0601CA0038.eurprd06.prod.outlook.com (2603:10a6:203:68::24) by AM6PR08MB4952.eurprd08.prod.outlook.com (2603:10a6:20b:e1::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.21; Tue, 14 Jul 2020 17:46:11 +0000 X-Received: from AM5EUR03FT023.eop-EUR03.prod.protection.outlook.com (2603:10a6:203:68:cafe::f0) by AM5PR0601CA0038.outlook.office365.com (2603:10a6:203:68::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.17 via Frontend Transport; Tue, 14 Jul 2020 17:46:11 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; edk2.groups.io; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;edk2.groups.io; dmarc=bestguesspass action=none header.from=arm.com; Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+62549+1787277+3901457@groups.io; helo=web01.groups.io; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; X-Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by AM5EUR03FT023.mail.protection.outlook.com (10.152.16.169) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.21 via Frontend Transport; Tue, 14 Jul 2020 17:46:11 +0000 X-Received: ("Tessian outbound 8f45de5545d6:v62"); Tue, 14 Jul 2020 17:46:11 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: c221e0e74706cc24 X-CR-MTA-TID: 64aa7808 X-Received: from 5131f80b5d3f.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 82C88368-D242-499C-A42C-8181B799362D.1; Tue, 14 Jul 2020 17:46:05 +0000 X-Received: from EUR04-VI1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 5131f80b5d3f.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Tue, 14 Jul 2020 17:46:05 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=j7pZNwrbiqZ4hPhOYXe8CZ9rSUqwxx+lTlHaWucPG9sQWFbagxokePOeuXGJmC1ocNyOWxh7aVwbmoTks2tSzi3wcxT73D201YQ+k7pu2OY36/uwnXF0w0HvJOfYjosgDo/s1qcOLLoKFS04gm0ZzBoHG800oz1+AWQSEdUiOJNbjKucKc+iMhG2kmpKHK11jSJvBNnLm5ok0fYO0JTmvXDiHlf3YF8LTZU6n+pIMyNpBpDY1jogXPrJg95F+9Catk1/H8Rm18H6lSnN+wVONZfwfY2Vod9b5DCkfa0jTEaMPCOZzGEy5YTiPrNjyWUj0BLY+kh6n3pPqdoz5EiKaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=nFOqDQ9+6/s3776z3MiwvdbV4JARGnEfieAUHmTGAhs=; b=GErc5yW46pi3Sp+BfuBSSuos1YrlUMjIzsigxmM3NoleYTxDXmP8EnadYiT+XFs5jqB0Xn8MIIj2Bw8E9Vax6rR8/ERj0J1UNw+xR5EiSruArA64RyHpFaTicUHm8vSuszYzJWgwQ/vBaAziNdWZmm3IxI6Fpb4nWAXAgi5B2D8XjOh27Ivm/EG3XMitwhYAq+kJD7ifuV17wItHx5hX8cBP5fm3wxueSh0gzQEk33MqP0K+si8WvbkMJRLDTyiP/jZmGtidugqXSBptrG02g7k5BIScBGaHSsKOIh/o/53H5rCygNYB5nWH7jan4j1zmkF+KiCjzsZcoOef42j0Jg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 40.67.248.234) smtp.rcpttodomain=edk2.groups.io smtp.mailfrom=arm.com; dmarc=bestguesspass action=none header.from=arm.com; dkim=none (message not signed); arc=none X-Received: from AM6P194CA0019.EURP194.PROD.OUTLOOK.COM (2603:10a6:209:90::32) by DBBPR08MB4538.eurprd08.prod.outlook.com (2603:10a6:10:d2::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.21; Tue, 14 Jul 2020 17:46:03 +0000 X-Received: from AM5EUR03FT029.eop-EUR03.prod.protection.outlook.com (2603:10a6:209:90:cafe::ea) by AM6P194CA0019.outlook.office365.com (2603:10a6:209:90::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.22 via Frontend Transport; Tue, 14 Jul 2020 17:46:03 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 40.67.248.234) smtp.mailfrom=arm.com; edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=bestguesspass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 40.67.248.234 as permitted sender) receiver=protection.outlook.com; client-ip=40.67.248.234; helo=nebula.arm.com; X-Received: from nebula.arm.com (40.67.248.234) by AM5EUR03FT029.mail.protection.outlook.com (10.152.16.150) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.3174.21 via Frontend Transport; Tue, 14 Jul 2020 17:46:03 +0000 X-Received: from AZ-NEU-EX01.Emea.Arm.com (10.251.26.4) by AZ-NEU-EX03.Arm.com (10.251.24.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.1415.2; Tue, 14 Jul 2020 17:46:02 +0000 X-Received: from AZ-NEU-EX04.Arm.com (10.251.24.32) by AZ-NEU-EX01.Emea.Arm.com (10.251.26.4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1779.2; Tue, 14 Jul 2020 17:46:01 +0000 X-Received: from localhost.localdomain (10.57.32.194) by mail.arm.com (10.251.24.32) with Microsoft SMTP Server id 15.1.1415.2 via Frontend Transport; Tue, 14 Jul 2020 17:46:01 +0000 From: "Tomas Pilar (tpilar)" To: CC: , , Ray Ni , "Zhichao Gao" Subject: [edk2-devel] [PATCH v3 4/8] ShellPkg/AcpiView: Create a logging facility Date: Tue, 14 Jul 2020 18:45:42 +0100 Message-ID: <20200714174546.560-5-Tomas.Pilar@arm.com> In-Reply-To: <20200714174546.560-1-Tomas.Pilar@arm.com> References: <20200714174546.560-1-Tomas.Pilar@arm.com> MIME-Version: 1.0 X-EOPAttributedMessage: 1 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report-Untrusted: CIP:40.67.248.234;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:nebula.arm.com;PTR:InfoDomainNonexistent;CAT:NONE;SFTY:;SFS:(4636009)(46966005)(186003)(70206006)(82310400002)(54906003)(36756003)(70586007)(336012)(83380400001)(8676002)(356005)(81166007)(5660300002)(4326008)(6666004)(26005)(498600001)(30864003)(47076004)(2906002)(8936002)(19627235002)(6916009)(86362001)(2616005)(1076003)(426003)(403724002);DIR:OUT;SFP:1101; X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b5142593-ef2d-44fa-109d-08d8281dcbf1 X-MS-TrafficTypeDiagnostic: DBBPR08MB4538:|AM6PR08MB4952: X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Oob-TLC-OOBClassifiers: OLM:10000;OLM:10000; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: ouCABwD8Lee5796Xa0LjbrJq48OhIChCrFgVpM1kMgW2eH1dB6x2bumnEBsJ1jcmmkSKGcqO3R6pack2cEuErfUEeBQGpIrDWgZwr10XRNq6CyGkdx2QSHySVqZDMSYQ9I0sw6GE6jjOg/1D1qLLXdWutxTlB8APQyJKwWy/aZfK/mEyW2xd/d0MeGohWEq4uTyhF4zlGYvPXyhm5tR7fq44SB0SjZPQBtOrvlxzjn0Sxu+ruEm5emtBxgY2EYXB1qb0huhK/S40FoVd3hHPImJEL3GWAk8AtlJx/sW2vArb354FAD7CjjO4vzHH84Zb2ctUV9QMBmvgBffhl62mnH16ZDgqw7tHO2hJPhWwHwP9M0aEepYt3GScL0JnqWs/EhMpEqhurBhxQNpCNsTzcfqf7y2H24BZzIk9+cXHkfY= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBBPR08MB4538 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM5EUR03FT023.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: ab54b6ad-5628-47ea-1aeb-08d8281dc71e X-Microsoft-Antispam-Message-Info: XPwHZC5a9m6kfhLyykHvxpRgo/3VdJRARQ0smSbo02SbqCeHPtpKpsMcolgLTGauT5I5cnLI02ASCy/RPqWeCANiJ3jjKbHU/SOyL5NJUIruIqkIixpC4xFC3k3uBcxWOy1NJhQv8VC+FkySh7WoCm25UIYjhMH8ufyb+N/m6ZAPJim0yaBkM8I6OXzn+MZ102cLe200oBYTpCn5HtioTe9syiWy8cV+XYgWM+4uwp7ycIDV8UuRuHiTkYVq5DDi6jR1A5GQqG9+FFV93g1hRHfSuy/DtzyaKLsAjXeOjyHmW2xPIxPiP+dCUe/35VeRDSfOxhfrbRFW54GLEsgMQJ27q5kNqXeRrR/V9iR617OtI5J7UFykXSoJjPBAO5qRNV20GbmL6YbID7u4Q+bWPz2fJy5a9TWHH0GePRAnqr0= X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jul 2020 17:46:11.2821 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b5142593-ef2d-44fa-109d-08d8281dcbf1 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d;Ip=[63.35.35.123];Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: AM5EUR03FT023.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB4952 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,Tomas.Pilar@arm.com X-Gm-Message-State: OJRGPm2XBo28iLwnG5tiuLu4x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1594748776; bh=sQp4KU7boKwMZJJHQjboAkh8umNjtIEz8VjoPcX6oLA=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=dwPI3EFi5BfenKBMwqLxbrIz8fuje5NzVFssq2/XQE8y9bsy35sD6U1h250+e8ubq6V 2HPX14ZzExASDe4bw+eiIzsbnrUfvixZvWtGq9EgrFLB56pKWR3D5Pk6JFcMB7nAjZ/es ua2TacpfP/OTBITqluvp5bGqEGi0Yekted8= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Extract error and warning logging into separate methods. Fold highlighting and other output properties into the logging methods. Cc: Ray Ni Cc: Zhichao Gao Signed-off-by: Tomas Pilar --- .../UefiShellAcpiViewCommandLib/AcpiParser.c | 5 +- .../UefiShellAcpiViewCommandLib/AcpiViewLog.c | 338 ++++++++++++++++++ .../UefiShellAcpiViewCommandLib/AcpiViewLog.h | 192 ++++++++++ .../UefiShellAcpiViewCommandLib.inf | 2 + 4 files changed, 533 insertions(+), 4 deletions(-) create mode 100644 ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiViewLo= g.c create mode 100644 ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiViewLo= g.h diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c b/Sh= ellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c index 7017fa93efae..b88594cf3865 100644 --- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiParser.c @@ -11,13 +11,10 @@ #include "AcpiParser.h" #include "AcpiView.h" #include "AcpiViewConfig.h" +#include "AcpiViewLog.h" =20 STATIC UINT32 gIndent; =20 -// Publicly accessible error and warning counters. -UINT32 mTableErrorCount; -UINT32 mTableWarningCount; - STATIC ACPI_DESCRIPTION_HEADER_INFO AcpiHdrInfo; =20 /** diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiViewLog.c b/S= hellPkg/Library/UefiShellAcpiViewCommandLib/AcpiViewLog.c new file mode 100644 index 000000000000..7ec276ac7528 --- /dev/null +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiViewLog.c @@ -0,0 +1,338 @@ +/** @file + 'acpiview' logging and output facility + + Copyright (c) 2020, ARM Limited. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include "AcpiViewLog.h" +#include "AcpiViewConfig.h" +#include "AcpiParser.h" +#include +#include + +static CHAR16 mOutputBuffer [MAX_OUTPUT_SIZE] =3D { 0 }; + +// String descriptions of error types +static const CHAR16* mErrorTypeDesc [ACPI_ERROR_MAX] =3D { + L"Not an error", ///< ACPI_ERROR_NONE + L"Generic", ///< ACPI_ERROR_GENERIC + L"Checksum", ///< ACPI_ERROR_CSUM + L"Parsing", ///< ACPI_ERROR_PARSE + L"Length", ///< ACPI_ERROR_LENGTH + L"Value", ///< ACPI_ERROR_VALUE + L"Cross-check", ///< ACPI_ERROR_CROSS +}; + +// Publicly accessible error and warning counters. +UINT32 mTableErrorCount; +UINT32 mTableWarningCount; + +/** + Change the attributes of the standard output console + to change the colour of the text according to the given + severity of a log message. + + @param[in] Severity The severity of the log message that is bei= ng + annotated with changed colour text. + @param[in] OriginalAttribute The current attributes of ConOut that will + be modified. +**/ +static +VOID +EFIAPI +ApplyColor ( + IN ACPI_LOG_SEVERITY Severity, + IN UINTN OriginalAttribute + ) +{ + if (!mConfig.ColourHighlighting) { + return; + } + + // Strip the foreground colour + UINTN NewAttribute =3D OriginalAttribute & 0xF0; + + // Add specific foreground colour based on severity + switch (Severity) { + case ACPI_DEBUG: + NewAttribute |=3D EFI_DARKGRAY; + break; + case ACPI_HIGHLIGHT: + NewAttribute |=3D EFI_LIGHTBLUE; + break; + case ACPI_GOOD: + NewAttribute |=3D EFI_GREEN; + break; + case ACPI_ITEM: + case ACPI_WARN: + NewAttribute |=3D EFI_YELLOW; + break; + case ACPI_BAD: + case ACPI_ERROR: + case ACPI_FATAL: + NewAttribute |=3D EFI_RED; + break; + case ACPI_INFO: + default: + NewAttribute |=3D OriginalAttribute; + break; + } + + gST->ConOut->SetAttribute (gST->ConOut, NewAttribute); +} + +/** + Restore ConOut text attributes. + + @param[in] OriginalAttribute The attribute set that will be restored. +**/ +static +VOID +EFIAPI +RestoreColor( + IN UINTN OriginalAttribute + ) +{ + gST->ConOut->SetAttribute (gST->ConOut, OriginalAttribute); +} + +/** + Formats and prints an ascii string to screen. + + @param[in] Format String that will be formatted and printed. + @param[in] Marker The marker for variable parameters to be formatted. +**/ +static +VOID +EFIAPI +AcpiViewVSOutput ( + IN const CHAR16 *Format, + IN VA_LIST Marker + ) +{ + UnicodeVSPrint (mOutputBuffer, sizeof(mOutputBuffer), Format, Marker); + gST->ConOut->OutputString (gST->ConOut, mOutputBuffer); +} + +/** + Formats and prints and ascii string to screen. + + @param[in] Format String that will be formatted and printed. + @param[in] ... A variable number of parameters that will be formatted. +**/ +VOID +EFIAPI +AcpiViewOutput ( + IN const CHAR16 *Format, + IN ... + ) +{ + VA_LIST Marker; + VA_START (Marker, Format); + + AcpiViewVSOutput (Format, Marker); + + VA_END (Marker); +} + + +/** + Prints the base file name given a full file path. + + @param[in] FullName Fully qualified file path +**/ +VOID +EFIAPI +PrintFileName ( + IN const CHAR8* FullName + ) +{ + const CHAR8* Cursor; + UINTN Size; + + Cursor =3D FullName; + Size =3D 0; + + // Find the end point of the string. + while (*Cursor && Cursor < FullName + MAX_OUTPUT_SIZE) + Cursor++; + + // Find the rightmost path separator. + while (*Cursor !=3D '\\' && *Cursor !=3D '/' && Cursor > FullName) { + Cursor--; + Size++; + } + + // Print base file name. + AcpiViewOutput (L"%.*a", Size - 1, Cursor + 1); +} + +/** + AcpiView output and logging function. Will log the event to + configured output (currently screen) and annotate with colour + and extra metadata. + + @param[in] FileName The full filename of the source file where this + event occured. + @param[in] FunctionName The name of the function where this event occur= ed. + @param[in] LineNumber The line number in the source code where this e= vent + occured. + @param[in] Severity The severity of the event that occured. + @param[in] Format The format of the string describing the event. + @param[in] ... The variable number of parameters that will for= mat the + string supplied in Format. +**/ +VOID +EFIAPI +AcpiViewLog ( + IN const CHAR8 *FileName, + IN const CHAR8 *FunctionName, + IN UINTN LineNumber, + IN ACPI_ERROR_TYPE Error, + IN ACPI_LOG_SEVERITY Severity, + IN const CHAR16 *Format, + ... + ) +{ + VA_LIST Marker; + UINTN OriginalAttribute; + + OriginalAttribute =3D gST->ConOut->Mode->Attribute; + ApplyColor (Severity, OriginalAttribute); + VA_START (Marker, Format); + + switch (Severity) { + case ACPI_FATAL: + AcpiViewOutput (L"FATAL "); + break; + case ACPI_ERROR: + AcpiViewOutput (L"ERROR[%s] ", mErrorTypeDesc[Error]); + mTableErrorCount++; + break; + case ACPI_WARN: + AcpiViewOutput (L"WARN "); + mTableWarningCount++; + break; + default: + break; + } + + if (Severity >=3D ACPI_WARN) { + AcpiViewOutput (L"("); + PrintFileName (FileName); + AcpiViewOutput (L":%d) ", LineNumber); + } + + AcpiViewVSOutput (Format, Marker); + AcpiViewOutput (L"\n"); + + VA_END (Marker); + RestoreColor (OriginalAttribute); +} + +/** + Check that a buffer has not been overrun by a member. Can be invoked + using the BufferOverrun macro that fills in local source metadata + (first three parameters) for logging purposes. + + @param[in] FileName Source file where this invocation is made + @param[in] FunctionName Name of the local symbol + @param[in] LineNumber Source line number of the local call + @param[in] ItemDescription User friendly name for the member being check= ed + @param[in] Position Memory address of the member + @param[in] Length Length of the member + @param[in] Buffer Memory address of the buffer where member res= ides + @param[in] BufferSize Size of the buffer where member resides + + @retval TRUE Buffer was overrun + @retval FALSE Buffer is safe +**/ +BOOLEAN +EFIAPI +MemberIntegrityInternal ( + IN const CHAR8 *FileName, + IN const CHAR8 *FunctionName, + IN UINTN LineNumber, + IN const CHAR8 *ItemDescription, + IN UINTN Offset, + IN UINTN Length, + IN VOID *Buffer, + IN UINTN BufferSize + ) +{ + if (Length =3D=3D 0) { + AcpiViewLog ( + FileName, + FunctionName, + LineNumber, + ACPI_ERROR_LENGTH, + ACPI_ERROR, + L"%a at %p in buffer %p+%x has zero size!", + ItemDescription, + (UINT8 *)Buffer + Offset, + Buffer, + BufferSize); + return TRUE; + } + + if (Offset + Length > BufferSize) { + AcpiViewLog ( + FileName, + FunctionName, + LineNumber, + ACPI_ERROR_LENGTH, + ACPI_ERROR, + L"%a %p+%x overruns buffer %p+%x", + ItemDescription, + (UINT8 *) Buffer + Offset, + Length, + Buffer, + BufferSize); + } + + return (Offset + Length > BufferSize); +} + +/** + Checks that a boolean constraint evaluates correctly. Can be invoked + using the CheckConstraint macro that fills in the source code metadata. + + @param[in] FileName Source file where this invocation is made + @param[in] FunctionName Name of the local symbol + @param[in] LineNumber Source line number of the local call + @param[in] ConstraintText The Source code of the constraint + @param[in] Specification The specification that imposes the constraint + @param[in] Constraint The actual constraint + @ + + @retval TRUE Constraint is violated + @retval FALSE Constraint is not violated +**/ +BOOLEAN +EFIAPI +CheckConstraintInternal ( + IN const CHAR8 *FileName, + IN const CHAR8 *FunctionName, + IN UINTN LineNumber, + IN const CHAR8 *ConstraintText, + IN const CHAR16 *Specification, + IN BOOLEAN Constraint, + IN ACPI_LOG_SEVERITY Severity +) +{ + if (!Constraint) { + AcpiViewLog ( + FileName, + FunctionName, + LineNumber, + Severity =3D=3D ACPI_ERROR ? ACPI_ERROR_VALUE : ACPI_ERROR_NONE, + Severity, + L"(%a) Constraint was violated: %a", + Specification, + ConstraintText); + } + + // Return TRUE if constraint was violated + return !Constraint; +} diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiViewLog.h b/S= hellPkg/Library/UefiShellAcpiViewCommandLib/AcpiViewLog.h new file mode 100644 index 000000000000..ce276ef7add2 --- /dev/null +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiViewLog.h @@ -0,0 +1,192 @@ +/** @file + Header file for 'acpiview' logging and output facility + + Copyright (c) 2020, ARM Limited. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#ifndef ACPI_VIEW_LOG_H_ +#define ACPI_VIEW_LOG_H_ + +/** + Categories of errors that can be logged by AcpiView. +*/ +typedef enum { + ACPI_ERROR_NONE, ///< Not an error + ACPI_ERROR_GENERIC, ///< An unspecified error + ACPI_ERROR_CSUM, ///< A checksum was invalid + ACPI_ERROR_PARSE, ///< Failed to parse item + ACPI_ERROR_LENGTH, ///< Size of a thing is incorrect + ACPI_ERROR_VALUE, ///< The value of a field was incorrect + ACPI_ERROR_CROSS, ///< A constraint on multiple items was violated + ACPI_ERROR_MAX +} ACPI_ERROR_TYPE; + +/** + Different severities of events that can be logged. +*/ +typedef enum { + ACPI_DEBUG, ///< Will not be shown unless specified on command line + ACPI_INFO, ///< Standard output + ACPI_GOOD, ///< Unspecified good outcome, green colour + ACPI_BAD, ///< Unspecified bad outcome, red colour + ACPI_ITEM, ///< Used when describing multiple items + ACPI_HIGHLIGHT, ///< A new context or section has been entered + ACPI_WARN, ///< An unusual event happened + ACPI_ERROR, ///< Acpi table is not conformant + ACPI_FATAL ///< This will abort program execution. +} ACPI_LOG_SEVERITY; + +// Publicly accessible error and warning counters. +extern UINT32 mTableErrorCount; +extern UINT32 mTableWarningCount; + +/** + AcpiView output and logging function. Will log the event to + configured output (currently screen) and annotate with colour + and extra metadata. + + @param[in] FileName The full filename of the source file where this + event occured. + @param[in] FunctionName The name of the function where this event occur= ed. + @param[in] LineNumber The line number in the source code where this e= vent + occured. + @param[in] Severity The severity of the event that occured. + @param[in] Error The type of the erorr reported. May be ACPI_ERR= OR_NONE if the event + is not an error. + @param[in] Format The format of the string describing the event. + @param[in] ... The variable number of parameters that will for= mat the + string supplied in Format. +**/ +VOID +EFIAPI +AcpiViewLog ( + IN const CHAR8 *FileName, + IN const CHAR8 *FunctionName, + IN UINTN LineNumber, + IN ACPI_ERROR_TYPE Error, + IN ACPI_LOG_SEVERITY Severity, + IN const CHAR16 *Format, + ... + ); + +/** + Formats and prints and ascii string to screen. + + @param[in] Format String that will be formatted and printed. + @param[in] ... A variable number of parameters that will be formatted. +**/ +VOID +EFIAPI +AcpiViewOutput ( + IN const CHAR16 *Format, + IN ... + ); + +/** + Check that a buffer has not been overrun by a member. Can be invoked + using the BufferOverrun macro that fills in local source metadata + (first three parameters) for logging purposes. + + @param[in] FileName Source file where this invocation is made + @param[in] FunctionName Name of the local symbol + @param[in] LineNumber Source line number of the local call + @param[in] ItemDescription User friendly name for the member being check= ed + @param[in] Position Memory address of the member + @param[in] Length Length of the member + @param[in] Buffer Memory address of the buffer where member res= ides + @param[in] BufferSize Size of the buffer where member resides + + @retval TRUE Buffer was overrun + @retval FALSE Buffer is safe +**/ +BOOLEAN +EFIAPI +MemberIntegrityInternal ( + IN const CHAR8 *FileName, + IN const CHAR8 *FunctionName, + IN UINTN LineNumber, + IN const CHAR8 *ItemDescription, + IN UINTN Offset, + IN UINTN Length, + IN VOID *Buffer, + IN UINTN BufferSize + ); + +// Determine if a member located at Offset into a Buffer lies entirely +// within the BufferSize given the member size is Length +// Evaluates to TRUE and logs error if buffer is overrun or if Length is z= ero +#define AssertMemberIntegrity(Offset, Length, Buffer, BufferSize) \ + MemberIntegrityInternal (__FILE__, __func__, __LINE__, #Length, Offset, = Length, Buffer, BufferSize) + + +/** + Checks that a boolean constraint evaluates correctly. Can be invoked + using the CheckConstraint macro that fills in the source code metadata. + + @param[in] FileName Source file where this invocation is made + @param[in] FunctionName Name of the local symbol + @param[in] LineNumber Source line number of the local call + @param[in] ConstraintText The Source code of the constraint + @param[in] Specification The specification that imposes the constraint + @param[in] Constraint The actual constraint + @ + + @retval TRUE Constraint is violated + @retval FALSE Constraint is not violated +**/ +BOOLEAN +EFIAPI +CheckConstraintInternal ( + IN const CHAR8 *FileName, + IN const CHAR8 *FunctionName, + IN UINTN LineNumber, + IN const CHAR8 *ConstraintText, + IN const CHAR16 *Specification, + IN BOOLEAN Constraint, + IN ACPI_LOG_SEVERITY Severity + ); + +// Evaluates to TRUE and logs error if a constraint is violated +// Constraint internally cast to BOOLEAN using !!(Constraint) +#define AssertConstraint(Specification, Constraint) \ + CheckConstraintInternal ( \ + __FILE__, \ + __func__, \ + __LINE__, \ + #Constraint, \ + Specification, \ + !!(Constraint), \ + ACPI_ERROR) + +// Evaluates to TRUE and logs error if a constraint is violated +// Constraint internally cast to BOOLEAN using !!(Constraint) +#define WarnConstraint(Specification, Constraint) \ + CheckConstraintInternal ( \ + __FILE__, \ + __func__, \ + __LINE__, \ + #Constraint, \ + Specification, \ + !!(Constraint), \ + ACPI_WARN) + + +// Maximum string size that can be printed +#define MAX_OUTPUT_SIZE 256 + +#define _AcpiLog(...) AcpiViewLog(__FILE__, __func__, __LINE__, __VA_ARGS_= _) + +// Generic Loging macro, needs severity and formatted string +#define AcpiLog(Severity, ...) _AcpiLog(ACPI_ERROR_NONE, Severity, __VA_AR= GS__) + +// Log undecorated text, needs formatted string +#define AcpiInfo(...) _AcpiLog(ACPI_ERROR_NONE, ACPI_INFO, __VA_ARGS__) + +// Log error and increment counter, needs error type and formatted string +#define AcpiError(Error, ...) _AcpiLog(Error, ACPI_ERROR, __VA_ARGS__) + +// Log a FATAL error, needs formatted string +#define AcpiFatal(...) _AcpiLog(ACPI_ERROR_GENERIC, ACPI_FATAL, __VA_ARGS_= _) + +#endif // ACPI_VIEW_LOG_H_ diff --git a/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiView= CommandLib.inf b/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpi= ViewCommandLib.inf index 91459f9ec632..e0586cbccec2 100644 --- a/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommand= Lib.inf +++ b/ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommand= Lib.inf @@ -27,6 +27,8 @@ [Sources.common] AcpiView.h AcpiViewConfig.c AcpiViewConfig.h + AcpiViewLog.h + AcpiViewLog.c Parsers/Bgrt/BgrtParser.c Parsers/Dbg2/Dbg2Parser.c Parsers/Dsdt/DsdtParser.c --=20 2.24.1.windows.2 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#62549): https://edk2.groups.io/g/devel/message/62549 Mute This Topic: https://groups.io/mt/75504249/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-