[newlib-cygwin] Cygwin: console: Fix master thread

Takashi Yano via Cygwin-cvs <[email protected]> Sun, 29 Mar 2026 00:43:45 +0000 (GMT)
Newsgroups gmane.os.cygwin.cvs
Message-ID <[email protected]>
https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3D95b477fb2df=
76beca1469decf71242c24b223ac5

commit 95b477fb2df76beca1469decf71242c24b223ac5
Author: Takashi Yano <[email protected]>
Date:   Fri Mar 20 22:59:58 2026 +0900

    Cygwin: console: Fix master thread
   =20
    In Windows 11, key event with wRepeatCount =3D=3D 0 is fixed-up to
    wRepeatCount =3D=3D 1 in conhost.exe.
    https://github.com/microsoft/terminal/blob/v1.25.622.0/src/host/inputBu=
ffer.cpp#L406
   =20
    The console master thread (`cons_master_thread`) reads INPUT_RECORDs
    from the console input buffer, processes signal-generating events,
    and writes the remaining records back. After the writeback, it peeks
    the buffer and uses `inrec_eq()` to verify that conhost stored the
    records faithfully. On Windows 11, conhost normalizes `wRepeatCount`
    from 0 to 1 on readback, causing `inrec_eq()` to report a mismatch
    and triggering an unnecessary fixup path. Treat 0 and 1 as equivalent
    for comparison purposes.
   =20
    Addresses: https://github.com/git-for-windows/git/issues/5632
    Fixes: ff4440fcf768 ("Cygwin: console: Introduce new thread which handl=
es input signal.")
    Signed-off-by: Takashi Yano <[email protected]>
    Reviewed-by: Johannes Schindelin <[email protected]>

Diff:
---
 winsup/cygwin/fhandler/console.cc | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/winsup/cygwin/fhandler/console.cc b/winsup/cygwin/fhandler/con=
sole.cc
index 8b4491daf..2f46bbc6c 100644
--- a/winsup/cygwin/fhandler/console.cc
+++ b/winsup/cygwin/fhandler/console.cc
@@ -318,9 +318,17 @@ inrec_eq (const INPUT_RECORD *a, const INPUT_RECORD *b=
, DWORD n)
 	     written event. Therefore they are ignored. */
 	  const KEY_EVENT_RECORD *ak =3D &a[i].Event.KeyEvent;
 	  const KEY_EVENT_RECORD *bk =3D &b[i].Event.KeyEvent;
+	  /* On Windows 11, conhost normalizes wRepeatCount from 0 to 1
+	     on readback. Treat them as equivalent for comparison. */
+	  WORD r1 =3D ak->wRepeatCount;
+	  WORD r2 =3D bk->wRepeatCount;
+	  if (r1 =3D=3D 0)
+	    r1 =3D 1;
+	  if (r2 =3D=3D 0)
+	    r2 =3D 1;
 	  if (ak->bKeyDown !=3D bk->bKeyDown
 	      || ak->uChar.UnicodeChar !=3D bk->uChar.UnicodeChar
-	      || ak->wRepeatCount !=3D bk->wRepeatCount)
+	      || r1 !=3D r2)
 	    return false;
 	}
       else if (a[i].EventType =3D=3D MOUSE_EVENT)