Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions msys2-runtime/0056-dumper-allow-compiling-with-binutils-2.47.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
From 154c310bfa2d19e1e1547e866bb624817b8ecf4d Mon Sep 17 00:00:00 2001
From: Johannes Schindelin <johannes.schindelin@gmx.de>
Date: Tue, 28 Jul 2026 10:48:45 +0200
Subject: [PATCH 56/N] dumper: allow compiling with binutils 2.47

In the latest version, binutils' BFD no longer declares a `bfd_boolean`,
and the `bfd_record_phdr()` function accepts plain `bool` parameters
instead.

Let's accommodate for that to avoid these build failures:

.../winsup/utils/dumper.cc: In member function 'int dumper::prepare_core_dump()':
.../winsup/utils/dumper.cc:830:7: error: 'bfd_boolean' was not declared in this scope; did you mean 'boolean'?
830 | bfd_boolean filehdr = 0;
| ^~~~~~~~~~~
| boolean
.../winsup/utils/dumper.cc:831:18: error: expected ';' before 'phdrs'
831 | bfd_boolean phdrs = 0;
| ^~~~~~
| ;
[...]

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
winsup/utils/dumper.cc | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/winsup/utils/dumper.cc b/winsup/utils/dumper.cc
index 994f9b6..ac261d0 100644
--- a/winsup/utils/dumper.cc
+++ b/winsup/utils/dumper.cc
@@ -827,14 +827,14 @@ dumper::prepare_core_dump ()
p->section = new_section;
int section_count = 1;

- bfd_boolean filehdr = 0;
- bfd_boolean phdrs = 0;
+ bool filehdr = false;
+ bool phdrs = false;

bfd_vma at = 0;
- bfd_boolean valid_at = 0;
+ bool valid_at = false;

flagword flags = 0;
- bfd_boolean valid_flags = 1;
+ bool valid_flags = true;

if (p->type == pr_ent_memory)
{
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
From 8fbd9808447ee78ed485deead9b79cd1e40c07b7 Mon Sep 17 00:00:00 2001
From: Takashi Yano <takashi.yano@nifty.ne.jp>
Date: Fri, 17 Jul 2026 10:48:11 +0900
Subject: [PATCH 57/N] Cygwin: open: Unlock fdtab before open_with_arch()

Since the commit 31bf91f867c5, opening fifo causes a deadlock. This
is because, open_with_arch() for fifo can be blocked until the other
side of the fifo is opened. The commit 31bf91f867c5 moves the creating
cygheap_fdnew before open_with_arch() to address the issue:
https://cygwin.com/pipermail/cygwin/2026-May/259664.html
However, cygheap_fdnew locks fdtab, so open() for the other side of
fifo cannot create cygheap_fdnew until fdtab is unlocked. This is
the cause of the deadlock.

With this patch, fdtab is unlocked before open_with_arch(), but marked
as used using tentative fhandler. The summary of open() is as follows.
1) Lock fdtab.
2) Create new fd.
3) Mark fd as used using tentative fhandler.
4) Unlock fdtab.
5) Call open_with_arch().
6) Set final fhandler to fd.

The important point is that create fd before open_with_arch() to
address https://cygwin.com/pipermail/cygwin/2026-May/259664.html,
but unlock fdtab before open_with_arch() to address
https://cygwin.com/pipermail/cygwin/2026-July/259884.html.

Fixes: 31bf91f867c5 ("Cygwin: Ensure unused fd available for open()")
Addresses: https://cygwin.com/pipermail/cygwin/2026-July/259884.html
Reported-by: kikairoya <kikairoya@gmail.com>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
Reviewed-by: Mark Geisert <mark@maxrnd.com>
(cherry picked from commit 524d75ff73986b263161665af771cc90e55b5e01)
---
winsup/cygwin/syscalls.cc | 20 +++++++++++++++++---
1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc
index 3ad2039..f04b7d3 100644
--- a/winsup/cygwin/syscalls.cc
+++ b/winsup/cygwin/syscalls.cc
@@ -1451,6 +1451,7 @@ extern "C" int
open (const char *unix_path, int flags, ...)
{
int res = -1;
+ int fd = -1;
va_list ap;
mode_t mode = 0;
fhandler_base *fh = NULL;
@@ -1550,9 +1551,12 @@ open (const char *unix_path, int flags, ...)
/* Reserve an fdtable entry here, before calling open_with_arch() below.
Otherwise there's a tiny chance of hitting OPEN_MAX further on which
could create a new file without any way for Cygwin to refer to it. */
- cygheap_fdnew fd;
+ cygheap->fdtab.lock();
+ fd = cygheap->fdtab.find_unused_handle ();
if (fd < 0)
- __leave; /* errno already set */
+ __leave; /* errno already set */
+ cygheap->fdtab[fd] = fh; /* tentative setting to mark as used */
+ cygheap->fdtab.unlock();

if (fh->dev () == FH_PROCESSFD && fh->pc.follow_fd_symlink ())
{
@@ -1580,13 +1584,23 @@ open (const char *unix_path, int flags, ...)
try_to_bin (fh->pc, fh->get_handle (), DELETE,
FILE_OPEN_FOR_BACKUP_INTENT);

- fd = fh;
+ cygheap->fdtab.lock ();
+ cygheap->fdtab[fd] = fh;
+ fh->inc_refcnt ();
+ cygheap->fdtab.unlock ();
+
if (fd <= 2)
set_std_handle (fd);
res = fd;
}
__except (EFAULT) {}
__endtry
+ if (res < 0 && fd >= 0)
+ {
+ cygheap->fdtab.lock ();
+ cygheap->fdtab[fd] = NULL; /* Mark as unused */
+ cygheap->fdtab.unlock ();
+ }
if (res < 0 && fh)
delete fh;
syscall_printf ("%R = open(%s, %y)", res, unix_path, flags);
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
From da84778cbc92590c1996c02c68c5a3d3c49e00af Mon Sep 17 00:00:00 2001
From: Takashi Yano <takashi.yano@nifty.ne.jp>
Date: Mon, 3 Aug 2026 10:41:14 +0900
Subject: [PATCH 58/N] Cygwin: console: Fix regression in console input

The commit fac73911f5a0 ("Cygwin: console: Fix typeahead input for
bash") introduced a bug where select() consumes some input chars in
canonical mode, preventing read() from reading them. This is due to
discarding input events when process_input_message() does not return
`input_ok` even if it is called from select().
The basic idea of that commit was making process_input_message()
not to store processed chars into readahead buffer. This was not
correct because the key input events were processed twice, once by
select() and again by read(). Thus even if that commit worked as
intended, the side effect such as input echo would be applied twice.

With this patch, process_input_message() handles only the minimum
necessary of input events in both cases, those processed by select()
and those processed by read(). To achieve this behaviour, the function
returns without processing when `input_ready` is already satisfied,
or after it has processed the specified number of chars.

Addresses: https://cygwin.com/pipermail/cygwin/2026-August/259915.html
Reported-by: Steven Doerfler <sgd-cygwinlist@lugaru.com>
Fixes: fac73911f5a0 ("Cygwin: console: Fix typeahead input for bash")
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
Revewied-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
(cherry picked from commit 9807479c90e37913900569d3a8f3b10247bf7860)
---
winsup/cygwin/fhandler/console.cc | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/winsup/cygwin/fhandler/console.cc b/winsup/cygwin/fhandler/console.cc
index 3de1bca..857485c 100644
--- a/winsup/cygwin/fhandler/console.cc
+++ b/winsup/cygwin/fhandler/console.cc
@@ -460,7 +460,7 @@ fhandler_console::cons_master_thread (handle_set_t *p, tty *ttyp)
}

WaitForSingleObject (p->input_mutex, mutex_timeout);
- /* Ensure accessing input recored is not disabled. */
+ /* Ensure accessing input record is not disabled. */
if (con.disable_master_thread)
{
ReleaseMutex (p->input_mutex);
@@ -1278,7 +1278,6 @@ fhandler_console::input_states
fhandler_console::process_input_message (size_t len)
{
char tmp[60];
- size_t num_chars = 0;

if (!shared_console_info[unit])
return input_error;
@@ -1301,6 +1300,13 @@ fhandler_console::process_input_message (size_t len)
return input_error;
}

+ /* len == 0 if called from select.cc:peek_console() */
+ /* This code is reached only when being passed the input_ready check,
+ however, the check was done outside input_mutex. Therefore, another
+ thread may set input_ready after the check. Check it again here. */
+ if (input_ready && (len == 0 || (get_ttyp ()->ti.c_lflag & ICANON)))
+ return input_ok;
+
for (i = 0; i < total_read; i ++)
{
DWORD nread = 1;
@@ -1666,7 +1672,6 @@ fhandler_console::process_input_message (size_t len)
}

num_input_events_processed = i + 1;
- num_chars += nread;
if (toadd)
{
ssize_t ret;
@@ -1685,21 +1690,17 @@ fhandler_console::process_input_message (size_t len)
}
}
/* len == 0 if called from select.cc:peek_console() */
- if (len && num_chars >= len)
+ if (input_ready && (len == 0 || con_ra.ralen >= len))
goto out;
}
out:
- if (len == 0)
- /* If len == 0, cancel reading from console input buffer.
- Clear readahead buffer. */
- eat_readahead (-1);
- /* Discard processed recored. */
+ /* Discard processed record. */
DWORD discard_len = min (total_read, i + 1);
/* If input is signalled, do not discard input here because
discard_key_events() is already called from line_edit(). */
if (stat == input_signalled)
discard_len = 0;
- if (discard_len && (len || stat != input_ok))
+ if (discard_len)
discard_key_events (discard_len);
return stat;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
From c892dfe93ec1f5a82d299efca8c0297ff7ade794 Mon Sep 17 00:00:00 2001
From: Takashi Yano <takashi.yano@nifty.ne.jp>
Date: Thu, 3 Jul 2025 09:06:22 +0900
Subject: [PATCH 59/N] Cygwin: console: Set console mode only if
std{in,out,err} is console

Currently, when cygwin app is launched, the console input mode is
set to tty::cygwin, even if the stdin is not a console. However,
it is not necessary because the cygwin app does not use stdin.
This also applies to stdout and stderr.

With this patch, the console mode is set only when std{in,out,err}
is a console for the cygwin app for better coexistence with non-
cygwin apps.

This is a prerequisite for the experimental backport of Takashi Yano's
v15 console-mode patch to msys2-3.6.10. The release branch's later,
already-applied suspension-before-mode ordering is preserved.

(cherry picked from commit bbd3710fc83451426e3a58e5032437ca535fa444)
Assisted-by: GPT-6
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
winsup/cygwin/dtable.cc | 6 +-----
winsup/cygwin/fhandler/console.cc | 36 ++++++++++++++++++++++---------
2 files changed, 27 insertions(+), 15 deletions(-)

diff --git a/winsup/cygwin/dtable.cc b/winsup/cygwin/dtable.cc
index 6ccc19a..e4cd3bd 100644
--- a/winsup/cygwin/dtable.cc
+++ b/winsup/cygwin/dtable.cc
@@ -326,11 +326,7 @@ dtable::init_std_file_from_handle (int fd, HANDLE handle)
if (CTTY_IS_VALID (myself->ctty))
dev.parse (myself->ctty);
else
- {
- dev.parse (FH_CONSOLE);
- CloseHandle (handle);
- handle = INVALID_HANDLE_VALUE;
- }
+ dev.parse (FH_CONSOLE);
}
else if (GetCommState (handle, &dcb))
/* FIXME: Not right - assumes ttyS0 */
diff --git a/winsup/cygwin/fhandler/console.cc b/winsup/cygwin/fhandler/console.cc
index 857485c..e19e124 100644
--- a/winsup/cygwin/fhandler/console.cc
+++ b/winsup/cygwin/fhandler/console.cc
@@ -953,8 +953,10 @@ fhandler_console::cleanup_for_non_cygwin_app (handle_set_t *p)
/* conmode can be tty::restore when non-cygwin app is
exec'ed from login shell. */
tty::cons_mode conmode = cons_mode_on_close (p);
- set_output_mode (conmode, ti, p);
- set_input_mode (conmode, ti, p);
+ if (con.curr_output_mode != conmode)
+ set_output_mode (conmode, ti, p);
+ if (con.curr_input_mode != conmode)
+ set_input_mode (conmode, ti, p);
}

/* Return the tty structure associated with a given tty number. If the
@@ -1947,13 +1949,24 @@ fhandler_console::open (int flags, mode_t)
setenv ("TERM", "cygwin", 1);
}

- if (con.curr_input_mode != tty::cygwin)
+ HANDLE h_in = GetStdHandle (STD_INPUT_HANDLE);
+ HANDLE h_out = GetStdHandle (STD_OUTPUT_HANDLE);
+ HANDLE h_err = GetStdHandle (STD_ERROR_HANDLE);
+
+ DWORD dummy;
+ bool in_is_console = GetConsoleMode (h_in, &dummy);
+ bool out_is_console =
+ GetConsoleMode (h_out, &dummy) || GetConsoleMode (h_err, &dummy);
+ if (in_is_console)
+ CloseHandle (h_in);
+
+ if (in_is_console && con.curr_input_mode != tty::cygwin)
{
prev_input_mode_backup = con.prev_input_mode;
GetConsoleMode (get_handle (), &con.prev_input_mode);
set_input_mode (tty::cygwin, &get_ttyp ()->ti, &handle_set);
}
- if (con.curr_output_mode != tty::cygwin)
+ if (out_is_console && con.curr_output_mode != tty::cygwin)
{
prev_output_mode_backup = con.prev_output_mode;
GetConsoleMode (get_output_handle (), &con.prev_output_mode);
@@ -2069,13 +2082,14 @@ fhandler_console::close (int flag)

acquire_output_mutex (mutex_timeout);

- if (shared_console_info[unit] && con.curr_input_mode != tty::restore
- && (dev_t) myself->ctty == get_device ()
+ if (shared_console_info[unit] && (dev_t) myself->ctty == get_device ()
&& cons_mode_on_close (&handle_set) == tty::restore)
{
set_disable_master_thread (true, this);
- set_output_mode (tty::restore, &get_ttyp ()->ti, &handle_set);
- set_input_mode (tty::restore, &get_ttyp ()->ti, &handle_set);
+ if (con.curr_output_mode != tty::restore)
+ set_output_mode (tty::restore, &get_ttyp ()->ti, &handle_set);
+ if (con.curr_input_mode != tty::restore)
+ set_input_mode (tty::restore, &get_ttyp ()->ti, &handle_set);
}

if (shared_console_info[unit] && con.owner == GetCurrentProcessId ())
@@ -2296,8 +2310,10 @@ int
fhandler_console::tcsetattr (int a, struct termios const *t)
{
get_ttyp ()->ti = *t;
- set_input_mode (tty::cygwin, t, &handle_set);
- set_output_mode (tty::cygwin, t, &handle_set);
+ if (con.curr_input_mode == tty::cygwin)
+ set_input_mode (tty::cygwin, t, &handle_set);
+ if (con.curr_output_mode == tty::cygwin)
+ set_output_mode (tty::cygwin, t, &handle_set);
return 0;
}

Loading
Loading