diff options
author | yshang1 <yshang1@6f19259b-4bc3-4df7-8a09-765794883524> | 2008-01-10 04:26:13 +0000 |
---|---|---|
committer | yshang1 <yshang1@6f19259b-4bc3-4df7-8a09-765794883524> | 2008-01-10 04:26:13 +0000 |
commit | 9cad030bc14e706d8986ed33f0fa8b28f0828c48 (patch) | |
tree | cd43555e2277a45cc1f1e03fb283125165a020fb /IntelFrameworkModulePkg/Universal | |
parent | fdb7765f2d0a835ca93abb63969fe802c12f3560 (diff) | |
download | edk2-platforms-9cad030bc14e706d8986ed33f0fa8b28f0828c48.tar.xz |
Align the header of variable from 1 to 4, which can avoid the size of variable content corrupt if the critical data cross two flash block.
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@4543 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'IntelFrameworkModulePkg/Universal')
-rw-r--r-- | IntelFrameworkModulePkg/Universal/VariablePei/Variable.c | 70 | ||||
-rw-r--r-- | IntelFrameworkModulePkg/Universal/VariablePei/Variable.h | 4 |
2 files changed, 64 insertions, 10 deletions
diff --git a/IntelFrameworkModulePkg/Universal/VariablePei/Variable.c b/IntelFrameworkModulePkg/Universal/VariablePei/Variable.c index 46c898609a..e050fbcf9d 100644 --- a/IntelFrameworkModulePkg/Universal/VariablePei/Variable.c +++ b/IntelFrameworkModulePkg/Universal/VariablePei/Variable.c @@ -80,6 +80,59 @@ Returns: }
+
+UINT32
+NameSizeOfVariable (
+ IN VARIABLE_HEADER *Variable
+ )
+{
+ //
+ // Check whether the header is valid fully;
+ // Tricky: The unprogramed data in FLASH equals 0xff.
+ //
+ if (Variable->DataSize == (UINT32) -1 ||
+ Variable->Attributes == (UINT32) -1 ||
+ Variable->NameSize == (UINT32) -1) {
+ return 0;
+ }
+ return Variable->NameSize;
+}
+
+UINT32
+DataSizeOfVariable (
+ IN VARIABLE_HEADER *Variable
+ )
+{
+ //
+ // Check whether the header is valid fully;
+ // Tricky: The unprogramed data in FLASH equals 0xff.
+ //
+ if (Variable->DataSize == (UINT32) -1 ||
+ Variable->Attributes == (UINT32) -1 ||
+ Variable->NameSize == (UINT32) -1) {
+ return 0;
+ }
+ return Variable->DataSize;
+}
+
+UINT32
+AttributesOfVariable (
+ IN VARIABLE_HEADER *Variable
+ )
+{
+
+ //
+ // Check whether the header is valid fully;
+ // Tricky: The unprogramed data in FLASH equals 0xff.
+ //
+ if (Variable->DataSize == (UINT32) -1 ||
+ Variable->Attributes == (UINT32) -1 ||
+ Variable->NameSize == (UINT32) -1) {
+ return 0;
+ }
+ return Variable->Attributes;
+}
+
STATIC
VARIABLE_HEADER *
GetNextVariablePtr (
@@ -100,7 +153,7 @@ Returns: --*/
{
- return (VARIABLE_HEADER *) ((UINTN) GET_VARIABLE_DATA_PTR (Variable) + Variable->DataSize + GET_PAD_SIZE (Variable->DataSize));
+ return (VARIABLE_HEADER *) HEADER_ALIGN ((UINTN) GET_VARIABLE_DATA_PTR (Variable) + DataSizeOfVariable (Variable) + GET_PAD_SIZE (DataSizeOfVariable (Variable)));
}
STATIC
@@ -124,10 +177,7 @@ Returns: --*/
{
- if (Variable == NULL ||
- Variable->StartId != VARIABLE_DATA ||
- (sizeof (VARIABLE_HEADER) + Variable->DataSize + Variable->NameSize) > MAX_VARIABLE_SIZE
- ) {
+ if (Variable == NULL || Variable->StartId != VARIABLE_DATA ) {
return FALSE;
}
@@ -221,7 +271,8 @@ Returns: (((INT32 *) VendorGuid)[2] == ((INT32 *) &Variable->VendorGuid)[2]) &&
(((INT32 *) VendorGuid)[3] == ((INT32 *) &Variable->VendorGuid)[3])
) {
- if (!CompareMem (VariableName, GET_VARIABLE_NAME_PTR (Variable), Variable->NameSize)) {
+ ASSERT (NameSizeOfVariable (Variable) != 0);
+ if (!CompareMem (VariableName, GET_VARIABLE_NAME_PTR (Variable), NameSizeOfVariable (Variable))) {
PtrTrack->CurrPtr = Variable;
return EFI_SUCCESS;
}
@@ -290,7 +341,6 @@ 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;
@@ -429,7 +479,7 @@ Returns: //
// Get data size
//
- VarDataSize = Variable.CurrPtr->DataSize;
+ VarDataSize = DataSizeOfVariable (Variable.CurrPtr);
if (*DataSize >= VarDataSize) {
(*PeiServices)->CopyMem (Data, GET_VARIABLE_DATA_PTR (Variable.CurrPtr), VarDataSize);
@@ -555,7 +605,9 @@ Returns: while (!(Variable.CurrPtr >= Variable.EndPtr || Variable.CurrPtr == NULL)) {
if (IsValidVariableHeader (Variable.CurrPtr)) {
if (Variable.CurrPtr->State == VAR_ADDED) {
- VarNameSize = (UINTN) Variable.CurrPtr->NameSize;
+ ASSERT (NameSizeOfVariable (Variable.CurrPtr) != 0);
+
+ VarNameSize = (UINTN) NameSizeOfVariable (Variable.CurrPtr);
if (VarNameSize <= *VariableNameSize) {
(*PeiServices)->CopyMem (VariableName, GET_VARIABLE_NAME_PTR (Variable.CurrPtr), VarNameSize);
diff --git a/IntelFrameworkModulePkg/Universal/VariablePei/Variable.h b/IntelFrameworkModulePkg/Universal/VariablePei/Variable.h index cc82b0fd5c..aeb49bca80 100644 --- a/IntelFrameworkModulePkg/Universal/VariablePei/Variable.h +++ b/IntelFrameworkModulePkg/Universal/VariablePei/Variable.h @@ -42,10 +42,12 @@ Abstract: #define GET_PAD_SIZE(a) (((~a) + 1) & (ALIGNMENT - 1))
#endif
+#define HEADER_ALIGN(Header) (((UINTN) (Header) + HEADER_ALIGNMENT - 1) & (~(HEADER_ALIGNMENT - 1)))
+
#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) + (a)->NameSize + GET_PAD_SIZE ((a)->NameSize))
+ (UINT8 *) ((UINTN) GET_VARIABLE_NAME_PTR (a) + NameSizeOfVariable(a) + GET_PAD_SIZE (NameSizeOfVariable(a) ))
typedef struct {
VARIABLE_HEADER *CurrPtr;
|