OpenCore  1.0.4
OpenCore Bootloader
Loading...
Searching...
No Matches
Variable.h File Reference
#include <PiDxe.h>
#include <Protocol/VariableWrite.h>
#include <Protocol/FaultTolerantWrite.h>
#include <Protocol/FirmwareVolumeBlock.h>
#include <Protocol/Variable.h>
#include <Protocol/VariableLock.h>
#include <Protocol/VarCheck.h>
#include <Library/PcdLib.h>
#include <Library/HobLib.h>
#include <Library/UefiDriverEntryPoint.h>
#include <Library/DxeServicesTableLib.h>
#include <Library/UefiRuntimeLib.h>
#include <Library/DebugLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/UefiLib.h>
#include <Library/BaseLib.h>
#include <Library/SynchronizationLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/AuthVariableLib.h>
#include <Library/VarCheckLib.h>
#include <Guid/GlobalVariable.h>
#include <Guid/EventGroup.h>
#include <Guid/VariableFormat.h>
#include <Guid/SystemNvDataGuid.h>
#include <Guid/FaultTolerantWrite.h>
#include <Guid/VarErrorFlag.h>
#include "PrivilegePolymorphic.h"

Go to the source code of this file.

Data Structures

struct  VARIABLE_RUNTIME_CACHE
 
struct  VARIABLE_RUNTIME_CACHE_CONTEXT
 
struct  VARIABLE_POINTER_TRACK
 
struct  VARIABLE_GLOBAL
 
struct  VARIABLE_MODULE_GLOBAL
 

Macros

#define NV_STORAGE_VARIABLE_BASE
 
#define EFI_VARIABLE_ATTRIBUTES_MASK
 
#define ISO_639_2_ENTRY_SIZE   3
 

Enumerations

enum  VARIABLE_STORE_TYPE { VariableStoreTypeVolatile , VariableStoreTypeHob , VariableStoreTypeNv , VariableStoreTypeMax }
 

Functions

VOID FlushHobVariableToFlash (IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid)
 
EFI_STATUS FtwVariableSpace (IN EFI_PHYSICAL_ADDRESS VariableBase, IN VARIABLE_STORE_HEADER *VariableBuffer)
 
EFI_STATUS FindVariable (IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid, OUT VARIABLE_POINTER_TRACK *PtrTrack, IN VARIABLE_GLOBAL *Global, IN BOOLEAN IgnoreRtCheck)
 
BOOLEAN EFIAPI CheckRemainingSpaceForConsistencyInternal (IN UINT32 Attributes, IN VA_LIST Marker)
 
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 *Variable, IN EFI_TIME *TimeStamp OPTIONAL)
 
BOOLEAN AtRuntime (VOID)
 
EFI_LOCK * InitializeLock (IN OUT EFI_LOCK *Lock, IN EFI_TPL Priority)
 
VOID AcquireLockOnlyAtBootTime (IN EFI_LOCK *Lock)
 
VOID ReleaseLockOnlyAtBootTime (IN EFI_LOCK *Lock)
 
EFI_STATUS GetFvbByHandle (IN EFI_HANDLE FvBlockHandle, OUT EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL **FvBlock)
 
EFI_STATUS GetFvbCountAndBuffer (OUT UINTN *NumberHandles, OUT EFI_HANDLE **Buffer)
 
EFI_STATUS VariableCommonInitialize (VOID)
 
VOID ReclaimForOS (VOID)
 
UINTN GetMaxVariableSize (VOID)
 
EFI_STATUS VariableWriteServiceInitialize (VOID)
 
EFI_STATUS GetFtwProtocol (OUT VOID **FtwProtocol)
 
EFI_STATUS GetFvbInfoByAddress (IN EFI_PHYSICAL_ADDRESS Address, OUT EFI_HANDLE *FvbHandle OPTIONAL, OUT EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL **FvbProtocol 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)
 
EFI_STATUS EFIAPI VariableLockRequestToLock (IN CONST EDKII_VARIABLE_LOCK_PROTOCOL *This, IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid)
 
EFI_STATUS EFIAPI VarCheckRegisterSetVariableCheckHandler (IN VAR_CHECK_SET_VARIABLE_CHECK_HANDLER Handler)
 
EFI_STATUS EFIAPI VarCheckVariablePropertySet (IN CHAR16 *Name, IN EFI_GUID *Guid, IN VAR_CHECK_VARIABLE_PROPERTY *VariableProperty)
 
EFI_STATUS EFIAPI VarCheckVariablePropertyGet (IN CHAR16 *Name, IN EFI_GUID *Guid, OUT VAR_CHECK_VARIABLE_PROPERTY *VariableProperty)
 
VOID InitializeVariableQuota (VOID)
 
EFI_STATUS EFIAPI VariableExLibFindVariable (IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid, OUT AUTH_VARIABLE_INFO *AuthVariableInfo)
 
EFI_STATUS EFIAPI VariableExLibFindNextVariable (IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid, OUT AUTH_VARIABLE_INFO *AuthVariableInfo)
 
EFI_STATUS EFIAPI VariableExLibUpdateVariable (IN AUTH_VARIABLE_INFO *AuthVariableInfo)
 
EFI_STATUS EFIAPI VariableExLibGetScratchBuffer (IN OUT UINTN *ScratchBufferSize, OUT VOID **ScratchBuffer)
 
BOOLEAN EFIAPI VariableExLibCheckRemainingSpaceForConsistency (IN UINT32 Attributes,...)
 
BOOLEAN EFIAPI VariableExLibAtRuntime (VOID)
 

Variables

VARIABLE_MODULE_GLOBALmVariableModuleGlobal
 
EFI_FIRMWARE_VOLUME_HEADER * mNvFvHeaderCache
 
VARIABLE_STORE_HEADER * mNvVariableCache
 
VARIABLE_INFO_ENTRY * gVariableInfo
 
BOOLEAN mEndOfDxe
 
VAR_CHECK_REQUEST_SOURCE mRequestSource
 
AUTH_VAR_LIB_CONTEXT_OUT mAuthContextOut
 

Detailed Description

The internal header file includes the common header files, defines internal structure and functions used by Variable modules.

Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent

Definition in file Variable.h.

Macro Definition Documentation

◆ EFI_VARIABLE_ATTRIBUTES_MASK

#define EFI_VARIABLE_ATTRIBUTES_MASK
Value:
(EFI_VARIABLE_NON_VOLATILE |\
EFI_VARIABLE_BOOTSERVICE_ACCESS | \
EFI_VARIABLE_RUNTIME_ACCESS | \
EFI_VARIABLE_HARDWARE_ERROR_RECORD | \
EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS | \
EFI_VARIABLE_APPEND_WRITE)

Definition at line 48 of file Variable.h.

◆ ISO_639_2_ENTRY_SIZE

#define ISO_639_2_ENTRY_SIZE   3

The size of a 3 character ISO639 language code.

Definition at line 58 of file Variable.h.

◆ NV_STORAGE_VARIABLE_BASE

#define NV_STORAGE_VARIABLE_BASE
Value:
(EFI_PHYSICAL_ADDRESS)\
(PcdGet64 (PcdFlashNvStorageVariableBase64) != 0 ? \
PcdGet64 (PcdFlashNvStorageVariableBase64) : \
PcdGet32 (PcdFlashNvStorageVariableBase))

Definition at line 43 of file Variable.h.

Enumeration Type Documentation

◆ VARIABLE_STORE_TYPE

Enumerator
VariableStoreTypeVolatile 
VariableStoreTypeHob 
VariableStoreTypeNv 
VariableStoreTypeMax 

Definition at line 60 of file Variable.h.

Function Documentation

◆ AcquireLockOnlyAtBootTime()

VOID AcquireLockOnlyAtBootTime ( IN EFI_LOCK * Lock)

Acquires lock only at boot time. Simply returns at runtime.

This is a temperary function that will be removed when EfiAcquireLock() in UefiLib can handle the call in UEFI Runtimer driver in RT phase. It calls EfiAcquireLock() at boot time, and simply returns at runtime.

Parameters
LockA pointer to the lock to acquire.

Definition at line 122 of file VariableDxe.c.

◆ AtRuntime()

BOOLEAN AtRuntime ( VOID )

Return TRUE if ExitBootServices () has been called.

Return values
TRUEIf ExitBootServices () has been called.

Definition at line 77 of file VariableDxe.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 1242 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 853 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 3294 of file Variable.c.

◆ FtwVariableSpace()

EFI_STATUS FtwVariableSpace ( IN EFI_PHYSICAL_ADDRESS VariableBase,
IN VARIABLE_STORE_HEADER * VariableBuffer )

Writes a buffer to variable storage space, in the working block.

This function writes a buffer to variable storage space into a firmware volume block device. The destination is specified by the parameter VariableBase. Fault Tolerant Write protocol is used for writing.

Parameters
VariableBaseBase address of the variable to write.
VariableBufferPoint to the variable data buffer.
Return values
EFI_SUCCESSThe function completed successfully.
EFI_NOT_FOUNDFail to locate Fault Tolerant Write protocol.
EFI_ABORTEDThe function could not complete successfully.

Writes a buffer to variable storage space, in the working block.

This function writes a buffer to variable storage space into a firmware volume block device. The destination is specified by parameter VariableBase. Fault Tolerant Write protocol is used for writing.

Parameters
VariableBaseBase address of variable to write
VariableBufferPoint to the variable data buffer.
Return values
EFI_SUCCESSThe function completed successfully.
EFI_NOT_FOUNDFail to locate Fault Tolerant Write protocol.
EFI_ABORTEDThe function could not complete successfully.

Definition at line 104 of file Reclaim.c.

◆ GetFtwProtocol()

EFI_STATUS GetFtwProtocol ( OUT VOID ** FtwProtocol)

Retrieve the SMM Fault Tolerent Write protocol interface.

Parameters
[out]FtwProtocolThe interface of SMM Ftw protocol
Return values
EFI_SUCCESSThe SMM SAR protocol instance was found and returned in SarProtocol.
EFI_NOT_FOUNDThe SMM SAR protocol instance was not found.
EFI_INVALID_PARAMETERSarProtocol is NULL.

Retrieve the Fault Tolerent Write protocol interface.

Parameters
[out]FtwProtocolThe interface of Ftw protocol
Return values
EFI_SUCCESSThe FTW protocol instance was found and returned in FtwProtocol.
EFI_NOT_FOUNDThe FTW protocol instance was not found.
EFI_INVALID_PARAMETERSarProtocol is NULL.

Definition at line 164 of file VariableDxe.c.

◆ GetFvbByHandle()

EFI_STATUS GetFvbByHandle ( IN EFI_HANDLE FvBlockHandle,
OUT EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL ** FvBlock )

Retrieve the FVB protocol interface by HANDLE.

Parameters
[in]FvBlockHandleThe handle of FVB protocol that provides services for reading, writing, and erasing the target block.
[out]FvBlockThe interface of FVB protocol
Return values
EFI_SUCCESSThe interface information for the specified protocol was returned.
EFI_UNSUPPORTEDThe device does not support the FVB protocol.
EFI_INVALID_PARAMETERFvBlockHandle is not a valid EFI_HANDLE or FvBlock is NULL.

Definition at line 194 of file VariableDxe.c.

◆ GetFvbCountAndBuffer()

EFI_STATUS GetFvbCountAndBuffer ( OUT UINTN * NumberHandles,
OUT EFI_HANDLE ** Buffer )

Function returns an array of handles that support the FVB protocol in a buffer allocated from pool.

Parameters
[out]NumberHandlesThe number of handles returned in Buffer.
[out]BufferA pointer to the buffer to return the requested array of handles that support FVB protocol.
Return values
EFI_SUCCESSThe array of handles was returned in Buffer, and the number of handles in Buffer was returned in NumberHandles.
EFI_NOT_FOUNDNo FVB handle was found.
EFI_OUT_OF_RESOURCESThere is not enough pool memory to store the matching results.
EFI_INVALID_PARAMETERNumberHandles is NULL or Buffer is NULL.

Definition at line 225 of file VariableDxe.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 3822 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 3268 of file Variable.c.

◆ InitializeLock()

EFI_LOCK * InitializeLock ( IN OUT EFI_LOCK * Lock,
IN EFI_TPL Priority )

Initializes a basic mutual exclusion lock.

This function initializes a basic mutual exclusion lock to the released state and returns the lock. Each lock provides mutual exclusion access at its task priority level. Since there is no preemption or multiprocessor support in EFI, acquiring the lock only consists of raising to the locks TPL. If Lock is NULL, then ASSERT(). If Priority is not a valid TPL value, then ASSERT().

Parameters
LockA pointer to the lock data structure to initialize.
PriorityEFI TPL is associated with the lock.
Returns
The lock.

Definition at line 101 of file VariableDxe.c.

◆ InitializeVariableQuota()

VOID InitializeVariableQuota ( VOID )

Initialize variable quota.

Definition at line 490 of file Variable.c.

◆ ReclaimForOS()

VOID ReclaimForOS ( VOID )

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

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 3213 of file Variable.c.

◆ ReleaseLockOnlyAtBootTime()

VOID ReleaseLockOnlyAtBootTime ( IN EFI_LOCK * Lock)

Releases lock only at boot time. Simply returns at runtime.

This is a temperary function which will be removed when EfiReleaseLock() in UefiLib can handle the call in UEFI Runtimer driver in RT phase. It calls EfiReleaseLock() at boot time and simply returns at runtime.

Parameters
LockA pointer to the lock to release.

Definition at line 144 of file VariableDxe.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]VariableThe variable information that 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, cannot write other data into this region.

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 1680 of file Variable.c.

◆ VarCheckRegisterSetVariableCheckHandler()

EFI_STATUS EFIAPI VarCheckRegisterSetVariableCheckHandler ( IN VAR_CHECK_SET_VARIABLE_CHECK_HANDLER Handler)

Register SetVariable check handler.

Parameters
[in]HandlerPointer to check handler.
Return values
EFI_SUCCESSThe SetVariable check handler was registered successfully.
EFI_INVALID_PARAMETERHandler is NULL.
EFI_ACCESS_DENIEDEFI_END_OF_DXE_EVENT_GROUP_GUID or EFI_EVENT_GROUP_READY_TO_BOOT has already been signaled.
EFI_OUT_OF_RESOURCESThere is not enough resource for the SetVariable check handler register request.
EFI_UNSUPPORTEDThis interface is not implemented. For example, it is unsupported in VarCheck protocol if both VarCheck and SmmVarCheck protocols are present.

Definition at line 29 of file VarCheck.c.

◆ VarCheckVariablePropertyGet()

EFI_STATUS EFIAPI VarCheckVariablePropertyGet ( IN CHAR16 * Name,
IN EFI_GUID * Guid,
OUT VAR_CHECK_VARIABLE_PROPERTY * VariableProperty )

Variable property get.

Parameters
[in]NamePointer to the variable name.
[in]GuidPointer to the vendor GUID.
[out]VariablePropertyPointer to the output variable property.
Return values
EFI_SUCCESSThe property of variable specified by the Name and Guid was got successfully.
EFI_INVALID_PARAMETERName, Guid or VariableProperty is NULL, or Name is an empty string.
EFI_NOT_FOUNDThe property of variable specified by the Name and Guid was not found.

Definition at line 88 of file VarCheck.c.

◆ VarCheckVariablePropertySet()

EFI_STATUS EFIAPI VarCheckVariablePropertySet ( IN CHAR16 * Name,
IN EFI_GUID * Guid,
IN VAR_CHECK_VARIABLE_PROPERTY * VariableProperty )

Variable property set.

Parameters
[in]NamePointer to the variable name.
[in]GuidPointer to the vendor GUID.
[in]VariablePropertyPointer to the input variable property.
Return values
EFI_SUCCESSThe property of variable specified by the Name and Guid was set successfully.
EFI_INVALID_PARAMETERName, Guid or VariableProperty is NULL, or Name is an empty string, or the fields of VariableProperty are not valid.
EFI_ACCESS_DENIEDEFI_END_OF_DXE_EVENT_GROUP_GUID or EFI_EVENT_GROUP_READY_TO_BOOT has already been signaled.
EFI_OUT_OF_RESOURCESThere is not enough resource for the variable property set request.

Definition at line 59 of file VarCheck.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 3714 of file Variable.c.

◆ VariableExLibAtRuntime()

BOOLEAN EFIAPI VariableExLibAtRuntime ( VOID )

Return TRUE if at OS runtime.

Return values
TRUEIf at OS runtime.
FALSEIf at boot time.

Definition at line 253 of file VariableExLib.c.

◆ VariableExLibCheckRemainingSpaceForConsistency()

BOOLEAN EFIAPI VariableExLibCheckRemainingSpaceForConsistency ( 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 227 of file VariableExLib.c.

◆ VariableExLibFindNextVariable()

EFI_STATUS EFIAPI VariableExLibFindNextVariable ( IN CHAR16 * VariableName,
IN EFI_GUID * VendorGuid,
OUT AUTH_VARIABLE_INFO * AuthVariableInfo )

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

This code finds next 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.

Parameters
[in]VariableNameName of the variable to be found.
[in]VendorGuidVariable vendor GUID to be found.
[out]AuthVariableInfoPointer to AUTH_VARIABLE_INFO structure for output of the next 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 92 of file VariableExLib.c.

◆ VariableExLibFindVariable()

EFI_STATUS EFIAPI VariableExLibFindVariable ( IN CHAR16 * VariableName,
IN EFI_GUID * VendorGuid,
OUT AUTH_VARIABLE_INFO * AuthVariableInfo )

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.

Parameters
[in]VariableNameName of the variable to be found.
[in]VendorGuidVariable vendor GUID to be found.
[out]AuthVariableInfoPointer to AUTH_VARIABLE_INFO structure for output of the variable found.
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 32 of file VariableExLib.c.

◆ VariableExLibGetScratchBuffer()

EFI_STATUS EFIAPI VariableExLibGetScratchBuffer ( IN OUT UINTN * ScratchBufferSize,
OUT VOID ** ScratchBuffer )

Get scratch buffer.

Parameters
[in,out]ScratchBufferSizeScratch buffer size. If input size is greater than the maximum supported buffer size, this value contains the maximum supported buffer size as output.
[out]ScratchBufferPointer to scratch buffer address.
Return values
EFI_SUCCESSGet scratch buffer successfully.
EFI_UNSUPPORTEDIf input size is greater than the maximum supported buffer size.

Definition at line 189 of file VariableExLib.c.

◆ VariableExLibUpdateVariable()

EFI_STATUS EFIAPI VariableExLibUpdateVariable ( IN AUTH_VARIABLE_INFO * AuthVariableInfo)

Update the variable region with Variable information.

Parameters
[in]AuthVariableInfoPointer AUTH_VARIABLE_INFO structure for input of the variable.
Return values
EFI_SUCCESSThe update operation is success.
EFI_INVALID_PARAMETERInvalid parameter.
EFI_WRITE_PROTECTEDVariable is write-protected.
EFI_OUT_OF_RESOURCESThere is not enough resource.

Definition at line 155 of file VariableExLib.c.

◆ VariableLockRequestToLock()

EFI_STATUS EFIAPI VariableLockRequestToLock ( IN CONST EDKII_VARIABLE_LOCK_PROTOCOL * This,
IN CHAR16 * VariableName,
IN EFI_GUID * VendorGuid )

Mark a variable that will become read-only after leaving the DXE phase of execution.

Parameters
[in]ThisThe VARIABLE_LOCK_PROTOCOL instance.
[in]VariableNameA pointer to the variable name that will be made read-only subsequently.
[in]VendorGuidA pointer to the vendor GUID that will be made read-only subsequently.
Return values
EFI_SUCCESSThe variable specified by the VariableName and the VendorGuid was marked as pending to be read-only.
EFI_INVALID_PARAMETERVariableName or VendorGuid is NULL. Or VariableName is an empty string.
EFI_ACCESS_DENIEDEFI_END_OF_DXE_EVENT_GROUP_GUID or EFI_EVENT_GROUP_READY_TO_BOOT has already been signaled.
EFI_OUT_OF_RESOURCESThere is not enough resource to hold the lock request.

DEPRECATED. THIS IS ONLY HERE AS A CONVENIENCE WHILE PORTING. Mark a variable that will become read-only after leaving the DXE phase of execution. Write request coming from SMM environment through EFI_SMM_VARIABLE_PROTOCOL is allowed.

Parameters
[in]ThisThe VARIABLE_LOCK_PROTOCOL instance.
[in]VariableNameA pointer to the variable name that will be made read-only subsequently.
[in]VendorGuidA pointer to the vendor GUID that will be made read-only subsequently.
Return values
EFI_SUCCESSThe variable specified by the VariableName and the VendorGuid was marked as pending to be read-only.
EFI_INVALID_PARAMETERVariableName or VendorGuid is NULL. Or VariableName is an empty string.
EFI_ACCESS_DENIEDEFI_END_OF_DXE_EVENT_GROUP_GUID or EFI_EVENT_GROUP_READY_TO_BOOT has already been signaled.
EFI_OUT_OF_RESOURCESThere is not enough resource to hold the lock request.

Definition at line 42 of file VariableLockRequestToLock.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.

Definition at line 2525 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 and data are 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.
Returns
EFI_INVALID_PARAMETER Invalid parameter.
EFI_SUCCESS Find the specified variable.
EFI_NOT_FOUND Not found.
EFI_BUFFER_TO_SMALL DataSize is too small for the result.

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.
Returns
EFI_INVALID_PARAMETER Invalid parameter.
EFI_SUCCESS Find the specified variable.
EFI_NOT_FOUND Not found.
EFI_BUFFER_TO_SMALL DataSize is too small for the result.

Definition at line 2435 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 3131 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 2951 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.
Returns
EFI_INVALID_PARAMETER Invalid parameter.
EFI_SUCCESS Set successfully.
EFI_OUT_OF_RESOURCES Resource not enough to set variable.
EFI_NOT_FOUND Not found.
EFI_WRITE_PROTECTED Variable is read-only.

Definition at line 2627 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 3426 of file Variable.c.

Variable Documentation

◆ gVariableInfo

VARIABLE_INFO_ENTRY* gVariableInfo
extern

The memory entry used for variable statistics data.

Definition at line 51 of file Variable.c.

◆ mAuthContextOut

AUTH_VAR_LIB_CONTEXT_OUT mAuthContextOut
extern

Definition at line 101 of file Variable.c.

◆ mEndOfDxe

BOOLEAN mEndOfDxe
extern

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

Definition at line 56 of file Variable.c.

◆ mNvFvHeaderCache

EFI_FIRMWARE_VOLUME_HEADER* mNvFvHeaderCache
extern

Memory cache of Fv Header.

Definition at line 46 of file Variable.c.

◆ mNvVariableCache

VARIABLE_STORE_HEADER* mNvVariableCache
extern

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

Definition at line 41 of file Variable.c.

◆ mRequestSource

VAR_CHECK_REQUEST_SOURCE mRequestSource
extern

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

Definition at line 62 of file Variable.c.

◆ mVariableModuleGlobal

VARIABLE_MODULE_GLOBAL* mVariableModuleGlobal
extern

Definition at line 35 of file Variable.c.