From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (NAM10-BN7-obe.outbound.protection.outlook.com [40.107.92.135]) by mx.groups.io with SMTP id smtpd.web12.2402.1592378969431276246 for ; Wed, 17 Jun 2020 00:29:29 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@microsoft.com header.s=selector2 header.b=gz/yq/lp; spf=pass (domain: microsoft.com, ip: 40.107.92.135, mailfrom: bret.barkelew@microsoft.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oLfTchhIs5/qQIfxwamvW0T2xYIMOQW7b1Bw+7J0QZROb3vIY2SeuPASeNkKtU/9kZWvjj8nc0PP50m56JaQsgWH7sgEEODf1pk7QzPqQeJXUI4TkjCvztetUD2rlXQQpSgy4/aWUoascuBB1yMt7SBUzNg3afuoqKi4t+wcgbofB+SthEBdxbGFc8ggjVPNvt8MKjxvycxMf3+GFgbJtMCxT8aFpeKezVibYeq+bRp0GYGn7wAWB44gX4qygoQIPQNtMq7yYzJo4RZzWns9q+htCyJnZNhzDhgOmeBfmAfosJA1JelJto9Fx/3T2fvjLUjbltyLUdi1arjDDXeCkw== 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=tEsH4XqDmnexFwE1YomZPaAh7h7WfWVbbaCPmGqyg+8=; b=I9vLLJf8D4oSvs56720gRWjyO+3A4gBIZ4mYGB/0nqCj0t/0rhB6Ax2XF5L1QtOYB7fdxZUG3k8nXhNNxRU089iDAlF0a1BchzRTRdP3Lq1T9mub0/IGXgo+PMvkldBAIMg6kN5gveaRT1I3ptIcN6tUKsAnQ/oi/8pgIuukC6my2cC6OT5770G1JIT4uQo+kH5LPu4iMc/IP+oEQ6YRCkszigiRFbr1bXUOdrQibhi3zlELmfgVMT63drtOxz+ZBxUAbmdCYYUZNtHzccAiLfer9U0vqFVl1O2DQK69nwlR+sypbR5rkbimEGMqgrXJIbLAafB71DQoLK4B78hEww== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microsoft.com; dmarc=pass action=none header.from=microsoft.com; dkim=pass header.d=microsoft.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=tEsH4XqDmnexFwE1YomZPaAh7h7WfWVbbaCPmGqyg+8=; b=gz/yq/lpHXgLEio4fWCAhzwiz0IlG5XS8PFY38EzI3KSA5rqcjVhNQWFzggMe4AePWQqQ/QCWo1nuSp9H0Ek2GGqdgRD6kDj2VJMtV/c6TolBhY8utTrEOHH+2HRcYgNe9klqEdxtisYEk3FMeSBx9KGkfOm4ckYa40uhP0wQi0= Received: from CY4PR21MB0743.namprd21.prod.outlook.com (2603:10b6:903:b2::9) by CY4PR2101MB0865.namprd21.prod.outlook.com (2603:10b6:910:8a::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3131.9; Wed, 17 Jun 2020 07:29:27 +0000 Received: from CY4PR21MB0743.namprd21.prod.outlook.com ([fe80::4ef:d9e:62c:f319]) by CY4PR21MB0743.namprd21.prod.outlook.com ([fe80::f112:82fb:d4fd:f7dd%10]) with mapi id 15.20.3131.009; Wed, 17 Jun 2020 07:29:27 +0000 From: "Bret Barkelew" To: "devel@edk2.groups.io" , "bret@corthon.com" CC: Jian J Wang , Hao A Wu , liming.gao Subject: Re: [EXTERNAL] [edk2-devel] [PATCH v5 03/14] MdeModulePkg: Define the VariablePolicyHelperLib Thread-Topic: [EXTERNAL] [edk2-devel] [PATCH v5 03/14] MdeModulePkg: Define the VariablePolicyHelperLib Thread-Index: AQHWOYy7PrJRQf/OCUSSeIb1NOWIBKjcfvMr Date: Wed, 17 Jun 2020 07:29:27 +0000 Message-ID: References: <20200603065810.806-1-brbarkel@microsoft.com>,<20200603065810.806-4-brbarkel@microsoft.com> In-Reply-To: <20200603065810.806-4-brbarkel@microsoft.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: msip_labels: MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_Enabled=True;MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_SiteId=72f988bf-86f1-41af-91ab-2d7cd011db47;MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_SetDate=2020-06-17T07:29:24.771Z;MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_Name=General;MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_ContentBits=0;MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_Method=Standard; authentication-results: edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=none action=none header.from=microsoft.com; x-originating-ip: [71.212.143.8] x-ms-publictraffictype: Email x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: eac11781-d152-45b9-bb11-08d812902aa2 x-ms-traffictypediagnostic: CY4PR2101MB0865: x-ld-processed: 72f988bf-86f1-41af-91ab-2d7cd011db47,ExtAddr x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:10000; x-forefront-prvs: 04371797A5 x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 1IbRSuFR/dzt/vu8yFYuVIGPdrVJ80TckFWIKH3k09ErVGG5X22P0msCz1v675Y68ojm9RgUwMJ64PjZ5ZtbQrfAn8xtKXcniqI3JsXnHTqV2Auis0Dn0qX8D+7SBxCbCB0kV/mb+g+WgXJL37QnyWULrAP3EH5tb42/tKcDn2/FOcdskTlbw9Mn+t/FbKa3J/cKb7VRZ+L6vN3KaqDWGMFbg0k6+bLnlo0diLO8qMhuvbKOZ4WaMrwVWFGhTJ7g6vSQlO0+hl5Bs8y5eJbw7qM3dNRsYcGLrCda0EIXba+/sJ2lMtzh0guh6HZf68DF4SM9CHQqH5MuzGTWHQQ5Z26u63ZZaETjEoXIioiTAIR6DF8yVZDVwMOqtbQ81WX8N+iIU7nUjXqzr4CQ7krfew== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CY4PR21MB0743.namprd21.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(4636009)(136003)(346002)(39860400002)(396003)(376002)(366004)(53546011)(8676002)(8990500004)(26005)(10290500003)(8936002)(9686003)(186003)(4326008)(6506007)(966005)(478600001)(2906002)(55016002)(19627405001)(86362001)(316002)(5660300002)(166002)(82960400001)(30864003)(66446008)(66946007)(64756008)(66476007)(66556008)(91956017)(76116006)(82950400001)(71200400001)(33656002)(83380400001)(7696005)(52536014)(110136005)(54906003)(559001)(579004);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata: C8qcjQk4kqMPlkVcfPqMq7F7G3sgHTYzZ0hrDjLlPP8xftzYQmnLl9LRssbciYNahrmiSLbi9aj+Wlg8KCiN8s1BVVtsYGgeaFwIA8DIqg/a2Zeoj/STyUKQlU2O1TwcEGdPqE6OHeaS2jNQe9vFxtGuusYPUPeUUsIHyANVDTwNgDrObYP0LAaUfaw1RRQDt+aE+6fguzvO0rV8GagUSupoSX//qWsw8Zg3Rp2mLxxhQooF/Pdvaw/u1/idm5gaBOYGKdoMXQJQpGgE0nfMzgf159sgylIOCRtoim0yKeMCYay77EgiNkc8SvnL5P0U53SWFrXDeh5umUz+b4xkkdjQsIaSpxkj4JckC1wJUt1iCUFsQOazbd8sDw7Ua7Lqli99VFvUUNvrfbnk7QlBnKHVD4/t78Ff+IPTI8b3sbyeP4yGo+A72oD2nbKb+5SVWckx37/+ruM+CPO0KPPDI9iWumLwqjOEBci1rlxv0VE= x-ms-exchange-transport-forked: True MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: CY4PR21MB0743.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: eac11781-d152-45b9-bb11-08d812902aa2 X-MS-Exchange-CrossTenant-originalarrivaltime: 17 Jun 2020 07:29:27.1784 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: wCefk6riKj9j5zIX2+ETq0x6uhA/XHBmx3j56cVuKqfd5qb6oOCehxXA8O5ymXuydSu/nWc9C59XWtSMfgebMA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR2101MB0865 Content-Language: en-US Content-Type: multipart/alternative; boundary="_000_CY4PR21MB0743E345A95976B62EB00AEBEF9A0CY4PR21MB0743namp_" --_000_CY4PR21MB0743E345A95976B62EB00AEBEF9A0CY4PR21MB0743namp_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Bump. This specific patch needs Reviews. - Bret ________________________________ From: devel@edk2.groups.io on behalf of Bret Barkele= w via groups.io Sent: Tuesday, June 2, 2020 11:57 PM To: devel@edk2.groups.io Cc: Jian J Wang ; Hao A Wu ; lim= ing.gao Subject: [EXTERNAL] [edk2-devel] [PATCH v5 03/14] MdeModulePkg: Define the = VariablePolicyHelperLib https://nam06.safelinks.protection.outlook.com/?url=3Dhttps%3A%2F%2Fbugzill= a.tianocore.org%2Fshow_bug.cgi%3Fid%3D2522&data=3D02%7C01%7CBret.Barkel= ew%40microsoft.com%7Cf4de67d242ec4517ab1c08d807a3dc74%7C72f988bf86f141af91a= b2d7cd011db47%7C1%7C0%7C637267747648232766&sdata=3DErqHXizN7Q6ghP%2BPui= vvQuQnhfYKMEMwWgitRbYMCmE%3D&reserved=3D0 VariablePolicy is an updated interface to replace VarLock and VarCheckProtocol. Add the VariablePolicyHelperLib library, containing several functions to help with the repetitive process of creating a correctly structured and packed VariablePolicy entry. Cc: Jian J Wang Cc: Hao A Wu Cc: Liming Gao Cc: Bret Barkelew Signed-off-by: Bret Barkelew --- MdeModulePkg/Library/VariablePolicyHelperLib/VariablePolicyHelperLib.c |= 396 ++++++++++++++++++++ MdeModulePkg/Include/Library/VariablePolicyHelperLib.h |= 164 ++++++++ MdeModulePkg/Library/VariablePolicyHelperLib/VariablePolicyHelperLib.inf |= 35 ++ MdeModulePkg/Library/VariablePolicyHelperLib/VariablePolicyHelperLib.uni |= 12 + MdeModulePkg/MdeModulePkg.dec |= 5 + MdeModulePkg/MdeModulePkg.dsc |= 2 + 6 files changed, 614 insertions(+) diff --git a/MdeModulePkg/Library/VariablePolicyHelperLib/VariablePolicyHel= perLib.c b/MdeModulePkg/Library/VariablePolicyHelperLib/VariablePolicyHelpe= rLib.c new file mode 100644 index 000000000000..0c9299c8b0e1 --- /dev/null +++ b/MdeModulePkg/Library/VariablePolicyHelperLib/VariablePolicyHelperLib.= c @@ -0,0 +1,396 @@ +/** @file -- VariablePolicyHelperLib.c +This library contains helper functions for marshalling and registering +new policies with the VariablePolicy infrastructure. + +This library is currently written against VariablePolicy revision 0x000100= 00. + +Copyright (c) Microsoft Corporation. +SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include + +#include +#include +#include +#include + +#include + +/** + This internal helper function populates the header structure, + all common fields, and takes care of fix-ups. + + NOTE: Only use this internally. Assumes correctly-sized buffers. + + @param[out] EntPtr Pointer to the buffer to be populated. + @param[in] Namespace Pointer to an EFI_GUID for the target variable n= amespace that this policy will protect. + @param[in] MinSize MinSize for the VariablePolicy. + @param[in] MaxSize MaxSize for the VariablePolicy. + @param[in] AttributesMustHave AttributesMustHave for the VariablePol= icy. + @param[in] AttributesCantHave AttributesCantHave for the VariablePol= icy. + @param[in] LockPolicyType LockPolicyType for the VariablePolicy. + +**/ +STATIC +VOID +PopulateCommonData ( + OUT VARIABLE_POLICY_ENTRY *EntPtr, + IN CONST EFI_GUID *Namespace, + IN UINT32 MinSize, + IN UINT32 MaxSize, + IN UINT32 AttributesMustHave, + IN UINT32 AttributesCantHave, + IN UINT8 LockPolicyType + ) +{ + EntPtr->Version =3D VARIABLE_POLICY_ENTRY_REVISION; + CopyGuid( &EntPtr->Namespace, Namespace ); + EntPtr->MinSize =3D MinSize; + EntPtr->MaxSize =3D MaxSize; + EntPtr->AttributesMustHave =3D AttributesMustHave; + EntPtr->AttributesCantHave =3D AttributesCantHave; + EntPtr->LockPolicyType =3D LockPolicyType; + + // NOTE: As a heler, fix up MaxSize for compatibility with the old model= . + if (EntPtr->MaxSize =3D=3D 0) { + EntPtr->MaxSize =3D VARIABLE_POLICY_NO_MAX_SIZE; + } + + return; +} + + +/** + This helper function will allocate and populate a new VariablePolicy + structure for a policy that does not contain any sub-structures (such as + VARIABLE_LOCK_ON_VAR_STATE_POLICY). + + NOTE: Caller will need to free structure once finished. + + @param[in] Namespace Pointer to an EFI_GUID for the target variable n= amespace that this policy will protect. + @param[in] Name [Optional] If provided, a pointer to the CHAR16 = array for the target variable name. + Otherwise, will create a policy that targets an = entire namespace. + @param[in] MinSize MinSize for the VariablePolicy. + @param[in] MaxSize MaxSize for the VariablePolicy. + @param[in] AttributesMustHave AttributesMustHave for the VariablePol= icy. + @param[in] AttributesCantHave AttributesCantHave for the VariablePol= icy. + @param[in] LockPolicyType LockPolicyType for the VariablePolicy. + @param[out] NewEntry If successful, will be set to a pointer to the a= llocated buffer containing the + new policy. + + @retval EFI_SUCCESS Operation completed successfully and= structure is populated. + @retval EFI_INVALID_PARAMETER Namespace is NULL. + @retval EFI_INVALID_PARAMETER LockPolicyType is invalid for a basi= c structure. + @retval EFI_BUFFER_TOO_SMALL Finished structure would not fit in = UINT16 size. + @retval EFI_OUT_OF_RESOURCES Could not allocate sufficient space = for structure. + +**/ +EFI_STATUS +EFIAPI +CreateBasicVariablePolicy ( + IN CONST EFI_GUID *Namespace, + IN CONST CHAR16 *Name OPTIONAL, + IN UINT32 MinSize, + IN UINT32 MaxSize, + IN UINT32 AttributesMustHave, + IN UINT32 AttributesCantHave, + IN UINT8 LockPolicyType, + OUT VARIABLE_POLICY_ENTRY **NewEntry + ) +{ + UINTN TotalSize; + UINTN NameSize; + VARIABLE_POLICY_ENTRY *EntPtr; + CHAR16 *CopyName; + + // Check some initial invalid parameters for this function. + if (Namespace =3D=3D NULL || NewEntry =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + if (LockPolicyType !=3D VARIABLE_POLICY_TYPE_NO_LOCK && + LockPolicyType !=3D VARIABLE_POLICY_TYPE_LOCK_NOW && + LockPolicyType !=3D VARIABLE_POLICY_TYPE_LOCK_ON_CREATE) { + return EFI_INVALID_PARAMETER; + } + + // Now we've gotta determine the total size of the buffer required for + // the VariablePolicy structure. + TotalSize =3D sizeof( VARIABLE_POLICY_ENTRY ); + if (Name !=3D NULL) { + NameSize =3D StrnSizeS( Name, MAX_UINT16 ); + TotalSize +=3D NameSize; + } + // Make sure the size fits within a VARIABLE_POLICY_ENTRY.Size. + ASSERT( TotalSize <=3D MAX_UINT16 ); + if (TotalSize > MAX_UINT16) { + return EFI_BUFFER_TOO_SMALL; + } + + // Allocate a buffer to hold all the data. We're on the home stretch. + *NewEntry =3D AllocatePool( TotalSize ); + if (*NewEntry =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + + // If we're still here, we're basically done. + // Copy the data and GET... OUT.... + EntPtr =3D *NewEntry; + PopulateCommonData ( EntPtr, + Namespace, + MinSize, + MaxSize, + AttributesMustHave, + AttributesCantHave, + LockPolicyType ); + EntPtr->Size =3D (UINT16)TotalSize; // This is safe = because we've already checked. + EntPtr->OffsetToName =3D sizeof(VARIABLE_POLICY_ENTRY); + if (Name !=3D NULL) { + CopyName =3D (CHAR16*)((UINT8*)EntPtr + EntPtr->OffsetToName); + CopyMem( CopyName, Name, NameSize ); + } + + return EFI_SUCCESS; +} + + +/** + This helper function will allocate and populate a new VariablePolicy + structure for a policy with a lock type of VARIABLE_POLICY_TYPE_LOCK_ON_= VAR_STATE. + + NOTE: Caller will need to free structure once finished. + + @param[in] Namespace Pointer to an EFI_GUID for the target variable n= amespace that this policy will protect. + @param[in] Name [Optional] If provided, a pointer to the CHAR16 = array for the target variable name. + Otherwise, will create a policy that targets an = entire namespace. + @param[in] MinSize MinSize for the VariablePolicy. + @param[in] MaxSize MaxSize for the VariablePolicy. + @param[in] AttributesMustHave AttributesMustHave for the VariablePol= icy. + @param[in] AttributesCantHave AttributesCantHave for the VariablePol= icy. + @param[in] VarStateNamespace Pointer to the EFI_GUID for the VARIAB= LE_LOCK_ON_VAR_STATE_POLICY.Namespace. + @param[in] VarStateValue Value for the VARIABLE_LOCK_ON_VAR_STA= TE_POLICY.Value. + @param[in] VarStateName Pointer to the CHAR16 array for the VA= RIABLE_LOCK_ON_VAR_STATE_POLICY.Name. + @param[out] NewEntry If successful, will be set to a pointer to the a= llocated buffer containing the + new policy. + + @retval EFI_SUCCESS Operation completed successfully and= structure is populated. + @retval EFI_INVALID_PARAMETER Namespace, VarStateNamespace, VarSta= teName is NULL. + @retval EFI_BUFFER_TOO_SMALL Finished structure would not fit in = UINT16 size. + @retval EFI_OUT_OF_RESOURCES Could not allocate sufficient space = for structure. + +**/ +EFI_STATUS +EFIAPI +CreateVarStateVariablePolicy ( + IN CONST EFI_GUID *Namespace, + IN CONST CHAR16 *Name OPTIONAL, + IN UINT32 MinSize, + IN UINT32 MaxSize, + IN UINT32 AttributesMustHave, + IN UINT32 AttributesCantHave, + IN CONST EFI_GUID *VarStateNamespace, + IN UINT8 VarStateValue, + IN CONST CHAR16 *VarStateName, + OUT VARIABLE_POLICY_ENTRY **NewEntry + ) +{ + UINTN TotalSize; + UINTN NameSize; + UINTN VarStateNameSize; + VARIABLE_POLICY_ENTRY *EntPtr; + CHAR16 *CopyName; + VARIABLE_LOCK_ON_VAR_STATE_POLICY *CopyPolicy; + + // Check some initial invalid parameters for this function. + if (Namespace =3D=3D NULL || VarStateNamespace =3D=3D NULL || + VarStateName =3D=3D NULL || NewEntry =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + // Now we've gotta determine the total size of the buffer required for + // the VariablePolicy structure. + VarStateNameSize =3D StrnSizeS( VarStateName, MAX_UINT16 ); + TotalSize =3D sizeof( VARIABLE_POLICY_ENTRY ) + + sizeof(VARIABLE_LOCK_ON_VAR_STATE_POLICY) + + VarStateNameSize; + if (Name !=3D NULL) { + NameSize =3D StrnSizeS( Name, MAX_UINT16 ); + TotalSize +=3D NameSize; + } + // Make sure the size fits within a VARIABLE_POLICY_ENTRY.Size. + ASSERT( TotalSize <=3D MAX_UINT16 ); + if (TotalSize > MAX_UINT16) { + return EFI_BUFFER_TOO_SMALL; + } + + // Allocate a buffer to hold all the data. We're on the home stretch. + *NewEntry =3D AllocatePool( TotalSize ); + if (*NewEntry =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + + // If we're still here, we're basically done. + // Copy the data and GET... OUT.... + EntPtr =3D *NewEntry; + PopulateCommonData ( EntPtr, + Namespace, + MinSize, + MaxSize, + AttributesMustHave, + AttributesCantHave, + VARIABLE_POLICY_TYPE_LOCK_ON_VAR_STATE ); + EntPtr->Size =3D (UINT16)TotalSize; // This is safe = because we've already checked. + EntPtr->OffsetToName =3D sizeof(VARIABLE_POLICY_ENTRY) + + sizeof(VARIABLE_LOCK_ON_VAR_STATE_POLICY) = + + (UINT16)VarStateNameSize; + + CopyPolicy =3D (VARIABLE_LOCK_ON_VAR_STATE_POLICY*)((UINT8*)EntPtr + siz= eof(VARIABLE_POLICY_ENTRY)); + CopyName =3D (CHAR16*)((UINT8*)CopyPolicy + sizeof(VARIABLE_LOCK_ON_VAR_= STATE_POLICY)); + CopyGuid( &CopyPolicy->Namespace, VarStateNamespace ); + CopyPolicy->Value =3D VarStateValue; + CopyMem( CopyName, VarStateName, VarStateNameSize ); + + if (Name !=3D NULL) { + CopyName =3D (CHAR16*)((UINT8*)EntPtr + EntPtr->OffsetToName); + CopyMem( CopyName, Name, NameSize ); + } + + return EFI_SUCCESS; +} + + +/** + This helper function does everything that CreateBasicVariablePolicy() do= es, but also + uses the passed in protocol to register the policy with the infrastructu= re. + Does not return a buffer, does not require the caller to free anything. + + @param[in] VariablePolicy Pointer to a valid instance of the VariableP= olicy protocol. + @param[in] Namespace Pointer to an EFI_GUID for the target variable n= amespace that this policy will protect. + @param[in] Name [Optional] If provided, a pointer to the CHAR16 = array for the target variable name. + Otherwise, will create a policy that targets an = entire namespace. + @param[in] MinSize MinSize for the VariablePolicy. + @param[in] MaxSize MaxSize for the VariablePolicy. + @param[in] AttributesMustHave AttributesMustHave for the VariablePol= icy. + @param[in] AttributesCantHave AttributesCantHave for the VariablePol= icy. + @param[in] LockPolicyType LockPolicyType for the VariablePolicy. + + @retval EFI_INVALID_PARAMETER VariablePolicy pointer is NULL. + @retval EFI_STATUS Status returned by CreateBasicVariable= Policy() or RegisterVariablePolicy(). + +**/ +EFI_STATUS +EFIAPI +RegisterBasicVariablePolicy ( + IN EDKII_VARIABLE_POLICY_PROTOCOL *VariablePolicy, + IN CONST EFI_GUID *Namespace, + IN CONST CHAR16 *Name OPTIONAL, + IN UINT32 MinSize, + IN UINT32 MaxSize, + IN UINT32 AttributesMustHave, + IN UINT32 AttributesCantHave, + IN UINT8 LockPolicyType + ) +{ + VARIABLE_POLICY_ENTRY *NewEntry; + EFI_STATUS Status; + + // Check the simple things. + if (VariablePolicy =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + // Create the new entry and make sure that everything worked. + NewEntry =3D NULL; + Status =3D CreateBasicVariablePolicy( Namespace, + Name, + MinSize, + MaxSize, + AttributesMustHave, + AttributesCantHave, + LockPolicyType, + &NewEntry ); + + // If that was successful, attempt to register the new policy. + if (!EFI_ERROR( Status )) { + Status =3D VariablePolicy->RegisterVariablePolicy( NewEntry ); + } + + // If we allocated the buffer, free the buffer. + if (NewEntry !=3D NULL) { + FreePool( NewEntry ); + } + + return Status; +} + + +/** + This helper function does everything that CreateBasicVariablePolicy() do= es, but also + uses the passed in protocol to register the policy with the infrastructu= re. + Does not return a buffer, does not require the caller to free anything. + + @param[in] VariablePolicy Pointer to a valid instance of the VariableP= olicy protocol. + @param[in] Namespace Pointer to an EFI_GUID for the target variable n= amespace that this policy will protect. + @param[in] Name [Optional] If provided, a pointer to the CHAR16 = array for the target variable name. + Otherwise, will create a policy that targets an = entire namespace. + @param[in] MinSize MinSize for the VariablePolicy. + @param[in] MaxSize MaxSize for the VariablePolicy. + @param[in] AttributesMustHave AttributesMustHave for the VariablePol= icy. + @param[in] AttributesCantHave AttributesCantHave for the VariablePol= icy. + @param[in] VarStateNamespace Pointer to the EFI_GUID for the VARIAB= LE_LOCK_ON_VAR_STATE_POLICY.Namespace. + @param[in] VarStateName Pointer to the CHAR16 array for the VA= RIABLE_LOCK_ON_VAR_STATE_POLICY.Name. + @param[in] VarStateValue Value for the VARIABLE_LOCK_ON_VAR_STA= TE_POLICY.Value. + + @retval EFI_INVALID_PARAMETER VariablePolicy pointer is NULL. + @retval EFI_STATUS Status returned by CreateBasicVariablePolicy()= or RegisterVariablePolicy(). + +**/ +EFI_STATUS +EFIAPI +RegisterVarStateVariablePolicy ( + IN EDKII_VARIABLE_POLICY_PROTOCOL *VariablePolicy, + IN CONST EFI_GUID *Namespace, + IN CONST CHAR16 *Name OPTIONAL, + IN UINT32 MinSize, + IN UINT32 MaxSize, + IN UINT32 AttributesMustHave, + IN UINT32 AttributesCantHave, + IN CONST EFI_GUID *VarStateNamespace, + IN CONST CHAR16 *VarStateName, + IN UINT8 VarStateValue + ) +{ + VARIABLE_POLICY_ENTRY *NewEntry; + EFI_STATUS Status; + + // Check the simple things. + if (VariablePolicy =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + // Create the new entry and make sure that everything worked. + NewEntry =3D NULL; + Status =3D CreateVarStateVariablePolicy( Namespace, + Name, + MinSize, + MaxSize, + AttributesMustHave, + AttributesCantHave, + VarStateNamespace, + VarStateValue, + VarStateName, + &NewEntry ); + + // If that was successful, attempt to register the new policy. + if (!EFI_ERROR( Status )) { + Status =3D VariablePolicy->RegisterVariablePolicy( NewEntry ); + } + + // If we allocated the buffer, free the buffer. + if (NewEntry !=3D NULL) { + FreePool( NewEntry ); + } + + return Status; +} diff --git a/MdeModulePkg/Include/Library/VariablePolicyHelperLib.h b/MdeMo= dulePkg/Include/Library/VariablePolicyHelperLib.h new file mode 100644 index 000000000000..3b75e9786094 --- /dev/null +++ b/MdeModulePkg/Include/Library/VariablePolicyHelperLib.h @@ -0,0 +1,164 @@ +/** @file -- VariablePolicyHelperLib.h +This library contains helper functions for marshalling and registering +new policies with the VariablePolicy infrastructure. + +Copyright (c) Microsoft Corporation. +SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef _EDKII_VARIABLE_POLICY_HELPER_LIB_H_ +#define _EDKII_VARIABLE_POLICY_HELPER_LIB_H_ + +#include + +/** + This helper function will allocate and populate a new VariablePolicy + structure for a policy that does not contain any sub-structures (such as + VARIABLE_LOCK_ON_VAR_STATE_POLICY). + + NOTE: Caller will need to free structure once finished. + + @param[in] Namespace Pointer to an EFI_GUID for the target variable n= amespace that this policy will protect. + @param[in] Name [Optional] If provided, a pointer to the CHAR16 = array for the target variable name. + Otherwise, will create a policy that targets an = entire namespace. + @param[in] MinSize MinSize for the VariablePolicy. + @param[in] MaxSize MaxSize for the VariablePolicy. + @param[in] AttributesMustHave AttributesMustHave for the VariablePol= icy. + @param[in] AttributesCantHave AttributesCantHave for the VariablePol= icy. + @param[in] LockPolicyType LockPolicyType for the VariablePolicy. + @param[out] NewEntry If successful, will be set to a pointer to the a= llocated buffer containing the + new policy. + + @retval EFI_SUCCESS Operation completed successfully and= structure is populated. + @retval EFI_INVALID_PARAMETER Namespace is NULL. + @retval EFI_INVALID_PARAMETER LockPolicyType is invalid for a basi= c structure. + @retval EFI_BUFFER_TOO_SMALL Finished structure would not fit in = UINT16 size. + @retval EFI_OUT_OF_RESOURCES Could not allocate sufficient space = for structure. + +**/ +EFI_STATUS +EFIAPI +CreateBasicVariablePolicy ( + IN CONST EFI_GUID *Namespace, + IN CONST CHAR16 *Name OPTIONAL, + IN UINT32 MinSize, + IN UINT32 MaxSize, + IN UINT32 AttributesMustHave, + IN UINT32 AttributesCantHave, + IN UINT8 LockPolicyType, + OUT VARIABLE_POLICY_ENTRY **NewEntry + ); + + +/** + This helper function will allocate and populate a new VariablePolicy + structure for a policy with a lock type of VARIABLE_POLICY_TYPE_LOCK_ON_= VAR_STATE. + + NOTE: Caller will need to free structure once finished. + + @param[in] Namespace Pointer to an EFI_GUID for the target variable n= amespace that this policy will protect. + @param[in] Name [Optional] If provided, a pointer to the CHAR16 = array for the target variable name. + Otherwise, will create a policy that targets an = entire namespace. + @param[in] MinSize MinSize for the VariablePolicy. + @param[in] MaxSize MaxSize for the VariablePolicy. + @param[in] AttributesMustHave AttributesMustHave for the VariablePol= icy. + @param[in] AttributesCantHave AttributesCantHave for the VariablePol= icy. + @param[in] VarStateNamespace Pointer to the EFI_GUID for the VARIAB= LE_LOCK_ON_VAR_STATE_POLICY.Namespace. + @param[in] VarStateValue Value for the VARIABLE_LOCK_ON_VAR_STA= TE_POLICY.Value. + @param[in] VarStateName Pointer to the CHAR16 array for the VA= RIABLE_LOCK_ON_VAR_STATE_POLICY.Name. + @param[out] NewEntry If successful, will be set to a pointer to the a= llocated buffer containing the + new policy. + + @retval EFI_SUCCESS Operation completed successfully and= structure is populated. + @retval EFI_INVALID_PARAMETER Namespace, VarStateNamespace, VarSta= teName is NULL. + @retval EFI_BUFFER_TOO_SMALL Finished structure would not fit in = UINT16 size. + @retval EFI_OUT_OF_RESOURCES Could not allocate sufficient space = for structure. + +**/ +EFI_STATUS +EFIAPI +CreateVarStateVariablePolicy ( + IN CONST EFI_GUID *Namespace, + IN CONST CHAR16 *Name OPTIONAL, + IN UINT32 MinSize, + IN UINT32 MaxSize, + IN UINT32 AttributesMustHave, + IN UINT32 AttributesCantHave, + IN CONST EFI_GUID *VarStateNamespace, + IN UINT8 VarStateValue, + IN CONST CHAR16 *VarStateName, + OUT VARIABLE_POLICY_ENTRY **NewEntry + ); + + +/** + This helper function does everything that CreateBasicVariablePolicy() do= es, but also + uses the passed in protocol to register the policy with the infrastructu= re. + Does not return a buffer, does not require the caller to free anything. + + @param[in] VariablePolicy Pointer to a valid instance of the VariableP= olicy protocol. + @param[in] Namespace Pointer to an EFI_GUID for the target variable n= amespace that this policy will protect. + @param[in] Name [Optional] If provided, a pointer to the CHAR16 = array for the target variable name. + Otherwise, will create a policy that targets an = entire namespace. + @param[in] MinSize MinSize for the VariablePolicy. + @param[in] MaxSize MaxSize for the VariablePolicy. + @param[in] AttributesMustHave AttributesMustHave for the VariablePol= icy. + @param[in] AttributesCantHave AttributesCantHave for the VariablePol= icy. + @param[in] LockPolicyType LockPolicyType for the VariablePolicy. + + @retval EFI_INVALID_PARAMETER VariablePolicy pointer is NULL. + @retval EFI_STATUS Status returned by CreateBasicVariable= Policy() or RegisterVariablePolicy(). + +**/ +EFI_STATUS +EFIAPI +RegisterBasicVariablePolicy ( + IN EDKII_VARIABLE_POLICY_PROTOCOL *VariablePolicy, + IN CONST EFI_GUID *Namespace, + IN CONST CHAR16 *Name OPTIONAL, + IN UINT32 MinSize, + IN UINT32 MaxSize, + IN UINT32 AttributesMustHave, + IN UINT32 AttributesCantHave, + IN UINT8 LockPolicyType + ); + + +/** + This helper function does everything that CreateBasicVariablePolicy() do= es, but also + uses the passed in protocol to register the policy with the infrastructu= re. + Does not return a buffer, does not require the caller to free anything. + + @param[in] VariablePolicy Pointer to a valid instance of the VariableP= olicy protocol. + @param[in] Namespace Pointer to an EFI_GUID for the target variable n= amespace that this policy will protect. + @param[in] Name [Optional] If provided, a pointer to the CHAR16 = array for the target variable name. + Otherwise, will create a policy that targets an = entire namespace. + @param[in] MinSize MinSize for the VariablePolicy. + @param[in] MaxSize MaxSize for the VariablePolicy. + @param[in] AttributesMustHave AttributesMustHave for the VariablePol= icy. + @param[in] AttributesCantHave AttributesCantHave for the VariablePol= icy. + @param[in] VarStateNamespace Pointer to the EFI_GUID for the VARIAB= LE_LOCK_ON_VAR_STATE_POLICY.Namespace. + @param[in] VarStateName Pointer to the CHAR16 array for the VA= RIABLE_LOCK_ON_VAR_STATE_POLICY.Name. + @param[in] VarStateValue Value for the VARIABLE_LOCK_ON_VAR_STA= TE_POLICY.Value. + + @retval EFI_INVALID_PARAMETER VariablePolicy pointer is NULL. + @retval EFI_STATUS Status returned by CreateBasicVariablePolicy()= or RegisterVariablePolicy(). + +**/ +EFI_STATUS +EFIAPI +RegisterVarStateVariablePolicy ( + IN EDKII_VARIABLE_POLICY_PROTOCOL *VariablePolicy, + IN CONST EFI_GUID *Namespace, + IN CONST CHAR16 *Name OPTIONAL, + IN UINT32 MinSize, + IN UINT32 MaxSize, + IN UINT32 AttributesMustHave, + IN UINT32 AttributesCantHave, + IN CONST EFI_GUID *VarStateNamespace, + IN CONST CHAR16 *VarStateName, + IN UINT8 VarStateValue + ); + +#endif // _EDKII_VARIABLE_POLICY_HELPER_LIB_H_ diff --git a/MdeModulePkg/Library/VariablePolicyHelperLib/VariablePolicyHel= perLib.inf b/MdeModulePkg/Library/VariablePolicyHelperLib/VariablePolicyHel= perLib.inf new file mode 100644 index 000000000000..506abf580e94 --- /dev/null +++ b/MdeModulePkg/Library/VariablePolicyHelperLib/VariablePolicyHelperLib.= inf @@ -0,0 +1,35 @@ +## @file VariablePolicyHelperLib.inf +# This library contains helper functions for marshalling and registering +# new policies with the VariablePolicy infrastructure. +# +# This library is currently written against VariablePolicy revision 0x0001= 0000. +# +# Copyright (c) Microsoft Corporation. +# SPDX-License-Identifier: BSD-2-Clause-Patent +## + + +[Defines] + INF_VERSION =3D 0x00010017 + BASE_NAME =3D VariablePolicyHelperLib + # MODULE_UNI_FILE =3D VariablePolicyHelperLib.uni + FILE_GUID =3D B3C2206B-FDD1-4AED-8352-FC5EC34C5630 + VERSION_STRING =3D 1.0 + MODULE_TYPE =3D BASE + LIBRARY_CLASS =3D VariablePolicyHelperLib + + +[Sources] + VariablePolicyHelperLib.c + + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + + +[LibraryClasses] + BaseLib + DebugLib + MemoryAllocationLib + BaseMemoryLib diff --git a/MdeModulePkg/Library/VariablePolicyHelperLib/VariablePolicyHel= perLib.uni b/MdeModulePkg/Library/VariablePolicyHelperLib/VariablePolicyHel= perLib.uni new file mode 100644 index 000000000000..39cbf11a4ce9 --- /dev/null +++ b/MdeModulePkg/Library/VariablePolicyHelperLib/VariablePolicyHelperLib.= uni @@ -0,0 +1,12 @@ +// /** @file +// VariablePolicyHelperLib.uni +// +// Copyright (c) Microsoft Corporation. +// SPDX-License-Identifier: BSD-2-Clause-Patent +// +// **/ + + +#string STR_MODULE_ABSTRACT #language en-US "Library containin= g helper functions for marshalling and registering new policies with the Va= riablePolicy infrastructure" + +#string STR_MODULE_DESCRIPTION #language en-US "Library containin= g helper functions for marshalling and registering new policies with the Va= riablePolicy infrastructure" diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec index 31339741b840..2db37bd8ea9e 100644 --- a/MdeModulePkg/MdeModulePkg.dec +++ b/MdeModulePkg/MdeModulePkg.dec @@ -149,6 +149,11 @@ [LibraryClasses] # DisplayUpdateProgressLib|Include/Library/DisplayUpdateProgressLib.h + ## @libraryclass This library contains helper functions for marshallin= g and + # registering new policies with the VariablePolicy infrastructure. + # + VariablePolicyHelperLib|Include/Library/VariablePolicyHelperLib.h + [Guids] ## MdeModule package token space guid # Include/Guid/MdeModulePkgTokenSpace.h diff --git a/MdeModulePkg/MdeModulePkg.dsc b/MdeModulePkg/MdeModulePkg.dsc index 14b6ed536962..37795b9e4f58 100644 --- a/MdeModulePkg/MdeModulePkg.dsc +++ b/MdeModulePkg/MdeModulePkg.dsc @@ -99,6 +99,7 @@ [LibraryClasses] BmpSupportLib|MdeModulePkg/Library/BaseBmpSupportLib/BaseBmpSupportLib.i= nf SafeIntLib|MdePkg/Library/BaseSafeIntLib/BaseSafeIntLib.inf DisplayUpdateProgressLib|MdeModulePkg/Library/DisplayUpdateProgressLibGr= aphics/DisplayUpdateProgressLibGraphics.inf + VariablePolicyHelperLib|MdeModulePkg/Library/VariablePolicyHelperLib/Var= iablePolicyHelperLib.inf [LibraryClasses.EBC.PEIM] IoLib|MdePkg/Library/PeiIoLibCpuIo/PeiIoLibCpuIo.inf @@ -225,6 +226,7 @@ [Components] MdeModulePkg/Library/UefiHiiServicesLib/UefiHiiServicesLib.inf MdeModulePkg/Library/BaseHobLibNull/BaseHobLibNull.inf MdeModulePkg/Library/BaseMemoryAllocationLibNull/BaseMemoryAllocationLib= Null.inf + MdeModulePkg/Library/VariablePolicyHelperLib/VariablePolicyHelperLib.inf MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridgeDxe.inf MdeModulePkg/Bus/Pci/PciSioSerialDxe/PciSioSerialDxe.inf -- 2.26.2.windows.1.8.g01c50adf56.20200515075929 -=3D-=3D-=3D-=3D-=3D-=3D Groups.io Links: You receive all messages sent to this group. View/Reply Online (#60645): https://nam06.safelinks.protection.outlook.com/= ?url=3Dhttps%3A%2F%2Fedk2.groups.io%2Fg%2Fdevel%2Fmessage%2F60645&data= =3D02%7C01%7CBret.Barkelew%40microsoft.com%7Cf4de67d242ec4517ab1c08d807a3dc= 74%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637267747648232766&sdat= a=3DlTgPFRVTGwLnCIehU8h2owdPPBpbaxJwHJK9URkZCGM%3D&reserved=3D0 Mute This Topic: https://nam06.safelinks.protection.outlook.com/?url=3Dhttp= s%3A%2F%2Fgroups.io%2Fmt%2F74646434%2F1822150&data=3D02%7C01%7CBret.Bar= kelew%40microsoft.com%7Cf4de67d242ec4517ab1c08d807a3dc74%7C72f988bf86f141af= 91ab2d7cd011db47%7C1%7C0%7C637267747648232766&sdata=3DGi2MEVRsoldxW%2FA= Bl7CTfV2s07wj5MvzCKVWbGR5fo0%3D&reserved=3D0 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://nam06.safelinks.protection.outlook.com/?url=3Dhttps%3A= %2F%2Fedk2.groups.io%2Fg%2Fdevel%2Funsub&data=3D02%7C01%7CBret.Barkelew= %40microsoft.com%7Cf4de67d242ec4517ab1c08d807a3dc74%7C72f988bf86f141af91ab2= d7cd011db47%7C1%7C0%7C637267747648232766&sdata=3D%2Bl6%2FLC0fMi3t5yz7Kd= UafNt1m1NcTXl0FNVjwYzRru0%3D&reserved=3D0 [brbarkel@microsoft.com] -=3D-=3D-=3D-=3D-=3D-=3D --_000_CY4PR21MB0743E345A95976B62EB00AEBEF9A0CY4PR21MB0743namp_ Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable
Bump. This specif= ic patch needs Reviews.

- Bret


From: devel@edk2.groups.io = <devel@edk2.groups.io> on behalf of Bret Barkelew via groups.io <b= ret=3Dcorthon.com@groups.io>
Sent: Tuesday, June 2, 2020 11:57 PM
To: devel@edk2.groups.io <devel@edk2.groups.io>
Cc: Jian J Wang <jian.j.wang@intel.com>; Hao A Wu <hao.a.wu= @intel.com>; liming.gao <liming.gao@intel.com>
Subject: [EXTERNAL] [edk2-devel] [PATCH v5 03/14] MdeModulePkg: Defi= ne the VariablePolicyHelperLib
 
https://nam06.safelinks.protection.outlook.com/?url=3Dh= ttps%3A%2F%2Fbugzilla.tianocore.org%2Fshow_bug.cgi%3Fid%3D2522&amp;data= =3D02%7C01%7CBret.Barkelew%40microsoft.com%7Cf4de67d242ec4517ab1c08d807a3dc= 74%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637267747648232766&amp;= sdata=3DErqHXizN7Q6ghP%2BPuivvQuQnhfYKMEMwWgitRbYMCmE%3D&amp;reserved= =3D0

VariablePolicy is an updated interface to
replace VarLock and VarCheckProtocol.

Add the VariablePolicyHelperLib library, containing
several functions to help with the repetitive process
of creating a correctly structured and packed
VariablePolicy entry.

Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Hao A Wu <hao.a.wu@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Bret Barkelew <brbarkel@microsoft.com>
Signed-off-by: Bret Barkelew <brbarkel@microsoft.com>
---
 MdeModulePkg/Library/VariablePolicyHelperLib/VariablePolicyHelperLib.= c   | 396 +++++++++++= +++++++++
 MdeModulePkg/Include/Library/VariablePolicyHelperLib.h  &nb= sp;            =     | 164 ++++++++
 MdeModulePkg/Library/VariablePolicyHelperLib/VariablePolicyHelperLib.= inf |  35 ++
 MdeModulePkg/Library/VariablePolicyHelperLib/VariablePolicyHelperLib.= uni |  12 +
 MdeModulePkg/MdeModulePkg.dec      &nbs= p;            &= nbsp;           &nbs= p;            | = ;  5 +
 MdeModulePkg/MdeModulePkg.dsc      &nbs= p;            &= nbsp;           &nbs= p;            | = ;  2 +
 6 files changed, 614 insertions(+)

diff --git a/MdeModulePkg/Library/VariablePolicyHelperLib/VariablePolicyHel= perLib.c b/MdeModulePkg/Library/VariablePolicyHelperLib/VariablePolicyHelpe= rLib.c
new file mode 100644
index 000000000000..0c9299c8b0e1
--- /dev/null
+++ b/MdeModulePkg/Library/VariablePolicyHelperLib/VariablePoli= cyHelperLib.c
@@ -0,0 +1,396 @@
+/** @file -- VariablePolicyHelperLib.c

+This library contains helper functions for marshalling and registering=

+new policies with the VariablePolicy infrastructure.

+

+This library is currently written against VariablePolicy revision 0x00= 010000.

+

+Copyright (c) Microsoft Corporation.

+SPDX-License-Identifier: BSD-2-Clause-Patent

+

+**/

+

+#include <Uefi.h>

+

+#include <Library/BaseLib.h>

+#include <Library/DebugLib.h>

+#include <Library/BaseMemoryLib.h>

+#include <Library/MemoryAllocationLib.h>

+

+#include <Protocol/VariablePolicy.h>

+

+/**

+  This internal helper function populates the header structure,
+  all common fields, and takes care of fix-ups.

+

+  NOTE: Only use this internally. Assumes correctly-sized buffers= .

+

+  @param[out] EntPtr      Pointer to the= buffer to be populated.

+  @param[in]  Namespace   Pointer to an EFI_GUID f= or the target variable namespace that this policy will protect.

+  @param[in]  MinSize     MinSize for th= e VariablePolicy.

+  @param[in]  MaxSize     MaxSize for th= e VariablePolicy.

+  @param[in]  AttributesMustHave    Attribute= sMustHave for the VariablePolicy.

+  @param[in]  AttributesCantHave    Attribute= sCantHave for the VariablePolicy.

+  @param[in]  LockPolicyType     &n= bsp;  LockPolicyType for the VariablePolicy.

+

+**/

+STATIC

+VOID

+PopulateCommonData (

+  OUT VARIABLE_POLICY_ENTRY   *EntPtr,

+  IN CONST  EFI_GUID      &nbs= p;   *Namespace,

+  IN        UINT32  =           MinSize,

+  IN        UINT32  =           MaxSize,

+  IN        UINT32  =           AttributesMustHave,<= br>
+  IN        UINT32  =           AttributesCantHave,<= br>
+  IN        UINT8  &= nbsp;          LockPolicyType<= br>
+  )

+{

+  EntPtr->Version       &nb= sp;     =3D VARIABLE_POLICY_ENTRY_REVISION;

+  CopyGuid( &EntPtr->Namespace, Namespace );

+  EntPtr->MinSize       &nb= sp;     =3D MinSize;

+  EntPtr->MaxSize       &nb= sp;     =3D MaxSize;

+  EntPtr->AttributesMustHave  =3D AttributesMustHave;

+  EntPtr->AttributesCantHave  =3D AttributesCantHave;

+  EntPtr->LockPolicyType      =3D Loc= kPolicyType;

+

+  // NOTE: As a heler, fix up MaxSize for compatibility with the = old model.

+  if (EntPtr->MaxSize =3D=3D 0) {

+    EntPtr->MaxSize =3D VARIABLE_POLICY_NO_MAX_SIZE;=

+  }

+

+  return;

+}

+

+

+/**

+  This helper function will allocate and populate a new VariableP= olicy

+  structure for a policy that does not contain any sub-structures= (such as

+  VARIABLE_LOCK_ON_VAR_STATE_POLICY).

+

+  NOTE: Caller will need to free structure once finished.

+

+  @param[in]  Namespace   Pointer to an EFI_GUID f= or the target variable namespace that this policy will protect.

+  @param[in]  Name       = [Optional] If provided, a pointer to the CHAR16 array for the target varia= ble name.

+           &nbs= p;            &= nbsp; Otherwise, will create a policy that targets an entire namespace.

+  @param[in]  MinSize     MinSize for th= e VariablePolicy.

+  @param[in]  MaxSize     MaxSize for th= e VariablePolicy.

+  @param[in]  AttributesMustHave    Attribute= sMustHave for the VariablePolicy.

+  @param[in]  AttributesCantHave    Attribute= sCantHave for the VariablePolicy.

+  @param[in]  LockPolicyType     &n= bsp;  LockPolicyType for the VariablePolicy.

+  @param[out] NewEntry    If successful, will be s= et to a pointer to the allocated buffer containing the

+           &nbs= p;            &= nbsp; new policy.

+

+  @retval     EFI_SUCCESS   &n= bsp;         Operation completed su= ccessfully and structure is populated.

+  @retval     EFI_INVALID_PARAMETER &nbs= p; Namespace is NULL.

+  @retval     EFI_INVALID_PARAMETER &nbs= p; LockPolicyType is invalid for a basic structure.

+  @retval     EFI_BUFFER_TOO_SMALL  = ;  Finished structure would not fit in UINT16 size.

+  @retval     EFI_OUT_OF_RESOURCES  = ;  Could not allocate sufficient space for structure.

+

+**/

+EFI_STATUS

+EFIAPI

+CreateBasicVariablePolicy (

+  IN CONST  EFI_GUID      &nbs= p;   *Namespace,

+  IN CONST  CHAR16       =      *Name OPTIONAL,

+  IN        UINT32  =           MinSize,

+  IN        UINT32  =           MaxSize,

+  IN        UINT32  =           AttributesMustHave,<= br>
+  IN        UINT32  =           AttributesCantHave,<= br>
+  IN        UINT8  &= nbsp;          LockPolicyType,=

+  OUT VARIABLE_POLICY_ENTRY   **NewEntry

+  )

+{

+  UINTN         &nbs= p;         TotalSize;

+  UINTN         &nbs= p;         NameSize;

+  VARIABLE_POLICY_ENTRY   *EntPtr;

+  CHAR16         &nb= sp;        *CopyName;

+

+  // Check some initial invalid parameters for this function.

+  if (Namespace =3D=3D NULL || NewEntry =3D=3D NULL) {

+    return EFI_INVALID_PARAMETER;

+  }

+  if (LockPolicyType !=3D VARIABLE_POLICY_TYPE_NO_LOCK &&=

+      LockPolicyType !=3D VARIABLE_POLICY_TYP= E_LOCK_NOW &&

+      LockPolicyType !=3D VARIABLE_POLICY_TYP= E_LOCK_ON_CREATE) {

+    return EFI_INVALID_PARAMETER;

+  }

+

+  // Now we've gotta determine the total size of the buffer requi= red for

+  // the VariablePolicy structure.

+  TotalSize =3D sizeof( VARIABLE_POLICY_ENTRY );

+  if (Name !=3D NULL) {

+    NameSize =3D StrnSizeS( Name, MAX_UINT16 );

+    TotalSize +=3D NameSize;

+  }

+  // Make sure the size fits within a VARIABLE_POLICY_ENTRY.Size.=

+  ASSERT( TotalSize <=3D MAX_UINT16 );

+  if (TotalSize > MAX_UINT16) {

+    return EFI_BUFFER_TOO_SMALL;

+  }

+

+  // Allocate a buffer to hold all the data. We're on the home st= retch.

+  *NewEntry =3D AllocatePool( TotalSize );

+  if (*NewEntry =3D=3D NULL) {

+    return EFI_OUT_OF_RESOURCES;

+  }

+

+  // If we're still here, we're basically done.

+  // Copy the data and GET... OUT....

+  EntPtr =3D *NewEntry;

+  PopulateCommonData ( EntPtr,

+           &nbs= p;           Namespace,
+           &nbs= p;           MinSize,

+           &nbs= p;           MaxSize,

+           &nbs= p;           AttributesMu= stHave,

+           &nbs= p;           AttributesCa= ntHave,

+           &nbs= p;           LockPolicyTy= pe );

+  EntPtr->Size        =         =3D (UINT16)TotalSize; &nbs= p;    // This is safe because we've already checked.

+  EntPtr->OffsetToName      &nbs= p; =3D sizeof(VARIABLE_POLICY_ENTRY);

+  if (Name !=3D NULL) {

+    CopyName =3D (CHAR16*)((UINT8*)EntPtr + EntPtr-= >OffsetToName);

+    CopyMem( CopyName, Name, NameSize );

+  }

+

+  return EFI_SUCCESS;

+}

+

+

+/**

+  This helper function will allocate and populate a new VariableP= olicy

+  structure for a policy with a lock type of VARIABLE_POLICY_TYPE= _LOCK_ON_VAR_STATE.

+

+  NOTE: Caller will need to free structure once finished.

+

+  @param[in]  Namespace   Pointer to an EFI_GUID f= or the target variable namespace that this policy will protect.

+  @param[in]  Name       = [Optional] If provided, a pointer to the CHAR16 array for the target varia= ble name.

+           &nbs= p;            &= nbsp; Otherwise, will create a policy that targets an entire namespace.

+  @param[in]  MinSize     MinSize for th= e VariablePolicy.

+  @param[in]  MaxSize     MaxSize for th= e VariablePolicy.

+  @param[in]  AttributesMustHave    Attribute= sMustHave for the VariablePolicy.

+  @param[in]  AttributesCantHave    Attribute= sCantHave for the VariablePolicy.

+  @param[in]  VarStateNamespace     Poin= ter to the EFI_GUID for the VARIABLE_LOCK_ON_VAR_STATE_POLICY.Namespace.
+  @param[in]  VarStateValue     &nb= sp;   Value for the VARIABLE_LOCK_ON_VAR_STATE_POLICY.Value.

+  @param[in]  VarStateName     &nbs= p;    Pointer to the CHAR16 array for the VARIABLE_LOCK_ON_V= AR_STATE_POLICY.Name.

+  @param[out] NewEntry    If successful, will be s= et to a pointer to the allocated buffer containing the

+           &nbs= p;            &= nbsp; new policy.

+

+  @retval     EFI_SUCCESS   &n= bsp;         Operation completed su= ccessfully and structure is populated.

+  @retval     EFI_INVALID_PARAMETER &nbs= p; Namespace, VarStateNamespace, VarStateName is NULL.

+  @retval     EFI_BUFFER_TOO_SMALL  = ;  Finished structure would not fit in UINT16 size.

+  @retval     EFI_OUT_OF_RESOURCES  = ;  Could not allocate sufficient space for structure.

+

+**/

+EFI_STATUS

+EFIAPI

+CreateVarStateVariablePolicy (

+  IN CONST  EFI_GUID      &nbs= p;   *Namespace,

+  IN CONST  CHAR16       =      *Name OPTIONAL,

+  IN        UINT32  =           MinSize,

+  IN        UINT32  =           MaxSize,

+  IN        UINT32  =           AttributesMustHave,<= br>
+  IN        UINT32  =           AttributesCantHave,<= br>
+  IN CONST  EFI_GUID      &nbs= p;   *VarStateNamespace,

+  IN        UINT8  &= nbsp;          VarStateValue,<= br>
+  IN CONST  CHAR16       =      *VarStateName,

+  OUT VARIABLE_POLICY_ENTRY   **NewEntry

+  )

+{

+  UINTN         &nbs= p;         TotalSize;

+  UINTN         &nbs= p;         NameSize;

+  UINTN         &nbs= p;         VarStateNameSize;

+  VARIABLE_POLICY_ENTRY   *EntPtr;

+  CHAR16         &nb= sp;        *CopyName;

+  VARIABLE_LOCK_ON_VAR_STATE_POLICY *CopyPolicy;

+

+  // Check some initial invalid parameters for this function.

+  if (Namespace =3D=3D NULL || VarStateNamespace =3D=3D NULL ||
+      VarStateName =3D=3D NULL || NewEntry = =3D=3D NULL) {

+    return EFI_INVALID_PARAMETER;

+  }

+

+  // Now we've gotta determine the total size of the buffer requi= red for

+  // the VariablePolicy structure.

+  VarStateNameSize =3D StrnSizeS( VarStateName, MAX_UINT16 );

+  TotalSize =3D sizeof( VARIABLE_POLICY_ENTRY ) +

+           &nbs= p;    sizeof(VARIABLE_LOCK_ON_VAR_STATE_POLICY) +

+           &nbs= p;    VarStateNameSize;

+  if (Name !=3D NULL) {

+    NameSize =3D StrnSizeS( Name, MAX_UINT16 );

+    TotalSize +=3D NameSize;

+  }

+  // Make sure the size fits within a VARIABLE_POLICY_ENTRY.Size.=

+  ASSERT( TotalSize <=3D MAX_UINT16 );

+  if (TotalSize > MAX_UINT16) {

+    return EFI_BUFFER_TOO_SMALL;

+  }

+

+  // Allocate a buffer to hold all the data. We're on the home st= retch.

+  *NewEntry =3D AllocatePool( TotalSize );

+  if (*NewEntry =3D=3D NULL) {

+    return EFI_OUT_OF_RESOURCES;

+  }

+

+  // If we're still here, we're basically done.

+  // Copy the data and GET... OUT....

+  EntPtr =3D *NewEntry;

+  PopulateCommonData ( EntPtr,

+           &nbs= p;           Namespace,
+           &nbs= p;           MinSize,

+           &nbs= p;           MaxSize,

+           &nbs= p;           AttributesMu= stHave,

+           &nbs= p;           AttributesCa= ntHave,

+           &nbs= p;           VARIABLE_POL= ICY_TYPE_LOCK_ON_VAR_STATE );

+  EntPtr->Size        =         =3D (UINT16)TotalSize; &nbs= p;    // This is safe because we've already checked.

+  EntPtr->OffsetToName      &nbs= p; =3D sizeof(VARIABLE_POLICY_ENTRY) +

+           &nbs= p;            &= nbsp;       sizeof(VARIABLE_LOCK_ON_VAR_STATE= _POLICY) +

+           &nbs= p;            &= nbsp;       (UINT16)VarStateNameSize;

+

+  CopyPolicy =3D (VARIABLE_LOCK_ON_VAR_STATE_POLICY*)((UINT8*)Ent= Ptr + sizeof(VARIABLE_POLICY_ENTRY));

+  CopyName =3D (CHAR16*)((UINT8*)CopyPolicy + sizeof(VARIABLE= _LOCK_ON_VAR_STATE_POLICY));

+  CopyGuid( &CopyPolicy->Namespace, VarStateNamespace );
+  CopyPolicy->Value =3D VarStateValue;

+  CopyMem( CopyName, VarStateName, VarStateNameSize );

+

+  if (Name !=3D NULL) {

+    CopyName =3D (CHAR16*)((UINT8*)EntPtr + EntPtr-= >OffsetToName);

+    CopyMem( CopyName, Name, NameSize );

+  }

+

+  return EFI_SUCCESS;

+}

+

+

+/**

+  This helper function does everything that CreateBasicVariablePo= licy() does, but also

+  uses the passed in protocol to register the policy with the inf= rastructure.

+  Does not return a buffer, does not require the caller to free a= nything.

+

+  @param[in]  VariablePolicy  Pointer to a valid instan= ce of the VariablePolicy protocol.

+  @param[in]  Namespace   Pointer to an EFI_GUID f= or the target variable namespace that this policy will protect.

+  @param[in]  Name       = [Optional] If provided, a pointer to the CHAR16 array for the target varia= ble name.

+           &nbs= p;            &= nbsp; Otherwise, will create a policy that targets an entire namespace.

+  @param[in]  MinSize     MinSize for th= e VariablePolicy.

+  @param[in]  MaxSize     MaxSize for th= e VariablePolicy.

+  @param[in]  AttributesMustHave    Attribute= sMustHave for the VariablePolicy.

+  @param[in]  AttributesCantHave    Attribute= sCantHave for the VariablePolicy.

+  @param[in]  LockPolicyType     &n= bsp;  LockPolicyType for the VariablePolicy.

+

+  @retval     EFI_INVALID_PARAMETER VariableP= olicy pointer is NULL.

+  @retval     EFI_STATUS   &nb= sp;        Status returned by CreateBasi= cVariablePolicy() or RegisterVariablePolicy().

+

+**/

+EFI_STATUS

+EFIAPI

+RegisterBasicVariablePolicy (

+  IN        EDKII_VARIABLE_POL= ICY_PROTOCOL  *VariablePolicy,

+  IN CONST  EFI_GUID      &nbs= p;            &= nbsp;    *Namespace,

+  IN CONST  CHAR16       =             &nb= sp;      *Name OPTIONAL,

+  IN        UINT32  =             &nb= sp;           MinSize,
+  IN        UINT32  =             &nb= sp;           MaxSize,
+  IN        UINT32  =             &nb= sp;           AttributesM= ustHave,

+  IN        UINT32  =             &nb= sp;           AttributesC= antHave,

+  IN        UINT8  &= nbsp;           &nbs= p;            LockPo= licyType

+  )

+{

+  VARIABLE_POLICY_ENTRY   *NewEntry;

+  EFI_STATUS         = ;     Status;

+

+  // Check the simple things.

+  if (VariablePolicy =3D=3D NULL) {

+    return EFI_INVALID_PARAMETER;

+  }

+

+  // Create the new entry and make sure that everything worked.
+  NewEntry =3D NULL;

+  Status =3D CreateBasicVariablePolicy( Namespace,

+           &nbs= p;            &= nbsp;           &nbs= p; Name,

+           &nbs= p;            &= nbsp;           &nbs= p; MinSize,

+           &nbs= p;            &= nbsp;           &nbs= p; MaxSize,

+           &nbs= p;            &= nbsp;           &nbs= p; AttributesMustHave,

+           &nbs= p;            &= nbsp;           &nbs= p; AttributesCantHave,

+           &nbs= p;            &= nbsp;           &nbs= p; LockPolicyType,

+           &nbs= p;            &= nbsp;           &nbs= p; &NewEntry );

+

+  // If that was successful, attempt to register the new policy.<= br>
+  if (!EFI_ERROR( Status )) {

+    Status =3D VariablePolicy->RegisterVariablePolic= y( NewEntry );

+  }

+

+  // If we allocated the buffer, free the buffer.

+  if (NewEntry !=3D NULL) {

+    FreePool( NewEntry );

+  }

+

+  return Status;

+}

+

+

+/**

+  This helper function does everything that CreateBasicVariablePo= licy() does, but also

+  uses the passed in protocol to register the policy with the inf= rastructure.

+  Does not return a buffer, does not require the caller to free a= nything.

+

+  @param[in]  VariablePolicy  Pointer to a valid instan= ce of the VariablePolicy protocol.

+  @param[in]  Namespace   Pointer to an EFI_GUID f= or the target variable namespace that this policy will protect.

+  @param[in]  Name       = [Optional] If provided, a pointer to the CHAR16 array for the target varia= ble name.

+           &nbs= p;            &= nbsp; Otherwise, will create a policy that targets an entire namespace.

+  @param[in]  MinSize     MinSize for th= e VariablePolicy.

+  @param[in]  MaxSize     MaxSize for th= e VariablePolicy.

+  @param[in]  AttributesMustHave    Attribute= sMustHave for the VariablePolicy.

+  @param[in]  AttributesCantHave    Attribute= sCantHave for the VariablePolicy.

+  @param[in]  VarStateNamespace     Poin= ter to the EFI_GUID for the VARIABLE_LOCK_ON_VAR_STATE_POLICY.Namespace.
+  @param[in]  VarStateName     &nbs= p;    Pointer to the CHAR16 array for the VARIABLE_LOCK_ON_V= AR_STATE_POLICY.Name.

+  @param[in]  VarStateValue     &nb= sp;   Value for the VARIABLE_LOCK_ON_VAR_STATE_POLICY.Value.

+

+  @retval     EFI_INVALID_PARAMETER VariableP= olicy pointer is NULL.

+  @retval     EFI_STATUS    St= atus returned by CreateBasicVariablePolicy() or RegisterVariablePolicy().
+

+**/

+EFI_STATUS

+EFIAPI

+RegisterVarStateVariablePolicy (

+  IN        EDKII_VARIABLE_POL= ICY_PROTOCOL  *VariablePolicy,

+  IN CONST  EFI_GUID      &nbs= p;            &= nbsp;    *Namespace,

+  IN CONST  CHAR16       =             &nb= sp;      *Name OPTIONAL,

+  IN        UINT32  =             &nb= sp;           MinSize,
+  IN        UINT32  =             &nb= sp;           MaxSize,
+  IN        UINT32  =             &nb= sp;           AttributesM= ustHave,

+  IN        UINT32  =             &nb= sp;           AttributesC= antHave,

+  IN CONST  EFI_GUID      &nbs= p;            &= nbsp;    *VarStateNamespace,

+  IN CONST  CHAR16       =             &nb= sp;      *VarStateName,

+  IN        UINT8  &= nbsp;           &nbs= p;            VarSta= teValue

+  )

+{

+  VARIABLE_POLICY_ENTRY   *NewEntry;

+  EFI_STATUS         = ;     Status;

+

+  // Check the simple things.

+  if (VariablePolicy =3D=3D NULL) {

+    return EFI_INVALID_PARAMETER;

+  }

+

+  // Create the new entry and make sure that everything worked.
+  NewEntry =3D NULL;

+  Status =3D CreateVarStateVariablePolicy( Namespace,

+           &nbs= p;            &= nbsp;           &nbs= p;    Name,

+           &nbs= p;            &= nbsp;           &nbs= p;    MinSize,

+           &nbs= p;            &= nbsp;           &nbs= p;    MaxSize,

+           &nbs= p;            &= nbsp;           &nbs= p;    AttributesMustHave,

+           &nbs= p;            &= nbsp;           &nbs= p;    AttributesCantHave,

+           &nbs= p;            &= nbsp;           &nbs= p;    VarStateNamespace,

+           &nbs= p;            &= nbsp;           &nbs= p;    VarStateValue,

+           &nbs= p;            &= nbsp;           &nbs= p;    VarStateName,

+           &nbs= p;            &= nbsp;           &nbs= p;    &NewEntry );

+

+  // If that was successful, attempt to register the new policy.<= br>
+  if (!EFI_ERROR( Status )) {

+    Status =3D VariablePolicy->RegisterVariablePolic= y( NewEntry );

+  }

+

+  // If we allocated the buffer, free the buffer.

+  if (NewEntry !=3D NULL) {

+    FreePool( NewEntry );

+  }

+

+  return Status;

+}

diff --git a/MdeModulePkg/Include/Library/VariablePolicyHelperLib.h b/MdeMo= dulePkg/Include/Library/VariablePolicyHelperLib.h
new file mode 100644
index 000000000000..3b75e9786094
--- /dev/null
+++ b/MdeModulePkg/Include/Library/VariablePolicyHelperLib.h @@ -0,0 +1,164 @@
+/** @file -- VariablePolicyHelperLib.h

+This library contains helper functions for marshalling and registering=

+new policies with the VariablePolicy infrastructure.

+

+Copyright (c) Microsoft Corporation.

+SPDX-License-Identifier: BSD-2-Clause-Patent

+

+**/

+

+#ifndef _EDKII_VARIABLE_POLICY_HELPER_LIB_H_

+#define _EDKII_VARIABLE_POLICY_HELPER_LIB_H_

+

+#include <Protocol/VariablePolicy.h>

+

+/**

+  This helper function will allocate and populate a new VariableP= olicy

+  structure for a policy that does not contain any sub-structures= (such as

+  VARIABLE_LOCK_ON_VAR_STATE_POLICY).

+

+  NOTE: Caller will need to free structure once finished.

+

+  @param[in]  Namespace   Pointer to an EFI_GUID f= or the target variable namespace that this policy will protect.

+  @param[in]  Name       = [Optional] If provided, a pointer to the CHAR16 array for the target varia= ble name.

+           &nbs= p;            &= nbsp; Otherwise, will create a policy that targets an entire namespace.

+  @param[in]  MinSize     MinSize for th= e VariablePolicy.

+  @param[in]  MaxSize     MaxSize for th= e VariablePolicy.

+  @param[in]  AttributesMustHave    Attribute= sMustHave for the VariablePolicy.

+  @param[in]  AttributesCantHave    Attribute= sCantHave for the VariablePolicy.

+  @param[in]  LockPolicyType     &n= bsp;  LockPolicyType for the VariablePolicy.

+  @param[out] NewEntry    If successful, will be s= et to a pointer to the allocated buffer containing the

+           &nbs= p;            &= nbsp; new policy.

+

+  @retval     EFI_SUCCESS   &n= bsp;         Operation completed su= ccessfully and structure is populated.

+  @retval     EFI_INVALID_PARAMETER &nbs= p; Namespace is NULL.

+  @retval     EFI_INVALID_PARAMETER &nbs= p; LockPolicyType is invalid for a basic structure.

+  @retval     EFI_BUFFER_TOO_SMALL  = ;  Finished structure would not fit in UINT16 size.

+  @retval     EFI_OUT_OF_RESOURCES  = ;  Could not allocate sufficient space for structure.

+

+**/

+EFI_STATUS

+EFIAPI

+CreateBasicVariablePolicy (

+  IN CONST  EFI_GUID      &nbs= p;   *Namespace,

+  IN CONST  CHAR16       =      *Name OPTIONAL,

+  IN        UINT32  =           MinSize,

+  IN        UINT32  =           MaxSize,

+  IN        UINT32  =           AttributesMustHave,<= br>
+  IN        UINT32  =           AttributesCantHave,<= br>
+  IN        UINT8  &= nbsp;          LockPolicyType,=

+  OUT VARIABLE_POLICY_ENTRY   **NewEntry

+  );

+

+

+/**

+  This helper function will allocate and populate a new VariableP= olicy

+  structure for a policy with a lock type of VARIABLE_POLICY_TYPE= _LOCK_ON_VAR_STATE.

+

+  NOTE: Caller will need to free structure once finished.

+

+  @param[in]  Namespace   Pointer to an EFI_GUID f= or the target variable namespace that this policy will protect.

+  @param[in]  Name       = [Optional] If provided, a pointer to the CHAR16 array for the target varia= ble name.

+           &nbs= p;            &= nbsp; Otherwise, will create a policy that targets an entire namespace.

+  @param[in]  MinSize     MinSize for th= e VariablePolicy.

+  @param[in]  MaxSize     MaxSize for th= e VariablePolicy.

+  @param[in]  AttributesMustHave    Attribute= sMustHave for the VariablePolicy.

+  @param[in]  AttributesCantHave    Attribute= sCantHave for the VariablePolicy.

+  @param[in]  VarStateNamespace     Poin= ter to the EFI_GUID for the VARIABLE_LOCK_ON_VAR_STATE_POLICY.Namespace.
+  @param[in]  VarStateValue     &nb= sp;   Value for the VARIABLE_LOCK_ON_VAR_STATE_POLICY.Value.

+  @param[in]  VarStateName     &nbs= p;    Pointer to the CHAR16 array for the VARIABLE_LOCK_ON_V= AR_STATE_POLICY.Name.

+  @param[out] NewEntry    If successful, will be s= et to a pointer to the allocated buffer containing the

+           &nbs= p;            &= nbsp; new policy.

+

+  @retval     EFI_SUCCESS   &n= bsp;         Operation completed su= ccessfully and structure is populated.

+  @retval     EFI_INVALID_PARAMETER &nbs= p; Namespace, VarStateNamespace, VarStateName is NULL.

+  @retval     EFI_BUFFER_TOO_SMALL  = ;  Finished structure would not fit in UINT16 size.

+  @retval     EFI_OUT_OF_RESOURCES  = ;  Could not allocate sufficient space for structure.

+

+**/

+EFI_STATUS

+EFIAPI

+CreateVarStateVariablePolicy (

+  IN CONST  EFI_GUID      &nbs= p;   *Namespace,

+  IN CONST  CHAR16       =      *Name OPTIONAL,

+  IN        UINT32  =           MinSize,

+  IN        UINT32  =           MaxSize,

+  IN        UINT32  =           AttributesMustHave,<= br>
+  IN        UINT32  =           AttributesCantHave,<= br>
+  IN CONST  EFI_GUID      &nbs= p;   *VarStateNamespace,

+  IN        UINT8  &= nbsp;          VarStateValue,<= br>
+  IN CONST  CHAR16       =      *VarStateName,

+  OUT VARIABLE_POLICY_ENTRY   **NewEntry

+  );

+

+

+/**

+  This helper function does everything that CreateBasicVariablePo= licy() does, but also

+  uses the passed in protocol to register the policy with the inf= rastructure.

+  Does not return a buffer, does not require the caller to free a= nything.

+

+  @param[in]  VariablePolicy  Pointer to a valid instan= ce of the VariablePolicy protocol.

+  @param[in]  Namespace   Pointer to an EFI_GUID f= or the target variable namespace that this policy will protect.

+  @param[in]  Name       = [Optional] If provided, a pointer to the CHAR16 array for the target varia= ble name.

+           &nbs= p;            &= nbsp; Otherwise, will create a policy that targets an entire namespace.

+  @param[in]  MinSize     MinSize for th= e VariablePolicy.

+  @param[in]  MaxSize     MaxSize for th= e VariablePolicy.

+  @param[in]  AttributesMustHave    Attribute= sMustHave for the VariablePolicy.

+  @param[in]  AttributesCantHave    Attribute= sCantHave for the VariablePolicy.

+  @param[in]  LockPolicyType     &n= bsp;  LockPolicyType for the VariablePolicy.

+

+  @retval     EFI_INVALID_PARAMETER VariableP= olicy pointer is NULL.

+  @retval     EFI_STATUS   &nb= sp;        Status returned by CreateBasi= cVariablePolicy() or RegisterVariablePolicy().

+

+**/

+EFI_STATUS

+EFIAPI

+RegisterBasicVariablePolicy (

+  IN        EDKII_VARIABLE_POL= ICY_PROTOCOL  *VariablePolicy,

+  IN CONST  EFI_GUID      &nbs= p;            &= nbsp;    *Namespace,

+  IN CONST  CHAR16       =             &nb= sp;      *Name OPTIONAL,

+  IN        UINT32  =             &nb= sp;           MinSize,
+  IN        UINT32  =             &nb= sp;           MaxSize,
+  IN        UINT32  =             &nb= sp;           AttributesM= ustHave,

+  IN        UINT32  =             &nb= sp;           AttributesC= antHave,

+  IN        UINT8  &= nbsp;           &nbs= p;            LockPo= licyType

+  );

+

+

+/**

+  This helper function does everything that CreateBasicVariablePo= licy() does, but also

+  uses the passed in protocol to register the policy with the inf= rastructure.

+  Does not return a buffer, does not require the caller to free a= nything.

+

+  @param[in]  VariablePolicy  Pointer to a valid instan= ce of the VariablePolicy protocol.

+  @param[in]  Namespace   Pointer to an EFI_GUID f= or the target variable namespace that this policy will protect.

+  @param[in]  Name       = [Optional] If provided, a pointer to the CHAR16 array for the target varia= ble name.

+           &nbs= p;            &= nbsp; Otherwise, will create a policy that targets an entire namespace.

+  @param[in]  MinSize     MinSize for th= e VariablePolicy.

+  @param[in]  MaxSize     MaxSize for th= e VariablePolicy.

+  @param[in]  AttributesMustHave    Attribute= sMustHave for the VariablePolicy.

+  @param[in]  AttributesCantHave    Attribute= sCantHave for the VariablePolicy.

+  @param[in]  VarStateNamespace     Poin= ter to the EFI_GUID for the VARIABLE_LOCK_ON_VAR_STATE_POLICY.Namespace.
+  @param[in]  VarStateName     &nbs= p;    Pointer to the CHAR16 array for the VARIABLE_LOCK_ON_V= AR_STATE_POLICY.Name.

+  @param[in]  VarStateValue     &nb= sp;   Value for the VARIABLE_LOCK_ON_VAR_STATE_POLICY.Value.

+

+  @retval     EFI_INVALID_PARAMETER VariableP= olicy pointer is NULL.

+  @retval     EFI_STATUS    St= atus returned by CreateBasicVariablePolicy() or RegisterVariablePolicy().
+

+**/

+EFI_STATUS

+EFIAPI

+RegisterVarStateVariablePolicy (

+  IN        EDKII_VARIABLE_POL= ICY_PROTOCOL  *VariablePolicy,

+  IN CONST  EFI_GUID      &nbs= p;            &= nbsp;    *Namespace,

+  IN CONST  CHAR16       =             &nb= sp;      *Name OPTIONAL,

+  IN        UINT32  =             &nb= sp;           MinSize,
+  IN        UINT32  =             &nb= sp;           MaxSize,
+  IN        UINT32  =             &nb= sp;           AttributesM= ustHave,

+  IN        UINT32  =             &nb= sp;           AttributesC= antHave,

+  IN CONST  EFI_GUID      &nbs= p;            &= nbsp;    *VarStateNamespace,

+  IN CONST  CHAR16       =             &nb= sp;      *VarStateName,

+  IN        UINT8  &= nbsp;           &nbs= p;            VarSta= teValue

+  );

+

+#endif // _EDKII_VARIABLE_POLICY_HELPER_LIB_H_

diff --git a/MdeModulePkg/Library/VariablePolicyHelperLib/VariablePolicyHel= perLib.inf b/MdeModulePkg/Library/VariablePolicyHelperLib/VariablePolicyHel= perLib.inf
new file mode 100644
index 000000000000..506abf580e94
--- /dev/null
+++ b/MdeModulePkg/Library/VariablePolicyHelperLib/VariablePoli= cyHelperLib.inf
@@ -0,0 +1,35 @@
+## @file VariablePolicyHelperLib.inf

+# This library contains helper functions for marshalling and registeri= ng

+# new policies with the VariablePolicy infrastructure.

+#

+# This library is currently written against VariablePolicy revision 0x= 00010000.

+#

+# Copyright (c) Microsoft Corporation.

+# SPDX-License-Identifier: BSD-2-Clause-Patent

+##

+

+

+[Defines]

+  INF_VERSION         =3D= 0x00010017

+  BASE_NAME         =   =3D VariablePolicyHelperLib

+  # MODULE_UNI_FILE   =3D VariablePolicyHelperLib.uni
+  FILE_GUID         =   =3D B3C2206B-FDD1-4AED-8352-FC5EC34C5630

+  VERSION_STRING      =3D 1.0

+  MODULE_TYPE         =3D= BASE

+  LIBRARY_CLASS       =3D VariableP= olicyHelperLib

+

+

+[Sources]

+  VariablePolicyHelperLib.c

+

+

+[Packages]

+  MdePkg/MdePkg.dec

+  MdeModulePkg/MdeModulePkg.dec

+

+

+[LibraryClasses]

+  BaseLib

+  DebugLib

+  MemoryAllocationLib

+  BaseMemoryLib

diff --git a/MdeModulePkg/Library/VariablePolicyHelperLib/VariablePolicyHel= perLib.uni b/MdeModulePkg/Library/VariablePolicyHelperLib/VariablePolicyHel= perLib.uni
new file mode 100644
index 000000000000..39cbf11a4ce9
--- /dev/null
+++ b/MdeModulePkg/Library/VariablePolicyHelperLib/VariablePoli= cyHelperLib.uni
@@ -0,0 +1,12 @@
+// /** @file

+// VariablePolicyHelperLib.uni

+//

+// Copyright (c) Microsoft Corporation.

+// SPDX-License-Identifier: BSD-2-Clause-Patent

+//

+// **/

+

+

+#string STR_MODULE_ABSTRACT       &= nbsp;     #language en-US "Library containing help= er functions for marshalling and registering new policies with the Variable= Policy infrastructure"

+

+#string STR_MODULE_DESCRIPTION      &nbs= p;   #language en-US "Library containing helper functions fo= r marshalling and registering new policies with the VariablePolicy infrastr= ucture"

diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec<= br> index 31339741b840..2db37bd8ea9e 100644
--- a/MdeModulePkg/MdeModulePkg.dec
+++ b/MdeModulePkg/MdeModulePkg.dec
@@ -149,6 +149,11 @@ [LibraryClasses]
   #

   DisplayUpdateProgressLib|Include/Library/DisplayUpdateProgress= Lib.h

 

+  ##  @libraryclass  This library contains helper funct= ions for marshalling and

+  #   registering new policies with the VariablePolicy = infrastructure.

+  #

+  VariablePolicyHelperLib|Include/Library/VariablePolicyHelperLib= .h

+

 [Guids]

   ## MdeModule package token space guid

   # Include/Guid/MdeModulePkgTokenSpace.h

diff --git a/MdeModulePkg/MdeModulePkg.dsc b/MdeModulePkg/MdeModulePkg.dsc<= br> index 14b6ed536962..37795b9e4f58 100644
--- a/MdeModulePkg/MdeModulePkg.dsc
+++ b/MdeModulePkg/MdeModulePkg.dsc
@@ -99,6 +99,7 @@ [LibraryClasses]
   BmpSupportLib|MdeModulePkg/Library/BaseBmpSupportLib/BaseBmpSu= pportLib.inf

   SafeIntLib|MdePkg/Library/BaseSafeIntLib/BaseSafeIntLib.inf
   DisplayUpdateProgressLib|MdeModulePkg/Library/DisplayUpdatePro= gressLibGraphics/DisplayUpdateProgressLibGraphics.inf

+  VariablePolicyHelperLib|MdeModulePkg/Library/VariablePolicyHelp= erLib/VariablePolicyHelperLib.inf

 

 [LibraryClasses.EBC.PEIM]

   IoLib|MdePkg/Library/PeiIoLibCpuIo/PeiIoLibCpuIo.inf

@@ -225,6 +226,7 @@ [Components]
   MdeModulePkg/Library/UefiHiiServicesLib/UefiHiiServicesLib.inf=

   MdeModulePkg/Library/BaseHobLibNull/BaseHobLibNull.inf

   MdeModulePkg/Library/BaseMemoryAllocationLibNull/BaseMemoryAll= ocationLibNull.inf

+  MdeModulePkg/Library/VariablePolicyHelperLib/VariablePolicyHelp= erLib.inf

 

   MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridgeDxe.inf

   MdeModulePkg/Bus/Pci/PciSioSerialDxe/PciSioSerialDxe.inf

--
2.26.2.windows.1.8.g01c50adf56.20200515075929


-=3D-=3D-=3D-=3D-=3D-=3D
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#60645): https://nam06.safelinks.protection.outlook.com/?url=3Dhttps%3A%2F%2Fedk2.gr= oups.io%2Fg%2Fdevel%2Fmessage%2F60645&amp;data=3D02%7C01%7CBret.Barkele= w%40microsoft.com%7Cf4de67d242ec4517ab1c08d807a3dc74%7C72f988bf86f141af91ab= 2d7cd011db47%7C1%7C0%7C637267747648232766&amp;sdata=3DlTgPFRVTGwLnCIehU= 8h2owdPPBpbaxJwHJK9URkZCGM%3D&amp;reserved=3D0
Mute This Topic: https://nam06.safelinks.protection.outlook.com/?url=3Dhttps%3A%2F%2Fgroups.= io%2Fmt%2F74646434%2F1822150&amp;data=3D02%7C01%7CBret.Barkelew%40micro= soft.com%7Cf4de67d242ec4517ab1c08d807a3dc74%7C72f988bf86f141af91ab2d7cd011d= b47%7C1%7C0%7C637267747648232766&amp;sdata=3DGi2MEVRsoldxW%2FABl7CTfV2s= 07wj5MvzCKVWbGR5fo0%3D&amp;reserved=3D0
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://nam06.safelinks.protection.outlook.com/?url=3Dhttps%3A%2F%2Fedk2.gr= oups.io%2Fg%2Fdevel%2Funsub&amp;data=3D02%7C01%7CBret.Barkelew%40micros= oft.com%7Cf4de67d242ec4517ab1c08d807a3dc74%7C72f988bf86f141af91ab2d7cd011db= 47%7C1%7C0%7C637267747648232766&amp;sdata=3D%2Bl6%2FLC0fMi3t5yz7KdUafNt= 1m1NcTXl0FNVjwYzRru0%3D&amp;reserved=3D0  [brbarkel@microsoft.com]
-=3D-=3D-=3D-=3D-=3D-=3D

--_000_CY4PR21MB0743E345A95976B62EB00AEBEF9A0CY4PR21MB0743namp_--