forked from git-for-windows/MSYS2-packages
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This corresponds to msys2/msys2-runtime#205. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
- Loading branch information
Showing
7 changed files
with
324 additions
and
4 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
msys2-runtime/0055-Cygwin-console-Fix-exit-code-for-non-cygwin-process.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
From 9fd76414684cfc137252b4a63a015dfc29e79fdb Mon Sep 17 00:00:00 2001 | ||
From: Takashi Yano <takashi.yano@nifty.ne.jp> | ||
Date: Fri, 2 Feb 2024 13:59:19 +0900 | ||
Subject: [PATCH 55/N] Cygwin: console: Fix exit code for non-cygwin process. | ||
|
||
If non-cygwin process is executed in console, the exit code is not | ||
set correctly. This is because the stub process for non-cygwin app | ||
crashes in fhandler_console::set_disable_master_thread() due to NULL | ||
pointer dereference. This bug was introduced by the commit: | ||
3721a756b0d8 ("Cygwin: console: Make the console accessible from | ||
other terminals."), that the pointer cons is accessed before fixing | ||
when it is NULL. This patch fixes the issue. | ||
|
||
Backported-from: aa73e11524 (Cygwin: console: Fix exit code for non-cygwin process., 2024-02-02) | ||
Fixes: 3721a756b0d8 ("Cygwin: console: Make the console accessible from other terminals.") | ||
Reported-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> | ||
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp> | ||
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> | ||
--- | ||
winsup/cygwin/fhandler/console.cc | 4 ++-- | ||
1 file changed, 2 insertions(+), 2 deletions(-) | ||
|
||
diff --git a/winsup/cygwin/fhandler/console.cc b/winsup/cygwin/fhandler/console.cc | ||
index c9b27c9..6c485f9 100644 | ||
--- a/winsup/cygwin/fhandler/console.cc | ||
+++ b/winsup/cygwin/fhandler/console.cc | ||
@@ -4328,8 +4328,6 @@ fhandler_console::need_console_handler () | ||
void | ||
fhandler_console::set_disable_master_thread (bool x, fhandler_console *cons) | ||
{ | ||
- if (con.disable_master_thread == x) | ||
- return; | ||
if (cons == NULL) | ||
{ | ||
if (cygheap->ctty && cygheap->ctty->get_major () == DEV_CONS_MAJOR) | ||
@@ -4337,6 +4335,8 @@ fhandler_console::set_disable_master_thread (bool x, fhandler_console *cons) | ||
else | ||
return; | ||
} | ||
+ if (con.disable_master_thread == x) | ||
+ return; | ||
cons->acquire_input_mutex (mutex_timeout); | ||
con.disable_master_thread = x; | ||
cons->release_input_mutex (); |
45 changes: 45 additions & 0 deletions
45
msys2-runtime/0056-Cygwin-console-Avoid-slipping-past-disable_master_th.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
From fb060f79f664189f3b61a9d361dafbedf79e2441 Mon Sep 17 00:00:00 2001 | ||
From: Takashi Yano <takashi.yano@nifty.ne.jp> | ||
Date: Sat, 3 Feb 2024 00:54:23 +0900 | ||
Subject: [PATCH 56/N] Cygwin: console: Avoid slipping past | ||
disable_master_thread check. | ||
|
||
If disable_master_thread flag is set between the code checking that | ||
flag not be set and the code acquiring input_mutex, input record is | ||
processed once after setting disable_master_thread flag. This patch | ||
prevents that. | ||
|
||
Backported-from: 9bcfd06045 (Cygwin: console: Avoid slipping past disable_master_thread check., 2024-02-03) | ||
Fixes: d4aacd50e6cf ("Cygwin: console: Add missing input_mutex guard.") | ||
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp> | ||
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> | ||
--- | ||
winsup/cygwin/fhandler/console.cc | 8 ++++++-- | ||
1 file changed, 6 insertions(+), 2 deletions(-) | ||
|
||
diff --git a/winsup/cygwin/fhandler/console.cc b/winsup/cygwin/fhandler/console.cc | ||
index 6c485f9..b415a0a 100644 | ||
--- a/winsup/cygwin/fhandler/console.cc | ||
+++ b/winsup/cygwin/fhandler/console.cc | ||
@@ -361,6 +361,12 @@ fhandler_console::cons_master_thread (handle_set_t *p, tty *ttyp) | ||
} | ||
|
||
WaitForSingleObject (p->input_mutex, mutex_timeout); | ||
+ /* Ensure accessing input recored is not disabled. */ | ||
+ if (con.disable_master_thread) | ||
+ { | ||
+ ReleaseMutex (p->input_mutex); | ||
+ continue; | ||
+ } | ||
total_read = 0; | ||
switch (cygwait (p->input_handle, (DWORD) 0)) | ||
{ | ||
@@ -4335,8 +4341,6 @@ fhandler_console::set_disable_master_thread (bool x, fhandler_console *cons) | ||
else | ||
return; | ||
} | ||
- if (con.disable_master_thread == x) | ||
- return; | ||
cons->acquire_input_mutex (mutex_timeout); | ||
con.disable_master_thread = x; | ||
cons->release_input_mutex (); |
32 changes: 32 additions & 0 deletions
32
msys2-runtime/0057-Cygwin-pty-Fix-handle-leak-in-master-process.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
From f769444ad2f17709dfcb9c0067aa3b39b525abee Mon Sep 17 00:00:00 2001 | ||
From: Takashi Yano <takashi.yano@nifty.ne.jp> | ||
Date: Tue, 13 Feb 2024 11:17:46 +0900 | ||
Subject: [PATCH 57/N] Cygwin: pty: Fix handle leak in master process. | ||
|
||
If non-cygwin process is started in pty, closing from_master_nat | ||
pipe handle was missing in fhandler_pty_slave::input_transfer(). | ||
This occured because the handle was duplicated but not closed. | ||
|
||
https://github.com/msys2/msys2-runtime/issues/198 | ||
|
||
Backported-from: a6ac7b4138 (Cygwin: pty: Fix handle leak in master process., 2024-02-13) | ||
Fixes: 29431fcb5b14 ("Cygwin: pty: Inherit typeahead data between two input pipes.") | ||
Reported-by: Hakkin Lain | ||
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp> | ||
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> | ||
--- | ||
winsup/cygwin/fhandler/pty.cc | 1 + | ||
1 file changed, 1 insertion(+) | ||
|
||
diff --git a/winsup/cygwin/fhandler/pty.cc b/winsup/cygwin/fhandler/pty.cc | ||
index dbeffc9..9d1a119 100644 | ||
--- a/winsup/cygwin/fhandler/pty.cc | ||
+++ b/winsup/cygwin/fhandler/pty.cc | ||
@@ -4066,6 +4066,7 @@ fhandler_pty_slave::transfer_input (tty::xfer_dir dir, HANDLE from, tty *ttyp, | ||
transfered = true;; | ||
} | ||
} | ||
+ CloseHandle (to); | ||
|
||
/* Fix input_available_event which indicates availability in cyg pipe. */ | ||
if (dir == tty::to_nat) /* all data is transfered to nat pipe, |
64 changes: 64 additions & 0 deletions
64
msys2-runtime/0058-Cygwin-pty-Fix-potential-handle-leak-regarding-CallN.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
From 85e89bbeff42c0195ec1f4cbbff063aeac145ad8 Mon Sep 17 00:00:00 2001 | ||
From: Takashi Yano <takashi.yano@nifty.ne.jp> | ||
Date: Tue, 13 Feb 2024 11:36:05 +0900 | ||
Subject: [PATCH 58/N] Cygwin: pty: Fix potential handle leak regarding | ||
CallNamedPipe(). | ||
|
||
In pty master_thread, 6 handles are duplicated when CallNamedPipe() | ||
requests that. Though some of them are not used so should be closed, | ||
they were not. This causes handle leak potentially. | ||
|
||
Backported-from: 73cd80c976 (Cygwin: pty: Fix potential handle leak regarding CallNamedPipe()., 2024-02-13) | ||
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp> | ||
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> | ||
--- | ||
winsup/cygwin/fhandler/pty.cc | 20 ++++++++++++++++++-- | ||
1 file changed, 18 insertions(+), 2 deletions(-) | ||
|
||
diff --git a/winsup/cygwin/fhandler/pty.cc b/winsup/cygwin/fhandler/pty.cc | ||
index 9d1a119..17b7b32 100644 | ||
--- a/winsup/cygwin/fhandler/pty.cc | ||
+++ b/winsup/cygwin/fhandler/pty.cc | ||
@@ -940,6 +940,8 @@ fhandler_pty_slave::open (int flags, mode_t) | ||
errmsg = "can't call master, %E"; | ||
goto err; | ||
} | ||
+ CloseHandle (repl.to_slave_nat); /* not used. */ | ||
+ CloseHandle (repl.to_slave); /* not used. */ | ||
from_master_nat_local = repl.from_master_nat; | ||
from_master_local = repl.from_master; | ||
to_master_nat_local = repl.to_master_nat; | ||
@@ -1218,6 +1220,10 @@ fhandler_pty_slave::reset_switch_to_nat_pipe (void) | ||
if (!CallNamedPipe (pipe, &req, sizeof req, | ||
&repl, sizeof repl, &len, 500)) | ||
return; /* What can we do? */ | ||
+ CloseHandle (repl.from_master); /* not used. */ | ||
+ CloseHandle (repl.to_master); /* not used. */ | ||
+ CloseHandle (repl.to_slave_nat); /* not used. */ | ||
+ CloseHandle (repl.to_slave); /* not used. */ | ||
CloseHandle (get_handle_nat ()); | ||
set_handle_nat (repl.from_master_nat); | ||
CloseHandle (get_output_handle_nat ()); | ||
@@ -3932,10 +3938,20 @@ fhandler_pty_slave::transfer_input (tty::xfer_dir dir, HANDLE from, tty *ttyp, | ||
if (!CallNamedPipe (pipe, &req, sizeof req, | ||
&repl, sizeof repl, &len, 500)) | ||
return; /* What can we do? */ | ||
+ CloseHandle (repl.from_master_nat); /* not used. */ | ||
+ CloseHandle (repl.from_master); /* not used. */ | ||
+ CloseHandle (repl.to_master_nat); /* not used. */ | ||
+ CloseHandle (repl.to_master); /* not used. */ | ||
if (dir == tty::to_nat) | ||
- to = repl.to_slave_nat; | ||
+ { | ||
+ CloseHandle (repl.to_slave); /* not used. */ | ||
+ to = repl.to_slave_nat; | ||
+ } | ||
else | ||
- to = repl.to_slave; | ||
+ { | ||
+ CloseHandle (repl.to_slave_nat); /* not used. */ | ||
+ to = repl.to_slave; | ||
+ } | ||
} | ||
|
||
UINT cp_from = 0, cp_to = 0; |
74 changes: 74 additions & 0 deletions
74
msys2-runtime/0059-Cygwin-console-Make-VMIN-and-VTIME-work.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
From b3295b576d7662daf6e2c14761f50c5e05a21209 Mon Sep 17 00:00:00 2001 | ||
From: Takashi Yano <takashi.yano@nifty.ne.jp> | ||
Date: Tue, 13 Feb 2024 11:42:42 +0900 | ||
Subject: [PATCH 59/N] Cygwin: console: Make VMIN and VTIME work. | ||
|
||
Previously, VMIN and VTIME did not work at all. This patch fixes that. | ||
|
||
Backported-from: 73cd80c976 (Cygwin: pty: Fix potential handle leak regarding CallNamedPipe()., 2024-02-13) | ||
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp> | ||
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> | ||
--- | ||
winsup/cygwin/fhandler/console.cc | 26 ++++++++++++++++++-------- | ||
1 file changed, 18 insertions(+), 8 deletions(-) | ||
|
||
diff --git a/winsup/cygwin/fhandler/console.cc b/winsup/cygwin/fhandler/console.cc | ||
index b415a0a..f9a6946 100644 | ||
--- a/winsup/cygwin/fhandler/console.cc | ||
+++ b/winsup/cygwin/fhandler/console.cc | ||
@@ -1011,10 +1011,14 @@ fhandler_console::read (void *pv, size_t& buflen) | ||
|
||
push_process_state process_state (PID_TTYIN); | ||
|
||
- int copied_chars = 0; | ||
+ size_t copied_chars = 0; | ||
|
||
- DWORD timeout = is_nonblocking () ? 0 : INFINITE; | ||
+ DWORD timeout = is_nonblocking () ? 0 : | ||
+ (get_ttyp ()->ti.c_lflag & ICANON ? INFINITE : | ||
+ (get_ttyp ()->ti.c_cc[VMIN] == 0 ? 0 : | ||
+ (get_ttyp ()->ti.c_cc[VTIME]*100 ? : INFINITE))); | ||
|
||
+read_more: | ||
while (!input_ready && !get_cons_readahead_valid ()) | ||
{ | ||
int bgres; | ||
@@ -1037,6 +1041,11 @@ wait_retry: | ||
pthread::static_cancel_self (); | ||
/*NOTREACHED*/ | ||
case WAIT_TIMEOUT: | ||
+ if (copied_chars) | ||
+ { | ||
+ buflen = copied_chars; | ||
+ return; | ||
+ } | ||
set_sig_errno (EAGAIN); | ||
buflen = (size_t) -1; | ||
return; | ||
@@ -1082,19 +1091,20 @@ wait_retry: | ||
} | ||
|
||
/* Check console read-ahead buffer filled from terminal requests */ | ||
- while (con.cons_rapoi && *con.cons_rapoi && buflen) | ||
- { | ||
- buf[copied_chars++] = *con.cons_rapoi++; | ||
- buflen --; | ||
- } | ||
+ while (con.cons_rapoi && *con.cons_rapoi && buflen > copied_chars) | ||
+ buf[copied_chars++] = *con.cons_rapoi++; | ||
|
||
copied_chars += | ||
- get_readahead_into_buffer (buf + copied_chars, buflen); | ||
+ get_readahead_into_buffer (buf + copied_chars, buflen - copied_chars); | ||
|
||
if (!con_ra.ralen) | ||
input_ready = false; | ||
release_input_mutex (); | ||
|
||
+ if (buflen > copied_chars && !(get_ttyp ()->ti.c_lflag & ICANON) | ||
+ && copied_chars < get_ttyp ()->ti.c_cc[VMIN]) | ||
+ goto read_more; | ||
+ | ||
#undef buf | ||
|
||
buflen = copied_chars; |
43 changes: 43 additions & 0 deletions
43
msys2-runtime/0060-Cygwin-pipe-Give-up-to-use-query_hdl-for-non-cygwin-.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
From 436c8752437af86d24712a5a95b78fecde3ad35b Mon Sep 17 00:00:00 2001 | ||
From: Takashi Yano <takashi.yano@nifty.ne.jp> | ||
Date: Sun, 3 Mar 2024 14:09:07 +0900 | ||
Subject: [PATCH 60/N] Cygwin: pipe: Give up to use query_hdl for non-cygwin | ||
apps. | ||
|
||
Non-cygwin app may call ReadFile() which makes NtQueryObject() for | ||
ObjectNameInformation block in fhandler_pipe::get_query_hdl_per_process. | ||
Therefore, stop to try to get query_hdl for non-cygwin apps. | ||
|
||
Addresses: https://github.com/msys2/msys2-runtime/issues/202 | ||
|
||
Backported-from: https://inbox.sourceware.org/cygwin-patches/20240303050915.2024-1-takashi.yano@nifty.ne.jp/ | ||
Fixes: b531d6b06eeb ("Cygwin: pipe: Introduce temporary query_hdl.") | ||
Reported-by: Alisa Sireneva, Johannes Schindelin <Johannes.Schindelin@gmx.de> | ||
Reviewed-by: | ||
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp> | ||
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> | ||
--- | ||
winsup/cygwin/fhandler/pipe.cc | 10 ++++++++++ | ||
1 file changed, 10 insertions(+) | ||
|
||
diff --git a/winsup/cygwin/fhandler/pipe.cc b/winsup/cygwin/fhandler/pipe.cc | ||
index 283319c..9319a57 100644 | ||
--- a/winsup/cygwin/fhandler/pipe.cc | ||
+++ b/winsup/cygwin/fhandler/pipe.cc | ||
@@ -1251,6 +1251,16 @@ fhandler_pipe::get_query_hdl_per_process (WCHAR *name, | ||
|
||
for (LONG i = (LONG) n_process - 1; i >= 0; i--) | ||
{ | ||
+ /* Non-cygwin app may call ReadFile() which makes NtQueryObject() | ||
+ for ObjectNameInformation block. Therefore, stop to try to get | ||
+ query_hdl for non-cygwin apps. */ | ||
+ pid_t cygpid; | ||
+ if (!(cygpid = cygwin_pid (proc_pids[i]))) | ||
+ continue; | ||
+ pinfo p (cygpid); | ||
+ if (p && ISSTATE (p, PID_NOTCYGWIN)) | ||
+ continue; | ||
+ | ||
HANDLE proc = OpenProcess (PROCESS_DUP_HANDLE | ||
| PROCESS_QUERY_INFORMATION, | ||
0, proc_pids[i]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters