[PATCH] Cygwin: pty: Discard remnants of win32-input-mode
Takashi Yano
takashi.yano@nifty.ne.jp
Mon Feb 23 08:00:19 GMT 2026
In Windoes 11, some remnants sequences of win32-input-mode used by
pseudo console occasionally sent to shell which start non-cygwin
apps. With this patch, the remnants sequneces just after closing
pseudo console will be discarded.
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
Reviewed-by:
---
winsup/cygwin/fhandler/pty.cc | 11 +++++++++++
winsup/cygwin/local_includes/tty.h | 1 +
winsup/cygwin/tty.cc | 1 +
3 files changed, 13 insertions(+)
diff --git a/winsup/cygwin/fhandler/pty.cc b/winsup/cygwin/fhandler/pty.cc
index b30cb0128..b90b2b609 100644
--- a/winsup/cygwin/fhandler/pty.cc
+++ b/winsup/cygwin/fhandler/pty.cc
@@ -2504,6 +2504,16 @@ fhandler_pty_master::write (const void *ptr, size_t len)
return len;
}
+ /* Remnants of win32-input-mode sequence in pcon_activated mode */
+ bool is_remnants_to_nat =
+ GetTickCount64 () - get_ttyp ()->pcon_close_time < 32
+ && len >= 3 && p[0] == '\033' && p[1] == '[' && p[len - 1] =='_';
+ if (is_remnants_to_nat) /* Discard */
+ {
+ ReleaseMutex (input_mutex);
+ return len;
+ }
+
/* The code path reaches here when pseudo console is not activated
or cygwin process is foreground even though pseudo console is
activated. */
@@ -3947,6 +3957,7 @@ fhandler_pty_slave::close_pseudoconsole (tty *ttyp, DWORD force_switch_to)
/* HeapFree() will be called in ClosePseudoConsole() */
ClosePseudoConsole ((HPCON) hp);
CloseHandle (ttyp->h_pcon_conhost_process);
+ ttyp->pcon_close_time = GetTickCount64 ();
ttyp->pcon_activated = false;
ttyp->switch_to_nat_pipe = false;
ttyp->nat_pipe_owner_pid = 0;
diff --git a/winsup/cygwin/local_includes/tty.h b/winsup/cygwin/local_includes/tty.h
index 9485e24c5..14b8f0278 100644
--- a/winsup/cygwin/local_includes/tty.h
+++ b/winsup/cygwin/local_includes/tty.h
@@ -141,6 +141,7 @@ private:
xfer_dir pty_input_state;
bool discard_input;
bool stop_fwd_thread;
+ ULONGLONG pcon_close_time;
public:
HANDLE from_master_nat () const { return _from_master_nat; }
diff --git a/winsup/cygwin/tty.cc b/winsup/cygwin/tty.cc
index 0c49dc2bd..defd3ead5 100644
--- a/winsup/cygwin/tty.cc
+++ b/winsup/cygwin/tty.cc
@@ -255,6 +255,7 @@ tty::init ()
last_sig = 0;
discard_input = false;
stop_fwd_thread = false;
+ pcon_close_time = 0;
}
HANDLE
--
2.51.0
More information about the Cygwin-patches
mailing list