]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/Variable/RuntimeDxe/VariableParsing.c
d6bb916e68e73b61737107df09f710350375be42
[mirror_edk2.git] / MdeModulePkg / Universal / Variable / RuntimeDxe / VariableParsing.c
1 /** @file
2 Functions in this module are associated with variable parsing operations and
3 are intended to be usable across variable driver source files.
4
5 Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
7
8 **/
9
10 #include "VariableParsing.h"
11
12 /**
13
14 This code checks if variable header is valid or not.
15
16 @param[in] Variable Pointer to the Variable Header.
17 @param[in] VariableStoreEnd Pointer to the Variable Store End.
18
19 @retval TRUE Variable header is valid.
20 @retval FALSE Variable header is not valid.
21
22 **/
23 BOOLEAN
24 IsValidVariableHeader (
25 IN VARIABLE_HEADER *Variable,
26 IN VARIABLE_HEADER *VariableStoreEnd
27 )
28 {
29 if ((Variable == NULL) || (Variable >= VariableStoreEnd) || (Variable->StartId != VARIABLE_DATA)) {
30 //
31 // Variable is NULL or has reached the end of variable store,
32 // or the StartId is not correct.
33 //
34 return FALSE;
35 }
36
37 return TRUE;
38 }
39
40 /**
41
42 This code gets the current status of Variable Store.
43
44 @param[in] VarStoreHeader Pointer to the Variable Store Header.
45
46 @retval EfiRaw Variable store status is raw.
47 @retval EfiValid Variable store status is valid.
48 @retval EfiInvalid Variable store status is invalid.
49
50 **/
51 VARIABLE_STORE_STATUS
52 GetVariableStoreStatus (
53 IN VARIABLE_STORE_HEADER *VarStoreHeader
54 )
55 {
56 if ((CompareGuid (&VarStoreHeader->Signature, &gEfiAuthenticatedVariableGuid) ||
57 CompareGuid (&VarStoreHeader->Signature, &gEfiVariableGuid)) &&
58 VarStoreHeader->Format == VARIABLE_STORE_FORMATTED &&
59 VarStoreHeader->State == VARIABLE_STORE_HEALTHY
60 ) {
61
62 return EfiValid;
63 } else if (((UINT32 *)(&VarStoreHeader->Signature))[0] == 0xffffffff &&
64 ((UINT32 *)(&VarStoreHeader->Signature))[1] == 0xffffffff &&
65 ((UINT32 *)(&VarStoreHeader->Signature))[2] == 0xffffffff &&
66 ((UINT32 *)(&VarStoreHeader->Signature))[3] == 0xffffffff &&
67 VarStoreHeader->Size == 0xffffffff &&
68 VarStoreHeader->Format == 0xff &&
69 VarStoreHeader->State == 0xff
70 ) {
71
72 return EfiRaw;
73 } else {
74 return EfiInvalid;
75 }
76 }
77
78 /**
79 This code gets the size of variable header.
80
81 @return Size of variable header in bytes in type UINTN.
82
83 **/
84 UINTN
85 GetVariableHeaderSize (
86 VOID
87 )
88 {
89 UINTN Value;
90
91 if (mVariableModuleGlobal->VariableGlobal.AuthFormat) {
92 Value = sizeof (AUTHENTICATED_VARIABLE_HEADER);
93 } else {
94 Value = sizeof (VARIABLE_HEADER);
95 }
96
97 return Value;
98 }
99
100 /**
101
102 This code gets the size of name of variable.
103
104 @param Variable Pointer to the Variable Header.
105
106 @return UINTN Size of variable in bytes.
107
108 **/
109 UINTN
110 NameSizeOfVariable (
111 IN VARIABLE_HEADER *Variable
112 )
113 {
114 AUTHENTICATED_VARIABLE_HEADER *AuthVariable;
115
116 AuthVariable = (AUTHENTICATED_VARIABLE_HEADER *) Variable;
117 if (mVariableModuleGlobal->VariableGlobal.AuthFormat) {
118 if (AuthVariable->State == (UINT8) (-1) ||
119 AuthVariable->DataSize == (UINT32) (-1) ||
120 AuthVariable->NameSize == (UINT32) (-1) ||
121 AuthVariable->Attributes == (UINT32) (-1)) {
122 return 0;
123 }
124 return (UINTN) AuthVariable->NameSize;
125 } else {
126 if (Variable->State == (UINT8) (-1) ||
127 Variable->DataSize == (UINT32) (-1) ||
128 Variable->NameSize == (UINT32) (-1) ||
129 Variable->Attributes == (UINT32) (-1)) {
130 return 0;
131 }
132 return (UINTN) Variable->NameSize;
133 }
134 }
135
136 /**
137 This code sets the size of name of variable.
138
139 @param[in] Variable Pointer to the Variable Header.
140 @param[in] NameSize Name size to set.
141
142 **/
143 VOID
144 SetNameSizeOfVariable (
145 IN VARIABLE_HEADER *Variable,
146 IN UINTN NameSize
147 )
148 {
149 AUTHENTICATED_VARIABLE_HEADER *AuthVariable;
150
151 AuthVariable = (AUTHENTICATED_VARIABLE_HEADER *) Variable;
152 if (mVariableModuleGlobal->VariableGlobal.AuthFormat) {
153 AuthVariable->NameSize = (UINT32) NameSize;
154 } else {
155 Variable->NameSize = (UINT32) NameSize;
156 }
157 }
158
159 /**
160
161 This code gets the size of variable data.
162
163 @param Variable Pointer to the Variable Header.
164
165 @return Size of variable in bytes.
166
167 **/
168 UINTN
169 DataSizeOfVariable (
170 IN VARIABLE_HEADER *Variable
171 )
172 {
173 AUTHENTICATED_VARIABLE_HEADER *AuthVariable;
174
175 AuthVariable = (AUTHENTICATED_VARIABLE_HEADER *) Variable;
176 if (mVariableModuleGlobal->VariableGlobal.AuthFormat) {
177 if (AuthVariable->State == (UINT8) (-1) ||
178 AuthVariable->DataSize == (UINT32) (-1) ||
179 AuthVariable->NameSize == (UINT32) (-1) ||
180 AuthVariable->Attributes == (UINT32) (-1)) {
181 return 0;
182 }
183 return (UINTN) AuthVariable->DataSize;
184 } else {
185 if (Variable->State == (UINT8) (-1) ||
186 Variable->DataSize == (UINT32) (-1) ||
187 Variable->NameSize == (UINT32) (-1) ||
188 Variable->Attributes == (UINT32) (-1)) {
189 return 0;
190 }
191 return (UINTN) Variable->DataSize;
192 }
193 }
194
195 /**
196 This code sets the size of variable data.
197
198 @param[in] Variable Pointer to the Variable Header.
199 @param[in] DataSize Data size to set.
200
201 **/
202 VOID
203 SetDataSizeOfVariable (
204 IN VARIABLE_HEADER *Variable,
205 IN UINTN DataSize
206 )
207 {
208 AUTHENTICATED_VARIABLE_HEADER *AuthVariable;
209
210 AuthVariable = (AUTHENTICATED_VARIABLE_HEADER *) Variable;
211 if (mVariableModuleGlobal->VariableGlobal.AuthFormat) {
212 AuthVariable->DataSize = (UINT32) DataSize;
213 } else {
214 Variable->DataSize = (UINT32) DataSize;
215 }
216 }
217
218 /**
219
220 This code gets the pointer to the variable name.
221
222 @param Variable Pointer to the Variable Header.
223
224 @return Pointer to Variable Name which is Unicode encoding.
225
226 **/
227 CHAR16 *
228 GetVariableNamePtr (
229 IN VARIABLE_HEADER *Variable
230 )
231 {
232 return (CHAR16 *) ((UINTN) Variable + GetVariableHeaderSize ());
233 }
234
235 /**
236 This code gets the pointer to the variable guid.
237
238 @param Variable Pointer to the Variable Header.
239
240 @return A EFI_GUID* pointer to Vendor Guid.
241
242 **/
243 EFI_GUID *
244 GetVendorGuidPtr (
245 IN VARIABLE_HEADER *Variable
246 )
247 {
248 AUTHENTICATED_VARIABLE_HEADER *AuthVariable;
249
250 AuthVariable = (AUTHENTICATED_VARIABLE_HEADER *) Variable;
251 if (mVariableModuleGlobal->VariableGlobal.AuthFormat) {
252 return &AuthVariable->VendorGuid;
253 } else {
254 return &Variable->VendorGuid;
255 }
256 }
257
258 /**
259
260 This code gets the pointer to the variable data.
261
262 @param Variable Pointer to the Variable Header.
263
264 @return Pointer to Variable Data.
265
266 **/
267 UINT8 *
268 GetVariableDataPtr (
269 IN VARIABLE_HEADER *Variable
270 )
271 {
272 UINTN Value;
273
274 //
275 // Be careful about pad size for alignment.
276 //
277 Value = (UINTN) GetVariableNamePtr (Variable);
278 Value += NameSizeOfVariable (Variable);
279 Value += GET_PAD_SIZE (NameSizeOfVariable (Variable));
280
281 return (UINT8 *) Value;
282 }
283
284 /**
285 This code gets the variable data offset related to variable header.
286
287 @param Variable Pointer to the Variable Header.
288
289 @return Variable Data offset.
290
291 **/
292 UINTN
293 GetVariableDataOffset (
294 IN VARIABLE_HEADER *Variable
295 )
296 {
297 UINTN Value;
298
299 //
300 // Be careful about pad size for alignment
301 //
302 Value = GetVariableHeaderSize ();
303 Value += NameSizeOfVariable (Variable);
304 Value += GET_PAD_SIZE (NameSizeOfVariable (Variable));
305
306 return Value;
307 }
308
309 /**
310
311 This code gets the pointer to the next variable header.
312
313 @param Variable Pointer to the Variable Header.
314
315 @return Pointer to next variable header.
316
317 **/
318 VARIABLE_HEADER *
319 GetNextVariablePtr (
320 IN VARIABLE_HEADER *Variable
321 )
322 {
323 UINTN Value;
324
325 Value = (UINTN) GetVariableDataPtr (Variable);
326 Value += DataSizeOfVariable (Variable);
327 Value += GET_PAD_SIZE (DataSizeOfVariable (Variable));
328
329 //
330 // Be careful about pad size for alignment.
331 //
332 return (VARIABLE_HEADER *) HEADER_ALIGN (Value);
333 }
334
335 /**
336
337 Gets the pointer to the first variable header in given variable store area.
338
339 @param[in] VarStoreHeader Pointer to the Variable Store Header.
340
341 @return Pointer to the first variable header.
342
343 **/
344 VARIABLE_HEADER *
345 GetStartPointer (
346 IN VARIABLE_STORE_HEADER *VarStoreHeader
347 )
348 {
349 //
350 // The start of variable store.
351 //
352 return (VARIABLE_HEADER *) HEADER_ALIGN (VarStoreHeader + 1);
353 }
354
355 /**
356
357 Gets the pointer to the end of the variable storage area.
358
359 This function gets pointer to the end of the variable storage
360 area, according to the input variable store header.
361
362 @param[in] VarStoreHeader Pointer to the Variable Store Header.
363
364 @return Pointer to the end of the variable storage area.
365
366 **/
367 VARIABLE_HEADER *
368 GetEndPointer (
369 IN VARIABLE_STORE_HEADER *VarStoreHeader
370 )
371 {
372 //
373 // The end of variable store
374 //
375 return (VARIABLE_HEADER *) HEADER_ALIGN ((UINTN) VarStoreHeader + VarStoreHeader->Size);
376 }
377
378 /**
379 Compare two EFI_TIME data.
380
381
382 @param[in] FirstTime A pointer to the first EFI_TIME data.
383 @param[in] SecondTime A pointer to the second EFI_TIME data.
384
385 @retval TRUE The FirstTime is not later than the SecondTime.
386 @retval FALSE The FirstTime is later than the SecondTime.
387
388 **/
389 BOOLEAN
390 VariableCompareTimeStampInternal (
391 IN EFI_TIME *FirstTime,
392 IN EFI_TIME *SecondTime
393 )
394 {
395 if (FirstTime->Year != SecondTime->Year) {
396 return (BOOLEAN) (FirstTime->Year < SecondTime->Year);
397 } else if (FirstTime->Month != SecondTime->Month) {
398 return (BOOLEAN) (FirstTime->Month < SecondTime->Month);
399 } else if (FirstTime->Day != SecondTime->Day) {
400 return (BOOLEAN) (FirstTime->Day < SecondTime->Day);
401 } else if (FirstTime->Hour != SecondTime->Hour) {
402 return (BOOLEAN) (FirstTime->Hour < SecondTime->Hour);
403 } else if (FirstTime->Minute != SecondTime->Minute) {
404 return (BOOLEAN) (FirstTime->Minute < SecondTime->Minute);
405 }
406
407 return (BOOLEAN) (FirstTime->Second <= SecondTime->Second);
408 }
409
410 /**
411 Find the variable in the specified variable store.
412
413 @param[in] VariableName Name of the variable to be found
414 @param[in] VendorGuid Vendor GUID to be found.
415 @param[in] IgnoreRtCheck Ignore EFI_VARIABLE_RUNTIME_ACCESS attribute
416 check at runtime when searching variable.
417 @param[in, out] PtrTrack Variable Track Pointer structure that contains Variable Information.
418
419 @retval EFI_SUCCESS Variable found successfully
420 @retval EFI_NOT_FOUND Variable not found
421 **/
422 EFI_STATUS
423 FindVariableEx (
424 IN CHAR16 *VariableName,
425 IN EFI_GUID *VendorGuid,
426 IN BOOLEAN IgnoreRtCheck,
427 IN OUT VARIABLE_POINTER_TRACK *PtrTrack
428 )
429 {
430 VARIABLE_HEADER *InDeletedVariable;
431 VOID *Point;
432
433 PtrTrack->InDeletedTransitionPtr = NULL;
434
435 //
436 // Find the variable by walk through HOB, volatile and non-volatile variable store.
437 //
438 InDeletedVariable = NULL;
439
440 for ( PtrTrack->CurrPtr = PtrTrack->StartPtr
441 ; IsValidVariableHeader (PtrTrack->CurrPtr, PtrTrack->EndPtr)
442 ; PtrTrack->CurrPtr = GetNextVariablePtr (PtrTrack->CurrPtr)
443 ) {
444 if (PtrTrack->CurrPtr->State == VAR_ADDED ||
445 PtrTrack->CurrPtr->State == (VAR_IN_DELETED_TRANSITION & VAR_ADDED)
446 ) {
447 if (IgnoreRtCheck || !AtRuntime () || ((PtrTrack->CurrPtr->Attributes & EFI_VARIABLE_RUNTIME_ACCESS) != 0)) {
448 if (VariableName[0] == 0) {
449 if (PtrTrack->CurrPtr->State == (VAR_IN_DELETED_TRANSITION & VAR_ADDED)) {
450 InDeletedVariable = PtrTrack->CurrPtr;
451 } else {
452 PtrTrack->InDeletedTransitionPtr = InDeletedVariable;
453 return EFI_SUCCESS;
454 }
455 } else {
456 if (CompareGuid (VendorGuid, GetVendorGuidPtr (PtrTrack->CurrPtr))) {
457 Point = (VOID *) GetVariableNamePtr (PtrTrack->CurrPtr);
458
459 ASSERT (NameSizeOfVariable (PtrTrack->CurrPtr) != 0);
460 if (CompareMem (VariableName, Point, NameSizeOfVariable (PtrTrack->CurrPtr)) == 0) {
461 if (PtrTrack->CurrPtr->State == (VAR_IN_DELETED_TRANSITION & VAR_ADDED)) {
462 InDeletedVariable = PtrTrack->CurrPtr;
463 } else {
464 PtrTrack->InDeletedTransitionPtr = InDeletedVariable;
465 return EFI_SUCCESS;
466 }
467 }
468 }
469 }
470 }
471 }
472 }
473
474 PtrTrack->CurrPtr = InDeletedVariable;
475 return (PtrTrack->CurrPtr == NULL) ? EFI_NOT_FOUND : EFI_SUCCESS;
476 }
477
478 /**
479 This code finds the next available variable.
480
481 Caution: This function may receive untrusted input.
482 This function may be invoked in SMM mode. This function will do basic validation, before parse the data.
483
484 @param[in] VariableName Pointer to variable name.
485 @param[in] VendorGuid Variable Vendor Guid.
486 @param[in] VariableStoreList A list of variable stores that should be used to get the next variable.
487 The maximum number of entries is the max value of VARIABLE_STORE_TYPE.
488 @param[out] VariablePtr Pointer to variable header address.
489
490 @retval EFI_SUCCESS The function completed successfully.
491 @retval EFI_NOT_FOUND The next variable was not found.
492 @retval EFI_INVALID_PARAMETER If VariableName is not an empty string, while VendorGuid is NULL.
493 @retval EFI_INVALID_PARAMETER The input values of VariableName and VendorGuid are not a name and
494 GUID of an existing variable.
495
496 **/
497 EFI_STATUS
498 EFIAPI
499 VariableServiceGetNextVariableInternal (
500 IN CHAR16 *VariableName,
501 IN EFI_GUID *VendorGuid,
502 IN VARIABLE_STORE_HEADER **VariableStoreList,
503 OUT VARIABLE_HEADER **VariablePtr
504 )
505 {
506 EFI_STATUS Status;
507 VARIABLE_STORE_TYPE StoreType;
508 VARIABLE_POINTER_TRACK Variable;
509 VARIABLE_POINTER_TRACK VariableInHob;
510 VARIABLE_POINTER_TRACK VariablePtrTrack;
511
512 Status = EFI_NOT_FOUND;
513
514 if (VariableStoreList == NULL) {
515 return EFI_INVALID_PARAMETER;
516 }
517
518 // Check if the variable exists in the given variable store list
519 for (StoreType = (VARIABLE_STORE_TYPE) 0; StoreType < VariableStoreTypeMax; StoreType++) {
520 if (VariableStoreList[StoreType] == NULL) {
521 continue;
522 }
523
524 Variable.StartPtr = GetStartPointer (VariableStoreList[StoreType]);
525 Variable.EndPtr = GetEndPointer (VariableStoreList[StoreType]);
526 Variable.Volatile = (BOOLEAN) (StoreType == VariableStoreTypeVolatile);
527
528 Status = FindVariableEx (VariableName, VendorGuid, FALSE, &Variable);
529 if (!EFI_ERROR (Status)) {
530 break;
531 }
532 }
533
534 if (Variable.CurrPtr == NULL || EFI_ERROR (Status)) {
535 //
536 // For VariableName is an empty string, FindVariableEx() will try to find and return
537 // the first qualified variable, and if FindVariableEx() returns error (EFI_NOT_FOUND)
538 // as no any variable is found, still go to return the error (EFI_NOT_FOUND).
539 //
540 if (VariableName[0] != 0) {
541 //
542 // For VariableName is not an empty string, and FindVariableEx() returns error as
543 // VariableName and VendorGuid are not a name and GUID of an existing variable,
544 // there is no way to get next variable, follow spec to return EFI_INVALID_PARAMETER.
545 //
546 Status = EFI_INVALID_PARAMETER;
547 }
548 goto Done;
549 }
550
551 if (VariableName[0] != 0) {
552 //
553 // If variable name is not empty, get next variable.
554 //
555 Variable.CurrPtr = GetNextVariablePtr (Variable.CurrPtr);
556 }
557
558 while (TRUE) {
559 //
560 // Switch to the next variable store if needed
561 //
562 while (!IsValidVariableHeader (Variable.CurrPtr, Variable.EndPtr)) {
563 //
564 // Find current storage index
565 //
566 for (StoreType = (VARIABLE_STORE_TYPE) 0; StoreType < VariableStoreTypeMax; StoreType++) {
567 if ((VariableStoreList[StoreType] != NULL) && (Variable.StartPtr == GetStartPointer (VariableStoreList[StoreType]))) {
568 break;
569 }
570 }
571 ASSERT (StoreType < VariableStoreTypeMax);
572 //
573 // Switch to next storage
574 //
575 for (StoreType++; StoreType < VariableStoreTypeMax; StoreType++) {
576 if (VariableStoreList[StoreType] != NULL) {
577 break;
578 }
579 }
580 //
581 // Capture the case that
582 // 1. current storage is the last one, or
583 // 2. no further storage
584 //
585 if (StoreType == VariableStoreTypeMax) {
586 Status = EFI_NOT_FOUND;
587 goto Done;
588 }
589 Variable.StartPtr = GetStartPointer (VariableStoreList[StoreType]);
590 Variable.EndPtr = GetEndPointer (VariableStoreList[StoreType]);
591 Variable.CurrPtr = Variable.StartPtr;
592 }
593
594 //
595 // Variable is found
596 //
597 if (Variable.CurrPtr->State == VAR_ADDED || Variable.CurrPtr->State == (VAR_IN_DELETED_TRANSITION & VAR_ADDED)) {
598 if (!AtRuntime () || ((Variable.CurrPtr->Attributes & EFI_VARIABLE_RUNTIME_ACCESS) != 0)) {
599 if (Variable.CurrPtr->State == (VAR_IN_DELETED_TRANSITION & VAR_ADDED)) {
600 //
601 // If it is a IN_DELETED_TRANSITION variable,
602 // and there is also a same ADDED one at the same time,
603 // don't return it.
604 //
605 VariablePtrTrack.StartPtr = Variable.StartPtr;
606 VariablePtrTrack.EndPtr = Variable.EndPtr;
607 Status = FindVariableEx (
608 GetVariableNamePtr (Variable.CurrPtr),
609 GetVendorGuidPtr (Variable.CurrPtr),
610 FALSE,
611 &VariablePtrTrack
612 );
613 if (!EFI_ERROR (Status) && VariablePtrTrack.CurrPtr->State == VAR_ADDED) {
614 Variable.CurrPtr = GetNextVariablePtr (Variable.CurrPtr);
615 continue;
616 }
617 }
618
619 //
620 // Don't return NV variable when HOB overrides it
621 //
622 if ((VariableStoreList[VariableStoreTypeHob] != NULL) && (VariableStoreList[VariableStoreTypeNv] != NULL) &&
623 (Variable.StartPtr == GetStartPointer (VariableStoreList[VariableStoreTypeNv]))
624 ) {
625 VariableInHob.StartPtr = GetStartPointer (VariableStoreList[VariableStoreTypeHob]);
626 VariableInHob.EndPtr = GetEndPointer (VariableStoreList[VariableStoreTypeHob]);
627 Status = FindVariableEx (
628 GetVariableNamePtr (Variable.CurrPtr),
629 GetVendorGuidPtr (Variable.CurrPtr),
630 FALSE,
631 &VariableInHob
632 );
633 if (!EFI_ERROR (Status)) {
634 Variable.CurrPtr = GetNextVariablePtr (Variable.CurrPtr);
635 continue;
636 }
637 }
638
639 *VariablePtr = Variable.CurrPtr;
640 Status = EFI_SUCCESS;
641 goto Done;
642 }
643 }
644
645 Variable.CurrPtr = GetNextVariablePtr (Variable.CurrPtr);
646 }
647
648 Done:
649 return Status;
650 }
651
652 /**
653 Routine used to track statistical information about variable usage.
654 The data is stored in the EFI system table so it can be accessed later.
655 VariableInfo.efi can dump out the table. Only Boot Services variable
656 accesses are tracked by this code. The PcdVariableCollectStatistics
657 build flag controls if this feature is enabled.
658
659 A read that hits in the cache will have Read and Cache true for
660 the transaction. Data is allocated by this routine, but never
661 freed.
662
663 @param[in] VariableName Name of the Variable to track.
664 @param[in] VendorGuid Guid of the Variable to track.
665 @param[in] Volatile TRUE if volatile FALSE if non-volatile.
666 @param[in] Read TRUE if GetVariable() was called.
667 @param[in] Write TRUE if SetVariable() was called.
668 @param[in] Delete TRUE if deleted via SetVariable().
669 @param[in] Cache TRUE for a cache hit.
670
671 **/
672 VOID
673 UpdateVariableInfo (
674 IN CHAR16 *VariableName,
675 IN EFI_GUID *VendorGuid,
676 IN BOOLEAN Volatile,
677 IN BOOLEAN Read,
678 IN BOOLEAN Write,
679 IN BOOLEAN Delete,
680 IN BOOLEAN Cache
681 )
682 {
683 VARIABLE_INFO_ENTRY *Entry;
684
685 if (FeaturePcdGet (PcdVariableCollectStatistics)) {
686
687 if (AtRuntime ()) {
688 // Don't collect statistics at runtime.
689 return;
690 }
691
692 if (gVariableInfo == NULL) {
693 //
694 // On the first call allocate a entry and place a pointer to it in
695 // the EFI System Table.
696 //
697 gVariableInfo = AllocateZeroPool (sizeof (VARIABLE_INFO_ENTRY));
698 ASSERT (gVariableInfo != NULL);
699
700 CopyGuid (&gVariableInfo->VendorGuid, VendorGuid);
701 gVariableInfo->Name = AllocateZeroPool (StrSize (VariableName));
702 ASSERT (gVariableInfo->Name != NULL);
703 StrCpyS (gVariableInfo->Name, StrSize(VariableName)/sizeof(CHAR16), VariableName);
704 gVariableInfo->Volatile = Volatile;
705 }
706
707
708 for (Entry = gVariableInfo; Entry != NULL; Entry = Entry->Next) {
709 if (CompareGuid (VendorGuid, &Entry->VendorGuid)) {
710 if (StrCmp (VariableName, Entry->Name) == 0) {
711 if (Read) {
712 Entry->ReadCount++;
713 }
714 if (Write) {
715 Entry->WriteCount++;
716 }
717 if (Delete) {
718 Entry->DeleteCount++;
719 }
720 if (Cache) {
721 Entry->CacheCount++;
722 }
723
724 return;
725 }
726 }
727
728 if (Entry->Next == NULL) {
729 //
730 // If the entry is not in the table add it.
731 // Next iteration of the loop will fill in the data.
732 //
733 Entry->Next = AllocateZeroPool (sizeof (VARIABLE_INFO_ENTRY));
734 ASSERT (Entry->Next != NULL);
735
736 CopyGuid (&Entry->Next->VendorGuid, VendorGuid);
737 Entry->Next->Name = AllocateZeroPool (StrSize (VariableName));
738 ASSERT (Entry->Next->Name != NULL);
739 StrCpyS (Entry->Next->Name, StrSize(VariableName)/sizeof(CHAR16), VariableName);
740 Entry->Next->Volatile = Volatile;
741 }
742
743 }
744 }
745 }