- 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
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>
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>
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)
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>
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>
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>
_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>
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>
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>
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>
../../../../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=]
../../../../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=]
../../../../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=]
../../../../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’
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>
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>
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>
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.
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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.
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>