X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FUniversal%2FVariable%2FRuntimeDxe%2FVariable.c;h=6caf603b3d305f41b43c45c966a6957a014bff31;hp=c11842b5c3ba742f440eaf474234c4deec9c5c27;hb=9b4a20321edc5865e38409b30814b6c4d898d7e6;hpb=56d0bd7eb8e08a7a9c47edb8a2483781359cac65 diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c b/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c index c11842b5c3..6caf603b3d 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c @@ -2345,12 +2345,14 @@ UpdateVariable ( CopyMem (BufferForMerge, (UINT8 *) ((UINTN) CacheVariable->CurrPtr + DataOffset), DataSizeOfVariable (CacheVariable->CurrPtr)); // - // Set Max Common/Auth Variable Data Size as default MaxDataSize. + // Set Max Auth/Non-Volatile/Volatile Variable Data Size as default MaxDataSize. // if ((Attributes & VARIABLE_ATTRIBUTE_AT_AW) != 0) { MaxDataSize = mVariableModuleGlobal->MaxAuthVariableSize - DataOffset; - } else { + } else if ((Attributes & EFI_VARIABLE_NON_VOLATILE) != 0) { MaxDataSize = mVariableModuleGlobal->MaxVariableSize - DataOffset; + } else { + MaxDataSize = mVariableModuleGlobal->MaxVolatileVariableSize - DataOffset; } // @@ -3218,16 +3220,20 @@ VariableServiceSetVariable ( } else { // // The size of the VariableName, including the Unicode Null in bytes plus - // the DataSize is limited to maximum size of Max(Auth)VariableSize bytes. + // the DataSize is limited to maximum size of Max(Auth|Volatile)VariableSize bytes. // if ((Attributes & VARIABLE_ATTRIBUTE_AT_AW) != 0) { if (StrSize (VariableName) + PayloadSize > mVariableModuleGlobal->MaxAuthVariableSize - GetVariableHeaderSize ()) { return EFI_INVALID_PARAMETER; } - } else { + } else if ((Attributes & EFI_VARIABLE_NON_VOLATILE) != 0) { if (StrSize (VariableName) + PayloadSize > mVariableModuleGlobal->MaxVariableSize - GetVariableHeaderSize ()) { return EFI_INVALID_PARAMETER; } + } else { + if (StrSize (VariableName) + PayloadSize > mVariableModuleGlobal->MaxVolatileVariableSize - GetVariableHeaderSize ()) { + return EFI_INVALID_PARAMETER; + } } } @@ -3399,12 +3405,14 @@ VariableServiceQueryVariableInfoInternal ( } // - // Let *MaximumVariableSize be Max(Auth)VariableSize with the exception of the variable header size. + // Let *MaximumVariableSize be Max(Auth|Volatile)VariableSize with the exception of the variable header size. // if ((Attributes & VARIABLE_ATTRIBUTE_AT_AW) != 0) { *MaximumVariableSize = mVariableModuleGlobal->MaxAuthVariableSize - GetVariableHeaderSize (); - } else { + } else if ((Attributes & EFI_VARIABLE_NON_VOLATILE) != 0) { *MaximumVariableSize = mVariableModuleGlobal->MaxVariableSize - GetVariableHeaderSize (); + } else { + *MaximumVariableSize = mVariableModuleGlobal->MaxVolatileVariableSize - GetVariableHeaderSize (); } } @@ -3657,6 +3665,30 @@ GetNonVolatileMaxVariableSize ( } } +/** + Get maximum variable size, covering both non-volatile and volatile variables. + + @return Maximum variable size. + +**/ +UINTN +GetMaxVariableSize ( + VOID + ) +{ + UINTN MaxVariableSize; + + MaxVariableSize = GetNonVolatileMaxVariableSize(); + // + // The condition below fails implicitly if PcdMaxVolatileVariableSize equals + // the default zero value. + // + if (MaxVariableSize < PcdGet32 (PcdMaxVolatileVariableSize)) { + MaxVariableSize = PcdGet32 (PcdMaxVolatileVariableSize); + } + return MaxVariableSize; +} + /** Init non-volatile variable store. @@ -4225,10 +4257,14 @@ VariableCommonInitialize ( } } + mVariableModuleGlobal->MaxVolatileVariableSize = ((PcdGet32 (PcdMaxVolatileVariableSize) != 0) ? + PcdGet32 (PcdMaxVolatileVariableSize) : + mVariableModuleGlobal->MaxVariableSize + ); // // Allocate memory for volatile variable store, note that there is a scratch space to store scratch data. // - ScratchSize = GetNonVolatileMaxVariableSize (); + ScratchSize = GetMaxVariableSize (); mVariableModuleGlobal->ScratchBufferSize = ScratchSize; VolatileVariableStore = AllocateRuntimePool (PcdGet32 (PcdVariableStoreSize) + ScratchSize); if (VolatileVariableStore == NULL) {