Try and upgrade to Git for Windows 2.40.0 (or the latest)
It includes:
When trying to call Cygwin (or for that matter, MSYS2) programs from Git Bash, users would frequently be greeted with cryptic error messages about a "cygheap
" or even just an even more puzzling exit code 127.
Many of these calls now succeed, allowing basic interactions.
While it is still not possible for, say, Cygwin's vim.exe
to interact with the Git Bash's terminal window, it is now possible for Cygwin's zstd.exe
in conjunction with Git for Windows' tar.exe
to handle .tar.zst
archives.
See git-for-windows/git
issue 4255 for a analysis of the issue:
Git for Windows includes a component that needs to be pinned in memory
at a known location, so that the Unix-like shell that git bash
uses
can find it.
Anything that moves the component – ASLR, rebasing due to
address conflicts, etc. – will cause the component to stop working.
The specific failure case here seems to be that when you’ve got
multiple versions of Git for Windows installed of the same bitness, if
that shared component DLL isn’t binary-identical across those
versions, the second one that is loaded into memory will be
automatically rebased and stop working.
The affected component is msys-2.0.dll
, which is present at (for
example):
C:\Program Files\Microsoft Visual Studio\2022\Professional\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\Git\usr\bin
for a typical Visual Studio installation; and
C:\Program Files\Git\usr\bin
within a typical Git for Windows
installation.
It seems that this problem may have started occurring when VS 2022
began to include 64-bit git components, at version 17.2.0.
The problem
is heavily dependent on the version of the Git for Windows
installation that is side-by-side with VS 2022; with GfW 2.35.2
against VS 2022 17.2.0, the problem is reproducible.
Updating VS 2022 to 17.2.7 moves its internal Git installation to 2.37.1 and the problem appears to cease; however, it seems likely that further
changes to either Git installation could cause the problem to recur.
Any git
operation taken from within Visual Studio in this state will
fail with a base address mismatch in the MSYS component, with this
output:
0 [main] which (4152) C:\Program Files\Git\usr\bin\which.exe: ***
fatal error - cygheap base mismatch detected - 0x18034B408/0x180349408.
This problem is probably due to using incompatible versions of the cygwin DLL.
Johannes Schindelin adds:
The root cause of these issues is that the MSYS2 runtime (or for that matter, the Cygwin runtime, from which the MSYS2 runtime is forked) needs to emulate certain POSIX functionality, e.g. the fork()
syscall, and said emulation requires the child processes to talk to their parent processes "before the child process starts up for real".
This communication happens via shared memory that is called the "Cygwin heap".
And naturally, such communication will only succeed if both parent and child process have a very, very similar idea of the shape of that Cygwin heap.
If they have even slightly different ideas, some of those bytes in that shared memory are misinterpreted by one side and chaos ensues. Or crashes. Or aborts with a cryptic message about some "cygheap base mismatch, whatever that is".
Now, the Cygwin runtime is very careful to version the definition of that Cygwin heap so that even different Cygwin runtimes have a chance to talk to each other.
It is quite possible that by rebasing the MSYS2 runtime's custom changes on top of newer Cygwin runtime versions, we miss some steps and inadvertently break that shared memory format versioning.
I implemented a pretty big hammer here, which seems to do the job by telling any two different MSYS2 runtime versions that they simply cannot talk to each other.
See