Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MinGit can be incompatible with Git for Windows installation of the same bitness #4255

Closed
luhansen-ms opened this issue Jan 28, 2023 · 13 comments · Fixed by git-for-windows/msys2-runtime#48 or git-for-windows/MSYS2-packages#77
Labels
Milestone

Comments

@luhansen-ms
Copy link

Summary:

This Issue is in reference to a ticket that was filed with us in Visual Studio. However, we believe the underlying issue to be related to mismatched versions of MinGit/Git for Windows. I haven't been able to reproduce the issue myself, but there is a lot of good info provided by the affected user in the linked ticket that might make more sense here.

Duplicate info from Linked Ticket

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.
Search for cygwin1.dll using the Windows Start->Find/Search facility
and delete all but the most recent version.  The most recent version *should*
reside in x:\cygwin\bin, where 'x' is the drive on which you have
installed the cygwin distribution.  Rebooting is also suggested if you
are unable to find another cygwin DLL.

Questions

I haven't found any existing resources mentioning this happening with 64bit git. Does this sound like an expected scenario? Are there any workarounds besides ensuring that all git processes on the system are compatible versions of Git+msys2?


  • [ X] I was not able to find an open or closed issue matching what I'm seeing

Setup

  • Which version of Git for Windows are you using? Is it 32-bit or 64-bit? 64 bit
MinGit: 2.36.0
GfW: 2.35.2
  • Which version of Windows are you running? Vista, 7, 8, 10? Is it 32-bit or 64-bit?
Windows 10
  • What options did you set as part of the installation? Or did you choose the
    defaults?
unknown at this time
  • Any other interesting things about your environment that might be related
    to the issue you're seeing?

I can ask this in the linked ticket.

Details

  • Which terminal/shell are you running Git from? e.g Bash/CMD/PowerShell/other
    GfW: unknown
    MinGit: VS spawns git.exe process directly via Kernel32.CreateProcess

  • What commands did you run to trigger this issue? If you can provide a
    Minimal, Complete, and Verifiable example
    this will help us understand the issue.

seemingly occurs when GfW and MinGit load conflicting msys2 versions
@rimrul
Copy link
Member

rimrul commented Jan 28, 2023

Questions

I haven't found any existing resources mentioning this happening with 64bit git. Does this sound like an expected scenario?

Yes, this seems to be a likely scenario when using parts of Git for Windows that need a posix-ish environment.

Are there any workarounds besides ensuring that all git processes on the system are compatible versions of Git+msys2?

The rebasing method described in https://github.com/git-for-windows/git/wiki/32-bit-issues#adjusting-msys-20dlls-address-range-manually should work around this.

Using the busybox based MinGit would theoretically reduce this issue, but it is not currently considered production ready and does not prevent the issue completely IIRC.

The general effort to port more scripted parts of git to builtins should also help to slowly reduce this issue in future versions of Git for Windows.

When we update our Msys2 runtime to Cygwin 3.4 this issue should theoretically cease to exist completely, but that is currently on hold, because it drops support for i686 and has had a bunch of follow-up issues.

MinGit: VS spawns git.exe process directly via Kernel32.CreateProcess

That's good, that avoids imeadiately loading msys2-0.dll for bash. I don't know what commands you run from Visual Studio, but trying to avoid scripted commands would also help. The user could try to reduce this issue by using Git-CMD or Powershell instead of Git-Bash when working with Git for Windows while using MinGit through Visual Studio in parallel.

@rimrul rimrul added the msys2 label Jan 28, 2023
@vermiculus
Copy link

Even as most of the address-conflict talk is going over my head, I can add that we're able to reproduce this with git-fetch -- a built-in.

It's also worth noting that we have client hooks that invoke git.exe directly (via Process.Start) that would be triggered by actions from VS22's MinGit. Would these hooks be considered scripted Git? I would imagine so. In that case, I don't think there's anything the VS team can really do to prevent folks from invoking Git in client hooks -- and using Git in this way certainly has a reasonable expectation of not crashing.

If it's relevant: to get around the fact that VS22 lags substantially behind in Git releases, we also alter PATH early in our hooks such that the system Git is used. I imagine this is not something most folks would need to do.

@rimrul
Copy link
Member

rimrul commented Jan 30, 2023

It's also worth noting that we have client hooks that invoke git.exe directly (via Process.Start) that would be triggered by actions from VS22's MinGit. Would these hooks be considered scripted Git?

It's not what I had in mind when I wrote that part, but it could very well trigger this issue, depending on the shebang.

I would imagine so. In that case, I don't think there's anything the VS team can really do to prevent folks from invoking Git in client hooks

Right. The Visual studio team has little control over the hooks their users have in their repos. That's why I didn't originally talk about hooks. Invoking git isn't (directly) what's causing this issue. What's causing the issue, is invoking conflicting versions of the various unix tools in Git for Windows (which can happen through git, like for example with hooks). Basically anything in /usr/ will conflict with the same tools in other copies of Git for Windows.

and using Git in this way certainly has a reasonable expectation of not crashing.

Sure. We just don't have a reasonable way to make it not crash at the moment.

If it's relevant: to get around the fact that VS22 lags substantially behind in Git releases, we also alter PATH early in our hooks such that the system Git is used. I imagine this is not something most folks would need to do.

That might exacerbate the problem in your environment. Assuming your hooks are written as shell scripts their shebang is probably #!/bin/bash or similar, which will load the Msys2 runtime of MinGit. You'll then call the system Git with its unix tools that will in turn load a conflicting Msys2 runtime.

@filefull
Copy link

The rebasing method described in https://github.com/git-for-windows/git/wiki/32-bit-issues#adjusting-msys-20dlls-address-range-manually should work around this.

When attempting to work around this issue originally, I started with the rebasing approach but the steps as provided were ineffective for the 64-bit installation. I attempted to tweak the specified base address ranges and the parameters passed to rebase.exe but couldn't get it to work.

My only effective workaround (short of reinstalling Git for Windows with a version identical to the MinGit version embedded in Visual Studio at the time) was to directly copy+overwrite msys2-0.dll from the GfW installation directory to the VS installation directory, making them binary identical. I'm sure this approach is too fragile for actual production use, but it did "work".

Would it be possible to get an update to that 32-bit wiki with effective steps for a 64-bit installation, if those steps are known? Having a straightforward, scriptable workaround would be extremely helpful given that the proper fixes described above sound like they are still a ways off from being viable.

Thank you for the background information and details you've already provided...

dscho added a commit to dscho/msys2-runtime that referenced this issue Jan 30, 2023
It frequently leads to problems when trying, say, to call from Git for
Windows' Bash into Cygwin's or MSYS2's, merely because sharing that data
is pretty finicky.

For example, using the Git for Windows that is current at time of
writing, trying to call MSYS2's Bash from Git for Windows' Bash fails
somewhere in `_cmalloc()`, without any error message, and with the
rather misleading exit code 127 (a code which is reserved to indicate
that a command was not found).

Let's just treat these as completely incompatible with one another, by
virtue of using a different `CHILD_INFO_MAGIC` constant.

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.

This should also help the scenario where interactions between two
different versions of Git for Windows lead to those infamous `cygheap
base mismatch detected` problems mentioned e.g. in
git-for-windows/git#4255

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
@dscho
Copy link
Member

dscho commented Jan 30, 2023

I investigated this a bit.

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.

This would most likely address this here ticket, but it might be too big of a hammer (and therefore have unfortunate consequences that I simply haven't had a chance to think through yet).

I will let this simmer for a few days, welcoming any insights anybody else might have, and then try to finalize a fix.

dscho added a commit to dscho/msys2-runtime that referenced this issue Jan 30, 2023
It frequently leads to problems when trying, say, to call from Git for
Windows' Bash into Cygwin's or MSYS2's, merely because sharing that data
is pretty finicky.

For example, using the Git for Windows that is current at time of
writing, trying to call MSYS2's Bash from Git for Windows' Bash fails
somewhere in `_cmalloc()`, without any error message, and with the
rather misleading exit code 127 (a code which is reserved to indicate
that a command was not found).

Let's just treat these as completely incompatible with one another, by
virtue of using a different `CHILD_INFO_MAGIC` constant.

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.

This should also help the scenario where interactions between two
different versions of Git for Windows lead to those infamous `cygheap
base mismatch detected` problems mentioned e.g. in
git-for-windows/git#4255

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
@dscho dscho added this to the Next release milestone Jan 31, 2023
@luhansen-ms
Copy link
Author

Thanks all for the contributions to this issue, and to @dscho for getting that patch in. We'll look forward to using it!

@dscho
Copy link
Member

dscho commented Feb 1, 2023

@luhansen-ms you're welcome!

Could I ask for a favor in return? It would be good to get some confirmation that installing the latest snapshot does indeed fix the problem. Would you mind trying that and reporting back the result?

@luhansen-ms
Copy link
Author

luhansen-ms commented Feb 1, 2023

@dscho Indeed, I haven't been able to reproduce the issue myself, but we'll be syncing tomorrow with our user who can reproduce this consistently. We'll try to validate this with them over the next few days.

This was also before the topic of scripted (loading bash/msys) vs built-ins came up in this thread, so I'll give it another try myself.

@filefull
Copy link

filefull commented Feb 2, 2023

@dscho, testing with the latest snapshot I am unable to reproduce the bug, and haven't seen any other side effects or odd behaviors. Based on my understanding of the root cause and what you've done here, this looks like it should resolve things for us - thank you.

(I should however note that I am currently unable to reproduce the bug with released builds, either... but that's not particularly unusual - in my experience this has been pretty finicky. I've seen pairings of VS 2022 and GfW that will never have trouble because their git versions are synced, and pairings that will usually have trouble because they aren't, but none that will always have trouble.)

@luhansen-ms
Copy link
Author

Thanks for testing this out @filefull.

@dscho Would you expect that only one of the "mismatched versions" would need to be updated to take advantage of the fix? Said another way, either the first or second process to load msys2 could be the version with the fix, since the patched version would have generated the new magic number, and therefore either version would bail out before ever attempting to treat the "first" process as valid msys2/cygwin process to share the heap with?

@dscho
Copy link
Member

dscho commented Feb 2, 2023

Would you expect that only one of the "mismatched versions" would need to be updated to take advantage of the fix?

@luhansen-ms yes.

dscho added a commit to dscho/msys2-runtime that referenced this issue Feb 21, 2023
Avoid sharing cygheaps across Cygwin versions

It frequently leads to problems when trying, say, to call from Git for
Windows' Bash into Cygwin's or MSYS2's, merely because sharing that data
is pretty finicky.

For example, using the Git for Windows that is current at time of
writing, trying to call MSYS2's Bash from Git for Windows' Bash fails
somewhere in `_cmalloc()`, without any error message, and with the
rather misleading exit code 127 (a code which is reserved to indicate
that a command was not found).

Let's just treat these as completely incompatible with one another, by
virtue of using a different `CHILD_INFO_MAGIC` constant.

Let's take the msys2-runtime commit 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.

This should also help the scenario where interactions between two
different versions of Git for Windows lead to those infamous `cygheap
base mismatch detected` problems mentioned e.g. in
git-for-windows/git#4255

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 in `configure.ac`
files to encode brackets otherwise.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
dscho added a commit to dscho/msys2-runtime that referenced this issue Feb 21, 2023
Avoid sharing cygheaps across Cygwin versions

It frequently leads to problems when trying, say, to call from Git for
Windows' Bash into Cygwin's or MSYS2's, merely because sharing that data
is pretty finicky.

For example, using the Git for Windows that is current at time of
writing, trying to call MSYS2's Bash from Git for Windows' Bash fails
somewhere in `_cmalloc()`, without any error message, and with the
rather misleading exit code 127 (a code which is reserved to indicate
that a command was not found).

Let's just treat these as completely incompatible with one another, by
virtue of using a different `CHILD_INFO_MAGIC` constant.

Let's take the msys2-runtime commit 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.

This should also help the scenario where interactions between two
different versions of Git for Windows lead to those infamous `cygheap
base mismatch detected` problems mentioned e.g. in
git-for-windows/git#4255

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 in `configure.ac`
files to encode brackets otherwise.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
dscho added a commit to dscho/msys2-runtime that referenced this issue Feb 21, 2023
Avoid sharing cygheaps across Cygwin versions

It frequently leads to problems when trying, say, to call from Git for
Windows' Bash into Cygwin's or MSYS2's, merely because sharing that data
is pretty finicky.

For example, using the Git for Windows that is current at time of
writing, trying to call MSYS2's Bash from Git for Windows' Bash fails
somewhere in `_cmalloc()`, without any error message, and with the
rather misleading exit code 127 (a code which is reserved to indicate
that a command was not found).

Let's just treat these as completely incompatible with one another, by
virtue of using a different `CHILD_INFO_MAGIC` constant.

Let's take the msys2-runtime commit 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.

This should also help the scenario where interactions between two
different versions of Git for Windows lead to those infamous `cygheap
base mismatch detected` problems mentioned e.g. in
git-for-windows/git#4255

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 in `configure.ac`
files to encode brackets otherwise.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
@luhansen-ms
Copy link
Author

@dscho Is this looking like it would make its way into 2.40?

@dscho
Copy link
Member

dscho commented Feb 22, 2023

@luhansen-ms it already made it into v2.39.2...

github-actions bot pushed a commit to git-for-windows/build-extra that referenced this issue Feb 22, 2023
When trying to call Cygwin (or for that matter, MSYS2) programs from Git

about a "cygheap"](git-for-windows/git#4255)

[now](git-for-windows/msys2-runtime#48)

allowing basic interactions. While it is still not possible for, say,

_is_ now possible for Cygwin's `zstd.exe` in conjuction with Git for

Signed-off-by: gitforwindowshelper[bot] <gitforwindowshelper-bot@users.noreply.github.com>
dscho added a commit to dscho/msys2-runtime that referenced this issue May 12, 2023
It frequently leads to problems when trying, say, to call from Git for
Windows' Bash into Cygwin's or MSYS2's, merely because sharing that data
is pretty finicky.

For example, using the Git for Windows that is current at time of
writing, trying to call MSYS2's Bash from Git for Windows' Bash fails
somewhere in `_cmalloc()`, without any error message, and with the
rather misleading exit code 127 (a code which is reserved to indicate
that a command was not found).

Let's just treat these as completely incompatible with one another, by
virtue of using a different `CHILD_INFO_MAGIC` constant.

Let's take the msys2-runtime commit 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.

This should also help the scenario where interactions between two
different versions of Git for Windows lead to those infamous `cygheap
base mismatch detected` problems mentioned e.g. in
git-for-windows/git#4255

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 in `configure.ac`
files to encode brackets otherwise.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
dscho added a commit to dscho/msys2-runtime that referenced this issue Jun 16, 2023
It frequently leads to problems when trying, say, to call from Git for
Windows' Bash into Cygwin's or MSYS2's, merely because sharing that data
is pretty finicky.

For example, using the Git for Windows that is current at time of
writing, trying to call MSYS2's Bash from Git for Windows' Bash fails
somewhere in `_cmalloc()`, without any error message, and with the
rather misleading exit code 127 (a code which is reserved to indicate
that a command was not found).

Let's just treat these as completely incompatible with one another, by
virtue of using a different `CHILD_INFO_MAGIC` constant.

Let's take the msys2-runtime commit 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.

This should also help the scenario where interactions between two
different versions of Git for Windows lead to those infamous `cygheap
base mismatch detected` problems mentioned e.g. in
git-for-windows/git#4255

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 in `configure.ac`
files to encode brackets otherwise.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
dscho added a commit to dscho/msys2-runtime that referenced this issue Jun 19, 2023
It frequently leads to problems when trying, say, to call from Git for
Windows' Bash into Cygwin's or MSYS2's, merely because sharing that data
is pretty finicky.

For example, using the Git for Windows that is current at time of
writing, trying to call MSYS2's Bash from Git for Windows' Bash fails
somewhere in `_cmalloc()`, without any error message, and with the
rather misleading exit code 127 (a code which is reserved to indicate
that a command was not found).

Let's just treat these as completely incompatible with one another, by
virtue of using a different `CHILD_INFO_MAGIC` constant.

Let's take the msys2-runtime commit 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.

This should also help the scenario where interactions between two
different versions of Git for Windows lead to those infamous `cygheap
base mismatch detected` problems mentioned e.g. in
git-for-windows/git#4255

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 in `configure.ac`
files to encode brackets otherwise.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
dscho added a commit to dscho/msys2-runtime that referenced this issue Sep 6, 2023
It frequently leads to problems when trying, say, to call from Git for
Windows' Bash into Cygwin's or MSYS2's, merely because sharing that data
is pretty finicky.

For example, using the Git for Windows that is current at time of
writing, trying to call MSYS2's Bash from Git for Windows' Bash fails
somewhere in `_cmalloc()`, without any error message, and with the
rather misleading exit code 127 (a code which is reserved to indicate
that a command was not found).

Let's just treat these as completely incompatible with one another, by
virtue of using a different `CHILD_INFO_MAGIC` constant.

Let's take the msys2-runtime commit 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.

This should also help the scenario where interactions between two
different versions of Git for Windows lead to those infamous `cygheap
base mismatch detected` problems mentioned e.g. in
git-for-windows/git#4255

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 in `configure.ac`
files to encode brackets otherwise.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
dscho added a commit to dscho/msys2-runtime that referenced this issue Nov 29, 2023
It frequently leads to problems when trying, say, to call from Git for
Windows' Bash into Cygwin's or MSYS2's, merely because sharing that data
is pretty finicky.

For example, using the Git for Windows that is current at time of
writing, trying to call MSYS2's Bash from Git for Windows' Bash fails
somewhere in `_cmalloc()`, without any error message, and with the
rather misleading exit code 127 (a code which is reserved to indicate
that a command was not found).

Let's just treat these as completely incompatible with one another, by
virtue of using a different `CHILD_INFO_MAGIC` constant.

Let's take the msys2-runtime commit 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.

This should also help the scenario where interactions between two
different versions of Git for Windows lead to those infamous `cygheap
base mismatch detected` problems mentioned e.g. in
git-for-windows/git#4255

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 in `configure.ac`
files to encode brackets otherwise.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
5 participants