summaryrefslogtreecommitdiff
path: root/MdeModulePkg/Library/VariablePolicyHelperLib/VariablePolicyHelperLib.c
diff options
context:
space:
mode:
Diffstat (limited to 'MdeModulePkg/Library/VariablePolicyHelperLib/VariablePolicyHelperLib.c')
-rw-r--r--MdeModulePkg/Library/VariablePolicyHelperLib/VariablePolicyHelperLib.c251
1 files changed, 130 insertions, 121 deletions
diff --git a/MdeModulePkg/Library/VariablePolicyHelperLib/VariablePolicyHelperLib.c b/MdeModulePkg/Library/VariablePolicyHelperLib/VariablePolicyHelperLib.c
index 6bcb952..e82e91f 100644
--- a/MdeModulePkg/Library/VariablePolicyHelperLib/VariablePolicyHelperLib.c
+++ b/MdeModulePkg/Library/VariablePolicyHelperLib/VariablePolicyHelperLib.c
@@ -36,22 +36,22 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
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
+ 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 = VARIABLE_POLICY_ENTRY_REVISION;
- CopyGuid( &EntPtr->Namespace, Namespace );
- EntPtr->MinSize = MinSize;
- EntPtr->MaxSize = MaxSize;
- EntPtr->AttributesMustHave = AttributesMustHave;
- EntPtr->AttributesCantHave = AttributesCantHave;
- EntPtr->LockPolicyType = LockPolicyType;
+ EntPtr->Version = VARIABLE_POLICY_ENTRY_REVISION;
+ CopyGuid (&EntPtr->Namespace, Namespace);
+ EntPtr->MinSize = MinSize;
+ EntPtr->MaxSize = MaxSize;
+ EntPtr->AttributesMustHave = AttributesMustHave;
+ EntPtr->AttributesCantHave = AttributesCantHave;
+ EntPtr->LockPolicyType = LockPolicyType;
// NOTE: As a heler, fix up MaxSize for compatibility with the old model.
if (EntPtr->MaxSize == 0) {
@@ -61,7 +61,6 @@ PopulateCommonData (
return;
}
-
/**
This helper function will allocate and populate a new VariablePolicy
structure for a policy that does not contain any sub-structures (such as
@@ -90,51 +89,54 @@ PopulateCommonData (
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
+ 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;
+ UINTN TotalSize;
+ UINTN NameSize;
+ VARIABLE_POLICY_ENTRY *EntPtr;
+ CHAR16 *CopyName;
// Check some initial invalid parameters for this function.
- if (Namespace == NULL || NewEntry == NULL) {
+ if ((Namespace == NULL) || (NewEntry == NULL)) {
return EFI_INVALID_PARAMETER;
}
- if (LockPolicyType != VARIABLE_POLICY_TYPE_NO_LOCK &&
- LockPolicyType != VARIABLE_POLICY_TYPE_LOCK_NOW &&
- LockPolicyType != VARIABLE_POLICY_TYPE_LOCK_ON_CREATE) {
+
+ if ((LockPolicyType != VARIABLE_POLICY_TYPE_NO_LOCK) &&
+ (LockPolicyType != VARIABLE_POLICY_TYPE_LOCK_NOW) &&
+ (LockPolicyType != VARIABLE_POLICY_TYPE_LOCK_ON_CREATE))
+ {
return EFI_INVALID_PARAMETER;
}
//
// Set NameSize to suppress incorrect compiler/analyzer warnings
//
- NameSize = 0;
+ NameSize = 0;
// Now we've gotta determine the total size of the buffer required for
// the VariablePolicy structure.
- TotalSize = sizeof( VARIABLE_POLICY_ENTRY );
+ TotalSize = sizeof (VARIABLE_POLICY_ENTRY);
if (Name != NULL) {
- NameSize = StrnSizeS( Name, MAX_UINT16 );
+ NameSize = StrnSizeS (Name, MAX_UINT16);
TotalSize += NameSize;
}
+
// Make sure the size fits within a VARIABLE_POLICY_ENTRY.Size.
- ASSERT( TotalSize <= MAX_UINT16 );
+ ASSERT (TotalSize <= 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 = AllocatePool( TotalSize );
+ *NewEntry = AllocatePool (TotalSize);
if (*NewEntry == NULL) {
return EFI_OUT_OF_RESOURCES;
}
@@ -142,24 +144,25 @@ CreateBasicVariablePolicy (
// If we're still here, we're basically done.
// Copy the data and GET... OUT....
EntPtr = *NewEntry;
- PopulateCommonData ( EntPtr,
- Namespace,
- MinSize,
- MaxSize,
- AttributesMustHave,
- AttributesCantHave,
- LockPolicyType );
- EntPtr->Size = (UINT16)TotalSize; // This is safe because we've already checked.
- EntPtr->OffsetToName = sizeof(VARIABLE_POLICY_ENTRY);
+ PopulateCommonData (
+ EntPtr,
+ Namespace,
+ MinSize,
+ MaxSize,
+ AttributesMustHave,
+ AttributesCantHave,
+ LockPolicyType
+ );
+ EntPtr->Size = (UINT16)TotalSize; // This is safe because we've already checked.
+ EntPtr->OffsetToName = sizeof (VARIABLE_POLICY_ENTRY);
if (Name != NULL) {
- CopyName = (CHAR16*)((UINT8*)EntPtr + EntPtr->OffsetToName);
- CopyMem( CopyName, Name, NameSize );
+ CopyName = (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.
@@ -188,49 +191,51 @@ CreateBasicVariablePolicy (
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
+ 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;
+ 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 == NULL || VarStateNamespace == NULL ||
- VarStateName == NULL || NewEntry == NULL) {
+ if ((Namespace == NULL) || (VarStateNamespace == NULL) ||
+ (VarStateName == NULL) || (NewEntry == NULL))
+ {
return EFI_INVALID_PARAMETER;
}
// Now we've gotta determine the total size of the buffer required for
// the VariablePolicy structure.
- VarStateNameSize = StrnSizeS( VarStateName, MAX_UINT16 );
- TotalSize = sizeof( VARIABLE_POLICY_ENTRY ) +
- sizeof(VARIABLE_LOCK_ON_VAR_STATE_POLICY) +
- VarStateNameSize;
+ VarStateNameSize = StrnSizeS (VarStateName, MAX_UINT16);
+ TotalSize = sizeof (VARIABLE_POLICY_ENTRY) +
+ sizeof (VARIABLE_LOCK_ON_VAR_STATE_POLICY) +
+ VarStateNameSize;
if (Name != NULL) {
- NameSize = StrnSizeS( Name, MAX_UINT16 );
+ NameSize = StrnSizeS (Name, MAX_UINT16);
TotalSize += NameSize;
}
+
// Make sure the size fits within a VARIABLE_POLICY_ENTRY.Size.
- ASSERT( TotalSize <= MAX_UINT16 );
+ ASSERT (TotalSize <= 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 = AllocatePool( TotalSize );
+ *NewEntry = AllocatePool (TotalSize);
if (*NewEntry == NULL) {
return EFI_OUT_OF_RESOURCES;
}
@@ -238,33 +243,34 @@ CreateVarStateVariablePolicy (
// If we're still here, we're basically done.
// Copy the data and GET... OUT....
EntPtr = *NewEntry;
- PopulateCommonData ( EntPtr,
- Namespace,
- MinSize,
- MaxSize,
- AttributesMustHave,
- AttributesCantHave,
- VARIABLE_POLICY_TYPE_LOCK_ON_VAR_STATE );
- EntPtr->Size = (UINT16)TotalSize; // This is safe because we've already checked.
- EntPtr->OffsetToName = sizeof(VARIABLE_POLICY_ENTRY) +
- sizeof(VARIABLE_LOCK_ON_VAR_STATE_POLICY) +
- (UINT16)VarStateNameSize;
-
- CopyPolicy = (VARIABLE_LOCK_ON_VAR_STATE_POLICY*)((UINT8*)EntPtr + sizeof(VARIABLE_POLICY_ENTRY));
- CopyName = (CHAR16*)((UINT8*)CopyPolicy + sizeof(VARIABLE_LOCK_ON_VAR_STATE_POLICY));
- CopyGuid( &CopyPolicy->Namespace, VarStateNamespace );
+ PopulateCommonData (
+ EntPtr,
+ Namespace,
+ MinSize,
+ MaxSize,
+ AttributesMustHave,
+ AttributesCantHave,
+ VARIABLE_POLICY_TYPE_LOCK_ON_VAR_STATE
+ );
+ EntPtr->Size = (UINT16)TotalSize; // This is safe because we've already checked.
+ EntPtr->OffsetToName = sizeof (VARIABLE_POLICY_ENTRY) +
+ sizeof (VARIABLE_LOCK_ON_VAR_STATE_POLICY) +
+ (UINT16)VarStateNameSize;
+
+ CopyPolicy = (VARIABLE_LOCK_ON_VAR_STATE_POLICY *)((UINT8 *)EntPtr + sizeof (VARIABLE_POLICY_ENTRY));
+ CopyName = (CHAR16 *)((UINT8 *)CopyPolicy + sizeof (VARIABLE_LOCK_ON_VAR_STATE_POLICY));
+ CopyGuid (&CopyPolicy->Namespace, VarStateNamespace);
CopyPolicy->Value = VarStateValue;
- CopyMem( CopyName, VarStateName, VarStateNameSize );
+ CopyMem (CopyName, VarStateName, VarStateNameSize);
if (Name != NULL) {
- CopyName = (CHAR16*)((UINT8*)EntPtr + EntPtr->OffsetToName);
- CopyMem( CopyName, Name, NameSize );
+ CopyName = (CHAR16 *)((UINT8 *)EntPtr + EntPtr->OffsetToName);
+ CopyMem (CopyName, Name, NameSize);
}
return EFI_SUCCESS;
}
-
/**
This helper function does everything that CreateBasicVariablePolicy() does, but also
uses the passed in protocol to register the policy with the infrastructure.
@@ -297,8 +303,8 @@ RegisterBasicVariablePolicy (
IN UINT8 LockPolicyType
)
{
- VARIABLE_POLICY_ENTRY *NewEntry;
- EFI_STATUS Status;
+ VARIABLE_POLICY_ENTRY *NewEntry;
+ EFI_STATUS Status;
// Check the simple things.
if (VariablePolicy == NULL) {
@@ -307,29 +313,30 @@ RegisterBasicVariablePolicy (
// Create the new entry and make sure that everything worked.
NewEntry = NULL;
- Status = CreateBasicVariablePolicy( Namespace,
- Name,
- MinSize,
- MaxSize,
- AttributesMustHave,
- AttributesCantHave,
- LockPolicyType,
- &NewEntry );
+ Status = CreateBasicVariablePolicy (
+ Namespace,
+ Name,
+ MinSize,
+ MaxSize,
+ AttributesMustHave,
+ AttributesCantHave,
+ LockPolicyType,
+ &NewEntry
+ );
// If that was successful, attempt to register the new policy.
- if (!EFI_ERROR( Status )) {
- Status = VariablePolicy->RegisterVariablePolicy( NewEntry );
+ if (!EFI_ERROR (Status)) {
+ Status = VariablePolicy->RegisterVariablePolicy (NewEntry);
}
// If we allocated the buffer, free the buffer.
if (NewEntry != NULL) {
- FreePool( NewEntry );
+ FreePool (NewEntry);
}
return Status;
}
-
/**
This helper function does everything that CreateBasicVariablePolicy() does, but also
uses the passed in protocol to register the policy with the infrastructure.
@@ -366,8 +373,8 @@ RegisterVarStateVariablePolicy (
IN UINT8 VarStateValue
)
{
- VARIABLE_POLICY_ENTRY *NewEntry;
- EFI_STATUS Status;
+ VARIABLE_POLICY_ENTRY *NewEntry;
+ EFI_STATUS Status;
// Check the simple things.
if (VariablePolicy == NULL) {
@@ -376,25 +383,27 @@ RegisterVarStateVariablePolicy (
// Create the new entry and make sure that everything worked.
NewEntry = NULL;
- Status = CreateVarStateVariablePolicy( Namespace,
- Name,
- MinSize,
- MaxSize,
- AttributesMustHave,
- AttributesCantHave,
- VarStateNamespace,
- VarStateValue,
- VarStateName,
- &NewEntry );
+ Status = 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 = VariablePolicy->RegisterVariablePolicy( NewEntry );
+ if (!EFI_ERROR (Status)) {
+ Status = VariablePolicy->RegisterVariablePolicy (NewEntry);
}
// If we allocated the buffer, free the buffer.
if (NewEntry != NULL) {
- FreePool( NewEntry );
+ FreePool (NewEntry);
}
return Status;