[New msys2-runtime version] Cygwin: Fix segfault when XSAVE area sizes are unaligned
Cygwin: Fix segfault when XSAVE area sizes are unaligned
During signal delivery, Cygwin saves the CPU's extended register state
(floating-point, SSE, AVX, etc.) to a stack buffer using the xsave64
instruction, which requires its destination to be 64-byte aligned.
Before executing xsave64, the code queries the CPU (via cpuid) for the
required buffer size, then subtracts that size (plus a fixed overhead)
from the stack pointer.
The stack alignment arithmetic assumes that cpuid returns a size that
is a multiple of 64. Until recently, this held true for all x86 CPUs.
On recent AMD and Intel CPUs, however, the PKU feature (Protection Keys
for Userspace, a memory-protection mechanism) adds an XSAVE component
of only 8 bytes, which makes the total size no longer a multiple of 64.
The subtraction then places the xsave64 buffer at a misaligned address,
causing a segfault.
This was first observed when running Cygwin/MSYS2 under Wine on Linux,
where the host kernel exposes the PKU feature directly. The same
problem could surface on future Windows versions that expose PKU or
other small XSAVE components.
The fix rounds up the cpuid-reported size to the next 64-byte multiple
before using it in the stack allocation. The existing code already
guarantees correct alignment for any buffer size that is a multiple of
64, so this rounding is sufficient.
Fixes: c607889824 ("Cygwin: sigfe: Fix a bug that signal handler destroys fpu states")
Signed-off-by: Pip Cet <pipcet@protonmail.com>
msys2/msys2-runtime@aa532e7
[New msys2-runtime version] Cygwin: Adjust CWD magic to accommodate for the latest Windows previews
Cygwin: Adjust CWD magic to accommodate for the latest Windows previews
Reportedly a very recent internal build of Windows 11 once again changed
the current working directory logic a bit, and Cygwin's "magic" (or:
"technologically sufficiently advanced") code needs to be adjusted
accordingly.
In particular, the following assembly code can be seen:
ntdll!RtlpReferenceCurrentDirectory
598 00000001`800c6925 488d0db4cd0f00 lea rcx,[ntdll!FastPebLock (00000001`801c36e0)]
583 00000001`800c692c 4c897810 mov qword ptr [rax+10h],r15
588 00000001`800c6930 0f1140c8 movups xmmword ptr [rax-38h],xmm0
598 00000001`800c6934 e82774f4ff call ntdll!RtlEnterCriticalSection
The change necessarily looks a bit different than 4840a56325 (Cygwin:
Adjust CWD magic to accommodate for the latest Windows previews,
2023-05-22): The needle `\x48\x8d\x0d` is already present, as the first
version of the hack after Windows 8.1 was released. In that code,
though, the `call` to `RtlEnterCriticalSection` followed the `lea`
instruction immediately, but now there are two more instructions
separating them.
Note: In the long run, we may very well want to follow the insightful
suggestion by a helpful Windows kernel engineer who pointed out that it
may be less fragile to implement kind of a disassembler that has a
better chance to adapt to the ever-changing code of
`ntdll!RtlpReferenceCurrentDirectory` by skipping uninteresting
instructions such as `mov %rsp,%rax`, `mov %rbx,0x20(%rax)`, `push %rsi`
`sub $0x70,%rsp`, etc, and focuses on finding the `lea`, `call
ntdll!RtlEnterCriticalSection` and `mov ..., rbx` instructions, much
like it was prototyped out for ARM64 at
https://gist.github.com/jeremyd2019/aa167df0a0ae422fa6ebaea5b60c80c9
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
msys2/msys2-runtime@cb25225
[New msys2-runtime version] uname: report msys2-runtime commit hash, too
uname: report msys2-runtime commit hash, too
Having just Cygwin's version in the output of `uname` is not helpful, as
both MSYS2 as well as Git for Windows release intermediate versions of
the MSYS2 runtime much more often than Cygwin runtime versions are
released.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
msys2/msys2-runtime@adee13c
[New msys2-runtime version] Avoid sharing cygheaps across Cygwin versions
Avoid sharing cygheaps across Cygwin versions
It frequently leads to problems when trying, say, to call from MSYS2's
Bash into Cygwin's or Git for Windows', merely because sharing that data
is pretty finicky.
For example, using the MSYS2' Bash using the MSYS2 runtime version that
is current at time of writing, trying to call Cygwin's programs fails
in manners like this:
$ /c/cygwin64/bin/uname -r
0 [main] uname (9540) child_copy: cygheap read copy failed, 0x800000000..0x800010BE0, done 0, windows pid 9540, Win32 error 6
680 [main] uname 880 C:\cygwin64\bin\uname.exe: *** fatal error - couldn't create signal pipe, Win32 error 5
with the rather misleading exit code 127 (a code which is reserved to
indicate that a command was not found).
Let's just treat the MSYS2 runtime and the Cygwin runtime as completely
incompatible with one another, by virtue of using a different
magic constant than merely `CHILD_INFO_MAGIC`.
By using the msys2-runtime commit to modify that magic constant, we can
even spawn programs using a different MSYS2 runtime (such as Git for
Windows') because the commit serves as the tell-tale whether two MSYS2
runtime versions are compatible with each other. To support building in
the MSYS2-packages repository (where we do not check out the
`msys2-runtime` but instead check out Cygwin and apply patches on top),
let's accept a hard-coded commit hash as `./configure` option.
One consequence is that spawned MSYS processes using a different MSYS2
runtime will not be visible as such to the parent process, i.e. they
cannot share any resources such as pseudo terminals. But that's okay,
they are simply treated as if they were regular Win32 programs.
Note: We have to use a very rare form of encoding the brackets in the
`expr` calls: quadrigraphs (for a thorough explanation, see
https://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf-2.70/html_node/Quadrigraphs.html#Quadrigraphs).
This is necessary because it is apparently impossible to encode brackets
in `configure.ac` files otherwise.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
msys2/msys2-runtime@546c331
[New msys2-runtime version] Revert "Cygwin: Enable dynamicbase on the Cygwin DLL by default"
Revert "Cygwin: Enable dynamicbase on the Cygwin DLL by default"
This reverts commit 943433b00cacdde0cb9507d0178770a2fb67bd71.
This seems to fix fork errors under Docker, see
https://cygwin.com/pipermail/cygwin/2022-December/252711.html
msys2/msys2-runtime@66cfb0c
[New msys2-runtime version] build_env(): respect the MSYS environment variable
build_env(): respect the `MSYS` environment variable
With this commit, you can call
MSYS=noemptyenvvalues my-command
and it does what is expected: to pass no empty-valued environment
variables to `my-command`.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
msys2/msys2-runtime@9c78766
[New msys2-runtime version] Optionally disallow empty environment values again
Optionally disallow empty environment values again
We just disabled the code that skips environment variables whose values
are empty.
However, this code was introduced a long time ago into Cygwin in
d6b1ac7faa (* environ.cc (build_env): Don't put an empty environment
variable into the environment. Optimize use of "len". * errno.cc
(ERROR_MORE_DATA): Translate to EMSGSIZE rather than EAGAIN.,
2006-09-07), seemingly without any complaints.
Meaning: There might very well be use cases out there where it makes
sense to skip empty-valued environment variables.
Therefore, it seems like a good idea to have a "knob" to turn it back
on. With this commit, we introduce such a knob: by setting
`noemptyenvvalues` the `MSYS` variable (or appending it if that variable
is already set), users can tell the MSYS2 runtime to behave just like in
the olden times.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
msys2/msys2-runtime@d064b00
[New msys2-runtime version] Pass environment variables with empty values
Pass environment variables with empty values
There is a difference between an empty value and an unset environment
variable. We should not confuse both; If the user wants to unset an
environment variable, they can certainly do so (unsetenv(3), or in the
shell: 'unset ABC').
This fixes Git's t3301-notes.sh, which overrides environment variables
with empty values.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
msys2/msys2-runtime@8fdf344
[New msys2-runtime version] uname: allow setting the system name to CYGWIN
uname: allow setting the system name to CYGWIN
We are currently trying to move our cygwin build environment closer
to cygwin and some autotools/bash based build systems call "uname -s"
to figure out the OS and in many cases only handle the cygwin case, so
we have to patch them.
With this instead of patching we can set MSYSTEM=CYGWIN and change
uname output that way.
The next step would be to always output CYGWIN in an msys env by default,
but for now this allows us to get rid of all the patches without
affecting users.
msys2/msys2-runtime@2f1036a
[New msys2-runtime version] Handle ORIGINAL_PATH just like PATH
Handle ORIGINAL_PATH just like PATH
MSYS2 recently introduced that hack where the ORIGINAL_PATH variable is
set to the original PATH value in /etc/profile, unless previously set.
In Git for Windows' default mode, that ORIGINAL_PATH value is the used
to define the PATH variable explicitly.
So far so good.
The problem: when calling from inside an MSYS2 process (such as Bash) a
MINGW executable (such as git.exe) that then calls another MSYS2
executable (such as bash.exe), that latter call will try to re-convert
ORIGINAL_PATH after the previous call converted ORIGINAL_PATH from POSIX
to Windows paths. And this conversion may very well fail, e.g. when the
path list contains mixed semicolons and colons.
So let's just *force* the MSYS2 runtime to handle ORIGINAL_PATH in the
same way as the PATH variable (which conversion works, as we know).
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
msys2/msys2-runtime@79885de
[New msys2-runtime version] POSIX-ify the SHELL variable
POSIX-ify the SHELL variable
When calling a non-MSys2 binary, all of the environment is converted from
POSIX to Win32, including the SHELL environment variable. In Git for
Windows, for example, `SHELL=/usr/bin/bash` is converted to
`SHELL=C:\Program Files\Git\usr\bin\bash.exe` when calling the `git.exe`
binary. This is appropriate because non-MSys2 binaries would not handle
POSIX paths correctly.
Under certain circumstances, however, `git.exe` calls an *MSys2* binary in
turn, such as `git config --edit` calling `vim.exe` unless Git is
configured to use another editor specifically.
Now, when this "improved vi" calls shell commands, it uses that $SHELL
variable *without quoting*, resulting in a nasty error:
C:\Program: No such file or directory
Many other programs behave in the same manner, assuming that $SHELL does
not contain spaces and hence needs no quoting, unfortunately including
some of Git's own scripts.
Therefore let's make sure that $SHELL gets "posified" again when entering
MSys2 programs.
Earlier attempts by Git for Windows contributors claimed that adding
`SHELL` to the `conv_envvars` array does not have the intended effect.
These reports just missed that the `conv_start_chars` array (which makes
the code more performant) needs to be adjusted, too.
Note that we set the `immediate` flag to `true` so that the environment
variable is set immediately by the MSys2 runtime, i.e. not only spawned
processes will see the POSIX-ified `SHELL` variable, but the MSys2 runtime
*itself*, too.
This fixes https://github.com/git-for-windows/git/issues/542,
https://github.com/git-for-windows/git/issues/498, and
https://github.com/git-for-windows/git/issues/468.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
msys2/msys2-runtime@4e9612f
[New msys2-runtime version] install-libs: depend on the "toollibs"
install-libs: depend on the "toollibs"
Before symlinking libg.a, we need the symlink source `libmsys-2.0.a`: in
MSYS2, we copy by default (if we were creating Unix-style symlinks, the
target would not have to exist before symlinking, but when copying we do
need the source _right away_).
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
msys2/msys2-runtime@b0fcf02
[New msys2-runtime version] docs: skip building texinfo and PDF files
docs: skip building texinfo and PDF files
The MSYS2 packages lack the infrastructure to build those.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
msys2/msys2-runtime@a0d53e4
[New msys2-runtime version] Cygwin: make option for native inner link handling.
Cygwin: make option for native inner link handling.
This code has been causing issues with SUBST and mapped network drives,
so add an option (defaulted to on) which can be used to disable it where
needed. MSYS=nonativeinnerlinks
msys2/msys2-runtime@450800b
[New msys2-runtime version] kill: kill Win32 processes more gently
kill: kill Win32 processes more gently
This change is the equivalent to the change to the Ctrl+C handling we
just made.
Co-authored-by: Naveen M K <naveen@syrusdark.website>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
msys2/msys2-runtime@5e19738
[New msys2-runtime version] Emulate GenerateConsoleCtrlEvent() upon Ctrl+C
Emulate GenerateConsoleCtrlEvent() upon Ctrl+C
This patch is heavily inspired by the Git for Windows' strategy in
handling Ctrl+C.
When a process is terminated via TerminateProcess(), it has no chance to
do anything in the way of cleaning up. This is particularly noticeable
when a lengthy Git for Windows process tries to update Git's index file
and leaves behind an index.lock file. Git's idea is to remove the stale
index.lock file in that case, using the signal and atexit handlers
available in Linux. But those signal handlers never run.
Note: this is not an issue for MSYS2 processes because MSYS2 emulates
Unix' signal system accurately, both for the process sending the kill
signal and the process receiving it. Win32 processes do not have such a
signal handler, though, instead MSYS2 shuts them down via
`TerminateProcess()`.
For a while, Git for Windows tried to use a gentler method, described in
the Dr Dobb's article "A Safer Alternative to TerminateProcess()" by
Andrew Tucker (July 1, 1999),
http://www.drdobbs.com/a-safer-alternative-to-terminateprocess/184416547
Essentially, we injected a new thread into the running process that does
nothing else than running the ExitProcess() function.
However, this was still not in line with the way CMD handles Ctrl+C: it
gives processes a chance to do something upon Ctrl+C by calling
SetConsoleCtrlHandler(), and ExitProcess() simply never calls that
handler.
So for a while we tried to handle SIGINT/SIGTERM by attaching to the
console of the command to interrupt, and generating the very same event
as CMD does via GenerateConsoleCtrlEvent().
This method *still* was not correct, though, as it would interrupt
*every* process attached to that Console, not just the process (and its
children) that we wanted to signal. A symptom was that hitting Ctrl+C
while `git log` was shown in the pager would interrupt *the pager*.
The method we settled on is to emulate what GenerateConsoleCtrlEvent()
does, but on a process by process basis: inject a remote thread and call
the (private) function kernel32!CtrlRoutine.
To obtain said function's address, we use the dbghelp API to generate a
stack trace from a handler configured via SetConsoleCtrlHandler() and
triggered via GenerateConsoleCtrlEvent(). To avoid killing each and all
processes attached to the same Console as the MSYS2 runtime, we modify
the cygwin-console-helper to optionally print the address of
kernel32!CtrlRoutine to stdout, and then spawn it with a new Console.
Note that this also opens the door to handling 32-bit process from a
64-bit MSYS2 runtime and vice versa, by letting the MSYS2 runtime look
for the cygwin-console-helper.exe of the "other architecture" in a
specific place (we choose /usr/libexec/, as it seems to be the
convention for helper .exe files that are not intended for public
consumption).
The 32-bit helper implicitly links to libgcc_s_dw2.dll and
libwinpthread-1.dll, so to avoid cluttering /usr/libexec/, we look for
the helped of the "other" architecture in the corresponding mingw32/ or
mingw64/ subdirectory.
Among other bugs, this strategy to handle Ctrl+C fixes the MSYS2 side of
the bug where interrupting `git clone https://...` would send the
spawned-off `git remote-https` process into the background instead of
interrupting it, i.e. the clone would continue and its progress would be
reported mercilessly to the console window without the user being able
to do anything about it (short of firing up the task manager and killing
the appropriate task manually).
Note that this special-handling is only necessary when *MSYS2* handles
the Ctrl+C event, e.g. when interrupting a process started from within
MinTTY or any other non-cmd-based terminal emulator. If the process was
started from within `cmd.exe`'s terminal window, child processes are
already killed appropriately upon Ctrl+C, by `cmd.exe` itself.
Also, we can't trust the processes to end it's subprocesses upon receiving
Ctrl+C. For example, `pip.exe` from `python-pip` doesn't kill the python
it lauches (it tries to but fails), and I noticed that in cmd it kills python
also correctly, which mean we should kill all the process using
`exit_process_tree`.
Co-authored-by: Naveen M K <naveen@syrusdark.website>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
msys2/msys2-runtime@b2413eb
[New msys2-runtime version] Add a helper to obtain a function's address in kernel32.dll
Add a helper to obtain a function's address in kernel32.dll
In particular, we are interested in the address of the CtrlRoutine
and the ExitProcess functions. Since kernel32.dll is loaded first thing,
the addresses will be the same for all processes (matching the
CPU architecture, of course).
This will help us with emulating SIGINT properly (by not sending signals
to *all* processes attached to the same Console, as
GenerateConsoleCtrlEvent() would do).
Co-authored-by: Naveen M K <naveen@syrusdark.website>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
msys2/msys2-runtime@9abc090
[New msys2-runtime version] Expose full command-lines to other Win32 processes by default
Expose full command-lines to other Win32 processes by default
In the Cygwin project, it was decided that the command-line of Cygwin
processes, as shown in the output of `wmic process list`, would suffer
from being truncated to 32k (and is transmitted to the child process via
a different mechanism, anyway), and therefore only the absolute path of
the executable is shown by default.
Users who would like to see the full command-line (even if it is
truncated) are expected to set `CYGWIN=wincmdln` (or, in MSYS2's case,
`MSYS=wincmdln`).
Seeing as MSYS2 tries to integrate much better with the surrounding
Win32 ecosystem than Cygwin, it makes sense to turn this on by default.
Users who wish to suppress it can still set `MSYS=nowincmdln`.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
msys2/msys2-runtime@7a40bbe
[New msys2-runtime version] Set up a GitHub Action to keep in sync with Cygwin
Set up a GitHub Action to keep in sync with Cygwin
This will help us by automating an otherwise tedious task.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
msys2/msys2-runtime@1f25400
[New msys2-runtime version] CI: add a GHA for doing a basic build test
CI: add a GHA for doing a basic build test
Build with --disable-dependency-tracking because we only build once
and this saves 3-4 minutes in CI.
msys2/msys2-runtime@cd14361
[New msys2-runtime version] Cygwin: Fix segfault when XSAVE area sizes are unaligned
msys2/msys2-runtime@aa532e7
[New msys2-runtime version] Cygwin: Adjust CWD magic to accommodate for the latest Windows previews
msys2/msys2-runtime@cb25225
[New msys2-runtime version] uname: report msys2-runtime commit hash, too
msys2/msys2-runtime@adee13c
[New msys2-runtime version] Avoid sharing cygheaps across Cygwin versions
msys2/msys2-runtime@546c331
[New msys2-runtime version] Revert "Cygwin: Enable dynamicbase on the Cygwin DLL by default"
msys2/msys2-runtime@66cfb0c
[New msys2-runtime version] build_env(): respect the
MSYSenvironment variablemsys2/msys2-runtime@9c78766
[New msys2-runtime version] Optionally disallow empty environment values again
msys2/msys2-runtime@d064b00
[New msys2-runtime version] Pass environment variables with empty values
msys2/msys2-runtime@8fdf344
[New msys2-runtime version] uname: allow setting the system name to CYGWIN
msys2/msys2-runtime@2f1036a
[New msys2-runtime version] Handle ORIGINAL_PATH just like PATH
msys2/msys2-runtime@79885de
[New msys2-runtime version] POSIX-ify the SHELL variable
msys2/msys2-runtime@4e9612f
[New msys2-runtime version] install-libs: depend on the "toollibs"
msys2/msys2-runtime@b0fcf02
[New msys2-runtime version] docs: skip building texinfo and PDF files
msys2/msys2-runtime@a0d53e4
[New msys2-runtime version] Cygwin: make option for native inner link handling.
msys2/msys2-runtime@450800b
[New msys2-runtime version] kill: kill Win32 processes more gently
msys2/msys2-runtime@5e19738
[New msys2-runtime version] Emulate GenerateConsoleCtrlEvent() upon Ctrl+C
msys2/msys2-runtime@b2413eb
[New msys2-runtime version] Add a helper to obtain a function's address in kernel32.dll
msys2/msys2-runtime@9abc090
[New msys2-runtime version] Expose full command-lines to other Win32 processes by default
msys2/msys2-runtime@7a40bbe
[New msys2-runtime version] Set up a GitHub Action to keep in sync with Cygwin
msys2/msys2-runtime@1f25400
[New msys2-runtime version] CI: add a GHA for doing a basic build test
msys2/msys2-runtime@cd14361