Reads and returns value of NVRAM variable. */
| 96 | |
| 97 | /** Reads and returns value of NVRAM variable. */ |
| 98 | VOID *GetNvramVariable( |
| 99 | IN CONST CHAR16 *VariableName, |
| 100 | IN EFI_GUID *VendorGuid, |
| 101 | OUT UINT32 *Attributes OPTIONAL, |
| 102 | OUT UINTN *DataSize OPTIONAL) |
| 103 | { |
| 104 | EFI_STATUS Status; |
| 105 | VOID *Data = NULL; |
| 106 | // |
| 107 | // Pass in a zero size buffer to find the required buffer size. |
| 108 | // |
| 109 | UINTN IntDataSize = 0; |
| 110 | |
| 111 | Status = gRT->GetVariable (VariableName, VendorGuid, Attributes, &IntDataSize, NULL); |
| 112 | if (IntDataSize == 0) { |
| 113 | return NULL; |
| 114 | } |
| 115 | |
| 116 | if (Status == EFI_BUFFER_TOO_SMALL) { |
| 117 | // |
| 118 | // Allocate the buffer to return |
| 119 | // |
| 120 | Data = (__typeof__(Data))AllocateZeroPool(IntDataSize + 1); |
| 121 | if (Data != NULL) { |
| 122 | // |
| 123 | // Read variable into the allocated buffer. |
| 124 | // |
| 125 | Status = gRT->GetVariable (VariableName, VendorGuid, Attributes, &IntDataSize, Data); |
| 126 | if (EFI_ERROR(Status)) { |
| 127 | FreePool(Data); |
| 128 | IntDataSize = 0; |
| 129 | Data = NULL; |
| 130 | } |
| 131 | } |
| 132 | } |
| 133 | if (DataSize != NULL) { |
| 134 | *DataSize = IntDataSize; |
| 135 | } |
| 136 | return Data; |
| 137 | } |
| 138 | |
| 139 | /** Reads and returns value of NVRAM variable. */ |
| 140 | XString8 GetNvramVariableAsXString8( |
no test coverage detected