From 75cd57a982724352a9c13e439d67b4fed1d407df Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Mon, 30 Jan 2023 23:22:22 +0100 Subject: [PATCH] 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. 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 Signed-off-by: Johannes Schindelin --- winsup/cygwin/dcrt0.cc | 2 +- winsup/cygwin/sigproc.cc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/winsup/cygwin/dcrt0.cc b/winsup/cygwin/dcrt0.cc index 300b31c41c..fc682bbccf 100644 --- a/winsup/cygwin/dcrt0.cc +++ b/winsup/cygwin/dcrt0.cc @@ -530,7 +530,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) + || res->intro != PROC_MAGIC_GENERIC || res->magic != (CHILD_INFO_MAGIC ^ CYGWIN_VERSION_DLL_COMBINED)) { strace.activate (false); res = NULL; diff --git a/winsup/cygwin/sigproc.cc b/winsup/cygwin/sigproc.cc index fd3291c1bc..374ca32480 100644 --- a/winsup/cygwin/sigproc.cc +++ b/winsup/cygwin/sigproc.cc @@ -811,7 +811,7 @@ int child_info::retry_count = 0; child_info::child_info (unsigned in_cb, child_info_types chtype, bool need_subproc_ready): msv_count (0), cb (in_cb), intro (PROC_MAGIC_GENERIC), - magic (CHILD_INFO_MAGIC), type (chtype), cygheap (::cygheap), + magic (CHILD_INFO_MAGIC ^ CYGWIN_VERSION_DLL_COMBINED), 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) {