Skip to content

Commit

Permalink
msys2-runtime: improve "avoid sharing incompatible cygheaps" logic
Browse files Browse the repository at this point in the history
This brings the patches of
git-for-windows/msys2-runtime#49 into
MSYS2-packages.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
  • Loading branch information
dscho committed Feb 21, 2023
1 parent d10bf5b commit df9725b
Show file tree
Hide file tree
Showing 4 changed files with 266 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
From f5f594c2ff906aabdfb440d032687569231c5d98 Mon Sep 17 00:00:00 2001
From: Johannes Schindelin <johannes.schindelin@gmx.de>
Date: Tue, 21 Feb 2023 15:21:03 +0100
Subject: [PATCH 62/N] amend! Avoid sharing cygheaps across Cygwin versions

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
https://github.com/git-for-windows/git/issues/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>
---
winsup/configure.ac | 28 ++++++++++++++++++++++++++++
winsup/cygwin/Makefile.am | 3 +++
winsup/cygwin/dcrt0.cc | 2 +-
winsup/cygwin/sigproc.cc | 2 +-
4 files changed, 33 insertions(+), 2 deletions(-)

diff --git a/winsup/configure.ac b/winsup/configure.ac
index ca2b8c0..cfb0bbf 100644
--- a/winsup/configure.ac
+++ b/winsup/configure.ac
@@ -57,6 +57,34 @@ AC_CHECK_TOOL(RANLIB, ranlib, ranlib)
AC_CHECK_TOOL(STRIP, strip, strip)
AC_CHECK_TOOL(WINDRES, windres, windres)

+# Record msys2-runtime commit
+AC_ARG_WITH([msys2-runtime-commit],
+ [AS_HELP_STRING([--with-msys2-runtime-commit=COMMIT],
+ [indicate the msys2-runtime commit corresponding to this build])],
+ [MSYS2_RUNTIME_COMMIT=$withval], [MSYS2_RUNTIME_COMMIT=yes])
+case "$MSYS2_RUNTIME_COMMIT" in
+no)
+ MSYS2_RUNTIME_COMMIT=
+ MSYS2_RUNTIME_COMMIT_HEX=0
+ ;;
+yes|auto)
+ if MSYS2_RUNTIME_COMMIT="$(git --git-dir="$srcdir/../.git" rev-parse HEAD)"
+ then
+ MSYS2_RUNTIME_COMMIT_HEX="0x$(expr "$MSYS2_RUNTIME_COMMIT" : '\(.\{,8\}\)')ull"
+ else
+ AC_MSG_WARN([Could not determine msys2-runtime commit"])
+ MSYS2_RUNTIME_COMMIT=
+ MSYS2_RUNTIME_COMMIT_HEX=0
+ fi
+ ;;
+*)
+ expr "$MSYS2_RUNTIME_COMMIT" : '@<:@0-9a-f@:>@\{6,64\}$' ||
+ AC_MSG_ERROR([Invalid commit name: "$MSYS2_RUNTIME_COMMIT"])
+ MSYS2_RUNTIME_COMMIT_HEX="0x$(expr "$MSYS2_RUNTIME_COMMIT" : '\(.\{,8\}\)')ull"
+ ;;
+esac
+AC_SUBST(MSYS2_RUNTIME_COMMIT_HEX)
+
AC_ARG_ENABLE(debugging,
[ --enable-debugging Build a cygwin DLL which has more consistency checking for debugging],
[case "${enableval}" in
diff --git a/winsup/cygwin/Makefile.am b/winsup/cygwin/Makefile.am
index 01666e1..695ebeb 100644
--- a/winsup/cygwin/Makefile.am
+++ b/winsup/cygwin/Makefile.am
@@ -17,6 +17,9 @@ if TARGET_X86_64
COMMON_CFLAGS+=-mcmodel=small
endif

+VERSION_CFLAGS = -DMSYS2_RUNTIME_COMMIT_HEX="@MSYS2_RUNTIME_COMMIT_HEX@"
+COMMON_CFLAGS += $(VERSION_CFLAGS)
+
AM_CFLAGS=$(cflags_common) $(COMMON_CFLAGS)
AM_CXXFLAGS=$(cxxflags_common) $(COMMON_CFLAGS) -fno-threadsafe-statics

diff --git a/winsup/cygwin/dcrt0.cc b/winsup/cygwin/dcrt0.cc
index 45f3b0f..d354eab 100644
--- a/winsup/cygwin/dcrt0.cc
+++ b/winsup/cygwin/dcrt0.cc
@@ -545,7 +545,7 @@ get_cygwin_startup_info ()
child_info *res = (child_info *) si.lpReserved2;

if (si.cbReserved2 < EXEC_MAGIC_SIZE || !res
- || res->intro != PROC_MAGIC_GENERIC || res->magic != (CHILD_INFO_MAGIC ^ CYGWIN_VERSION_DLL_COMBINED))
+ || res->intro != PROC_MAGIC_GENERIC || res->magic != (CHILD_INFO_MAGIC ^ MSYS2_RUNTIME_COMMIT_HEX))
{
strace.activate (false);
res = NULL;
diff --git a/winsup/cygwin/sigproc.cc b/winsup/cygwin/sigproc.cc
index 65dc523..782c0d9 100644
--- a/winsup/cygwin/sigproc.cc
+++ b/winsup/cygwin/sigproc.cc
@@ -817,7 +817,7 @@ int child_info::retry_count = 0;
by fork/spawn/exec. */
child_info::child_info (unsigned in_cb, child_info_types chtype,
bool need_subproc_ready):
- cb (in_cb), intro (PROC_MAGIC_GENERIC), magic (CHILD_INFO_MAGIC ^ CYGWIN_VERSION_DLL_COMBINED),
+ cb (in_cb), intro (PROC_MAGIC_GENERIC), magic (CHILD_INFO_MAGIC ^ MSYS2_RUNTIME_COMMIT_HEX),
type (chtype), cygheap (::cygheap), cygheap_max (::cygheap_max),
flag (0), retry (child_info::retry_count), rd_proc_pipe (NULL),
wr_proc_pipe (NULL), sigmask (_my_tls.sigmask)
129 changes: 129 additions & 0 deletions msys2-runtime/0063-uname-report-msys2-runtime-commit-hash-too.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
From bec3d608e863dc48f447bd365448ea4274cc3ce6 Mon Sep 17 00:00:00 2001
From: Johannes Schindelin <johannes.schindelin@gmx.de>
Date: Tue, 21 Feb 2023 16:36:36 +0100
Subject: [PATCH 63/N] 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>
---
winsup/configure.ac | 10 ++++++++--
winsup/cygwin/Makefile.am | 6 ++++--
winsup/cygwin/mkvers.sh | 8 ++++++++
winsup/cygwin/uname.cc | 3 ++-
4 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/winsup/configure.ac b/winsup/configure.ac
index cfb0bbf..ace0126 100644
--- a/winsup/configure.ac
+++ b/winsup/configure.ac
@@ -65,24 +65,30 @@ AC_ARG_WITH([msys2-runtime-commit],
case "$MSYS2_RUNTIME_COMMIT" in
no)
MSYS2_RUNTIME_COMMIT=
+ MSYS2_RUNTIME_COMMIT_SHORT=
MSYS2_RUNTIME_COMMIT_HEX=0
;;
yes|auto)
if MSYS2_RUNTIME_COMMIT="$(git --git-dir="$srcdir/../.git" rev-parse HEAD)"
then
- MSYS2_RUNTIME_COMMIT_HEX="0x$(expr "$MSYS2_RUNTIME_COMMIT" : '\(.\{,8\}\)')ull"
+ MSYS2_RUNTIME_COMMIT_SHORT="$(expr "$MSYS2_RUNTIME_COMMIT" : '\(.\{,8\}\)')"
+ MSYS2_RUNTIME_COMMIT_HEX="0x${MSYS2_RUNTIME_COMMIT_SHORT}ul"
else
AC_MSG_WARN([Could not determine msys2-runtime commit"])
MSYS2_RUNTIME_COMMIT=
+ MSYS2_RUNTIME_COMMIT_SHORT=
MSYS2_RUNTIME_COMMIT_HEX=0
fi
;;
*)
expr "$MSYS2_RUNTIME_COMMIT" : '@<:@0-9a-f@:>@\{6,64\}$' ||
AC_MSG_ERROR([Invalid commit name: "$MSYS2_RUNTIME_COMMIT"])
- MSYS2_RUNTIME_COMMIT_HEX="0x$(expr "$MSYS2_RUNTIME_COMMIT" : '\(.\{,8\}\)')ull"
+ MSYS2_RUNTIME_COMMIT_SHORT="$(expr "$MSYS2_RUNTIME_COMMIT" : '\(.\{,8\}\)')"
+ MSYS2_RUNTIME_COMMIT_HEX="0x${MSYS2_RUNTIME_COMMIT_SHORT}ul"
;;
esac
+AC_SUBST(MSYS2_RUNTIME_COMMIT)
+AC_SUBST(MSYS2_RUNTIME_COMMIT_SHORT)
AC_SUBST(MSYS2_RUNTIME_COMMIT_HEX)

AC_ARG_ENABLE(debugging,
diff --git a/winsup/cygwin/Makefile.am b/winsup/cygwin/Makefile.am
index 695ebeb..58551de 100644
--- a/winsup/cygwin/Makefile.am
+++ b/winsup/cygwin/Makefile.am
@@ -17,7 +17,9 @@ if TARGET_X86_64
COMMON_CFLAGS+=-mcmodel=small
endif

-VERSION_CFLAGS = -DMSYS2_RUNTIME_COMMIT_HEX="@MSYS2_RUNTIME_COMMIT_HEX@"
+VERSION_CFLAGS = -DMSYS2_RUNTIME_COMMIT="\"@MSYS2_RUNTIME_COMMIT@\""
+VERSION_CFLAGS += -DMSYS2_RUNTIME_COMMIT_SHORT="\"@MSYS2_RUNTIME_COMMIT_SHORT@\""
+VERSION_CFLAGS += -DMSYS2_RUNTIME_COMMIT_HEX="@MSYS2_RUNTIME_COMMIT_HEX@"
COMMON_CFLAGS += $(VERSION_CFLAGS)

AM_CFLAGS=$(cflags_common) $(COMMON_CFLAGS)
@@ -408,7 +410,7 @@ src_files := $(foreach dir,$(dirs),$(find_src_files))
version.cc: mkvers.sh include/cygwin/version.h winver.rc $(src_files)
@echo "Making version.cc and winver.o";\
export CC="$(CC)";\
- /bin/sh $(word 1,$^) $(word 2,$^) $(word 3,$^) $(WINDRES) $(CFLAGS)
+ /bin/sh $(word 1,$^) $(word 2,$^) $(word 3,$^) $(WINDRES) $(CFLAGS) $(VERSION_CFLAGS)

winver.o: version.cc

diff --git a/winsup/cygwin/mkvers.sh b/winsup/cygwin/mkvers.sh
index ee99dd0..54e131a 100755
--- a/winsup/cygwin/mkvers.sh
+++ b/winsup/cygwin/mkvers.sh
@@ -16,6 +16,7 @@ incfile="$1"; shift
rcfile="$1"; shift
windres="$1"; shift
iflags=
+msys2_runtime_commit=
# Find header file locations
while [ -n "$*" ]; do
case "$1" in
@@ -26,6 +27,9 @@ while [ -n "$*" ]; do
shift
iflags="$iflags -I$1"
;;
+ -DMSYS2_RUNTIME_COMMIT=*)
+ msys2_runtime_commit="${1#*=}"
+ ;;
esac
shift
done
@@ -185,6 +189,10 @@ then
cvs_tag="$(echo $wv_cvs_tag | sed -e 's/-branch.*//')"
cygwin_ver="$cygwin_ver-$cvs_tag"
fi
+if [ -n "$msys2_runtime_commit" ]
+then
+ cygwin_ver="$cygwin_ver-$msys2_runtime_commit"
+fi

echo "Version $cygwin_ver"
set -$- $builddate
diff --git a/winsup/cygwin/uname.cc b/winsup/cygwin/uname.cc
index f6a5f88..4bc5c09 100644
--- a/winsup/cygwin/uname.cc
+++ b/winsup/cygwin/uname.cc
@@ -64,10 +64,11 @@ uname_x (struct utsname *name)
cygwin_gethostname (buf, sizeof buf - 1);
strncat (name->nodename, buf, sizeof (name->nodename) - 1);
/* release */
- __small_sprintf (name->release, "%d.%d.%d-%d.",
+ __small_sprintf (name->release, "%d.%d.%d-%s-%d.",
cygwin_version.dll_major / 1000,
cygwin_version.dll_major % 1000,
cygwin_version.dll_minor,
+ MSYS2_RUNTIME_COMMIT_SHORT,
cygwin_version.api_minor);
/* version */
stpcpy (name->version, cygwin_version.dll_build_date);
10 changes: 7 additions & 3 deletions msys2-runtime/PKGBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
pkgbase=msys2-runtime
pkgname=('msys2-runtime' 'msys2-runtime-devel')
pkgver=3.3.6
pkgrel=3
pkgrel=4
pkgdesc="Cygwin POSIX emulation engine"
arch=('i686' 'x86_64')
url="https://www.cygwin.com/"
Expand Down Expand Up @@ -86,7 +86,8 @@ source=('msys2-runtime'::git+https://github.com/cygwin/cygwin#tag=cygwin-${pkgve
0059-Avoid-sharing-cygheaps-across-Cygwin-versions.patch
0060-dumper-avoid-linker-problem-when-libbfd-depends-on-l.patch
0061-Cygwin-console-Fix-hangup-of-less-on-quit-after-the-.patch
msys2-runtime.commit)
0062-amend-Avoid-sharing-cygheaps-across-Cygwin-versions.patch
0063-uname-report-msys2-runtime-commit-hash-too.patch)
sha256sums=('SKIP'
'c375315e58181ee5589b7966101aa095de3f864a579c3c3f0f0683595d4e428d'
'01ea2b131cf5a3b27fdbc458019eac14e45a36782ce3ce33e62328eefcd2d02e'
Expand Down Expand Up @@ -149,7 +150,8 @@ sha256sums=('SKIP'
'865bcaa5dc7275a79d732241c7e61c4c22cda537d1764227b96c9dd89a623593'
'6abfae0da52df37dcbde6eca92d66e5abd8a4e5460efc36fd7ce593fd9c9bad3'
'433685c3c366f0aa077d1230f027ed9314e7f0b1e91d4e98e6bfbaa92ed18f89'
'0935600af15cfcbe4265679b74e2cada9a4b117137e3a024620341875e254544')
'4b55c8fd81bdf4c552433e79fe24db7e1289ed3b99cd9c4d1272f1336b1a8b4b'
'7865ca781926f104a15fd659432b6b72462f54125c351122195b2314c6c74cf3')

# Helper macro to help make tasks easier #
del_file_exists() {
Expand Down Expand Up @@ -237,6 +239,8 @@ prepare() {
git am --committer-date-is-author-date --ignore-space-change "${srcdir}"/0059-Avoid-sharing-cygheaps-across-Cygwin-versions.patch
git am --committer-date-is-author-date --ignore-space-change "${srcdir}"/0060-dumper-avoid-linker-problem-when-libbfd-depends-on-l.patch
git am --committer-date-is-author-date --ignore-space-change "${srcdir}"/0061-Cygwin-console-Fix-hangup-of-less-on-quit-after-the-.patch
git am --committer-date-is-author-date --ignore-space-change "${srcdir}"/0062-amend-Avoid-sharing-cygheaps-across-Cygwin-versions.patch
git am --committer-date-is-author-date --ignore-space-change "${srcdir}"/0063-uname-report-msys2-runtime-commit-hash-too.patch
}

build() {
Expand Down
2 changes: 1 addition & 1 deletion msys2-runtime/msys2-runtime.commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8a2855c182ed7117bae3c4eb8a17eb8f26b27891
bec3d608e863dc48f447bd365448ea4274cc3ce6

0 comments on commit df9725b

Please sign in to comment.