diff --git a/MdeModulePkg/Universal/Variable/EmuRuntimeDxe/EmuVariable.c b/MdeModulePkg/Universal/Variable/EmuRuntimeDxe/EmuVariable.c index 3585f106db..b49b743972 100644 --- a/MdeModulePkg/Universal/Variable/EmuRuntimeDxe/EmuVariable.c +++ b/MdeModulePkg/Universal/Variable/EmuRuntimeDxe/EmuVariable.c @@ -944,6 +944,7 @@ UpdateVariable ( UINTN VarSize; VARIABLE_GLOBAL *Global; UINTN NonVolatileVarableStoreSize; + BOOLEAN Delete = FALSE; Global = &mVariableModuleGlobal->VariableGlobal[Physical]; @@ -976,10 +977,8 @@ UpdateVariable ( // specified causes it to be deleted. // if (DataSize == 0 || (Attributes & (EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS)) == 0) { - Variable->CurrPtr->State &= VAR_DELETED; - UpdateVariableInfo (VariableName, VendorGuid, Variable->Volatile, FALSE, FALSE, TRUE, FALSE); - Status = EFI_SUCCESS; - goto Done; + DataSize = 0; + Delete = TRUE; } // @@ -989,8 +988,12 @@ UpdateVariable ( if (Variable->CurrPtr->DataSize == DataSize && CompareMem (Data, GetVariableDataPtr (Variable->CurrPtr), DataSize) == 0 ) { - Status = EFI_SUCCESS; - goto Done; + if (Delete) { + goto Update; + } else { + Status = EFI_SUCCESS; + goto Done; + } } else if (Variable->CurrPtr->State == VAR_ADDED) { // // Mark the old variable as in delete transition @@ -1032,6 +1035,10 @@ UpdateVariable ( VarDataOffset = VarNameOffset + VarNameSize + GET_PAD_SIZE (VarNameSize); VarSize = VarDataOffset + DataSize + GET_PAD_SIZE (DataSize); + if (Delete) { + goto Store; + } + if ((Attributes & EFI_VARIABLE_NON_VOLATILE) != 0) { NonVolatileVarableStoreSize = ((VARIABLE_STORE_HEADER *)(UINTN)(Global->NonVolatileVariableBase))->Size; if ((((Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) != 0) @@ -1089,7 +1096,16 @@ UpdateVariable ( DataSize ); - if (storeInitialized && ((Attributes & EFI_VARIABLE_NON_VOLATILE) != 0)) { +Store: + // If the store is initialized + // And we are storing or deleting a non volatile variable + // Send the new data to SMMSTORE + if (storeInitialized && ( + (Attributes & EFI_VARIABLE_NON_VOLATILE) != 0 || ( + Delete && + (Variable->CurrPtr->Attributes & EFI_VARIABLE_NON_VOLATILE) != 0 + ) + )) { /* TODO: add hook for logging nv changes here */ @@ -1116,6 +1132,7 @@ UpdateVariable ( */ } +Update: // // Mark the old variable as deleted // @@ -1123,7 +1140,11 @@ UpdateVariable ( Variable->CurrPtr->State &= VAR_DELETED; } - UpdateVariableInfo (VariableName, VendorGuid, Variable->Volatile, FALSE, TRUE, FALSE, FALSE); + if (Delete) { + UpdateVariableInfo (VariableName, VendorGuid, Variable->Volatile, FALSE, FALSE, TRUE, FALSE); + } else { + UpdateVariableInfo (VariableName, VendorGuid, Variable->Volatile, FALSE, TRUE, FALSE, FALSE); + } Status = EFI_SUCCESS;