18BOOLEAN mVarCheckLibEndOfDxe =
FALSE;
20#define VAR_CHECK_TABLE_SIZE 0x8
22UINTN mVarCheckLibEndOfDxeCallbackCount = 0;
23UINTN mVarCheckLibEndOfDxeCallbackMaxCount = 0;
24VAR_CHECK_END_OF_DXE_CALLBACK *mVarCheckLibEndOfDxeCallback =
NULL;
26UINTN mVarCheckLibAddressPointerCount = 0;
27UINTN mVarCheckLibAddressPointerMaxCount = 0;
28VOID ***mVarCheckLibAddressPointer =
NULL;
30UINTN mNumberOfVarCheckHandler = 0;
31UINTN mMaxNumberOfVarCheckHandler = 0;
32VAR_CHECK_SET_VARIABLE_CHECK_HANDLER *mVarCheckHandlerTable =
NULL;
40UINTN mNumberOfVarCheckVariable = 0;
41UINTN mMaxNumberOfVarCheckVariable = 0;
49 &gEfiGlobalVariableGuid,
56 &gEfiGlobalVariableGuid,
63 &gEfiGlobalVariableGuid,
70 &gEfiGlobalVariableGuid,
77 &gEfiGlobalVariableGuid,
78 L
"PlatformRecovery####",
84 &gEfiHardwareErrorVariableGuid,
112 return (BOOLEAN)((Char >= L
'0' && Char <= L
'9') || (Char >= L
'A' && Char <= L
'F'));
127 IN CHAR16 *VariableName,
129 IN BOOLEAN WildcardMatch
135 NameLength =
StrLen (VariableName) - 4;
136 for (Index = 0; Index <
sizeof (mVarCheckVariableWithWildcardName)/
sizeof (mVarCheckVariableWithWildcardName[0]); Index++) {
137 if (
CompareGuid (mVarCheckVariableWithWildcardName[Index].Guid, VendorGuid)) {
139 if ((
StrLen (VariableName) ==
StrLen (mVarCheckVariableWithWildcardName[Index].Name)) &&
140 (
StrnCmp (VariableName, mVarCheckVariableWithWildcardName[Index].Name, NameLength) == 0) &&
146 return &mVarCheckVariableWithWildcardName[Index].VariableProperty;
150 if (
StrCmp (mVarCheckVariableWithWildcardName[Index].Name, VariableName) == 0) {
151 return &mVarCheckVariableWithWildcardName[Index].VariableProperty;
173 IN BOOLEAN WildcardMatch
178 CHAR16 *VariableName;
180 for (Index = 0; Index < mNumberOfVarCheckVariable; Index++) {
182 VariableName = (CHAR16 *)((
UINTN)Entry +
sizeof (*Entry));
184 return &Entry->VariableProperty;
216 if (*CurrentNumber == *MaxNumber) {
221 *MaxNumber *
sizeof (
UINTN),
222 (*MaxNumber + VAR_CHECK_TABLE_SIZE) *
sizeof (
UINTN),
229 if (TempTable ==
NULL) {
230 return EFI_OUT_OF_RESOURCES;
237 *MaxNumber += VAR_CHECK_TABLE_SIZE;
243 (*Table)[*CurrentNumber] = Entry;
265 IN VAR_CHECK_END_OF_DXE_CALLBACK Callback
270 if (Callback ==
NULL) {
271 return EFI_INVALID_PARAMETER;
274 if (mVarCheckLibEndOfDxe) {
275 return EFI_ACCESS_DENIED;
279 (
UINTN **)&mVarCheckLibEndOfDxeCallback,
280 &mVarCheckLibEndOfDxeCallbackMaxCount,
281 &mVarCheckLibEndOfDxeCallbackCount,
285 DEBUG ((DEBUG_INFO,
"VarCheckLibRegisterEndOfDxeCallback - 0x%x %r\n", Callback, Status));
312 for (Index = 0; Index < mVarCheckLibEndOfDxeCallbackCount; Index++) {
316 mVarCheckLibEndOfDxeCallback[Index]();
319 if (mVarCheckLibEndOfDxeCallback !=
NULL) {
323 mVarCheckLibEndOfDxeCallbackCount = 0;
324 mVarCheckLibEndOfDxeCallbackMaxCount = 0;
325 FreePool ((VOID *)mVarCheckLibEndOfDxeCallback);
326 mVarCheckLibEndOfDxeCallback =
NULL;
329 mVarCheckLibEndOfDxe =
TRUE;
331 if (AddressPointerCount ==
NULL) {
332 if (mVarCheckLibAddressPointer !=
NULL) {
336 mVarCheckLibAddressPointerCount = 0;
337 mVarCheckLibAddressPointerMaxCount = 0;
338 FreePool ((VOID *)mVarCheckLibAddressPointer);
339 mVarCheckLibAddressPointer =
NULL;
349 TotalCount = mVarCheckLibAddressPointerCount + (mNumberOfVarCheckHandler + 1) + (mNumberOfVarCheckVariable + 1);
351 mVarCheckLibAddressPointerMaxCount *
sizeof (VOID **),
352 TotalCount *
sizeof (VOID **),
353 (VOID *)mVarCheckLibAddressPointer
356 if (TempTable !=
NULL) {
357 mVarCheckLibAddressPointer = (VOID ***)TempTable;
362 mVarCheckLibAddressPointer[mVarCheckLibAddressPointerCount++] = (VOID **)&mVarCheckHandlerTable;
363 for (Index = 0; Index < mNumberOfVarCheckHandler; Index++) {
364 mVarCheckLibAddressPointer[mVarCheckLibAddressPointerCount++] = (VOID **)&mVarCheckHandlerTable[Index];
370 mVarCheckLibAddressPointer[mVarCheckLibAddressPointerCount++] = (VOID **)&mVarCheckVariableTable;
371 for (Index = 0; Index < mNumberOfVarCheckVariable; Index++) {
372 mVarCheckLibAddressPointer[mVarCheckLibAddressPointerCount++] = (VOID **)&mVarCheckVariableTable[Index];
375 ASSERT (mVarCheckLibAddressPointerCount == TotalCount);
376 mVarCheckLibAddressPointerMaxCount = mVarCheckLibAddressPointerCount;
379 *AddressPointerCount = mVarCheckLibAddressPointerCount;
380 return mVarCheckLibAddressPointer;
399 IN VOID **AddressPointer
404 if (AddressPointer ==
NULL) {
405 return EFI_INVALID_PARAMETER;
408 if (mVarCheckLibEndOfDxe) {
409 return EFI_ACCESS_DENIED;
413 (
UINTN **)&mVarCheckLibAddressPointer,
414 &mVarCheckLibAddressPointerMaxCount,
415 &mVarCheckLibAddressPointerCount,
416 (
UINTN)AddressPointer
419 DEBUG ((DEBUG_INFO,
"VarCheckLibRegisterAddressPointer - 0x%x %r\n", AddressPointer, Status));
441 IN VAR_CHECK_SET_VARIABLE_CHECK_HANDLER Handler
446 if (Handler ==
NULL) {
447 return EFI_INVALID_PARAMETER;
450 if (mVarCheckLibEndOfDxe) {
451 return EFI_ACCESS_DENIED;
455 (
UINTN **)&mVarCheckHandlerTable,
456 &mMaxNumberOfVarCheckHandler,
457 &mNumberOfVarCheckHandler,
461 DEBUG ((DEBUG_INFO,
"VarCheckLibRegisterSetVariableCheckHandler - 0x%x %r\n", Handler, Status));
491 CHAR16 *VariableName;
494 if ((Name ==
NULL) || (Name[0] == 0) || (Guid ==
NULL)) {
495 return EFI_INVALID_PARAMETER;
498 if (VariableProperty ==
NULL) {
499 return EFI_INVALID_PARAMETER;
502 if (VariableProperty->Revision != VAR_CHECK_VARIABLE_PROPERTY_REVISION) {
503 return EFI_INVALID_PARAMETER;
506 if (mVarCheckLibEndOfDxe) {
507 return EFI_ACCESS_DENIED;
516 if (Property !=
NULL) {
517 CopyMem (Property, VariableProperty,
sizeof (*VariableProperty));
521 return EFI_OUT_OF_RESOURCES;
524 VariableName = (CHAR16 *)((
UINTN)Entry +
sizeof (*Entry));
527 CopyMem (&Entry->VariableProperty, VariableProperty, sizeof (*VariableProperty));
530 (
UINTN **)&mVarCheckVariableTable,
531 &mMaxNumberOfVarCheckVariable,
532 &mNumberOfVarCheckVariable,
536 if (EFI_ERROR (Status)) {
566 if ((Name ==
NULL) || (Name[0] == 0) || (Guid ==
NULL)) {
567 return EFI_INVALID_PARAMETER;
570 if (VariableProperty ==
NULL) {
571 return EFI_INVALID_PARAMETER;
580 if ((Property !=
NULL) && (Property->Revision == VAR_CHECK_VARIABLE_PROPERTY_REVISION)) {
581 CopyMem (VariableProperty, Property,
sizeof (*VariableProperty));
585 return EFI_NOT_FOUND;
608 IN CHAR16 *VariableName,
610 IN UINT32 Attributes,
613 IN VAR_CHECK_REQUEST_SOURCE RequestSource
620 if (!mVarCheckLibEndOfDxe) {
633 if ((Property !=
NULL) && (Property->Revision == VAR_CHECK_VARIABLE_PROPERTY_REVISION)) {
634 if ((RequestSource != VarCheckFromTrusted) && ((Property->Property & VAR_CHECK_VARIABLE_PROPERTY_READ_ONLY) != 0)) {
635 DEBUG ((DEBUG_INFO,
"Variable Check ReadOnly variable fail %r - %g:%s\n", EFI_WRITE_PROTECTED, VendorGuid, VariableName));
636 return EFI_WRITE_PROTECTED;
639 if (!((((Attributes & EFI_VARIABLE_APPEND_WRITE) == 0) && (DataSize == 0)) || (Attributes == 0))) {
643 if ((Property->Attributes != 0) && ((Attributes & (~EFI_VARIABLE_APPEND_WRITE)) != Property->Attributes)) {
644 DEBUG ((DEBUG_INFO,
"Variable Check Attributes(0x%08x to 0x%08x) fail %r - %g:%s\n", Property->Attributes, Attributes, EFI_INVALID_PARAMETER, VendorGuid, VariableName));
645 return EFI_INVALID_PARAMETER;
649 if ((DataSize < Property->MinSize) || (DataSize > Property->MaxSize)) {
650 DEBUG ((DEBUG_INFO,
"Variable Check DataSize fail(0x%x not in 0x%x - 0x%x) %r - %g:%s\n", DataSize, Property->MinSize, Property->MaxSize, EFI_INVALID_PARAMETER, VendorGuid, VariableName));
651 return EFI_INVALID_PARAMETER;
657 for (Index = 0; Index < mNumberOfVarCheckHandler; Index++) {
658 Status = mVarCheckHandlerTable[Index](
665 if ((Status == EFI_WRITE_PROTECTED) && (RequestSource == VarCheckFromTrusted)) {
673 if (EFI_ERROR (Status)) {
674 DEBUG ((DEBUG_INFO,
"Variable Check handler fail %r - %g:%s\n", Status, VendorGuid, VariableName));
UINTN EFIAPI StrSize(IN CONST CHAR16 *String)
RETURN_STATUS EFIAPI StrCpyS(OUT CHAR16 *Destination, IN UINTN DestMax, IN CONST CHAR16 *Source)
INTN EFIAPI StrCmp(IN CONST CHAR16 *FirstString, IN CONST CHAR16 *SecondString)
INTN EFIAPI StrnCmp(IN CONST CHAR16 *FirstString, IN CONST CHAR16 *SecondString, IN UINTN Length)
UINTN EFIAPI StrLen(IN CONST CHAR16 *String)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
BOOLEAN EFIAPI CompareGuid(IN CONST GUID *Guid1, IN CONST GUID *Guid2)
GUID *EFIAPI CopyGuid(OUT GUID *DestinationGuid, IN CONST GUID *SourceGuid)
VOID EFIAPI FreePool(IN VOID *Buffer)
VOID *EFIAPI ReallocateRuntimePool(IN UINTN OldSize, IN UINTN NewSize, IN VOID *OldBuffer OPTIONAL)
VOID *EFIAPI AllocateRuntimeZeroPool(IN UINTN AllocationSize)
#define DEBUG(Expression)
VAR_CHECK_VARIABLE_PROPERTY * VariablePropertyGetWithWildcardName(IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid, IN BOOLEAN WildcardMatch)
VOID ***EFIAPI VarCheckLibInitializeAtEndOfDxe(IN OUT UINTN *AddressPointerCount OPTIONAL)
EFI_STATUS EFIAPI VarCheckLibRegisterAddressPointer(IN VOID **AddressPointer)
VAR_CHECK_VARIABLE_PROPERTY * VariablePropertyGetFunction(IN CHAR16 *Name, IN EFI_GUID *Guid, IN BOOLEAN WildcardMatch)
EFI_STATUS EFIAPI VarCheckLibRegisterSetVariableCheckHandler(IN VAR_CHECK_SET_VARIABLE_CHECK_HANDLER Handler)
EFI_STATUS EFIAPI VarCheckLibRegisterEndOfDxeCallback(IN VAR_CHECK_END_OF_DXE_CALLBACK Callback)
EFI_STATUS EFIAPI VarCheckLibVariablePropertySet(IN CHAR16 *Name, IN EFI_GUID *Guid, IN VAR_CHECK_VARIABLE_PROPERTY *VariableProperty)
BOOLEAN EFIAPI VarCheckInternalIsHexaDecimalDigitCharacter(IN CHAR16 Char)
EFI_STATUS VarCheckAddTableEntry(IN OUT UINTN **Table, IN OUT UINTN *MaxNumber, IN OUT UINTN *CurrentNumber, IN UINTN Entry)
EFI_STATUS EFIAPI VarCheckLibSetVariableCheck(IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid, IN UINT32 Attributes, IN UINTN DataSize, IN VOID *Data, IN VAR_CHECK_REQUEST_SOURCE RequestSource)
EFI_STATUS EFIAPI VarCheckLibVariablePropertyGet(IN CHAR16 *Name, IN EFI_GUID *Guid, OUT VAR_CHECK_VARIABLE_PROPERTY *VariableProperty)