forked from msys2/MSYS2-packages
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
msys2-runtime: Implement fixes for Wine
This is intended to address msys2#682, and should eventually be upstreamed to Cygwin to resolve https://bugs.winehq.org/show_bug.cgi?id=40528 0025: Do not directly use FastPebLock on the Wine code-path Older versions of Wine did not populate this pointer, so instead call the exported ntdll.dll function, which works correctly in all cases. 0026: Do not use FAST_CWD on Wine The Cygwin cwd-handling code manipulates two internal Windows structures, the Process Information Block and an undocumented global dubbed FAST_CWD, in order to support some POSIX-like behaviours. Wine doesn't have FAST_CWD, so disable that part of the manipulation when Wine is detected. 0027: Unapplied logging change This simply outputs some logs so that a crash or other bad behaviour can be positively confirmed as being within or outside the CWD-override support in Cygwin. It should be dropped before applying, assuming everything else works.
- Loading branch information
Showing
4 changed files
with
215 additions
and
3 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
msys2-runtime/0025-Use-RtlAcquirePebLock-instead-of-peb.FastPebLock.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
From 3c3e60fdef10970b6646c220a3e69f8c43fa13ef Mon Sep 17 00:00:00 2001 | ||
From: "Paul \"TBBle\" Hampson" <Paul.Hampson@Pobox.com> | ||
Date: Sat, 28 Apr 2018 17:17:27 +1000 | ||
Subject: [PATCH 25/27] Use RtlAcquirePebLock instead of peb.FastPebLock | ||
|
||
Older Wine versions did not use peb.FastPebLock. This is the only | ||
code-path that Wine shoudl hit, so the other uses of peb.FastPebLock | ||
have been retained. | ||
--- | ||
winsup/cygwin/path.cc | 4 ++-- | ||
1 file changed, 2 insertions(+), 2 deletions(-) | ||
|
||
diff --git a/winsup/cygwin/path.cc b/winsup/cygwin/path.cc | ||
index cf6422341..1e1ba9c3d 100644 | ||
--- a/winsup/cygwin/path.cc | ||
+++ b/winsup/cygwin/path.cc | ||
@@ -4402,11 +4402,11 @@ cwdstuff::override_win32_cwd (bool init, ULONG old_dismount_count) | ||
} | ||
else if (upp_cwd_hdl == NULL) | ||
return; | ||
- RtlEnterCriticalSection (peb.FastPebLock); | ||
+ RtlAcquirePebLock (); | ||
fcwd_access_t::SetDirHandleFromBufferPointer(upp_cwd_str.Buffer, dir); | ||
h = upp_cwd_hdl; | ||
upp_cwd_hdl = dir; | ||
- RtlLeaveCriticalSection (peb.FastPebLock); | ||
+ RtlReleasePebLock (); | ||
/* The handle on init is always a fresh one, not the handle inherited | ||
from the parent process. We always have to close it here. */ | ||
NtClose (h); | ||
-- | ||
2.16.2.windows.1 | ||
|
115 changes: 115 additions & 0 deletions
115
msys2-runtime/0026-Disable-FAST_CWD-when-Wine-is-detected.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
From 5c7809d3d8fbfab64cbafa6f4fd6f56b37128e16 Mon Sep 17 00:00:00 2001 | ||
From: "Paul \"TBBle\" Hampson" <Paul.Hampson@Pobox.com> | ||
Date: Fri, 27 Apr 2018 02:32:46 +1000 | ||
Subject: [PATCH 26/27] Disable FAST_CWD when Wine is detected | ||
|
||
Wine doesn't use FAST_CWD internally, so manipulating the PEB is | ||
sufficient for replacing the CWD Directory Handle. | ||
--- | ||
winsup/cygwin/cygheap.h | 4 +++- | ||
winsup/cygwin/path.cc | 29 ++++++++++++++++++++++++++++- | ||
2 files changed, 31 insertions(+), 2 deletions(-) | ||
|
||
diff --git a/winsup/cygwin/cygheap.h b/winsup/cygwin/cygheap.h | ||
index abbf9ec07..ed58285e6 100644 | ||
--- a/winsup/cygwin/cygheap.h | ||
+++ b/winsup/cygwin/cygheap.h | ||
@@ -204,7 +204,8 @@ public: | ||
enum fcwd_version_t { | ||
FCWD_OLD, | ||
FCWD_W7, | ||
- FCWD_W8 | ||
+ FCWD_W8, | ||
+ FCWD_DISABLED | ||
}; | ||
|
||
/* This class is used to store the CWD. The CWD storage in the | ||
@@ -281,6 +282,7 @@ public: | ||
void FillIn (HANDLE dir, PUNICODE_STRING name, ULONG old_dismount_count); | ||
static void SetDirHandleFromBufferPointer (PWCHAR buf_p, HANDLE dir); | ||
static void SetVersionFromPointer (PBYTE buf_p, bool is_buffer); | ||
+ static void Disable (void); | ||
}; | ||
|
||
class cwdstuff | ||
diff --git a/winsup/cygwin/path.cc b/winsup/cygwin/path.cc | ||
index 1e1ba9c3d..936dc33cd 100644 | ||
--- a/winsup/cygwin/path.cc | ||
+++ b/winsup/cygwin/path.cc | ||
@@ -3947,6 +3947,7 @@ fcwd_access_t::SetFSCharacteristics (LONG val) | ||
/* Special case FSCharacteristics. Didn't exist originally. */ | ||
switch (fast_cwd_version ()) | ||
{ | ||
+ case FCWD_DISABLED: | ||
case FCWD_OLD: | ||
break; | ||
case FCWD_W7: | ||
@@ -4033,6 +4034,8 @@ fcwd_access_t::SetDirHandleFromBufferPointer (PWCHAR buf_p, HANDLE dir) | ||
fcwd_access_t *f_cwd; | ||
switch (fast_cwd_version ()) | ||
{ | ||
+ case FCWD_DISABLED: | ||
+ return; | ||
case FCWD_OLD: | ||
default: | ||
f_cwd = (fcwd_access_t *) | ||
@@ -4070,10 +4073,19 @@ fcwd_access_t::SetVersionFromPointer (PBYTE buf_p, bool is_buffer) | ||
fast_cwd_version () = FCWD_OLD; | ||
} | ||
|
||
+void | ||
+fcwd_access_t::Disable (void) | ||
+{ | ||
+ fast_cwd_version () = FCWD_DISABLED; | ||
+} | ||
+ | ||
/* This function scans the code in ntdll.dll to find the address of the | ||
global variable used to access the CWD. While the pointer is global, | ||
it's not exported from the DLL, unfortunately. Therefore we have to | ||
- use some knowledge to figure out the address. */ | ||
+ use some knowledge to figure out the address. | ||
+ If we happen to be running under Wine, returns -1 to disable this | ||
+ whole mechanism, as Wine's implementation does not have FAST_CWD. | ||
+ */ | ||
|
||
#ifdef __x86_64__ | ||
|
||
@@ -4086,6 +4098,10 @@ find_fast_cwd_pointer () | ||
HMODULE ntdll = GetModuleHandle ("ntdll.dll"); | ||
if (!ntdll) | ||
return NULL; | ||
+ const uint8_t *wine_get_version = (const uint8_t *) | ||
+ GetProcAddress (ntdll, "wine_get_version"); | ||
+ if (wine_get_version) | ||
+ return (fcwd_access_t **) -1; | ||
const uint8_t *get_dir = (const uint8_t *) | ||
GetProcAddress (ntdll, "RtlGetCurrentDirectory_U"); | ||
const uint8_t *ent_crit = (const uint8_t *) | ||
@@ -4185,6 +4201,10 @@ find_fast_cwd_pointer () | ||
HMODULE ntdll = GetModuleHandle ("ntdll.dll"); | ||
if (!ntdll) | ||
return NULL; | ||
+ const uint8_t *wine_get_version = (const uint8_t *) | ||
+ GetProcAddress (ntdll, "wine_get_version"); | ||
+ if (wine_get_version) | ||
+ return (fcwd_access_t **) -1; | ||
const uint8_t *get_dir = (const uint8_t *) | ||
GetProcAddress (ntdll, "RtlGetCurrentDirectory_U"); | ||
const uint8_t *ent_crit = (const uint8_t *) | ||
@@ -4280,6 +4300,13 @@ find_fast_cwd () | ||
we have to make sure we know the version of the FAST_CWD structure | ||
used on the system. */ | ||
fcwd_access_t **f_cwd_ptr = find_fast_cwd_pointer (); | ||
+ if (f_cwd_ptr == (fcwd_access_t **) -1) | ||
+ { | ||
+ /* FAST_CWD is disabled with prejudice e.g., Wine. In effect, the | ||
+ PEB is canonical, so changing that is sufficient */ | ||
+ fcwd_access_t::Disable (); | ||
+ return NULL; | ||
+ } | ||
if (!f_cwd_ptr) | ||
small_printf ("Cygwin WARNING:\n" | ||
" Couldn't compute FAST_CWD pointer. This typically occurs if you're using\n" | ||
-- | ||
2.16.2.windows.1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
From 9d981752f7cfb16eb6b6f008d87cec5ba68a1c14 Mon Sep 17 00:00:00 2001 | ||
From: "Paul \"TBBle\" Hampson" <Paul.Hampson@Pobox.com> | ||
Date: Sat, 28 Apr 2018 17:19:08 +1000 | ||
Subject: [PATCH 27/27] Debug logs for Wine FAST_CWD | ||
|
||
--- | ||
winsup/cygwin/path.cc | 5 +++++ | ||
1 file changed, 5 insertions(+) | ||
|
||
diff --git a/winsup/cygwin/path.cc b/winsup/cygwin/path.cc | ||
index 936dc33cd..a77732a67 100644 | ||
--- a/winsup/cygwin/path.cc | ||
+++ b/winsup/cygwin/path.cc | ||
@@ -4304,6 +4304,7 @@ find_fast_cwd () | ||
{ | ||
/* FAST_CWD is disabled with prejudice e.g., Wine. In effect, the | ||
PEB is canonical, so changing that is sufficient */ | ||
+ small_printf ("Wine detected, disabling FAST_CWD\n\n"); | ||
fcwd_access_t::Disable (); | ||
return NULL; | ||
} | ||
@@ -4444,6 +4445,7 @@ cwdstuff::override_win32_cwd (bool init, ULONG old_dismount_count) | ||
void | ||
cwdstuff::init () | ||
{ | ||
+ small_printf ("cwdstff::init: start\n\n"); | ||
cwd_lock.init ("cwd_lock"); | ||
|
||
/* Cygwin processes inherit the cwd from their parent. If the win32 path | ||
@@ -4459,12 +4461,14 @@ cwdstuff::init () | ||
/* Initially re-open the cwd to allow POSIX semantics. */ | ||
set (NULL, NULL); | ||
} | ||
+ small_printf ("cwdstff::init: done\n\n"); | ||
} | ||
|
||
/* Chdir and fill out the elements of a cwdstuff struct. */ | ||
int | ||
cwdstuff::set (path_conv *nat_cwd, const char *posix_cwd) | ||
{ | ||
+ small_printf ("cwdstff::set: start\n\n"); | ||
NTSTATUS status; | ||
UNICODE_STRING upath; | ||
PEB &peb = *NtCurrentTeb ()->Peb; | ||
@@ -4715,6 +4719,7 @@ cwdstuff::set (path_conv *nat_cwd, const char *posix_cwd) | ||
stpcpy (posix, posix_cwd); | ||
|
||
cwd_lock.release (); | ||
+ small_printf ("cwdstff::set: done\n\n"); | ||
return 0; | ||
} | ||
|
||
-- | ||
2.16.2.windows.1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters