From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=pass header.i=@intel.onmicrosoft.com header.s=selector2-intel-onmicrosoft-com header.b=qMkM5X07; spf=pass (domain: intel.com, ip: 192.55.52.88, mailfrom: michael.a.kubacki@intel.com) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by groups.io with SMTP; Fri, 27 Sep 2019 10:32:14 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Sep 2019 10:32:06 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,556,1559545200"; d="scan'208";a="219856488" Received: from fmsmsx103.amr.corp.intel.com ([10.18.124.201]) by fmsmga002.fm.intel.com with ESMTP; 27 Sep 2019 10:32:05 -0700 Received: from fmsmsx113.amr.corp.intel.com (10.18.116.7) by FMSMSX103.amr.corp.intel.com (10.18.124.201) with Microsoft SMTP Server (TLS) id 14.3.439.0; Fri, 27 Sep 2019 10:32:05 -0700 Received: from FMSEDG002.ED.cps.intel.com (10.1.192.134) by FMSMSX113.amr.corp.intel.com (10.18.116.7) with Microsoft SMTP Server (TLS) id 14.3.439.0; Fri, 27 Sep 2019 10:32:04 -0700 Received: from NAM05-DM3-obe.outbound.protection.outlook.com (104.47.49.52) by edgegateway.intel.com (192.55.55.69) with Microsoft SMTP Server (TLS) id 14.3.439.0; Fri, 27 Sep 2019 10:32:05 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TKv/zAMD8+xoEXM5V3MyrwfnIaXKBvQvsyhyH9VrotwRl9EAtIdNDXt4JClkkppriP9zJKVuK0pTgWtQGV08dp6z3LPEj81J2NwQrBxdiTTJCEnZigR8WKMgrkp+nfozdRFEDw91OLCj6bHMZKx7pfYONeCFu4tpAXlHEdNzh9fwfBqQ0oZhZMVTOvaUO5y5pxkyFA8/w2FXoPJ2L16criqA8U1TwXULuN3rPdR70TVKThTv/FRuXL+JHlhk25jFZx5ERhqD/kCd+OMmOpVpR8B3u3wFfTOyxV3gzjIhSb3mbQuClgNaeRUUgkOHpSy3FEWvNssGWr89OzN6IsiLuA== 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=elU1MPr2Py+sSsyxGx9Us16JLj5wSIleX+z6RpWUazE=; b=JN5x1QAbkM2kJXoNoE+Q+8iSx2ja1vbPddVD01Lfs9k4vyeDTlceckkeeqrXCVU0nxxxvrbfgQSzJCkISAt4mp602RNYGnTAw472rm9xqm1EGZD0yciGCiRtqf1/uPPiFXsDROFyKJ24SnJHWeEsihQZr+9Xi0/zA4IwwHzyaXcX3tFkME9k2MP2Mvf33MEqxkV9c2qYRmt1LBoUjFlIR5CMGQouTnGKRZJ3Xx0lvILaRblp77Dy9eKPfLhkPNTSjOCsuVY96/gB1KGnNljybVfHv2FWiL2fPwgdAWg4/mDOf3m5JTO3E8gsivy7WtxXMikhjXujgcf02gjjKehmQA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.onmicrosoft.com; s=selector2-intel-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=elU1MPr2Py+sSsyxGx9Us16JLj5wSIleX+z6RpWUazE=; b=qMkM5X07thmCFEts0NgxRbVZKxaBhB1GTFxNf8W9N9GMiNzdKKeKJBj8VBEbH5XQLhI7uLSbCcxlMluOuP/jrmclcHaIGKkc8urO0NSu4I9D7KWJOSru/kJCbWk/cd//ib6gs4HZL9t3IJc2ML1FW1dPwoKyEkrnY3oGm8fJLGg= Received: from DM6PR11MB3834.namprd11.prod.outlook.com (20.179.17.87) by DM6PR11MB3787.namprd11.prod.outlook.com (20.179.16.202) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2284.20; Fri, 27 Sep 2019 17:31:48 +0000 Received: from DM6PR11MB3834.namprd11.prod.outlook.com ([fe80::59cc:8a30:6b9e:584e]) by DM6PR11MB3834.namprd11.prod.outlook.com ([fe80::59cc:8a30:6b9e:584e%3]) with mapi id 15.20.2305.017; Fri, 27 Sep 2019 17:31:48 +0000 From: "Kubacki, Michael A" To: "Wu, Hao A" , "devel@edk2.groups.io" CC: "Bi, Dandan" , Ard Biesheuvel , "Dong, Eric" , Laszlo Ersek , "Gao, Liming" , "Kinney, Michael D" , "Ni, Ray" , "Wang, Jian J" , "Yao, Jiewen" Subject: Re: [edk2-devel] [PATCH V1 1/5] MdeModulePkg/Variable: Consolidate common parsing functions Thread-Topic: [edk2-devel] [PATCH V1 1/5] MdeModulePkg/Variable: Consolidate common parsing functions Thread-Index: AQHVdQwIPgtFnMDPpkSHFB+T8wjL7ac/s0Og Date: Fri, 27 Sep 2019 17:31:48 +0000 Message-ID: References: <20190926045046.34592-1-michael.a.kubacki@intel.com> <20190926045046.34592-2-michael.a.kubacki@intel.com> In-Reply-To: Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows x-ctpclassification: CTP_NT x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiZGVlYWQxZDQtMTJmOS00NmFiLTgxOWEtNzQ0MjU2YTIwZjgxIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoienliYVR5Mmx0QVRza2h5bnVjTE9DQnArNGthOEM2QWwyamJzZ3RDTVpqN21iQVBRV0psMFV5NWNKaCswN3NZYyJ9 dlp-reaction: no-action dlp-version: 11.2.0.6 authentication-results: spf=none (sender IP is ) smtp.mailfrom=michael.a.kubacki@intel.com; x-originating-ip: [134.134.136.217] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: a60d4b48-1bd0-49f2-3a46-08d743709358 x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600167)(711020)(4605104)(1401327)(2017052603328)(7193020);SRVR:DM6PR11MB3787; x-ms-traffictypediagnostic: DM6PR11MB3787: x-ms-exchange-purlcount: 3 x-ld-processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:4502; x-forefront-prvs: 0173C6D4D5 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(396003)(376002)(346002)(39860400002)(136003)(366004)(189003)(199004)(51914003)(45074003)(13464003)(66446008)(66556008)(966005)(76116006)(8676002)(7736002)(81166006)(81156014)(8936002)(54906003)(5660300002)(52536014)(316002)(64756008)(110136005)(2906002)(33656002)(55016002)(4326008)(86362001)(102836004)(6246003)(7696005)(6116002)(30864003)(9686003)(107886003)(6306002)(66946007)(6436002)(26005)(66476007)(76176011)(2501003)(486006)(446003)(66066001)(186003)(476003)(6506007)(11346002)(25786009)(3846002)(229853002)(71190400001)(14454004)(53546011)(74316002)(99286004)(305945005)(478600001)(256004)(71200400001)(14444005)(569006);DIR:OUT;SFP:1102;SCL:1;SRVR:DM6PR11MB3787;H:DM6PR11MB3834.namprd11.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: pbfEpaL2WvBuFV2G79s6+OqaQu4wgyEiKghF8ddubgghPlVNbhgOw6dU2Mx+GobNgkqg/7HyJn6bzbSRor8ev7Qiq5NdVQn4NOf8BzwldnJRCboHr0lEF3q13liyOb+Z91hG1yQFIgd/CkcqGJ9mdmGLs6dt3Am5N1dL82Ei0hGFkwYm5UG/P1y+xoi4B4FEX5s5lzyZSG4qX0CW+PRviUjUryaHWnbLSpYIHQf2he3iAUBXGIxK5eFTBPv6b0yAwL494518ab1UZYxt7J0SgtcmWNHllBvBojjqrByNRDm5V7l6zxJ9IAlOP9F4ABsJDlRs78RJEFWZkzP2gjzwxAVdMr3OmAZa9P2fq6QXb010QOhV3CJ9WYITTue8RL1HyNsccMmaSsjtDjIflSygeFWoAkEutQva4fDvPDE92P6tnG1RX1NL86a3Dw+VLeNJYhEJifyNtyPmQIGp3xla3Q== MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: a60d4b48-1bd0-49f2-3a46-08d743709358 X-MS-Exchange-CrossTenant-originalarrivaltime: 27 Sep 2019 17:31:48.2386 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: IPoNrHoZgSVdzWoOBM0AIowE3gkORes3xfcyO95zay4/C3ey19W9SLYcQmOldcDtD7fsZxgyIFudzGmhxdS9xlTg3Tfil682JeHmNcIAMgo= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR11MB3787 Return-Path: michael.a.kubacki@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hi Hao, Thanks for the feedback. I left my replies inline. Thanks, Michael > -----Original Message----- > From: Wu, Hao A > Sent: Friday, September 27, 2019 1:18 AM > To: devel@edk2.groups.io; Kubacki, Michael A > > Cc: Bi, Dandan ; Ard Biesheuvel > ; Dong, Eric ; Laszlo Er= sek > ; Gao, Liming ; Kinney, Michael > D ; Ni, Ray ; Wang, Jian J > ; Yao, Jiewen > Subject: RE: [edk2-devel] [PATCH V1 1/5] MdeModulePkg/Variable: > Consolidate common parsing functions >=20 > > -----Original Message----- > > From: devel@edk2.groups.io [mailto:devel@edk2.groups.io] On Behalf Of > > Kubacki, Michael A > > Sent: Thursday, September 26, 2019 12:51 PM > > To: devel@edk2.groups.io > > Cc: Bi, Dandan; Ard Biesheuvel; Dong, Eric; Laszlo Ersek; Gao, Liming; > Kinney, > > Michael D; Ni, Ray; Wang, Jian J; Wu, Hao A; Yao, Jiewen > > Subject: [edk2-devel] [PATCH V1 1/5] MdeModulePkg/Variable: > Consolidate > > common parsing functions > > > > This change moves the following functions into a dedicated file > > so they may be used in other variable files as needed. Furthermore, > > it reduces the overall size of the common Variable.c file. > > > > * DataSizeOfVariable () > > * FindVariableEx () > > * GetEndPointer () > > * GetNextVariableEx () > > * GetNextVariablePtr () > > * GetStartPointer () > > * GetVariableDataOffset () > > * GetVariableDataPtr () > > * GetVariableHeaderSize () > > * GetVariableNamePtr () > > * GetVariableStoreStatus () > > * GetVendorGuidPtr () > > * IsAuthenticatedVariable () > > * IsValidVariableHeader () > > * NameSizeOfVariable () > > * SetDataSizeOfVariable () > > * SetNameSizeOfVariable () > > * UpdateVariableInfo () > > * VariableCompareTimeStampInternal () >=20 >=20 > Hello, >=20 > Some thoughts for this patch: > (Sorry for not being able to going through the whole series, and please = grant > more time for the review of other patches.) >=20 > 0. I would suggest this patch only changing the location for functions. > Modifications that might have functional impact need be separated to oth= er > independent patches. >=20 I agree this should be a 2-step process. I will break this patch into a pa= tch that simply moves the functions and then others that make functional updates in a gran= ular fashion. > 1. For UpdateVariableInfo(), I think it is still possible for file > VariableParsing.c to reference 'gVariableInfo'. The additional input > parameter > can be drop, in my opinion. >=20 That is true. This decision was made because I had a preference to describ= ing required inputs in the function interface and not rely upon link-time bind= ing with global variables in different drivers (VariableSmmRuntimeDxe and VariableSmm). Do you feel strongly this should be changed? > 2. It would be better for the removal of > VariableServiceGetNextVariableInternal() > to be a separate patch. >=20 Sure. I can add this as a new patch after patch #1 in this series. I think= this is related to your comment #0. It was moved to VariableParsing.c and renamed to GetNextVariableNameEx () since it is available outside the scope of the fi= le. > 3. Maybe the introduce of InitVariableHelpers() can be separated to anot= her > patch. > Also, I think variable 'mVariableModuleGlobal' can be referred in file > VariableParsing.c. >=20 > Is the intention of adding InitVariableHelpers() to reduce code length > from: > if (mVariableModuleGlobal->VariableGlobal.AuthFormat) { > to: > if (mAuthFormat) { >=20 mVariableModuleGlobal is available to other translation units in the same = module as Variable.c.=20 VariableParsing.c provides a more generic set of functionality that is ava= ilable to modules that do not link against Variable.c. For example, VariableSmmRunti= meDxe. The driver that ultimately reads from flash and can access the variable st= ore signature to determine whether authenticated variables are being used is the SMM dri= ver. This information is given to the Runtime DXE driver through the=20 SMM_VARIABLE_FUNCTION_GET_RUNTIME_CACHE_INFO SMI during initialization which is then passed to InitVariableHelpers () so the functions have the a= uthenticated variable status available regardless of which driver the files is linked a= gainst. Also, I will change the name from InitVariableHelpers () to InitVariablePa= rsing () in the next patch. > 4. I am confused for the changes made in: > MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe. > c > MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.i > nf >=20 > Originally, for VariableSmmRuntimeDxe.inf, the source code file includes= : > [Sources] > VariableSmmRuntimeDxe.c > PrivilegePolymorphic.h > Measurement.c >=20 > The proposed patch only adds the below header inclusion: > #include "VariableParsing.h" > to file VariableSmmRuntimeDxe.c, which has no functional impact in my > opinion. >=20 > Could you help to check whether changes made for > VariableSmmRuntimeDxe is needed? >=20 You're right that the changes do not cause a functional impact in this pat= ch and that they are not needed in the patch. They are needed in patch #3 when to= assist with runtime cache variable operations in the file. I will move the header file inclusion to the patch when the runtime cache = changes are Introduced. > Best Regards, > Hao Wu >=20 >=20 > > > > Cc: Dandan Bi > > Cc: Ard Biesheuvel > > Cc: Eric Dong > > Cc: Laszlo Ersek > > Cc: Liming Gao > > Cc: Michael D Kinney > > Cc: Ray Ni > > Cc: Jian J Wang > > Cc: Hao A Wu > > Cc: Jiewen Yao > > Signed-off-by: Michael Kubacki > > --- > > MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf > > | 4 + > > MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.inf = | > 4 > > + > > > > > MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.i > > nf | 8 +- > > > > > MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.inf > > | 9 + > > MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.h = | 119 - > -- > > MdeModulePkg/Universal/Variable/RuntimeDxe/VariableNonVolatile.h > | > > 25 + > > MdeModulePkg/Universal/Variable/RuntimeDxe/VariableParsing.h = | > > 342 ++++++++ > > MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c = | 784 > +-- > > ---------------- > > MdeModulePkg/Universal/Variable/RuntimeDxe/VariableExLib.c = | > 11 > > +- > > MdeModulePkg/Universal/Variable/RuntimeDxe/VariableNonVolatile.c > | > > 28 + > > MdeModulePkg/Universal/Variable/RuntimeDxe/VariableParsing.c = | > > 816 ++++++++++++++++++++ > > MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c = | > 2 > > + > > > > > MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe. > > c | 3 +- > > 13 files changed, 1273 insertions(+), 882 deletions(-) > > > > diff --git > > > a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf > > > b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf > > index 641376c9c5..08a5490787 100644 > > --- > > > a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf > > +++ > > > b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf > > @@ -36,6 +36,10 @@ > > Variable.c > > VariableDxe.c > > Variable.h > > + VariableNonVolatile.c > > + VariableNonVolatile.h > > + VariableParsing.c > > + VariableParsing.h > > PrivilegePolymorphic.h > > Measurement.c > > TcgMorLockDxe.c > > diff --git > > a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.inf > > b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.inf > > index 0a160d269d..6dc2721b81 100644 > > --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.inf > > +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.inf > > @@ -45,6 +45,10 @@ > > Variable.c > > VariableTraditionalMm.c > > VariableSmm.c > > + VariableNonVolatile.c > > + VariableNonVolatile.h > > + VariableParsing.c > > + VariableParsing.h > > VarCheck.c > > Variable.h > > PrivilegePolymorphic.h > > diff --git > > > a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDx > > e.inf > > > b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDx > > e.inf > > index 14894e6f13..1873b4fe43 100644 > > --- > > > a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDx > > e.inf > > +++ > > > b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDx > > e.inf > > @@ -13,7 +13,7 @@ > > # may not be modified without authorization. If platform fails to pr= otect > > these resources, > > # the authentication service provided in this driver will be broken,= and the > > behavior is undefined. > > # > > -# Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved.<= BR> > > +# Copyright (c) 2010 - 2019, Intel Corporation. All rights reserved.<= BR> > > # SPDX-License-Identifier: BSD-2-Clause-Patent > > # > > ## > > @@ -39,6 +39,9 @@ > > VariableSmmRuntimeDxe.c > > PrivilegePolymorphic.h > > Measurement.c > > + Variable.h > > + VariableParsing.c > > + VariableParsing.h > > > > [Packages] > > MdePkg/MdePkg.dec > > @@ -65,6 +68,9 @@ > > gEdkiiVariableLockProtocolGuid ## PRODUCES > > gEdkiiVarCheckProtocolGuid ## PRODUCES > > > > +[FeaturePcd] > > + gEfiMdeModulePkgTokenSpaceGuid.PcdVariableCollectStatistics > ## > > CONSUMES > > + > > [Guids] > > gEfiEventVirtualAddressChangeGuid ## CONSUMES ## Event > > gEfiEventExitBootServicesGuid ## CONSUMES ## Event > > diff --git > > > a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.i > > nf > > > b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm. > > inf > > index 21bc81163b..ca9d23ce9f 100644 > > --- > > > a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.i > > nf > > +++ > > > b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm. > > inf > > @@ -45,6 +45,10 @@ > > Variable.c > > VariableSmm.c > > VariableStandaloneMm.c > > + VariableNonVolatile.c > > + VariableNonVolatile.h > > + VariableParsing.c > > + VariableParsing.h > > VarCheck.c > > Variable.h > > PrivilegePolymorphic.h > > @@ -99,6 +103,11 @@ > > ## SOMETIMES_PRODUCES ## Variable:L"Lang" > > gEfiGlobalVariableGuid > > > > + ## SOMETIMES_CONSUMES ## Variable:L"db" > > + ## SOMETIMES_CONSUMES ## Variable:L"dbx" > > + ## SOMETIMES_CONSUMES ## Variable:L"dbt" > > + gEfiImageSecurityDatabaseGuid > > + > > gEfiMemoryOverwriteControlDataGuid ## SOMETIMES_CONSUMES > > ## Variable:L"MemoryOverwriteRequestControl" > > gEfiMemoryOverwriteRequestControlLockGuid ## > > SOMETIMES_PRODUCES ## > > Variable:L"MemoryOverwriteRequestControlLock" > > > > diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.h > > b/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.h > > index 9eac43759f..fb574b2e32 100644 > > --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.h > > +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.h > > @@ -179,89 +179,6 @@ FindVariable ( > > IN BOOLEAN IgnoreRtCheck > > ); > > > > -/** > > - > > - Gets the pointer to the end of the variable storage area. > > - > > - This function gets pointer to the end of the variable storage > > - area, according to the input variable store header. > > - > > - @param VarStoreHeader Pointer to the Variable Store Header. > > - > > - @return Pointer to the end of the variable storage area. > > - > > -**/ > > -VARIABLE_HEADER * > > -GetEndPointer ( > > - IN VARIABLE_STORE_HEADER *VarStoreHeader > > - ); > > - > > -/** > > - This code gets the size of variable header. > > - > > - @return Size of variable header in bytes in type UINTN. > > - > > -**/ > > -UINTN > > -GetVariableHeaderSize ( > > - VOID > > - ); > > - > > -/** > > - > > - This code gets the pointer to the variable name. > > - > > - @param Variable Pointer to the Variable Header. > > - > > - @return Pointer to Variable Name which is Unicode encoding. > > - > > -**/ > > -CHAR16 * > > -GetVariableNamePtr ( > > - IN VARIABLE_HEADER *Variable > > - ); > > - > > -/** > > - This code gets the pointer to the variable guid. > > - > > - @param Variable Pointer to the Variable Header. > > - > > - @return A EFI_GUID* pointer to Vendor Guid. > > - > > -**/ > > -EFI_GUID * > > -GetVendorGuidPtr ( > > - IN VARIABLE_HEADER *Variable > > - ); > > - > > -/** > > - > > - This code gets the pointer to the variable data. > > - > > - @param Variable Pointer to the Variable Header. > > - > > - @return Pointer to Variable Data. > > - > > -**/ > > -UINT8 * > > -GetVariableDataPtr ( > > - IN VARIABLE_HEADER *Variable > > - ); > > - > > -/** > > - > > - This code gets the size of variable data. > > - > > - @param Variable Pointer to the Variable Header. > > - > > - @return Size of variable in bytes. > > - > > -**/ > > -UINTN > > -DataSizeOfVariable ( > > - IN VARIABLE_HEADER *Variable > > - ); > > - > > /** > > This function is to check if the remaining variable space is enough= to set > > all Variables from argument list successfully. The purpose of the c= heck > > @@ -450,17 +367,6 @@ ReclaimForOS( > > VOID > > ); > > > > -/** > > - Get non-volatile maximum variable size. > > - > > - @return Non-volatile maximum variable size. > > - > > -**/ > > -UINTN > > -GetNonVolatileMaxVariableSize ( > > - VOID > > - ); > > - > > /** > > Get maximum variable size, covering both non-volatile and volatile > variables. > > > > @@ -546,31 +452,6 @@ VariableServiceGetVariable ( > > OUT VOID *Data OPTIONAL > > ); > > > > -/** > > - This code Finds the Next available variable. > > - > > - Caution: This function may receive untrusted input. > > - This function may be invoked in SMM mode. This function will do bas= ic > > validation, before parse the data. > > - > > - @param[in] VariableName Pointer to variable name. > > - @param[in] VendorGuid Variable Vendor Guid. > > - @param[out] VariablePtr Pointer to variable header address. > > - > > - @retval EFI_SUCCESS The function completed successfully. > > - @retval EFI_NOT_FOUND The next variable was not found. > > - @retval EFI_INVALID_PARAMETER If VariableName is not an empty > string, > > while VendorGuid is NULL. > > - @retval EFI_INVALID_PARAMETER The input values of VariableName and > > VendorGuid are not a name and > > - GUID of an existing variable. > > - > > -**/ > > -EFI_STATUS > > -EFIAPI > > -VariableServiceGetNextVariableInternal ( > > - IN CHAR16 *VariableName, > > - IN EFI_GUID *VendorGuid, > > - OUT VARIABLE_HEADER **VariablePtr > > - ); > > - > > /** > > > > This code Finds the Next available variable. > > diff --git > > a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableNonVolatile.h > > b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableNonVolatile.h > > new file mode 100644 > > index 0000000000..82572262ef > > --- /dev/null > > +++ > > b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableNonVolatile.h > > @@ -0,0 +1,25 @@ > > +/** @file > > + Common variable non-volatile store routines. > > + > > +Copyright (c) 2019, Intel Corporation. All rights reserved.
> > +SPDX-License-Identifier: BSD-2-Clause-Patent > > + > > +**/ > > + > > +#ifndef _VARIABLE_NON_VOLATILE_H_ > > +#define _VARIABLE_NON_VOLATILE_H_ > > + > > +#include "Variable.h" > > + > > +/** > > + Get non-volatile maximum variable size. > > + > > + @return Non-volatile maximum variable size. > > + > > +**/ > > +UINTN > > +GetNonVolatileMaxVariableSize ( > > + VOID > > + ); > > + > > +#endif > > diff --git > > a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableParsing.h > > b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableParsing.h > > new file mode 100644 > > index 0000000000..bd617fca10 > > --- /dev/null > > +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableParsing.h > > @@ -0,0 +1,342 @@ > > +/** @file > > + Common variable helper routines are shared by the DXE_RUNTIME > > variable > > + module and the DXE_SMM variable module. > > + > > +Copyright (c) 2019, Intel Corporation. All rights reserved.
> > +SPDX-License-Identifier: BSD-2-Clause-Patent > > + > > +**/ > > + > > +#ifndef _VARIABLE_PARSING_H_ > > +#define _VARIABLE_PARSING_H_ > > + > > +#include > > +#include "Variable.h" > > + > > +/** > > + > > + This code checks if variable header is valid or not. > > + > > + @param Variable Pointer to the Variable Header. > > + @param VariableStoreEnd Pointer to the Variable Store End. > > + > > + @retval TRUE Variable header is valid. > > + @retval FALSE Variable header is not valid. > > + > > +**/ > > +BOOLEAN > > +IsValidVariableHeader ( > > + IN VARIABLE_HEADER *Variable, > > + IN VARIABLE_HEADER *VariableStoreEnd > > + ); > > + > > +/** > > + > > + This code gets the current status of Variable Store. > > + > > + @param VarStoreHeader Pointer to the Variable Store Header. > > + > > + @retval EfiRaw Variable store status is raw. > > + @retval EfiValid Variable store status is valid. > > + @retval EfiInvalid Variable store status is invalid. > > + > > +**/ > > +VARIABLE_STORE_STATUS > > +GetVariableStoreStatus ( > > + IN VARIABLE_STORE_HEADER *VarStoreHeader > > + ); > > + > > +/** > > + This code gets the size of variable header. > > + > > + @return Size of variable header in bytes in type UINTN. > > + > > +**/ > > +UINTN > > +GetVariableHeaderSize ( > > + VOID > > + ); > > + > > +/** > > + > > + This code gets the size of name of variable. > > + > > + @param Variable Pointer to the Variable Header. > > + > > + @return UINTN Size of variable in bytes. > > + > > +**/ > > +UINTN > > +NameSizeOfVariable ( > > + IN VARIABLE_HEADER *Variable > > + ); > > + > > +/** > > + This code sets the size of name of variable. > > + > > + @param[in] Variable Pointer to the Variable Header. > > + @param[in] NameSize Name size to set. > > + > > +**/ > > +VOID > > +SetNameSizeOfVariable ( > > + IN VARIABLE_HEADER *Variable, > > + IN UINTN NameSize > > + ); > > + > > +/** > > + > > + This code gets the size of variable data. > > + > > + @param Variable Pointer to the Variable Header. > > + > > + @return Size of variable in bytes. > > + > > +**/ > > +UINTN > > +DataSizeOfVariable ( > > + IN VARIABLE_HEADER *Variable > > + ); > > + > > +/** > > + This code sets the size of variable data. > > + > > + @param[in] Variable Pointer to the Variable Header. > > + @param[in] DataSize Data size to set. > > + > > +**/ > > +VOID > > +SetDataSizeOfVariable ( > > + IN VARIABLE_HEADER *Variable, > > + IN UINTN DataSize > > + ); > > + > > +/** > > + > > + This code gets the pointer to the variable name. > > + > > + @param Variable Pointer to the Variable Header. > > + > > + @return Pointer to Variable Name which is Unicode encoding. > > + > > +**/ > > +CHAR16 * > > +GetVariableNamePtr ( > > + IN VARIABLE_HEADER *Variable > > + ); > > + > > +/** > > + This code gets the pointer to the variable guid. > > + > > + @param Variable Pointer to the Variable Header. > > + > > + @return A EFI_GUID* pointer to Vendor Guid. > > + > > +**/ > > +EFI_GUID * > > +GetVendorGuidPtr ( > > + IN VARIABLE_HEADER *Variable > > + ); > > + > > +/** > > + > > + This code gets the pointer to the variable data. > > + > > + @param Variable Pointer to the Variable Header. > > + > > + @return Pointer to Variable Data. > > + > > +**/ > > +UINT8 * > > +GetVariableDataPtr ( > > + IN VARIABLE_HEADER *Variable > > + ); > > + > > +/** > > + This code gets the variable data offset related to variable header. > > + > > + @param Variable Pointer to the Variable Header. > > + > > + @return Variable Data offset. > > + > > +**/ > > +UINTN > > +GetVariableDataOffset ( > > + IN VARIABLE_HEADER *Variable > > + ); > > + > > +/** > > + > > + This code gets the pointer to the next variable header. > > + > > + @param Variable Pointer to the Variable Header. > > + > > + @return Pointer to next variable header. > > + > > +**/ > > +VARIABLE_HEADER * > > +GetNextVariablePtr ( > > + IN VARIABLE_HEADER *Variable > > + ); > > + > > +/** > > + > > + Gets the pointer to the first variable header in given variable sto= re area. > > + > > + @param VarStoreHeader Pointer to the Variable Store Header. > > + > > + @return Pointer to the first variable header. > > + > > +**/ > > +VARIABLE_HEADER * > > +GetStartPointer ( > > + IN VARIABLE_STORE_HEADER *VarStoreHeader > > + ); > > + > > +/** > > + > > + Gets the pointer to the end of the variable storage area. > > + > > + This function gets pointer to the end of the variable storage > > + area, according to the input variable store header. > > + > > + @param VarStoreHeader Pointer to the Variable Store Header. > > + > > + @return Pointer to the end of the variable storage area. > > + > > +**/ > > +VARIABLE_HEADER * > > +GetEndPointer ( > > + IN VARIABLE_STORE_HEADER *VarStoreHeader > > + ); > > + > > +/** > > + Returns if this is a variable that always requires authenticated wr= ites. > > + There may be other scenarios that result in a variable not identifi= ed by > the > > + function to also require authentication. > > + > > + @param[in] VariableName Name of variable. > > + @param[in] VendorGuid Guid of variable. > > + > > + @retval TRUE The variable always requires authenticated= writes > > + @retval FALSE The variable may or may not require authen= ticated > > writes > > +**/ > > +BOOLEAN > > +IsAuthenticatedVariable ( > > + IN CHAR16 *VariableName, > > + IN EFI_GUID *VendorGuid > > + ); > > + > > +/** > > + Compare two EFI_TIME data. > > + > > + > > + @param FirstTime A pointer to the first EFI_TIME data. > > + @param SecondTime A pointer to the second EFI_TIME data. > > + > > + @retval TRUE The FirstTime is not later than the Seco= ndTime. > > + @retval FALSE The FirstTime is later than the SecondTi= me. > > + > > +**/ > > +BOOLEAN > > +VariableCompareTimeStampInternal ( > > + IN EFI_TIME *FirstTime, > > + IN EFI_TIME *SecondTime > > + ); > > + > > +/** > > + Find the variable in the specified variable store. > > + > > + @param[in] VariableName Name of the variable to be fou= nd > > + @param[in] VendorGuid Vendor GUID to be found. > > + @param[in] IgnoreRtCheck Ignore > EFI_VARIABLE_RUNTIME_ACCESS > > attribute > > + check at runtime when searchin= g variable. > > + @param[in, out] PtrTrack Variable Track Pointer structu= re that > > contains Variable Information. > > + > > + @retval EFI_SUCCESS Variable found successfully > > + @retval EFI_NOT_FOUND Variable not found > > +**/ > > +EFI_STATUS > > +FindVariableEx ( > > + IN CHAR16 *VariableName, > > + IN EFI_GUID *VendorGuid, > > + IN BOOLEAN IgnoreRtCheck, > > + IN OUT VARIABLE_POINTER_TRACK *PtrTrack > > + ); > > + > > +/** > > + This code finds the next available variable. > > + > > + Caution: This function may receive untrusted input. > > + This function may be invoked in SMM mode. This function will do bas= ic > > validation, before parse the data. > > + > > + @param[in] VariableName Pointer to variable name. > > + @param[in] VendorGuid Variable Vendor Guid. > > + @param[in] VariableStoreList A list of variable stores that should= be > used > > to get the next variable. > > + The maximum number of entries is the = max value of > > VARIABLE_STORE_TYPE. > > + @param[out] VariablePtr Pointer to variable header address. > > + > > + @retval EFI_SUCCESS The function completed successfully. > > + @retval EFI_NOT_FOUND The next variable was not found. > > + @retval EFI_INVALID_PARAMETER If VariableName is nt an empty string= , > > while VendorGuid is NULL. > > + @retval EFI_INVALID_PARAMETER The input values of VariableName > and > > VendorGuid are not a name and > > + GUID of an existing variable. > > + > > +**/ > > +EFI_STATUS > > +EFIAPI > > +GetNextVariableEx ( > > + IN CHAR16 *VariableName, > > + IN EFI_GUID *VendorGuid, > > + IN VARIABLE_STORE_HEADER **VariableStoreList, > > + OUT VARIABLE_HEADER **VariablePtr > > + ); > > + > > +/** > > + Routine used to track statistical information about variable usage. > > + The data is stored in the EFI system table so it can be accessed la= ter. > > + VariableInfo.efi can dump out the table. Only Boot Services variabl= e > > + accesses are tracked by this code. The PcdVariableCollectStatistics > > + build flag controls if this feature is enabled. > > + > > + A read that hits in the cache will have Read and Cache true for > > + the transaction. Data is allocated by this routine, but never > > + freed. > > + > > + @param[in] VariableName Name of the Variable to track. > > + @param[in] VendorGuid Guid of the Variable to track. > > + @param[in] Volatile TRUE if volatile FALSE if non-volati= le. > > + @param[in] Read TRUE if GetVariable() was called. > > + @param[in] Write TRUE if SetVariable() was called. > > + @param[in] Delete TRUE if deleted via SetVariable(). > > + @param[in] Cache TRUE for a cache hit. > > + @param[in,out] VariableInfo Pointer to a pointer of > > VARIABLE_INFO_ENTRY structures. > > + > > +**/ > > +VOID > > +UpdateVariableInfo ( > > + IN CHAR16 *VariableName, > > + IN EFI_GUID *VendorGuid, > > + IN BOOLEAN Volatile, > > + IN BOOLEAN Read, > > + IN BOOLEAN Write, > > + IN BOOLEAN Delete, > > + IN BOOLEAN Cache, > > + IN OUT VARIABLE_INFO_ENTRY **VariableInfo > > + ); > > + > > +/** > > + Initializes context needed for variable helpers. > > + > > + @param[in] AuthFormat If true then indicates authent= icated > > variables are supported > > + > > + @retval EFI_SUCCESS Initialized successfully > > + @retval Others An error occurred during initi= alization > > +**/ > > +EFI_STATUS > > +EFIAPI > > +InitVariableHelpers ( > > + IN BOOLEAN AuthFormat > > + ); > > + > > +#endif > > diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c > > b/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c > > index f32c9c2808..d14fecc830 100644 > > --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c > > +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c > > @@ -23,6 +23,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent > > **/ > > > > #include "Variable.h" > > +#include "VariableNonVolatile.h" > > +#include "VariableParsing.h" > > > > VARIABLE_MODULE_GLOBAL *mVariableModuleGlobal; > > > > @@ -92,131 +94,6 @@ AUTH_VAR_LIB_CONTEXT_IN mAuthContextIn =3D { > > > > AUTH_VAR_LIB_CONTEXT_OUT mAuthContextOut; > > > > -/** > > - Routine used to track statistical information about variable usage. > > - The data is stored in the EFI system table so it can be accessed la= ter. > > - VariableInfo.efi can dump out the table. Only Boot Services variabl= e > > - accesses are tracked by this code. The PcdVariableCollectStatistics > > - build flag controls if this feature is enabled. > > - > > - A read that hits in the cache will have Read and Cache true for > > - the transaction. Data is allocated by this routine, but never > > - freed. > > - > > - @param[in] VariableName Name of the Variable to track. > > - @param[in] VendorGuid Guid of the Variable to track. > > - @param[in] Volatile TRUE if volatile FALSE if non-volatile. > > - @param[in] Read TRUE if GetVariable() was called. > > - @param[in] Write TRUE if SetVariable() was called. > > - @param[in] Delete TRUE if deleted via SetVariable(). > > - @param[in] Cache TRUE for a cache hit. > > - > > -**/ > > -VOID > > -UpdateVariableInfo ( > > - IN CHAR16 *VariableName, > > - IN EFI_GUID *VendorGuid, > > - IN BOOLEAN Volatile, > > - IN BOOLEAN Read, > > - IN BOOLEAN Write, > > - IN BOOLEAN Delete, > > - IN BOOLEAN Cache > > - ) > > -{ > > - VARIABLE_INFO_ENTRY *Entry; > > - > > - if (FeaturePcdGet (PcdVariableCollectStatistics)) { > > - > > - if (AtRuntime ()) { > > - // Don't collect statistics at runtime. > > - return; > > - } > > - > > - if (gVariableInfo =3D=3D NULL) { > > - // > > - // On the first call allocate a entry and place a pointer to it= in > > - // the EFI System Table. > > - // > > - gVariableInfo =3D AllocateZeroPool (sizeof (VARIABLE_INFO_ENTRY= )); > > - ASSERT (gVariableInfo !=3D NULL); > > - > > - CopyGuid (&gVariableInfo->VendorGuid, VendorGuid); > > - gVariableInfo->Name =3D AllocateZeroPool (StrSize (VariableName= )); > > - ASSERT (gVariableInfo->Name !=3D NULL); > > - StrCpyS (gVariableInfo->Name, StrSize(VariableName)/sizeof(CHAR= 16), > > VariableName); > > - gVariableInfo->Volatile =3D Volatile; > > - } > > - > > - > > - for (Entry =3D gVariableInfo; Entry !=3D NULL; Entry =3D Entry->N= ext) { > > - if (CompareGuid (VendorGuid, &Entry->VendorGuid)) { > > - if (StrCmp (VariableName, Entry->Name) =3D=3D 0) { > > - if (Read) { > > - Entry->ReadCount++; > > - } > > - if (Write) { > > - Entry->WriteCount++; > > - } > > - if (Delete) { > > - Entry->DeleteCount++; > > - } > > - if (Cache) { > > - Entry->CacheCount++; > > - } > > - > > - return; > > - } > > - } > > - > > - if (Entry->Next =3D=3D NULL) { > > - // > > - // If the entry is not in the table add it. > > - // Next iteration of the loop will fill in the data. > > - // > > - Entry->Next =3D AllocateZeroPool (sizeof (VARIABLE_INFO_ENTRY= )); > > - ASSERT (Entry->Next !=3D NULL); > > - > > - CopyGuid (&Entry->Next->VendorGuid, VendorGuid); > > - Entry->Next->Name =3D AllocateZeroPool (StrSize (VariableName= )); > > - ASSERT (Entry->Next->Name !=3D NULL); > > - StrCpyS (Entry->Next->Name, StrSize(VariableName)/sizeof(CHAR= 16), > > VariableName); > > - Entry->Next->Volatile =3D Volatile; > > - } > > - > > - } > > - } > > -} > > - > > - > > -/** > > - > > - This code checks if variable header is valid or not. > > - > > - @param Variable Pointer to the Variable Header. > > - @param VariableStoreEnd Pointer to the Variable Store End. > > - > > - @retval TRUE Variable header is valid. > > - @retval FALSE Variable header is not valid. > > - > > -**/ > > -BOOLEAN > > -IsValidVariableHeader ( > > - IN VARIABLE_HEADER *Variable, > > - IN VARIABLE_HEADER *VariableStoreEnd > > - ) > > -{ > > - if ((Variable =3D=3D NULL) || (Variable >=3D VariableStoreEnd) || (= Variable- > > >StartId !=3D VARIABLE_DATA)) { > > - // > > - // Variable is NULL or has reached the end of variable store, > > - // or the StartId is not correct. > > - // > > - return FALSE; > > - } > > - > > - return TRUE; > > -} > > - > > - > > /** > > > > This function writes data to the FWH at the correct LBA even if the= LBAs > > @@ -376,345 +253,6 @@ UpdateVariableStore ( > > return EFI_SUCCESS; > > } > > > > - > > -/** > > - > > - This code gets the current status of Variable Store. > > - > > - @param VarStoreHeader Pointer to the Variable Store Header. > > - > > - @retval EfiRaw Variable store status is raw. > > - @retval EfiValid Variable store status is valid. > > - @retval EfiInvalid Variable store status is invalid. > > - > > -**/ > > -VARIABLE_STORE_STATUS > > -GetVariableStoreStatus ( > > - IN VARIABLE_STORE_HEADER *VarStoreHeader > > - ) > > -{ > > - if ((CompareGuid (&VarStoreHeader->Signature, > > &gEfiAuthenticatedVariableGuid) || > > - CompareGuid (&VarStoreHeader->Signature, &gEfiVariableGuid)) &= & > > - VarStoreHeader->Format =3D=3D VARIABLE_STORE_FORMATTED && > > - VarStoreHeader->State =3D=3D VARIABLE_STORE_HEALTHY > > - ) { > > - > > - return EfiValid; > > - } else if (((UINT32 *)(&VarStoreHeader->Signature))[0] =3D=3D 0xfff= fffff && > > - ((UINT32 *)(&VarStoreHeader->Signature))[1] =3D=3D 0xfff= fffff && > > - ((UINT32 *)(&VarStoreHeader->Signature))[2] =3D=3D 0xfff= fffff && > > - ((UINT32 *)(&VarStoreHeader->Signature))[3] =3D=3D 0xfff= fffff && > > - VarStoreHeader->Size =3D=3D 0xffffffff && > > - VarStoreHeader->Format =3D=3D 0xff && > > - VarStoreHeader->State =3D=3D 0xff > > - ) { > > - > > - return EfiRaw; > > - } else { > > - return EfiInvalid; > > - } > > -} > > - > > -/** > > - This code gets the size of variable header. > > - > > - @return Size of variable header in bytes in type UINTN. > > - > > -**/ > > -UINTN > > -GetVariableHeaderSize ( > > - VOID > > - ) > > -{ > > - UINTN Value; > > - > > - if (mVariableModuleGlobal->VariableGlobal.AuthFormat) { > > - Value =3D sizeof (AUTHENTICATED_VARIABLE_HEADER); > > - } else { > > - Value =3D sizeof (VARIABLE_HEADER); > > - } > > - > > - return Value; > > -} > > - > > -/** > > - > > - This code gets the size of name of variable. > > - > > - @param Variable Pointer to the Variable Header. > > - > > - @return UINTN Size of variable in bytes. > > - > > -**/ > > -UINTN > > -NameSizeOfVariable ( > > - IN VARIABLE_HEADER *Variable > > - ) > > -{ > > - AUTHENTICATED_VARIABLE_HEADER *AuthVariable; > > - > > - AuthVariable =3D (AUTHENTICATED_VARIABLE_HEADER *) Variable; > > - if (mVariableModuleGlobal->VariableGlobal.AuthFormat) { > > - if (AuthVariable->State =3D=3D (UINT8) (-1) || > > - AuthVariable->DataSize =3D=3D (UINT32) (-1) || > > - AuthVariable->NameSize =3D=3D (UINT32) (-1) || > > - AuthVariable->Attributes =3D=3D (UINT32) (-1)) { > > - return 0; > > - } > > - return (UINTN) AuthVariable->NameSize; > > - } else { > > - if (Variable->State =3D=3D (UINT8) (-1) || > > - Variable->DataSize =3D=3D (UINT32) (-1) || > > - Variable->NameSize =3D=3D (UINT32) (-1) || > > - Variable->Attributes =3D=3D (UINT32) (-1)) { > > - return 0; > > - } > > - return (UINTN) Variable->NameSize; > > - } > > -} > > - > > -/** > > - This code sets the size of name of variable. > > - > > - @param[in] Variable Pointer to the Variable Header. > > - @param[in] NameSize Name size to set. > > - > > -**/ > > -VOID > > -SetNameSizeOfVariable ( > > - IN VARIABLE_HEADER *Variable, > > - IN UINTN NameSize > > - ) > > -{ > > - AUTHENTICATED_VARIABLE_HEADER *AuthVariable; > > - > > - AuthVariable =3D (AUTHENTICATED_VARIABLE_HEADER *) Variable; > > - if (mVariableModuleGlobal->VariableGlobal.AuthFormat) { > > - AuthVariable->NameSize =3D (UINT32) NameSize; > > - } else { > > - Variable->NameSize =3D (UINT32) NameSize; > > - } > > -} > > - > > -/** > > - > > - This code gets the size of variable data. > > - > > - @param Variable Pointer to the Variable Header. > > - > > - @return Size of variable in bytes. > > - > > -**/ > > -UINTN > > -DataSizeOfVariable ( > > - IN VARIABLE_HEADER *Variable > > - ) > > -{ > > - AUTHENTICATED_VARIABLE_HEADER *AuthVariable; > > - > > - AuthVariable =3D (AUTHENTICATED_VARIABLE_HEADER *) Variable; > > - if (mVariableModuleGlobal->VariableGlobal.AuthFormat) { > > - if (AuthVariable->State =3D=3D (UINT8) (-1) || > > - AuthVariable->DataSize =3D=3D (UINT32) (-1) || > > - AuthVariable->NameSize =3D=3D (UINT32) (-1) || > > - AuthVariable->Attributes =3D=3D (UINT32) (-1)) { > > - return 0; > > - } > > - return (UINTN) AuthVariable->DataSize; > > - } else { > > - if (Variable->State =3D=3D (UINT8) (-1) || > > - Variable->DataSize =3D=3D (UINT32) (-1) || > > - Variable->NameSize =3D=3D (UINT32) (-1) || > > - Variable->Attributes =3D=3D (UINT32) (-1)) { > > - return 0; > > - } > > - return (UINTN) Variable->DataSize; > > - } > > -} > > - > > -/** > > - This code sets the size of variable data. > > - > > - @param[in] Variable Pointer to the Variable Header. > > - @param[in] DataSize Data size to set. > > - > > -**/ > > -VOID > > -SetDataSizeOfVariable ( > > - IN VARIABLE_HEADER *Variable, > > - IN UINTN DataSize > > - ) > > -{ > > - AUTHENTICATED_VARIABLE_HEADER *AuthVariable; > > - > > - AuthVariable =3D (AUTHENTICATED_VARIABLE_HEADER *) Variable; > > - if (mVariableModuleGlobal->VariableGlobal.AuthFormat) { > > - AuthVariable->DataSize =3D (UINT32) DataSize; > > - } else { > > - Variable->DataSize =3D (UINT32) DataSize; > > - } > > -} > > - > > -/** > > - > > - This code gets the pointer to the variable name. > > - > > - @param Variable Pointer to the Variable Header. > > - > > - @return Pointer to Variable Name which is Unicode encoding. > > - > > -**/ > > -CHAR16 * > > -GetVariableNamePtr ( > > - IN VARIABLE_HEADER *Variable > > - ) > > -{ > > - return (CHAR16 *) ((UINTN) Variable + GetVariableHeaderSize ()); > > -} > > - > > -/** > > - This code gets the pointer to the variable guid. > > - > > - @param Variable Pointer to the Variable Header. > > - > > - @return A EFI_GUID* pointer to Vendor Guid. > > - > > -**/ > > -EFI_GUID * > > -GetVendorGuidPtr ( > > - IN VARIABLE_HEADER *Variable > > - ) > > -{ > > - AUTHENTICATED_VARIABLE_HEADER *AuthVariable; > > - > > - AuthVariable =3D (AUTHENTICATED_VARIABLE_HEADER *) Variable; > > - if (mVariableModuleGlobal->VariableGlobal.AuthFormat) { > > - return &AuthVariable->VendorGuid; > > - } else { > > - return &Variable->VendorGuid; > > - } > > -} > > - > > -/** > > - > > - This code gets the pointer to the variable data. > > - > > - @param Variable Pointer to the Variable Header. > > - > > - @return Pointer to Variable Data. > > - > > -**/ > > -UINT8 * > > -GetVariableDataPtr ( > > - IN VARIABLE_HEADER *Variable > > - ) > > -{ > > - UINTN Value; > > - > > - // > > - // Be careful about pad size for alignment. > > - // > > - Value =3D (UINTN) GetVariableNamePtr (Variable); > > - Value +=3D NameSizeOfVariable (Variable); > > - Value +=3D GET_PAD_SIZE (NameSizeOfVariable (Variable)); > > - > > - return (UINT8 *) Value; > > -} > > - > > -/** > > - This code gets the variable data offset related to variable header. > > - > > - @param Variable Pointer to the Variable Header. > > - > > - @return Variable Data offset. > > - > > -**/ > > -UINTN > > -GetVariableDataOffset ( > > - IN VARIABLE_HEADER *Variable > > - ) > > -{ > > - UINTN Value; > > - > > - // > > - // Be careful about pad size for alignment > > - // > > - Value =3D GetVariableHeaderSize (); > > - Value +=3D NameSizeOfVariable (Variable); > > - Value +=3D GET_PAD_SIZE (NameSizeOfVariable (Variable)); > > - > > - return Value; > > -} > > - > > -/** > > - > > - This code gets the pointer to the next variable header. > > - > > - @param Variable Pointer to the Variable Header. > > - > > - @return Pointer to next variable header. > > - > > -**/ > > -VARIABLE_HEADER * > > -GetNextVariablePtr ( > > - IN VARIABLE_HEADER *Variable > > - ) > > -{ > > - UINTN Value; > > - > > - Value =3D (UINTN) GetVariableDataPtr (Variable); > > - Value +=3D DataSizeOfVariable (Variable); > > - Value +=3D GET_PAD_SIZE (DataSizeOfVariable (Variable)); > > - > > - // > > - // Be careful about pad size for alignment. > > - // > > - return (VARIABLE_HEADER *) HEADER_ALIGN (Value); > > -} > > - > > -/** > > - > > - Gets the pointer to the first variable header in given variable sto= re area. > > - > > - @param VarStoreHeader Pointer to the Variable Store Header. > > - > > - @return Pointer to the first variable header. > > - > > -**/ > > -VARIABLE_HEADER * > > -GetStartPointer ( > > - IN VARIABLE_STORE_HEADER *VarStoreHeader > > - ) > > -{ > > - // > > - // The start of variable store. > > - // > > - return (VARIABLE_HEADER *) HEADER_ALIGN (VarStoreHeader + 1); > > -} > > - > > -/** > > - > > - Gets the pointer to the end of the variable storage area. > > - > > - This function gets pointer to the end of the variable storage > > - area, according to the input variable store header. > > - > > - @param VarStoreHeader Pointer to the Variable Store Header. > > - > > - @return Pointer to the end of the variable storage area. > > - > > -**/ > > -VARIABLE_HEADER * > > -GetEndPointer ( > > - IN VARIABLE_STORE_HEADER *VarStoreHeader > > - ) > > -{ > > - // > > - // The end of variable store > > - // > > - return (VARIABLE_HEADER *) HEADER_ALIGN ((UINTN) VarStoreHeader > + > > VarStoreHeader->Size); > > -} > > - > > /** > > Record variable error flag. > > > > @@ -1228,75 +766,6 @@ Done: > > return Status; > > } > > > > -/** > > - Find the variable in the specified variable store. > > - > > - @param[in] VariableName Name of the variable to be fou= nd > > - @param[in] VendorGuid Vendor GUID to be found. > > - @param[in] IgnoreRtCheck Ignore > EFI_VARIABLE_RUNTIME_ACCESS > > attribute > > - check at runtime when searchin= g variable. > > - @param[in, out] PtrTrack Variable Track Pointer structu= re that > > contains Variable Information. > > - > > - @retval EFI_SUCCESS Variable found successfully > > - @retval EFI_NOT_FOUND Variable not found > > -**/ > > -EFI_STATUS > > -FindVariableEx ( > > - IN CHAR16 *VariableName, > > - IN EFI_GUID *VendorGuid, > > - IN BOOLEAN IgnoreRtCheck, > > - IN OUT VARIABLE_POINTER_TRACK *PtrTrack > > - ) > > -{ > > - VARIABLE_HEADER *InDeletedVariable; > > - VOID *Point; > > - > > - PtrTrack->InDeletedTransitionPtr =3D NULL; > > - > > - // > > - // Find the variable by walk through HOB, volatile and non-volatile > variable > > store. > > - // > > - InDeletedVariable =3D NULL; > > - > > - for ( PtrTrack->CurrPtr =3D PtrTrack->StartPtr > > - ; IsValidVariableHeader (PtrTrack->CurrPtr, PtrTrack->EndPtr) > > - ; PtrTrack->CurrPtr =3D GetNextVariablePtr (PtrTrack->CurrPtr) > > - ) { > > - if (PtrTrack->CurrPtr->State =3D=3D VAR_ADDED || > > - PtrTrack->CurrPtr->State =3D=3D (VAR_IN_DELETED_TRANSITION & > > VAR_ADDED) > > - ) { > > - if (IgnoreRtCheck || !AtRuntime () || ((PtrTrack->CurrPtr->Attr= ibutes & > > EFI_VARIABLE_RUNTIME_ACCESS) !=3D 0)) { > > - if (VariableName[0] =3D=3D 0) { > > - if (PtrTrack->CurrPtr->State =3D=3D (VAR_IN_DELETED_TRANSIT= ION & > > VAR_ADDED)) { > > - InDeletedVariable =3D PtrTrack->CurrPtr; > > - } else { > > - PtrTrack->InDeletedTransitionPtr =3D InDeletedVariable; > > - return EFI_SUCCESS; > > - } > > - } else { > > - if (CompareGuid (VendorGuid, GetVendorGuidPtr (PtrTrack- > >CurrPtr))) > > { > > - Point =3D (VOID *) GetVariableNamePtr (PtrTrack->CurrPtr)= ; > > - > > - ASSERT (NameSizeOfVariable (PtrTrack->CurrPtr) !=3D 0); > > - if (CompareMem (VariableName, Point, NameSizeOfVariable > > (PtrTrack->CurrPtr)) =3D=3D 0) { > > - if (PtrTrack->CurrPtr->State =3D=3D (VAR_IN_DELETED_TRA= NSITION & > > VAR_ADDED)) { > > - InDeletedVariable =3D PtrTrack->CurrPtr; > > - } else { > > - PtrTrack->InDeletedTransitionPtr =3D InDeletedVariabl= e; > > - return EFI_SUCCESS; > > - } > > - } > > - } > > - } > > - } > > - } > > - } > > - > > - PtrTrack->CurrPtr =3D InDeletedVariable; > > - return (PtrTrack->CurrPtr =3D=3D NULL) ? EFI_NOT_FOUND : EFI_SUCCE= SS; > > -} > > - > > - > > /** > > Finds variable in storage blocks of volatile and non-volatile stora= ge areas. > > > > @@ -2078,38 +1547,6 @@ AutoUpdateLangVariable ( > > } > > } > > > > -/** > > - Compare two EFI_TIME data. > > - > > - > > - @param FirstTime A pointer to the first EFI_TIME data. > > - @param SecondTime A pointer to the second EFI_TIME data. > > - > > - @retval TRUE The FirstTime is not later than the Seco= ndTime. > > - @retval FALSE The FirstTime is later than the SecondTi= me. > > - > > -**/ > > -BOOLEAN > > -VariableCompareTimeStampInternal ( > > - IN EFI_TIME *FirstTime, > > - IN EFI_TIME *SecondTime > > - ) > > -{ > > - if (FirstTime->Year !=3D SecondTime->Year) { > > - return (BOOLEAN) (FirstTime->Year < SecondTime->Year); > > - } else if (FirstTime->Month !=3D SecondTime->Month) { > > - return (BOOLEAN) (FirstTime->Month < SecondTime->Month); > > - } else if (FirstTime->Day !=3D SecondTime->Day) { > > - return (BOOLEAN) (FirstTime->Day < SecondTime->Day); > > - } else if (FirstTime->Hour !=3D SecondTime->Hour) { > > - return (BOOLEAN) (FirstTime->Hour < SecondTime->Hour); > > - } else if (FirstTime->Minute !=3D SecondTime->Minute) { > > - return (BOOLEAN) (FirstTime->Minute < SecondTime->Minute); > > - } > > - > > - return (BOOLEAN) (FirstTime->Second <=3D SecondTime->Second); > > -} > > - > > /** > > Update the variable region with Variable information. If > > EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS is set, > > index of associated public key is needed. > > @@ -2205,7 +1642,7 @@ UpdateVariable ( > > // go to delete this variable in variable HOB and > > // try to flush other variables from HOB to flash. > > // > > - UpdateVariableInfo (VariableName, VendorGuid, FALSE, FALSE, > FALSE, > > TRUE, FALSE); > > + UpdateVariableInfo (VariableName, VendorGuid, FALSE, FALSE, > FALSE, > > TRUE, FALSE, &gVariableInfo); > > FlushHobVariableToFlash (VariableName, VendorGuid); > > return EFI_SUCCESS; > > } > > @@ -2322,7 +1759,7 @@ UpdateVariable ( > > &State > > ); > > if (!EFI_ERROR (Status)) { > > - UpdateVariableInfo (VariableName, VendorGuid, Variable->Volat= ile, > > FALSE, FALSE, TRUE, FALSE); > > + UpdateVariableInfo (VariableName, VendorGuid, Variable->Volat= ile, > > FALSE, FALSE, TRUE, FALSE, &gVariableInfo); > > if (!Variable->Volatile) { > > CacheVariable->CurrPtr->State =3D State; > > FlushHobVariableToFlash (VariableName, VendorGuid); > > @@ -2341,7 +1778,7 @@ UpdateVariable ( > > // > > // Variable content unchanged and no need to update timestamp, = just > > return. > > // > > - UpdateVariableInfo (VariableName, VendorGuid, Variable->Volatil= e, > > FALSE, TRUE, FALSE, FALSE); > > + UpdateVariableInfo (VariableName, VendorGuid, Variable->Volatil= e, > > FALSE, TRUE, FALSE, FALSE, &gVariableInfo); > > Status =3D EFI_SUCCESS; > > goto Done; > > } else if ((CacheVariable->CurrPtr->State =3D=3D VAR_ADDED) || > > @@ -2570,7 +2007,7 @@ UpdateVariable ( > > CacheVariable->CurrPtr =3D (VARIABLE_HEADER *)((UINTN) > > CacheVariable->StartPtr + ((UINTN) Variable->CurrPtr - (UINTN) Variabl= e- > > >StartPtr)); > > CacheVariable->InDeletedTransitionPtr =3D NULL; > > } > > - UpdateVariableInfo (VariableName, VendorGuid, FALSE, FALSE, T= RUE, > > FALSE, FALSE); > > + UpdateVariableInfo (VariableName, VendorGuid, FALSE, FALSE, T= RUE, > > FALSE, FALSE, &gVariableInfo); > > FlushHobVariableToFlash (VariableName, VendorGuid); > > } else { > > if (IsCommonUserVariable && ((VarSize + mVariableModuleGlobal= - > > >CommonUserVariableTotalSize) > mVariableModuleGlobal- > > >CommonMaxUserVariableSpace)) { > > @@ -2720,7 +2157,7 @@ UpdateVariable ( > > CacheVariable->CurrPtr =3D (VARIABLE_HEADER *)((UINTN) > > CacheVariable->StartPtr + ((UINTN) Variable->CurrPtr - (UINTN) Variabl= e- > > >StartPtr)); > > CacheVariable->InDeletedTransitionPtr =3D NULL; > > } > > - UpdateVariableInfo (VariableName, VendorGuid, TRUE, FALSE, TR= UE, > > FALSE, FALSE); > > + UpdateVariableInfo (VariableName, VendorGuid, TRUE, FALSE, TR= UE, > > FALSE, FALSE, &gVariableInfo); > > } > > goto Done; > > } > > @@ -2791,7 +2228,7 @@ UpdateVariable ( > > } > > > > if (!EFI_ERROR (Status)) { > > - UpdateVariableInfo (VariableName, VendorGuid, Volatile, FALSE, TR= UE, > > FALSE, FALSE); > > + UpdateVariableInfo (VariableName, VendorGuid, Volatile, FALSE, TR= UE, > > FALSE, FALSE, &gVariableInfo); > > if (!Volatile) { > > FlushHobVariableToFlash (VariableName, VendorGuid); > > } > > @@ -2870,7 +2307,7 @@ VariableServiceGetVariable ( > > } > > > > *DataSize =3D VarDataSize; > > - UpdateVariableInfo (VariableName, VendorGuid, Variable.Volatile, > TRUE, > > FALSE, FALSE, FALSE); > > + UpdateVariableInfo (VariableName, VendorGuid, Variable.Volatile, > TRUE, > > FALSE, FALSE, FALSE, &gVariableInfo); > > > > Status =3D EFI_SUCCESS; > > goto Done; > > @@ -2885,166 +2322,6 @@ Done: > > return Status; > > } > > > > -/** > > - This code Finds the Next available variable. > > - > > - Caution: This function may receive untrusted input. > > - This function may be invoked in SMM mode. This function will do bas= ic > > validation, before parse the data. > > - > > - @param[in] VariableName Pointer to variable name. > > - @param[in] VendorGuid Variable Vendor Guid. > > - @param[out] VariablePtr Pointer to variable header address. > > - > > - @retval EFI_SUCCESS The function completed successfully. > > - @retval EFI_NOT_FOUND The next variable was not found. > > - @retval EFI_INVALID_PARAMETER If VariableName is not an empty > string, > > while VendorGuid is NULL. > > - @retval EFI_INVALID_PARAMETER The input values of VariableName and > > VendorGuid are not a name and > > - GUID of an existing variable. > > - > > -**/ > > -EFI_STATUS > > -EFIAPI > > -VariableServiceGetNextVariableInternal ( > > - IN CHAR16 *VariableName, > > - IN EFI_GUID *VendorGuid, > > - OUT VARIABLE_HEADER **VariablePtr > > - ) > > -{ > > - VARIABLE_STORE_TYPE Type; > > - VARIABLE_POINTER_TRACK Variable; > > - VARIABLE_POINTER_TRACK VariableInHob; > > - VARIABLE_POINTER_TRACK VariablePtrTrack; > > - EFI_STATUS Status; > > - VARIABLE_STORE_HEADER > *VariableStoreHeader[VariableStoreTypeMax]; > > - > > - Status =3D FindVariable (VariableName, VendorGuid, &Variable, > > &mVariableModuleGlobal->VariableGlobal, FALSE); > > - if (Variable.CurrPtr =3D=3D NULL || EFI_ERROR (Status)) { > > - // > > - // For VariableName is an empty string, FindVariable() will try t= o find and > > return > > - // the first qualified variable, and if FindVariable() returns er= ror > > (EFI_NOT_FOUND) > > - // as no any variable is found, still go to return the error > > (EFI_NOT_FOUND). > > - // > > - if (VariableName[0] !=3D 0) { > > - // > > - // For VariableName is not an empty string, and FindVariable() = returns > > error as > > - // VariableName and VendorGuid are not a name and GUID of an > existing > > variable, > > - // there is no way to get next variable, follow spec to return > > EFI_INVALID_PARAMETER. > > - // > > - Status =3D EFI_INVALID_PARAMETER; > > - } > > - goto Done; > > - } > > - > > - if (VariableName[0] !=3D 0) { > > - // > > - // If variable name is not NULL, get next variable. > > - // > > - Variable.CurrPtr =3D GetNextVariablePtr (Variable.CurrPtr); > > - } > > - > > - // > > - // 0: Volatile, 1: HOB, 2: Non-Volatile. > > - // The index and attributes mapping must be kept in this order as > > FindVariable > > - // makes use of this mapping to implement search algorithm. > > - // > > - VariableStoreHeader[VariableStoreTypeVolatile] =3D > > (VARIABLE_STORE_HEADER *) (UINTN) mVariableModuleGlobal- > > >VariableGlobal.VolatileVariableBase; > > - VariableStoreHeader[VariableStoreTypeHob] =3D > > (VARIABLE_STORE_HEADER *) (UINTN) mVariableModuleGlobal- > > >VariableGlobal.HobVariableBase; > > - VariableStoreHeader[VariableStoreTypeNv] =3D mNvVariableCache= ; > > - > > - while (TRUE) { > > - // > > - // Switch from Volatile to HOB, to Non-Volatile. > > - // > > - while (!IsValidVariableHeader (Variable.CurrPtr, Variable.EndPtr)= ) { > > - // > > - // Find current storage index > > - // > > - for (Type =3D (VARIABLE_STORE_TYPE) 0; Type < VariableStoreType= Max; > > Type++) { > > - if ((VariableStoreHeader[Type] !=3D NULL) && (Variable.StartP= tr =3D=3D > > GetStartPointer (VariableStoreHeader[Type]))) { > > - break; > > - } > > - } > > - ASSERT (Type < VariableStoreTypeMax); > > - // > > - // Switch to next storage > > - // > > - for (Type++; Type < VariableStoreTypeMax; Type++) { > > - if (VariableStoreHeader[Type] !=3D NULL) { > > - break; > > - } > > - } > > - // > > - // Capture the case that > > - // 1. current storage is the last one, or > > - // 2. no further storage > > - // > > - if (Type =3D=3D VariableStoreTypeMax) { > > - Status =3D EFI_NOT_FOUND; > > - goto Done; > > - } > > - Variable.StartPtr =3D GetStartPointer (VariableStoreHeader[Type= ]); > > - Variable.EndPtr =3D GetEndPointer (VariableStoreHeader[Type= ]); > > - Variable.CurrPtr =3D Variable.StartPtr; > > - } > > - > > - // > > - // Variable is found > > - // > > - if (Variable.CurrPtr->State =3D=3D VAR_ADDED || Variable.CurrPtr-= >State =3D=3D > > (VAR_IN_DELETED_TRANSITION & VAR_ADDED)) { > > - if (!AtRuntime () || ((Variable.CurrPtr->Attributes & > > EFI_VARIABLE_RUNTIME_ACCESS) !=3D 0)) { > > - if (Variable.CurrPtr->State =3D=3D (VAR_IN_DELETED_TRANSITION= & > > VAR_ADDED)) { > > - // > > - // If it is a IN_DELETED_TRANSITION variable, > > - // and there is also a same ADDED one at the same time, > > - // don't return it. > > - // > > - VariablePtrTrack.StartPtr =3D Variable.StartPtr; > > - VariablePtrTrack.EndPtr =3D Variable.EndPtr; > > - Status =3D FindVariableEx ( > > - GetVariableNamePtr (Variable.CurrPtr), > > - GetVendorGuidPtr (Variable.CurrPtr), > > - FALSE, > > - &VariablePtrTrack > > - ); > > - if (!EFI_ERROR (Status) && VariablePtrTrack.CurrPtr->State = = =3D=3D > > VAR_ADDED) { > > - Variable.CurrPtr =3D GetNextVariablePtr (Variable.CurrPtr= ); > > - continue; > > - } > > - } > > - > > - // > > - // Don't return NV variable when HOB overrides it > > - // > > - if ((VariableStoreHeader[VariableStoreTypeHob] !=3D NULL) && > > (VariableStoreHeader[VariableStoreTypeNv] !=3D NULL) && > > - (Variable.StartPtr =3D=3D GetStartPointer > > (VariableStoreHeader[VariableStoreTypeNv])) > > - ) { > > - VariableInHob.StartPtr =3D GetStartPointer > > (VariableStoreHeader[VariableStoreTypeHob]); > > - VariableInHob.EndPtr =3D GetEndPointer > > (VariableStoreHeader[VariableStoreTypeHob]); > > - Status =3D FindVariableEx ( > > - GetVariableNamePtr (Variable.CurrPtr), > > - GetVendorGuidPtr (Variable.CurrPtr), > > - FALSE, > > - &VariableInHob > > - ); > > - if (!EFI_ERROR (Status)) { > > - Variable.CurrPtr =3D GetNextVariablePtr (Variable.CurrPtr= ); > > - continue; > > - } > > - } > > - > > - *VariablePtr =3D Variable.CurrPtr; > > - Status =3D EFI_SUCCESS; > > - goto Done; > > - } > > - } > > - > > - Variable.CurrPtr =3D GetNextVariablePtr (Variable.CurrPtr); > > - } > > - > > -Done: > > - return Status; > > -} > > - > > /** > > > > This code Finds the Next available variable. > > @@ -3082,6 +2359,7 @@ VariableServiceGetNextVariableName ( > > UINTN MaxLen; > > UINTN VarNameSize; > > VARIABLE_HEADER *VariablePtr; > > + VARIABLE_STORE_HEADER > > *VariableStoreHeader[VariableStoreTypeMax]; > > > > if (VariableNameSize =3D=3D NULL || VariableName =3D=3D NULL || Ven= dorGuid > =3D=3D > > NULL) { > > return EFI_INVALID_PARAMETER; > > @@ -3101,7 +2379,16 @@ VariableServiceGetNextVariableName ( > > > > AcquireLockOnlyAtBootTime(&mVariableModuleGlobal- > > >VariableGlobal.VariableServicesLock); > > > > - Status =3D VariableServiceGetNextVariableInternal (VariableName, > > VendorGuid, &VariablePtr); > > + // > > + // 0: Volatile, 1: HOB, 2: Non-Volatile. > > + // The index and attributes mapping must be kept in this order as > > FindVariable > > + // makes use of this mapping to implement search algorithm. > > + // > > + VariableStoreHeader[VariableStoreTypeVolatile] =3D > > (VARIABLE_STORE_HEADER *) (UINTN) mVariableModuleGlobal- > > >VariableGlobal.VolatileVariableBase; > > + VariableStoreHeader[VariableStoreTypeHob] =3D > > (VARIABLE_STORE_HEADER *) (UINTN) mVariableModuleGlobal- > > >VariableGlobal.HobVariableBase; > > + VariableStoreHeader[VariableStoreTypeNv] =3D mNvVariableCache= ; > > + > > + Status =3D GetNextVariableEx (VariableName, VendorGuid, > > VariableStoreHeader, &VariablePtr); > > if (!EFI_ERROR (Status)) { > > VarNameSize =3D NameSizeOfVariable (VariablePtr); > > ASSERT (VarNameSize !=3D 0); > > @@ -3720,25 +3007,6 @@ ReclaimForOS( > > } > > } > > > > -/** > > - Get non-volatile maximum variable size. > > - > > - @return Non-volatile maximum variable size. > > - > > -**/ > > -UINTN > > -GetNonVolatileMaxVariableSize ( > > - VOID > > - ) > > -{ > > - if (PcdGet32 (PcdHwErrStorageSize) !=3D 0) { > > - return MAX (MAX (PcdGet32 (PcdMaxVariableSize), PcdGet32 > > (PcdMaxAuthVariableSize)), > > - PcdGet32 (PcdMaxHardwareErrorVariableSize)); > > - } else { > > - return MAX (PcdGet32 (PcdMaxVariableSize), PcdGet32 > > (PcdMaxAuthVariableSize)); > > - } > > -} > > - > > /** > > Get maximum variable size, covering both non-volatile and volatile > variables. > > > > @@ -4024,7 +3292,7 @@ InitNonVolatileVariableStore ( > > return Status; > > } > > mVariableModuleGlobal->VariableGlobal.EmuNvMode =3D TRUE; > > - DEBUG ((DEBUG_INFO, "Variable driver will work at emulated non- > volatile > > variable mode!\n")); > > + DEBUG ((DEBUG_INFO, "Variable driver will work in emulated non- > > volatile variable mode!\n")); > > } else { > > Status =3D InitRealNonVolatileVariableStore (&VariableStoreBase); > > if (EFI_ERROR (Status)) { > > @@ -4040,6 +3308,9 @@ InitNonVolatileVariableStore ( > > mVariableModuleGlobal->MaxVariableSize =3D PcdGet32 > > (PcdMaxVariableSize); > > mVariableModuleGlobal->MaxAuthVariableSize =3D ((PcdGet32 > > (PcdMaxAuthVariableSize) !=3D 0) ? PcdGet32 (PcdMaxAuthVariableSize) : > > mVariableModuleGlobal->MaxVariableSize); > > > > + Status =3D InitVariableHelpers (mVariableModuleGlobal- > > >VariableGlobal.AuthFormat); > > + ASSERT_EFI_ERROR (Status); > > + > > // > > // Parse non-volatile variable data and get last variable offset. > > // > > @@ -4470,18 +3741,13 @@ VariableCommonInitialize ( > > > > // > > // mVariableModuleGlobal->VariableGlobal.AuthFormat > > - // has been initialized in InitNonVolatileVariableStore(). > > + // is initialized in InitNonVolatileVariableStore(). > > // > > if (mVariableModuleGlobal->VariableGlobal.AuthFormat) { > > DEBUG ((EFI_D_INFO, "Variable driver will work with auth variable > > format!\n")); > > - // > > - // Set AuthSupport to FALSE first, VariableWriteServiceInitialize= () will > > initialize it. > > - // > > - mVariableModuleGlobal->VariableGlobal.AuthSupport =3D FALSE; > > VariableGuid =3D &gEfiAuthenticatedVariableGuid; > > } else { > > DEBUG ((EFI_D_INFO, "Variable driver will work without auth varia= ble > > support!\n")); > > - mVariableModuleGlobal->VariableGlobal.AuthSupport =3D FALSE; > > VariableGuid =3D &gEfiVariableGuid; > > } > > > > diff --git > a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableExLib.c > > b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableExLib.c > > index cb6fcebe2d..232d9ffe25 100644 > > --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableExLib.c > > +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableExLib.c > > @@ -1,12 +1,13 @@ > > /** @file > > Provides variable driver extended services. > > > > -Copyright (c) 2015, Intel Corporation. All rights reserved.
> > +Copyright (c) 2015 - 2019, Intel Corporation. All rights reserved. > > SPDX-License-Identifier: BSD-2-Clause-Patent > > > > **/ > > > > #include "Variable.h" > > +#include "VariableParsing.h" > > > > /** > > Finds variable in storage blocks of volatile and non-volatile stora= ge areas. > > @@ -97,10 +98,16 @@ VariableExLibFindNextVariable ( > > EFI_STATUS Status; > > VARIABLE_HEADER *VariablePtr; > > AUTHENTICATED_VARIABLE_HEADER *AuthVariablePtr; > > + VARIABLE_STORE_HEADER > > *VariableStoreHeader[VariableStoreTypeMax]; > > > > - Status =3D VariableServiceGetNextVariableInternal ( > > + VariableStoreHeader[VariableStoreTypeVolatile] =3D > > (VARIABLE_STORE_HEADER *) (UINTN) mVariableModuleGlobal- > > >VariableGlobal.VolatileVariableBase; > > + VariableStoreHeader[VariableStoreTypeHob] =3D > > (VARIABLE_STORE_HEADER *) (UINTN) mVariableModuleGlobal- > > >VariableGlobal.HobVariableBase; > > + VariableStoreHeader[VariableStoreTypeNv] =3D mNvVariableCache= ; > > + > > + Status =3D GetNextVariableEx ( > > VariableName, > > VendorGuid, > > + VariableStoreHeader, > > &VariablePtr > > ); > > if (EFI_ERROR (Status)) { > > diff --git > > a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableNonVolatile.c > > b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableNonVolatile.c > > new file mode 100644 > > index 0000000000..b1b6d8282f > > --- /dev/null > > +++ > > b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableNonVolatile.c > > @@ -0,0 +1,28 @@ > > +/** @file > > + Common variable non-volatile store routines. > > + > > +Copyright (c) 2019, Intel Corporation. All rights reserved.
> > +SPDX-License-Identifier: BSD-2-Clause-Patent > > + > > +**/ > > + > > +#include "VariableNonVolatile.h" > > + > > +/** > > + Get non-volatile maximum variable size. > > + > > + @return Non-volatile maximum variable size. > > + > > +**/ > > +UINTN > > +GetNonVolatileMaxVariableSize ( > > + VOID > > + ) > > +{ > > + if (PcdGet32 (PcdHwErrStorageSize) !=3D 0) { > > + return MAX (MAX (PcdGet32 (PcdMaxVariableSize), PcdGet32 > > (PcdMaxAuthVariableSize)), > > + PcdGet32 (PcdMaxHardwareErrorVariableSize)); > > + } else { > > + return MAX (PcdGet32 (PcdMaxVariableSize), PcdGet32 > > (PcdMaxAuthVariableSize)); > > + } > > +} > > diff --git > > a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableParsing.c > > b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableParsing.c > > new file mode 100644 > > index 0000000000..d448e5a264 > > --- /dev/null > > +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableParsing.c > > @@ -0,0 +1,816 @@ > > +/** @file > > + The common variable helper routines shared by the DXE_RUNTIME > > variable > > + module and the DXE_SMM variable module. > > + > > + Caution: This module requires additional review when modified. > > + This driver will have external input - variable data. They may be i= nput in > > SMM mode. > > + This external input must be validated carefully to avoid security i= ssue like > > + buffer overflow, integer overflow. > > + > > +Copyright (c) 2019, Intel Corporation. All rights reserved.
> > +SPDX-License-Identifier: BSD-2-Clause-Patent > > + > > +**/ > > + > > +#include "VariableParsing.h" > > + > > +typedef struct { > > + CONST CHAR16 *VariableName; > > + EFI_GUID *VendorGuid; > > +} VARIABLE_TYPE; > > + > > +VARIABLE_TYPE mAlwaysAuthenticatedVariables[] =3D { > > + {EFI_SECURE_BOOT_MODE_NAME, &gEfiGlobalVariableGuid}, > > + {EFI_PLATFORM_KEY_NAME, &gEfiGlobalVariableGuid}, > > + {EFI_KEY_EXCHANGE_KEY_NAME, &gEfiGlobalVariableGuid}, > > + {EFI_IMAGE_SECURITY_DATABASE, &gEfiImageSecurityDatabaseGuid}, > > + {EFI_IMAGE_SECURITY_DATABASE1, &gEfiImageSecurityDatabaseGuid}, > > + {EFI_IMAGE_SECURITY_DATABASE2, &gEfiImageSecurityDatabaseGuid}, > > +}; > > + > > +STATIC BOOLEAN mAuthFormat; > > + > > +/** > > + > > + This code checks if variable header is valid or not. > > + > > + @param Variable Pointer to the Variable Header. > > + @param VariableStoreEnd Pointer to the Variable Store End. > > + > > + @retval TRUE Variable header is valid. > > + @retval FALSE Variable header is not valid. > > + > > +**/ > > +BOOLEAN > > +IsValidVariableHeader ( > > + IN VARIABLE_HEADER *Variable, > > + IN VARIABLE_HEADER *VariableStoreEnd > > + ) > > +{ > > + if ((Variable =3D=3D NULL) || (Variable >=3D VariableStoreEnd) || (= Variable- > > >StartId !=3D VARIABLE_DATA)) { > > + // > > + // Variable is NULL or has reached the end of variable store, > > + // or the StartId is not correct. > > + // > > + return FALSE; > > + } > > + > > + return TRUE; > > +} > > + > > +/** > > + > > + This code gets the current status of Variable Store. > > + > > + @param VarStoreHeader Pointer to the Variable Store Header. > > + > > + @retval EfiRaw Variable store status is raw. > > + @retval EfiValid Variable store status is valid. > > + @retval EfiInvalid Variable store status is invalid. > > + > > +**/ > > +VARIABLE_STORE_STATUS > > +GetVariableStoreStatus ( > > + IN VARIABLE_STORE_HEADER *VarStoreHeader > > + ) > > +{ > > + if ((CompareGuid (&VarStoreHeader->Signature, > > &gEfiAuthenticatedVariableGuid) || > > + CompareGuid (&VarStoreHeader->Signature, &gEfiVariableGuid)) &= & > > + VarStoreHeader->Format =3D=3D VARIABLE_STORE_FORMATTED && > > + VarStoreHeader->State =3D=3D VARIABLE_STORE_HEALTHY > > + ) { > > + > > + return EfiValid; > > + } else if (((UINT32 *)(&VarStoreHeader->Signature))[0] =3D=3D 0xfff= fffff && > > + ((UINT32 *)(&VarStoreHeader->Signature))[1] =3D=3D 0xfff= fffff && > > + ((UINT32 *)(&VarStoreHeader->Signature))[2] =3D=3D 0xfff= fffff && > > + ((UINT32 *)(&VarStoreHeader->Signature))[3] =3D=3D 0xfff= fffff && > > + VarStoreHeader->Size =3D=3D 0xffffffff && > > + VarStoreHeader->Format =3D=3D 0xff && > > + VarStoreHeader->State =3D=3D 0xff > > + ) { > > + > > + return EfiRaw; > > + } else { > > + return EfiInvalid; > > + } > > +} > > + > > +/** > > + This code gets the size of variable header. > > + > > + @return Size of variable header in bytes in type UINTN. > > + > > +**/ > > +UINTN > > +GetVariableHeaderSize ( > > + VOID > > + ) > > +{ > > + UINTN Value; > > + > > + if (mAuthFormat) { > > + Value =3D sizeof (AUTHENTICATED_VARIABLE_HEADER); > > + } else { > > + Value =3D sizeof (VARIABLE_HEADER); > > + } > > + > > + return Value; > > +} > > + > > +/** > > + > > + This code gets the size of name of variable. > > + > > + @param Variable Pointer to the Variable Header. > > + > > + @return UINTN Size of variable in bytes. > > + > > +**/ > > +UINTN > > +NameSizeOfVariable ( > > + IN VARIABLE_HEADER *Variable > > + ) > > +{ > > + AUTHENTICATED_VARIABLE_HEADER *AuthVariable; > > + > > + AuthVariable =3D (AUTHENTICATED_VARIABLE_HEADER *) Variable; > > + if (mAuthFormat) { > > + if (AuthVariable->State =3D=3D (UINT8) (-1) || > > + AuthVariable->DataSize =3D=3D (UINT32) (-1) || > > + AuthVariable->NameSize =3D=3D (UINT32) (-1) || > > + AuthVariable->Attributes =3D=3D (UINT32) (-1)) { > > + return 0; > > + } > > + return (UINTN) AuthVariable->NameSize; > > + } else { > > + if (Variable->State =3D=3D (UINT8) (-1) || > > + Variable->DataSize =3D=3D (UINT32) (-1) || > > + Variable->NameSize =3D=3D (UINT32) (-1) || > > + Variable->Attributes =3D=3D (UINT32) (-1)) { > > + return 0; > > + } > > + return (UINTN) Variable->NameSize; > > + } > > +} > > + > > +/** > > + This code sets the size of name of variable. > > + > > + @param[in] Variable Pointer to the Variable Header. > > + @param[in] NameSize Name size to set. > > + > > +**/ > > +VOID > > +SetNameSizeOfVariable ( > > + IN VARIABLE_HEADER *Variable, > > + IN UINTN NameSize > > + ) > > +{ > > + AUTHENTICATED_VARIABLE_HEADER *AuthVariable; > > + > > + AuthVariable =3D (AUTHENTICATED_VARIABLE_HEADER *) Variable; > > + if (mAuthFormat) { > > + AuthVariable->NameSize =3D (UINT32) NameSize; > > + } else { > > + Variable->NameSize =3D (UINT32) NameSize; > > + } > > +} > > + > > +/** > > + > > + This code gets the size of variable data. > > + > > + @param Variable Pointer to the Variable Header. > > + > > + @return Size of variable in bytes. > > + > > +**/ > > +UINTN > > +DataSizeOfVariable ( > > + IN VARIABLE_HEADER *Variable > > + ) > > +{ > > + AUTHENTICATED_VARIABLE_HEADER *AuthVariable; > > + > > + AuthVariable =3D (AUTHENTICATED_VARIABLE_HEADER *) Variable; > > + if (mAuthFormat) { > > + if (AuthVariable->State =3D=3D (UINT8) (-1) || > > + AuthVariable->DataSize =3D=3D (UINT32) (-1) || > > + AuthVariable->NameSize =3D=3D (UINT32) (-1) || > > + AuthVariable->Attributes =3D=3D (UINT32) (-1)) { > > + return 0; > > + } > > + return (UINTN) AuthVariable->DataSize; > > + } else { > > + if (Variable->State =3D=3D (UINT8) (-1) || > > + Variable->DataSize =3D=3D (UINT32) (-1) || > > + Variable->NameSize =3D=3D (UINT32) (-1) || > > + Variable->Attributes =3D=3D (UINT32) (-1)) { > > + return 0; > > + } > > + return (UINTN) Variable->DataSize; > > + } > > +} > > + > > +/** > > + This code sets the size of variable data. > > + > > + @param[in] Variable Pointer to the Variable Header. > > + @param[in] DataSize Data size to set. > > + > > +**/ > > +VOID > > +SetDataSizeOfVariable ( > > + IN VARIABLE_HEADER *Variable, > > + IN UINTN DataSize > > + ) > > +{ > > + AUTHENTICATED_VARIABLE_HEADER *AuthVariable; > > + > > + AuthVariable =3D (AUTHENTICATED_VARIABLE_HEADER *) Variable; > > + if (mAuthFormat) { > > + AuthVariable->DataSize =3D (UINT32) DataSize; > > + } else { > > + Variable->DataSize =3D (UINT32) DataSize; > > + } > > +} > > + > > +/** > > + > > + This code gets the pointer to the variable name. > > + > > + @param Variable Pointer to the Variable Header. > > + > > + @return Pointer to Variable Name which is Unicode encoding. > > + > > +**/ > > +CHAR16 * > > +GetVariableNamePtr ( > > + IN VARIABLE_HEADER *Variable > > + ) > > +{ > > + return (CHAR16 *) ((UINTN) Variable + GetVariableHeaderSize ()); > > +} > > + > > +/** > > + This code gets the pointer to the variable guid. > > + > > + @param Variable Pointer to the Variable Header. > > + > > + @return A EFI_GUID* pointer to Vendor Guid. > > + > > +**/ > > +EFI_GUID * > > +GetVendorGuidPtr ( > > + IN VARIABLE_HEADER *Variable > > + ) > > +{ > > + AUTHENTICATED_VARIABLE_HEADER *AuthVariable; > > + > > + AuthVariable =3D (AUTHENTICATED_VARIABLE_HEADER *) Variable; > > + if (mAuthFormat) { > > + return &AuthVariable->VendorGuid; > > + } else { > > + return &Variable->VendorGuid; > > + } > > +} > > + > > +/** > > + > > + This code gets the pointer to the variable data. > > + > > + @param Variable Pointer to the Variable Header. > > + > > + @return Pointer to Variable Data. > > + > > +**/ > > +UINT8 * > > +GetVariableDataPtr ( > > + IN VARIABLE_HEADER *Variable > > + ) > > +{ > > + UINTN Value; > > + > > + // > > + // Be careful about pad size for alignment. > > + // > > + Value =3D (UINTN) GetVariableNamePtr (Variable); > > + Value +=3D NameSizeOfVariable (Variable); > > + Value +=3D GET_PAD_SIZE (NameSizeOfVariable (Variable)); > > + > > + return (UINT8 *) Value; > > +} > > + > > +/** > > + This code gets the variable data offset related to variable header. > > + > > + @param Variable Pointer to the Variable Header. > > + > > + @return Variable Data offset. > > + > > +**/ > > +UINTN > > +GetVariableDataOffset ( > > + IN VARIABLE_HEADER *Variable > > + ) > > +{ > > + UINTN Value; > > + > > + // > > + // Be careful about pad size for alignment > > + // > > + Value =3D GetVariableHeaderSize (); > > + Value +=3D NameSizeOfVariable (Variable); > > + Value +=3D GET_PAD_SIZE (NameSizeOfVariable (Variable)); > > + > > + return Value; > > +} > > + > > +/** > > + > > + This code gets the pointer to the next variable header. > > + > > + @param Variable Pointer to the Variable Header. > > + > > + @return Pointer to next variable header. > > + > > +**/ > > +VARIABLE_HEADER * > > +GetNextVariablePtr ( > > + IN VARIABLE_HEADER *Variable > > + ) > > +{ > > + UINTN Value; > > + > > + Value =3D (UINTN) GetVariableDataPtr (Variable); > > + Value +=3D DataSizeOfVariable (Variable); > > + Value +=3D GET_PAD_SIZE (DataSizeOfVariable (Variable)); > > + > > + // > > + // Be careful about pad size for alignment. > > + // > > + return (VARIABLE_HEADER *) HEADER_ALIGN (Value); > > +} > > + > > +/** > > + > > + Gets the pointer to the first variable header in given variable sto= re area. > > + > > + @param VarStoreHeader Pointer to the Variable Store Header. > > + > > + @return Pointer to the first variable header. > > + > > +**/ > > +VARIABLE_HEADER * > > +GetStartPointer ( > > + IN VARIABLE_STORE_HEADER *VarStoreHeader > > + ) > > +{ > > + // > > + // The end of variable store. > > + // > > + return (VARIABLE_HEADER *) HEADER_ALIGN (VarStoreHeader + 1); > > +} > > + > > +/** > > + > > + Gets the pointer to the end of the variable storage area. > > + > > + This function gets pointer to the end of the variable storage > > + area, according to the input variable store header. > > + > > + @param VarStoreHeader Pointer to the Variable Store Header. > > + > > + @return Pointer to the end of the variable storage area. > > + > > +**/ > > +VARIABLE_HEADER * > > +GetEndPointer ( > > + IN VARIABLE_STORE_HEADER *VarStoreHeader > > + ) > > +{ > > + // > > + // The end of variable store > > + // > > + return (VARIABLE_HEADER *) HEADER_ALIGN ((UINTN) VarStoreHeader > + > > VarStoreHeader->Size); > > +} > > + > > +/** > > + Returns if this is a variable that always requires authenticated wr= ites. > > + There may be other scenarios that result in a variable not identifi= ed by > the > > + function to also require authentication. > > + > > + @param[in] VariableName Name of variable. > > + @param[in] VendorGuid Guid of variable. > > + > > + @retval TRUE The variable always requires authenticated= writes > > + @retval FALSE The variable may or may not require authen= ticated > > writes > > +**/ > > +BOOLEAN > > +IsAuthenticatedVariable ( > > + IN CHAR16 *VariableName, > > + IN EFI_GUID *VendorGuid > > + ) > > +{ > > + UINTN Index; > > + > > + for (Index =3D 0; Index < sizeof (mAlwaysAuthenticatedVariables) / = sizeof > > (mAlwaysAuthenticatedVariables[0]); Index++) { > > + if ((StrCmp (VariableName, > > mAlwaysAuthenticatedVariables[Index].VariableName) =3D=3D 0) && > > + (CompareGuid (VendorGuid, > > mAlwaysAuthenticatedVariables[Index].VendorGuid))) { > > + return TRUE; > > + } > > + } > > + return FALSE; > > +} > > + > > +/** > > + Compare two EFI_TIME data. > > + > > + > > + @param FirstTime A pointer to the first EFI_TIME data. > > + @param SecondTime A pointer to the second EFI_TIME data. > > + > > + @retval TRUE The FirstTime is not later than the Seco= ndTime. > > + @retval FALSE The FirstTime is later than the SecondTi= me. > > + > > +**/ > > +BOOLEAN > > +VariableCompareTimeStampInternal ( > > + IN EFI_TIME *FirstTime, > > + IN EFI_TIME *SecondTime > > + ) > > +{ > > + if (FirstTime->Year !=3D SecondTime->Year) { > > + return (BOOLEAN) (FirstTime->Year < SecondTime->Year); > > + } else if (FirstTime->Month !=3D SecondTime->Month) { > > + return (BOOLEAN) (FirstTime->Month < SecondTime->Month); > > + } else if (FirstTime->Day !=3D SecondTime->Day) { > > + return (BOOLEAN) (FirstTime->Day < SecondTime->Day); > > + } else if (FirstTime->Hour !=3D SecondTime->Hour) { > > + return (BOOLEAN) (FirstTime->Hour < SecondTime->Hour); > > + } else if (FirstTime->Minute !=3D SecondTime->Minute) { > > + return (BOOLEAN) (FirstTime->Minute < SecondTime->Minute); > > + } > > + > > + return (BOOLEAN) (FirstTime->Second <=3D SecondTime->Second); > > +} > > + > > +/** > > + Find the variable in the specified variable store. > > + > > + @param[in] VariableName Name of the variable to be fou= nd > > + @param[in] VendorGuid Vendor GUID to be found. > > + @param[in] IgnoreRtCheck Ignore > EFI_VARIABLE_RUNTIME_ACCESS > > attribute > > + check at runtime when searchin= g variable. > > + @param[in, out] PtrTrack Variable Track Pointer structu= re that > > contains Variable Information. > > + > > + @retval EFI_SUCCESS Variable found successfully > > + @retval EFI_NOT_FOUND Variable not found > > +**/ > > +EFI_STATUS > > +FindVariableEx ( > > + IN CHAR16 *VariableName, > > + IN EFI_GUID *VendorGuid, > > + IN BOOLEAN IgnoreRtCheck, > > + IN OUT VARIABLE_POINTER_TRACK *PtrTrack > > + ) > > +{ > > + VARIABLE_HEADER *InDeletedVariable; > > + VOID *Point; > > + > > + PtrTrack->InDeletedTransitionPtr =3D NULL; > > + > > + // > > + // Find the variable by walk through HOB, volatile and non-volatile > variable > > store. > > + // > > + InDeletedVariable =3D NULL; > > + > > + for ( PtrTrack->CurrPtr =3D PtrTrack->StartPtr > > + ; IsValidVariableHeader (PtrTrack->CurrPtr, PtrTrack->EndPtr) > > + ; PtrTrack->CurrPtr =3D GetNextVariablePtr (PtrTrack->CurrPtr) > > + ) { > > + if (PtrTrack->CurrPtr->State =3D=3D VAR_ADDED || > > + PtrTrack->CurrPtr->State =3D=3D (VAR_IN_DELETED_TRANSITION & > > VAR_ADDED) > > + ) { > > + if (IgnoreRtCheck || !AtRuntime () || ((PtrTrack->CurrPtr->Attr= ibutes > & > > EFI_VARIABLE_RUNTIME_ACCESS) !=3D 0)) { > > + if (VariableName[0] =3D=3D 0) { > > + if (PtrTrack->CurrPtr->State =3D=3D (VAR_IN_DELETED_TRANSIT= ION & > > VAR_ADDED)) { > > + InDeletedVariable =3D PtrTrack->CurrPtr; > > + } else { > > + PtrTrack->InDeletedTransitionPtr =3D InDeletedVariable; > > + return EFI_SUCCESS; > > + } > > + } else { > > + if (CompareGuid (VendorGuid, GetVendorGuidPtr (PtrTrack- > >CurrPtr))) > > { > > + Point =3D (VOID *) GetVariableNamePtr (PtrTrack->CurrPtr)= ; > > + > > + ASSERT (NameSizeOfVariable (PtrTrack->CurrPtr) !=3D 0); > > + if (CompareMem (VariableName, Point, NameSizeOfVariable > > (PtrTrack->CurrPtr)) =3D=3D 0) { > > + if (PtrTrack->CurrPtr->State =3D=3D (VAR_IN_DELETED_TRA= NSITION & > > VAR_ADDED)) { > > + InDeletedVariable =3D PtrTrack->CurrPtr; > > + } else { > > + PtrTrack->InDeletedTransitionPtr =3D InDeletedVariabl= e; > > + return EFI_SUCCESS; > > + } > > + } > > + } > > + } > > + } > > + } > > + } > > + > > + PtrTrack->CurrPtr =3D InDeletedVariable; > > + return (PtrTrack->CurrPtr =3D=3D NULL) ? EFI_NOT_FOUND : EFI_SUCCE= SS; > > +} > > + > > +/** > > + This code finds the next available variable. > > + > > + Caution: This function may receive untrusted input. > > + This function may be invoked in SMM mode. This function will do bas= ic > > validation, before parse the data. > > + > > + @param[in] VariableName Pointer to variable name. > > + @param[in] VendorGuid Variable Vendor Guid. > > + @param[in] VariableStoreList A list of variable stores that should= be > used > > to get the next variable. > > + The maximum number of entries is the = max value of > > VARIABLE_STORE_TYPE. > > + @param[out] VariablePtr Pointer to variable header address. > > + > > + @retval EFI_SUCCESS The function completed successfully. > > + @retval EFI_NOT_FOUND The next variable was not found. > > + @retval EFI_INVALID_PARAMETER If VariableName is not an empty > string, > > while VendorGuid is NULL. > > + @retval EFI_INVALID_PARAMETER The input values of VariableName > and > > VendorGuid are not a name and > > + GUID of an existing variable. > > + > > +**/ > > +EFI_STATUS > > +EFIAPI > > +GetNextVariableEx ( > > + IN CHAR16 *VariableName, > > + IN EFI_GUID *VendorGuid, > > + IN VARIABLE_STORE_HEADER **VariableStoreList, > > + OUT VARIABLE_HEADER **VariablePtr > > + ) > > +{ > > + EFI_STATUS Status; > > + VARIABLE_STORE_TYPE StoreType; > > + VARIABLE_POINTER_TRACK Variable; > > + VARIABLE_POINTER_TRACK VariableInHob; > > + VARIABLE_POINTER_TRACK VariablePtrTrack; > > + > > + Status =3D EFI_NOT_FOUND; > > + > > + if (VariableStoreList =3D=3D NULL) { > > + return EFI_INVALID_PARAMETER; > > + } > > + > > + // Check if the variable exists in the given variable store list > > + for (StoreType =3D (VARIABLE_STORE_TYPE) 0; StoreType < > > VariableStoreTypeMax; StoreType++) { > > + if (VariableStoreList[StoreType] =3D=3D NULL) { > > + continue; > > + } > > + > > + Variable.StartPtr =3D GetStartPointer (VariableStoreList[StoreTyp= e]); > > + Variable.EndPtr =3D GetEndPointer (VariableStoreList[StoreTyp= e]); > > + Variable.Volatile =3D (BOOLEAN) (StoreType =3D=3D > VariableStoreTypeVolatile); > > + > > + Status =3D FindVariableEx (VariableName, VendorGuid, FALSE, &Vari= able); > > + if (!EFI_ERROR (Status)) { > > + break; > > + } > > + } > > + > > + if (Variable.CurrPtr =3D=3D NULL || EFI_ERROR (Status)) { > > + // > > + // For VariableName is an empty string, FindVariable() will try t= o find > and > > return > > + // the first qualified variable, and if FindVariable() returns er= ror > > (EFI_NOT_FOUND) > > + // as no any variable is found, still go to return the error > > (EFI_NOT_FOUND). > > + // > > + if (VariableName[0] !=3D 0) { > > + // > > + // For VariableName is not an empty string, and FindVariable() = returns > > error as > > + // VariableName and VendorGuid are not a name and GUID of an > > existing variable, > > + // there is no way to get next variable, follow spec to return > > EFI_INVALID_PARAMETER. > > + // > > + Status =3D EFI_INVALID_PARAMETER; > > + } > > + goto Done; > > + } > > + > > + if (VariableName[0] !=3D 0) { > > + // > > + // If variable name is not empty, get next variable. > > + // > > + Variable.CurrPtr =3D GetNextVariablePtr (Variable.CurrPtr); > > + } > > + > > + while (TRUE) { > > + // > > + // Switch to the next variable store if needed > > + // > > + while (!IsValidVariableHeader (Variable.CurrPtr, Variable.EndPtr)= ) { > > + // > > + // Find current storage index > > + // > > + for (StoreType =3D (VARIABLE_STORE_TYPE) 0; StoreType < > > VariableStoreTypeMax; StoreType++) { > > + if ((VariableStoreList[StoreType] !=3D NULL) && (Variable.Sta= rtPtr =3D=3D > > GetStartPointer (VariableStoreList[StoreType]))) { > > + break; > > + } > > + } > > + ASSERT (StoreType < VariableStoreTypeMax); > > + // > > + // Switch to next storage > > + // > > + for (StoreType++; StoreType < VariableStoreTypeMax; StoreType++= ) { > > + if (VariableStoreList[StoreType] !=3D NULL) { > > + break; > > + } > > + } > > + // > > + // Capture the case that > > + // 1. current storage is the last one, or > > + // 2. no further storage > > + // > > + if (StoreType =3D=3D VariableStoreTypeMax) { > > + Status =3D EFI_NOT_FOUND; > > + goto Done; > > + } > > + Variable.StartPtr =3D GetStartPointer (VariableStoreList[StoreT= ype]); > > + Variable.EndPtr =3D GetEndPointer (VariableStoreList[StoreT= ype]); > > + Variable.CurrPtr =3D Variable.StartPtr; > > + } > > + > > + // > > + // Variable is found > > + // > > + if (Variable.CurrPtr->State =3D=3D VAR_ADDED || Variable.CurrPtr-= >State > =3D=3D > > (VAR_IN_DELETED_TRANSITION & VAR_ADDED)) { > > + if (!AtRuntime () || ((Variable.CurrPtr->Attributes & > > EFI_VARIABLE_RUNTIME_ACCESS) !=3D 0)) { > > + if (Variable.CurrPtr->State =3D=3D (VAR_IN_DELETED_TRANSITION= & > > VAR_ADDED)) { > > + // > > + // If it is a IN_DELETED_TRANSITION variable, > > + // and there is also a same ADDED one at the same time, > > + // don't return it. > > + // > > + VariablePtrTrack.StartPtr =3D Variable.StartPtr; > > + VariablePtrTrack.EndPtr =3D Variable.EndPtr; > > + Status =3D FindVariableEx ( > > + GetVariableNamePtr (Variable.CurrPtr), > > + GetVendorGuidPtr (Variable.CurrPtr), > > + FALSE, > > + &VariablePtrTrack > > + ); > > + if (!EFI_ERROR (Status) && VariablePtrTrack.CurrPtr->State = = =3D=3D > > VAR_ADDED) { > > + Variable.CurrPtr =3D GetNextVariablePtr (Variable.CurrPtr= ); > > + continue; > > + } > > + } > > + > > + // > > + // Don't return NV variable when HOB overrides it > > + // > > + if ((VariableStoreList[VariableStoreTypeHob] !=3D NULL) && > > (VariableStoreList[VariableStoreTypeNv] !=3D NULL) && > > + (Variable.StartPtr =3D=3D GetStartPointer > > (VariableStoreList[VariableStoreTypeNv])) > > + ) { > > + VariableInHob.StartPtr =3D GetStartPointer > > (VariableStoreList[VariableStoreTypeHob]); > > + VariableInHob.EndPtr =3D GetEndPointer > > (VariableStoreList[VariableStoreTypeHob]); > > + Status =3D FindVariableEx ( > > + GetVariableNamePtr (Variable.CurrPtr), > > + GetVendorGuidPtr (Variable.CurrPtr), > > + FALSE, > > + &VariableInHob > > + ); > > + if (!EFI_ERROR (Status)) { > > + Variable.CurrPtr =3D GetNextVariablePtr (Variable.CurrPtr= ); > > + continue; > > + } > > + } > > + > > + *VariablePtr =3D Variable.CurrPtr; > > + Status =3D EFI_SUCCESS; > > + goto Done; > > + } > > + } > > + > > + Variable.CurrPtr =3D GetNextVariablePtr (Variable.CurrPtr); > > + } > > + > > +Done: > > + return Status; > > +} > > + > > +/** > > + Routine used to track statistical information about variable usage. > > + The data is stored in the EFI system table so it can be accessed la= ter. > > + VariableInfo.efi can dump out the table. Only Boot Services variabl= e > > + accesses are tracked by this code. The PcdVariableCollectStatistics > > + build flag controls if this feature is enabled. > > + > > + A read that hits in the cache will have Read and Cache true for > > + the transaction. Data is allocated by this routine, but never > > + freed. > > + > > + @param[in] VariableName Name of the Variable to track. > > + @param[in] VendorGuid Guid of the Variable to track. > > + @param[in] Volatile TRUE if volatile FALSE if non-volati= le. > > + @param[in] Read TRUE if GetVariable() was called. > > + @param[in] Write TRUE if SetVariable() was called. > > + @param[in] Delete TRUE if deleted via SetVariable(). > > + @param[in] Cache TRUE for a cache hit. > > + @param[in,out] VariableInfo Pointer to a pointer of > > VARIABLE_INFO_ENTRY structures. > > + > > +**/ > > +VOID > > +UpdateVariableInfo ( > > + IN CHAR16 *VariableName, > > + IN EFI_GUID *VendorGuid, > > + IN BOOLEAN Volatile, > > + IN BOOLEAN Read, > > + IN BOOLEAN Write, > > + IN BOOLEAN Delete, > > + IN BOOLEAN Cache, > > + IN OUT VARIABLE_INFO_ENTRY **VariableInfo > > + ) > > +{ > > + VARIABLE_INFO_ENTRY *Entry; > > + > > + if (FeaturePcdGet (PcdVariableCollectStatistics)) { > > + if (VariableName =3D=3D NULL || VendorGuid =3D=3D NULL || Variabl= eInfo =3D=3D > > NULL) { > > + return; > > + } > > + if (AtRuntime ()) { > > + // Don't collect statistics at runtime. > > + return; > > + } > > + > > + if (*VariableInfo =3D=3D NULL) { > > + // > > + // On the first call allocate a entry and place a pointer to it= in > > + // the EFI System Table. > > + // > > + *VariableInfo =3D AllocateZeroPool (sizeof (VARIABLE_INFO_ENTRY= )); > > + ASSERT (*VariableInfo !=3D NULL); > > + > > + CopyGuid (&(*VariableInfo)->VendorGuid, VendorGuid); > > + (*VariableInfo)->Name =3D AllocateZeroPool (StrSize (VariableNa= me)); > > + ASSERT ((*VariableInfo)->Name !=3D NULL); > > + StrCpyS ((*VariableInfo)->Name, > StrSize(VariableName)/sizeof(CHAR16), > > VariableName); > > + (*VariableInfo)->Volatile =3D Volatile; > > + } > > + > > + > > + for (Entry =3D (*VariableInfo); Entry !=3D NULL; Entry =3D Entry-= >Next) { > > + if (CompareGuid (VendorGuid, &Entry->VendorGuid)) { > > + if (StrCmp (VariableName, Entry->Name) =3D=3D 0) { > > + if (Read) { > > + Entry->ReadCount++; > > + } > > + if (Write) { > > + Entry->WriteCount++; > > + } > > + if (Delete) { > > + Entry->DeleteCount++; > > + } > > + if (Cache) { > > + Entry->CacheCount++; > > + } > > + > > + return; > > + } > > + } > > + > > + if (Entry->Next =3D=3D NULL) { > > + // > > + // If the entry is not in the table add it. > > + // Next iteration of the loop will fill in the data. > > + // > > + Entry->Next =3D AllocateZeroPool (sizeof (VARIABLE_INFO_ENTRY= )); > > + ASSERT (Entry->Next !=3D NULL); > > + > > + CopyGuid (&Entry->Next->VendorGuid, VendorGuid); > > + Entry->Next->Name =3D AllocateZeroPool (StrSize (VariableName= )); > > + ASSERT (Entry->Next->Name !=3D NULL); > > + StrCpyS (Entry->Next->Name, > StrSize(VariableName)/sizeof(CHAR16), > > VariableName); > > + Entry->Next->Volatile =3D Volatile; > > + } > > + } > > + } > > +} > > + > > +/** > > + Initializes context needed for variable helpers. > > + > > + @param[in] AuthFormat If true then indicates authent= icated > > variables are supported > > + > > + @retval EFI_SUCCESS Initialized successfully > > + @retval Others An error occurred during initi= alization > > +**/ > > +EFI_STATUS > > +EFIAPI > > +InitVariableHelpers ( > > + IN BOOLEAN AuthFormat > > + ) > > +{ > > + mAuthFormat =3D AuthFormat; > > + > > + return EFI_SUCCESS; > > +} > > diff --git > a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c > > b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c > > index ec463d063e..bda531d104 100644 > > --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c > > +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c > > @@ -30,6 +30,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent > > > > #include > > #include "Variable.h" > > +#include "VariableNonVolatile.h" > > +#include "VariableParsing.h" > > > > BOOLEAN mAtRuntime = =3D FALSE; > > UINT8 *mVariableBuffer= Payload =3D NULL; > > diff --git > > > a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDx > > e.c > > > b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDx > > e.c > > index 0a1888e5ef..5bf90039d6 100644 > > --- > > > a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDx > > e.c > > +++ > > > b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDx > > e.c > > @@ -13,7 +13,7 @@ > > > > InitCommunicateBuffer() is really function to check the variable da= ta size. > > > > -Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved. > > +Copyright (c) 2010 - 2019, Intel Corporation. All rights reserved. > > SPDX-License-Identifier: BSD-2-Clause-Patent > > > > **/ > > @@ -39,6 +39,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent > > #include > > > > #include "PrivilegePolymorphic.h" > > +#include "VariableParsing.h" > > > > EFI_HANDLE mHandle =3D NULL; > > EFI_SMM_VARIABLE_PROTOCOL *mSmmVariable =3D NULL; > > -- > > 2.16.2.windows.1 > > > > > >=20 >=20