From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from EUR04-VI1-obe.outbound.protection.outlook.com (EUR04-VI1-obe.outbound.protection.outlook.com [40.107.8.74]) by mx.groups.io with SMTP id smtpd.web10.6637.1594549962714862758 for ; Sun, 12 Jul 2020 03:32:43 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@armh.onmicrosoft.com header.s=selector2-armh-onmicrosoft-com header.b=TkAGD4wv; spf=pass (domain: arm.com, ip: 40.107.8.74, mailfrom: tomas.pilar@arm.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=xNYP0HilM/I4bv+QK5HOX2eVGAGv7Z6pE+kfBHMAfLU=; b=TkAGD4wvdpGXt/clKCSwRxsKMtJT1btyvn+zG3TzzJl39319hmhzZcLtpKmzu3laq29LECsZg0zJVl9GQUz3Q306lzxXlcuD9GA/kn3sBvaFeHs8kbOxnnzn0YvbtoskYX36qk6dy4RIHkxnCUjlej4mgvbdo/wwvqkzlBOMTtE= Received: from DB6PR0802CA0026.eurprd08.prod.outlook.com (2603:10a6:4:a3::12) by DBBPR08MB4917.eurprd08.prod.outlook.com (2603:10a6:10:f1::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.22; Sun, 12 Jul 2020 10:32:39 +0000 Received: from DB5EUR03FT015.eop-EUR03.prod.protection.outlook.com (2603:10a6:4:a3:cafe::17) by DB6PR0802CA0026.outlook.office365.com (2603:10a6:4:a3::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.21 via Frontend Transport; Sun, 12 Jul 2020 10:32:39 +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 (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; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by DB5EUR03FT015.mail.protection.outlook.com (10.152.20.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.21 via Frontend Transport; Sun, 12 Jul 2020 10:32:39 +0000 Received: ("Tessian outbound 1dc58800d5dd:v62"); Sun, 12 Jul 2020 10:32:39 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: da62a33b9ec669c4 X-CR-MTA-TID: 64aa7808 Received: from e4fecd5eed28.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 6632697E-52C2-4ACE-B2A9-4DD8A830E9EB.1; Sun, 12 Jul 2020 10:32:34 +0000 Received: from EUR04-HE1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id e4fecd5eed28.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Sun, 12 Jul 2020 10:32:34 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dPZhgfkjawsCzOCk+q+Z5zOdaaTHhwcaymoinbog9KkZ/lg5jRq2iWTGfBRdZrXHOSlmRw+hQaq4jIvp3/D5MF2t9zvKu8QAcd3jS6UAmnf6z/9elzFPrfTBjUDoJVz9H52mojZVAF5vZbKQ4b6kDP5uph1lTXTFqm+Rotc9GGFxz/ReRSm7HZHd2BfMJZ76hzbcKJ0f8E+PzoQ45PmTNvvtewWXD33jkX9vzBYcBpNp4QO7krVg6t71x9ybpFSEIfpfUojebV2KFnGCDfUEaws8F0L3H88ljCHFuWWQMmj5mrpJjKgdQ4zdKUAkoYHz4ISUbfAeQX+Ssm4m4MUSBA== 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=xNYP0HilM/I4bv+QK5HOX2eVGAGv7Z6pE+kfBHMAfLU=; b=G/QkHRZkL5/qVgGPB1x+sBsUk6e02Q/jCV9nJMsLOS1OBmE8NRq+tbu9or1IMXwEtaxbNZ2J4X2CJjcSusaKErykBzxB0LypjU+TtXlydftOLAA0+GERrdRSkDTgzr5/O6aPNvF0D1vLvJw70agZ34NH80veSOGiBQZ+/25TsZTVzG5xSYBfqjajlovhqc723auxG0PfeubB5Kjl8GECP4o5aYgVeLtoYm0q35AvnqFwHQY5Xjrk7EV7z+Tq/omIRe0jbO82PiN6CbDEzFkOuhjU/6k5ogbR0S4yXTXdZlMcW6Uas0pBY//o0sO0/7nmJj0QSaY9ZnLbas7uaGgdIw== 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=xNYP0HilM/I4bv+QK5HOX2eVGAGv7Z6pE+kfBHMAfLU=; b=TkAGD4wvdpGXt/clKCSwRxsKMtJT1btyvn+zG3TzzJl39319hmhzZcLtpKmzu3laq29LECsZg0zJVl9GQUz3Q306lzxXlcuD9GA/kn3sBvaFeHs8kbOxnnzn0YvbtoskYX36qk6dy4RIHkxnCUjlej4mgvbdo/wwvqkzlBOMTtE= Received: from DBBPR09CA0018.eurprd09.prod.outlook.com (2603:10a6:10:c0::30) by AM6PR08MB4214.eurprd08.prod.outlook.com (2603:10a6:20b:8d::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.20; Sun, 12 Jul 2020 10:32:31 +0000 Received: from DB5EUR03FT008.eop-EUR03.prod.protection.outlook.com (2603:10a6:10:c0:cafe::25) by DBBPR09CA0018.outlook.office365.com (2603:10a6:10:c0::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.21 via Frontend Transport; Sun, 12 Jul 2020 10:32:30 +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; Received: from nebula.arm.com (40.67.248.234) by DB5EUR03FT008.mail.protection.outlook.com (10.152.20.98) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.3174.21 via Frontend Transport; Sun, 12 Jul 2020 10:32:30 +0000 Received: from AZ-NEU-EX04.Arm.com (10.251.24.32) by AZ-NEU-EX03.Arm.com (10.251.24.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1415.2; Sun, 12 Jul 2020 10:32:30 +0000 Received: from localhost.localdomain (10.57.55.192) by mail.arm.com (10.251.24.32) with Microsoft SMTP Server id 15.1.1415.2 via Frontend Transport; Sun, 12 Jul 2020 10:32:29 +0000 From: "Tomas Pilar (tpilar)" To: CC: , , Ray Ni , "Zhichao Gao" Subject: [PATCH v2 4/8] ShellPkg/AcpiView: Create a logging facility Date: Sun, 12 Jul 2020 11:32:11 +0100 Message-ID: <20200712103215.855-5-Tomas.Pilar@arm.com> X-Mailer: git-send-email 2.24.1.windows.2 In-Reply-To: <20200712103215.855-1-Tomas.Pilar@arm.com> References: <20200712103215.855-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)(136003)(346002)(376002)(396003)(39850400004)(46966005)(356005)(5660300002)(36756003)(82310400002)(6666004)(83380400001)(54906003)(6916009)(86362001)(81166007)(316002)(478600001)(30864003)(186003)(4326008)(1076003)(2906002)(26005)(82740400003)(8676002)(2616005)(70586007)(70206006)(47076004)(19627235002)(426003)(336012)(8936002)(403724002);DIR:OUT;SFP:1101; X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6ea61644-ad44-49da-704c-08d8264ee6ce X-MS-TrafficTypeDiagnostic: AM6PR08MB4214:|DBBPR08MB4917: 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: LA/7rSkYZrHJJYca9Cp+F4uJN795ZIy1jAdOivxJkwZ0AFX6XNb92ci0/r/vLKKfMwChfLr28ZlfEM1j0Gms99ue2TuLhGSmxdxJwcDhz7ftfLIT/aYLmpwo7dWox487kT3z3X1+Fz5YHYtUoroyfT+DN5WvXPeqvLKMIHrNLKbZ/g4E8eItr0jK5DwIErWfUJCZii3GK/NG9Wu/j8hi+FCya7eZhPL7dZMsvdophyTKyrZDhh7ChGWHlH+QDzdSQG2a2e1yZii97lT5DzSui17Jy+bhDuoHhmH7hZGDR14eGPnq3E09Mk37QjEowJoTYeJRohpmrb5MtfZ6NffoYuW7rdaJOohXtwGJM9YH9+E2nR8qt8qrAm9AqxdohScJbftPw6Ftp4ONj6LoCvyD0x56WmibYSqXQFqrm83l72A= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB4214 Return-Path: Tomas.Pilar@arm.com X-MS-Exchange-Transport-CrossTenantHeadersStripped: DB5EUR03FT015.eop-EUR03.prod.protection.outlook.com X-Forefront-Antispam-Report: CIP:63.35.35.123;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:64aa7808-outbound-1.mta.getcheckrecipient.com;PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com;CAT:NONE;SFTY:;SFS:(4636009)(136003)(346002)(396003)(376002)(39850400004)(46966005)(478600001)(1076003)(2906002)(316002)(54906003)(6666004)(4326008)(8936002)(6916009)(5660300002)(30864003)(186003)(2616005)(83380400001)(426003)(336012)(19627235002)(82310400002)(26005)(107886003)(82740400003)(36756003)(47076004)(81166007)(86362001)(70206006)(70586007)(8676002)(403724002);DIR:OUT;SFP:1101; X-MS-Office365-Filtering-Correlation-Id-Prvs: bad553c2-66fc-4bab-d1b1-08d8264ee1bd X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: LSuqbnUwF+WGbzex6LGkZhmiUN07XZGdjznPuhL/GMSrIzIRSjH8IuAjETued7RVF5sfbAegS1UtzBD1PsS5CVScTnp9S7QM7upbzG7R0P/Zw8noihdq6HsTi/1dfI6IeFpkknAwZ4AS9qq8iwJLXB//3MVtlFg5PqqK5Yk3CvUKHwE9uH61/gsOSyp8+ca7tVqlvXrXSSO3WRL4aTDHoOf9Cpj6pygrBp0OTC2mkSy4tVejJxcFHrI9D9fyU1S08f7x1xq4Hs/++vV7PsrRra42a6J/vdqfntQm4RKYRzOYSmvwNcFpflCbk/hy9X1e3Nb6f58A/1YbMmb271mvWRtz7J+b3jxpZmAYODMgOIe6vrXNQjgetXTEueTZYUxzGOy/us96g264bW+zAKxcmiA4JiY+0M4whzmGvv9XACc= X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Jul 2020 10:32:39.4438 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6ea61644-ad44-49da-704c-08d8264ee6ce 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: DB5EUR03FT015.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBBPR08MB4917 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain Extract error and warning logging into separate methods. Fold highlighting and other output properties into the logging methods. Change-Id: I46bba2afc6fe8d7bc0c92ec7054f2af2d2254441 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 lin= e + 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