Skip to content

Commit baade52

Browse files
committed
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 <[email protected]>
1 parent 97086fd commit baade52

File tree

4 files changed

+33
-2
lines changed

4 files changed

+33
-2
lines changed

winsup/configure.ac

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,34 @@ AC_CHECK_TOOL(RANLIB, ranlib, ranlib)
5757
AC_CHECK_TOOL(STRIP, strip, strip)
5858
AC_CHECK_TOOL(WINDRES, windres, windres)
5959

60+
# Record msys2-runtime commit
61+
AC_ARG_WITH([msys2-runtime-commit],
62+
[AS_HELP_STRING([--with-msys2-runtime-commit=COMMIT],
63+
[indicate the msys2-runtime commit corresponding to this build])],
64+
[MSYS2_RUNTIME_COMMIT=$withval], [MSYS2_RUNTIME_COMMIT=yes])
65+
case "$MSYS2_RUNTIME_COMMIT" in
66+
no)
67+
MSYS2_RUNTIME_COMMIT=
68+
MSYS2_RUNTIME_COMMIT_HEX=0
69+
;;
70+
yes|auto)
71+
if MSYS2_RUNTIME_COMMIT="$(git --git-dir="$srcdir/../.git" rev-parse HEAD)"
72+
then
73+
MSYS2_RUNTIME_COMMIT_HEX="0x$(expr "$MSYS2_RUNTIME_COMMIT" : '\(.\{,8\}\)')ull"
74+
else
75+
AC_MSG_WARN([Could not determine msys2-runtime commit])
76+
MSYS2_RUNTIME_COMMIT=
77+
MSYS2_RUNTIME_COMMIT_HEX=0
78+
fi
79+
;;
80+
*)
81+
expr "$MSYS2_RUNTIME_COMMIT" : '@<:@0-9a-f@:>@\{6,64\}$' ||
82+
AC_MSG_ERROR([Invalid commit name: "$MSYS2_RUNTIME_COMMIT"])
83+
MSYS2_RUNTIME_COMMIT_HEX="0x$(expr "$MSYS2_RUNTIME_COMMIT" : '\(.\{,8\}\)')ull"
84+
;;
85+
esac
86+
AC_SUBST(MSYS2_RUNTIME_COMMIT_HEX)
87+
6088
AC_ARG_ENABLE(debugging,
6189
[AS_HELP_STRING([--enable-debugging],[Build a cygwin DLL which has more consistency checking for debugging])],
6290
[case "${enableval}" in

winsup/cygwin/Makefile.am

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ if TARGET_X86_64
1717
COMMON_CFLAGS+=-mcmodel=small
1818
endif
1919

20+
VERSION_CFLAGS = -DMSYS2_RUNTIME_COMMIT_HEX="@MSYS2_RUNTIME_COMMIT_HEX@"
21+
COMMON_CFLAGS += $(VERSION_CFLAGS)
22+
2023
AM_CFLAGS=$(cflags_common) $(COMMON_CFLAGS)
2124
AM_CXXFLAGS=$(cxxflags_common) $(COMMON_CFLAGS) -fno-threadsafe-statics
2225

winsup/cygwin/dcrt0.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ get_cygwin_startup_info ()
531531
child_info *res = (child_info *) si.lpReserved2;
532532

533533
if (si.cbReserved2 < EXEC_MAGIC_SIZE || !res
534-
|| res->intro != PROC_MAGIC_GENERIC || res->magic != CHILD_INFO_MAGIC)
534+
|| res->intro != PROC_MAGIC_GENERIC || res->magic != (CHILD_INFO_MAGIC ^ MSYS2_RUNTIME_COMMIT_HEX))
535535
{
536536
strace.activate (false);
537537
res = NULL;

winsup/cygwin/sigproc.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -893,7 +893,7 @@ int child_info::retry_count = 0;
893893
child_info::child_info (unsigned in_cb, child_info_types chtype,
894894
bool need_subproc_ready):
895895
msv_count (0), cb (in_cb), intro (PROC_MAGIC_GENERIC),
896-
magic (CHILD_INFO_MAGIC), type (chtype), cygheap (::cygheap),
896+
magic (CHILD_INFO_MAGIC ^ MSYS2_RUNTIME_COMMIT_HEX), type (chtype), cygheap (::cygheap),
897897
cygheap_max (::cygheap_max), flag (0), retry (child_info::retry_count),
898898
rd_proc_pipe (NULL), wr_proc_pipe (NULL), sigmask (_my_tls.sigmask)
899899
{

0 commit comments

Comments
 (0)