X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=MdeModulePkg%2FUniversal%2FHiiDatabaseDxe%2FString.c;h=d5a7488a79d39ee2201560dc8146881e805451e0;hb=0a18956d54cfe70b736b029c62ce53f29b903745;hp=c55305886f8fef38aca7afd2183dfeeb97a5f98c;hpb=05bf16e04d5eabe4c0fd31a6e0e639c096a74ebe;p=mirror_edk2.git diff --git a/MdeModulePkg/Universal/HiiDatabaseDxe/String.c b/MdeModulePkg/Universal/HiiDatabaseDxe/String.c index c55305886f..d5a7488a79 100644 --- a/MdeModulePkg/Universal/HiiDatabaseDxe/String.c +++ b/MdeModulePkg/Universal/HiiDatabaseDxe/String.c @@ -2,7 +2,8 @@ Implementation for EFI_HII_STRING_PROTOCOL. -Copyright (c) 2007 - 2012, Intel Corporation. All rights reserved.
+Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.
+(C) Copyright 2016 Hewlett Packard Enterprise Development LP
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -105,7 +106,7 @@ ReferFontInfoLocally ( @param StringSrc Points to current null-terminated string. @param BufferSize Length of the buffer. - @retval EFI_SUCCESS The string text was outputed successfully. + @retval EFI_SUCCESS The string text was outputted successfully. @retval EFI_BUFFER_TOO_SMALL Buffer is insufficient to store the found string text. BufferSize is updated to the required buffer size. @@ -149,7 +150,7 @@ ConvertToUnicodeText ( @param StringSrc Points to current null-terminated string. @param BufferSize Length of the buffer. - @retval EFI_SUCCESS The string text was outputed successfully. + @retval EFI_SUCCESS The string text was outputted successfully. @retval EFI_BUFFER_TOO_SMALL Buffer is insufficient to store the found string text. BufferSize is updated to the required buffer size. @@ -198,7 +199,7 @@ GetUnicodeStringTextOrSize ( @param StringFontInfo Buffer to record the output font info. It's caller's responsibility to free this buffer. - @retval EFI_SUCCESS The string font is outputed successfully. + @retval EFI_SUCCESS The string font is outputted successfully. @retval EFI_NOT_FOUND The specified font id does not exist. **/ @@ -295,6 +296,7 @@ FindStringBlock ( ASSERT (StringPackage->Signature == HII_STRING_PACKAGE_SIGNATURE); CurrentStringId = 1; + StringSize = 0; if (StringId != (EFI_STRING_ID) (-1) && StringId != 0) { ASSERT (BlockType != NULL && StringBlockAddr != NULL && StringTextOffset != NULL); @@ -335,7 +337,7 @@ FindStringBlock ( case EFI_HII_SIBT_STRINGS_SCSU: CopyMem (&StringCount, BlockHdr + sizeof (EFI_HII_STRING_BLOCK), sizeof (UINT16)); - StringTextPtr = BlockHdr + sizeof (EFI_HII_SIBT_STRINGS_SCSU_BLOCK) - sizeof (UINT8); + StringTextPtr = (UINT8*)((UINTN)BlockHdr + sizeof (EFI_HII_SIBT_STRINGS_SCSU_BLOCK) - sizeof (UINT8)); BlockSize += StringTextPtr - BlockHdr; for (Index = 0; Index < StringCount; Index++) { @@ -355,10 +357,10 @@ FindStringBlock ( case EFI_HII_SIBT_STRINGS_SCSU_FONT: CopyMem ( &StringCount, - BlockHdr + sizeof (EFI_HII_STRING_BLOCK) + sizeof (UINT8), + (UINT8*)((UINTN)BlockHdr + sizeof (EFI_HII_STRING_BLOCK) + sizeof (UINT8)), sizeof (UINT16) ); - StringTextPtr = BlockHdr + sizeof (EFI_HII_SIBT_STRINGS_SCSU_FONT_BLOCK) - sizeof (UINT8); + StringTextPtr = (UINT8*)((UINTN)BlockHdr + sizeof (EFI_HII_SIBT_STRINGS_SCSU_FONT_BLOCK) - sizeof (UINT8)); BlockSize += StringTextPtr - BlockHdr; for (Index = 0; Index < StringCount; Index++) { @@ -425,7 +427,7 @@ FindStringBlock ( BlockSize += Offset; CopyMem ( &StringCount, - BlockHdr + sizeof (EFI_HII_STRING_BLOCK) + sizeof (UINT8), + (UINT8*)((UINTN)BlockHdr + sizeof (EFI_HII_STRING_BLOCK) + sizeof (UINT8)), sizeof (UINT16) ); for (Index = 0; Index < StringCount; Index++) { @@ -465,7 +467,7 @@ FindStringBlock ( break; case EFI_HII_SIBT_SKIP1: - SkipCount = (UINT16) (*(BlockHdr + sizeof (EFI_HII_STRING_BLOCK))); + SkipCount = (UINT16) (*(UINT8*)((UINTN)BlockHdr + sizeof (EFI_HII_STRING_BLOCK))); CurrentStringId = (UINT16) (CurrentStringId + SkipCount); BlockSize += sizeof (EFI_HII_SIBT_SKIP1_BLOCK); break; @@ -479,7 +481,7 @@ FindStringBlock ( case EFI_HII_SIBT_EXT1: CopyMem ( &Length8, - BlockHdr + sizeof (EFI_HII_STRING_BLOCK) + sizeof (UINT8), + (UINT8*)((UINTN)BlockHdr + sizeof (EFI_HII_STRING_BLOCK) + sizeof (UINT8)), sizeof (UINT8) ); BlockSize += Length8; @@ -494,7 +496,7 @@ FindStringBlock ( // BlockHdr += sizeof (EFI_HII_SIBT_EXT2_BLOCK); CopyMem (&FontId, BlockHdr, sizeof (UINT8)); - BlockHdr += sizeof (UINT8); + BlockHdr ++; CopyMem (&FontSize, BlockHdr, sizeof (UINT16)); BlockHdr += sizeof (UINT16); CopyMem (&FontStyle, BlockHdr, sizeof (EFI_HII_FONT_STYLE)); @@ -535,7 +537,7 @@ FindStringBlock ( case EFI_HII_SIBT_EXT4: CopyMem ( &Length32, - BlockHdr + sizeof (EFI_HII_STRING_BLOCK) + sizeof (UINT8), + (UINT8*)((UINTN)BlockHdr + sizeof (EFI_HII_STRING_BLOCK) + sizeof (UINT8)), sizeof (UINT32) ); @@ -717,7 +719,7 @@ GetStringWorker ( @param StringBlockAddr Output the block address of found string block. @param FontBlock whether this string block has font info. - @retval EFI_SUCCESS The string font is outputed successfully. + @retval EFI_SUCCESS The string font is outputted successfully. @retval EFI_OUT_OF_RESOURCES NO resource for the memory to save the new string block. **/ @@ -1080,7 +1082,7 @@ SetStringWorker ( BlockPtr += sizeof (EFI_HII_SIBT_EXT2_BLOCK); *BlockPtr = LocalFont->FontId; - BlockPtr += sizeof (UINT8); + BlockPtr ++; CopyMem (BlockPtr, &GlobalFont->FontInfo->FontSize, sizeof (UINT16)); BlockPtr += sizeof (UINT16); CopyMem (BlockPtr, &GlobalFont->FontInfo->FontStyle, sizeof (UINT32)); @@ -1333,7 +1335,7 @@ HiiNewString ( StringPackage->StringPkgHdr->StringInfoOffset = HeaderSize; CopyMem (StringPackage->StringPkgHdr->LanguageWindow, mLanguageWindow, 16 * sizeof (CHAR16)); StringPackage->StringPkgHdr->LanguageName = 1; - AsciiStrCpy (StringPackage->StringPkgHdr->Language, (CHAR8 *) Language); + AsciiStrCpyS (StringPackage->StringPkgHdr->Language, (HeaderSize - OFFSET_OF(EFI_HII_STRING_PACKAGE_HDR,Language)) / sizeof (CHAR8), (CHAR8 *) Language); // // Calculate the length of the string blocks, including string block to record @@ -1442,7 +1444,7 @@ HiiNewString ( *BlockPtr = EFI_HII_SIBT_STRING_UCS2_FONT; BlockPtr += sizeof (EFI_HII_STRING_BLOCK); *BlockPtr = LocalFont->FontId; - BlockPtr += sizeof (UINT8); + BlockPtr ++; CopyMem (BlockPtr, (EFI_STRING) String, StrSize ((EFI_STRING) String)); BlockPtr += StrSize ((EFI_STRING) String); @@ -1486,7 +1488,7 @@ HiiNewString ( BlockPtr += sizeof (EFI_HII_SIBT_EXT2_BLOCK); *BlockPtr = LocalFont->FontId; - BlockPtr += sizeof (UINT8); + BlockPtr ++; CopyMem (BlockPtr, &((EFI_FONT_INFO *) StringFontInfo)->FontSize, sizeof (UINT16)); BlockPtr += sizeof (UINT16); CopyMem (BlockPtr, &((EFI_FONT_INFO *) StringFontInfo)->FontStyle, sizeof (EFI_HII_FONT_STYLE)); @@ -1503,7 +1505,7 @@ HiiNewString ( *BlockPtr = EFI_HII_SIBT_STRING_UCS2_FONT; BlockPtr += sizeof (EFI_HII_STRING_BLOCK); *BlockPtr = LocalFont->FontId; - BlockPtr += sizeof (UINT8); + BlockPtr ++; CopyMem (BlockPtr, (EFI_STRING) String, StrSize ((EFI_STRING) String)); BlockPtr += StrSize ((EFI_STRING) String); @@ -1558,6 +1560,18 @@ Done: FreePool (StringPackage->StringPkgHdr); FreePool (StringPackage); } + // + // The contents of HiiDataBase may updated,need to check. + // + // + // Check whether need to get the contents of HiiDataBase. + // Only after ReadyToBoot to do the export. + // + if (gExportAfterReadyToBoot) { + if (!EFI_ERROR (Status)) { + HiiGetDatabaseInfo(&Private->HiiDatabase); + } + } return Status; } @@ -1590,7 +1604,8 @@ Done: @retval EFI_INVALID_LANGUAGE - The string specified by StringId is available but @retval EFI_BUFFER_TOO_SMALL The buffer specified by StringSize is too small to hold the string. - @retval EFI_INVALID_PARAMETER The String or Language or StringSize was NULL. + @retval EFI_INVALID_PARAMETER The Language or StringSize was NULL. + @retval EFI_INVALID_PARAMETER The value referenced by StringSize was not zero and String was NULL. @retval EFI_OUT_OF_RESOURCES There were insufficient resources to complete the request. @@ -1752,6 +1767,13 @@ HiiSetString ( return Status; } PackageListNode->PackageListHdr.PackageLength += StringPackage->StringPkgHdr->Header.Length - OldPackageLen; + // + // Check whether need to get the contents of HiiDataBase. + // Only after ReadyToBoot to do the export. + // + if (gExportAfterReadyToBoot) { + HiiGetDatabaseInfo(&Private->HiiDatabase); + } return EFI_SUCCESS; } } @@ -1775,7 +1797,8 @@ HiiSetString ( the length of Languages, in bytes. @retval EFI_SUCCESS The languages were returned successfully. - @retval EFI_INVALID_PARAMETER The Languages or LanguagesSize was NULL. + @retval EFI_INVALID_PARAMETER The LanguagesSize was NULL. + @retval EFI_INVALID_PARAMETER The value referenced by LanguagesSize is not zero and Languages is NULL. @retval EFI_BUFFER_TOO_SMALL The LanguagesSize is too small to hold the list of supported languages. LanguageSize is updated to contain the required size. @@ -1799,7 +1822,10 @@ HiiGetLanguages ( HII_STRING_PACKAGE_INSTANCE *StringPackage; UINTN ResultSize; - if (This == NULL || Languages == NULL || LanguagesSize == NULL || PackageList == NULL) { + if (This == NULL || LanguagesSize == NULL || PackageList == NULL) { + return EFI_INVALID_PARAMETER; + } + if (*LanguagesSize != 0 && Languages == NULL) { return EFI_INVALID_PARAMETER; } if (!IsHiiHandleValid (PackageList)) { @@ -1831,7 +1857,7 @@ HiiGetLanguages ( StringPackage = CR (Link, HII_STRING_PACKAGE_INSTANCE, StringEntry, HII_STRING_PACKAGE_SIGNATURE); ResultSize += AsciiStrSize (StringPackage->StringPkgHdr->Language); if (ResultSize <= *LanguagesSize) { - AsciiStrCpy (Languages, StringPackage->StringPkgHdr->Language); + AsciiStrCpyS (Languages, *LanguagesSize / sizeof (CHAR8), StringPackage->StringPkgHdr->Language); Languages += AsciiStrSize (StringPackage->StringPkgHdr->Language); *(Languages - 1) = L';'; } @@ -1871,15 +1897,16 @@ HiiGetLanguages ( points to the length of SecondaryLanguages in bytes. @retval EFI_SUCCESS Secondary languages were correctly returned. - @retval EFI_INVALID_PARAMETER PrimaryLanguage or SecondaryLanguages or - SecondaryLanguagesSize was NULL. + @retval EFI_INVALID_PARAMETER PrimaryLanguage or SecondaryLanguagesSize was NULL. + @retval EFI_INVALID_PARAMETER The value referenced by SecondaryLanguagesSize is not + zero and SecondaryLanguages is NULL. @retval EFI_BUFFER_TOO_SMALL The buffer specified by SecondaryLanguagesSize is too small to hold the returned information. SecondaryLanguageSize is updated to hold the size of the buffer required. @retval EFI_INVALID_LANGUAGE The language specified by PrimaryLanguage is not present in the specified package list. - @retval EFI_NOT_FOUND The specified PackageList is not in the Database. + @retval EFI_NOT_FOUND The specified PackageList is not in the Database. **/ EFI_STATUS @@ -1901,10 +1928,10 @@ HiiGetSecondaryLanguages ( CHAR8 *Languages; UINTN ResultSize; - if (This == NULL || PackageList == NULL || PrimaryLanguage == NULL) { + if (This == NULL || PackageList == NULL || PrimaryLanguage == NULL || SecondaryLanguagesSize == NULL) { return EFI_INVALID_PARAMETER; } - if (SecondaryLanguages == NULL || SecondaryLanguagesSize == NULL) { + if (SecondaryLanguages == NULL && *SecondaryLanguagesSize != 0) { return EFI_INVALID_PARAMETER; } if (!IsHiiHandleValid (PackageList)) { @@ -1947,7 +1974,7 @@ HiiGetSecondaryLanguages ( ResultSize = AsciiStrSize (Languages); if (ResultSize <= *SecondaryLanguagesSize) { - AsciiStrCpy (SecondaryLanguages, Languages); + AsciiStrCpyS (SecondaryLanguages, *SecondaryLanguagesSize / sizeof (CHAR8), Languages); } else { *SecondaryLanguagesSize = ResultSize; return EFI_BUFFER_TOO_SMALL; @@ -2012,13 +2039,13 @@ HiiCompareLanguage ( StrLen = AsciiStrSize (Language1); Lan1 = AllocateZeroPool (StrLen); ASSERT (Lan1 != NULL); - AsciiStrCpy(Lan1, Language1); + AsciiStrCpyS(Lan1, StrLen / sizeof (CHAR8), Language1); AsciiHiiToLower (Lan1); StrLen = AsciiStrSize (Language2); Lan2 = AllocateZeroPool (StrLen); ASSERT (Lan2 != NULL); - AsciiStrCpy(Lan2, Language2); + AsciiStrCpyS(Lan2, StrLen / sizeof (CHAR8), Language2); AsciiHiiToLower (Lan2); //