22585 Commits
Author SHA1 Message Date
Michael de Lang 06add56f7c Fix __call_atexit to guard against null reference
- with _REENT_SMALL, args is p->_on_exit_args_ptr.
  That pointer stays NULL unless __on_exit_args is linked, which happens
  only through on_exit() or __cxa_atexit(). A program that registers its
  handlers only with atexit() therefore reads NULL+0x100, NULL+0x104 and
  NULL+4*n at exit. Because args has now been dereferenced, GCC also removes
  the later !args || test before the call. On a target with an MPU null
  guard this faults; where address 0 is readable, the junk value decides
  how fn is called.

- add guard for this scenario
2026-10-07 14:23:01 -04:00
Takashi Yano 8f145421c9 Cygwin: Update the 3.6.11 release notes regarding recent bug fixes
(cherry picked from commit 230404cef9)
2026-09-30 22:03:34 +09:00
Christoph Reiter 6a16c4bfb6 Cygwin: console: Avoid deadlock with app execution aliases
Calling `winget.exe` through its app execution alias from an interactive
MSYS2 shell can leave the shell hanging after `winget.exe` exits. This
affects all app execution aliases, not only `winget.exe`.

App execution alias handling was introduced in 0631c6644e (Cygwin: Treat
Windows Store's "app execution aliases" as symbolic links, 2021-03-22),
and 6c3d26961d (Cygwin: termios: Handle app execution alias in
is_console_app(), 2025-12-10) taught `is_console_app()` to follow
aliases using another `path_conv`, which allocates cygheap memory.

618eb90fc2 (Cygwin: console: Fix undesired mode change at exit of
non-cygwin apps, 2026-09-19) added a second `is_console_app()` call from
`wait_for_resume_if_necessary()`. Unfortunately, at that point,
`child_info_spawn::worker()` already holds the non-recursive
`cygheap_protect`, so following an alias tries to acquire the same lock
recursively and deadlocks.

Let's avoid running `is_console_app()` under that lock by instead
classifying the executable _once_, in `spawn_worker::setup()`, before
acquiring the cygheap lock, then cache and reuse the result for both PTY
setup and the post-resume wait.

Addresses: https://github.com/msys2/msys2-runtime/issues/372
Fixes: 618eb90fc2 (Cygwin: console: Fix undesired mode change at exit
 of non-cygwin apps, 2026-09-19)
Reviewed-by: Takashi Yano <takashi.yano@nifty.ne.jp>
Signed-off-by: Christoph Reiter <reiter.christoph@gmail.com>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2026-09-30 19:27:37 +09:00
Mark Geisert 6fde14c0e2 Cygwin: Add #define for IPTOS_DSCP_VA in <netinet/ip.h>
Define IPTOS_DSCP_VA (0xb0) according to RFC 5865 to complete the DSCP
code point definitions in <netinet/ip.h>. This fixes compilation for
utilities like openbsd-netcat.

I provide this patch to the Cygwin sources under the 2-clause BSD license.

Signed-off-by: Michał Korczak <omikorin@disroot.org>
Reviewed-by: Mark Geisert <mark@maxrnd.com>
2026-09-28 23:07:10 -07:00
Mark Geisert 3883fda70d Cygwin: Handle uids/gids correctly on NFSv4 filesystems
Currently, Cygwin assumes that all Windows NFS clients operate
similarly to the Windows NFSv3 client. It expects that account names
and numeric uid/gid values are identical on both the client and server
sides, with LDAP acting as the sole authority for these numeric
values.

However, the NFSv4 protocol fundamentally changes this paradigm. As
defined in RFC 7530 (Section 5.9) and expanded upon in RFC 8178 (Rules
for NFSv4 Domain and ID Mapping), NFSv4 deprecates raw numeric uid/gid
protocol representation in favor of string-based identifiers (e.g.,
user@domain and group@domain).

To handle this, all NFSv4 clients implement a local "idmapper"
component that translates these string-based identities from the
network side into local account data (in the case of Windows, mapping
user/group names and uid/gid values via nfs3attr XATTR). Because NFSv4
clients manage their own uid/gid translation locally, Cygwin's
reliance on raw LDAP data fails in these environments and results in
the dreaded "Unix_User+<1234>" and "Unix_Group+<5678>"-kind of
owner/group output in Cygwin ls -l.

The [...] patch addresses this by detecting whether the underlying
filesystem is NFSv4. If it is, Cygwin bypasses the LDAP assumption and
performs a direct pass-through of the uid/gid values supplied by the
NFSv4 client's idmapper.

[Lionel has] successfully tested this fix against several major clients,
including:
- Exceed NFSv4 client
- OpenText NFSv4 client
- ms-nfs41-client
- ms-nfs42-client
- Windows NFSv3 client (no change, it continues to use LDAP raw data)

Reported-by: Lionel Cons <lionelcons1972@gmail.com>
Addresses: https://cygwin.com/pipermail/cygwin-patches/2026q3/015287.html
Authored-by: Roland Mainz <roland.mainz@nrubsig.org>
Reviewed-by: Mark Geisert <mark@maxrnd.com>
Fixes: 88dce3a (Try harder to avoid LDAP access for RFC2307 mapping)
2026-09-28 22:39:45 -07:00
Jon Turney 1bec354a7e Cygwin: CI: Update aarch64 workarounds 2026-09-28 22:20:16 +01:00
Takashi YanoandJohannes Schindelin dd317d0b2b Cygwin: console: Improve the performance of peek_console
Previously, peek_console() used PeekConsoleInput() to confirm whether
the console input buffer has some input records. However, this need
attaching to the console if the process does not attach to the console.
To reduce that overhead, this patch uses WaitForSingleObject() with
console input handle instead. WaitForSingleObject() works without
attaching to the console, so this simplifies the peek_console()
code.

Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
Co-authored-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Reviewed-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
2026-09-28 22:01:05 +09:00
Máté Dimand b6e315143b Cygwin: gendef: fix SEH directives in AArch64 sigdelayed
The directive .seh_save_regp_x should not be used with x16 or x17
registers. (This error is now deteected by gas, reporing "Error:
unexpected register number")

The newly added x29 and x30 push + the save_fplr directive enables full
stack unwinding.

Co-authored by: Evgeny Karpov <evgeny.karpov@arm.com>
Signed-off-by: Máté Dimand <mate.dimand@arm.com>
2026-09-27 15:42:41 +01:00
Mayank Agrawal 72949ea444 Cygwin: gendef: fix AArch64 stabilize_sig_stack lock retry
The retry label sat below the code that computes the stacklock address
and the "locked" constant, so those were set up once on entry and not
recomputed.  The signal-handler path below branches back to the label
after using x9 and x12 for the incyg counter, so a retry could operate
on incyg rather than stacklock, or spin.

Move the label above the setup so both are recomputed on every
iteration, and clear the exclusive monitor before yielding on
contention.

Fixes: 5effc7a9bf ("Cygwin: gendef: Implement stabilize_sig_stack for aarch64")
Signed-off-by: Aswin Kalies <aswin.kalies@multicorewareinc.com>
2026-09-27 15:35:52 +01:00
Mayank Agrawal f23292d8a7 Cygwin: gendef: fix AArch64 _sigfe_maybe control flow
_sigfe_maybe returned on both outcomes of the 'TLS initialized?' check,
so it never entered _sigfe and never called the wrapped function.

The wrapper enters it with 'br' after reserving 16 bytes and storing the
real function address at [sp], but AArch64 'ret' branches to x30 and
pops nothing, so the bypass path returned without calling the function
while leaking the wrapper slot.

Branch to a shared L_sigfe_entry label when TLS is valid, mirroring the
x86_64 path's "je 1f", and otherwise pop the wrapper slot and tail-call
the real function through it.

The CYGTLS_INITIALIZED comparison also built 0x173fc763 instead of
0xc763173f, as the movz/movk halves were swapped, so it could never
match.

Fixes: ae46abc226 ("Cygwin: gendef: add _sigfe_maybe for TLS initialization checks on AArch64")
Signed-off-by: Aswin Kalies <aswin.kalies@multicorewareinc.com>
2026-09-27 14:55:31 +01:00
Christian Franke e8f50ec5b7 Cygwin: CI: Fix syntax thinko in doc deploy conditional
Fixes: 85a4343524 ("Cygwin: CI: Extend cross-compile workflow to also build for aarch64")
Signed-off-by: Jon Turney <jon.turney@dronecode.org.uk>
2026-09-27 11:17:15 +01:00
Takashi Yano 2867786d24 Cygwin: console: Clear readahead buffer on tcflush()
Previously, tcflush(TCIFLUSH) only discarded the input events and
did not clear the readahead buffer. Because of this bug, when user
program called select() -> tcflush() -> read(), the last read()
returned the contents of the readahead buffer instead of blocking
as it should.

Correctly, tcflush() must discard all pending input, so read()
should block until new input arrives. With this patch, the read-
ahead buffer and `rapoi` are also cleared as well as input events.

Fixes: 8382778cdb ("Cygwin: console: fix select() behaviour")
Suggested-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
Reviewed-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
2026-09-27 01:02:20 +09:00
Takashi YanoandJohannes Schindelin 3e6859192d Cygwin: console: Abort setting disable_master_thread when no con.owner
With the commit 733d5a953f ("Cygwin: console: Ensure the master
thread runs only when it is supposed to"), the process which calls
set_disable_master_thread() hangs if the con.owner already exited,
because set_disable_master_thread() waits for cons_master_thread
accepting the status change and reflecting the current status to
master_thread_suspended. With this patch, set_disable_master_thread()
is aborted if the owner process no longer exists to avoid this
hang.

Addresses: https://cygwin.com/pipermail/cygwin/2026-September/260037.html
Fixes: 733d5a953f ("Cygwin: console: Ensure the master thread runs only when it is supposed to")
Reported-by: Jay Libove Alzina <libove@felines.org>
Co-authored-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
Reviewed-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
2026-09-26 23:04:14 +09:00
Takashi YanoandJohannes Schindelin a3dd824af8 Cygwin: console: Fix undesired mode change at exit of non-cygwin apps
Previously, if two non-cygwin apps are started and one of them
exits first, the other one lost appropriate console mode, since
the first one restored it to tty::cygwin. This patch counts the
active console process whose pgid is pgid of the tty and if the
result is zero (means the last non-cygwin foreground process),
restore console mode. To avoid race issue between apps modifying
console mode simultaneously, this patch also introduce a mutex
named `cons_mode_mutex`.

Known limitation:
In the case of non-overlayed spawn, there still exists a small
window in which another non-cygwin process may restore tty::cygwin
mode even though new non-cygwin app is about to start.

In addition:
Avoid the cleanup/startup deadlock: cleanup can hold `cons_mode_mutex`
while waiting for a console master that a new owner cannot start until
acquiring that mutex. Startup must precede the mode-mutex wait without
changing the handshake or mode serialization.

Fixes: 48285aa36c ("Cygwin: console: Fix handling of Ctrl-S in Win7.")
Co-authored-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
Reviewed-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
2026-09-26 23:04:14 +09:00
Jon Turney 04f9e88ce7 Cygwin: Variable 'nfences' computed but never used
../../../../src/winsup/cygwin/mm/malloc.cc: In function ‘void add_segment(mstate, char*, size_t, flag_t)’:
../../../../src/winsup/cygwin/mm/malloc.cc:3995:7: error: variable ‘nfences’ set but not used [-Werror=unused-but-set-variable=]
2026-09-24 16:08:21 +01:00
Jon Turney 761d284ed8 Cygwin: Variable 'prot' computed but never used
../../../../src/winsup/cygserver/sysv_shm.cc: In function ‘int kern_shmat(thread*, int, const void*, int)’:
../../../../src/winsup/cygserver/sysv_shm.cc:345:19: error: variable ‘prot’ set but not used [-Werror=unused-but-set-variable=]
2026-09-24 16:08:21 +01:00
Jon Turney c3b7e4fdd5 Cygwin: Variable 'looped' computed but never used
../../../../src/winsup/cygwin/spawn.cc: In member function ‘int child_info_spawn::worker(const char*, const char* const*, const char* const*, int, int, int)’:
../../../../src/winsup/cygwin/spawn.cc:328:7: warning: variable ‘looped’ set but not used [-Wunused-but-set-variable=]
2026-09-24 16:08:20 +01:00
Takashi Yano 8eedf95152 Cygwin: clipboard: Handle ERROR_SYS_KEY_NOT_FOUND and NO_ERROR
Windows 10 seems to return ERROR_SXS_KEY_NOT_FOUND instead of
ERROR_NOT_FOUND. In addition, it returns NO_ERROR even though
GetClipboardData() returns NULL. This patch handles these cases.

Addresses: https://cygwin.com/pipermail/cygwin/2026-September/260058.html
Fixes: 7fd670a36b ("Cygwin: clipboard: Add workaround for ERROR_CLIPBOARD_NOT_OPEN")
Reported-by: Shun <shun1048576@gmail.com>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
Reviewed-by: Mark Geisert <mark@maxrnd.com>
2026-09-18 20:30:43 +09:00
Jon Turney 85a4343524 Cygwin: CI: Extend cross-compile workflow to also build for aarch64 2026-09-17 16:18:18 +01:00
Jeff Johnston c324e5125a Fix other conversion routines similarly to strtol.c 2026-09-16 17:09:58 -04:00
Jon Turney 2a7858e916 Cygwin: Fix compilation of c8rtomb with gcc 16
../../../../src/winsup/cygwin/strfuncs.cc: In function ‘size_t c8rtomb(char*, char8_t, mbstate_t*)’:
../../../../src/winsup/cygwin/strfuncs.cc:214:41: error: cannot bind non-const lvalue reference of type ‘char8_t&’ to a value of type ‘unsigned char’
../../../../src/winsup/cygwin/strfuncs.cc:215:41: error: cannot bind non-const lvalue reference of type ‘char8_t&’ to a value of type ‘unsigned char’
../../../../src/winsup/cygwin/strfuncs.cc:216:41: error: cannot bind non-const lvalue reference of type ‘char8_t&’ to a value of type ‘unsigned char’
2026-09-16 16:45:47 +01:00
Máté Dimand 58028b6b74 Cygwin: gendef: fixed AArch64 setjmp storing incorrect frame pointer in jmpbuf
This bug caused testcase "mmaptest02" to not run properly, because of the
exception handler not being ran at the last access violation, presumably
due to the frame pointer being incorrect. Fixing this allows the process
to end gracefully.

Signed-off-by: Máté Dimand <mate.dimand@arm.com>
2026-09-16 16:44:05 +01:00
Chandru Kumaresan b5826996ad Cygwin: Add AArch64 cpuid
Implement ARM64 support for /proc/cpuinfo and sysconf cache queries
using Windows APIs and registry data. Add ARM64 CPU feature reporting,
MIDR parsing, cache detection via GetLogicalProcessorInformationEx, and
minimal cpuid() fallback handling. Restrict x86 CPUID paths to x86_64
and fix AArch64 preprocessor conditions.

Signed-off-by: Radek Bartoň <radek.barton@microsoft.com>
Signed-off-by: Thirumalai Nagalingam <thirumalai.nagalingam@multicorewareinc.com>
Signed-off-by: Chandru Kumaresan <chandru.kumaresan@multicorewareinc.com>
2026-09-16 16:42:55 +01:00
Jon Turney a101ec3bac Cygwin: Explicitly pass include directory to winres
(This is needed for a bootstrap build, where an installed
cygwin/version.h doesn't exist yet.)
2026-09-16 16:36:54 +01:00
Jonathan Wakely 00208dc31e Fix stdbit functions for 16-bit targets
All the USHRT_WIDTH < UINT_WIDTH assertions fail for 16-bit int targets,
such as msp430-elf. Remove those static assertions and instead fix the
stdc_xxx_us functions to work correctly when USHRT_WIDTH == UINT_WIDTH.

Signed-off-by: Jonathan Wakely <jwakely@redhat.com>
2026-09-15 12:10:15 -04:00
Jeff Johnston 807f45a145 Tweak logic fix to strtol.c 2026-09-15 11:07:18 -04:00
Jeff Johnston 03f936e72c Fix strtol when there is an invalid hex number
If input starts with '0x' but then either ends or has an non-hex
character, treat it as if '0' is read and we stop at 'x'.  This
matches what glibc does.
2026-09-14 20:57:31 -04:00
Takashi Yano 2ac3428a93 Cygwin: console: Fix argument of process_input_message() in read()
The commit fac73911f5 ("Cygwin: console: Fix typeahead input for
bash") introduced an argument to process_input_message() to restict
the maximum length to be processed by this function. However, the
commit failed to account for the number of chars already copied into
the buffer.  This patch corrects the argument to process_input_message()
to address this issue.

Fixes: fac73911f5 ("Cygwin: console: Fix typeahead input for bash")
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
Reviewed-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
2026-09-13 20:22:39 +09:00
Jon Turney 935d5dae0f Cygwin: CI: Update python module packages now python3.12 is the default 2026-09-08 12:49:28 +01:00
Takashi Yano dae171e433 Cygwin: proc: Cache system process information
If a process reads /proc/<pid>/stat for multiple PIDs, current code
every time calls NtQuerySystemInformation(SystemProcessInformation).
In addition, the buffer size is estimated by calling that function
with increasing buffer size. This takes 15 - 20 msec. This looks
short time, however it is not negligible in some situation. If the
number of processes is 100, reading /proc/<pid>/stat takes 1.5 - 2.0
sec. Due to this behaviour, process pane of the btop is very heavy.

With this patch, system process information is cached per process
for a short time (20 msec) to improve efficiency. The buffer is
allocated first time when the corresponding /proc file system is
read, and held until process exits. If the buffer size needed by
NtQuerySystemInformation() is increased, the buffer will be re-
allocated, however never freed. The buffer pointer and the buffer
size are stored in the static area, so that the number of the
function call is reduced much. As a result, the process pane of
btop becomes significantly light. It takes only ~15 msec for 100
processes.

Fixes: 9ba913a56d ("* fhandler_process.cc (process_listing): Add 'stat' and 'statm'.")
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
Reviewed-by: Mark Geisert <mark@maxrnd.com>
2026-09-07 09:33:26 +09:00
Aswin Kalies Ramkumar Mangayarkarasi 0fd43e4884 Cygwin: Add AArch64 support for alternate signal stack and ucontext
Add the AArch64 implementations that were previously #error stubs:
  - the alternate-signal-stack (SA_ONSTACK) asm in call_signal_handler,
  - the __cont_link_context trampoline, and
  - setcontext/makecontext for aarch64.

Signal delivery itself already worked; this fills in the SA_ONSTACK and
ucontext paths.

Signed-off-by: Chandru Kumaresan <chandru.kumaresan@multicorewareinc.com>
Signed-off-by: Aswin Kalies <aswin.kalies@multicorewareinc.com>
2026-09-06 16:59:54 +01:00
Jon Turney 2fa3829922 Cygwin: CI: Use git protocol to clone stc repo
This might be more reliable if the http service is being DDoS'ed.
2026-09-06 16:56:03 +01:00
Takashi Yano 9756b33318 Cygwin: proc: Provides correct number of thread rather than 0
Currently, /proc/<pid>/stat always reports 0 as the number of thread.
However, get_process_state() does know the thread count for the
process, so expose that value in /proc/<pid>/stat. Additionally, add
a "Threads:" entry to /proc/<pid>/status.

Fixes: 9ba913a56d ("* fhandler_proc.cc (proc_listing_array): Add 'loadavg', 'meminfo', and 'stat'.")
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
Reviewed-by: Mark Geisert <mark@maxrnd.com>
2026-09-06 20:09:46 +09:00
Takashi Yano 6a2f4b101c Cygwin: proc: Fix loadavg calculation
Previously, format_proc_loadavg() wrongly passed an argument `i` to
get_process_state(). This should be windows process ID (pids[i]->
dwProcessId). This patch fix that.

Fixes: 9ca65531e0 ("* fhandler_proc.cc (format_proc_loadavg): Add running/total processes as fourth component of output.")
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
Reviewed-by: Mark Geisert <mark@maxrnd.com>
2026-09-06 20:09:26 +09:00
Sebastian Huber cf61e0140e moxie: Save $r11 in setjmp() and longjmp()
The ABI of the architecture makes $r6 to $r11 call-saved.  The routines
saved and restored $r6 to $r10 only, and _JBLEN left no room for
another register.  A value which the compiler holds in $r11 across a
setjmp() and longjmp() pair was lost.  A caller which returns through
longjmp() and then makes an indirect call through $r11 jumps to
whatever the intervening code left there.

Add $r11 to the jump buffer and raise _JBLEN to 11.  Correct the layout
comment, which swapped $sp and $fp and gave the last stack frame slot
as 0x25.

The size of jmp_buf changes, so the C library and every application
must be built together.

Found with the RTEMS test suite on the moxie GDB simulator.  The test
spmutex01 calls longjmp() from a fatal error extension and returns into
an indirect call through $r11.

Assisted-by: Claude:claude-opus-5 claude-code
Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
2026-08-24 20:37:35 -04:00
Jan Dubiec a83b868a0b H8: Honor USER_LABEL_PREFIX set by ld
This patch complements the following binutils patch: https://sourceware.org/pipermail/binutils/2026-August/150974.html.

Signed-off-by: Jan Dubiec <jdx@o2.pl>
2026-08-24 20:15:59 -04:00
Takashi Yano 51532d2727 newlib: getlocalename_l: Avoid strcpy onto const area on "C" locale
With the commit a0fe984953 ("getlocalename_l: allow LC_ALL category"),
the code attempts to copy locale string to `locobj->locale_string`,
in __currentlocale() in _getlocalename_l_r(). However, if `locobj` is
the "C" locale, it points to the const area. This results in a crash.

This patch simply returns "C" when the `locobj` represents the C
locale, instead of constructing LC_ALL string from `categories[]`
because all the `categories[]` are always "C" for the C locale.

Fixes: a0fe984953 ("getlocalename_l: allow LC_ALL category")
Addresses: https://cygwin.com/pipermail/cygwin/2026-August/259965.html
Reported-by: Tony Cook <tony@develop-help.com>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2026-08-24 19:54:34 -04:00
Keith Thompson c2ccfae997 Correct isspace(3) man page (copied wording from isalpha(3)) 2026-08-13 17:13:50 -04:00
Jeff Johnston 656465de6b Revert last changes to fini.c and init.c 2026-08-12 13:35:21 -04:00
Jan Dubiec 81f45549e7 Make the UNALIGNED_X_Y() macro more robust against errors.
Signed-off-by: Jan Dubiec <jdx@o2.pl>
2026-08-10 14:48:32 -04:00
Johannes Schindelin 61b4866baf Cygwin: pty: keep interactive console input for native programs via Cygwin
Currently, when a native Windows program starts a Cygwin program while a
pseudo console is active, and the Cygwin program then starts another
native Windows program, the final program can lose access to console
input. It then behaves as though its standard input were redirected
instead of remaining interactive.

For example, a native `git.exe` may invoke shell aliases (i.e. execute a
shell command) that would in turn call interactive Git commands who
would no longer work because their standard input appeared to be
redirected. This can be demonstrated as follows:

  git -c 'alias.console-probe=!powershell.exe -NoLogo -NoProfile -Command "
    Write-Output ([Console]::IsInputRedirected)
    try {
      [void][Console]::KeyAvailable
      exit 0
    } catch {
      exit 1
    }
  "' console-probe

Running this command with a Win32 version of `git.exe` currently prints
`True` and exits with exit code 1. In the latest official release, where
this bug is not present, it prints `False` and results in exit code 0.

The reason is to be fonud in the archetype code. Reminder: For each
pseudo terminal (pty), the archetype is the shared pty fhandler that
owns the underlying native handles and supplies them to every
per-file-descriptor fhandler for that pty.

`open_with_arch()` calls `open()`, copies the first pty fhandler's state
into the archetype, and then calls `open_setup()`. At that stage, pcon
handle adoption already took place in `open_setup()`. This was not
anticipated by 60a88896dc (Cygwin: pty: do not leak nat handles when
adopting the pcon's in open_setup(), 2026-06-25), which tried to fix a
leak by closing the superseded native handles as they were replaced in
`open_setup()`.  Because `open_with_arch()` had already copied those
handle values into the archetype, closing them invalidated the
archetype's copies.

The archetype therefore retained stale values for those closed handles,
which later pty fd fhandlers would inherit. If Windows reuses one of
those values for a newly duplicated pcon handle, closing the stale value
closes the new handle instead. The nested native program then receives
unusable console input.

Preserve usable console input by moving the unchanged transactional pcon
handle adoption to `open()`, before the archetype snapshot. The archetype
then receives valid pcon handles, all pty fd fhandlers inherit live
handles, and the superseded raw pipe handles are closed exactly once.

This commit is best viewed with `--color-moved`.

Fixes: 60a88896dc ("Cygwin: pty: do not leak nat handles when
 adopting the pcon's in open_setup()")
Assisted-by: GPT-5.6 Sol
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Reviewed-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2026-08-07 19:26:54 +09:00
Takashi Yano 9807479c90 Cygwin: console: Fix regression in console input
The commit fac73911f5 ("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: fac73911f5 ("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>
2026-08-07 01:02:39 +09:00
Takashi Yano 4d51e9693f Cygwin: open: Do not set tentative fhandler to fdtab
Tentative assignment of fhandler to fdtab introduced by the commit
524d75ff73 ("Cygwin: open: Unlock fdtab before open_with_arch()")
causes the undesired behaviour. The commit intended that fhandler
was just a marker for reservation of fd. However, another cygwin
call may assume that the fd is valid and in use, and may operate on
it.

This patch introduces a special value ((fhandler_base *) -1) for
fdtab that marks the fd as reserved and means it cannot be assigned
for another open(), etc.

Fixes: 524d75ff73 ("Cygwin: open: Unlock fdtab before open_with_arch()")
Suggested-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
Reviewed-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
2026-08-05 22:08:28 +09:00
Mate Dimand bc99666a4b Cygwin: exceptions: Fix AArch64 non-incyg signal handling
This patch fixes crashes that occur when a signal interrupts sigfe or
any non-cygwin function that does not preserve the LR register in its
prologue/epilogue. This crash was discovered through the "run-heredoc"
testcase in bash's testsuite, which caused bash to call "read"
frequently, leading to a high chance of a signal interrupting sigfe.

The original "sigdelayed" function in gendef clobbered the LR register
to return to the instruction where the thread was interrupted. Picking
any other register for branching back would also clobber said register.
Leaf functions are not guaranteed to be compiled with LR being preserved
on the stack. The solution is to use RtlRestoreContext to restore all
registers without needing to sacrifice any.

The patch replaces sigdelayed with an implementation that consists of
both C and assembly functions. The "sigdelayed" assembly function was
replaced with a simple wrapper function that was kept as assembly code
to guarantee total control of the registers that get clobbered prior to
capturing the context. This function calls RtlCaptureContext first, with
the context being stored on the stack. The context is then passed to a
C++ function which fixes the clobbered registers. Finally, this calls a
C++ implementation of the original x64/AArch64 assembly version of
sigdelayed. These functions were not written in assembly for the sake of
readability. Once it completed handling the signals, it uses
RtlRestoreContext to jump back.

Signed-off-by: Mate Dimand <mate.dimand@arm.com>
2026-08-03 16:27:39 +01:00
Johannes Schindelin ec3607ba28 Cygwin: 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>
2026-08-03 14:49:45 +01:00
Takashi Yano 0d3ea0ee65 Cygwin: open: Add missing unlock on error
the commit 524d75ff73 ("Cygwin: open: Unlock fdtab before open_
with_arch()") introduced a bug that fdtab lock was not unlocked
when new fd cannot be allocated due to an error.

This patch adds missing unlock for fdtab lock on error.

Fixes: 524d75ff73 ("Cygwin: open: Unlock fdtab before open_with_arch()")
Suggested-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
Reviewed-by: Mark Geisert <mark@maxrnd.com>
2026-08-03 19:49:21 +09:00
Kito Cheng a78440e35f RISC-V: introduce ENTRY/END assembler macros for function boilerplate
Factor out the repeated .text, .globl, .type, landing-pad (lpad) and
.size boilerplate at the start and end of each assembly function into
ENTRY/END style macros, and convert the RISC-V assembly routines to use
them.
2026-08-03 14:39:57 +08:00
Takashi Yano 9e2f67d8b4 Cygwin: pty: Fix cursor position on new nat app in existing pcon
Previously, the steps: cmd.exe -> bash -> cmd.exe exhibit broken
cursor position even with the commit b34394d456 ("Cygwin: pty:
Fixup pty state after a cygwin app exits").

This patch sets req_fixup_pcon_cur_pos also when reusing existing
pseudo console as well as req_xfer_input. In addition, clearing
`pcon_start_pid` has been moved inside `input_mutex`, to addess
the race condition that becomes harmfull with this patch.

Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
Reviewed-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2026-08-03 11:41:04 +09:00
Jan Dubiec fa7b0cd4d5 Silence -Wpointer-to-int-cast warnings in newlib/libc/string/local.h.
Signed-off-by: Jan Dubiec <jdx@o2.pl>
2026-07-22 17:16:08 -04:00
Jeff Johnston 137e27ffb6 Regenerate configure for atari changes 2026-07-20 22:08:53 -04:00