TianoCore EDK2 master
Loading...
Searching...
No Matches
MockUefiLib.c
Go to the documentation of this file.
1
13#include <Uefi.h>
14
15#include <Library/DebugLib.h>
18
40EFIAPI
42 IN CONST CHAR16 *Name,
43 IN CONST EFI_GUID *Guid,
44 OUT VOID **Value,
45 OUT UINTN *Size OPTIONAL
46 )
47{
48 EFI_STATUS Status;
49 UINTN BufferSize;
50
51 ASSERT (Name != NULL && Guid != NULL && Value != NULL);
52
53 //
54 // Try to get the variable size.
55 //
56 BufferSize = 0;
57 *Value = NULL;
58 if (Size != NULL) {
59 *Size = 0;
60 }
61
62 Status = gRT->GetVariable ((CHAR16 *)Name, (EFI_GUID *)Guid, NULL, &BufferSize, *Value);
63 if (Status != EFI_BUFFER_TOO_SMALL) {
64 return Status;
65 }
66
67 //
68 // Allocate buffer to get the variable.
69 //
70 *Value = AllocatePool (BufferSize);
71 ASSERT (*Value != NULL);
72 if (*Value == NULL) {
73 return EFI_OUT_OF_RESOURCES;
74 }
75
76 //
77 // Get the variable data.
78 //
79 Status = gRT->GetVariable ((CHAR16 *)Name, (EFI_GUID *)Guid, NULL, &BufferSize, *Value);
80 if (EFI_ERROR (Status)) {
81 FreePool (*Value);
82 *Value = NULL;
83 }
84
85 if (Size != NULL) {
86 *Size = BufferSize;
87 }
88
89 return Status;
90}
91
116EFIAPI
118 IN CONST CHAR16 *Name,
119 IN CONST EFI_GUID *Guid,
120 OUT VOID **Value,
121 OUT UINTN *Size OPTIONAL,
122 OUT UINT32 *Attr OPTIONAL
123 )
124{
125 EFI_STATUS Status;
126 UINTN BufferSize;
127
128 ASSERT (Name != NULL && Guid != NULL && Value != NULL);
129
130 //
131 // Try to get the variable size.
132 //
133 BufferSize = 0;
134 *Value = NULL;
135 if (Size != NULL) {
136 *Size = 0;
137 }
138
139 if (Attr != NULL) {
140 *Attr = 0;
141 }
142
143 Status = gRT->GetVariable ((CHAR16 *)Name, (EFI_GUID *)Guid, Attr, &BufferSize, *Value);
144 if (Status != EFI_BUFFER_TOO_SMALL) {
145 return Status;
146 }
147
148 //
149 // Allocate buffer to get the variable.
150 //
151 *Value = AllocatePool (BufferSize);
152 ASSERT (*Value != NULL);
153 if (*Value == NULL) {
154 return EFI_OUT_OF_RESOURCES;
155 }
156
157 //
158 // Get the variable data.
159 //
160 Status = gRT->GetVariable ((CHAR16 *)Name, (EFI_GUID *)Guid, Attr, &BufferSize, *Value);
161 if (EFI_ERROR (Status)) {
162 FreePool (*Value);
163 *Value = NULL;
164 }
165
166 if (Size != NULL) {
167 *Size = BufferSize;
168 }
169
170 return Status;
171}
172
193EFIAPI
195 IN CONST CHAR16 *Name,
196 OUT VOID **Value,
197 OUT UINTN *Size OPTIONAL
198 )
199{
200 return GetVariable2 (Name, &gEfiGlobalVariableGuid, Value, Size);
201}
UINT64 UINTN
VOID EFIAPI FreePool(IN VOID *Buffer)
EFI_RUNTIME_SERVICES * gRT
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
EFI_STATUS EFIAPI GetEfiGlobalVariable2(IN CONST CHAR16 *Name, OUT VOID **Value, OUT UINTN *Size OPTIONAL)
Definition: MockUefiLib.c:194
EFI_STATUS EFIAPI GetVariable2(IN CONST CHAR16 *Name, IN CONST EFI_GUID *Guid, OUT VOID **Value, OUT UINTN *Size OPTIONAL)
Definition: MockUefiLib.c:41
EFI_STATUS EFIAPI GetVariable3(IN CONST CHAR16 *Name, IN CONST EFI_GUID *Guid, OUT VOID **Value, OUT UINTN *Size OPTIONAL, OUT UINT32 *Attr OPTIONAL)
Definition: MockUefiLib.c:117
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
Definition: Base.h:213