diff options
-rw-r--r-- | IntelFrameworkModulePkg/Universal/VariablePei/Variable.c | 220 | ||||
-rw-r--r-- | IntelFrameworkModulePkg/Universal/VariablePei/Variable.h | 21 | ||||
-rw-r--r-- | MdeModulePkg/Include/VariableFormat.h | 4 | ||||
-rw-r--r-- | MdeModulePkg/Universal/Variable/Pei/Variable.c | 177 | ||||
-rw-r--r-- | MdeModulePkg/Universal/Variable/Pei/Variable.h | 21 | ||||
-rw-r--r-- | MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c | 140 | ||||
-rw-r--r-- | MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.h | 18 |
7 files changed, 490 insertions, 111 deletions
diff --git a/IntelFrameworkModulePkg/Universal/VariablePei/Variable.c b/IntelFrameworkModulePkg/Universal/VariablePei/Variable.c index 3751845fbf..72d8fd1252 100644 --- a/IntelFrameworkModulePkg/Universal/VariablePei/Variable.c +++ b/IntelFrameworkModulePkg/Universal/VariablePei/Variable.c @@ -80,27 +80,56 @@ Returns: }
-STATIC
VARIABLE_HEADER *
-GetNextVariablePtr (
- IN VARIABLE_HEADER *Variable
+GetStartPointer (
+ IN VARIABLE_STORE_HEADER *VarStoreHeader
)
/*++
Routine Description:
- This code checks if variable header is valid or not.
+ This code gets the pointer to the first variable memory pointer byte
Arguments:
- Variable Pointer to the Variable Header.
+
+ VarStoreHeader Pointer to the Variable Store Header.
Returns:
- TRUE Variable header is valid.
- FALSE Variable header is not valid.
+
+ VARIABLE_HEADER* Pointer to last unavailable Variable Header
+
+--*/
+{
+ //
+ // The end of variable store
+ //
+ return (VARIABLE_HEADER *) HEADER_ALIGN (VarStoreHeader + 1);
+}
+
+VARIABLE_HEADER *
+GetEndPointer (
+ IN VARIABLE_STORE_HEADER *VarStoreHeader
+ )
+/*++
+
+Routine Description:
+
+ This code gets the pointer to the last variable memory pointer byte
+
+Arguments:
+
+ VarStoreHeader Pointer to the Variable Store Header.
+
+Returns:
+
+ VARIABLE_HEADER* Pointer to last unavailable Variable Header
--*/
{
- return (VARIABLE_HEADER *) HEADER_ALIGN ((UINTN) GET_VARIABLE_DATA_PTR (Variable) + DATASIZE_OF_VARIABLE (Variable) + GET_PAD_SIZE (DATASIZE_OF_VARIABLE (Variable)));
+ //
+ // The end of variable store
+ //
+ return (VARIABLE_HEADER *) HEADER_ALIGN ((UINTN) VarStoreHeader + VarStoreHeader->Size);
}
STATIC
@@ -131,6 +160,159 @@ Returns: return TRUE;
}
+
+UINTN
+NameSizeOfVariable (
+ IN VARIABLE_HEADER *Variable
+ )
+/*++
+
+Routine Description:
+
+ This code gets the size of name of variable.
+
+Arguments:
+
+ Variable Pointer to the Variable Header.
+
+Returns:
+
+ UINTN Size of variable in bytes
+
+--*/
+{
+ if (Variable->State == (UINT8) (-1) ||
+ Variable->DataSize == (UINT32) -1 ||
+ Variable->NameSize == (UINT32) -1 ||
+ Variable->Attributes == (UINT32) -1) {
+ return 0;
+ }
+ return (UINTN) Variable->NameSize;
+}
+
+UINTN
+DataSizeOfVariable (
+ IN VARIABLE_HEADER *Variable
+ )
+/*++
+
+Routine Description:
+
+ This code gets the size of name of variable.
+
+Arguments:
+
+ Variable Pointer to the Variable Header.
+
+Returns:
+
+ UINTN Size of variable in bytes
+
+--*/
+{
+ if (Variable->State == (UINT8) -1 ||
+ Variable->DataSize == (UINT32) -1 ||
+ Variable->NameSize == (UINT32) -1 ||
+ Variable->Attributes == (UINT32) -1) {
+ return 0;
+ }
+ return (UINTN) Variable->DataSize;
+}
+
+CHAR16 *
+GetVariableNamePtr (
+ IN VARIABLE_HEADER *Variable
+ )
+/*++
+
+Routine Description:
+
+ This code gets the pointer to the variable name.
+
+Arguments:
+
+ Variable Pointer to the Variable Header.
+
+Returns:
+
+ CHAR16* Pointer to Variable Name
+
+--*/
+{
+
+ return (CHAR16 *) (Variable + 1);
+}
+
+
+UINT8 *
+GetVariableDataPtr (
+ IN VARIABLE_HEADER *Variable
+ )
+/*++
+
+Routine Description:
+
+ This code gets the pointer to the variable data.
+
+Arguments:
+
+ Variable Pointer to the Variable Header.
+
+Returns:
+
+ UINT8* Pointer to Variable Data
+
+--*/
+{
+ UINTN Value;
+
+ //
+ // Be careful about pad size for alignment
+ //
+ Value = (UINTN) GetVariableNamePtr (Variable);
+ Value += NameSizeOfVariable (Variable);
+ Value += GET_PAD_SIZE (NameSizeOfVariable (Variable));
+
+ return (UINT8 *) Value;
+}
+
+VARIABLE_HEADER *
+GetNextVariablePtr (
+ IN VARIABLE_HEADER *Variable
+ )
+/*++
+
+Routine Description:
+
+ This code gets the pointer to the next variable header.
+
+Arguments:
+
+ Variable Pointer to the Variable Header.
+
+Returns:
+
+ VARIABLE_HEADER* Pointer to next variable header.
+
+--*/
+{
+ UINTN Value;
+
+ if (!IsValidVariableHeader (Variable)) {
+ return NULL;
+ }
+
+ Value = (UINTN) GetVariableDataPtr (Variable);
+ Value += DataSizeOfVariable (Variable);
+ Value += GET_PAD_SIZE (DataSizeOfVariable (Variable));
+
+ //
+ // Be careful about pad size for alignment
+ //
+ return (VARIABLE_HEADER *) HEADER_ALIGN (Value);
+}
+
+
STATIC
VARIABLE_STORE_STATUS
EFIAPI
@@ -204,6 +386,8 @@ Returns: --*/
{
+ VOID *Point;
+
if (VariableName[0] == 0) {
PtrTrack->CurrPtr = Variable;
return EFI_SUCCESS;
@@ -218,8 +402,9 @@ Returns: (((INT32 *) VendorGuid)[2] == ((INT32 *) &Variable->VendorGuid)[2]) &&
(((INT32 *) VendorGuid)[3] == ((INT32 *) &Variable->VendorGuid)[3])
) {
- ASSERT (NAMESIZE_OF_VARIABLE (Variable) != 0);
- if (!CompareMem (VariableName, GET_VARIABLE_NAME_PTR (Variable), NAMESIZE_OF_VARIABLE (Variable))) {
+ ASSERT (NameSizeOfVariable (Variable) != 0);
+ Point = (VOID *) GetVariableNamePtr (Variable);
+ if (!CompareMem (VariableName, Point, NameSizeOfVariable (Variable))) {
PtrTrack->CurrPtr = Variable;
return EFI_SUCCESS;
}
@@ -288,6 +473,7 @@ Returns: for (Count = 0; Count < IndexTable->Length; Count++)
{
MaxIndex = GetVariableByIndex (IndexTable, Count);
+
if (CompareWithValidVariable (MaxIndex, VariableName, VendorGuid, PtrTrack) == EFI_SUCCESS) {
PtrTrack->StartPtr = IndexTable->StartPtr;
PtrTrack->EndPtr = IndexTable->EndPtr;
@@ -323,8 +509,8 @@ Returns: //
// Find the variable by walk through non-volatile variable store
//
- IndexTable->StartPtr = (VARIABLE_HEADER *) (VariableStoreHeader + 1);
- IndexTable->EndPtr = (VARIABLE_HEADER *) ((UINTN) VariableStoreHeader + VariableStoreHeader->Size);
+ IndexTable->StartPtr = GetStartPointer (VariableStoreHeader);
+ IndexTable->EndPtr = GetEndPointer (VariableStoreHeader);
//
// Start Pointers for the variable.
@@ -426,9 +612,9 @@ Returns: //
// Get data size
//
- VarDataSize = DATASIZE_OF_VARIABLE (Variable.CurrPtr);
+ VarDataSize = DataSizeOfVariable (Variable.CurrPtr);
if (*DataSize >= VarDataSize) {
- (*PeiServices)->CopyMem (Data, GET_VARIABLE_DATA_PTR (Variable.CurrPtr), VarDataSize);
+ (*PeiServices)->CopyMem (Data, GetVariableDataPtr (Variable.CurrPtr), VarDataSize);
if (Attributes != NULL) {
*Attributes = Variable.CurrPtr->Attributes;
@@ -552,11 +738,11 @@ Returns: while (!(Variable.CurrPtr >= Variable.EndPtr || Variable.CurrPtr == NULL)) {
if (IsValidVariableHeader (Variable.CurrPtr)) {
if (Variable.CurrPtr->State == VAR_ADDED) {
- ASSERT (NAMESIZE_OF_VARIABLE (Variable.CurrPtr) != 0);
+ ASSERT (NameSizeOfVariable (Variable.CurrPtr) != 0);
- VarNameSize = (UINTN) NAMESIZE_OF_VARIABLE (Variable.CurrPtr);
+ VarNameSize = (UINTN) NameSizeOfVariable (Variable.CurrPtr);
if (VarNameSize <= *VariableNameSize) {
- (*PeiServices)->CopyMem (VariableName, GET_VARIABLE_NAME_PTR (Variable.CurrPtr), VarNameSize);
+ (*PeiServices)->CopyMem (VariableName, GetVariableNamePtr (Variable.CurrPtr), VarNameSize);
(*PeiServices)->CopyMem (VendorGuid, &Variable.CurrPtr->VendorGuid, sizeof (EFI_GUID));
diff --git a/IntelFrameworkModulePkg/Universal/VariablePei/Variable.h b/IntelFrameworkModulePkg/Universal/VariablePei/Variable.h index 2f586c6f4a..0e37be5292 100644 --- a/IntelFrameworkModulePkg/Universal/VariablePei/Variable.h +++ b/IntelFrameworkModulePkg/Universal/VariablePei/Variable.h @@ -44,27 +44,6 @@ Abstract: #define HEADER_ALIGN(Header) (((UINTN) (Header) + HEADER_ALIGNMENT - 1) & (~(HEADER_ALIGNMENT - 1)))
-#define NAMESIZE_OF_VARIABLE(Variable) \
- ((((Variable)->DataSize == (UINT32) -1) || \
- ((Variable)->Attributes == (UINT32) -1) || \
- ((Variable)->NameSize == (UINT32) -1)) ? \
- 0 : \
- (Variable)->NameSize \
- )
-
-#define DATASIZE_OF_VARIABLE(Variable) \
- ((((Variable)->DataSize == (UINT32) -1) || \
- ((Variable)->Attributes == (UINT32) -1) || \
- ((Variable)->NameSize == (UINT32) -1)) ? \
- 0 : \
- (Variable)->DataSize \
- )
-
-#define GET_VARIABLE_NAME_PTR(a) (CHAR16 *) ((UINTN) (a) + sizeof (VARIABLE_HEADER))
-
-#define GET_VARIABLE_DATA_PTR(a) \
- (UINT8 *) ((UINTN) GET_VARIABLE_NAME_PTR (a) + NAMESIZE_OF_VARIABLE(a) + GET_PAD_SIZE (NAMESIZE_OF_VARIABLE(a)))
-
typedef struct {
VARIABLE_HEADER *CurrPtr;
VARIABLE_HEADER *EndPtr;
diff --git a/MdeModulePkg/Include/VariableFormat.h b/MdeModulePkg/Include/VariableFormat.h index 431f01bbb5..bdc33ecb54 100644 --- a/MdeModulePkg/Include/VariableFormat.h +++ b/MdeModulePkg/Include/VariableFormat.h @@ -60,7 +60,9 @@ typedef enum { //
#define VAR_IN_DELETED_TRANSITION 0xfe // Variable is in obsolete transistion
#define VAR_DELETED 0xfd // Variable is obsolete
-#define VAR_ADDED 0x7f // Variable has been completely added
+#define VAR_HEADER_VALID_ONLY 0x7f // Variable header has been valid
+#define VAR_ADDED 0x3f // Variable has been completely added
+ //
#define IS_VARIABLE_STATE(_c, _Mask) (BOOLEAN) (((~_c) & (~_Mask)) != 0)
#pragma pack(1)
diff --git a/MdeModulePkg/Universal/Variable/Pei/Variable.c b/MdeModulePkg/Universal/Variable/Pei/Variable.c index d1165e1fe5..92e690724d 100644 --- a/MdeModulePkg/Universal/Variable/Pei/Variable.c +++ b/MdeModulePkg/Universal/Variable/Pei/Variable.c @@ -121,9 +121,10 @@ Returns: }
STATIC
-VARIABLE_HEADER *
-GetNextVariablePtr (
- IN VARIABLE_HEADER *Variable
+BOOLEAN
+EFIAPI
+IsValidVariableHeader (
+ IN VARIABLE_HEADER *Variable
)
/*++
@@ -132,7 +133,7 @@ Routine Description: This code checks if variable header is valid or not.
Arguments:
- Variable Pointer to the Variable Header.
+ Variable Pointer to the Variable Header.
Returns:
TRUE Variable header is valid.
@@ -140,37 +141,166 @@ Returns: --*/
{
- return (VARIABLE_HEADER *) HEADER_ALIGN ((UINTN) GET_VARIABLE_DATA_PTR (Variable) + DATASIZE_OF_VARIABLE (Variable) + GET_PAD_SIZE (DATASIZE_OF_VARIABLE (Variable)));
+ if (Variable == NULL || Variable->StartId != VARIABLE_DATA ) {
+ return FALSE;
+ }
+
+ return TRUE;
}
-STATIC
-BOOLEAN
-EFIAPI
-IsValidVariableHeader (
+
+UINTN
+NameSizeOfVariable (
IN VARIABLE_HEADER *Variable
)
/*++
Routine Description:
- This code checks if variable header is valid or not.
+ This code gets the size of name of variable.
+
+Arguments:
+
+ Variable Pointer to the Variable Header.
+
+Returns:
+
+ UINTN Size of variable in bytes
+
+--*/
+{
+ if (Variable->State == (UINT8) (-1) ||
+ Variable->DataSize == (UINT32) -1 ||
+ Variable->NameSize == (UINT32) -1 ||
+ Variable->Attributes == (UINT32) -1) {
+ return 0;
+ }
+ return (UINTN) Variable->NameSize;
+}
+
+UINTN
+DataSizeOfVariable (
+ IN VARIABLE_HEADER *Variable
+ )
+/*++
+
+Routine Description:
+
+ This code gets the size of name of variable.
+
+Arguments:
+
+ Variable Pointer to the Variable Header.
+
+Returns:
+
+ UINTN Size of variable in bytes
+
+--*/
+{
+ if (Variable->State == (UINT8) -1 ||
+ Variable->DataSize == (UINT32) -1 ||
+ Variable->NameSize == (UINT32) -1 ||
+ Variable->Attributes == (UINT32) -1) {
+ return 0;
+ }
+ return (UINTN) Variable->DataSize;
+}
+
+CHAR16 *
+GetVariableNamePtr (
+ IN VARIABLE_HEADER *Variable
+ )
+/*++
+
+Routine Description:
+
+ This code gets the pointer to the variable name.
Arguments:
+
+ Variable Pointer to the Variable Header.
+
+Returns:
+
+ CHAR16* Pointer to Variable Name
+
+--*/
+{
+
+ return (CHAR16 *) (Variable + 1);
+}
+
+
+UINT8 *
+GetVariableDataPtr (
+ IN VARIABLE_HEADER *Variable
+ )
+/*++
+
+Routine Description:
+
+ This code gets the pointer to the variable data.
+
+Arguments:
+
+ Variable Pointer to the Variable Header.
+
+Returns:
+
+ UINT8* Pointer to Variable Data
+
+--*/
+{
+ UINTN Value;
+
+ //
+ // Be careful about pad size for alignment
+ //
+ Value = (UINTN) GetVariableNamePtr (Variable);
+ Value += NameSizeOfVariable (Variable);
+ Value += GET_PAD_SIZE (NameSizeOfVariable (Variable));
+
+ return (UINT8 *) Value;
+}
+
+VARIABLE_HEADER *
+GetNextVariablePtr (
+ IN VARIABLE_HEADER *Variable
+ )
+/*++
+
+Routine Description:
+
+ This code gets the pointer to the next variable header.
+
+Arguments:
+
Variable Pointer to the Variable Header.
Returns:
- TRUE Variable header is valid.
- FALSE Variable header is not valid.
+
+ VARIABLE_HEADER* Pointer to next variable header.
--*/
{
- if (Variable == NULL || Variable->StartId != VARIABLE_DATA ) {
- return FALSE;
+ UINTN Value;
+
+ if (!IsValidVariableHeader (Variable)) {
+ return NULL;
}
- return TRUE;
+ Value = (UINTN) GetVariableDataPtr (Variable);
+ Value += DataSizeOfVariable (Variable);
+ Value += GET_PAD_SIZE (DataSizeOfVariable (Variable));
+
+ //
+ // Be careful about pad size for alignment
+ //
+ return (VARIABLE_HEADER *) HEADER_ALIGN (Value);
}
+
STATIC
VARIABLE_STORE_STATUS
EFIAPI
@@ -244,6 +374,8 @@ Returns: --*/
{
+ VOID *Point;
+
if (VariableName[0] == 0) {
PtrTrack->CurrPtr = Variable;
return EFI_SUCCESS;
@@ -258,8 +390,9 @@ Returns: (((INT32 *) VendorGuid)[2] == ((INT32 *) &Variable->VendorGuid)[2]) &&
(((INT32 *) VendorGuid)[3] == ((INT32 *) &Variable->VendorGuid)[3])
) {
- ASSERT (NAMESIZE_OF_VARIABLE (Variable) != 0);
- if (!CompareMem (VariableName, GET_VARIABLE_NAME_PTR (Variable), NAMESIZE_OF_VARIABLE (Variable))) {
+ ASSERT (NameSizeOfVariable (Variable) != 0);
+ Point = (VOID *) GetVariableNamePtr (Variable);
+ if (!CompareMem (VariableName, Point, NameSizeOfVariable (Variable))) {
PtrTrack->CurrPtr = Variable;
return EFI_SUCCESS;
}
@@ -468,9 +601,9 @@ Returns: //
// Get data size
//
- VarDataSize = DATASIZE_OF_VARIABLE (Variable.CurrPtr);
+ VarDataSize = DataSizeOfVariable (Variable.CurrPtr);
if (*DataSize >= VarDataSize) {
- (*PeiServices)->CopyMem (Data, GET_VARIABLE_DATA_PTR (Variable.CurrPtr), VarDataSize);
+ (*PeiServices)->CopyMem (Data, GetVariableDataPtr (Variable.CurrPtr), VarDataSize);
if (Attributes != NULL) {
*Attributes = Variable.CurrPtr->Attributes;
@@ -544,11 +677,11 @@ Returns: while (!(Variable.CurrPtr >= Variable.EndPtr || Variable.CurrPtr == NULL)) {
if (IsValidVariableHeader (Variable.CurrPtr)) {
if (Variable.CurrPtr->State == VAR_ADDED) {
- ASSERT (NAMESIZE_OF_VARIABLE (Variable.CurrPtr) != 0);
+ ASSERT (NameSizeOfVariable (Variable.CurrPtr) != 0);
- VarNameSize = (UINTN) NAMESIZE_OF_VARIABLE (Variable.CurrPtr);
+ VarNameSize = (UINTN) NameSizeOfVariable (Variable.CurrPtr);
if (VarNameSize <= *VariableNameSize) {
- (*PeiServices)->CopyMem (VariableName, GET_VARIABLE_NAME_PTR (Variable.CurrPtr), VarNameSize);
+ (*PeiServices)->CopyMem (VariableName, GetVariableNamePtr (Variable.CurrPtr), VarNameSize);
(*PeiServices)->CopyMem (VariableGuid, &Variable.CurrPtr->VendorGuid, sizeof (EFI_GUID));
diff --git a/MdeModulePkg/Universal/Variable/Pei/Variable.h b/MdeModulePkg/Universal/Variable/Pei/Variable.h index 73e1b7afdb..965f722f38 100644 --- a/MdeModulePkg/Universal/Variable/Pei/Variable.h +++ b/MdeModulePkg/Universal/Variable/Pei/Variable.h @@ -43,27 +43,6 @@ Abstract: #define HEADER_ALIGN(Header) (((UINTN) (Header) + HEADER_ALIGNMENT - 1) & (~(HEADER_ALIGNMENT - 1)))
-#define NAMESIZE_OF_VARIABLE(Variable) \
- ((((Variable)->DataSize == (UINT32) -1) || \
- ((Variable)->Attributes == (UINT32) -1) || \
- ((Variable)->NameSize == (UINT32) -1)) ? \
- 0 : \
- (Variable)->NameSize \
- )
-
-#define DATASIZE_OF_VARIABLE(Variable) \
- ((((Variable)->DataSize == (UINT32) -1) || \
- ((Variable)->Attributes == (UINT32) -1) || \
- ((Variable)->NameSize == (UINT32) -1)) ? \
- 0 : \
- (Variable)->DataSize \
- )
-
-#define GET_VARIABLE_NAME_PTR(a) (CHAR16 *) ((UINTN) (a) + sizeof (VARIABLE_HEADER))
-
-#define GET_VARIABLE_DATA_PTR(a) \
- (UINT8 *) ((UINTN) GET_VARIABLE_NAME_PTR (a) + NAMESIZE_OF_VARIABLE(a) + GET_PAD_SIZE (NAMESIZE_OF_VARIABLE(a)))
-
typedef struct {
VARIABLE_HEADER *CurrPtr;
VARIABLE_HEADER *EndPtr;
diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c b/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c index d7cb0cd71c..9ff417230a 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c @@ -367,6 +367,89 @@ Returns: }
}
+
+UINTN
+NameSizeOfVariable (
+ IN VARIABLE_HEADER *Variable
+ )
+/*++
+
+Routine Description:
+
+ This code gets the size of name of variable.
+
+Arguments:
+
+ Variable Pointer to the Variable Header.
+
+Returns:
+
+ UINTN Size of variable in bytes
+
+--*/
+{
+ if (Variable->State == (UINT8) (-1) ||
+ Variable->DataSize == (UINT32) -1 ||
+ Variable->NameSize == (UINT32) -1 ||
+ Variable->Attributes == (UINT32) -1) {
+ return 0;
+ }
+ return (UINTN) Variable->NameSize;
+}
+
+UINTN
+DataSizeOfVariable (
+ IN VARIABLE_HEADER *Variable
+ )
+/*++
+
+Routine Description:
+
+ This code gets the size of name of variable.
+
+Arguments:
+
+ Variable Pointer to the Variable Header.
+
+Returns:
+
+ UINTN Size of variable in bytes
+
+--*/
+{
+ if (Variable->State == (UINT8) -1 ||
+ Variable->DataSize == (UINT32) -1 ||
+ Variable->NameSize == (UINT32) -1 ||
+ Variable->Attributes == (UINT32) -1) {
+ return 0;
+ }
+ return (UINTN) Variable->DataSize;
+}
+
+CHAR16 *
+GetVariableNamePtr (
+ IN VARIABLE_HEADER *Variable
+ )
+/*++
+
+Routine Description:
+
+ This code gets the pointer to the variable name.
+
+Arguments:
+
+ Variable Pointer to the Variable Header.
+
+Returns:
+
+ CHAR16* Pointer to Variable Name
+
+--*/
+{
+
+ return (CHAR16 *) (Variable + 1);
+}
+
UINT8 *
GetVariableDataPtr (
IN VARIABLE_HEADER *Variable
@@ -387,10 +470,16 @@ Returns: --*/
{
+ UINTN Value;
+
//
// Be careful about pad size for alignment
//
- return (UINT8 *) ((UINTN) GET_VARIABLE_NAME_PTR (Variable) + NAMESIZE_OF_VARIABLE (Variable) + GET_PAD_SIZE (NAMESIZE_OF_VARIABLE (Variable)));
+ Value = (UINTN) GetVariableNamePtr (Variable);
+ Value += NameSizeOfVariable (Variable);
+ Value += GET_PAD_SIZE (NameSizeOfVariable (Variable));
+
+ return (UINT8 *) Value;
}
@@ -414,13 +503,20 @@ Returns: --*/
{
+ UINTN Value;
+
if (!IsValidVariableHeader (Variable)) {
return NULL;
}
+
+ Value = (UINTN) GetVariableDataPtr (Variable);
+ Value += DataSizeOfVariable (Variable);
+ Value += GET_PAD_SIZE (DataSizeOfVariable (Variable));
+
//
// Be careful about pad size for alignment
//
- return (VARIABLE_HEADER *) HEADER_ALIGN (((UINTN) GetVariableDataPtr (Variable) + DATASIZE_OF_VARIABLE (Variable) + GET_PAD_SIZE (DATASIZE_OF_VARIABLE (Variable))));
+ return (VARIABLE_HEADER *) HEADER_ALIGN (Value);
}
VARIABLE_HEADER *
@@ -747,6 +843,7 @@ Returns: VARIABLE_HEADER *Variable[2];
VARIABLE_STORE_HEADER *VariableStoreHeader[2];
UINTN Index;
+ VOID *Point;
//
// 0: Volatile, 1: Non-Volatile
@@ -782,8 +879,10 @@ Returns: return EFI_SUCCESS;
} else {
if (CompareGuid (VendorGuid, &Variable[Index]->VendorGuid)) {
- ASSERT (NAMESIZE_OF_VARIABLE (Variable[Index]) != 0);
- if (!CompareMem (VariableName, GET_VARIABLE_NAME_PTR (Variable[Index]), NAMESIZE_OF_VARIABLE (Variable[Index]))) {
+ Point = (VOID *) GetVariableNamePtr (Variable[Index]);
+
+ ASSERT (NameSizeOfVariable (Variable[Index]) != 0);
+ if (!CompareMem (VariableName, Point, NameSizeOfVariable (Variable[Index]))) {
PtrTrack->CurrPtr = Variable[Index];
PtrTrack->Volatile = (BOOLEAN)(Index == 0);
return EFI_SUCCESS;
@@ -866,7 +965,7 @@ RuntimeServiceGetVariable ( //
// Get data size
//
- VarDataSize = DATASIZE_OF_VARIABLE (Variable.CurrPtr);
+ VarDataSize = DataSizeOfVariable (Variable.CurrPtr);
ASSERT (VarDataSize != 0);
if (*DataSize >= VarDataSize) {
@@ -973,13 +1072,13 @@ RuntimeServiceGetNextVariableName ( //
if (IsValidVariableHeader (Variable.CurrPtr) && Variable.CurrPtr->State == VAR_ADDED) {
if (!(EfiAtRuntime () && !(Variable.CurrPtr->Attributes & EFI_VARIABLE_RUNTIME_ACCESS))) {
- VarNameSize = NAMESIZE_OF_VARIABLE (Variable.CurrPtr);
+ VarNameSize = NameSizeOfVariable (Variable.CurrPtr);
ASSERT (VarNameSize != 0);
if (VarNameSize <= *VariableNameSize) {
CopyMem (
VariableName,
- GET_VARIABLE_NAME_PTR (Variable.CurrPtr),
+ GetVariableNamePtr (Variable.CurrPtr),
VarNameSize
);
CopyMem (
@@ -1174,7 +1273,7 @@ RuntimeServiceSetVariable ( // If the variable is marked valid and the same data has been passed in
// then return to the caller immediately.
//
- if (DATASIZE_OF_VARIABLE (Variable.CurrPtr) == DataSize &&
+ if (DataSizeOfVariable (Variable.CurrPtr) == DataSize &&
(CompareMem (Data, GetVariableDataPtr (Variable.CurrPtr), DataSize) == 0)) {
UpdateVariableInfo (VariableName, VendorGuid, Volatile, FALSE, TRUE, FALSE, FALSE);
@@ -1310,8 +1409,9 @@ RuntimeServiceSetVariable ( //
// Three steps
// 1. Write variable header
- // 2. Write variable data
- // 3. Set variable state to valid
+ // 2. Set variable state to header valid
+ // 3. Write variable data
+ // 4. Set variable state to valid
//
//
// Step 1:
@@ -1329,9 +1429,27 @@ RuntimeServiceSetVariable ( if (EFI_ERROR (Status)) {
goto Done;
}
+
//
// Step 2:
//
+ NextVariable->State = VAR_HEADER_VALID_ONLY;
+ Status = UpdateVariableStore (
+ &mVariableModuleGlobal->VariableGlobal,
+ FALSE,
+ TRUE,
+ Instance,
+ *NonVolatileOffset,
+ sizeof (VARIABLE_HEADER),
+ (UINT8 *) NextVariable
+ );
+
+ if (EFI_ERROR (Status)) {
+ goto Done;
+ }
+ //
+ // Step 3:
+ //
Status = UpdateVariableStore (
&mVariableModuleGlobal->VariableGlobal,
FALSE,
@@ -1346,7 +1464,7 @@ RuntimeServiceSetVariable ( goto Done;
}
//
- // Step 3:
+ // Step 4:
//
NextVariable->State = VAR_ADDED;
Status = UpdateVariableStore (
diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.h b/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.h index 09a184d478..f8a4e058f5 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.h +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.h @@ -59,24 +59,6 @@ Abstract: #define HEADER_ALIGN(Header) (((UINTN) (Header) + HEADER_ALIGNMENT - 1) & (~(HEADER_ALIGNMENT - 1)))
-#define NAMESIZE_OF_VARIABLE(Variable) \
- ((((Variable)->DataSize == (UINT32) -1) || \
- ((Variable)->Attributes == (UINT32) -1) || \
- ((Variable)->NameSize == (UINT32) -1)) ? \
- 0 : \
- (Variable)->NameSize \
- )
-
-#define DATASIZE_OF_VARIABLE(Variable) \
- ((((Variable)->DataSize == (UINT32) -1) || \
- ((Variable)->Attributes == (UINT32) -1) || \
- ((Variable)->NameSize == (UINT32) -1)) ? \
- 0 : \
- (Variable)->DataSize \
- )
-
-#define GET_VARIABLE_NAME_PTR(a) (CHAR16 *) ((UINTN) (a) + sizeof (VARIABLE_HEADER))
-
typedef struct {
VARIABLE_HEADER *CurrPtr;
|