[newlib-cygwin] Cygwin: select: Speed up select() call for pty, pipe and fifo.

2020-01-13 Thread Corinna Vinschen
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=a1c7e920845ab21185f18950be3d84f431de

commit a1c7e920845ab21185f18950be3d84f431de
Author: Takashi Yano 
Date:   Mon Jan 6 23:38:34 2020 +0900

Cygwin: select: Speed up select() call for pty, pipe and fifo.

- The slowing down issue of X11 forwarding using ssh -Y, reported
  in https://www.cygwin.com/ml/cygwin/2019-12/msg00295.html,
  is due to the change of select() code for pty in the commit
  915fcd0ae8d83546ce135131cd25bf6795d97966. cygthread::detach()
  takes at most about 10msec because Sleep() is used in the thread.
  For this issue, this patch uses cygwait() instead of Sleep() and
  introduces an event to abort the wait. For not only pty, but pipe
  and fifo also have the same problem potentially, so this patch
  applies same strategy to them as well.

Diff:
---
 winsup/cygwin/select.cc | 15 ---
 winsup/cygwin/select.h  |  1 +
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/winsup/cygwin/select.cc b/winsup/cygwin/select.cc
index e701442..b3aedf2 100644
--- a/winsup/cygwin/select.cc
+++ b/winsup/cygwin/select.cc
@@ -744,7 +744,7 @@ thread_pipe (void *arg)
  }
   if (!looping)
break;
-  Sleep (sleep_time >> 3);
+  cygwait (pi->bye, sleep_time >> 3);
   if (sleep_time < 80)
++sleep_time;
   if (pi->stop_thread)
@@ -763,6 +763,7 @@ start_thread_pipe (select_record *me, select_stuff *stuff)
 {
   pi->start = &stuff->start;
   pi->stop_thread = false;
+  pi->bye = CreateEvent (&sec_none_nih, TRUE, FALSE, NULL);
   pi->thread = new cygthread (thread_pipe, pi, "pipesel");
   me->h = *pi->thread;
   if (!me->h)
@@ -780,8 +781,10 @@ pipe_cleanup (select_record *, select_stuff *stuff)
   if (pi->thread)
 {
   pi->stop_thread = true;
+  SetEvent (pi->bye);
   pi->thread->detach ();
 }
+  CloseHandle (pi->bye);
   delete pi;
   stuff->device_specific_pipe = NULL;
 }
@@ -924,7 +927,7 @@ thread_fifo (void *arg)
  }
   if (!looping)
break;
-  Sleep (sleep_time >> 3);
+  cygwait (pi->bye, sleep_time >> 3);
   if (sleep_time < 80)
++sleep_time;
   if (pi->stop_thread)
@@ -943,6 +946,7 @@ start_thread_fifo (select_record *me, select_stuff *stuff)
 {
   pi->start = &stuff->start;
   pi->stop_thread = false;
+  pi->bye = CreateEvent (&sec_none_nih, TRUE, FALSE, NULL);
   pi->thread = new cygthread (thread_fifo, pi, "fifosel");
   me->h = *pi->thread;
   if (!me->h)
@@ -960,8 +964,10 @@ fifo_cleanup (select_record *, select_stuff *stuff)
   if (pi->thread)
 {
   pi->stop_thread = true;
+  SetEvent (pi->bye);
   pi->thread->detach ();
 }
+  CloseHandle (pi->bye);
   delete pi;
   stuff->device_specific_fifo = NULL;
 }
@@ -1279,7 +1285,7 @@ thread_pty_slave (void *arg)
  }
   if (!looping)
break;
-  Sleep (sleep_time >> 3);
+  cygwait (pi->bye, sleep_time >> 3);
   if (sleep_time < 80)
++sleep_time;
   if (pi->stop_thread)
@@ -1303,6 +1309,7 @@ pty_slave_startup (select_record *me, select_stuff *stuff)
 {
   pi->start = &stuff->start;
   pi->stop_thread = false;
+  pi->bye = CreateEvent (&sec_none_nih, TRUE, FALSE, NULL);
   pi->thread = new cygthread (thread_pty_slave, pi, "ptyssel");
   me->h = *pi->thread;
   if (!me->h)
@@ -1325,8 +1332,10 @@ pty_slave_cleanup (select_record *me, select_stuff 
*stuff)
   if (pi->thread)
 {
   pi->stop_thread = true;
+  SetEvent (pi->bye);
   pi->thread->detach ();
 }
+  CloseHandle (pi->bye);
   delete pi;
   stuff->device_specific_ptys = NULL;
 }
diff --git a/winsup/cygwin/select.h b/winsup/cygwin/select.h
index ae98c65..98fde3a 100644
--- a/winsup/cygwin/select.h
+++ b/winsup/cygwin/select.h
@@ -44,6 +44,7 @@ struct select_info
 {
   cygthread *thread;
   bool stop_thread;
+  HANDLE bye;
   select_record *start;
   select_info (): thread (NULL), stop_thread (0), start (NULL) {}
 };


[newlib-cygwin] Cygwin: console: Make suspending process work properly.

2020-01-13 Thread Corinna Vinschen
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=a6e87f589ae113cc3f947eca7db8c6d8c795e3c2

commit a6e87f589ae113cc3f947eca7db8c6d8c795e3c2
Author: Takashi Yano 
Date:   Sun Jan 5 22:25:55 2020 +0900

Cygwin: console: Make suspending process work properly.

- After commit f4b47827cf87f055687a0c52a3485d42b3e2b941, suspending
  process by Ctrl-Z does not work in console and results in hang up.
  This patch fixes the issue.

Diff:
---
 winsup/cygwin/fhandler_console.cc | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/winsup/cygwin/fhandler_console.cc 
b/winsup/cygwin/fhandler_console.cc
index b3095bb..b286c6c 100644
--- a/winsup/cygwin/fhandler_console.cc
+++ b/winsup/cygwin/fhandler_console.cc
@@ -850,7 +850,9 @@ fhandler_console::process_input_message (void)
   if (toadd)
{
  ssize_t ret;
+ release_input_mutex ();
  line_edit_status res = line_edit (toadd, nread, *ti, &ret);
+ acquire_input_mutex (INFINITE);
  if (res == line_edit_signalled)
{
  stat = input_signalled;


[newlib-cygwin] Cygwin: pty: Revise the code for setting code page of pseudo console.

2020-01-13 Thread Corinna Vinschen
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=b3e78186d107c3cf6cabad4fc18ee829f2b279f4

commit b3e78186d107c3cf6cabad4fc18ee829f2b279f4
Author: Takashi Yano 
Date:   Wed Jan 1 15:50:36 2020 +0900

Cygwin: pty: Revise the code for setting code page of pseudo console.

- Fix the problem which overrides the code page setting, reported
  in https://www.cygwin.com/ml/cygwin/2019-12/msg00292.html.

Diff:
---
 winsup/cygwin/fhandler_tty.cc | 52 +--
 winsup/cygwin/release/3.1.3   |  3 +++
 2 files changed, 28 insertions(+), 27 deletions(-)

diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc
index a235ea7..0837b63 100644
--- a/winsup/cygwin/fhandler_tty.cc
+++ b/winsup/cygwin/fhandler_tty.cc
@@ -2629,39 +2629,36 @@ fhandler_pty_slave::setup_locale (void)
   if (lcid == 0 || lcid == (LCID) -1)
 code_page = 20127; /* ASCII */
   else if (!GetLocaleInfo (lcid,
-  LOCALE_IDEFAULTANSICODEPAGE | LOCALE_RETURN_NUMBER,
+  LOCALE_IDEFAULTCODEPAGE | LOCALE_RETURN_NUMBER,
   (char *) &code_page, sizeof (code_page)))
 code_page = 20127; /* ASCII */
   SetConsoleCP (code_page);
   SetConsoleOutputCP (code_page);
 
-  if (get_ttyp ()->term_code_page == 0)
-{
-  /* Set terminal code page from locale */
-  /* This code is borrowed from mintty: charset.c */
-  get_ttyp ()->term_code_page = 20127; /* Default ASCII */
-  char charset_u[ENCODING_LEN + 1] = {0, };
-  for (int i=0; charset[i] && iterm_code_page = 20127; /* Default ASCII */
+  char charset_u[ENCODING_LEN + 1] = {0, };
+  for (int i=0; charset[i] && iterm_code_page = 28590 + iso;
+}
+  else if (sscanf (charset_u, "CP%u", &cp) == 1)
+get_ttyp ()->term_code_page = cp;
+  else
+for (int i=0; cs_names[i].cp; i++)
+  if (strcasecmp (charset_u, cs_names[i].name) == 0)
{
- if (iso && iso <= 16 && iso !=12)
-   get_ttyp ()->term_code_page = 28590 + iso;
+ get_ttyp ()->term_code_page = cs_names[i].cp;
+ break;
}
-  else if (sscanf (charset_u, "CP%u", &cp) == 1)
-   get_ttyp ()->term_code_page = cp;
-  else
-   for (int i=0; cs_names[i].cp; i++)
- if (strcasecmp (charset_u, cs_names[i].name) == 0)
-   {
- get_ttyp ()->term_code_page = cs_names[i].cp;
- break;
-   }
-}
 }
 
 void
@@ -2792,7 +2789,8 @@ fhandler_pty_slave::fixup_after_exec ()
 }
 
   /* Set locale */
-  setup_locale ();
+  if (get_ttyp ()->term_code_page == 0)
+setup_locale ();
 
 #if USE_API_HOOK
   /* Hook Console API */
diff --git a/winsup/cygwin/release/3.1.3 b/winsup/cygwin/release/3.1.3
index d698b44..0fcdcca 100644
--- a/winsup/cygwin/release/3.1.3
+++ b/winsup/cygwin/release/3.1.3
@@ -3,3 +3,6 @@ Bug Fixes
 
 - Define CPU_SETSIZE, as on Linux.
   Addresses: https://cygwin.com/ml/cygwin/2019-12/msg00248.html
+
+- Fix the problem which overrides the code page setting.
+  Addresses: https://www.cygwin.com/ml/cygwin/2019-12/msg00292.html


[newlib-cygwin] Cygwin: pty: Remove destructor for fhandler_pty_master class.

2020-01-13 Thread Corinna Vinschen
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=fd03749b9c255d6f78d71c65fb4f49d8f766a629

commit fd03749b9c255d6f78d71c65fb4f49d8f766a629
Author: Takashi Yano 
Date:   Wed Jan 1 15:49:41 2020 +0900

Cygwin: pty: Remove destructor for fhandler_pty_master class.

- The destructor for fhandler_pty_master class does not seem to be
  necessary anymore. Therefore, it has been removed.

Diff:
---
 winsup/cygwin/fhandler.h  | 1 -
 winsup/cygwin/fhandler_tty.cc | 9 -
 2 files changed, 10 deletions(-)

diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h
index 3954c37..4a71c16 100644
--- a/winsup/cygwin/fhandler.h
+++ b/winsup/cygwin/fhandler.h
@@ -2218,7 +2218,6 @@ public:
   HANDLE get_echo_handle () const { return echo_r; }
   /* Constructor */
   fhandler_pty_master (int);
-  ~fhandler_pty_master ();
 
   DWORD pty_master_thread ();
   DWORD pty_master_fwd_thread ();
diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc
index f10f0fc..a235ea7 100644
--- a/winsup/cygwin/fhandler_tty.cc
+++ b/winsup/cygwin/fhandler_tty.cc
@@ -2126,15 +2126,6 @@ fhandler_pty_master::fhandler_pty_master (int unit)
   set_name ("/dev/ptmx");
 }
 
-fhandler_pty_master::~fhandler_pty_master ()
-{
-  /* Without this wait, helper process for pseudo console
- sometimes remains running after the pty session is
- closed. The reason is not clear. */
-  if (to_master && from_master)
-Sleep (20);
-}
-
 int
 fhandler_pty_master::open (int flags, mode_t)
 {


[newlib-cygwin] Fixed crash on wine by adding NULL check after memchr

2020-01-13 Thread Corinna Vinschen
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=4ddf5903fd24feaa6f75ffb12f9cafdd266b386a

commit 4ddf5903fd24feaa6f75ffb12f9cafdd266b386a
Author: Arseniy Lartsev 
Date:   Tue Jan 7 16:34:39 2020 +0100

Fixed crash on wine by adding NULL check after memchr

This is not a joke, there are vendors out there who build software for 
cygwin
only. Besides, this NULL check is good to have anyway.

Diff:
---
 winsup/cygwin/path.cc | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/winsup/cygwin/path.cc b/winsup/cygwin/path.cc
index b5efd61..c8e73c6 100644
--- a/winsup/cygwin/path.cc
+++ b/winsup/cygwin/path.cc
@@ -4307,6 +4307,8 @@ find_fast_cwd_pointer ()
   const uint8_t *use_cwd = rcall + 5 + offset;
   /* Find first `push %edi' instruction. */
   const uint8_t *pushedi = (const uint8_t *) memchr (use_cwd, 0x57, 32);
+  if (!pushedi)
+return NULL;
   /* ...which should be followed by `mov crit-sect-addr,%edi' then
  `push %edi', or by just a single `push crit-sect-addr'. */
   const uint8_t *movedi = pushedi + 1;


[newlib-cygwin] Cygwin: Add missing Linux #define of CPU_SETSIZE

2020-01-13 Thread Corinna Vinschen
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=7b6414d459bb66affe077a062b88ca1e1e392fc4

commit 7b6414d459bb66affe077a062b88ca1e1e392fc4
Author: Mark Geisert 
Date:   Sun Dec 22 22:45:54 2019 -0800

Cygwin: Add missing Linux #define of CPU_SETSIZE

Though our implementation of cpu sets doesn't need it, software from
Linux environments expects this definition to be present.  It's
documented on the Linux CPU_SET(3) man page but was left out due to
oversight.

Addresses https://cygwin.com/ml/cygwin/2019-12/msg00248.html

Diff:
---
 winsup/cygwin/include/sys/cpuset.h | 1 +
 winsup/cygwin/release/3.1.3| 5 +
 2 files changed, 6 insertions(+)

diff --git a/winsup/cygwin/include/sys/cpuset.h 
b/winsup/cygwin/include/sys/cpuset.h
index 1adf48d..5725651 100644
--- a/winsup/cygwin/include/sys/cpuset.h
+++ b/winsup/cygwin/include/sys/cpuset.h
@@ -89,6 +89,7 @@ int __sched_getaffinity_sys (pid_t, size_t, cpu_set_t *);
 #define CPU_XOR(dst, src1, src2)  CPU_XOR_S(sizeof (cpu_set_t), dst, src1, 
src2)
 #define CPU_EQUAL(src1, src2) CPU_EQUAL_S(sizeof (cpu_set_t), src1, src2)
 
+#define CPU_SETSIZE   __CPU_SETSIZE
 #endif /* __GNU_VISIBLE */
 
 #ifdef __cplusplus
diff --git a/winsup/cygwin/release/3.1.3 b/winsup/cygwin/release/3.1.3
new file mode 100644
index 000..d698b44
--- /dev/null
+++ b/winsup/cygwin/release/3.1.3
@@ -0,0 +1,5 @@
+Bug Fixes
+-
+
+- Define CPU_SETSIZE, as on Linux.
+  Addresses: https://cygwin.com/ml/cygwin/2019-12/msg00248.html