]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/Variable/RuntimeDxe/VariableParsing.c
5698a1a5e42f487ea6a6165e853035fe6a5d24e9
[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[out] VariablePtr Pointer to variable header address.
487
488 @retval EFI_SUCCESS The function completed successfully.
489 @retval EFI_NOT_FOUND The next variable was not found.
490 @retval EFI_INVALID_PARAMETER If VariableName is not an empty string, while VendorGuid is NULL.
491 @retval EFI_INVALID_PARAMETER The input values of VariableName and VendorGuid are not a name and
492 GUID of an existing variable.
493
494 **/
495 EFI_STATUS
496 EFIAPI
497 VariableServiceGetNextVariableInternal (
498 IN CHAR16 *VariableName,
499 IN EFI_GUID *VendorGuid,
500 OUT VARIABLE_HEADER **VariablePtr
501 )
502 {
503 VARIABLE_STORE_TYPE Type;
504 VARIABLE_POINTER_TRACK Variable;
505 VARIABLE_POINTER_TRACK VariableInHob;
506 VARIABLE_POINTER_TRACK VariablePtrTrack;
507 EFI_STATUS Status;
508 VARIABLE_STORE_HEADER *VariableStoreHeader[VariableStoreTypeMax];
509
510 Status = FindVariable (VariableName, VendorGuid, &Variable, &mVariableModuleGlobal->VariableGlobal, FALSE);
511 if (Variable.CurrPtr == NULL || EFI_ERROR (Status)) {
512 //
513 // For VariableName is an empty string, FindVariable() will try to find and return
514 // the first qualified variable, and if FindVariable() returns error (EFI_NOT_FOUND)
515 // as no any variable is found, still go to return the error (EFI_NOT_FOUND).
516 //
517 if (VariableName[0] != 0) {
518 //
519 // For VariableName is not an empty string, and FindVariable() returns error as
520 // VariableName and VendorGuid are not a name and GUID of an existing variable,
521 // there is no way to get next variable, follow spec to return EFI_INVALID_PARAMETER.
522 //
523 Status = EFI_INVALID_PARAMETER;
524 }
525 goto Done;
526 }
527
528 if (VariableName[0] != 0) {
529 //
530 // If variable name is not NULL, get next variable.
531 //
532 Variable.CurrPtr = GetNextVariablePtr (Variable.CurrPtr);
533 }
534
535 //
536 // 0: Volatile, 1: HOB, 2: Non-Volatile.
537 // The index and attributes mapping must be kept in this order as FindVariable
538 // makes use of this mapping to implement search algorithm.
539 //
540 VariableStoreHeader[VariableStoreTypeVolatile] = (VARIABLE_STORE_HEADER *) (UINTN) mVariableModuleGlobal->VariableGlobal.VolatileVariableBase;
541 VariableStoreHeader[VariableStoreTypeHob] = (VARIABLE_STORE_HEADER *) (UINTN) mVariableModuleGlobal->VariableGlobal.HobVariableBase;
542 VariableStoreHeader[VariableStoreTypeNv] = mNvVariableCache;
543
544 while (TRUE) {
545 //
546 // Switch from Volatile to HOB, to Non-Volatile.
547 //
548 while (!IsValidVariableHeader (Variable.CurrPtr, Variable.EndPtr)) {
549 //
550 // Find current storage index
551 //
552 for (Type = (VARIABLE_STORE_TYPE) 0; Type < VariableStoreTypeMax; Type++) {
553 if ((VariableStoreHeader[Type] != NULL) && (Variable.StartPtr == GetStartPointer (VariableStoreHeader[Type]))) {
554 break;
555 }
556 }
557 ASSERT (Type < VariableStoreTypeMax);
558 //
559 // Switch to next storage
560 //
561 for (Type++; Type < VariableStoreTypeMax; Type++) {
562 if (VariableStoreHeader[Type] != NULL) {
563 break;
564 }
565 }
566 //
567 // Capture the case that
568 // 1. current storage is the last one, or
569 // 2. no further storage
570 //
571 if (Type == VariableStoreTypeMax) {
572 Status = EFI_NOT_FOUND;
573 goto Done;
574 }
575 Variable.StartPtr = GetStartPointer (VariableStoreHeader[Type]);
576 Variable.EndPtr = GetEndPointer (VariableStoreHeader[Type]);
577 Variable.CurrPtr = Variable.StartPtr;
578 }
579
580 //
581 // Variable is found
582 //
583 if (Variable.CurrPtr->State == VAR_ADDED || Variable.CurrPtr->State == (VAR_IN_DELETED_TRANSITION & VAR_ADDED)) {
584 if (!AtRuntime () || ((Variable.CurrPtr->Attributes & EFI_VARIABLE_RUNTIME_ACCESS) != 0)) {
585 if (Variable.CurrPtr->State == (VAR_IN_DELETED_TRANSITION & VAR_ADDED)) {
586 //
587 // If it is a IN_DELETED_TRANSITION variable,
588 // and there is also a same ADDED one at the same time,
589 // don't return it.
590 //
591 VariablePtrTrack.StartPtr = Variable.StartPtr;
592 VariablePtrTrack.EndPtr = Variable.EndPtr;
593 Status = FindVariableEx (
594 GetVariableNamePtr (Variable.CurrPtr),
595 GetVendorGuidPtr (Variable.CurrPtr),
596 FALSE,
597 &VariablePtrTrack
598 );
599 if (!EFI_ERROR (Status) && VariablePtrTrack.CurrPtr->State == VAR_ADDED) {
600 Variable.CurrPtr = GetNextVariablePtr (Variable.CurrPtr);
601 continue;
602 }
603 }
604
605 //
606 // Don't return NV variable when HOB overrides it
607 //
608 if ((VariableStoreHeader[VariableStoreTypeHob] != NULL) && (VariableStoreHeader[VariableStoreTypeNv] != NULL) &&
609 (Variable.StartPtr == GetStartPointer (VariableStoreHeader[VariableStoreTypeNv]))
610 ) {
611 VariableInHob.StartPtr = GetStartPointer (VariableStoreHeader[VariableStoreTypeHob]);
612 VariableInHob.EndPtr = GetEndPointer (VariableStoreHeader[VariableStoreTypeHob]);
613 Status = FindVariableEx (
614 GetVariableNamePtr (Variable.CurrPtr),
615 GetVendorGuidPtr (Variable.CurrPtr),
616 FALSE,
617 &VariableInHob
618 );
619 if (!EFI_ERROR (Status)) {
620 Variable.CurrPtr = GetNextVariablePtr (Variable.CurrPtr);
621 continue;
622 }
623 }
624
625 *VariablePtr = Variable.CurrPtr;
626 Status = EFI_SUCCESS;
627 goto Done;
628 }
629 }
630
631 Variable.CurrPtr = GetNextVariablePtr (Variable.CurrPtr);
632 }
633
634 Done:
635 return Status;
636 }
637
638 /**
639 Routine used to track statistical information about variable usage.
640 The data is stored in the EFI system table so it can be accessed later.
641 VariableInfo.efi can dump out the table. Only Boot Services variable
642 accesses are tracked by this code. The PcdVariableCollectStatistics
643 build flag controls if this feature is enabled.
644
645 A read that hits in the cache will have Read and Cache true for
646 the transaction. Data is allocated by this routine, but never
647 freed.
648
649 @param[in] VariableName Name of the Variable to track.
650 @param[in] VendorGuid Guid of the Variable to track.
651 @param[in] Volatile TRUE if volatile FALSE if non-volatile.
652 @param[in] Read TRUE if GetVariable() was called.
653 @param[in] Write TRUE if SetVariable() was called.
654 @param[in] Delete TRUE if deleted via SetVariable().
655 @param[in] Cache TRUE for a cache hit.
656
657 **/
658 VOID
659 UpdateVariableInfo (
660 IN CHAR16 *VariableName,
661 IN EFI_GUID *VendorGuid,
662 IN BOOLEAN Volatile,
663 IN BOOLEAN Read,
664 IN BOOLEAN Write,
665 IN BOOLEAN Delete,
666 IN BOOLEAN Cache
667 )
668 {
669 VARIABLE_INFO_ENTRY *Entry;
670
671 if (FeaturePcdGet (PcdVariableCollectStatistics)) {
672
673 if (AtRuntime ()) {
674 // Don't collect statistics at runtime.
675 return;
676 }
677
678 if (gVariableInfo == NULL) {
679 //
680 // On the first call allocate a entry and place a pointer to it in
681 // the EFI System Table.
682 //
683 gVariableInfo = AllocateZeroPool (sizeof (VARIABLE_INFO_ENTRY));
684 ASSERT (gVariableInfo != NULL);
685
686 CopyGuid (&gVariableInfo->VendorGuid, VendorGuid);
687 gVariableInfo->Name = AllocateZeroPool (StrSize (VariableName));
688 ASSERT (gVariableInfo->Name != NULL);
689 StrCpyS (gVariableInfo->Name, StrSize(VariableName)/sizeof(CHAR16), VariableName);
690 gVariableInfo->Volatile = Volatile;
691 }
692
693
694 for (Entry = gVariableInfo; Entry != NULL; Entry = Entry->Next) {
695 if (CompareGuid (VendorGuid, &Entry->VendorGuid)) {
696 if (StrCmp (VariableName, Entry->Name) == 0) {
697 if (Read) {
698 Entry->ReadCount++;
699 }
700 if (Write) {
701 Entry->WriteCount++;
702 }
703 if (Delete) {
704 Entry->DeleteCount++;
705 }
706 if (Cache) {
707 Entry->CacheCount++;
708 }
709
710 return;
711 }
712 }
713
714 if (Entry->Next == NULL) {
715 //
716 // If the entry is not in the table add it.
717 // Next iteration of the loop will fill in the data.
718 //
719 Entry->Next = AllocateZeroPool (sizeof (VARIABLE_INFO_ENTRY));
720 ASSERT (Entry->Next != NULL);
721
722 CopyGuid (&Entry->Next->VendorGuid, VendorGuid);
723 Entry->Next->Name = AllocateZeroPool (StrSize (VariableName));
724 ASSERT (Entry->Next->Name != NULL);
725 StrCpyS (Entry->Next->Name, StrSize(VariableName)/sizeof(CHAR16), VariableName);
726 Entry->Next->Volatile = Volatile;
727 }
728
729 }
730 }
731 }