]> git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/Library/SerializeVariablesLib/SerializeVariablesLib.c
OvmfPkg: Remove variables that are set, but not used
[mirror_edk2.git] / OvmfPkg / Library / SerializeVariablesLib / SerializeVariablesLib.c
1 /** @file
2 Serialize Variables Library implementation
3
4 Copyright (c) 2004 - 2011, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #include "SerializeVariablesLib.h"
16
17 /**
18 Serialization format:
19
20 The SerializeVariablesLib interface does not specify a format
21 for the serialization of the variable data. This library uses
22 a packed array of a non-uniformly sized data structure elements.
23
24 Each variable is stored (packed) as:
25 UINT32 VendorNameSize; // Name size in bytes
26 CHAR16 VendorName[?]; // The variable unicode name including the
27 // null terminating character.
28 EFI_GUID VendorGuid; // The variable GUID
29 UINT32 DataSize; // The size of variable data in bytes
30 UINT8 Data[?]; // The variable data
31
32 **/
33
34
35 /**
36 Unpacks the next variable from the buffer
37
38 @param[in] Buffer - Buffer pointing to the next variable instance
39 On subsequent calls, the pointer should be incremented
40 by the returned SizeUsed value.
41 @param[in] MaxSize - Max allowable size for the variable data
42 On subsequent calls, this should be decremented
43 by the returned SizeUsed value.
44 @param[out] Name - Variable name string (address in Buffer)
45 @param[out] NameSize - Size of Name in bytes
46 @param[out] Guid - GUID of variable (address in Buffer)
47 @param[out] Attributes - Attributes of variable
48 @param[out] Data - Buffer containing Data for variable (address in Buffer)
49 @param[out] DataSize - Size of Data in bytes
50 @param[out] SizeUsed - Total size used for this variable instance in Buffer
51
52 @return EFI_STATUS based on the success or failure of the operation
53
54 **/
55 STATIC
56 EFI_STATUS
57 UnpackVariableFromBuffer (
58 IN VOID *Buffer,
59 IN UINTN MaxSize,
60 OUT CHAR16 **Name,
61 OUT UINT32 *NameSize,
62 OUT EFI_GUID **Guid,
63 OUT UINT32 *Attributes,
64 OUT UINT32 *DataSize,
65 OUT VOID **Data,
66 OUT UINTN *SizeUsed
67 )
68 {
69 UINT8 *BytePtr;
70 UINTN Offset;
71
72 BytePtr = (UINT8*)Buffer;
73 Offset = 0;
74
75 *NameSize = *(UINT32*) (BytePtr + Offset);
76 Offset = Offset + sizeof (UINT32);
77
78 if (Offset > MaxSize) {
79 return EFI_INVALID_PARAMETER;
80 }
81
82 *Name = (CHAR16*) (BytePtr + Offset);
83 Offset = Offset + *(UINT32*)BytePtr;
84 if (Offset > MaxSize) {
85 return EFI_INVALID_PARAMETER;
86 }
87
88 *Guid = (EFI_GUID*) (BytePtr + Offset);
89 Offset = Offset + sizeof (EFI_GUID);
90 if (Offset > MaxSize) {
91 return EFI_INVALID_PARAMETER;
92 }
93
94 *Attributes = *(UINT32*) (BytePtr + Offset);
95 Offset = Offset + sizeof (UINT32);
96 if (Offset > MaxSize) {
97 return EFI_INVALID_PARAMETER;
98 }
99
100 *DataSize = *(UINT32*) (BytePtr + Offset);
101 Offset = Offset + sizeof (UINT32);
102 if (Offset > MaxSize) {
103 return EFI_INVALID_PARAMETER;
104 }
105
106 *Data = (VOID*) (BytePtr + Offset);
107 Offset = Offset + *DataSize;
108 if (Offset > MaxSize) {
109 return EFI_INVALID_PARAMETER;
110 }
111
112 *SizeUsed = Offset;
113
114 return EFI_SUCCESS;
115 }
116
117
118 /**
119 Iterates through the variables in the buffer, and calls a callback
120 function for each variable found.
121
122 @param[in] CallbackFunction - Function called for each variable instance
123 @param[in] Context - Passed to each call of CallbackFunction
124 @param[in] Buffer - Buffer containing serialized variables
125 @param[in] MaxSize - Size of Buffer in bytes
126
127 @return EFI_STATUS based on the success or failure of the operation
128
129 **/
130 STATIC
131 EFI_STATUS
132 IterateVariablesInBuffer (
133 IN VARIABLE_SERIALIZATION_ITERATION_CALLBACK CallbackFunction,
134 IN VOID *CallbackContext,
135 IN VOID *Buffer,
136 IN UINTN MaxSize
137 )
138 {
139 RETURN_STATUS Status;
140 UINTN TotalSizeUsed;
141 UINTN SizeUsed;
142
143 CHAR16 *Name;
144 UINT32 NameSize;
145 CHAR16 *AlignedName;
146 UINT32 AlignedNameMaxSize;
147 EFI_GUID *Guid;
148 UINT32 Attributes;
149 UINT32 DataSize;
150 VOID *Data;
151
152 SizeUsed = 0;
153 AlignedName = NULL;
154 AlignedNameMaxSize = 0;
155 Name = NULL;
156 Guid = NULL;
157 Attributes = 0;
158 DataSize = 0;
159 Data = NULL;
160
161 for (
162 Status = EFI_SUCCESS, TotalSizeUsed = 0;
163 !EFI_ERROR (Status) && (TotalSizeUsed < MaxSize);
164 ) {
165 Status = UnpackVariableFromBuffer (
166 (VOID*) ((UINT8*) Buffer + TotalSizeUsed),
167 (MaxSize - TotalSizeUsed),
168 &Name,
169 &NameSize,
170 &Guid,
171 &Attributes,
172 &DataSize,
173 &Data,
174 &SizeUsed
175 );
176 if (EFI_ERROR (Status)) {
177 return Status;
178 }
179
180 //
181 // We copy the name to a separately allocated buffer,
182 // to be sure it is 16-bit aligned.
183 //
184 if (NameSize > AlignedNameMaxSize) {
185 if (AlignedName != NULL) {
186 FreePool (AlignedName);
187 }
188 AlignedName = AllocatePool (NameSize);
189 }
190 if (AlignedName == NULL) {
191 return EFI_OUT_OF_RESOURCES;
192 }
193 CopyMem (AlignedName, Name, NameSize);
194
195 TotalSizeUsed = TotalSizeUsed + SizeUsed;
196
197 //
198 // Run the callback function
199 //
200 Status = (*CallbackFunction) (
201 CallbackContext,
202 AlignedName,
203 Guid,
204 Attributes,
205 DataSize,
206 Data
207 );
208
209 }
210
211 if (AlignedName != NULL) {
212 FreePool (AlignedName);
213 }
214
215 //
216 // Make sure the entire buffer was used, or else return an error
217 //
218 if (TotalSizeUsed != MaxSize) {
219 DEBUG ((
220 EFI_D_ERROR,
221 "Deserialize variables error: TotalSizeUsed(%d) != MaxSize(%d)\n",
222 TotalSizeUsed,
223 MaxSize
224 ));
225 return EFI_INVALID_PARAMETER;
226 }
227
228 return EFI_SUCCESS;
229 }
230
231
232 STATIC
233 RETURN_STATUS
234 EFIAPI
235 IterateVariablesCallbackNop (
236 IN VOID *Context,
237 IN CHAR16 *VariableName,
238 IN EFI_GUID *VendorGuid,
239 IN UINT32 Attributes,
240 IN UINTN DataSize,
241 IN VOID *Data
242 )
243 {
244 return RETURN_SUCCESS;
245 }
246
247
248 STATIC
249 RETURN_STATUS
250 EFIAPI
251 IterateVariablesCallbackSetInInstance (
252 IN VOID *Context,
253 IN CHAR16 *VariableName,
254 IN EFI_GUID *VendorGuid,
255 IN UINT32 Attributes,
256 IN UINTN DataSize,
257 IN VOID *Data
258 )
259 {
260 EFI_HANDLE Instance;
261
262 Instance = (EFI_HANDLE) Context;
263
264 return SerializeVariablesAddVariable (
265 Instance,
266 VariableName,
267 VendorGuid,
268 Attributes,
269 DataSize,
270 Data
271 );
272 }
273
274
275 STATIC
276 RETURN_STATUS
277 EFIAPI
278 IterateVariablesCallbackSetSystemVariable (
279 IN VOID *Context,
280 IN CHAR16 *VariableName,
281 IN EFI_GUID *VendorGuid,
282 IN UINT32 Attributes,
283 IN UINTN DataSize,
284 IN VOID *Data
285 )
286 {
287 return gRT->SetVariable (
288 VariableName,
289 VendorGuid,
290 Attributes,
291 DataSize,
292 Data
293 );
294 }
295
296
297 STATIC
298 RETURN_STATUS
299 EnsureExtraBufferSpace (
300 IN SV_INSTANCE *Instance,
301 IN UINTN Size
302 )
303 {
304 VOID *NewBuffer;
305 UINTN NewSize;
306
307 NewSize = Instance->DataSize + Size;
308 if (NewSize <= Instance->BufferSize) {
309 return RETURN_SUCCESS;
310 }
311
312 //
313 // Double the required size to lessen the need to re-allocate in the future
314 //
315 NewSize = 2 * NewSize;
316
317 NewBuffer = AllocatePool (NewSize);
318 if (NewBuffer == NULL) {
319 return RETURN_OUT_OF_RESOURCES;
320 }
321
322 if (Instance->BufferPtr != NULL) {
323 CopyMem (NewBuffer, Instance->BufferPtr, Instance->DataSize);
324 FreePool (Instance->BufferPtr);
325 }
326
327 Instance->BufferPtr = NewBuffer;
328 Instance->BufferSize = NewSize;
329
330 return RETURN_SUCCESS;
331 }
332
333
334 STATIC
335 VOID
336 AppendToBuffer (
337 IN SV_INSTANCE *Instance,
338 IN VOID *Data,
339 IN UINTN Size
340 )
341 {
342 UINTN NewSize;
343
344 ASSERT (Instance != NULL);
345 ASSERT (Data != NULL);
346
347 NewSize = Instance->DataSize + Size;
348 ASSERT ((Instance->DataSize + Size) <= Instance->BufferSize);
349
350 CopyMem (
351 (VOID*) (((UINT8*) (Instance->BufferPtr)) + Instance->DataSize),
352 Data,
353 Size
354 );
355
356 Instance->DataSize = NewSize;
357 }
358
359
360 /**
361 Creates a new variable serialization instance
362
363 @param[out] Handle - Handle for a variable serialization instance
364
365 @retval RETURN_SUCCESS - The variable serialization instance was
366 successfully created.
367 @retval RETURN_OUT_OF_RESOURCES - There we not enough resources to
368 create the variable serialization instance.
369
370 **/
371 RETURN_STATUS
372 EFIAPI
373 SerializeVariablesNewInstance (
374 OUT EFI_HANDLE *Handle
375 )
376 {
377 SV_INSTANCE *New;
378
379 New = AllocateZeroPool (sizeof (*New));
380 if (New == NULL) {
381 return RETURN_OUT_OF_RESOURCES;
382 }
383
384 New->Signature = SV_SIGNATURE;
385
386 *Handle = (EFI_HANDLE) New;
387 return RETURN_SUCCESS;
388 }
389
390
391 /**
392 Free memory associated with a variable serialization instance
393
394 @param[in] Handle - Handle for a variable serialization instance
395
396 @retval RETURN_SUCCESS - The variable serialization instance was
397 successfully freed.
398 @retval RETURN_INVALID_PARAMETER - Handle was not a valid
399 variable serialization instance.
400
401 **/
402 RETURN_STATUS
403 EFIAPI
404 SerializeVariablesFreeInstance (
405 IN EFI_HANDLE Handle
406 )
407 {
408 SV_INSTANCE *Instance;
409
410 Instance = SV_FROM_HANDLE (Handle);
411
412 if (Instance->Signature != SV_SIGNATURE) {
413 return RETURN_INVALID_PARAMETER;
414 }
415
416 Instance->Signature = 0;
417
418 if (Instance->BufferPtr != NULL) {
419 FreePool (Instance->BufferPtr);
420 }
421
422 FreePool (Instance);
423
424 return RETURN_SUCCESS;
425 }
426
427
428 /**
429 Creates a new variable serialization instance using the given
430 binary representation of the variables to fill the new instance
431
432 @param[out] Handle - Handle for a variable serialization instance
433 @param[in] Buffer - A buffer with the serialized representation
434 of the variables. Must be the same format as produced
435 by SerializeVariablesToBuffer.
436 @param[in] Size - This is the size of the binary representation
437 of the variables.
438
439 @retval RETURN_SUCCESS - The binary representation was successfully
440 imported into a new variable serialization instance
441 @retval RETURN_OUT_OF_RESOURCES - There we not enough resources to
442 create the new variable serialization instance
443
444 **/
445 RETURN_STATUS
446 EFIAPI
447 SerializeVariablesNewInstanceFromBuffer (
448 OUT EFI_HANDLE *Handle,
449 IN VOID *Buffer,
450 IN UINTN Size
451 )
452 {
453 RETURN_STATUS Status;
454
455 Status = SerializeVariablesNewInstance (Handle);
456 if (RETURN_ERROR (Status)) {
457 return Status;
458 }
459
460 Status = IterateVariablesInBuffer (
461 IterateVariablesCallbackNop,
462 NULL,
463 Buffer,
464 Size
465 );
466 if (RETURN_ERROR (Status)) {
467 SerializeVariablesFreeInstance (*Handle);
468 return Status;
469 }
470
471 Status = IterateVariablesInBuffer (
472 IterateVariablesCallbackSetInInstance,
473 (VOID*) *Handle,
474 Buffer,
475 Size
476 );
477 if (RETURN_ERROR (Status)) {
478 SerializeVariablesFreeInstance (*Handle);
479 return Status;
480 }
481
482 return Status;
483 }
484
485
486 /**
487 Iterates all variables found with RuntimeServices GetNextVariableName
488
489 @param[in] CallbackFunction - Function called for each variable instance
490 @param[in] Context - Passed to each call of CallbackFunction
491
492 @retval RETURN_SUCCESS - All variables were iterated without the
493 CallbackFunction returning an error
494 @retval RETURN_OUT_OF_RESOURCES - There we not enough resources to
495 iterate through the variables
496 @return Any of RETURN_ERROR indicates an error reading the variable
497 or an error was returned from CallbackFunction
498
499 **/
500 RETURN_STATUS
501 EFIAPI
502 SerializeVariablesIterateSystemVariables (
503 IN VARIABLE_SERIALIZATION_ITERATION_CALLBACK CallbackFunction,
504 IN VOID *Context
505 )
506 {
507 RETURN_STATUS Status;
508 UINTN VariableNameBufferSize;
509 UINTN VariableNameSize;
510 CHAR16 *VariableName;
511 EFI_GUID VendorGuid;
512 UINTN VariableDataBufferSize;
513 UINTN VariableDataSize;
514 VOID *VariableData;
515 UINT32 VariableAttributes;
516 VOID *NewBuffer;
517
518 //
519 // Initialize the variable name and data buffer variables.
520 //
521 VariableNameBufferSize = sizeof (CHAR16);
522 VariableName = AllocateZeroPool (VariableNameBufferSize);
523
524 VariableDataBufferSize = 0;
525 VariableData = NULL;
526
527 for (;;) {
528 //
529 // Get the next variable name and guid
530 //
531 VariableNameSize = VariableNameBufferSize;
532 Status = gRT->GetNextVariableName (
533 &VariableNameSize,
534 VariableName,
535 &VendorGuid
536 );
537 if (Status == EFI_BUFFER_TOO_SMALL) {
538 //
539 // The currently allocated VariableName buffer is too small,
540 // so we allocate a larger buffer, and copy the old buffer
541 // to it.
542 //
543 NewBuffer = AllocatePool (VariableNameSize);
544 if (NewBuffer == NULL) {
545 Status = EFI_OUT_OF_RESOURCES;
546 break;
547 }
548 CopyMem (NewBuffer, VariableName, VariableNameBufferSize);
549 if (VariableName != NULL) {
550 FreePool (VariableName);
551 }
552 VariableName = NewBuffer;
553 VariableNameBufferSize = VariableNameSize;
554
555 //
556 // Try to get the next variable name again with the larger buffer.
557 //
558 Status = gRT->GetNextVariableName (
559 &VariableNameSize,
560 VariableName,
561 &VendorGuid
562 );
563 }
564
565 if (EFI_ERROR (Status)) {
566 if (Status == EFI_NOT_FOUND) {
567 Status = EFI_SUCCESS;
568 }
569 break;
570 }
571
572 //
573 // Get the variable data and attributes
574 //
575 VariableDataSize = VariableDataBufferSize;
576 Status = gRT->GetVariable (
577 VariableName,
578 &VendorGuid,
579 &VariableAttributes,
580 &VariableDataSize,
581 VariableData
582 );
583 if (Status == EFI_BUFFER_TOO_SMALL) {
584 //
585 // The currently allocated VariableData buffer is too small,
586 // so we allocate a larger buffer.
587 //
588 if (VariableDataBufferSize != 0) {
589 FreePool (VariableData);
590 VariableData = NULL;
591 VariableDataBufferSize = 0;
592 }
593 VariableData = AllocatePool (VariableDataSize);
594 if (VariableData == NULL) {
595 Status = EFI_OUT_OF_RESOURCES;
596 break;
597 }
598 VariableDataBufferSize = VariableDataSize;
599
600 //
601 // Try to read the variable again with the larger buffer.
602 //
603 Status = gRT->GetVariable (
604 VariableName,
605 &VendorGuid,
606 &VariableAttributes,
607 &VariableDataSize,
608 VariableData
609 );
610 }
611 if (EFI_ERROR (Status)) {
612 break;
613 }
614
615 //
616 // Run the callback function
617 //
618 Status = (*CallbackFunction) (
619 Context,
620 VariableName,
621 &VendorGuid,
622 VariableAttributes,
623 VariableDataSize,
624 VariableData
625 );
626 if (EFI_ERROR (Status)) {
627 break;
628 }
629
630 }
631
632 if (VariableName != NULL) {
633 FreePool (VariableName);
634 }
635
636 if (VariableData != NULL) {
637 FreePool (VariableData);
638 }
639
640 return Status;
641 }
642
643
644 /**
645 Iterates all variables found in the variable serialization instance
646
647 @param[in] Handle - Handle for a variable serialization instance
648 @param[in] CallbackFunction - Function called for each variable instance
649 @param[in] Context - Passed to each call of CallbackFunction
650
651 @retval RETURN_SUCCESS - All variables were iterated without the
652 CallbackFunction returning an error
653 @retval RETURN_OUT_OF_RESOURCES - There we not enough resources to
654 iterate through the variables
655 @return Any of RETURN_ERROR indicates an error reading the variable
656 or an error was returned from CallbackFunction
657
658 **/
659 RETURN_STATUS
660 EFIAPI
661 SerializeVariablesIterateInstanceVariables (
662 IN EFI_HANDLE Handle,
663 IN VARIABLE_SERIALIZATION_ITERATION_CALLBACK CallbackFunction,
664 IN VOID *Context
665 )
666 {
667 SV_INSTANCE *Instance;
668
669 Instance = SV_FROM_HANDLE (Handle);
670
671 if ((Instance->BufferPtr != NULL) && (Instance->DataSize != 0)) {
672 return IterateVariablesInBuffer (
673 CallbackFunction,
674 Context,
675 Instance->BufferPtr,
676 Instance->DataSize
677 );
678 } else {
679 return RETURN_SUCCESS;
680 }
681 }
682
683
684 /**
685 Sets all variables found in the variable serialization instance
686
687 @param[in] Handle - Handle for a variable serialization instance
688
689 @retval RETURN_SUCCESS - All variables were set successfully
690 @retval RETURN_OUT_OF_RESOURCES - There we not enough resources to
691 set all the variables
692 @return Any of RETURN_ERROR indicates an error reading the variables
693 or in attempting to set a variable
694
695 **/
696 RETURN_STATUS
697 EFIAPI
698 SerializeVariablesSetSerializedVariables (
699 IN EFI_HANDLE Handle
700 )
701 {
702 return SerializeVariablesIterateInstanceVariables (
703 Handle,
704 IterateVariablesCallbackSetSystemVariable,
705 NULL
706 );
707 }
708
709
710 /**
711 Adds a variable to the variable serialization instance
712
713 @param[in] Handle - Handle for a variable serialization instance
714 @param[in] VariableName - Refer to RuntimeServices GetVariable
715 @param[in] VendorGuid - Refer to RuntimeServices GetVariable
716 @param[in] Attributes - Refer to RuntimeServices GetVariable
717 @param[in] DataSize - Refer to RuntimeServices GetVariable
718 @param[in] Data - Refer to RuntimeServices GetVariable
719
720 @retval RETURN_SUCCESS - All variables were set successfully
721 @retval RETURN_OUT_OF_RESOURCES - There we not enough resources to
722 add the variable
723 @retval RETURN_INVALID_PARAMETER - Handle was not a valid
724 variable serialization instance or
725 VariableName, VariableGuid or Data are NULL.
726
727 **/
728 RETURN_STATUS
729 EFIAPI
730 SerializeVariablesAddVariable (
731 IN EFI_HANDLE Handle,
732 IN CHAR16 *VariableName,
733 IN EFI_GUID *VendorGuid,
734 IN UINT32 Attributes,
735 IN UINTN DataSize,
736 IN VOID *Data
737 )
738 {
739 RETURN_STATUS Status;
740 SV_INSTANCE *Instance;
741 UINT32 SerializedNameSize;
742 UINT32 SerializedDataSize;
743 UINTN SerializedSize;
744
745 Instance = SV_FROM_HANDLE (Handle);
746
747 if ((Instance->Signature != SV_SIGNATURE) ||
748 (VariableName == NULL) || (VendorGuid == NULL) || (Data == NULL)) {
749 }
750
751 SerializedNameSize = (UINT32) StrSize (VariableName);
752
753 SerializedSize =
754 sizeof (SerializedNameSize) +
755 SerializedNameSize +
756 sizeof (*VendorGuid) +
757 sizeof (Attributes) +
758 sizeof (SerializedDataSize) +
759 DataSize;
760
761 Status = EnsureExtraBufferSpace (
762 Instance,
763 SerializedSize
764 );
765 if (RETURN_ERROR (Status)) {
766 return Status;
767 }
768
769 //
770 // Add name size (UINT32)
771 //
772 AppendToBuffer (Instance, (VOID*) &SerializedNameSize, sizeof (SerializedNameSize));
773
774 //
775 // Add variable unicode name string
776 //
777 AppendToBuffer (Instance, (VOID*) VariableName, SerializedNameSize);
778
779 //
780 // Add variable GUID
781 //
782 AppendToBuffer (Instance, (VOID*) VendorGuid, sizeof (*VendorGuid));
783
784 //
785 // Add variable attributes
786 //
787 AppendToBuffer (Instance, (VOID*) &Attributes, sizeof (Attributes));
788
789 //
790 // Add variable data size (UINT32)
791 //
792 SerializedDataSize = (UINT32) DataSize;
793 AppendToBuffer (Instance, (VOID*) &SerializedDataSize, sizeof (SerializedDataSize));
794
795 //
796 // Add variable data
797 //
798 AppendToBuffer (Instance, Data, DataSize);
799
800 return RETURN_SUCCESS;
801 }
802
803
804 /**
805 Serializes the variables known to this instance into the
806 provided buffer.
807
808 @param[in] Handle - Handle for a variable serialization instance
809 @param[out] Buffer - A buffer to store the binary representation
810 of the variables.
811 @param[in,out] Size - On input this is the size of the buffer.
812 On output this is the size of the binary representation
813 of the variables.
814
815 @retval RETURN_SUCCESS - The binary representation was successfully
816 completed and returned in the buffer.
817 @retval RETURN_OUT_OF_RESOURCES - There we not enough resources to
818 save the variables to the buffer.
819 @retval RETURN_INVALID_PARAMETER - Handle was not a valid
820 variable serialization instance or
821 Size or Buffer were NULL.
822 @retval RETURN_BUFFER_TOO_SMALL - The Buffer size as indicated by
823 the Size parameter was too small for the serialized
824 variable data. Size is returned with the required size.
825
826 **/
827 RETURN_STATUS
828 EFIAPI
829 SerializeVariablesToBuffer (
830 IN EFI_HANDLE Handle,
831 OUT VOID *Buffer,
832 IN OUT UINTN *Size
833 )
834 {
835 SV_INSTANCE *Instance;
836
837 Instance = SV_FROM_HANDLE (Handle);
838
839 if (Size == NULL) {
840 return RETURN_INVALID_PARAMETER;
841 }
842
843 if (*Size < Instance->DataSize) {
844 *Size = Instance->DataSize;
845 return RETURN_BUFFER_TOO_SMALL;
846 }
847
848 if (Buffer == NULL) {
849 return RETURN_INVALID_PARAMETER;
850 }
851
852 *Size = Instance->DataSize;
853 CopyMem (Buffer, Instance->BufferPtr, Instance->DataSize);
854
855 return RETURN_SUCCESS;
856 }
857