]>
git.proxmox.com Git - mirror_edk2.git/blob - SecurityPkg/Library/SecureBootVariableLib/UnitTest/MockUefiLib.c
2 The UEFI Library provides functions and macros that simplify the development of
3 UEFI Drivers and UEFI Applications. These functions and macros help manage EFI
4 events, build simple locks utilizing EFI Task Priority Levels (TPLs), install
5 EFI Driver Model related protocols, manage Unicode string tables for UEFI Drivers,
6 and print messages on the console output and standard error devices.
8 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
9 SPDX-License-Identifier: BSD-2-Clause-Patent
15 #include <Library/DebugLib.h>
16 #include <Library/MemoryAllocationLib.h>
17 #include <Library/UefiRuntimeServicesTableLib.h>
20 Returns the status whether get the variable success. The function retrieves
21 variable through the UEFI Runtime Service GetVariable(). The
22 returned buffer is allocated using AllocatePool(). The caller is responsible
23 for freeing this buffer with FreePool().
25 If Name is NULL, then ASSERT().
26 If Guid is NULL, then ASSERT().
27 If Value is NULL, then ASSERT().
29 @param[in] Name The pointer to a Null-terminated Unicode string.
30 @param[in] Guid The pointer to an EFI_GUID structure
31 @param[out] Value The buffer point saved the variable info.
32 @param[out] Size The buffer size of the variable.
34 @return EFI_OUT_OF_RESOURCES Allocate buffer failed.
35 @return EFI_SUCCESS Find the specified variable.
36 @return Others Errors Return errors from call to gRT->GetVariable.
42 IN CONST CHAR16
*Name
,
43 IN CONST EFI_GUID
*Guid
,
45 OUT UINTN
*Size OPTIONAL
51 ASSERT (Name
!= NULL
&& Guid
!= NULL
&& Value
!= NULL
);
54 // Try to get the variable size.
62 Status
= gRT
->GetVariable ((CHAR16
*)Name
, (EFI_GUID
*)Guid
, NULL
, &BufferSize
, *Value
);
63 if (Status
!= EFI_BUFFER_TOO_SMALL
) {
68 // Allocate buffer to get the variable.
70 *Value
= AllocatePool (BufferSize
);
71 ASSERT (*Value
!= NULL
);
73 return EFI_OUT_OF_RESOURCES
;
77 // Get the variable data.
79 Status
= gRT
->GetVariable ((CHAR16
*)Name
, (EFI_GUID
*)Guid
, NULL
, &BufferSize
, *Value
);
80 if (EFI_ERROR (Status
)) {
92 /** Return the attributes of the variable.
94 Returns the status whether get the variable success. The function retrieves
95 variable through the UEFI Runtime Service GetVariable(). The
96 returned buffer is allocated using AllocatePool(). The caller is responsible
97 for freeing this buffer with FreePool(). The attributes are returned if
98 the caller provides a valid Attribute parameter.
100 If Name is NULL, then ASSERT().
101 If Guid is NULL, then ASSERT().
102 If Value is NULL, then ASSERT().
104 @param[in] Name The pointer to a Null-terminated Unicode string.
105 @param[in] Guid The pointer to an EFI_GUID structure
106 @param[out] Value The buffer point saved the variable info.
107 @param[out] Size The buffer size of the variable.
108 @param[out] Attr The pointer to the variable attributes as found in var store
110 @retval EFI_OUT_OF_RESOURCES Allocate buffer failed.
111 @retval EFI_SUCCESS Find the specified variable.
112 @retval Others Errors Return errors from call to gRT->GetVariable.
118 IN CONST CHAR16
*Name
,
119 IN CONST EFI_GUID
*Guid
,
121 OUT UINTN
*Size OPTIONAL
,
122 OUT UINT32
*Attr OPTIONAL
128 ASSERT (Name
!= NULL
&& Guid
!= NULL
&& Value
!= NULL
);
131 // Try to get the variable size.
143 Status
= gRT
->GetVariable ((CHAR16
*)Name
, (EFI_GUID
*)Guid
, Attr
, &BufferSize
, *Value
);
144 if (Status
!= EFI_BUFFER_TOO_SMALL
) {
149 // Allocate buffer to get the variable.
151 *Value
= AllocatePool (BufferSize
);
152 ASSERT (*Value
!= NULL
);
153 if (*Value
== NULL
) {
154 return EFI_OUT_OF_RESOURCES
;
158 // Get the variable data.
160 Status
= gRT
->GetVariable ((CHAR16
*)Name
, (EFI_GUID
*)Guid
, Attr
, &BufferSize
, *Value
);
161 if (EFI_ERROR (Status
)) {
174 Returns a pointer to an allocated buffer that contains the contents of a
175 variable retrieved through the UEFI Runtime Service GetVariable(). This
176 function always uses the EFI_GLOBAL_VARIABLE GUID to retrieve variables.
177 The returned buffer is allocated using AllocatePool(). The caller is
178 responsible for freeing this buffer with FreePool().
180 If Name is NULL, then ASSERT().
181 If Value is NULL, then ASSERT().
183 @param[in] Name The pointer to a Null-terminated Unicode string.
184 @param[out] Value The buffer point saved the variable info.
185 @param[out] Size The buffer size of the variable.
187 @return EFI_OUT_OF_RESOURCES Allocate buffer failed.
188 @return EFI_SUCCESS Find the specified variable.
189 @return Others Errors Return errors from call to gRT->GetVariable.
194 GetEfiGlobalVariable2 (
195 IN CONST CHAR16
*Name
,
197 OUT UINTN
*Size OPTIONAL
200 return GetVariable2 (Name
, &gEfiGlobalVariableGuid
, Value
, Size
);