Re: [PATCH v2 0/2] cpuinfo: fix check; add AVX features; move SME, SEV/_ES features

2021-02-18 Thread Corinna Vinschen via Cygwin-patches
On Feb 17 09:28, Brian Inglis wrote:
> Brian Inglis (2):
>   fix check for cpuid 0x8007 support
>   add AVX features; move SME, SEV/_ES features
> 
>  winsup/cygwin/fhandler_proc.cc | 46 ++
>  1 file changed, 24 insertions(+), 22 deletions(-)
> 
> -- 
> 2.30.0

Pushed.

Thanks,
Corinna


[PATCH 0/2] Console fixes for Win7.

2021-02-18 Thread Takashi Yano via Cygwin-patches
Takashi Yano (2):
  Cygwin: console: Fix SIGWINCH handling in Win7.
  Cygwin: console: Fix handling of Ctrl-S in Win7.

 winsup/cygwin/fhandler.h  |   9 +-
 winsup/cygwin/fhandler_console.cc | 306 --
 winsup/cygwin/select.cc   |   4 +-
 winsup/cygwin/spawn.cc|  32 ++--
 winsup/cygwin/tty.h   |   8 +-
 5 files changed, 113 insertions(+), 246 deletions(-)

-- 
2.30.0



[PATCH 1/2] Cygwin: console: Fix SIGWINCH handling in Win7.

2021-02-18 Thread Takashi Yano via Cygwin-patches
- If ENABLE_VIRTUAL_TERMINAL_INPUT is not set, changing window height
  does not generate WINDOW_BUFFER_SIZE_EVENT. This happens if console
  is in the legacy mode. Therefore, with this patch, the windows size
  is checked every time in cons_master_thread() if the cosole is in
  the legacy mode.
---
 winsup/cygwin/fhandler_console.cc | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/winsup/cygwin/fhandler_console.cc 
b/winsup/cygwin/fhandler_console.cc
index 5053cb053..4dee506dd 100644
--- a/winsup/cygwin/fhandler_console.cc
+++ b/winsup/cygwin/fhandler_console.cc
@@ -223,6 +223,21 @@ fhandler_console::cons_master_thread (handle_set_t *p, tty 
*ttyp)
  ReleaseMutex (p->input_mutex);
  return;
}
+  /* If ENABLE_VIRTUAL_TERMINAL_INPUT is not set, changing
+window height does not generate WINDOW_BUFFER_SIZE_EVENT.
+Therefore, check windows size every time here. */
+  if (!wincap.has_con_24bit_colors () || con_is_legacy)
+   {
+ SHORT y = con.dwWinSize.Y;
+ SHORT x = con.dwWinSize.X;
+ con.fillin (p->output_handle);
+ if (y != con.dwWinSize.Y || x != con.dwWinSize.X)
+   {
+ con.scroll_region.Top = 0;
+ con.scroll_region.Bottom = -1;
+ ttyp->kill_pgrp (SIGWINCH);
+   }
+   }
   for (i = 0; i < total_read; i++)
{
  const char c = input_rec[i].Event.KeyEvent.uChar.AsciiChar;
-- 
2.30.0



[PATCH 2/2] Cygwin: console: Fix handling of Ctrl-S in Win7.

2021-02-18 Thread Takashi Yano via Cygwin-patches
- If ENABLE_LINE_INPUT is set, Ctrl-S is handled by Windows if the
  OS is Windows 7. This conflicts with Ctrl-S handling in cygwin
  console code. This patch unsets ENABLE_LINE_INPUT flag in cygwin
  and set it when native app is executed.
---
 winsup/cygwin/fhandler.h  |   9 +-
 winsup/cygwin/fhandler_console.cc | 291 +++---
 winsup/cygwin/select.cc   |   4 +-
 winsup/cygwin/spawn.cc|  32 ++--
 winsup/cygwin/tty.h   |   8 +-
 5 files changed, 98 insertions(+), 246 deletions(-)

diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h
index e457e2785..faa910692 100644
--- a/winsup/cygwin/fhandler.h
+++ b/winsup/cygwin/fhandler.h
@@ -2135,11 +2135,9 @@ private:
   const unsigned char *write_normal (unsigned const char*, unsigned const char 
*);
   void char_command (char);
   bool set_raw_win32_keyboard_mode (bool);
-  int output_tcsetattr (int a, const struct termios *t);
 
 /* Input calls */
   int igncr_enabled ();
-  int input_tcsetattr (int a, const struct termios *t);
   void set_cursor_maybe ();
   static bool create_invisible_console (HWINSTA);
   static bool create_invisible_console_workaround (bool force);
@@ -2196,7 +2194,6 @@ private:
   void fixup_after_exec () {fixup_after_fork_exec (true);}
   void fixup_after_fork (HANDLE) {fixup_after_fork_exec (false);}
   void set_close_on_exec (bool val);
-  void set_input_state ();
   bool send_winch_maybe ();
   void setup ();
   bool set_unit ();
@@ -2245,8 +2242,10 @@ private:
   void get_duplicated_handle_set (handle_set_t *p);
   static void close_handle_set (handle_set_t *p);
 
-  static void request_xterm_mode_input (bool, const handle_set_t *p);
-  static void request_xterm_mode_output (bool, const handle_set_t *p);
+  static void set_input_mode (tty::cons_mode m, const termios *t,
+ const handle_set_t *p);
+  static void set_output_mode (tty::cons_mode m, const termios *t,
+  const handle_set_t *p);
 
   static void cons_master_thread (handle_set_t *p, tty *ttyp);
 
diff --git a/winsup/cygwin/fhandler_console.cc 
b/winsup/cygwin/fhandler_console.cc
index 4dee506dd..ca8eb6400 100644
--- a/winsup/cygwin/fhandler_console.cc
+++ b/winsup/cygwin/fhandler_console.cc
@@ -299,8 +299,8 @@ fhandler_console::cons_master_thread (handle_set_t *p, tty 
*ttyp)
{ /* Fix tab position */
  /* Re-setting ENABLE_VIRTUAL_TERMINAL_PROCESSING
 fixes the tab position. */
- request_xterm_mode_output (false, p);
- request_xterm_mode_output (true, p);
+ set_output_mode (tty::restore, &ti, p);
+ set_input_mode (tty::cygwin, &ti, p);
}
  ttyp->kill_pgrp (SIGWINCH);
}
@@ -446,64 +446,72 @@ fhandler_console::rabuflen ()
   return con_ra.rabuflen;
 }
 
-/* The function request_xterm_mode_{in,out}put() should be static so that
-   they can be called even after the fhandler_console instance is deleted. */
+/* The function set_{in,out}put_mode() should be static so that they
+   can be called even after the fhandler_console instance is deleted. */
 void
-fhandler_console::request_xterm_mode_input (bool req, const handle_set_t *p)
+fhandler_console::set_input_mode (tty::cons_mode m, const termios *t,
+ const handle_set_t *p)
 {
-  if (con_is_legacy)
-return;
+  DWORD flags = 0, oflags;
   WaitForSingleObject (p->input_mutex, INFINITE);
-  DWORD dwMode;
-  GetConsoleMode (p->input_handle, &dwMode);
-  if (req)
+  GetConsoleMode (p->input_handle, &oflags);
+  switch (m)
 {
-  if (!(dwMode & ENABLE_VIRTUAL_TERMINAL_INPUT))
-   {
- dwMode |= ENABLE_VIRTUAL_TERMINAL_INPUT;
- SetConsoleMode (p->input_handle, dwMode);
- if (con.cursor_key_app_mode) /* Restore DECCKM */
-   {
- request_xterm_mode_output (true, p);
- WriteConsoleW (p->output_handle, L"\033[?1h", 5, NULL, 0);
-   }
-   }
+case tty::restore:
+  flags = ENABLE_ECHO_INPUT | ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT;
+  break;
+case tty::cygwin:
+  flags = ENABLE_WINDOW_INPUT;
+  if (wincap.has_con_24bit_colors () && !con_is_legacy)
+   flags |= ENABLE_VIRTUAL_TERMINAL_INPUT;
+  else
+   flags |= ENABLE_MOUSE_INPUT;
+  break;
+case tty::native:
+  if (t->c_lflag & ECHO)
+   flags |= ENABLE_ECHO_INPUT;
+  if (t->c_lflag & ICANON)
+   flags |= ENABLE_LINE_INPUT;
+  if (flags & ENABLE_ECHO_INPUT && !(flags & ENABLE_LINE_INPUT))
+   /* This is illegal, so turn off the echo here, and fake it
+  when we read the characters */
+   flags &= ~ENABLE_ECHO_INPUT;
+  if ((t->c_lflag & ISIG) && !(t->c_iflag & IGNBRK))
+   flags |= ENABLE_PROCESSED_INPUT;
+  break;
 }
-  else
-{
-  if (dwMode & ENABLE_VIR

[PATCH] Cygwin: Add console fix regarding Ctrl-Z etc. to release notes.

2021-02-18 Thread Takashi Yano via Cygwin-patches
---
 winsup/cygwin/release/3.2.0 | 5 +
 1 file changed, 5 insertions(+)

diff --git a/winsup/cygwin/release/3.2.0 b/winsup/cygwin/release/3.2.0
index d02d16863..d69ed446c 100644
--- a/winsup/cygwin/release/3.2.0
+++ b/winsup/cygwin/release/3.2.0
@@ -9,6 +9,11 @@ What's new:
   thrd_detach, thrd_equal, thrd_exit, thrd_join, thrd_sleep, thrd_yield,
   tss_create, tss_delete, tss_get, tss_set.
 
+- In cygwin console, new thread which handles special keys/signals such
+  as Ctrl-Z (VSUSP), Ctrl-\ (VQUIT), Ctrl-S (VSTOP), Ctrl-Q (VSTART) and
+  SIGWINCH has been intrudocued. There have been a long standing issue
+  that these keys/signals are handled only when app calls read() or
+  select(). Now, these work even if app does not call read() or select().
 
 What changed:
 -
-- 
2.30.0



[PATCH] Cygwin: pty: Reflect tty settings to pseudo console mode.

2021-02-18 Thread Takashi Yano via Cygwin-patches
- With this patch, tty setting such as echo, icanon, isig and onlcr
  are reflected to pseudo console mode.
---
 winsup/cygwin/fhandler_tty.cc | 27 +++
 1 file changed, 27 insertions(+)

diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc
index 5afede859..e4c35ea41 100644
--- a/winsup/cygwin/fhandler_tty.cc
+++ b/winsup/cygwin/fhandler_tty.cc
@@ -3261,6 +3261,33 @@ skip_create:
   if (get_ttyp ()->previous_output_code_page)
 SetConsoleOutputCP (get_ttyp ()->previous_output_code_page);
 
+  do
+{
+  termios &t = get_ttyp ()->ti;
+  DWORD mode;
+  /* Set input mode */
+  GetConsoleMode (hpConIn, &mode);
+  mode &= ~(ENABLE_ECHO_INPUT | ENABLE_LINE_INPUT | 
ENABLE_PROCESSED_INPUT);
+  if (t.c_lflag & ECHO)
+   mode |= ENABLE_ECHO_INPUT;
+  if (t.c_lflag & ICANON)
+   mode |= ENABLE_LINE_INPUT;
+  if (mode & ENABLE_ECHO_INPUT && !(mode & ENABLE_LINE_INPUT))
+   /* This is illegal, so turn off the echo here, and fake it
+  when we read the characters */
+   mode &= ~ENABLE_ECHO_INPUT;
+  if ((t.c_lflag & ISIG) && !(t.c_iflag & IGNBRK))
+   mode |= ENABLE_PROCESSED_INPUT;
+  SetConsoleMode (hpConIn, mode);
+  /* Set output mode */
+  GetConsoleMode (hpConOut, &mode);
+  mode &= ~DISABLE_NEWLINE_AUTO_RETURN;
+  if (!(t.c_oflag & OPOST) || !(t.c_oflag & ONLCR))
+   mode |= DISABLE_NEWLINE_AUTO_RETURN;
+  SetConsoleMode (hpConOut, mode);
+}
+  while (false);
+
   return true;
 
 cleanup_pcon_in:
-- 
2.30.0



[PATCH] Cygwin: pty: Make tty setting NOFLSH work.

2021-02-18 Thread Takashi Yano via Cygwin-patches
- With this patch, "stty noflsh" gets working in pty.
---
 winsup/cygwin/fhandler_termios.cc | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/winsup/cygwin/fhandler_termios.cc 
b/winsup/cygwin/fhandler_termios.cc
index e8daf946b..ae35fe894 100644
--- a/winsup/cygwin/fhandler_termios.cc
+++ b/winsup/cygwin/fhandler_termios.cc
@@ -332,7 +332,8 @@ fhandler_termios::line_edit (const char *rptr, size_t 
nread, termios& ti,
goto not_a_sig;
 
  termios_printf ("got interrupt %d, sending signal %d", c, sig);
- eat_readahead (-1);
+ if (!(ti.c_lflag & NOFLSH))
+   eat_readahead (-1);
  release_input_mutex_if_necessary ();
  tc ()->kill_pgrp (sig);
  acquire_input_mutex_if_necessary (INFINITE);
-- 
2.30.0



[PATCH 0/3] Fix fstat on FIFOs, part 2

2021-02-18 Thread Ken Brown via Cygwin-patches
The first patch fixes a bug, in which fstat on FIFOs sometimes used
pipe handles instead of file handles.

The second and third patches should improve the efficiency of fstat
and open on FIFOs.

Ken Brown (3):
  Cygwin: define fhandler_fifo::fstat
  Cygwin: fstat_helper: always use handle in call to get_file_attribute
  Cygwin: FIFO: temporarily keep a conv_handle in syscalls.cc:open

 winsup/cygwin/fhandler.h|  1 +
 winsup/cygwin/fhandler_disk_file.cc |  3 +--
 winsup/cygwin/fhandler_fifo.cc  | 23 +++
 winsup/cygwin/syscalls.cc   | 22 +++---
 4 files changed, 44 insertions(+), 5 deletions(-)

-- 
2.30.0



[PATCH 2/3] Cygwin: fstat_helper: always use handle in call to get_file_attribute

2021-02-18 Thread Ken Brown via Cygwin-patches
Previously, the call to get_file_attribute for FIFOs set the first
argument to NULL instead of the handle h returned by get_stat_handle,
thereby forcing the file to be opened for fetching the security
descriptor in get_file_sd().  This was done because h might have been
a pipe handle rather than a file handle, and its permissions would not
necessarily reflect those of the file.

That situation can no longer occur with the new fhandler_fifo::fstat
introduced in the previous commit.
---
 winsup/cygwin/fhandler_disk_file.cc | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/winsup/cygwin/fhandler_disk_file.cc 
b/winsup/cygwin/fhandler_disk_file.cc
index ef9171bbf..6170427b0 100644
--- a/winsup/cygwin/fhandler_disk_file.cc
+++ b/winsup/cygwin/fhandler_disk_file.cc
@@ -475,8 +475,7 @@ fhandler_base::fstat_helper (struct stat *buf)
   else if (pc.issocket ())
 buf->st_mode = S_IFSOCK;
 
-  if (!get_file_attribute (is_fs_special () && !pc.issocket () ? NULL : h, pc,
-  &buf->st_mode, &buf->st_uid, &buf->st_gid))
+  if (!get_file_attribute (h, pc, &buf->st_mode, &buf->st_uid, &buf->st_gid))
 {
   /* If read-only attribute is set, modify ntsec return value */
   if (::has_attribute (attributes, FILE_ATTRIBUTE_READONLY)
-- 
2.30.0



[PATCH 3/3] Cygwin: FIFO: temporarily keep a conv_handle in syscalls.cc:open

2021-02-18 Thread Ken Brown via Cygwin-patches
When a FIFO is opened, syscalls.cc:open always calls fstat on the
newly-created fhandler_fifo.  This results from a call to
device_access_denied.

To speed-up this fstat call, and therefore the open(2) call, use
PC_KEEP_HANDLE when the fhandler is created.  The resulting
conv_handle is retained until after the fstat call if the fhandler is
a FIFO; otherwise, it is closed immediately.
---
 winsup/cygwin/syscalls.cc | 22 +++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc
index 32a155a1c..460fe6801 100644
--- a/winsup/cygwin/syscalls.cc
+++ b/winsup/cygwin/syscalls.cc
@@ -1487,8 +1487,15 @@ open (const char *unix_path, int flags, ...)
  opt |= PC_CTTY;
}
 
+  /* If we're opening a FIFO, we will call device_access_denied
+below.  This leads to a call to fstat, which can use the
+path_conv handle. */
+  opt |= PC_KEEP_HANDLE;
   if (!(fh = build_fh_name (unix_path, opt, stat_suffixes)))
__leave;/* errno already set */
+  opt &= ~PC_KEEP_HANDLE;
+  if (!fh->isfifo ())
+   fh->pc.close_conv_handle ();
   if ((flags & O_NOFOLLOW) && fh->issymlink () && !(flags & O_PATH))
{
  set_errno (ELOOP);
@@ -1555,9 +1562,18 @@ open (const char *unix_path, int flags, ...)
  delete fh;
  fh = fh_file;
}
-  else if ((fh->is_fs_special () && fh->device_access_denied (flags))
-  || !fh->open_with_arch (flags, mode & 0))
-   __leave;/* errno already set */
+  else
+   {
+ if (fh->is_fs_special ())
+   {
+ if (fh->device_access_denied (flags))
+   __leave;/* errno already set */
+ else if (fh->isfifo ())
+   fh->pc.close_conv_handle ();
+   }
+ if (!fh->open_with_arch (flags, mode & 0))
+   __leave;/* errno already set */
+   }
   /* Move O_TMPFILEs to the bin to avoid blocking the parent dir. */
   if ((flags & O_TMPFILE) && !fh->pc.isremote ())
try_to_bin (fh->pc, fh->get_handle (), DELETE,
-- 
2.30.0



[PATCH 1/3] Cygwin: define fhandler_fifo::fstat

2021-02-18 Thread Ken Brown via Cygwin-patches
Previously fstat on a FIFO would call fhandler_base::fstat.

The latter is not appropriate if fhandler_fifo::open has already been
called (and O_PATH is not set), for the following reason.  If a FIFO
has been opened as a writer or duplexer, then it has an io_handle that
is a pipe handle rather than a file handle.  fhandler_base::fstat will
use this handle and potentially return incorrect results.  If the FIFO
has been opened as a reader, then it has no io_handle, and a call to
fhandler_base::fstat will lead to a call to fhandler_base::open.
Opening the fhandler a second time can change it in undesired ways;
for example, it can modify the flags and status_flags.

The new fhandler_fifo::fstat avoids these problems by creating an
fhandler_disk_file and calling its fstat method in case
fhandler_fifo::open has already been called and O_PATH is not set.
---
 winsup/cygwin/fhandler.h   |  1 +
 winsup/cygwin/fhandler_fifo.cc | 23 +++
 2 files changed, 24 insertions(+)

diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h
index e457e2785..78d9c7984 100644
--- a/winsup/cygwin/fhandler.h
+++ b/winsup/cygwin/fhandler.h
@@ -1510,6 +1510,7 @@ public:
   ssize_t __reg3 raw_write (const void *ptr, size_t ulen);
   void fixup_after_fork (HANDLE);
   void fixup_after_exec ();
+  int __reg2 fstat (struct stat *buf);
   int __reg2 fstatvfs (struct statvfs *buf);
   select_record *select_read (select_stuff *);
   select_record *select_write (select_stuff *);
diff --git a/winsup/cygwin/fhandler_fifo.cc b/winsup/cygwin/fhandler_fifo.cc
index 8b67037cb..365f14053 100644
--- a/winsup/cygwin/fhandler_fifo.cc
+++ b/winsup/cygwin/fhandler_fifo.cc
@@ -1494,6 +1494,29 @@ errout:
   len = (size_t) -1;
 }
 
+int __reg2
+fhandler_fifo::fstat (struct stat *buf)
+{
+  if (reader || writer || duplexer)
+{
+  /* fhandler_fifo::open has been called, and O_PATH is not set.
+We don't want to call fhandler_base::fstat.  In the writer
+and duplexer cases we have a handle, but it's a pipe handle
+rather than a file handle, so it's not suitable for stat.  In
+the reader case we don't have a handle, but
+fhandler_base::fstat would call fhandler_base::open, which
+would modify the flags and status_flags. */
+  fhandler_disk_file fh (pc);
+  fh.get_device () = FH_FS;
+  int res = fh.fstat (buf);
+  buf->st_dev = buf->st_rdev = dev ();
+  buf->st_mode = dev ().mode ();
+  buf->st_size = 0;
+  return res;
+}
+  return fhandler_base::fstat (buf);
+}
+
 int __reg2
 fhandler_fifo::fstatvfs (struct statvfs *sfs)
 {
-- 
2.30.0