]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/UefiLib/UefiLib.c
remove unnecessary comments introduced by tools from MdePkg. The regular express...
[mirror_edk2.git] / MdePkg / Library / UefiLib / UefiLib.c
index 5fe7999073270bd12958edbfbf0cdb98e0567b19..a58878e5d348c0c83233f5ebdcd9bf3f6fb6967f 100644 (file)
   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 \r
-  Module Name:  UefiLib.c\r
-\r
 **/\r
 \r
-//\r
-// Include common header file for this module.\r
-//\r
-#include "CommonHeader.h"\r
+\r
+#include "UefiLibInternal.h"\r
 \r
 /**\r
   Compare whether two names of languages are identical.\r
@@ -29,7 +25,6 @@
   @retval FALSE     Language 1 and language 2 are not the same.\r
 \r
 **/\r
-STATIC\r
 BOOLEAN\r
 CompareIso639LanguageCode (\r
   IN CONST CHAR8  *Language1,\r
@@ -50,6 +45,8 @@ CompareIso639LanguageCode (
   Table for a table with a GUID that matches TableGuid.  If a match is found,\r
   then a pointer to the configuration table is returned in Table, and EFI_SUCCESS\r
   is returned.  If a matching GUID is not found, then EFI_NOT_FOUND is returned.\r
+  If TableGuid is NULL, then ASSERT().\r
+  If Table is NULL, then ASSERT().\r
 \r
   @param  TableGuid       Pointer to table's GUID type..\r
   @param  Table           Pointer to the table associated with TableGuid in the EFI System Table.\r
@@ -149,6 +146,9 @@ EfiCreateProtocolNotifyEvent(
   This function creates an event using NotifyTpl, NoifyFunction, and NotifyContext.\r
   This event is signaled with EfiNamedEventSignal().  This provide the ability for\r
   one or more listeners on the same event named by the GUID specified by Name.\r
+  If Name is NULL, then ASSERT().\r
+  If NotifyTpl is not a legal TPL value, then ASSERT().\r
+  If NotifyFunction is NULL, then ASSERT().\r
 \r
   @param  Name                  Supplies GUID name of the event.\r
   @param  NotifyTpl             Supplies the task priority level of the event notifications.\r
@@ -174,6 +174,10 @@ EfiNamedEventListen (
   EFI_EVENT   Event;\r
   VOID        *RegistrationLocal;\r
 \r
+  ASSERT (Name != NULL);\r
+  ASSERT (NotifyFunction != NULL);\r
+  ASSERT (NotifyTpl <= TPL_HIGH_LEVEL);\r
+  \r
   //\r
   // Create event\r
   //\r
@@ -207,7 +211,7 @@ EfiNamedEventListen (
                   );\r
   ASSERT_EFI_ERROR (Status);\r
 \r
-  return EFI_SUCCESS;\r
+  return Status;\r
 }\r
 \r
 /**\r
@@ -245,7 +249,7 @@ EfiNamedEventSignal (
                   );\r
   ASSERT_EFI_ERROR (Status);\r
 \r
-  return EFI_SUCCESS;\r
+  return Status;\r
 }\r
 \r
 /**\r
@@ -259,7 +263,7 @@ EfiNamedEventSignal (
 \r
   @param  VOID\r
 \r
-  @retvale EFI_TPL              The current TPL.\r
+  @retval EFI_TPL              The current TPL.\r
 \r
 **/\r
 EFI_TPL\r
@@ -282,6 +286,8 @@ EfiGetCurrentTpl (
   and returns the lock.  Each lock provides mutual exclusion access at its task\r
   priority level.  Since there is no preemption or multiprocessor support in EFI,\r
   acquiring the lock only consists of raising to the locks TPL.\r
+  If Lock is NULL, then ASSERT().\r
+  If Priority is not a valid TPL value, then ASSERT().\r
 \r
   @param  Lock       A pointer to the lock data structure to initialize.\r
   @param  Priority   EFI TPL associated with the lock.\r
@@ -309,8 +315,11 @@ EfiInitializeLock (
   This function raises the system's current task priority level to the task\r
   priority level of the mutual exclusion lock.  Then, it places the lock in the\r
   acquired state.\r
+  If Lock is NULL, then ASSERT().\r
+  If Lock is not initialized, then ASSERT().\r
+  If Lock is already in the acquired state, then ASSERT().\r
 \r
-  @param  Priority  The task priority level of the lock.\r
+  @param  Lock   The task lock with priority level.\r
 \r
 **/\r
 VOID\r
@@ -459,7 +468,7 @@ EfiTestManagedDevice (
 \r
   @param  ControllerHandle     A handle for a (parent) controller to test.\r
   @param  ChildHandle          A child handle to test.\r
-  @param  ConsumsedGuid        Supplies the protocol that the child controller\r
+  @param  ProtocolGuid         Supplies the protocol that the child controller\r
                                opens on its parent controller.\r
 \r
   @retval EFI_SUCCESS          ChildHandle is a child of the ControllerHandle.\r
@@ -513,32 +522,51 @@ EfiTestChildHandle (
 }\r
 \r
 /**\r
-  This function looks up a Unicode string in UnicodeStringTable.  If Language is\r
-  a member of SupportedLanguages and a Unicode string is found in UnicodeStringTable\r
-  that matches the language code specified by Language, then it is returned in\r
+  This function looks up a Unicode string in UnicodeStringTable.\r
+  If Language is a member of SupportedLanguages and a Unicode\r
+  string is found in UnicodeStringTable that matches the\r
+  language code specified by Language, then it is returned in\r
   UnicodeString.\r
 \r
-  @param  Language                A pointer to the ISO 639-2 language code for the\r
-                                  Unicode string to look up and return.\r
-  @param  SupportedLanguages      A pointer to the set of ISO 639-2 language codes\r
-                                  that the Unicode string table supports.  Language\r
-                                  must be a member of this set.\r
-  @param  UnicodeStringTable      A pointer to the table of Unicode strings.\r
-  @param  UnicodeString           A pointer to the Unicode string from UnicodeStringTable\r
-                                  that matches the language specified by Language.\r
-\r
-  @retval  EFI_SUCCESS            The Unicode string that matches the language\r
-                                  specified by Language was found\r
-                                  in the table of Unicoide strings UnicodeStringTable,\r
-                                  and it was returned in UnicodeString.\r
+  @param  Language                A pointer to the ISO 639-2\r
+                                  language code for the Unicode\r
+                                  string to look up and return.\r
+  \r
+  @param  SupportedLanguages      A pointer to the set of ISO\r
+                                  639-2language\r
+                                  codes that the Unicode string\r
+                                  table supports. Language must\r
+                                  be a member of this set.\r
+  \r
+  @param  UnicodeStringTable      A pointer to the table of\r
+                                  Unicode strings.\r
+  \r
+  @param  UnicodeString           A pointer to the Unicode\r
+                                  string from UnicodeStringTable\r
+                                  that matches the language\r
+                                  specified by Language.\r
+\r
+  @retval  EFI_SUCCESS            The Unicode string that\r
+                                  matches the language specified\r
+                                  by Language was found in the\r
+                                  table of Unicoide strings\r
+                                  UnicodeStringTable, and it was\r
+                                  returned in UnicodeString.\r
+  \r
   @retval  EFI_INVALID_PARAMETER  Language is NULL.\r
+  \r
   @retval  EFI_INVALID_PARAMETER  UnicodeString is NULL.\r
   @retval  EFI_UNSUPPORTED        SupportedLanguages is NULL.\r
+  \r
   @retval  EFI_UNSUPPORTED        UnicodeStringTable is NULL.\r
-  @retval  EFI_UNSUPPORTED        The language specified by Language is not a\r
-                                  member of SupportedLanguages.\r
-  @retval  EFI_UNSUPPORTED        The language specified by Language is not\r
-                                  supported by UnicodeStringTable.\r
+  \r
+  @retval  EFI_UNSUPPORTED        The language specified by\r
+                                  Language is not a member\r
+                                  ofSupportedLanguages.\r
+  \r
+  @retval EFI_UNSUPPORTED         The language specified by\r
+                                  Language is not supported by\r
+                                  UnicodeStringTable.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -596,36 +624,196 @@ LookupUnicodeString (
   return EFI_UNSUPPORTED;\r
 }\r
 \r
+\r
+\r
+/**\r
+  This function looks up a Unicode string in UnicodeStringTable.\r
+  If Language is a member of SupportedLanguages and a Unicode\r
+  string is found in UnicodeStringTable that matches the\r
+  language code specified by Language, then it is returned in\r
+  UnicodeString.\r
+\r
+  @param  Language                A pointer to the ISO 639-2 or\r
+                                  RFC 3066 language code for the\r
+                                  Unicode string to look up and\r
+                                  return.\r
+  \r
+  @param  SupportedLanguages      A pointer to the set of ISO\r
+                                  639-2 or RFC 3066 language\r
+                                  codes that the Unicode string\r
+                                  table supports. Language must\r
+                                  be a member of this set.\r
+  \r
+  @param  UnicodeStringTable      A pointer to the table of\r
+                                  Unicode strings.\r
+  \r
+  @param  UnicodeString           A pointer to the Unicode\r
+                                  string from UnicodeStringTable\r
+                                  that matches the language\r
+                                  specified by Language.\r
+\r
+  @param  Iso639Language          Specify the language code\r
+                                  format supported. If true,\r
+                                  then the format follow ISO\r
+                                  639-2. If false, then it\r
+                                  follows RFC3066.\r
+\r
+  @retval  EFI_SUCCESS            The Unicode string that\r
+                                  matches the language specified\r
+                                  by Language was found in the\r
+                                  table of Unicoide strings\r
+                                  UnicodeStringTable, and it was\r
+                                  returned in UnicodeString.\r
+  \r
+  @retval  EFI_INVALID_PARAMETER  Language is NULL.\r
+  \r
+  @retval  EFI_INVALID_PARAMETER  UnicodeString is NULL.\r
+  \r
+  @retval  EFI_UNSUPPORTED        SupportedLanguages is NULL.\r
+  \r
+  @retval  EFI_UNSUPPORTED        UnicodeStringTable is NULL.\r
+  \r
+  @retval  EFI_UNSUPPORTED        The language specified by\r
+                                  Language is not a member\r
+                                  ofSupportedLanguages.\r
+  \r
+  @retval EFI_UNSUPPORTED         The language specified by\r
+                                  Language is not supported by\r
+                                  UnicodeStringTable.\r
+\r
+**/\r
+EFI_STATUS\r
+\r
+EFIAPI\r
+LookupUnicodeString2 (\r
+  IN CONST CHAR8                     *Language,\r
+  IN CONST CHAR8                     *SupportedLanguages,\r
+  IN CONST EFI_UNICODE_STRING_TABLE  *UnicodeStringTable,\r
+  OUT CHAR16                         **UnicodeString,\r
+  IN BOOLEAN                         Iso639Language\r
+  )\r
+{\r
+  BOOLEAN   Found;\r
+  UINTN     Index;\r
+  CHAR8     *LanguageString;\r
+\r
+  //\r
+  // Make sure the parameters are valid\r
+  //\r
+  if (Language == NULL || UnicodeString == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  //\r
+  // If there are no supported languages, or the Unicode String Table is empty, then the\r
+  // Unicode String specified by Language is not supported by this Unicode String Table\r
+  //\r
+  if (SupportedLanguages == NULL || UnicodeStringTable == NULL) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  //\r
+  // Make sure Language is in the set of Supported Languages\r
+  //\r
+  Found = FALSE;\r
+  while (*SupportedLanguages != 0) {\r
+    if (Iso639Language) {\r
+      if (CompareIso639LanguageCode (Language, SupportedLanguages)) {\r
+        Found = TRUE;\r
+        break;\r
+      }\r
+      SupportedLanguages += 3;\r
+    } else {\r
+      for (Index = 0; SupportedLanguages[Index] != 0 && SupportedLanguages[Index] != ';'; Index++);\r
+      if ((AsciiStrnCmp(SupportedLanguages, Language, Index) == 0) && (Language[Index] == 0)) {\r
+        Found = TRUE;\r
+        break;\r
+      }\r
+      SupportedLanguages += Index;\r
+      for (; *SupportedLanguages != 0 && *SupportedLanguages == ';'; SupportedLanguages++);\r
+    }\r
+  }\r
+\r
+  //\r
+  // If Language is not a member of SupportedLanguages, then return EFI_UNSUPPORTED\r
+  //\r
+  if (!Found) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  //\r
+  // Search the Unicode String Table for the matching Language specifier\r
+  //\r
+  while (UnicodeStringTable->Language != NULL) {\r
+    LanguageString = UnicodeStringTable->Language;\r
+    while (0 != *LanguageString) {\r
+      for (Index = 0 ;LanguageString[Index] != 0 && LanguageString[Index] != ';'; Index++);\r
+      if (AsciiStrnCmp(LanguageString, Language, Index) == 0) {\r
+        *UnicodeString = UnicodeStringTable->UnicodeString;\r
+        return EFI_SUCCESS;\r
+      }\r
+      LanguageString += Index;\r
+      for (Index = 0 ;LanguageString[Index] != 0 && LanguageString[Index] == ';'; Index++);\r
+    }\r
+    UnicodeStringTable++;\r
+  }\r
+\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+\r
 /**\r
+  \r
   This function adds a Unicode string to UnicodeStringTable.\r
-  If Language is a member of SupportedLanguages then UnicodeString is added to\r
-  UnicodeStringTable.  New buffers are allocated for both Language and\r
-  UnicodeString.  The contents of Language and UnicodeString are copied into\r
-  these new buffers.  These buffers are automatically freed when\r
+  If Language is a member of SupportedLanguages then\r
+  UnicodeString is added to UnicodeStringTable.  New buffers are\r
+  allocated for both Language and UnicodeString.  The contents\r
+  of Language and UnicodeString are copied into these new\r
+  buffers.  These buffers are automatically freed when\r
   FreeUnicodeStringTable() is called.\r
 \r
-  @param  Language                A pointer to the ISO 639-2 language code for the Unicode\r
+  @param  Language                A pointer to the ISO 639-2\r
+                                  language code for the Unicode\r
+                                  string to add.\r
+  \r
+  @param  SupportedLanguages      A pointer to the set of ISO\r
+                                  639-2 language codes that the\r
+                                  Unicode string table supports.\r
+                                  Language must be a member of\r
+                                  this set.\r
+  \r
+  @param  UnicodeStringTable      A pointer to the table of\r
+                                  Unicode strings.\r
+  \r
+  @param  UnicodeString           A pointer to the Unicode\r
                                   string to add.\r
-  @param  SupportedLanguages      A pointer to the set of ISO 639-2 language codes\r
-                                  that the Unicode string table supports.\r
-                                  Language must be a member of this set.\r
-  @param  UnicodeStringTable      A pointer to the table of Unicode strings.\r
-  @param  UnicodeString           A pointer to the Unicode string to add.\r
-\r
-  @retval EFI_SUCCESS             The Unicode string that matches the language\r
-                                  specified by Language was found in the table of\r
-                                  Unicode strings UnicodeStringTable, and it was\r
+\r
+  @retval EFI_SUCCESS             The Unicode string that\r
+                                  matches the language specified\r
+                                  by Language was found in the\r
+                                  table of Unicode strings\r
+                                  UnicodeStringTable, and it was\r
                                   returned in UnicodeString.\r
+  \r
   @retval EFI_INVALID_PARAMETER   Language is NULL.\r
+  \r
   @retval EFI_INVALID_PARAMETER   UnicodeString is NULL.\r
+  \r
   @retval EFI_INVALID_PARAMETER   UnicodeString is an empty string.\r
+  \r
   @retval EFI_UNSUPPORTED         SupportedLanguages is NULL.\r
-  @retval EFI_ALREADY_STARTED     A Unicode string with language Language is\r
-                                  already present in UnicodeStringTable.\r
-  @retval EFI_OUT_OF_RESOURCES    There is not enough memory to add another\r
-                                  Unicode string to UnicodeStringTable.\r
-  @retval EFI_UNSUPPORTED         The language specified by Language is not a\r
-                                  member of SupportedLanguages.\r
+  \r
+  @retval EFI_ALREADY_STARTED     A Unicode string with language\r
+                                  Language is already present in\r
+                                  UnicodeStringTable.\r
+  \r
+  @retval EFI_OUT_OF_RESOURCES    There is not enough memory to\r
+                                  add another Unicode string to\r
+                                  UnicodeStringTable.\r
+  \r
+  @retval EFI_UNSUPPORTED         The language specified by\r
+                                  Language is not a member of\r
+                                  SupportedLanguages.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -762,10 +950,229 @@ AddUnicodeString (
   return EFI_UNSUPPORTED;\r
 }\r
 \r
+\r
+/**\r
+  \r
+  This function adds a Unicode string to UnicodeStringTable.\r
+  If Language is a member of SupportedLanguages then\r
+  UnicodeString is added to UnicodeStringTable.  New buffers are\r
+  allocated for both Language and UnicodeString.  The contents\r
+  of Language and UnicodeString are copied into these new\r
+  buffers.  These buffers are automatically freed when\r
+  FreeUnicodeStringTable() is called.\r
+\r
+  @param  Language                A pointer to the ISO 639-2 or\r
+                                  RFC 3066 language code for the\r
+                                  Unicode string to add.\r
+  \r
+  @param  SupportedLanguages      A pointer to the set of ISO\r
+                                  639-2 or RFC 3.66 language\r
+                                  codes that the Unicode string\r
+                                  table supports. Language must\r
+                                  be a member of this set.\r
+  \r
+  @param  UnicodeStringTable      A pointer to the table of\r
+                                  Unicode strings.\r
+  \r
+  @param  UnicodeString           A pointer to the Unicode\r
+                                  string to add.\r
+  \r
+  @param  Iso639Language          Specify the language code\r
+                                  format supported. If true,\r
+                                  then the format follow ISO\r
+                                  639-2. If false, then it\r
+                                  follows RFC3066.\r
+\r
+  @retval EFI_SUCCESS             The Unicode string that\r
+                                  matches the language specified\r
+                                  by Language was found in the\r
+                                  table of Unicode strings\r
+                                  UnicodeStringTable, and it was\r
+                                  returned in UnicodeString.\r
+  \r
+  @retval EFI_INVALID_PARAMETER   Language is NULL.\r
+  \r
+  @retval EFI_INVALID_PARAMETER   UnicodeString is NULL.\r
+  \r
+  @retval EFI_INVALID_PARAMETER   UnicodeString is an empty string.\r
+  \r
+  @retval EFI_UNSUPPORTED         SupportedLanguages is NULL.\r
+  \r
+  @retval EFI_ALREADY_STARTED     A Unicode string with language\r
+                                  Language is already present in\r
+                                  UnicodeStringTable.\r
+  \r
+  @retval EFI_OUT_OF_RESOURCES    There is not enough memory to\r
+                                  add another Unicode string to\r
+                                  UnicodeStringTable.\r
+  \r
+  @retval EFI_UNSUPPORTED         The language specified by\r
+                                  Language is not a member of\r
+                                  SupportedLanguages.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+AddUnicodeString2 (\r
+  IN CONST CHAR8               *Language,\r
+  IN CONST CHAR8               *SupportedLanguages,\r
+  IN EFI_UNICODE_STRING_TABLE  **UnicodeStringTable,\r
+  IN CONST CHAR16              *UnicodeString,\r
+  IN BOOLEAN                   Iso639Language\r
+  )\r
+{\r
+  UINTN                     NumberOfEntries;\r
+  EFI_UNICODE_STRING_TABLE  *OldUnicodeStringTable;\r
+  EFI_UNICODE_STRING_TABLE  *NewUnicodeStringTable;\r
+  UINTN                     UnicodeStringLength;\r
+  BOOLEAN                   Found;\r
+  UINTN                     Index;\r
+  CHAR8                     *LanguageString;\r
+\r
+  //\r
+  // Make sure the parameter are valid\r
+  //\r
+  if (Language == NULL || UnicodeString == NULL || UnicodeStringTable == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  //\r
+  // If there are no supported languages, then a Unicode String can not be added\r
+  //\r
+  if (SupportedLanguages == NULL) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  //\r
+  // If the Unicode String is empty, then a Unicode String can not be added\r
+  //\r
+  if (UnicodeString[0] == 0) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  //\r
+  // Make sure Language is a member of SupportedLanguages\r
+  //\r
+  Found = FALSE;\r
+  while (*SupportedLanguages != 0) {\r
+    if (Iso639Language) {\r
+      if (CompareIso639LanguageCode (Language, SupportedLanguages)) {\r
+        Found = TRUE;\r
+        break;\r
+      }\r
+      SupportedLanguages += 3;\r
+    } else {\r
+      for (Index = 0; SupportedLanguages[Index] != 0 && SupportedLanguages[Index] != ';'; Index++);\r
+      if (AsciiStrnCmp(SupportedLanguages, Language, Index) == 0) {\r
+        Found = TRUE;\r
+        break;\r
+      }\r
+      SupportedLanguages += Index;\r
+      for (; *SupportedLanguages != 0 && *SupportedLanguages == ';'; SupportedLanguages++);\r
+    }\r
+  }\r
+\r
+  //\r
+  // If Language is not a member of SupportedLanguages, then return EFI_UNSUPPORTED\r
+  //\r
+  if (!Found) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  //\r
+  // Determine the size of the Unicode String Table by looking for a NULL Language entry\r
+  //\r
+  NumberOfEntries = 0;\r
+  if (*UnicodeStringTable != NULL) {\r
+    OldUnicodeStringTable = *UnicodeStringTable;\r
+    while (OldUnicodeStringTable->Language != NULL) {\r
+      LanguageString = OldUnicodeStringTable->Language;\r
+\r
+      while (*LanguageString != 0) {\r
+        for (Index = 0; LanguageString[Index] != 0 && LanguageString[Index] != ';'; Index++);\r
+\r
+        if (AsciiStrnCmp (Language, LanguageString, Index) == 0) { \r
+          return EFI_ALREADY_STARTED;\r
+        }\r
+        LanguageString += Index;\r
+        for (; *LanguageString != 0 && *LanguageString == ';'; LanguageString++);\r
+      }\r
+      OldUnicodeStringTable++;\r
+      NumberOfEntries++;\r
+    }\r
+  }\r
+\r
+  //\r
+  // Allocate space for a new Unicode String Table.  It must hold the current number of\r
+  // entries, plus 1 entry for the new Unicode String, plus 1 entry for the end of table\r
+  // marker\r
+  //\r
+  NewUnicodeStringTable = AllocatePool ((NumberOfEntries + 2) * sizeof (EFI_UNICODE_STRING_TABLE));\r
+  if (NewUnicodeStringTable == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  //\r
+  // If the current Unicode String Table contains any entries, then copy them to the\r
+  // newly allocated Unicode String Table.\r
+  //\r
+  if (*UnicodeStringTable != NULL) {\r
+    CopyMem (\r
+      NewUnicodeStringTable,\r
+      *UnicodeStringTable,\r
+      NumberOfEntries * sizeof (EFI_UNICODE_STRING_TABLE)\r
+      );\r
+  }\r
+\r
+  //\r
+  // Allocate space for a copy of the Language specifier\r
+  //\r
+  NewUnicodeStringTable[NumberOfEntries].Language = AllocateCopyPool (AsciiStrSize(Language), Language);\r
+  if (NewUnicodeStringTable[NumberOfEntries].Language == NULL) {\r
+    gBS->FreePool (NewUnicodeStringTable);\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  //\r
+  // Compute the length of the Unicode String\r
+  //\r
+  for (UnicodeStringLength = 0; UnicodeString[UnicodeStringLength] != 0; UnicodeStringLength++);\r
+\r
+  //\r
+  // Allocate space for a copy of the Unicode String\r
+  //\r
+  NewUnicodeStringTable[NumberOfEntries].UnicodeString = AllocateCopyPool (StrSize (UnicodeString), UnicodeString);\r
+  if (NewUnicodeStringTable[NumberOfEntries].UnicodeString == NULL) {\r
+    gBS->FreePool (NewUnicodeStringTable[NumberOfEntries].Language);\r
+    gBS->FreePool (NewUnicodeStringTable);\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  //\r
+  // Mark the end of the Unicode String Table\r
+  //\r
+  NewUnicodeStringTable[NumberOfEntries + 1].Language       = NULL;\r
+  NewUnicodeStringTable[NumberOfEntries + 1].UnicodeString  = NULL;\r
+\r
+  //\r
+  // Free the old Unicode String Table\r
+  //\r
+  if (*UnicodeStringTable != NULL) {\r
+    gBS->FreePool (*UnicodeStringTable);\r
+  }\r
+\r
+  //\r
+  // Point UnicodeStringTable at the newly allocated Unicode String Table\r
+  //\r
+  *UnicodeStringTable = NewUnicodeStringTable;\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
 /**\r
   This function frees the table of Unicode strings in UnicodeStringTable.\r
   If UnicodeStringTable is NULL, then EFI_SUCCESS is returned.\r
-  Otherwise, each language code, and each Unicode string in the Unicode string\r
+  Otherwise, each language code, and each Unicode string in the Unicode string \r
   table are freed, and EFI_SUCCESS is returned.\r
 \r
   @param  UnicodeStringTable  A pointer to the table of Unicode strings.\r
@@ -814,73 +1221,4 @@ FreeUnicodeStringTable (
   return EFI_SUCCESS;\r
 }\r
 \r
-/**\r
-  Intialize a driver by installing the Driver Binding Protocol onto the\r
-  driver's DriverBindingHandle.  This is typically the same as the driver's\r
-  ImageHandle, but it can be different if the driver produces multiple\r
-  DriverBinding Protocols.  This function also initializes the EFI Driver\r
-  Library that initializes the global variables gST, gBS, gRT.\r
-\r
-  @param  ImageHandle          The image handle of the driver\r
-  @param  SystemTable          The EFI System Table that was passed to the driver's entry point\r
-  @param  DriverBinding        A Driver Binding Protocol instance that this driver is producing\r
-  @param  DriverBindingHandle  The handle that DriverBinding is to be installe onto.  If this\r
-                               parameter is NULL, then a new handle is created.\r
-\r
-  @retval EFI_SUCCESS          DriverBinding is installed onto DriverBindingHandle\r
-  @retval Other                Status from gBS->InstallProtocolInterface()\r
-\r
-**/\r
-EFI_STATUS\r
-EfiLibInstallDriverBinding (\r
-  IN const EFI_HANDLE             ImageHandle,\r
-  IN const EFI_SYSTEM_TABLE       *SystemTable,\r
-  IN EFI_DRIVER_BINDING_PROTOCOL  *DriverBinding,\r
-  IN EFI_HANDLE                   DriverBindingHandle\r
-  )\r
-{\r
-  //\r
-  //  bugbug:Need to implement ...\r
-  //\r
-\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-/**\r
-  Intialize a driver by installing the Driver Binding Protocol onto the\r
-  driver's DriverBindingHandle.  This is typically the same as the driver's\r
-  ImageHandle, but it can be different if the driver produces multiple\r
-  DriverBinding Protocols.  This function also initializes the EFI Driver\r
-  Library that initializes the global variables gST, gBS, gRT.\r
-\r
-  @ImageHandle                 The image handle of the driver\r
-  @SystemTable                 The EFI System Table that was passed to the driver's entry point\r
-  @DriverBinding               A Driver Binding Protocol instance that this driver is producing\r
-  @DriverBindingHandle         The handle that DriverBinding is to be installe onto.  If this\r
-                               parameter is NULL, then a new handle is created.\r
-  @ComponentName               A Component Name Protocol instance that this driver is producing\r
-  @DriverConfiguration         A Driver Configuration Protocol instance that this driver is producing\r
-  @DriverDiagnostics           A Driver Diagnostics Protocol instance that this driver is producing\r
-\r
-  @retval EFI_SUCCESS          DriverBinding is installed onto DriverBindingHandle\r
-  @retval Other                Status from gBS->InstallProtocolInterface()\r
-\r
-**/\r
-EFI_STATUS\r
-EfiLibInstallAllDriverProtocols (\r
-  IN const EFI_HANDLE                         ImageHandle,\r
-  IN const EFI_SYSTEM_TABLE                   *SystemTable,\r
-  IN EFI_DRIVER_BINDING_PROTOCOL              *DriverBinding,\r
-  IN EFI_HANDLE                               DriverBindingHandle,\r
-  IN const EFI_COMPONENT_NAME_PROTOCOL        *ComponentName,       OPTIONAL\r
-  IN const EFI_DRIVER_CONFIGURATION_PROTOCOL  *DriverConfiguration, OPTIONAL\r
-  IN const EFI_DRIVER_DIAGNOSTICS_PROTOCOL    *DriverDiagnostics    OPTIONAL\r
-  )\r
-{\r
-  //\r
-  //  bugbug:Need to implement ...\r
-  //\r
-\r
-  return EFI_SUCCESS;\r
-}\r
 \r