From nobody Fri May 17 10:13:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+109080+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+109080+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1695753387; cv=none; d=zohomail.com; s=zohoarc; b=bSsz8u1T1NEKaPR7+HxsifTuvTOswWjWni1bZuu6jkQO8eTaHzOsP6IJ+biCrMSBUzKtbRRKv+4oPbQ6K5q/mns6zBZPWVIS3YS0WKq79vAbPsyYWIrz2pa8/UdAj4AuSfdL9vFCIoF14wWRCd9FPgQpweYMGEi5G69FDA0e4YI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695753387; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Sender:Subject:To; bh=CvY1byrPJm9StZ9EAWONS1uwbDBvJmbTDBGEYLIfW/U=; b=I/ODB3NIXhRoq58IcNTH74+y8Bbs28IFZ5EZX2qOJ4BWeEwyxUORV/WfeZq4Xmk2xj7I/NHy05W562tWP+JxBIDZNHvL2eiF7ehWUd2ZM9pHvJBmGWfLDTWKcR9hZwvXWH5rHsvw5p0AvGJFZwXTlEN6VbCD7W0uEsBguk/apQs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+109080+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1695753387250540.5855682538903; Tue, 26 Sep 2023 11:36:27 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=/buTe4ehSh4F38sINNU86Od2qdwFxyV1FKfvQRDBY1w=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1695753386; v=1; b=UZ5RLUfDnPYUWVioTwdoWbxg6iDT9I/yUcnKZrKOjMhZxDofAp+p38yCAQyTB1hVVc0JL8wO 4hbNDI0/0VzmQ/6oYt0hWrULQCC4jPpXKRUiF0lcgotSQr/FWCNjPoBERFs1slRIuVrV0kEnT1n Z2dvLD4GNcoPmHEZ+FiftYfU= X-Received: by 127.0.0.2 with SMTP id 6rjBYY1788612xIywCPYFvxt; Tue, 26 Sep 2023 11:36:26 -0700 X-Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.93]) by mx.groups.io with SMTP id smtpd.web11.27274.1695753385910650769 for ; Tue, 26 Sep 2023 11:36:26 -0700 X-IronPort-AV: E=McAfee;i="6600,9927,10845"; a="378918240" X-IronPort-AV: E=Sophos;i="6.03,178,1694761200"; d="scan'208";a="378918240" X-Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Sep 2023 11:36:25 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10845"; a="752277609" X-IronPort-AV: E=Sophos;i="6.03,178,1694761200"; d="scan'208";a="752277609" X-Received: from nldesimo-desk.amr.corp.intel.com ([10.241.240.72]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Sep 2023 11:36:24 -0700 From: "Nate DeSimone" To: devel@edk2.groups.io Cc: Andrew Fish , Ray Ni , Michael D Kinney , Chasel Chiu Subject: [edk2-devel] [PATCH v1] EmulatorPkg: Fix Terminal Issues Date: Tue, 26 Sep 2023 11:36:01 -0700 Message-Id: <20230926183601.2974-1-nathaniel.l.desimone@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,nathaniel.l.desimone@intel.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: FS1caqx8kgWFAS2fqP0MdlmWx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1695753389415100005 Content-Type: text/plain; charset="utf-8" After running EmulatorPkg, one will notice that their terminal acts strangely. This is caused by the EmulatorPkg Host changing the terminal mode and not restoring the original mode, which is now fixed. Cc: Andrew Fish Cc: Ray Ni Cc: Michael D Kinney Cc: Chasel Chiu Signed-off-by: Nate DeSimone Reviewed-by: Michael D Kinney --- EmulatorPkg/Unix/Host/EmuThunk.c | 16 ++++++++++++- EmulatorPkg/Win/Host/WinThunk.c | 40 +++++++++++++++++++++++++++++++- 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/EmulatorPkg/Unix/Host/EmuThunk.c b/EmulatorPkg/Unix/Host/EmuTh= unk.c index 6422f056a6..e6879db650 100644 --- a/EmulatorPkg/Unix/Host/EmuThunk.c +++ b/EmulatorPkg/Unix/Host/EmuThunk.c @@ -9,7 +9,7 @@ it may cause the table to be initialized with the members at the end bei= ng set to zero. This is bad as jumping to zero will crash. =20 -Copyright (c) 2004 - 2019, Intel Corporation. All rights reserved.
+Copyright (c) 2004 - 2023, Intel Corporation. All rights reserved.
Portions copyright (c) 2008 - 2011, Apple Inc. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent =20 @@ -34,6 +34,9 @@ UINTN settimer_callback =3D 0; =20 BOOLEAN gEmulatorInterruptEnabled =3D FALSE; =20 +STATIC BOOLEAN mEmulatorStdInConfigured =3D FALSE; +STATIC struct termios mOldTty; + UINTN SecWriteStdErr ( IN UINT8 *Buffer, @@ -58,8 +61,15 @@ SecConfigStdIn ( // Need to turn off line buffering, ECHO, and make it unbuffered. // tcgetattr (STDIN_FILENO, &tty); + if (!mEmulatorStdInConfigured) { + // + // Save the original state of the TTY so it can be restored on exit + // + CopyMem (&mOldTty, &tty, sizeof (struct termios)); + } tty.c_lflag &=3D ~(ICANON | ECHO); tcsetattr (STDIN_FILENO, TCSANOW, &tty); + mEmulatorStdInConfigured =3D TRUE; =20 // setvbuf (STDIN_FILENO, NULL, _IONBF, 0); =20 @@ -338,6 +348,10 @@ SecExit ( UINTN Status ) { + // Reset the TTY back to its original state + if (mEmulatorStdInConfigured) { + tcsetattr (STDIN_FILENO, TCSANOW, &mOldTty); + } exit (Status); } =20 diff --git a/EmulatorPkg/Win/Host/WinThunk.c b/EmulatorPkg/Win/Host/WinThun= k.c index 008e5755db..90a6da2ece 100644 --- a/EmulatorPkg/Win/Host/WinThunk.c +++ b/EmulatorPkg/Win/Host/WinThunk.c @@ -1,6 +1,6 @@ /**@file =20 -Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.
+Copyright (c) 2006 - 2023, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent =20 Module Name: @@ -30,6 +30,12 @@ Abstract: =20 #include "WinHost.h" =20 +STATIC BOOLEAN mEmulatorStdInConfigured =3D FALSE; +STATIC DWORD mOldStdInMode; +#if defined (NTDDI_VERSION) && defined (NTDDI_WIN10_TH2) && (NTDDI_VERSION= > NTDDI_WIN10_TH2) + STATIC DWORD mOldStdOutMode; +#endif + UINTN SecWriteStdErr ( IN UINT8 *Buffer, @@ -61,6 +67,12 @@ SecConfigStdIn ( =20 Success =3D GetConsoleMode (GetStdHandle (STD_INPUT_HANDLE), &Mode); if (Success) { + if (!mEmulatorStdInConfigured) { + // + // Save the original state of the console so it can be restored on e= xit + // + mOldStdInMode =3D Mode; + } // // Disable buffer (line input), echo, mouse, window // @@ -82,6 +94,12 @@ SecConfigStdIn ( // if (Success) { Success =3D GetConsoleMode (GetStdHandle (STD_OUTPUT_HANDLE), &Mode); + if (!mEmulatorStdInConfigured) { + // + // Save the original state of the console so it can be restored on e= xit + // + mOldStdOutMode =3D Mode; + } if (Success) { Success =3D SetConsoleMode ( GetStdHandle (STD_OUTPUT_HANDLE), @@ -91,6 +109,9 @@ SecConfigStdIn ( } =20 #endif + if (Success) { + mEmulatorStdInConfigured =3D TRUE; + } return Success ? EFI_SUCCESS : EFI_DEVICE_ERROR; } =20 @@ -467,6 +488,23 @@ SecExit ( UINTN Status ) { + #if defined (NTDDI_VERSION) && defined (NTDDI_WIN10_TH2) && (NTDDI_VERSIO= N > NTDDI_WIN10_TH2) + BOOL Success; + #endif + + if (mEmulatorStdInConfigured) { + // + // Reset the console back to its original state + // + #if defined (NTDDI_VERSION) && defined (NTDDI_WIN10_TH2) && (NTDDI_VERSIO= N > NTDDI_WIN10_TH2) + Success =3D SetConsoleMode (GetStdHandle (STD_INPUT_HANDLE), mOldStdIn= Mode); + if (Success) { + SetConsoleMode (GetStdHandle (STD_OUTPUT_HANDLE), mOldStdOutMode); + } + #else + SetConsoleMode (GetStdHandle (STD_INPUT_HANDLE), mOldStdInMode); + #endif + } exit ((int)Status); } =20 --=20 2.34.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#109080): https://edk2.groups.io/g/devel/message/109080 Mute This Topic: https://groups.io/mt/101602599/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-