TianoCore EDK2 master
Loading...
Searching...
No Matches
Variable.c File Reference
#include "Variable.h"
#include "VariableNonVolatile.h"
#include "VariableParsing.h"
#include "VariableRuntimeCache.h"

Go to the source code of this file.

Functions

EFI_STATUS UpdateVariableStore (IN VARIABLE_GLOBAL *Global, IN BOOLEAN Volatile, IN BOOLEAN SetByIndex, IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *Fvb, IN UINTN DataPtrIndex, IN UINT32 DataSize, IN UINT8 *Buffer)
 
VOID RecordVarErrorFlag (IN VAR_ERROR_FLAG Flag, IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid, IN UINT32 Attributes, IN UINTN VariableSize)
 
VOID InitializeVarErrorFlag (VOID)
 
BOOLEAN IsUserVariable (IN VARIABLE_HEADER *Variable)
 
VOID CalculateCommonUserVariableTotalSize (VOID)
 
VOID InitializeVariableQuota (VOID)
 
EFI_STATUS Reclaim (IN EFI_PHYSICAL_ADDRESS VariableBase, OUT UINTN *LastVariableOffset, IN BOOLEAN IsVolatile, IN OUT VARIABLE_POINTER_TRACK *UpdatingPtrTrack, IN VARIABLE_HEADER *NewVariable, IN UINTN NewVariableSize)
 
EFI_STATUS FindVariable (IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid, OUT VARIABLE_POINTER_TRACK *PtrTrack, IN VARIABLE_GLOBAL *Global, IN BOOLEAN IgnoreRtCheck)
 
UINTN GetIndexFromSupportedLangCodes (IN CHAR8 *SupportedLang, IN CHAR8 *Lang, IN BOOLEAN Iso639Language)
 
CHAR8 * GetLangFromSupportedLangCodes (IN CHAR8 *SupportedLang, IN UINTN Index, IN BOOLEAN Iso639Language)
 
CHAR8 *EFIAPI VariableGetBestLanguage (IN CONST CHAR8 *SupportedLanguages, IN UINTN Iso639Language,...)
 
BOOLEAN EFIAPI CheckRemainingSpaceForConsistencyInternal (IN UINT32 Attributes, IN VA_LIST Marker)
 
BOOLEAN EFIAPI CheckRemainingSpaceForConsistency (IN UINT32 Attributes,...)
 
EFI_STATUS AutoUpdateLangVariable (IN CHAR16 *VariableName, IN VOID *Data, IN UINTN DataSize)
 
EFI_STATUS UpdateVariable (IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid, IN VOID *Data, IN UINTN DataSize, IN UINT32 Attributes OPTIONAL, IN UINT32 KeyIndex OPTIONAL, IN UINT64 MonotonicCount OPTIONAL, IN OUT VARIABLE_POINTER_TRACK *CacheVariable, IN EFI_TIME *TimeStamp OPTIONAL)
 
EFI_STATUS EFIAPI VariableServiceGetVariable (IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid, OUT UINT32 *Attributes OPTIONAL, IN OUT UINTN *DataSize, OUT VOID *Data OPTIONAL)
 
EFI_STATUS EFIAPI VariableServiceGetNextVariableName (IN OUT UINTN *VariableNameSize, IN OUT CHAR16 *VariableName, IN OUT EFI_GUID *VendorGuid)
 
EFI_STATUS EFIAPI VariableServiceSetVariable (IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid, IN UINT32 Attributes, IN UINTN DataSize, IN VOID *Data)
 
EFI_STATUS EFIAPI VariableServiceQueryVariableInfoInternal (IN UINT32 Attributes, OUT UINT64 *MaximumVariableStorageSize, OUT UINT64 *RemainingVariableStorageSize, OUT UINT64 *MaximumVariableSize)
 
EFI_STATUS EFIAPI VariableServiceQueryVariableInfo (IN UINT32 Attributes, OUT UINT64 *MaximumVariableStorageSize, OUT UINT64 *RemainingVariableStorageSize, OUT UINT64 *MaximumVariableSize)
 
VOID ReclaimForOS (VOID)
 
UINTN GetMaxVariableSize (VOID)
 
VOID FlushHobVariableToFlash (IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid)
 
EFI_STATUS VariableWriteServiceInitialize (VOID)
 
VOID * ConvertNormalVarStorageToAuthVarStorage (VARIABLE_STORE_HEADER *NormalVarStorage)
 
EFI_STATUS GetHobVariableStore (IN EFI_GUID *VariableGuid)
 
EFI_STATUS VariableCommonInitialize (VOID)
 
EFI_STATUS GetFvbInfoByAddress (IN EFI_PHYSICAL_ADDRESS Address, OUT EFI_HANDLE *FvbHandle OPTIONAL, OUT EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL **FvbProtocol OPTIONAL)
 

Variables

VARIABLE_MODULE_GLOBALmVariableModuleGlobal
 
VARIABLE_STORE_HEADERmNvVariableCache = NULL
 
EFI_FIRMWARE_VOLUME_HEADERmNvFvHeaderCache = NULL
 
VARIABLE_INFO_ENTRYgVariableInfo = NULL
 
BOOLEAN mEndOfDxe = FALSE
 
VAR_CHECK_REQUEST_SOURCE mRequestSource = VarCheckFromUntrusted
 
VAR_ERROR_FLAG mCurrentBootVarErrFlag = VAR_ERROR_FLAG_NO_ERROR
 
VARIABLE_ENTRY_PROPERTY mVariableEntryProperty []
 
AUTH_VAR_LIB_CONTEXT_IN mAuthContextIn
 
AUTH_VAR_LIB_CONTEXT_OUT mAuthContextOut
 

Detailed Description

The common variable operation routines shared by DXE_RUNTIME variable module and DXE_SMM variable module.

Caution: This module requires additional review when modified. This driver will have external input - variable data. They may be input in SMM mode. This external input must be validated carefully to avoid security issue like buffer overflow, integer overflow.

VariableServiceGetNextVariableName () and VariableServiceQueryVariableInfo() are external API. They need check input parameter.

VariableServiceGetVariable() and VariableServiceSetVariable() are external API to receive datasize and data buffer. The size should be checked carefully.

VariableServiceSetVariable() should also check authenticate data to avoid buffer overflow, integer overflow. It should also check attribute to avoid authentication bypass.

Copyright (c) 2006 - 2020, Intel Corporation. All rights reserved.
(C) Copyright 2015-2018 Hewlett Packard Enterprise Development LP
Copyright (c) Microsoft Corporation.
Copyright (c) 2022, ARM Limited. All rights reserved.

SPDX-License-Identifier: BSD-2-Clause-Patent

Definition in file Variable.c.

Function Documentation

◆ AutoUpdateLangVariable()

EFI_STATUS AutoUpdateLangVariable ( IN CHAR16 *  VariableName,
IN VOID *  Data,
IN UINTN  DataSize 
)

Hook the operations in PlatformLangCodes, LangCodes, PlatformLang and Lang.

When setting Lang/LangCodes, simultaneously update PlatformLang/PlatformLangCodes.

According to UEFI spec, PlatformLangCodes/LangCodes are only set once in firmware initialization, and are read-only. Therefore, in variable driver, only store the original value for other use.

Parameters
[in]VariableNameName of variable.
[in]DataVariable data.
[in]DataSizeSize of data. 0 means delete.
Return values
EFI_SUCCESSThe update operation is successful or ignored.
EFI_WRITE_PROTECTEDUpdate PlatformLangCodes/LangCodes at runtime.
EFI_OUT_OF_RESOURCESNo enough variable space to do the update operation.
OthersOther errors happened during the update operation.

Definition at line 1415 of file Variable.c.

◆ CalculateCommonUserVariableTotalSize()

VOID CalculateCommonUserVariableTotalSize ( VOID  )

Calculate common user variable total size.

Definition at line 445 of file Variable.c.

◆ CheckRemainingSpaceForConsistency()

BOOLEAN EFIAPI CheckRemainingSpaceForConsistency ( IN UINT32  Attributes,
  ... 
)

This function is to check if the remaining variable space is enough to set all Variables from argument list successfully. The purpose of the check is to keep the consistency of the Variables to be in variable storage.

Note: Variables are assumed to be in same storage. The set sequence of Variables will be same with the sequence of VariableEntry from argument list, so follow the argument sequence to check the Variables.

Parameters
[in]AttributesVariable attributes for Variable entries.
...The variable argument list with type VARIABLE_ENTRY_CONSISTENCY *. A NULL terminates the list. The VariableSize of VARIABLE_ENTRY_CONSISTENCY is the variable data size as input. It will be changed to variable total size as output.
Return values
TRUEHave enough variable space to set the Variables successfully.
FALSENo enough variable space to set the Variables successfully.

Definition at line 1377 of file Variable.c.

◆ CheckRemainingSpaceForConsistencyInternal()

BOOLEAN EFIAPI CheckRemainingSpaceForConsistencyInternal ( IN UINT32  Attributes,
IN VA_LIST  Marker 
)

This function is to check if the remaining variable space is enough to set all Variables from argument list successfully. The purpose of the check is to keep the consistency of the Variables to be in variable storage.

Note: Variables are assumed to be in same storage. The set sequence of Variables will be same with the sequence of VariableEntry from argument list, so follow the argument sequence to check the Variables.

Parameters
[in]AttributesVariable attributes for Variable entries.
[in]MarkerVA_LIST style variable argument list. The variable argument list with type VARIABLE_ENTRY_CONSISTENCY *. A NULL terminates the list. The VariableSize of VARIABLE_ENTRY_CONSISTENCY is the variable data size as input. It will be changed to variable total size as output.
Return values
TRUEHave enough variable space to set the Variables successfully.
FALSENo enough variable space to set the Variables successfully.

Definition at line 1240 of file Variable.c.

◆ ConvertNormalVarStorageToAuthVarStorage()

VOID * ConvertNormalVarStorageToAuthVarStorage ( VARIABLE_STORE_HEADER NormalVarStorage)

Convert normal variable storage to the allocated auth variable storage.

Parameters
[in]NormalVarStoragePointer to the normal variable storage header
Return values
theallocated auth variable storage

Definition at line 3512 of file Variable.c.

◆ FindVariable()

EFI_STATUS FindVariable ( IN CHAR16 *  VariableName,
IN EFI_GUID VendorGuid,
OUT VARIABLE_POINTER_TRACK PtrTrack,
IN VARIABLE_GLOBAL Global,
IN BOOLEAN  IgnoreRtCheck 
)

Finds variable in storage blocks of volatile and non-volatile storage areas.

This code finds variable in storage blocks of volatile and non-volatile storage areas. If VariableName is an empty string, then we just return the first qualified variable without comparing VariableName and VendorGuid. If IgnoreRtCheck is TRUE, then we ignore the EFI_VARIABLE_RUNTIME_ACCESS attribute check at runtime when searching existing variable, only VariableName and VendorGuid are compared. Otherwise, variables without EFI_VARIABLE_RUNTIME_ACCESS are not visible at runtime.

Parameters
[in]VariableNameName of the variable to be found.
[in]VendorGuidVendor GUID to be found.
[out]PtrTrackVARIABLE_POINTER_TRACK structure for output, including the range searched and the target position.
[in]GlobalPointer to VARIABLE_GLOBAL structure, including base of volatile variable storage area, base of NV variable storage area, and a lock.
[in]IgnoreRtCheckIgnore EFI_VARIABLE_RUNTIME_ACCESS attribute check at runtime when searching variable.
Return values
EFI_INVALID_PARAMETERIf VariableName is not an empty string, while VendorGuid is NULL.
EFI_SUCCESSVariable successfully found.
EFI_NOT_FOUNDVariable not found

Definition at line 851 of file Variable.c.

◆ FlushHobVariableToFlash()

VOID FlushHobVariableToFlash ( IN CHAR16 *  VariableName,
IN EFI_GUID VendorGuid 
)

Flush the HOB variable to flash.

Parameters
[in]VariableNameName of variable has been updated or deleted.
[in]VendorGuidGuid of variable has been updated or deleted.

Definition at line 3283 of file Variable.c.

◆ GetFvbInfoByAddress()

EFI_STATUS GetFvbInfoByAddress ( IN EFI_PHYSICAL_ADDRESS  Address,
OUT EFI_HANDLE *FvbHandle  OPTIONAL,
OUT EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL **FvbProtocol  OPTIONAL 
)

Get the proper fvb handle and/or fvb protocol by the given Flash address.

Parameters
[in]AddressThe Flash address.
[out]FvbHandleIn output, if it is not NULL, it points to the proper FVB handle.
[out]FvbProtocolIn output, if it is not NULL, it points to the proper FVB protocol.

Definition at line 3811 of file Variable.c.

◆ GetHobVariableStore()

EFI_STATUS GetHobVariableStore ( IN EFI_GUID VariableGuid)

Get HOB variable store.

Parameters
[in]VariableGuidNV variable store signature.
Return values
EFI_SUCCESSFunction successfully executed.
EFI_OUT_OF_RESOURCESFail to allocate enough memory resource.

Definition at line 3621 of file Variable.c.

◆ GetIndexFromSupportedLangCodes()

UINTN GetIndexFromSupportedLangCodes ( IN CHAR8 *  SupportedLang,
IN CHAR8 *  Lang,
IN BOOLEAN  Iso639Language 
)

Get index from supported language codes according to language string.

This code is used to get corresponding index in supported language codes. It can handle RFC4646 and ISO639 language tags. In ISO639 language tags, take 3-characters as a delimitation to find matched string and calculate the index. In RFC4646 language tags, take semicolon as a delimitation to find matched string and calculate the index.

For example: SupportedLang = "engfraengfra" Lang = "eng" Iso639Language = TRUE The return value is "0". Another example: SupportedLang = "en;fr;en-US;fr-FR" Lang = "fr-FR" Iso639Language = FALSE The return value is "3".

Parameters
SupportedLangPlatform supported language codes.
LangConfigured language.
Iso639LanguageA bool value to signify if the handler is operated on ISO639 or RFC4646.
Return values
Theindex of language in the language codes.

Definition at line 930 of file Variable.c.

◆ GetLangFromSupportedLangCodes()

CHAR8 * GetLangFromSupportedLangCodes ( IN CHAR8 *  SupportedLang,
IN UINTN  Index,
IN BOOLEAN  Iso639Language 
)

Get language string from supported language codes according to index.

This code is used to get corresponding language strings in supported language codes. It can handle RFC4646 and ISO639 language tags. In ISO639 language tags, take 3-characters as a delimitation. Find language string according to the index. In RFC4646 language tags, take semicolon as a delimitation. Find language string according to the index.

For example: SupportedLang = "engfraengfra" Index = "1" Iso639Language = TRUE The return value is "fra". Another example: SupportedLang = "en;fr;en-US;fr-FR" Index = "1" Iso639Language = FALSE The return value is "fr".

Parameters
SupportedLangPlatform supported language codes.
IndexThe index in supported language codes.
Iso639LanguageA bool value to signify if the handler is operated on ISO639 or RFC4646.
Return values
Thelanguage string in the language codes.

Definition at line 1017 of file Variable.c.

◆ GetMaxVariableSize()

UINTN GetMaxVariableSize ( VOID  )

Get maximum variable size, covering both non-volatile and volatile variables.

Returns
Maximum variable size.

Definition at line 3257 of file Variable.c.

◆ InitializeVarErrorFlag()

VOID InitializeVarErrorFlag ( VOID  )

Initialize variable error flag.

Before EndOfDxe, the variable indicates the last boot variable error flag, then it means the last boot variable error flag must be got before EndOfDxe. After EndOfDxe, the variable indicates the current boot variable error flag, then it means the current boot variable error flag must be got after EndOfDxe.

Definition at line 362 of file Variable.c.

◆ InitializeVariableQuota()

VOID InitializeVariableQuota ( VOID  )

Initialize variable quota.

Definition at line 488 of file Variable.c.

◆ IsUserVariable()

BOOLEAN IsUserVariable ( IN VARIABLE_HEADER Variable)

Is user variable?

Parameters
[in]VariablePointer to variable header.
Return values
TRUEUser variable.
FALSESystem variable.

Definition at line 415 of file Variable.c.

◆ Reclaim()

EFI_STATUS Reclaim ( IN EFI_PHYSICAL_ADDRESS  VariableBase,
OUT UINTN LastVariableOffset,
IN BOOLEAN  IsVolatile,
IN OUT VARIABLE_POINTER_TRACK UpdatingPtrTrack,
IN VARIABLE_HEADER NewVariable,
IN UINTN  NewVariableSize 
)

Variable store garbage collection and reclaim operation.

Parameters
[in]VariableBaseBase address of variable store.
[out]LastVariableOffsetOffset of last variable.
[in]IsVolatileThe variable store is volatile or not; if it is non-volatile, need FTW.
[in,out]UpdatingPtrTrackPointer to updating variable pointer track structure.
[in]NewVariablePointer to new variable.
[in]NewVariableSizeNew variable size.
Returns
EFI_SUCCESS Reclaim operation has finished successfully.
EFI_OUT_OF_RESOURCES No enough memory resources or variable space.
Others Unexpect error happened during reclaim operation.

Definition at line 518 of file Variable.c.

◆ ReclaimForOS()

VOID ReclaimForOS ( VOID  )

This function reclaims variable storage if free size is below the threshold.

Caution: This function may be invoked at SMM mode. Care must be taken to make sure not security issue.

Definition at line 3202 of file Variable.c.

◆ RecordVarErrorFlag()

VOID RecordVarErrorFlag ( IN VAR_ERROR_FLAG  Flag,
IN CHAR16 *  VariableName,
IN EFI_GUID VendorGuid,
IN UINT32  Attributes,
IN UINTN  VariableSize 
)

Record variable error flag.

Parameters
[in]FlagVariable error flag to record.
[in]VariableNameName of variable.
[in]VendorGuidGuid of variable.
[in]AttributesAttributes of the variable.
[in]VariableSizeSize of the variable.

Definition at line 272 of file Variable.c.

◆ UpdateVariable()

EFI_STATUS UpdateVariable ( IN CHAR16 *  VariableName,
IN EFI_GUID VendorGuid,
IN VOID *  Data,
IN UINTN  DataSize,
IN UINT32 Attributes  OPTIONAL,
IN UINT32 KeyIndex  OPTIONAL,
IN UINT64 MonotonicCount  OPTIONAL,
IN OUT VARIABLE_POINTER_TRACK CacheVariable,
IN EFI_TIME *TimeStamp  OPTIONAL 
)

Update the variable region with Variable information. If EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS is set, index of associated public key is needed.

Parameters
[in]VariableNameName of variable.
[in]VendorGuidGuid of variable.
[in]DataVariable data.
[in]DataSizeSize of data. 0 means delete.
[in]AttributesAttributes of the variable.
[in]KeyIndexIndex of associated public key.
[in]MonotonicCountValue of associated monotonic count.
[in,out]CacheVariableThe variable information which is used to keep track of variable usage.
[in]TimeStampValue of associated TimeStamp.
Return values
EFI_SUCCESSThe update operation is success.
EFI_OUT_OF_RESOURCESVariable region is full, can not write other data into this region.

Definition at line 1678 of file Variable.c.

◆ UpdateVariableStore()

EFI_STATUS UpdateVariableStore ( IN VARIABLE_GLOBAL Global,
IN BOOLEAN  Volatile,
IN BOOLEAN  SetByIndex,
IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL Fvb,
IN UINTN  DataPtrIndex,
IN UINT32  DataSize,
IN UINT8 *  Buffer 
)

This function writes data to the FWH at the correct LBA even if the LBAs are fragmented.

Parameters
GlobalPointer to VARAIBLE_GLOBAL structure.
VolatilePoint out the Variable is Volatile or Non-Volatile.
SetByIndexTRUE if target pointer is given as index. FALSE if target pointer is absolute.
FvbPointer to the writable FVB protocol.
DataPtrIndexPointer to the Data from the end of VARIABLE_STORE_HEADER structure.
DataSizeSize of data to be written.
BufferPointer to the buffer from which data is written.
Return values
EFI_INVALID_PARAMETERParameters not valid.
EFI_UNSUPPORTEDFvb is a NULL for Non-Volatile variable update.
EFI_OUT_OF_RESOURCESThe remaining size is not enough.
EFI_SUCCESSVariable store successfully updated.

Definition at line 123 of file Variable.c.

◆ VariableCommonInitialize()

EFI_STATUS VariableCommonInitialize ( VOID  )

Initializes variable store area for non-volatile and volatile variable.

Return values
EFI_SUCCESSFunction successfully executed.
EFI_OUT_OF_RESOURCESFail to allocate enough memory resource.

Definition at line 3703 of file Variable.c.

◆ VariableGetBestLanguage()

CHAR8 *EFIAPI VariableGetBestLanguage ( IN CONST CHAR8 *  SupportedLanguages,
IN UINTN  Iso639Language,
  ... 
)

Returns a pointer to an allocated buffer that contains the best matching language from a set of supported languages.

This function supports both ISO 639-2 and RFC 4646 language codes, but language code types may not be mixed in a single call to this function. This function supports a variable argument list that allows the caller to pass in a prioritized list of language codes to test against all the language codes in SupportedLanguages.

If SupportedLanguages is NULL, then ASSERT().

Parameters
[in]SupportedLanguagesA pointer to a Null-terminated ASCII string that contains a set of language codes in the format specified by Iso639Language.
[in]Iso639LanguageIf not zero, then all language codes are assumed to be in ISO 639-2 format. If zero, then all language codes are assumed to be in RFC 4646 language format
[in]...A variable argument list that contains pointers to Null-terminated ASCII strings that contain one or more language codes in the format specified by Iso639Language. The first language code from each of these language code lists is used to determine if it is an exact or close match to any of the language codes in SupportedLanguages. Close matches only apply to RFC 4646 language codes, and the matching algorithm from RFC 4647 is used to determine if a close match is present. If an exact or close match is found, then the matching language code from SupportedLanguages is returned. If no matches are found, then the next variable argument parameter is evaluated. The variable argument list is terminated by a NULL.
Return values
NULLThe best matching language could not be found in SupportedLanguages.
NULLThere are not enough resources available to return the best matching language.
OtherA pointer to a Null-terminated ASCII string that is the best matching language in SupportedLanguages.

Definition at line 1118 of file Variable.c.

◆ VariableServiceGetNextVariableName()

EFI_STATUS EFIAPI VariableServiceGetNextVariableName ( IN OUT UINTN VariableNameSize,
IN OUT CHAR16 *  VariableName,
IN OUT EFI_GUID VendorGuid 
)

This code Finds the Next available variable.

Caution: This function may receive untrusted input. This function may be invoked in SMM mode. This function will do basic validation, before parse the data.

Parameters
VariableNameSizeThe size of the VariableName buffer. The size must be large enough to fit input string supplied in VariableName buffer.
VariableNamePointer to variable name.
VendorGuidVariable Vendor Guid.
Return values
EFI_SUCCESSThe function completed successfully.
EFI_NOT_FOUNDThe next variable was not found.
EFI_BUFFER_TOO_SMALLThe VariableNameSize is too small for the result. VariableNameSize has been updated with the size needed to complete the request.
EFI_INVALID_PARAMETERVariableNameSize is NULL.
EFI_INVALID_PARAMETERVariableName is NULL.
EFI_INVALID_PARAMETERVendorGuid is NULL.
EFI_INVALID_PARAMETERThe input values of VariableName and VendorGuid are not a name and GUID of an existing variable.
EFI_INVALID_PARAMETERNull-terminator is not found in the first VariableNameSize bytes of the input VariableName buffer.
EFI_DEVICE_ERRORThe variable could not be retrieved due to a hardware error.
EFI_UNSUPPORTEDAfter ExitBootServices() has been called, this return code may be returned if no variable storage is supported. The platform should describe this runtime service as unsupported at runtime via an EFI_RT_PROPERTIES_TABLE configuration table.

Definition at line 2502 of file Variable.c.

◆ VariableServiceGetVariable()

EFI_STATUS EFIAPI VariableServiceGetVariable ( IN CHAR16 *  VariableName,
IN EFI_GUID VendorGuid,
OUT UINT32 *Attributes  OPTIONAL,
IN OUT UINTN DataSize,
OUT VOID *Data  OPTIONAL 
)

This code finds variable in storage blocks (Volatile or Non-Volatile).

Caution: This function may receive untrusted input. This function may be invoked in SMM mode, and datasize is external input. This function will do basic validation, before parse the data.

Parameters
VariableNameName of Variable to be found.
VendorGuidVariable vendor GUID.
AttributesAttribute value of the variable found.
DataSizeSize of Data found. If size is less than the data, this value contains the required size.
DataThe buffer to return the contents of the variable. May be NULL with a zero DataSize in order to determine the size buffer needed.
Return values
EFI_SUCCESSThe function completed successfully.
EFI_NOT_FOUNDThe variable was not found.
EFI_BUFFER_TOO_SMALLThe DataSize is too small for the result.
EFI_INVALID_PARAMETERVariableName is NULL.
EFI_INVALID_PARAMETERVendorGuid is NULL.
EFI_INVALID_PARAMETERDataSize is NULL.
EFI_INVALID_PARAMETERThe DataSize is not too small and Data is NULL.
EFI_DEVICE_ERRORThe variable could not be retrieved due to a hardware error.
EFI_SECURITY_VIOLATIONThe variable could not be retrieved due to an authentication failure.
EFI_UNSUPPORTEDAfter ExitBootServices() has been called, this return code may be returned if no variable storage is supported. The platform should describe this runtime service as unsupported at runtime via an EFI_RT_PROPERTIES_TABLE configuration table.

Definition at line 2407 of file Variable.c.

◆ VariableServiceQueryVariableInfo()

EFI_STATUS EFIAPI VariableServiceQueryVariableInfo ( IN UINT32  Attributes,
OUT UINT64 *  MaximumVariableStorageSize,
OUT UINT64 *  RemainingVariableStorageSize,
OUT UINT64 *  MaximumVariableSize 
)

This code returns information about the EFI variables.

Caution: This function may receive untrusted input. This function may be invoked in SMM mode. This function will do basic validation, before parse the data.

Parameters
AttributesAttributes bitmask to specify the type of variables on which to return information.
MaximumVariableStorageSizePointer to the maximum size of the storage space available for the EFI variables associated with the attributes specified.
RemainingVariableStorageSizePointer to the remaining size of the storage space available for EFI variables associated with the attributes specified.
MaximumVariableSizePointer to the maximum size of an individual EFI variables associated with the attributes specified.
Returns
EFI_INVALID_PARAMETER An invalid combination of attribute bits was supplied.
EFI_SUCCESS Query successfully.
EFI_UNSUPPORTED The attribute is not supported on this platform.

Definition at line 3120 of file Variable.c.

◆ VariableServiceQueryVariableInfoInternal()

EFI_STATUS EFIAPI VariableServiceQueryVariableInfoInternal ( IN UINT32  Attributes,
OUT UINT64 *  MaximumVariableStorageSize,
OUT UINT64 *  RemainingVariableStorageSize,
OUT UINT64 *  MaximumVariableSize 
)

This code returns information about the EFI variables.

Caution: This function may receive untrusted input. This function may be invoked in SMM mode. This function will do basic validation, before parse the data.

Parameters
AttributesAttributes bitmask to specify the type of variables on which to return information.
MaximumVariableStorageSizePointer to the maximum size of the storage space available for the EFI variables associated with the attributes specified.
RemainingVariableStorageSizePointer to the remaining size of the storage space available for EFI variables associated with the attributes specified.
MaximumVariableSizePointer to the maximum size of an individual EFI variables associated with the attributes specified.
Returns
EFI_SUCCESS Query successfully.

Definition at line 2940 of file Variable.c.

◆ VariableServiceSetVariable()

EFI_STATUS EFIAPI VariableServiceSetVariable ( IN CHAR16 *  VariableName,
IN EFI_GUID VendorGuid,
IN UINT32  Attributes,
IN UINTN  DataSize,
IN VOID *  Data 
)

This code sets variable in storage blocks (Volatile or Non-Volatile).

Caution: This function may receive untrusted input. This function may be invoked in SMM mode, and datasize and data are external input. This function will do basic validation, before parse the data. This function will parse the authentication carefully to avoid security issues, like buffer overflow, integer overflow. This function will check attribute carefully to avoid authentication bypass.

Parameters
VariableNameName of Variable to be found.
VendorGuidVariable vendor GUID.
AttributesAttribute value of the variable found
DataSizeSize of Data found. If size is less than the data, this value contains the required size.
DataData pointer.
Return values
EFI_SUCCESSThe function completed successfully.
EFI_NOT_FOUNDThe variable was not found.
EFI_BUFFER_TOO_SMALLThe DataSize is too small for the result.
EFI_INVALID_PARAMETERVariableName is NULL.
EFI_INVALID_PARAMETERVendorGuid is NULL.
EFI_INVALID_PARAMETERDataSize is NULL.
EFI_INVALID_PARAMETERThe DataSize is not too small and Data is NULL.
EFI_DEVICE_ERRORThe variable could not be retrieved due to a hardware error.
EFI_SECURITY_VIOLATIONThe variable could not be retrieved due to an authentication failure.
EFI_UNSUPPORTEDAfter ExitBootServices() has been called, this return code may be returned if no variable storage is supported. The platform should describe this runtime service as unsupported at runtime via an EFI_RT_PROPERTIES_TABLE configuration table.

Definition at line 2612 of file Variable.c.

◆ VariableWriteServiceInitialize()

EFI_STATUS VariableWriteServiceInitialize ( VOID  )

Initializes variable write service.

Return values
EFI_SUCCESSFunction successfully executed.
OthersFail to initialize the variable service.

Definition at line 3415 of file Variable.c.

Variable Documentation

◆ gVariableInfo

VARIABLE_INFO_ENTRY* gVariableInfo = NULL

The memory entry used for variable statistics data.

Definition at line 49 of file Variable.c.

◆ mAuthContextIn

AUTH_VAR_LIB_CONTEXT_IN mAuthContextIn
Initial value:
= {
AUTH_VAR_LIB_CONTEXT_IN_STRUCT_VERSION,
0,
0,
}
EFI_STATUS EFIAPI VariableExLibGetScratchBuffer(IN OUT UINTN *ScratchBufferSize, OUT VOID **ScratchBuffer)
BOOLEAN EFIAPI VariableExLibAtRuntime(VOID)
BOOLEAN EFIAPI VariableExLibCheckRemainingSpaceForConsistency(IN UINT32 Attributes,...)
EFI_STATUS EFIAPI VariableExLibFindVariable(IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid, OUT AUTH_VARIABLE_INFO *AuthVariableInfo)
Definition: VariableExLib.c:32
EFI_STATUS EFIAPI VariableExLibUpdateVariable(IN AUTH_VARIABLE_INFO *AuthVariableInfo)
EFI_STATUS EFIAPI VariableExLibFindNextVariable(IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid, OUT AUTH_VARIABLE_INFO *AuthVariableInfo)
Definition: VariableExLib.c:92

Definition at line 81 of file Variable.c.

◆ mAuthContextOut

AUTH_VAR_LIB_CONTEXT_OUT mAuthContextOut

Definition at line 99 of file Variable.c.

◆ mCurrentBootVarErrFlag

VAR_ERROR_FLAG mCurrentBootVarErrFlag = VAR_ERROR_FLAG_NO_ERROR

Definition at line 65 of file Variable.c.

◆ mEndOfDxe

BOOLEAN mEndOfDxe = FALSE

The flag to indicate whether the platform has left the DXE phase of execution.

Definition at line 54 of file Variable.c.

◆ mNvFvHeaderCache

EFI_FIRMWARE_VOLUME_HEADER* mNvFvHeaderCache = NULL

Memory cache of Fv Header.

Definition at line 44 of file Variable.c.

◆ mNvVariableCache

VARIABLE_STORE_HEADER* mNvVariableCache = NULL

Define a memory cache that improves the search performance for a variable. For EmuNvMode == TRUE, it will be equal to NonVolatileVariableBase.

Definition at line 39 of file Variable.c.

◆ mRequestSource

VAR_CHECK_REQUEST_SOURCE mRequestSource = VarCheckFromUntrusted

It indicates the var check request source. In the implementation, DXE is regarded as untrusted, and SMM is trusted.

Definition at line 60 of file Variable.c.

◆ mVariableEntryProperty

VARIABLE_ENTRY_PROPERTY mVariableEntryProperty[]
Initial value:
= {
{
&gEdkiiVarErrorFlagGuid,
VAR_ERROR_FLAG_NAME,
{
VAR_CHECK_VARIABLE_PROPERTY_REVISION,
VAR_CHECK_VARIABLE_PROPERTY_READ_ONLY,
VARIABLE_ATTRIBUTE_NV_BS_RT,
sizeof (VAR_ERROR_FLAG),
sizeof (VAR_ERROR_FLAG)
}
},
}

Definition at line 67 of file Variable.c.

◆ mVariableModuleGlobal

VARIABLE_MODULE_GLOBAL* mVariableModuleGlobal

Definition at line 33 of file Variable.c.