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 This program and the accompanying materials
10 are licensed and made available under the terms and conditions of the BSD License
11 which accompanies this distribution. The full text of the license may be found at
12 http://opensource.org/licenses/bsd-license.php.
14 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
15 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
20 #include "UefiLibInternal.h"
23 Empty constructor function that is required to resolve dependencies between
28 @param ImageHandle The firmware allocated handle for the EFI image.
29 @param SystemTable A pointer to the EFI System Table.
31 @retval EFI_SUCCESS The constructor executed correctly.
37 IN EFI_HANDLE ImageHandle
,
38 IN EFI_SYSTEM_TABLE
*SystemTable
45 Compare whether two names of languages are identical.
47 @param Language1 Name of language 1.
48 @param Language2 Name of language 2.
50 @retval TRUE Language 1 and language 2 are the same.
51 @retval FALSE Language 1 and language 2 are not the same.
55 CompareIso639LanguageCode (
56 IN CONST CHAR8
*Language1
,
57 IN CONST CHAR8
*Language2
63 Name1
= ReadUnaligned24 ((CONST UINT32
*) Language1
);
64 Name2
= ReadUnaligned24 ((CONST UINT32
*) Language2
);
66 return (BOOLEAN
) (Name1
== Name2
);
70 Retrieves a pointer to the system configuration table from the EFI System Table
71 based on a specified GUID.
73 This function searches the list of configuration tables stored in the EFI System Table
74 for a table with a GUID that matches TableGuid. If a match is found, then a pointer to
75 the configuration table is returned in Table., and EFI_SUCCESS is returned. If a matching GUID
76 is not found, then EFI_NOT_FOUND is returned.
77 If TableGuid is NULL, then ASSERT().
78 If Table is NULL, then ASSERT().
80 @param TableGuid The pointer to table's GUID type.
81 @param Table The pointer to the table associated with TableGuid in the EFI System Table.
83 @retval EFI_SUCCESS A configuration table matching TableGuid was found.
84 @retval EFI_NOT_FOUND A configuration table matching TableGuid could not be found.
89 EfiGetSystemConfigurationTable (
90 IN EFI_GUID
*TableGuid
,
94 EFI_SYSTEM_TABLE
*SystemTable
;
97 ASSERT (TableGuid
!= NULL
);
98 ASSERT (Table
!= NULL
);
102 for (Index
= 0; Index
< SystemTable
->NumberOfTableEntries
; Index
++) {
103 if (CompareGuid (TableGuid
, &(SystemTable
->ConfigurationTable
[Index
].VendorGuid
))) {
104 *Table
= SystemTable
->ConfigurationTable
[Index
].VendorTable
;
109 return EFI_NOT_FOUND
;
113 Creates and returns a notification event and registers that event with all the protocol
114 instances specified by ProtocolGuid.
116 This function causes the notification function to be executed for every protocol of type
117 ProtocolGuid instance that exists in the system when this function is invoked. If there are
118 no instances of ProtocolGuid in the handle database at the time this function is invoked,
119 then the notification function is still executed one time. In addition, every time a protocol
120 of type ProtocolGuid instance is installed or reinstalled, the notification function is also
121 executed. This function returns the notification event that was created.
122 If ProtocolGuid is NULL, then ASSERT().
123 If NotifyTpl is not a legal TPL value, then ASSERT().
124 If NotifyFunction is NULL, then ASSERT().
125 If Registration is NULL, then ASSERT().
128 @param ProtocolGuid Supplies GUID of the protocol upon whose installation the event is fired.
129 @param NotifyTpl Supplies the task priority level of the event notifications.
130 @param NotifyFunction Supplies the function to notify when the event is signaled.
131 @param NotifyContext The context parameter to pass to NotifyFunction.
132 @param Registration A pointer to a memory location to receive the registration value.
133 This value is passed to LocateHandle() to obtain new handles that
134 have been added that support the ProtocolGuid-specified protocol.
136 @return The notification event that was created.
141 EfiCreateProtocolNotifyEvent(
142 IN EFI_GUID
*ProtocolGuid
,
143 IN EFI_TPL NotifyTpl
,
144 IN EFI_EVENT_NOTIFY NotifyFunction
,
145 IN VOID
*NotifyContext
, OPTIONAL
146 OUT VOID
**Registration
152 ASSERT (ProtocolGuid
!= NULL
);
153 ASSERT (NotifyFunction
!= NULL
);
154 ASSERT (Registration
!= NULL
);
160 Status
= gBS
->CreateEvent (
167 ASSERT_EFI_ERROR (Status
);
170 // Register for protocol notifications on this event
173 Status
= gBS
->RegisterProtocolNotify (
179 ASSERT_EFI_ERROR (Status
);
182 // Kick the event so we will perform an initial pass of
183 // current installed drivers
186 gBS
->SignalEvent (Event
);
191 Creates a named event that can be signaled with EfiNamedEventSignal().
193 This function creates an event using NotifyTpl, NoifyFunction, and NotifyContext.
194 This event is signaled with EfiNamedEventSignal(). This provides the ability for one or more
195 listeners on the same event named by the GUID specified by Name.
196 If Name is NULL, then ASSERT().
197 If NotifyTpl is not a legal TPL value, then ASSERT().
198 If NotifyFunction is NULL, then ASSERT().
200 @param Name Supplies the GUID name of the event.
201 @param NotifyTpl Supplies the task priority level of the event notifications.
202 @param NotifyFunction Supplies the function to notify when the event is signaled.
203 @param NotifyContext The context parameter to pass to NotifyFunction.
204 @param Registration A pointer to a memory location to receive the registration value.
206 @retval EFI_SUCCESS A named event was created.
207 @retval EFI_OUT_OF_RESOURCES There are not enough resource to create the named event.
212 EfiNamedEventListen (
213 IN CONST EFI_GUID
*Name
,
214 IN EFI_TPL NotifyTpl
,
215 IN EFI_EVENT_NOTIFY NotifyFunction
,
216 IN CONST VOID
*NotifyContext
, OPTIONAL
217 OUT VOID
*Registration OPTIONAL
222 VOID
*RegistrationLocal
;
224 ASSERT (Name
!= NULL
);
225 ASSERT (NotifyFunction
!= NULL
);
226 ASSERT (NotifyTpl
<= TPL_HIGH_LEVEL
);
231 Status
= gBS
->CreateEvent (
235 (VOID
*) NotifyContext
,
238 ASSERT_EFI_ERROR (Status
);
241 // The Registration is not optional to RegisterProtocolNotify().
242 // To make it optional to EfiNamedEventListen(), may need to substitute with a local.
244 if (Registration
!= NULL
) {
245 RegistrationLocal
= Registration
;
247 RegistrationLocal
= &RegistrationLocal
;
251 // Register for an installation of protocol interface
254 Status
= gBS
->RegisterProtocolNotify (
259 ASSERT_EFI_ERROR (Status
);
265 Signals a named event created with EfiNamedEventListen().
267 This function signals the named event specified by Name. The named event must have been
268 created with EfiNamedEventListen().
269 If Name is NULL, then ASSERT().
271 @param Name Supplies the GUID name of the event.
273 @retval EFI_SUCCESS A named event was signaled.
274 @retval EFI_OUT_OF_RESOURCES There are not enough resource to signal the named event.
279 EfiNamedEventSignal (
280 IN CONST EFI_GUID
*Name
286 ASSERT(Name
!= NULL
);
289 Status
= gBS
->InstallProtocolInterface (
292 EFI_NATIVE_INTERFACE
,
295 ASSERT_EFI_ERROR (Status
);
297 Status
= gBS
->UninstallProtocolInterface (
302 ASSERT_EFI_ERROR (Status
);
308 Signals an event group by placing a new event in the group temporarily and
311 @param[in] EventGroup Supplies the unique identifier of the event
314 @retval EFI_SUCCESS The event group was signaled successfully.
315 @retval EFI_INVALID_PARAMETER EventGroup is NULL.
316 @return Error codes that report problems about event
317 creation or signaling.
321 EfiEventGroupSignal (
322 IN CONST EFI_GUID
*EventGroup
328 if (EventGroup
== NULL
) {
329 return EFI_INVALID_PARAMETER
;
332 Status
= gBS
->CreateEventEx (
335 EfiEventEmptyFunction
,
340 if (EFI_ERROR (Status
)) {
344 Status
= gBS
->SignalEvent (Event
);
345 gBS
->CloseEvent (Event
);
351 An empty function that can be used as NotifyFunction parameter of
352 CreateEvent() or CreateEventEx().
354 @param Event Event whose notification function is being invoked.
355 @param Context The pointer to the notification function's context,
356 which is implementation-dependent.
361 EfiEventEmptyFunction (
369 Returns the current TPL.
371 This function returns the current TPL. There is no EFI service to directly
372 retrieve the current TPL. Instead, the RaiseTPL() function is used to raise
373 the TPL to TPL_HIGH_LEVEL. This will return the current TPL. The TPL level
374 can then immediately be restored back to the current TPL level with a call
377 @return The current TPL.
388 Tpl
= gBS
->RaiseTPL (TPL_HIGH_LEVEL
);
389 gBS
->RestoreTPL (Tpl
);
396 Initializes a basic mutual exclusion lock.
398 This function initializes a basic mutual exclusion lock to the released state
399 and returns the lock. Each lock provides mutual exclusion access at its task
400 priority level. Since there is no preemption or multiprocessor support in EFI,
401 acquiring the lock only consists of raising to the locks TPL.
402 If Lock is NULL, then ASSERT().
403 If Priority is not a valid TPL value, then ASSERT().
405 @param Lock A pointer to the lock data structure to initialize.
406 @param Priority EFI TPL is associated with the lock.
414 IN OUT EFI_LOCK
*Lock
,
418 ASSERT (Lock
!= NULL
);
419 ASSERT (Priority
<= TPL_HIGH_LEVEL
);
421 Lock
->Tpl
= Priority
;
422 Lock
->OwnerTpl
= TPL_APPLICATION
;
423 Lock
->Lock
= EfiLockReleased
;
428 Acquires ownership of a lock.
430 This function raises the system's current task priority level to the task
431 priority level of the mutual exclusion lock. Then, it places the lock in the
433 If Lock is NULL, then ASSERT().
434 If Lock is not initialized, then ASSERT().
435 If Lock is already in the acquired state, then ASSERT().
437 @param Lock A pointer to the lock to acquire.
446 ASSERT (Lock
!= NULL
);
447 ASSERT (Lock
->Lock
== EfiLockReleased
);
449 Lock
->OwnerTpl
= gBS
->RaiseTPL (Lock
->Tpl
);
450 Lock
->Lock
= EfiLockAcquired
;
454 Acquires ownership of a lock.
456 This function raises the system's current task priority level to the task priority
457 level of the mutual exclusion lock. Then, it attempts to place the lock in the acquired state.
458 If the lock is already in the acquired state, then EFI_ACCESS_DENIED is returned.
459 Otherwise, EFI_SUCCESS is returned.
460 If Lock is NULL, then ASSERT().
461 If Lock is not initialized, then ASSERT().
463 @param Lock A pointer to the lock to acquire.
465 @retval EFI_SUCCESS The lock was acquired.
466 @retval EFI_ACCESS_DENIED The lock could not be acquired because it is already owned.
471 EfiAcquireLockOrFail (
476 ASSERT (Lock
!= NULL
);
477 ASSERT (Lock
->Lock
!= EfiLockUninitialized
);
479 if (Lock
->Lock
== EfiLockAcquired
) {
481 // Lock is already owned, so bail out
483 return EFI_ACCESS_DENIED
;
486 Lock
->OwnerTpl
= gBS
->RaiseTPL (Lock
->Tpl
);
488 Lock
->Lock
= EfiLockAcquired
;
494 Releases ownership of a lock.
496 This function transitions a mutual exclusion lock from the acquired state to
497 the released state, and restores the system's task priority level to its
499 If Lock is NULL, then ASSERT().
500 If Lock is not initialized, then ASSERT().
501 If Lock is already in the released state, then ASSERT().
503 @param Lock A pointer to the lock to release.
514 ASSERT (Lock
!= NULL
);
515 ASSERT (Lock
->Lock
== EfiLockAcquired
);
517 Tpl
= Lock
->OwnerTpl
;
519 Lock
->Lock
= EfiLockReleased
;
521 gBS
->RestoreTPL (Tpl
);
525 Tests whether a controller handle is being managed by a specific driver.
527 This function tests whether the driver specified by DriverBindingHandle is
528 currently managing the controller specified by ControllerHandle. This test
529 is performed by evaluating if the the protocol specified by ProtocolGuid is
530 present on ControllerHandle and is was opened by DriverBindingHandle with an
531 attribute of EFI_OPEN_PROTOCOL_BY_DRIVER.
532 If ProtocolGuid is NULL, then ASSERT().
534 @param ControllerHandle A handle for a controller to test.
535 @param DriverBindingHandle Specifies the driver binding handle for the
537 @param ProtocolGuid Specifies the protocol that the driver specified
538 by DriverBindingHandle opens in its Start()
541 @retval EFI_SUCCESS ControllerHandle is managed by the driver
542 specified by DriverBindingHandle.
543 @retval EFI_UNSUPPORTED ControllerHandle is not managed by the driver
544 specified by DriverBindingHandle.
549 EfiTestManagedDevice (
550 IN CONST EFI_HANDLE ControllerHandle
,
551 IN CONST EFI_HANDLE DriverBindingHandle
,
552 IN CONST EFI_GUID
*ProtocolGuid
556 VOID
*ManagedInterface
;
558 ASSERT (ProtocolGuid
!= NULL
);
560 Status
= gBS
->OpenProtocol (
562 (EFI_GUID
*) ProtocolGuid
,
566 EFI_OPEN_PROTOCOL_BY_DRIVER
568 if (!EFI_ERROR (Status
)) {
571 (EFI_GUID
*) ProtocolGuid
,
575 return EFI_UNSUPPORTED
;
578 if (Status
!= EFI_ALREADY_STARTED
) {
579 return EFI_UNSUPPORTED
;
586 Tests whether a child handle is a child device of the controller.
588 This function tests whether ChildHandle is one of the children of
589 ControllerHandle. This test is performed by checking to see if the protocol
590 specified by ProtocolGuid is present on ControllerHandle and opened by
591 ChildHandle with an attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
592 If ProtocolGuid is NULL, then ASSERT().
594 @param ControllerHandle A handle for a (parent) controller to test.
595 @param ChildHandle A child handle to test.
596 @param ProtocolGuid Supplies the protocol that the child controller
597 opens on its parent controller.
599 @retval EFI_SUCCESS ChildHandle is a child of the ControllerHandle.
600 @retval EFI_UNSUPPORTED ChildHandle is not a child of the
607 IN CONST EFI_HANDLE ControllerHandle
,
608 IN CONST EFI_HANDLE ChildHandle
,
609 IN CONST EFI_GUID
*ProtocolGuid
613 EFI_OPEN_PROTOCOL_INFORMATION_ENTRY
*OpenInfoBuffer
;
617 ASSERT (ProtocolGuid
!= NULL
);
620 // Retrieve the list of agents that are consuming the specific protocol
621 // on ControllerHandle.
623 Status
= gBS
->OpenProtocolInformation (
625 (EFI_GUID
*) ProtocolGuid
,
629 if (EFI_ERROR (Status
)) {
630 return EFI_UNSUPPORTED
;
634 // Inspect if ChildHandle is one of the agents.
636 Status
= EFI_UNSUPPORTED
;
637 for (Index
= 0; Index
< EntryCount
; Index
++) {
638 if ((OpenInfoBuffer
[Index
].ControllerHandle
== ChildHandle
) &&
639 (OpenInfoBuffer
[Index
].Attributes
& EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
) != 0) {
640 Status
= EFI_SUCCESS
;
645 FreePool (OpenInfoBuffer
);
650 This function looks up a Unicode string in UnicodeStringTable.
652 If Language is a member of SupportedLanguages and a Unicode string is found in
653 UnicodeStringTable that matches the language code specified by Language, then it
654 is returned in UnicodeString.
656 @param Language A pointer to the ISO 639-2 language code for the
657 Unicode string to look up and return.
658 @param SupportedLanguages A pointer to the set of ISO 639-2 language codes
659 that the Unicode string table supports. Language
660 must be a member of this set.
661 @param UnicodeStringTable A pointer to the table of Unicode strings.
662 @param UnicodeString A pointer to the Unicode string from UnicodeStringTable
663 that matches the language specified by Language.
665 @retval EFI_SUCCESS The Unicode string that matches the language
666 specified by Language was found
667 in the table of Unicode strings UnicodeStringTable,
668 and it was returned in UnicodeString.
669 @retval EFI_INVALID_PARAMETER Language is NULL.
670 @retval EFI_INVALID_PARAMETER UnicodeString is NULL.
671 @retval EFI_UNSUPPORTED SupportedLanguages is NULL.
672 @retval EFI_UNSUPPORTED UnicodeStringTable is NULL.
673 @retval EFI_UNSUPPORTED The language specified by Language is not a
674 member of SupportedLanguages.
675 @retval EFI_UNSUPPORTED The language specified by Language is not
676 supported by UnicodeStringTable.
681 LookupUnicodeString (
682 IN CONST CHAR8
*Language
,
683 IN CONST CHAR8
*SupportedLanguages
,
684 IN CONST EFI_UNICODE_STRING_TABLE
*UnicodeStringTable
,
685 OUT CHAR16
**UnicodeString
689 // Make sure the parameters are valid
691 if (Language
== NULL
|| UnicodeString
== NULL
) {
692 return EFI_INVALID_PARAMETER
;
696 // If there are no supported languages, or the Unicode String Table is empty, then the
697 // Unicode String specified by Language is not supported by this Unicode String Table
699 if (SupportedLanguages
== NULL
|| UnicodeStringTable
== NULL
) {
700 return EFI_UNSUPPORTED
;
704 // Make sure Language is in the set of Supported Languages
706 while (*SupportedLanguages
!= 0) {
707 if (CompareIso639LanguageCode (Language
, SupportedLanguages
)) {
710 // Search the Unicode String Table for the matching Language specifier
712 while (UnicodeStringTable
->Language
!= NULL
) {
713 if (CompareIso639LanguageCode (Language
, UnicodeStringTable
->Language
)) {
716 // A matching string was found, so return it
718 *UnicodeString
= UnicodeStringTable
->UnicodeString
;
722 UnicodeStringTable
++;
725 return EFI_UNSUPPORTED
;
728 SupportedLanguages
+= 3;
731 return EFI_UNSUPPORTED
;
737 This function looks up a Unicode string in UnicodeStringTable.
739 If Language is a member of SupportedLanguages and a Unicode string is found in
740 UnicodeStringTable that matches the language code specified by Language, then
741 it is returned in UnicodeString.
743 @param Language A pointer to an ASCII string containing the ISO 639-2 or the
744 RFC 4646 language code for the Unicode string to look up and
745 return. If Iso639Language is TRUE, then this ASCII string is
746 not assumed to be Null-terminated, and only the first three
747 characters are used. If Iso639Language is FALSE, then this ASCII
748 string must be Null-terminated.
749 @param SupportedLanguages A pointer to a Null-terminated ASCII string that contains a
750 set of ISO 639-2 or RFC 4646 language codes that the Unicode
751 string table supports. Language must be a member of this set.
752 If Iso639Language is TRUE, then this string contains one or more
753 ISO 639-2 language codes with no separator characters. If Iso639Language
754 is FALSE, then is string contains one or more RFC 4646 language
755 codes separated by ';'.
756 @param UnicodeStringTable A pointer to the table of Unicode strings. Type EFI_UNICODE_STRING_TABLE
757 is defined in "Related Definitions".
758 @param UnicodeString A pointer to the Null-terminated Unicode string from UnicodeStringTable
759 that matches the language specified by Language.
760 @param Iso639Language Specifies the supported language code format. If it is TRUE, then
761 Language and SupportedLanguages follow ISO 639-2 language code format.
762 Otherwise, they follow RFC 4646 language code format.
765 @retval EFI_SUCCESS The Unicode string that matches the language specified by Language
766 was found in the table of Unicode strings UnicodeStringTable, and
767 it was returned in UnicodeString.
768 @retval EFI_INVALID_PARAMETER Language is NULL.
769 @retval EFI_INVALID_PARAMETER UnicodeString is NULL.
770 @retval EFI_UNSUPPORTED SupportedLanguages is NULL.
771 @retval EFI_UNSUPPORTED UnicodeStringTable is NULL.
772 @retval EFI_UNSUPPORTED The language specified by Language is not a member of SupportedLanguages.
773 @retval EFI_UNSUPPORTED The language specified by Language is not supported by UnicodeStringTable.
778 LookupUnicodeString2 (
779 IN CONST CHAR8
*Language
,
780 IN CONST CHAR8
*SupportedLanguages
,
781 IN CONST EFI_UNICODE_STRING_TABLE
*UnicodeStringTable
,
782 OUT CHAR16
**UnicodeString
,
783 IN BOOLEAN Iso639Language
788 CHAR8
*LanguageString
;
791 // Make sure the parameters are valid
793 if (Language
== NULL
|| UnicodeString
== NULL
) {
794 return EFI_INVALID_PARAMETER
;
798 // If there are no supported languages, or the Unicode String Table is empty, then the
799 // Unicode String specified by Language is not supported by this Unicode String Table
801 if (SupportedLanguages
== NULL
|| UnicodeStringTable
== NULL
) {
802 return EFI_UNSUPPORTED
;
806 // Make sure Language is in the set of Supported Languages
809 while (*SupportedLanguages
!= 0) {
810 if (Iso639Language
) {
811 if (CompareIso639LanguageCode (Language
, SupportedLanguages
)) {
815 SupportedLanguages
+= 3;
817 for (Index
= 0; SupportedLanguages
[Index
] != 0 && SupportedLanguages
[Index
] != ';'; Index
++);
818 if ((AsciiStrnCmp(SupportedLanguages
, Language
, Index
) == 0) && (Language
[Index
] == 0)) {
822 SupportedLanguages
+= Index
;
823 for (; *SupportedLanguages
!= 0 && *SupportedLanguages
== ';'; SupportedLanguages
++);
828 // If Language is not a member of SupportedLanguages, then return EFI_UNSUPPORTED
831 return EFI_UNSUPPORTED
;
835 // Search the Unicode String Table for the matching Language specifier
837 while (UnicodeStringTable
->Language
!= NULL
) {
838 LanguageString
= UnicodeStringTable
->Language
;
839 while (0 != *LanguageString
) {
840 for (Index
= 0 ;LanguageString
[Index
] != 0 && LanguageString
[Index
] != ';'; Index
++);
841 if (AsciiStrnCmp(LanguageString
, Language
, Index
) == 0) {
842 *UnicodeString
= UnicodeStringTable
->UnicodeString
;
845 LanguageString
+= Index
;
846 for (Index
= 0 ;LanguageString
[Index
] != 0 && LanguageString
[Index
] == ';'; Index
++);
848 UnicodeStringTable
++;
851 return EFI_UNSUPPORTED
;
856 This function adds a Unicode string to UnicodeStringTable.
858 If Language is a member of SupportedLanguages then UnicodeString is added to
859 UnicodeStringTable. New buffers are allocated for both Language and
860 UnicodeString. The contents of Language and UnicodeString are copied into
861 these new buffers. These buffers are automatically freed when
862 FreeUnicodeStringTable() is called.
864 @param Language A pointer to the ISO 639-2 language code for the Unicode
866 @param SupportedLanguages A pointer to the set of ISO 639-2 language codes
867 that the Unicode string table supports.
868 Language must be a member of this set.
869 @param UnicodeStringTable A pointer to the table of Unicode strings.
870 @param UnicodeString A pointer to the Unicode string to add.
872 @retval EFI_SUCCESS The Unicode string that matches the language
873 specified by Language was found in the table of
874 Unicode strings UnicodeStringTable, and it was
875 returned in UnicodeString.
876 @retval EFI_INVALID_PARAMETER Language is NULL.
877 @retval EFI_INVALID_PARAMETER UnicodeString is NULL.
878 @retval EFI_INVALID_PARAMETER UnicodeString is an empty string.
879 @retval EFI_UNSUPPORTED SupportedLanguages is NULL.
880 @retval EFI_ALREADY_STARTED A Unicode string with language Language is
881 already present in UnicodeStringTable.
882 @retval EFI_OUT_OF_RESOURCES There is not enough memory to add another
883 Unicode string to UnicodeStringTable.
884 @retval EFI_UNSUPPORTED The language specified by Language is not a
885 member of SupportedLanguages.
891 IN CONST CHAR8
*Language
,
892 IN CONST CHAR8
*SupportedLanguages
,
893 IN OUT EFI_UNICODE_STRING_TABLE
**UnicodeStringTable
,
894 IN CONST CHAR16
*UnicodeString
897 UINTN NumberOfEntries
;
898 EFI_UNICODE_STRING_TABLE
*OldUnicodeStringTable
;
899 EFI_UNICODE_STRING_TABLE
*NewUnicodeStringTable
;
900 UINTN UnicodeStringLength
;
903 // Make sure the parameter are valid
905 if (Language
== NULL
|| UnicodeString
== NULL
|| UnicodeStringTable
== NULL
) {
906 return EFI_INVALID_PARAMETER
;
910 // If there are no supported languages, then a Unicode String can not be added
912 if (SupportedLanguages
== NULL
) {
913 return EFI_UNSUPPORTED
;
917 // If the Unicode String is empty, then a Unicode String can not be added
919 if (UnicodeString
[0] == 0) {
920 return EFI_INVALID_PARAMETER
;
924 // Make sure Language is a member of SupportedLanguages
926 while (*SupportedLanguages
!= 0) {
927 if (CompareIso639LanguageCode (Language
, SupportedLanguages
)) {
930 // Determine the size of the Unicode String Table by looking for a NULL Language entry
933 if (*UnicodeStringTable
!= NULL
) {
934 OldUnicodeStringTable
= *UnicodeStringTable
;
935 while (OldUnicodeStringTable
->Language
!= NULL
) {
936 if (CompareIso639LanguageCode (Language
, OldUnicodeStringTable
->Language
)) {
937 return EFI_ALREADY_STARTED
;
940 OldUnicodeStringTable
++;
946 // Allocate space for a new Unicode String Table. It must hold the current number of
947 // entries, plus 1 entry for the new Unicode String, plus 1 entry for the end of table
950 NewUnicodeStringTable
= AllocatePool ((NumberOfEntries
+ 2) * sizeof (EFI_UNICODE_STRING_TABLE
));
951 if (NewUnicodeStringTable
== NULL
) {
952 return EFI_OUT_OF_RESOURCES
;
956 // If the current Unicode String Table contains any entries, then copy them to the
957 // newly allocated Unicode String Table.
959 if (*UnicodeStringTable
!= NULL
) {
961 NewUnicodeStringTable
,
963 NumberOfEntries
* sizeof (EFI_UNICODE_STRING_TABLE
)
968 // Allocate space for a copy of the Language specifier
970 NewUnicodeStringTable
[NumberOfEntries
].Language
= AllocateCopyPool (3, Language
);
971 if (NewUnicodeStringTable
[NumberOfEntries
].Language
== NULL
) {
972 FreePool (NewUnicodeStringTable
);
973 return EFI_OUT_OF_RESOURCES
;
977 // Compute the length of the Unicode String
979 for (UnicodeStringLength
= 0; UnicodeString
[UnicodeStringLength
] != 0; UnicodeStringLength
++)
983 // Allocate space for a copy of the Unicode String
985 NewUnicodeStringTable
[NumberOfEntries
].UnicodeString
= AllocateCopyPool (
986 (UnicodeStringLength
+ 1) * sizeof (CHAR16
),
989 if (NewUnicodeStringTable
[NumberOfEntries
].UnicodeString
== NULL
) {
990 FreePool (NewUnicodeStringTable
[NumberOfEntries
].Language
);
991 FreePool (NewUnicodeStringTable
);
992 return EFI_OUT_OF_RESOURCES
;
996 // Mark the end of the Unicode String Table
998 NewUnicodeStringTable
[NumberOfEntries
+ 1].Language
= NULL
;
999 NewUnicodeStringTable
[NumberOfEntries
+ 1].UnicodeString
= NULL
;
1002 // Free the old Unicode String Table
1004 if (*UnicodeStringTable
!= NULL
) {
1005 FreePool (*UnicodeStringTable
);
1009 // Point UnicodeStringTable at the newly allocated Unicode String Table
1011 *UnicodeStringTable
= NewUnicodeStringTable
;
1016 SupportedLanguages
+= 3;
1019 return EFI_UNSUPPORTED
;
1024 This function adds the Null-terminated Unicode string specified by UnicodeString
1025 to UnicodeStringTable.
1027 If Language is a member of SupportedLanguages then UnicodeString is added to
1028 UnicodeStringTable. New buffers are allocated for both Language and UnicodeString.
1029 The contents of Language and UnicodeString are copied into these new buffers.
1030 These buffers are automatically freed when EfiLibFreeUnicodeStringTable() is called.
1032 @param Language A pointer to an ASCII string containing the ISO 639-2 or
1033 the RFC 4646 language code for the Unicode string to add.
1034 If Iso639Language is TRUE, then this ASCII string is not
1035 assumed to be Null-terminated, and only the first three
1036 chacters are used. If Iso639Language is FALSE, then this
1037 ASCII string must be Null-terminated.
1038 @param SupportedLanguages A pointer to a Null-terminated ASCII string that contains
1039 a set of ISO 639-2 or RFC 4646 language codes that the Unicode
1040 string table supports. Language must be a member of this set.
1041 If Iso639Language is TRUE, then this string contains one or more
1042 ISO 639-2 language codes with no separator characters.
1043 If Iso639Language is FALSE, then is string contains one or more
1044 RFC 4646 language codes separated by ';'.
1045 @param UnicodeStringTable A pointer to the table of Unicode strings. Type EFI_UNICODE_STRING_TABLE
1046 is defined in "Related Definitions".
1047 @param UnicodeString A pointer to the Unicode string to add.
1048 @param Iso639Language Specifies the supported language code format. If it is TRUE,
1049 then Language and SupportedLanguages follow ISO 639-2 language code format.
1050 Otherwise, they follow RFC 4646 language code format.
1052 @retval EFI_SUCCESS The Unicode string that matches the language specified by
1053 Language was found in the table of Unicode strings UnicodeStringTable,
1054 and it was returned in UnicodeString.
1055 @retval EFI_INVALID_PARAMETER Language is NULL.
1056 @retval EFI_INVALID_PARAMETER UnicodeString is NULL.
1057 @retval EFI_INVALID_PARAMETER UnicodeString is an empty string.
1058 @retval EFI_UNSUPPORTED SupportedLanguages is NULL.
1059 @retval EFI_ALREADY_STARTED A Unicode string with language Language is already present in
1061 @retval EFI_OUT_OF_RESOURCES There is not enough memory to add another Unicode string UnicodeStringTable.
1062 @retval EFI_UNSUPPORTED The language specified by Language is not a member of SupportedLanguages.
1068 IN CONST CHAR8
*Language
,
1069 IN CONST CHAR8
*SupportedLanguages
,
1070 IN OUT EFI_UNICODE_STRING_TABLE
**UnicodeStringTable
,
1071 IN CONST CHAR16
*UnicodeString
,
1072 IN BOOLEAN Iso639Language
1075 UINTN NumberOfEntries
;
1076 EFI_UNICODE_STRING_TABLE
*OldUnicodeStringTable
;
1077 EFI_UNICODE_STRING_TABLE
*NewUnicodeStringTable
;
1078 UINTN UnicodeStringLength
;
1081 CHAR8
*LanguageString
;
1084 // Make sure the parameter are valid
1086 if (Language
== NULL
|| UnicodeString
== NULL
|| UnicodeStringTable
== NULL
) {
1087 return EFI_INVALID_PARAMETER
;
1091 // If there are no supported languages, then a Unicode String can not be added
1093 if (SupportedLanguages
== NULL
) {
1094 return EFI_UNSUPPORTED
;
1098 // If the Unicode String is empty, then a Unicode String can not be added
1100 if (UnicodeString
[0] == 0) {
1101 return EFI_INVALID_PARAMETER
;
1105 // Make sure Language is a member of SupportedLanguages
1108 while (*SupportedLanguages
!= 0) {
1109 if (Iso639Language
) {
1110 if (CompareIso639LanguageCode (Language
, SupportedLanguages
)) {
1114 SupportedLanguages
+= 3;
1116 for (Index
= 0; SupportedLanguages
[Index
] != 0 && SupportedLanguages
[Index
] != ';'; Index
++);
1117 if (AsciiStrnCmp(SupportedLanguages
, Language
, Index
) == 0) {
1121 SupportedLanguages
+= Index
;
1122 for (; *SupportedLanguages
!= 0 && *SupportedLanguages
== ';'; SupportedLanguages
++);
1127 // If Language is not a member of SupportedLanguages, then return EFI_UNSUPPORTED
1130 return EFI_UNSUPPORTED
;
1134 // Determine the size of the Unicode String Table by looking for a NULL Language entry
1136 NumberOfEntries
= 0;
1137 if (*UnicodeStringTable
!= NULL
) {
1138 OldUnicodeStringTable
= *UnicodeStringTable
;
1139 while (OldUnicodeStringTable
->Language
!= NULL
) {
1140 LanguageString
= OldUnicodeStringTable
->Language
;
1142 while (*LanguageString
!= 0) {
1143 for (Index
= 0; LanguageString
[Index
] != 0 && LanguageString
[Index
] != ';'; Index
++);
1145 if (AsciiStrnCmp (Language
, LanguageString
, Index
) == 0) {
1146 return EFI_ALREADY_STARTED
;
1148 LanguageString
+= Index
;
1149 for (; *LanguageString
!= 0 && *LanguageString
== ';'; LanguageString
++);
1151 OldUnicodeStringTable
++;
1157 // Allocate space for a new Unicode String Table. It must hold the current number of
1158 // entries, plus 1 entry for the new Unicode String, plus 1 entry for the end of table
1161 NewUnicodeStringTable
= AllocatePool ((NumberOfEntries
+ 2) * sizeof (EFI_UNICODE_STRING_TABLE
));
1162 if (NewUnicodeStringTable
== NULL
) {
1163 return EFI_OUT_OF_RESOURCES
;
1167 // If the current Unicode String Table contains any entries, then copy them to the
1168 // newly allocated Unicode String Table.
1170 if (*UnicodeStringTable
!= NULL
) {
1172 NewUnicodeStringTable
,
1173 *UnicodeStringTable
,
1174 NumberOfEntries
* sizeof (EFI_UNICODE_STRING_TABLE
)
1179 // Allocate space for a copy of the Language specifier
1181 NewUnicodeStringTable
[NumberOfEntries
].Language
= AllocateCopyPool (AsciiStrSize(Language
), Language
);
1182 if (NewUnicodeStringTable
[NumberOfEntries
].Language
== NULL
) {
1183 FreePool (NewUnicodeStringTable
);
1184 return EFI_OUT_OF_RESOURCES
;
1188 // Compute the length of the Unicode String
1190 for (UnicodeStringLength
= 0; UnicodeString
[UnicodeStringLength
] != 0; UnicodeStringLength
++);
1193 // Allocate space for a copy of the Unicode String
1195 NewUnicodeStringTable
[NumberOfEntries
].UnicodeString
= AllocateCopyPool (StrSize (UnicodeString
), UnicodeString
);
1196 if (NewUnicodeStringTable
[NumberOfEntries
].UnicodeString
== NULL
) {
1197 FreePool (NewUnicodeStringTable
[NumberOfEntries
].Language
);
1198 FreePool (NewUnicodeStringTable
);
1199 return EFI_OUT_OF_RESOURCES
;
1203 // Mark the end of the Unicode String Table
1205 NewUnicodeStringTable
[NumberOfEntries
+ 1].Language
= NULL
;
1206 NewUnicodeStringTable
[NumberOfEntries
+ 1].UnicodeString
= NULL
;
1209 // Free the old Unicode String Table
1211 if (*UnicodeStringTable
!= NULL
) {
1212 FreePool (*UnicodeStringTable
);
1216 // Point UnicodeStringTable at the newly allocated Unicode String Table
1218 *UnicodeStringTable
= NewUnicodeStringTable
;
1224 This function frees the table of Unicode strings in UnicodeStringTable.
1226 If UnicodeStringTable is NULL, then EFI_SUCCESS is returned.
1227 Otherwise, each language code, and each Unicode string in the Unicode string
1228 table are freed, and EFI_SUCCESS is returned.
1230 @param UnicodeStringTable A pointer to the table of Unicode strings.
1232 @retval EFI_SUCCESS The Unicode string table was freed.
1237 FreeUnicodeStringTable (
1238 IN EFI_UNICODE_STRING_TABLE
*UnicodeStringTable
1244 // If the Unicode String Table is NULL, then it is already freed
1246 if (UnicodeStringTable
== NULL
) {
1251 // Loop through the Unicode String Table until we reach the end of table marker
1253 for (Index
= 0; UnicodeStringTable
[Index
].Language
!= NULL
; Index
++) {
1256 // Free the Language string from the Unicode String Table
1258 FreePool (UnicodeStringTable
[Index
].Language
);
1261 // Free the Unicode String from the Unicode String Table
1263 if (UnicodeStringTable
[Index
].UnicodeString
!= NULL
) {
1264 FreePool (UnicodeStringTable
[Index
].UnicodeString
);
1269 // Free the Unicode String Table itself
1271 FreePool (UnicodeStringTable
);
1276 #ifndef DISABLE_NEW_DEPRECATED_INTERFACES
1279 [ATTENTION] This function will be deprecated for security reason.
1281 Returns a pointer to an allocated buffer that contains the contents of a
1282 variable retrieved through the UEFI Runtime Service GetVariable(). The
1283 returned buffer is allocated using AllocatePool(). The caller is responsible
1284 for freeing this buffer with FreePool().
1286 If Name is NULL, then ASSERT().
1287 If Guid is NULL, then ASSERT().
1289 @param[in] Name The pointer to a Null-terminated Unicode string.
1290 @param[in] Guid The pointer to an EFI_GUID structure
1292 @retval NULL The variable could not be retrieved.
1293 @retval NULL There are not enough resources available for the variable contents.
1294 @retval Other A pointer to allocated buffer containing the variable contents.
1300 IN CONST CHAR16
*Name
,
1301 IN CONST EFI_GUID
*Guid
1308 ASSERT (Name
!= NULL
);
1309 ASSERT (Guid
!= NULL
);
1312 // Try to get the variable size.
1316 Status
= gRT
->GetVariable ((CHAR16
*) Name
, (EFI_GUID
*) Guid
, NULL
, &Size
, Value
);
1317 if (Status
!= EFI_BUFFER_TOO_SMALL
) {
1322 // Allocate buffer to get the variable.
1324 Value
= AllocatePool (Size
);
1325 if (Value
== NULL
) {
1330 // Get the variable data.
1332 Status
= gRT
->GetVariable ((CHAR16
*) Name
, (EFI_GUID
*) Guid
, NULL
, &Size
, Value
);
1333 if (EFI_ERROR (Status
)) {
1342 [ATTENTION] This function will be deprecated for security reason.
1344 Returns a pointer to an allocated buffer that contains the contents of a
1345 variable retrieved through the UEFI Runtime Service GetVariable(). This
1346 function always uses the EFI_GLOBAL_VARIABLE GUID to retrieve variables.
1347 The returned buffer is allocated using AllocatePool(). The caller is
1348 responsible for freeing this buffer with FreePool().
1350 If Name is NULL, then ASSERT().
1352 @param[in] Name The pointer to a Null-terminated Unicode string.
1354 @retval NULL The variable could not be retrieved.
1355 @retval NULL There are not enough resources available for the variable contents.
1356 @retval Other A pointer to allocated buffer containing the variable contents.
1361 GetEfiGlobalVariable (
1362 IN CONST CHAR16
*Name
1365 return GetVariable (Name
, &gEfiGlobalVariableGuid
);
1370 Returns the status whether get the variable success. The function retrieves
1371 variable through the UEFI Runtime Service GetVariable(). The
1372 returned buffer is allocated using AllocatePool(). The caller is responsible
1373 for freeing this buffer with FreePool().
1375 If Name is NULL, then ASSERT().
1376 If Guid is NULL, then ASSERT().
1377 If Value is NULL, then ASSERT().
1379 @param[in] Name The pointer to a Null-terminated Unicode string.
1380 @param[in] Guid The pointer to an EFI_GUID structure
1381 @param[out] Value The buffer point saved the variable info.
1382 @param[out] Size The buffer size of the variable.
1384 @return EFI_OUT_OF_RESOURCES Allocate buffer failed.
1385 @return EFI_SUCCESS Find the specified variable.
1386 @return Others Errors Return errors from call to gRT->GetVariable.
1392 IN CONST CHAR16
*Name
,
1393 IN CONST EFI_GUID
*Guid
,
1395 OUT UINTN
*Size OPTIONAL
1401 ASSERT (Name
!= NULL
&& Guid
!= NULL
&& Value
!= NULL
);
1404 // Try to get the variable size.
1412 Status
= gRT
->GetVariable ((CHAR16
*) Name
, (EFI_GUID
*) Guid
, NULL
, &BufferSize
, *Value
);
1413 if (Status
!= EFI_BUFFER_TOO_SMALL
) {
1418 // Allocate buffer to get the variable.
1420 *Value
= AllocatePool (BufferSize
);
1421 ASSERT (*Value
!= NULL
);
1422 if (*Value
== NULL
) {
1423 return EFI_OUT_OF_RESOURCES
;
1427 // Get the variable data.
1429 Status
= gRT
->GetVariable ((CHAR16
*) Name
, (EFI_GUID
*) Guid
, NULL
, &BufferSize
, *Value
);
1430 if (EFI_ERROR (Status
)) {
1443 Returns a pointer to an allocated buffer that contains the contents of a
1444 variable retrieved through the UEFI Runtime Service GetVariable(). This
1445 function always uses the EFI_GLOBAL_VARIABLE GUID to retrieve variables.
1446 The returned buffer is allocated using AllocatePool(). The caller is
1447 responsible for freeing this buffer with FreePool().
1449 If Name is NULL, then ASSERT().
1450 If Value is NULL, then ASSERT().
1452 @param[in] Name The pointer to a Null-terminated Unicode string.
1453 @param[out] Value The buffer point saved the variable info.
1454 @param[out] Size The buffer size of the variable.
1456 @return EFI_OUT_OF_RESOURCES Allocate buffer failed.
1457 @return EFI_SUCCESS Find the specified variable.
1458 @return Others Errors Return errors from call to gRT->GetVariable.
1463 GetEfiGlobalVariable2 (
1464 IN CONST CHAR16
*Name
,
1466 OUT UINTN
*Size OPTIONAL
1469 return GetVariable2 (Name
, &gEfiGlobalVariableGuid
, Value
, Size
);
1473 Returns a pointer to an allocated buffer that contains the best matching language
1474 from a set of supported languages.
1476 This function supports both ISO 639-2 and RFC 4646 language codes, but language
1477 code types may not be mixed in a single call to this function. The language
1478 code returned is allocated using AllocatePool(). The caller is responsible for
1479 freeing the allocated buffer using FreePool(). This function supports a variable
1480 argument list that allows the caller to pass in a prioritized list of language
1481 codes to test against all the language codes in SupportedLanguages.
1483 If SupportedLanguages is NULL, then ASSERT().
1485 @param[in] SupportedLanguages A pointer to a Null-terminated ASCII string that
1486 contains a set of language codes in the format
1487 specified by Iso639Language.
1488 @param[in] Iso639Language If not zero, then all language codes are assumed to be
1489 in ISO 639-2 format. If zero, then all language
1490 codes are assumed to be in RFC 4646 language format
1491 @param[in] ... A variable argument list that contains pointers to
1492 Null-terminated ASCII strings that contain one or more
1493 language codes in the format specified by Iso639Language.
1494 The first language code from each of these language
1495 code lists is used to determine if it is an exact or
1496 close match to any of the language codes in
1497 SupportedLanguages. Close matches only apply to RFC 4646
1498 language codes, and the matching algorithm from RFC 4647
1499 is used to determine if a close match is present. If
1500 an exact or close match is found, then the matching
1501 language code from SupportedLanguages is returned. If
1502 no matches are found, then the next variable argument
1503 parameter is evaluated. The variable argument list
1504 is terminated by a NULL.
1506 @retval NULL The best matching language could not be found in SupportedLanguages.
1507 @retval NULL There are not enough resources available to return the best matching
1509 @retval Other A pointer to a Null-terminated ASCII string that is the best matching
1510 language in SupportedLanguages.
1516 IN CONST CHAR8
*SupportedLanguages
,
1517 IN UINTN Iso639Language
,
1523 UINTN CompareLength
;
1524 UINTN LanguageLength
;
1525 CONST CHAR8
*Supported
;
1526 CHAR8
*BestLanguage
;
1528 ASSERT (SupportedLanguages
!= NULL
);
1530 VA_START (Args
, Iso639Language
);
1531 while ((Language
= VA_ARG (Args
, CHAR8
*)) != NULL
) {
1533 // Default to ISO 639-2 mode
1536 LanguageLength
= MIN (3, AsciiStrLen (Language
));
1539 // If in RFC 4646 mode, then determine the length of the first RFC 4646 language code in Language
1541 if (Iso639Language
== 0) {
1542 for (LanguageLength
= 0; Language
[LanguageLength
] != 0 && Language
[LanguageLength
] != ';'; LanguageLength
++);
1546 // Trim back the length of Language used until it is empty
1548 while (LanguageLength
> 0) {
1550 // Loop through all language codes in SupportedLanguages
1552 for (Supported
= SupportedLanguages
; *Supported
!= '\0'; Supported
+= CompareLength
) {
1554 // In RFC 4646 mode, then Loop through all language codes in SupportedLanguages
1556 if (Iso639Language
== 0) {
1558 // Skip ';' characters in Supported
1560 for (; *Supported
!= '\0' && *Supported
== ';'; Supported
++);
1562 // Determine the length of the next language code in Supported
1564 for (CompareLength
= 0; Supported
[CompareLength
] != 0 && Supported
[CompareLength
] != ';'; CompareLength
++);
1566 // If Language is longer than the Supported, then skip to the next language
1568 if (LanguageLength
> CompareLength
) {
1573 // See if the first LanguageLength characters in Supported match Language
1575 if (AsciiStrnCmp (Supported
, Language
, LanguageLength
) == 0) {
1578 // Allocate, copy, and return the best matching language code from SupportedLanguages
1580 BestLanguage
= AllocateZeroPool (CompareLength
+ 1);
1581 if (BestLanguage
== NULL
) {
1584 return CopyMem (BestLanguage
, Supported
, CompareLength
);
1588 if (Iso639Language
!= 0) {
1590 // If ISO 639 mode, then each language can only be tested once
1595 // If RFC 4646 mode, then trim Language from the right to the next '-' character
1597 for (LanguageLength
--; LanguageLength
> 0 && Language
[LanguageLength
] != '-'; LanguageLength
--);
1604 // No matches were found
1610 Returns an array of protocol instance that matches the given protocol.
1612 @param[in] Protocol Provides the protocol to search for.
1613 @param[out] NoProtocols The number of protocols returned in Buffer.
1614 @param[out] Buffer A pointer to the buffer to return the requested
1615 array of protocol instances that match Protocol.
1616 The returned buffer is allocated using
1617 EFI_BOOT_SERVICES.AllocatePool(). The caller is
1618 responsible for freeing this buffer with
1619 EFI_BOOT_SERVICES.FreePool().
1621 @retval EFI_SUCCESS The array of protocols was returned in Buffer,
1622 and the number of protocols in Buffer was
1623 returned in NoProtocols.
1624 @retval EFI_NOT_FOUND No protocols found.
1625 @retval EFI_OUT_OF_RESOURCES There is not enough pool memory to store the
1627 @retval EFI_INVALID_PARAMETER Protocol is NULL.
1628 @retval EFI_INVALID_PARAMETER NoProtocols is NULL.
1629 @retval EFI_INVALID_PARAMETER Buffer is NULL.
1634 EfiLocateProtocolBuffer (
1635 IN EFI_GUID
*Protocol
,
1636 OUT UINTN
*NoProtocols
,
1642 EFI_HANDLE
*HandleBuffer
;
1646 // Check input parameters
1648 if (Protocol
== NULL
|| NoProtocols
== NULL
|| Buffer
== NULL
) {
1649 return EFI_INVALID_PARAMETER
;
1653 // Initialze output parameters
1659 // Retrieve the array of handles that support Protocol
1661 Status
= gBS
->LocateHandleBuffer (
1668 if (EFI_ERROR (Status
)) {
1673 // Allocate array of protocol instances
1675 Status
= gBS
->AllocatePool (
1676 EfiBootServicesData
,
1677 NoHandles
* sizeof (VOID
*),
1680 if (EFI_ERROR (Status
)) {
1682 // Free the handle buffer
1684 gBS
->FreePool (HandleBuffer
);
1685 return EFI_OUT_OF_RESOURCES
;
1687 ZeroMem (*Buffer
, NoHandles
* sizeof (VOID
*));
1690 // Lookup Protocol on each handle in HandleBuffer to fill in the array of
1691 // protocol instances. Handle case where protocol instance was present when
1692 // LocateHandleBuffer() was called, but is not present when HandleProtocol()
1695 for (Index
= 0, *NoProtocols
= 0; Index
< NoHandles
; Index
++) {
1696 Status
= gBS
->HandleProtocol (
1697 HandleBuffer
[Index
],
1699 &((*Buffer
)[*NoProtocols
])
1701 if (!EFI_ERROR (Status
)) {
1707 // Free the handle buffer
1709 gBS
->FreePool (HandleBuffer
);
1712 // Make sure at least one protocol instance was found
1714 if (*NoProtocols
== 0) {
1715 gBS
->FreePool (*Buffer
);
1717 return EFI_NOT_FOUND
;