summaryrefslogtreecommitdiff
path: root/EmulatorPkg/Win
diff options
context:
space:
mode:
authorNate DeSimone <nathaniel.l.desimone@intel.com>2023-09-26 11:07:43 -0700
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2023-09-27 01:00:47 +0000
commitad1c0394b1770315099e511de7c88a04d7af76f2 (patch)
tree48b18c4a22abfa2e704125f262fd0184ef30b4be /EmulatorPkg/Win
parentbe971fc302cbef8f47e2612eda114135f21205e6 (diff)
downloadedk2-ad1c0394b1770315099e511de7c88a04d7af76f2.zip
edk2-ad1c0394b1770315099e511de7c88a04d7af76f2.tar.gz
edk2-ad1c0394b1770315099e511de7c88a04d7af76f2.tar.bz2
EmulatorPkg: Fix Terminal Issues
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. Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com> Cc: Andrew Fish <afish@apple.com> Cc: Ray Ni <ray.ni@intel.com> Cc: Chasel Chiu <chasel.chiu@intel.com> Signed-off-by: Nate DeSimone <nathaniel.l.desimone@intel.com>
Diffstat (limited to 'EmulatorPkg/Win')
-rw-r--r--EmulatorPkg/Win/Host/WinThunk.c41
1 files changed, 40 insertions, 1 deletions
diff --git a/EmulatorPkg/Win/Host/WinThunk.c b/EmulatorPkg/Win/Host/WinThunk.c
index 008e575..42044f2 100644
--- a/EmulatorPkg/Win/Host/WinThunk.c
+++ b/EmulatorPkg/Win/Host/WinThunk.c
@@ -1,6 +1,6 @@
/**@file
-Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006 - 2023, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
Module Name:
@@ -30,6 +30,12 @@ Abstract:
#include "WinHost.h"
+STATIC BOOLEAN mEmulatorStdInConfigured = 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,13 @@ SecConfigStdIn (
Success = 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 = Mode;
+ }
+
//
// Disable buffer (line input), echo, mouse, window
//
@@ -82,6 +95,13 @@ SecConfigStdIn (
//
if (Success) {
Success = GetConsoleMode (GetStdHandle (STD_OUTPUT_HANDLE), &Mode);
+ if (!mEmulatorStdInConfigured) {
+ //
+ // Save the original state of the console so it can be restored on exit
+ //
+ mOldStdOutMode = Mode;
+ }
+
if (Success) {
Success = SetConsoleMode (
GetStdHandle (STD_OUTPUT_HANDLE),
@@ -91,6 +111,10 @@ SecConfigStdIn (
}
#endif
+ if (Success) {
+ mEmulatorStdInConfigured = TRUE;
+ }
+
return Success ? EFI_SUCCESS : EFI_DEVICE_ERROR;
}
@@ -467,6 +491,21 @@ SecExit (
UINTN Status
)
{
+ if (mEmulatorStdInConfigured) {
+ //
+ // Reset the console back to its original state
+ //
+ #if defined (NTDDI_VERSION) && defined (NTDDI_WIN10_TH2) && (NTDDI_VERSION > NTDDI_WIN10_TH2)
+ BOOL Success = SetConsoleMode (GetStdHandle (STD_INPUT_HANDLE), mOldStdInMode);
+ if (Success) {
+ SetConsoleMode (GetStdHandle (STD_OUTPUT_HANDLE), mOldStdOutMode);
+ }
+
+ #else
+ SetConsoleMode (GetStdHandle (STD_INPUT_HANDLE), mOldStdInMode);
+ #endif
+ }
+
exit ((int)Status);
}