From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: redhat.com, ip: 209.132.183.28, mailfrom: lersek@redhat.com) Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by groups.io with SMTP; Tue, 17 Sep 2019 12:50:42 -0700 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 73AA110C6352; Tue, 17 Sep 2019 19:50:42 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-120-37.rdu2.redhat.com [10.10.120.37]) by smtp.corp.redhat.com (Postfix) with ESMTP id 379AF600C4; Tue, 17 Sep 2019 19:50:41 +0000 (UTC) From: "Laszlo Ersek" To: edk2-devel-groups-io Cc: Jaben Carsey , Ray Ni , Zhichao Gao Subject: [PATCH 32/35] ShellPkg/UefiShellLib: clarify workaround for unfixable EdkShell bug Date: Tue, 17 Sep 2019 21:49:32 +0200 Message-Id: <20190917194935.24322-33-lersek@redhat.com> In-Reply-To: <20190917194935.24322-1-lersek@redhat.com> References: <20190917194935.24322-1-lersek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.64]); Tue, 17 Sep 2019 19:50:42 +0000 (UTC) Content-Transfer-Encoding: quoted-printable The EDK 1 Shell (available at ) has a bug in its EFI_SHELL_ENVIRONMENT2.Execute() implementation that edk2's UefiShellLib has no choice but to work around. Improve the explanation in the code. Also, document the implicit EFI_HANDLE -> (EFI_HANDLE*) conversion, which happens implicitly after dereferencing ParentHandle, with an explicit cast. In practice, this patch is a no-op. Cc: Jaben Carsey Cc: Ray Ni Cc: Zhichao Gao Signed-off-by: Laszlo Ersek --- Notes: build-tested only ShellPkg/Library/UefiShellLib/UefiShellLib.c | 22 ++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/ShellPkg/Library/UefiShellLib/UefiShellLib.c b/ShellPkg/Libr= ary/UefiShellLib/UefiShellLib.c index 835d0f88ca74..9f07a58eb23d 100644 --- a/ShellPkg/Library/UefiShellLib/UefiShellLib.c +++ b/ShellPkg/Library/UefiShellLib/UefiShellLib.c @@ -1291,9 +1291,27 @@ ShellExecute ( if (mEfiShellEnvironment2 !=3D NULL) { // // Call EFI Shell version. - // Due to oddity in the EFI shell we want to dereference the ParentH= andle here // - CmdStatus =3D (mEfiShellEnvironment2->Execute(*ParentHandle, + // Due to an unfixable bug in the EdkShell implementation, we must + // dereference "ParentHandle" here: + // + // 1. The EFI shell installs the EFI_SHELL_ENVIRONMENT2 protocol, + // identified by gEfiShellEnvironment2Guid. + // 2. The Execute() member function takes "ParentImageHandle" as fir= st + // parameter, with type (EFI_HANDLE*). + // 3. In the EdkShell implementation, SEnvExecute() implements the + // Execute() member function. It passes "ParentImageHandle" corre= ctly to + // SEnvDoExecute(). + // 4. SEnvDoExecute() takes the (EFI_HANDLE*), and passes it directl= y -- + // without de-referencing -- to the HandleProtocol() boot service= . + // 5. But HandleProtocol() takes an EFI_HANDLE. + // + // Therefore we must + // - de-reference "ParentHandle" here, to mask the bug in + // SEnvDoExecute(), and + // - pass the resultant EFI_HANDLE as an (EFI_HANDLE*). + // + CmdStatus =3D (mEfiShellEnvironment2->Execute((EFI_HANDLE *)*ParentH= andle, CommandLine, Output)); // --=20 2.19.1.3.g30247aa5d201