From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id DFAD9941B7C for ; Tue, 26 Sep 2023 20:37:35 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=/Nifxi8wDNBD/ROaVwmIrrVnWhuEyhOoBgaHdTD7iDA=; c=relaxed/simple; d=groups.io; h=ARC-Seal:ARC-Message-Signature:ARC-Authentication-Results:From:To:CC:Subject:Thread-Topic:Thread-Index:Date:Message-ID:References:In-Reply-To:Accept-Language:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Language:Content-Type:Content-Transfer-Encoding; s=20140610; t=1695760654; v=1; b=ZcmJJ8QLQqEeH6pH/kZWNOB6Fr9pj6ZkX2t0bK7S9RpzDcoUBklOOnoq6D5i89b6PwPbHq79 nS/hgkzspRq0lGmevONAIJe/Jm+1bkdiI5VAgYgPljv0ofavj2Hhxn4zaT+vXw1ezQ4TE8FfKug 0t9hOS7DGeEmzCUdw5KUeQGA= X-Received: by 127.0.0.2 with SMTP id CfDLYY7687511xmweQXDbAkX; Tue, 26 Sep 2023 13:37:34 -0700 X-Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.115]) by mx.groups.io with SMTP id smtpd.web11.2117.1695760654051835801 for ; Tue, 26 Sep 2023 13:37:34 -0700 X-IronPort-AV: E=McAfee;i="6600,9927,10845"; a="381563956" X-IronPort-AV: E=Sophos;i="6.03,178,1694761200"; d="scan'208";a="381563956" X-Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Sep 2023 13:37:33 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.03,178,1694761200"; d="scan'208";a="286789" X-Received: from fmsmsx603.amr.corp.intel.com ([10.18.126.83]) by fmviesa001.fm.intel.com with ESMTP/TLS/AES256-GCM-SHA384; 26 Sep 2023 13:37:34 -0700 X-Received: from fmsmsx602.amr.corp.intel.com (10.18.126.82) by fmsmsx603.amr.corp.intel.com (10.18.126.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.32; Tue, 26 Sep 2023 13:37:33 -0700 X-Received: from fmsedg602.ED.cps.intel.com (10.1.192.136) by fmsmsx602.amr.corp.intel.com (10.18.126.82) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.32 via Frontend Transport; Tue, 26 Sep 2023 13:37:33 -0700 X-Received: from NAM12-MW2-obe.outbound.protection.outlook.com (104.47.66.48) by edgegateway.intel.com (192.55.55.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.32; Tue, 26 Sep 2023 13:37:33 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hASFKsCdF0I4e9mcx2BLm674JgxmI1LXTqtEanueAVDQPIX4Yw2daI7yhT55673lF8jJ+4InRI1bd91L3ISAsznv+bv0ZJ/HgfUJmuI6LNRcvwg+It5DYKCADnlQ3cWcNNLfP2joNhNcLOVvHX4uo1PulYpH6Kn+UHkqfPGL9Xy3CnIzfcjLyd6CiyBXP5vd7tomG2ihqmcPQXcsMZWlwwUaHeRcZ/MTzrCkS7d2KHnvmnoAXnu2hvfI/w6NDssbLT8ljsEur76unf0wZmLxo9N6rcLn9CeLNJTQMYE51VSI4vXVddgFUMD9YUfKtM7lGQDcyOAxvtlxKg4SZrdqBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=2FvZeOs35XTd5VTtqvq2TYv6TfiEgBV/YdFIWdBvLAs=; b=lYQZ9nh8Zjo4TI5E1NGljSxTrVzcC8cuN6i6kSlzjNkKMFgY8OAba5f56tdtOO37O7tPa2H9D9hH4xsWon4Z+jfHYwv3PWGvNVp4Iy3MBSRQo0m9pFMqor1l38TZeYvwXRZZshgQ8j0Vr9ezz2z63dlgcIU5dCkr6iYz+bd1EFvYcBTKcwOIw6pODWg4gN/6GqWkwsWxYbfWsXPq4OotbXjmAexkOHoM6dIUoA/0JX+CCJAFovOjCdZkrQcBsIwxYptT7wb1o78HVL0U0Qa7a8KR7QpexqNnHRmPMcRbQORi1bvRx2iOQilwft3o/C1SE2J8/LZVQxlxYrWIHDFE1w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none X-Received: from MW4PR11MB5821.namprd11.prod.outlook.com (2603:10b6:303:184::5) by DM4PR11MB5503.namprd11.prod.outlook.com (2603:10b6:5:39f::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6813.28; Tue, 26 Sep 2023 20:37:31 +0000 X-Received: from MW4PR11MB5821.namprd11.prod.outlook.com ([fe80::89db:ecf0:29f5:9f3c]) by MW4PR11MB5821.namprd11.prod.outlook.com ([fe80::89db:ecf0:29f5:9f3c%4]) with mapi id 15.20.6813.017; Tue, 26 Sep 2023 20:37:31 +0000 From: "Nate DeSimone" To: "Kinney, Michael D" , "devel@edk2.groups.io" CC: Andrew Fish , "Ni, Ray" , "Chiu, Chasel" Subject: Re: [edk2-devel] [PATCH v1] EmulatorPkg: Fix Terminal Issues Thread-Topic: [PATCH v1] EmulatorPkg: Fix Terminal Issues Thread-Index: AQHZ8KhcA9l2MMuSy0C673hGdEk4+rAth0pwgAAJYYA= Date: Tue, 26 Sep 2023 20:37:31 +0000 Message-ID: References: <20230926183601.2974-1-nathaniel.l.desimone@intel.com> In-Reply-To: Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-publictraffictype: Email x-ms-traffictypediagnostic: MW4PR11MB5821:EE_|DM4PR11MB5503:EE_ x-ms-office365-filtering-correlation-id: 31599e5c-d671-490a-5871-08dbbed0682d x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam-message-info: 8KlSEa6YQoiWW8Jf9YHuSbwihLzyrPsu6H99b5duhFssH4aQMWClfUXLI1W6sPhhvbOxDM4sHd2muAfjekgU1lEat9NoYKcWp6YHymp+3nze983NXTalNTsDUvg/ehNVagD962+BENi5mGex1kSG35n4NUUNNxErW/PVl11BWeqEtYfr/OHKSiSyu1/p8kVODlrBWvIWlaa8tF+s2rQT1lsLZnvoi4LySIj846PdK7ZmJ5RHgbXNuwu53rvPznt5mCqPmjj9e7w4EwkQrpcNJ0oIc33WeSkyPpIi0zNifs+i8pB0RJ7ro/G5zLdX0bXLio7qdS73jbZZtG8nC7eQOkNblQnua6lADWDZUBo/+79PIG7163JCXT8xHRuhVdH9yDR2Efgeg13fALLHvanzgYX1Omw9q2zhNPVcJmURjdkDyRRTKeNxuoDu9a2jvTkBxLlN0ZFoHHTtLOrV/h4zZEDpEx7bCliEJ0yPkwMaVSptZ8cnLSNDFOPlNWsns/eACzCTfRjhARKB46NkAy38Lt5Sx/JslZvqueLXIY+2Sj/LEHxwVMYjKOG4z0O4eKlTfrfCWrmOVl5fbjmOvoAAlcqqee4hhzJ1cmVEgBd6D8CTdE+F/Cws9SzKboBJ8iHz x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?noQ+7OWYHTGZAa8q5cATw3dlCi0z6r/SfeZADe+m6amTe9/MjWxm6513QSeZ?= =?us-ascii?Q?4bLbmMWo/EmCzV1ujqPNHLVMvkWCiQpOB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?Q?9FMP9n1UuVLU8s7ea8glIPFYyemhW/TQVLVzQYjFLvnProl5TbXKP+gKTJHJ?= =?us-ascii?Q?hzj5zn5KL8cv9hLEfkOzPKmyXVhScV1r4qJrK/sHhR5R6Htfr6syDrdlQhQm?= =?us-ascii?Q?T26aTN9Bo4aSysAleIIuff5cCx+wKHYARiuxLsJlGzSWfIkUtvn2RfYNTCrk?= =?us-ascii?Q?K0uy7Uo0jaPM/ZLxor5V6nR91T11WZGbRym+WxpadX91vlOpTpGFFT5LIYrf?= =?us-ascii?Q?Kras/bvSt3FvIKDErJmLv95MLIWH0KjMzNe+RKuTnO9aZTYWqtkEWWzFWrSs?= =?us-ascii?Q?xp0Mywll8AZS7TIh4eAtY7sjGRP7/jV2OUxbG+13gapAp/8UaRt7MURAGHs/?= =?us-ascii?Q?Q96VSS3uY/0wNmofvmWkwMewjK5ciMukIKdHshz9UUr+xJxsg/d3jZ4rbB5F?= =?us-ascii?Q?lMqrQIpH1bFLkibBoSNproccqDZHpPBgSgcffxF2T8pFzWH8Uj+S2nvofjLd?= =?us-ascii?Q?XhYJR68xhnigXdqDKS8E+Y5fL72oTRoyMn4dghvdFFqy9GPXIjYJcMiVH74b?= =?us-ascii?Q?Q1CNKZ8Ebl91WBCfA7leRuPA2GBHuujI6zLkcK++gie8IuB2jf61pKPKYy2I?= =?us-ascii?Q?fPLP2MeTxrYqxZyz4D80a2YXb67pw0RGwrTW1P/IGck6hAuOrlxbuTl59oGc?= =?us-ascii?Q?mg=3D=3D?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MW4PR11MB5821.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 31599e5c-d671-490a-5871-08dbbed0682d X-MS-Exchange-CrossTenant-originalarrivaltime: 26 Sep 2023 20:37:31.3257 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: pJaj6yWlwpGfvsynN8pakn6vJHpfqr4CmGx0Zxz/Pdbn8TGIuJ08SGtIPJtqEV858nsJ9KFx2cCjGobvp19G4YeAhc40XtnfdK7KDRa0UfA= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR11MB5503 X-OriginatorOrg: intel.com 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: z9DBoMnCoG61R0O2k4oJHjbFx7686176AA= Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=ZcmJJ8QL; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=intel.com (policy=none); spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io Hi Mike, Unfortunately, that change will generate the following warning on GCC4.6+ warning: variable "Success" set but not used [-Wunused-but-set-variable] Hence why I wrote it that way. Let me know if you would like me to make a d= ifferent change before committing. Thanks, Nate -----Original Message----- From: Kinney, Michael D =20 Sent: Tuesday, September 26, 2023 1:03 PM To: Desimone, Nathaniel L ; devel@edk2.grou= ps.io Cc: Andrew Fish ; Ni, Ray ; Chiu, Chasel= ; Kinney, Michael D Subject: RE: [PATCH v1] EmulatorPkg: Fix Terminal Issues Thanks Nate! I have noticed this issue for a while. One comment below. With that update: Reviewed-by: Michael D Kinney Mike > -----Original Message----- > From: Desimone, Nathaniel L > Sent: Tuesday, September 26, 2023 11:36 AM > To: devel@edk2.groups.io > Cc: Andrew Fish ; Ni, Ray ; Kinney,=20 > Michael D ; Chiu, Chasel=20 > > Subject: [PATCH v1] EmulatorPkg: Fix Terminal Issues >=20 > After running EmulatorPkg, one will notice that their terminal acts=20 > strangely. This is caused by the EmulatorPkg Host changing the=20 > terminal mode and not restoring the original mode, which is now fixed. >=20 > Cc: Andrew Fish > Cc: Ray Ni > Cc: Michael D Kinney > Cc: Chasel Chiu > Signed-off-by: Nate DeSimone > --- > EmulatorPkg/Unix/Host/EmuThunk.c | 16 ++++++++++++- =20 > EmulatorPkg/Win/Host/WinThunk.c | 40 > +++++++++++++++++++++++++++++++- > 2 files changed, 54 insertions(+), 2 deletions(-) >=20 > diff --git a/EmulatorPkg/Unix/Host/EmuThunk.c > b/EmulatorPkg/Unix/Host/EmuThunk.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=20 > end being > set to zero. This is bad as jumping to zero will crash. >=20 > -Copyright (c) 2004 - 2019, Intel Corporation. All rights=20 > reserved.
> +Copyright (c) 2004 - 2023, Intel Corporation. All rights > reserved.
> Portions copyright (c) 2008 - 2011, Apple Inc. All rights=20 > 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=20 > +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=20 > + (mEmulatorStdInConfigured) { > + tcsetattr (STDIN_FILENO, TCSANOW, &mOldTty); } > exit (Status); > } >=20 > diff --git a/EmulatorPkg/Win/Host/WinThunk.c=20 > b/EmulatorPkg/Win/Host/WinThunk.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=20 > 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=20 > +mOldStdInMode; #if defined (NTDDI_VERSION) && defined=20 > +(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 exit > + // > + mOldStdInMode =3D Mode; > + } > // > // Disable buffer (line input), echo, mouse, window > // > @@ -82,6 +94,12 @@ SecConfigStdIn ( > // > if (Success) { > Success =3D GetConsoleMode (GetStdHandle (STD_OUTPUT_HANDLE),=20 > &Mode); > + if (!mEmulatorStdInConfigured) { > + // > + // Save the original state of the console so it can be restored > on exit > + // > + mOldStdOutMode =3D Mode; > + } > if (Success) { > Success =3D SetConsoleMode ( > GetStdHandle (STD_OUTPUT_HANDLE), @@ -91,6 +109,9=20 > @@ 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_VERSION > 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_VERSION > NTDDI_WIN10_TH2) I think the BOOL Success variable could be added here and reduce the #if st= atements > + Success =3D SetConsoleMode (GetStdHandle (STD_INPUT_HANDLE), > mOldStdInMode); > + if (Success) { > + SetConsoleMode (GetStdHandle (STD_OUTPUT_HANDLE), > mOldStdOutMode); > + } > + #else > + SetConsoleMode (GetStdHandle (STD_INPUT_HANDLE), mOldStdInMode);=20 > + #endif } > exit ((int)Status); > } >=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 (#109090): https://edk2.groups.io/g/devel/message/109090 Mute This Topic: https://groups.io/mt/101602599/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-