X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=EdkModulePkg%2FUniversal%2FEmuVariable%2FRuntimeDxe%2FEmuVariable.c;h=208f3b427682c4bac482867044f144398c064bf9;hp=b44da1c47486c09a5abc0f738b5bfb69b1dfb56d;hb=fb5a3ed8c728f692d111633d478b31e0b5e2942c;hpb=35d02d76bffba0b2ab598ac1151cc02e47ad197e diff --git a/EdkModulePkg/Universal/EmuVariable/RuntimeDxe/EmuVariable.c b/EdkModulePkg/Universal/EmuVariable/RuntimeDxe/EmuVariable.c index b44da1c474..208f3b4276 100644 --- a/EdkModulePkg/Universal/EmuVariable/RuntimeDxe/EmuVariable.c +++ b/EdkModulePkg/Universal/EmuVariable/RuntimeDxe/EmuVariable.c @@ -26,6 +26,7 @@ Revision History // ESAL_VARIABLE_GLOBAL *mVariableModuleGlobal; +STATIC UINT32 EFIAPI ArrayLength ( @@ -62,47 +63,7 @@ Returns: return (Count * 2) + 2; } -VARIABLE_STORE_STATUS -EFIAPI -GetVariableStoreStatus ( - IN VARIABLE_STORE_HEADER *VarStoreHeader - ) -/*++ - -Routine Description: - - This code gets the pointer to the variable name. - -Arguments: - - VarStoreHeader Pointer to the Variable Store Header. - -Returns: - - EfiHealthy Variable store is healthy - EfiRaw Variable store is raw - EfiInvalid Variable store is invalid - ---*/ -{ - if (VarStoreHeader->Signature == VARIABLE_STORE_SIGNATURE && - VarStoreHeader->Format == VARIABLE_STORE_FORMATTED && - VarStoreHeader->State == VARIABLE_STORE_HEALTHY - ) { - - return EfiValid; - } else if (VarStoreHeader->Signature == 0xffffffff && - VarStoreHeader->Size == 0xffffffff && - VarStoreHeader->Format == 0xff && - VarStoreHeader->State == 0xff - ) { - - return EfiRaw; - } else { - return EfiInvalid; - } -} - +STATIC UINT8 * EFIAPI GetVariableDataPtr ( @@ -133,6 +94,7 @@ Returns: return (UINT8 *) ((UINTN) GET_VARIABLE_NAME_PTR (Variable) + Variable->NameSize + GET_PAD_SIZE (Variable->NameSize)); } +STATIC VARIABLE_HEADER * EFIAPI GetNextVariablePtr ( @@ -173,6 +135,7 @@ Returns: return VarHeader; } +STATIC VARIABLE_HEADER * EFIAPI GetEndPointer ( @@ -200,6 +163,7 @@ Returns: return (VARIABLE_HEADER *) ((UINTN) VolHeader + VolHeader->Size); } +STATIC EFI_STATUS EFIAPI FindVariable ( @@ -413,7 +377,7 @@ Returns: Variable.StartPtr = (VARIABLE_HEADER *) ((UINTN) (Global->VolatileVariableBase + sizeof (VARIABLE_STORE_HEADER))); Variable.EndPtr = (VARIABLE_HEADER *) GetEndPointer ((VARIABLE_STORE_HEADER *) ((UINTN) Global->VolatileVariableBase)); } else { - return EFI_NOT_FOUND; + goto Error; } Variable.CurrPtr = Variable.StartPtr; @@ -449,6 +413,7 @@ Returns: } } +Error: return EFI_NOT_FOUND; } @@ -506,38 +471,40 @@ Returns: if (Status == EFI_INVALID_PARAMETER) { return Status; - } - // - // The size of the VariableName, including the Unicode Null in bytes plus - // the DataSize is limited to maximum size of MAX_VARIABLE_SIZE (1024) bytes. - // - else if (sizeof (VARIABLE_HEADER) + (ArrayLength (VariableName) + DataSize) > MAX_VARIABLE_SIZE) { + } else if (!EFI_ERROR (Status) && Variable.Volatile && EfiAtRuntime()) { + // + // If EfiAtRuntime and the variable is Volatile and Runtime Access, + // the volatile is ReadOnly, and SetVariable should be aborted and + // return EFI_WRITE_PROTECTED. + // + return EFI_WRITE_PROTECTED; + } else if (sizeof (VARIABLE_HEADER) + (ArrayLength (VariableName) + DataSize) > MAX_VARIABLE_SIZE) { + // + // The size of the VariableName, including the Unicode Null in bytes plus + // the DataSize is limited to maximum size of MAX_VARIABLE_SIZE (1024) bytes. + // return EFI_INVALID_PARAMETER; - } - // - // Make sure if runtime bit is set, boot service bit is set also - // - else if ((Attributes & (EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS)) == EFI_VARIABLE_RUNTIME_ACCESS + } else if ((Attributes & (EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS)) == EFI_VARIABLE_RUNTIME_ACCESS ) { + // + // Make sure if runtime bit is set, boot service bit is set also + // return EFI_INVALID_PARAMETER; - } - // - // Runtime but Attribute is not Runtime - // - else if (EfiAtRuntime () && Attributes && !(Attributes & EFI_VARIABLE_RUNTIME_ACCESS)) { + } else if (EfiAtRuntime () && Attributes && !(Attributes & EFI_VARIABLE_RUNTIME_ACCESS)) { + // + // Runtime but Attribute is not Runtime + // return EFI_INVALID_PARAMETER; - } - // - // Cannot set volatile variable in Runtime - // - else if (EfiAtRuntime () && Attributes && !(Attributes & EFI_VARIABLE_NON_VOLATILE)) { + } else if (EfiAtRuntime () && Attributes && !(Attributes & EFI_VARIABLE_NON_VOLATILE)) { + // + // Cannot set volatile variable in Runtime + // return EFI_INVALID_PARAMETER; - } - // - // Setting a data variable with no access, or zero DataSize attributes - // specified causes it to be deleted. - // - else if (DataSize == 0 || Attributes == 0) { + } else if (DataSize == 0 || (Attributes & (EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_BOOTSERVICE_ACCESS)) == 0) { + // + // Setting a data variable with no access, or zero DataSize attributes + // specified causes it to be deleted. + // if (!EFI_ERROR (Status)) { Variable.CurrPtr->State &= VAR_DELETED; return EFI_SUCCESS; @@ -692,6 +659,11 @@ Returns: // Make sure RT Attribute is set if we are in Runtime phase. // return EFI_INVALID_PARAMETER; + } else if (EfiAtRuntime () && Attributes && !(Attributes & EFI_VARIABLE_NON_VOLATILE)) { + // + // Cannot Query volatile variable in Runtime + // + return EFI_INVALID_PARAMETER; } if((Attributes & EFI_VARIABLE_NON_VOLATILE) == 0) { @@ -748,6 +720,7 @@ Returns: } #endif +STATIC EFI_STATUS EFIAPI InitializeVariableStore (