summaryrefslogtreecommitdiff
path: root/MdeModulePkg/Universal/Variable/Pei/Variable.c
diff options
context:
space:
mode:
authoryshang1 <yshang1@6f19259b-4bc3-4df7-8a09-765794883524>2008-01-14 06:35:23 +0000
committeryshang1 <yshang1@6f19259b-4bc3-4df7-8a09-765794883524>2008-01-14 06:35:23 +0000
commit130e25699a6d060c966978e345c6c8eeed85d065 (patch)
tree9ba431713d743f899f3928f17d8b908a5efbe7ea /MdeModulePkg/Universal/Variable/Pei/Variable.c
parent51dc1f659f280fefefc960377dc79490c03d3f5e (diff)
downloadedk2-platforms-130e25699a6d060c966978e345c6c8eeed85d065.tar.xz
1) Replace MACRO with C functions.
2) Add HEADER_VALID_ONLY state of variable, which represents only the header is valid and the data/name is stale. This may be caused by incomplete data updating. Adding the state helps to check whether the header is valid. If variable header is valid, then we must skip the data of variable with the valid size. If the header is invalid, we should only skip the header of variable. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@4555 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'MdeModulePkg/Universal/Variable/Pei/Variable.c')
-rw-r--r--MdeModulePkg/Universal/Variable/Pei/Variable.c177
1 files changed, 155 insertions, 22 deletions
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));