From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.115; helo=mga14.intel.com; envelope-from=ruiyu.ni@intel.com; receiver=edk2-devel@lists.01.org Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id BA7A92222C24C for ; Fri, 26 Jan 2018 01:02:13 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Jan 2018 01:07:43 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,415,1511856000"; d="scan'208";a="12765729" Received: from ray-dev.ccr.corp.intel.com ([10.239.9.19]) by orsmga007.jf.intel.com with ESMTP; 26 Jan 2018 01:07:43 -0800 From: Ruiyu Ni To: edk2-devel@lists.01.org Cc: Jaben Date: Fri, 26 Jan 2018 17:07:38 +0800 Message-Id: <20180126090739.14188-2-ruiyu.ni@intel.com> X-Mailer: git-send-email 2.15.1.windows.2 In-Reply-To: <20180126090739.14188-1-ruiyu.ni@intel.com> References: <20180126090739.14188-1-ruiyu.ni@intel.com> Subject: [PATCH 1/2] ShellPkg/CommandLib: Locate proper UnicodeCollation instance X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 26 Jan 2018 09:02:14 -0000 Original code locates the first UnicodeCollation instance in DXE Core protocol database. It's not correct considering multiple UnicodeCollation instances exist in system. The patch changes logic to find the one that matches the current system language. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ruiyu Ni Cc: Jaben Carsey + Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.
(C) Copyright 2013-2015 Hewlett-Packard Development Company, L.P.
(C) Copyright 2016 Hewlett Packard Enterprise Development LP
@@ -72,14 +72,70 @@ CommandInit( VOID ) { - EFI_STATUS Status; + UINTN NumHandles; + EFI_HANDLE *Handles; + EFI_UNICODE_COLLATION_PROTOCOL *Uc; + CHAR8 *BestLanguage; + UINTN Index; + EFI_STATUS Status; + CHAR8 *PlatformLang; + + GetEfiGlobalVariable2 (EFI_PLATFORM_LANG_VARIABLE_NAME, (VOID**)&PlatformLang, NULL); + if (PlatformLang == NULL) { + return EFI_UNSUPPORTED; + } + if (gUnicodeCollation == NULL) { - Status = gBS->LocateProtocol(&gEfiUnicodeCollation2ProtocolGuid, NULL, (VOID**)&gUnicodeCollation); - if (EFI_ERROR(Status)) { - return (EFI_DEVICE_ERROR); + Status = gBS->LocateHandleBuffer ( + ByProtocol, + &gEfiUnicodeCollation2ProtocolGuid, + NULL, + &NumHandles, + &Handles + ); + if (EFI_ERROR (Status)) { + NumHandles = 0; + Handles = NULL; } + for (Index = 0; Index < NumHandles; Index++) { + // + // Open Unicode Collation Protocol + // + Status = gBS->OpenProtocol ( + Handles[Index], + &gEfiUnicodeCollation2ProtocolGuid, + (VOID **) &Uc, + gImageHandle, + NULL, + EFI_OPEN_PROTOCOL_GET_PROTOCOL + ); + if (EFI_ERROR (Status)) { + continue; + } + + // + // Find the best matching matching language from the supported languages + // of Unicode Collation2 protocol. + // + BestLanguage = GetBestLanguage ( + Uc->SupportedLanguages, + FALSE, + PlatformLang, + NULL + ); + if (BestLanguage != NULL) { + FreePool (BestLanguage); + gUnicodeCollation = Uc; + break; + } + } + if (Handles != NULL) { + FreePool (Handles); + } + FreePool (PlatformLang); } - return (EFI_SUCCESS); + + return (gUnicodeCollation == NULL) ? EFI_UNSUPPORTED : EFI_SUCCESS; } /** @@ -112,11 +168,9 @@ ShellCommandLibConstructor ( mProfileListSize = 0; mProfileList = NULL; - if (gUnicodeCollation == NULL) { - Status = gBS->LocateProtocol(&gEfiUnicodeCollation2ProtocolGuid, NULL, (VOID**)&gUnicodeCollation); - if (EFI_ERROR(Status)) { - return (EFI_DEVICE_ERROR); - } + Status = CommandInit (); + if (EFI_ERROR (Status)) { + return EFI_DEVICE_ERROR; } return (RETURN_SUCCESS); diff --git a/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.h b/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.h index b998656b4e..bcfde60c26 100644 --- a/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.h +++ b/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.h @@ -1,7 +1,7 @@ /** @file Provides interface to shell internal functions for shell commands. - Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.
+ Copyright (c) 2006 - 2018, 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 @@ -19,6 +19,7 @@ #include #include +#include #include #include -- 2.15.1.windows.2