From f03806b68a556323f858f816e391fadb01b287bb Mon Sep 17 00:00:00 2001 From: Takashi Yano Date: Tue, 14 Jan 2020 10:53:59 +0900 Subject: [PATCH] Cygwin: console: Add workaround for broken CSI3J in Win10 1809. - In Win10 1809, the cursor position sometimes goes out of screen by clear command in console. This seems to be caused by escape sequence CSI3J (ESC[3J). This happens only for 1809. This patch is a workaround for the issue. --- winsup/cygwin/fhandler_console.cc | 12 +++++++++ winsup/cygwin/wincap.cc | 41 ++++++++++++++++++++++++++++++- winsup/cygwin/wincap.h | 2 ++ 3 files changed, 54 insertions(+), 1 deletion(-) diff --git a/winsup/cygwin/fhandler_console.cc b/winsup/cygwin/fhandler_console.cc index d9766915f..337331be2 100644 --- a/winsup/cygwin/fhandler_console.cc +++ b/winsup/cygwin/fhandler_console.cc @@ -1658,6 +1658,18 @@ bool fhandler_console::write_console (PWCHAR buf, DWORD len, DWORD& done) if (wincap.has_con_24bit_colors () && !con_is_legacy && memmem (buf, len*sizeof (WCHAR), L"\033[?1049", 7*sizeof (WCHAR))) need_fix_tab_position = true; + /* Workaround for broken CSI3J (ESC[3J) support in xterm compatible mode. */ + if (wincap.has_con_24bit_colors () && !con_is_legacy && + wincap.has_con_broken_csi3j ()) + { + WCHAR *p = buf; + while ((p = (WCHAR *) memmem (p, (len - (p - buf))*sizeof (WCHAR), + L"\033[3J", 4*sizeof (WCHAR)))) + { + memmove (p, p+4, (len - (p+4 - buf))*sizeof (WCHAR)); + len -= 4; + } + } if (con.iso_2022_G1 ? con.vt100_graphics_mode_G1 diff --git a/winsup/cygwin/wincap.cc b/winsup/cygwin/wincap.cc index 5c6e6428e..a52262b89 100644 --- a/winsup/cygwin/wincap.cc +++ b/winsup/cygwin/wincap.cc @@ -42,6 +42,7 @@ wincaps wincap_vista __attribute__((section (".cygwin_dll_common"), shared)) = { has_posix_rename_semantics:false, no_msv1_0_s4u_logon_in_wow64:true, has_con_24bit_colors:false, + has_con_broken_csi3j:false, }, }; @@ -69,6 +70,7 @@ wincaps wincap_7 __attribute__((section (".cygwin_dll_common"), shared)) = { has_posix_rename_semantics:false, no_msv1_0_s4u_logon_in_wow64:true, has_con_24bit_colors:false, + has_con_broken_csi3j:false, }, }; @@ -96,6 +98,7 @@ wincaps wincap_8 __attribute__((section (".cygwin_dll_common"), shared)) = { has_posix_rename_semantics:false, no_msv1_0_s4u_logon_in_wow64:false, has_con_24bit_colors:false, + has_con_broken_csi3j:false, }, }; @@ -123,6 +126,7 @@ wincaps wincap_8_1 __attribute__((section (".cygwin_dll_common"), shared)) = { has_posix_rename_semantics:false, no_msv1_0_s4u_logon_in_wow64:false, has_con_24bit_colors:false, + has_con_broken_csi3j:false, }, }; @@ -150,6 +154,7 @@ wincaps wincap_10_1507 __attribute__((section (".cygwin_dll_common"), shared)) has_posix_rename_semantics:false, no_msv1_0_s4u_logon_in_wow64:false, has_con_24bit_colors:false, + has_con_broken_csi3j:false, }, }; @@ -177,6 +182,7 @@ wincaps wincap_10_1703 __attribute__((section (".cygwin_dll_common"), shared)) = has_posix_rename_semantics:false, no_msv1_0_s4u_logon_in_wow64:false, has_con_24bit_colors:true, + has_con_broken_csi3j:false, }, }; @@ -204,6 +210,7 @@ wincaps wincap_10_1709 __attribute__((section (".cygwin_dll_common"), shared)) = has_posix_rename_semantics:false, no_msv1_0_s4u_logon_in_wow64:false, has_con_24bit_colors:true, + has_con_broken_csi3j:false, }, }; @@ -231,6 +238,7 @@ wincaps wincap_10_1803 __attribute__((section (".cygwin_dll_common"), shared)) = has_posix_rename_semantics:false, no_msv1_0_s4u_logon_in_wow64:false, has_con_24bit_colors:true, + has_con_broken_csi3j:false, }, }; @@ -258,6 +266,35 @@ wincaps wincap_10_1809 __attribute__((section (".cygwin_dll_common"), shared)) = has_posix_rename_semantics:true, no_msv1_0_s4u_logon_in_wow64:false, has_con_24bit_colors:true, + has_con_broken_csi3j:true, + }, +}; + +wincaps wincap_10_1903 __attribute__((section (".cygwin_dll_common"), shared)) = { + def_guard_pages:2, + mmap_storage_high:0x700000000000LL, + { + is_server:false, + needs_count_in_si_lpres2:false, + needs_query_information:false, + has_gaa_largeaddress_bug:false, + has_broken_alloc_console:true, + has_console_logon_sid:true, + has_precise_system_time:true, + has_microsoft_accounts:true, + has_processor_groups:true, + has_broken_prefetchvm:false, + has_new_pebteb_region:true, + has_broken_whoami:false, + has_unprivileged_createsymlink:true, + has_unbiased_interrupt_time:true, + has_precise_interrupt_time:true, + has_posix_unlink_semantics:true, + has_case_sensitive_dirs:true, + has_posix_rename_semantics:true, + no_msv1_0_s4u_logon_in_wow64:false, + has_con_24bit_colors:true, + has_con_broken_csi3j:false, }, }; @@ -301,7 +338,9 @@ wincapc::init () break; case 10: default: - if (likely (version.dwBuildNumber >= 17763)) + if (likely (version.dwBuildNumber >= 18362)) + caps = &wincap_10_1903; + else if (version.dwBuildNumber >= 17763) caps = &wincap_10_1809; else if (version.dwBuildNumber >= 17134) caps = &wincap_10_1803; diff --git a/winsup/cygwin/wincap.h b/winsup/cygwin/wincap.h index ba01a1565..11902d976 100644 --- a/winsup/cygwin/wincap.h +++ b/winsup/cygwin/wincap.h @@ -36,6 +36,7 @@ struct wincaps unsigned has_posix_rename_semantics : 1; unsigned no_msv1_0_s4u_logon_in_wow64 : 1; unsigned has_con_24bit_colors : 1; + unsigned has_con_broken_csi3j : 1; }; }; @@ -95,6 +96,7 @@ public: bool IMPLEMENT (has_posix_rename_semantics) bool IMPLEMENT (no_msv1_0_s4u_logon_in_wow64) bool IMPLEMENT (has_con_24bit_colors) + bool IMPLEMENT (has_con_broken_csi3j) void disable_case_sensitive_dirs () {