56 OUT UINT32 *Attributes,
65 BytePtr = (UINT8 *)Buffer;
68 *NameSize = *(UINT32 *)(BytePtr + Offset);
69 Offset = Offset +
sizeof (UINT32);
71 if (Offset > MaxSize) {
72 return EFI_INVALID_PARAMETER;
75 *Name = (CHAR16 *)(BytePtr + Offset);
76 Offset = Offset + *(UINT32 *)BytePtr;
77 if (Offset > MaxSize) {
78 return EFI_INVALID_PARAMETER;
81 *Guid = (
EFI_GUID *)(BytePtr + Offset);
83 if (Offset > MaxSize) {
84 return EFI_INVALID_PARAMETER;
87 *Attributes = *(UINT32 *)(BytePtr + Offset);
88 Offset = Offset +
sizeof (UINT32);
89 if (Offset > MaxSize) {
90 return EFI_INVALID_PARAMETER;
93 *DataSize = *(UINT32 *)(BytePtr + Offset);
94 Offset = Offset +
sizeof (UINT32);
95 if (Offset > MaxSize) {
96 return EFI_INVALID_PARAMETER;
99 *Data = (VOID *)(BytePtr + Offset);
100 Offset = Offset + *DataSize;
101 if (Offset > MaxSize) {
102 return EFI_INVALID_PARAMETER;
126 IN VOID *CallbackContext,
131 RETURN_STATUS Status;
138 UINT32 AlignedNameMaxSize;
146 AlignedNameMaxSize = 0;
155 !EFI_ERROR (Status) && (TotalSizeUsed < MaxSize);
159 (VOID *)((UINT8 *)Buffer + TotalSizeUsed),
160 (MaxSize - TotalSizeUsed),
169 if (EFI_ERROR (Status)) {
177 if (NameSize > AlignedNameMaxSize) {
178 if (AlignedName !=
NULL) {
185 if (AlignedName ==
NULL) {
186 return EFI_OUT_OF_RESOURCES;
189 CopyMem (AlignedName, Name, NameSize);
191 TotalSizeUsed = TotalSizeUsed + SizeUsed;
196 Status = (*CallbackFunction)(
206 if (AlignedName !=
NULL) {
213 if (TotalSizeUsed != MaxSize) {
216 "Deserialize variables error: TotalSizeUsed(%Lu) != MaxSize(%Lu)\n",
217 (UINT64)TotalSizeUsed,
220 return EFI_INVALID_PARAMETER;
229IterateVariablesCallbackNop (
231 IN CHAR16 *VariableName,
233 IN UINT32 Attributes,
244IterateVariablesCallbackSetInInstance (
246 IN CHAR16 *VariableName,
248 IN UINT32 Attributes,
270IterateVariablesCallbackSetSystemVariable (
272 IN CHAR16 *VariableName,
274 IN UINT32 Attributes,
284 Status =
gRT->SetVariable (
292 if ((Status == EFI_SECURITY_VIOLATION) && ((Attributes & AuthMask) != 0)) {
295 "%a: setting authenticated variable \"%s\" "
296 "failed with EFI_SECURITY_VIOLATION, ignoring\n",
301 }
else if (Status == EFI_WRITE_PROTECTED) {
304 "%a: setting ReadOnly variable \"%s\" "
305 "failed with EFI_WRITE_PROTECTED, ignoring\n",
317EnsureExtraBufferSpace (
325 NewSize = Instance->DataSize + Size;
326 if (NewSize <= Instance->BufferSize) {
333 NewSize = 2 * NewSize;
336 if (NewBuffer ==
NULL) {
340 if (Instance->BufferPtr !=
NULL) {
341 CopyMem (NewBuffer, Instance->BufferPtr, Instance->DataSize);
345 Instance->BufferPtr = NewBuffer;
346 Instance->BufferSize = NewSize;
361 ASSERT (Instance !=
NULL);
362 ASSERT (Data !=
NULL);
364 NewSize = Instance->DataSize + Size;
365 ASSERT ((Instance->DataSize + Size) <= Instance->BufferSize);
368 (VOID *)(((UINT8 *)(Instance->BufferPtr)) + Instance->DataSize),
373 Instance->DataSize = NewSize;
400 New->Signature = SV_SIGNATURE;
425 Instance = SV_FROM_HANDLE (Handle);
427 if (Instance->Signature != SV_SIGNATURE) {
431 Instance->Signature = 0;
433 if (Instance->BufferPtr !=
NULL) {
467 RETURN_STATUS Status;
475 IterateVariablesCallbackNop,
486 IterateVariablesCallbackSetInInstance,
520 RETURN_STATUS Status;
521 UINTN VariableNameBufferSize;
522 UINTN VariableNameSize;
523 CHAR16 *VariableName;
525 UINTN VariableDataBufferSize;
526 UINTN VariableDataSize;
528 UINT32 VariableAttributes;
534 VariableNameBufferSize =
sizeof (CHAR16);
537 VariableDataBufferSize = 0;
544 VariableNameSize = VariableNameBufferSize;
545 Status =
gRT->GetNextVariableName (
550 if (Status == EFI_BUFFER_TOO_SMALL) {
557 if (NewBuffer ==
NULL) {
558 Status = EFI_OUT_OF_RESOURCES;
562 CopyMem (NewBuffer, VariableName, VariableNameBufferSize);
563 if (VariableName !=
NULL) {
567 VariableName = NewBuffer;
568 VariableNameBufferSize = VariableNameSize;
573 Status =
gRT->GetNextVariableName (
580 if (EFI_ERROR (Status)) {
581 if (Status == EFI_NOT_FOUND) {
591 VariableDataSize = VariableDataBufferSize;
592 Status =
gRT->GetVariable (
599 if (Status == EFI_BUFFER_TOO_SMALL) {
604 if (VariableDataBufferSize != 0) {
607 VariableDataBufferSize = 0;
611 if (VariableData ==
NULL) {
612 Status = EFI_OUT_OF_RESOURCES;
616 VariableDataBufferSize = VariableDataSize;
621 Status =
gRT->GetVariable (
630 if (EFI_ERROR (Status)) {
637 Status = (*CallbackFunction)(
645 if (EFI_ERROR (Status)) {
650 if (VariableName !=
NULL) {
654 if (VariableData !=
NULL) {
686 Instance = SV_FROM_HANDLE (Handle);
688 if ((Instance->BufferPtr !=
NULL) && (Instance->DataSize != 0)) {
720 IterateVariablesCallbackSetSystemVariable,
747 IN CHAR16 *VariableName,
749 IN UINT32 Attributes,
754 RETURN_STATUS Status;
756 UINT32 SerializedNameSize;
757 UINT32 SerializedDataSize;
758 UINTN SerializedSize;
760 Instance = SV_FROM_HANDLE (Handle);
762 if ((Instance->Signature != SV_SIGNATURE) ||
763 (VariableName ==
NULL) || (VendorGuid ==
NULL) || (Data ==
NULL))
767 SerializedNameSize = (UINT32)
StrSize (VariableName);
770 sizeof (SerializedNameSize) +
772 sizeof (*VendorGuid) +
773 sizeof (Attributes) +
774 sizeof (SerializedDataSize) +
777 Status = EnsureExtraBufferSpace (
788 AppendToBuffer (Instance, (VOID *)&SerializedNameSize,
sizeof (SerializedNameSize));
793 AppendToBuffer (Instance, (VOID *)VariableName, SerializedNameSize);
798 AppendToBuffer (Instance, (VOID *)VendorGuid,
sizeof (*VendorGuid));
803 AppendToBuffer (Instance, (VOID *)&Attributes,
sizeof (Attributes));
808 SerializedDataSize = (UINT32)DataSize;
809 AppendToBuffer (Instance, (VOID *)&SerializedDataSize,
sizeof (SerializedDataSize));
814 AppendToBuffer (Instance, Data, DataSize);
852 Instance = SV_FROM_HANDLE (Handle);
858 if (*Size < Instance->DataSize) {
859 *Size = Instance->DataSize;
863 if (Buffer ==
NULL) {
867 *Size = Instance->DataSize;
868 CopyMem (Buffer, Instance->BufferPtr, Instance->DataSize);
UINTN EFIAPI StrSize(IN CONST CHAR16 *String)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
RETURN_STATUS(EFIAPI * VARIABLE_SERIALIZATION_ITERATION_CALLBACK)(IN VOID *Context, IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid, IN UINT32 Attributes, IN UINTN DataSize, IN VOID *Data)
EFI_RUNTIME_SERVICES * gRT
#define RETURN_BUFFER_TOO_SMALL
#define RETURN_ERROR(StatusCode)
#define RETURN_OUT_OF_RESOURCES
#define RETURN_INVALID_PARAMETER
#define DEBUG(Expression)
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
RETURN_STATUS EFIAPI SerializeVariablesIterateSystemVariables(IN VARIABLE_SERIALIZATION_ITERATION_CALLBACK CallbackFunction, IN VOID *Context)
RETURN_STATUS EFIAPI SerializeVariablesFreeInstance(IN EFI_HANDLE Handle)
RETURN_STATUS EFIAPI SerializeVariablesNewInstanceFromBuffer(OUT EFI_HANDLE *Handle, IN VOID *Buffer, IN UINTN Size)
RETURN_STATUS EFIAPI SerializeVariablesAddVariable(IN EFI_HANDLE Handle, IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid, IN UINT32 Attributes, IN UINTN DataSize, IN VOID *Data)
RETURN_STATUS EFIAPI SerializeVariablesToBuffer(IN EFI_HANDLE Handle, OUT VOID *Buffer, IN OUT UINTN *Size)
RETURN_STATUS EFIAPI SerializeVariablesNewInstance(OUT EFI_HANDLE *Handle)
STATIC EFI_STATUS IterateVariablesInBuffer(IN VARIABLE_SERIALIZATION_ITERATION_CALLBACK CallbackFunction, IN VOID *CallbackContext, IN VOID *Buffer, IN UINTN MaxSize)
RETURN_STATUS EFIAPI SerializeVariablesSetSerializedVariables(IN EFI_HANDLE Handle)
RETURN_STATUS EFIAPI SerializeVariablesIterateInstanceVariables(IN EFI_HANDLE Handle, IN VARIABLE_SERIALIZATION_ITERATION_CALLBACK CallbackFunction, IN VOID *Context)
STATIC EFI_STATUS UnpackVariableFromBuffer(IN VOID *Buffer, IN UINTN MaxSize, OUT CHAR16 **Name, OUT UINT32 *NameSize, OUT EFI_GUID **Guid, OUT UINT32 *Attributes, OUT UINT32 *DataSize, OUT VOID **Data, OUT UINTN *SizeUsed)
#define EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS
#define EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS
VOID EFIAPI CallbackFunction(IN EFI_EVENT Event, IN VOID *Context)