fix(components): limit Mono GAC overrides to assemblies Mono ships

Gac=n makes Wine Mono skip the Windows GAC for that assembly, so an
assembly that only exists there could no longer load. Overrides now
cover only GAC assemblies found in the Mono runtime Wine uses: the
prefix's own Mono install, else the game's Proton Mono folder. With
no Mono found, no override is written.
This commit is contained in:
maxjivi05 committed 2026-11-11 11:14:20 -05:00
1 parent 66f59dc9d0
commit 02b2486858
4 files changed
+107 -11

No files matched your search

+1
View File
@@ -74,6 +74,7 @@ DroidDeck is [GPL-3.0](LICENSE). Steam and Proton belong to Valve Corporation. V
- x86 AppImages, and arm64 ones whose runtime can't unpack on Android, are unpacked with [uruntime](https://github.com/VHSgunzo/uruntime) by VHSgunzo (MIT), shipped unmodified with its licence.
- x86 programs linking OpenSSL 3 use the copy in the [Steam Linux Runtime 4.0](https://gitlab.steamos.cloud/steamrt/steamrt). x86 Linux games get the `/etc/asound.conf` that [pressure-vessel](https://gitlab.steamos.cloud/steamrt/steam-runtime-tools) writes.
- `WriteProcessMemory` hooks fall back to `/proc/<pid>/mem` the way [Wine](https://gitlab.winehq.org/wine/wine)'s `server/ptrace.c` did before Wine 11.
- Windows components give Wine Mono a `Gac=n` assembly override only for assemblies in Mono's own GAC, following the assembly search order in [Wine](https://gitlab.winehq.org/wine/wine)'s `dlls/mscoree/metahost.c`.
- Wine write watches use userfaultfd support in [Proton](https://github.com/ValveSoftware/wine)'s `dlls/ntdll/unix/virtual.c` (LGPL-2.1-or-later). libblsession supplies the arm64 syscall number and answers `PAGEMAP_SCAN` from `/proc/self/pagemap`.
- libblsession runs Wine's arm64 `SIGUSR2` context handler (`dlls/ntdll/unix/signal_arm64.c`, LGPL-2.1-or-later) in place on a frame laid out like [Linux](https://github.com/torvalds/linux)'s `arch/arm64/kernel/signal.c`, and serves `fill_vm_counters` in `dlls/ntdll/unix/process.c` the kernel's own `/proc/<pid>/status`.
- droiddeck-ntsync follows the [Linux](https://github.com/torvalds/linux) ntsync semantics in `Documentation/userspace-api/ntsync.rst` (GPL-2.0).
@@ -333,12 +333,12 @@ def engine_fixes(exe, args):
return env, extra, notes
def win_components(compat, app_id):
def win_components(compat, app_id, proton=None):
if not compat:
return ""
try:
module = runpy.run_path(str(Path(__file__).resolve().parent / "droiddeck-wincomponents"))
names, notes = module["apply"](compat.rstrip("/"), app_id)
names, notes = module["apply"](compat.rstrip("/"), app_id, proton=proton)
for note in notes:
print("droiddeck-game-env: " + note, file=sys.stderr)
return module["overrides_value"](names)
@@ -1183,7 +1183,7 @@ def main():
for note in notes:
print("droiddeck-game-env: " + note, file=sys.stderr)
command += extra
components = win_components(env.get("STEAM_COMPAT_DATA_PATH", ""), app_id)
components = win_components(env.get("STEAM_COMPAT_DATA_PATH", ""), app_id, os.path.dirname(command[0]))
if components:
own = fixes.get("WINEDLLOVERRIDES")
fixes["WINEDLLOVERRIDES"] = components + ";" + own if own else components
@@ -17,6 +17,7 @@ BUILTIN_MARKS = (b"Wine builtin DLL", b"Wine placeholder DLL")
ARCH_DIRS = ("system32", "syswow64")
ID = re.compile(r"[A-Za-z0-9][A-Za-z0-9._-]{0,63}")
HIVES = {"HKLM": "system.reg", "HKCU": "user.reg"}
PROTON_MONO = ("files/share/wine/mono", "dist/share/wine/mono")
VALUE_TYPES = {"key", "sz", "expand_sz", "multi_sz", "dword", "binary", "append", "prepend"}
@@ -38,7 +39,7 @@ def wanted(app_id, selection=SELECTION):
return ids
def component(store, cid):
def component(store, cid, mono=frozenset()):
root = Path(store) / cid
try:
with open(root / "component.json", encoding="utf-8") as source:
@@ -66,7 +67,7 @@ def component(store, cid):
for rel, _ in files:
parts = Path(rel.lower()).parts
gac_paths = (("windows", "assembly"), ("windows", "microsoft.net", "assembly"))
if rel.lower().endswith(".dll") and any(
if rel.lower().endswith(".dll") and Path(rel).stem.lower() in mono and any(
parts[i:i + len(prefix)] == prefix
and i + len(prefix) < len(parts)
and (parts[i + len(prefix)] == "gac" or parts[i + len(prefix)].startswith("gac_"))
@@ -78,6 +79,23 @@ def component(store, cid):
return overrides, files, requires, values
def mono_assemblies(pfx, proton=None):
candidates = [[spelled(Path(pfx) / "drive_c/windows/mono/mono-2.0/lib/mono/gac")]]
if proton:
candidates += [sorted((Path(proton) / home).glob("wine-mono*/lib/mono/gac")) for home in PROTON_MONO]
for gacs in candidates:
names = set()
for gac in gacs:
try:
with os.scandir(gac) as entries:
names.update(entry.name.lower() for entry in entries if entry.is_dir())
except OSError:
pass
if names:
return names
return set()
def registry_values(root):
try:
with open(Path(root) / "registry.json", encoding="utf-8") as source:
@@ -530,7 +548,8 @@ def wait_for_pending(app_id, pending=PENDING, store=STORE, timeout=PENDING_WAIT,
return "wincomp: %s waited %dms for %s" % (app_id, waited, ",".join(asked))
def apply(compat_path, app_id, selection=SELECTION, store=STORE, pending=PENDING, wait=wait_for_pending):
def apply(compat_path, app_id, selection=SELECTION, store=STORE, pending=PENDING, wait=wait_for_pending, *,
proton=None):
compat = Path(compat_path)
pfx = compat / "pfx"
waited = wait(app_id, pending, store) if wait else None
@@ -556,8 +575,9 @@ def apply(compat_path, app_id, selection=SELECTION, store=STORE, pending=PENDING
saved_requires = dict(saved_requires, **{cid: loose})
inferred.add(cid)
kept_overrides, kept_requires = {}, {}
mono = mono_assemblies(pfx, proton)
for cid in expand(store, ids, saved_requires):
found = component(store, cid)
found = component(store, cid, mono)
if found is None:
if cid in saved_requires or cid in recorded or cid in owners or cid in registry_owners:
held.add(cid)
@@ -657,10 +677,10 @@ def overrides_value(names):
def main():
if len(sys.argv) != 3:
print("usage: droiddeck-wincomponents <compatdata dir> <appid>", file=sys.stderr)
if len(sys.argv) not in (3, 4):
print("usage: droiddeck-wincomponents <compatdata dir> <appid> [proton dir]", file=sys.stderr)
return 2
names, notes = apply(sys.argv[1], sys.argv[2])
names, notes = apply(sys.argv[1], sys.argv[2], proton=sys.argv[3] if len(sys.argv) == 4 else None)
for note in notes:
print(note)
print("WINEDLLOVERRIDES=" + overrides_value(names))
+76 -1
View File
@@ -19,6 +19,7 @@ class WinComponentsTest(unittest.TestCase):
self.compat = root / "compatdata/2571976725"
self.selection = root / "wincomponents.json"
self.pfx = self.compat / "pfx/drive_c/windows"
self.proton = root / "proton"
def tearDown(self):
self.tmp.cleanup()
@@ -35,8 +36,12 @@ class WinComponentsTest(unittest.TestCase):
def pick(self, *ids):
self.selection.write_text(json.dumps({"version": 1, "games": {"2571976725": list(ids)}}))
def mono(self, *names, home="files/share/wine/mono/wine-mono"):
for name in names:
(self.proton / home / "lib/mono/gac" / name / "4.0.0.0__b77a5c561934e089").mkdir(parents=True)
def apply(self):
return MODULE["apply"](self.compat, "2571976725", self.selection, self.store)
return MODULE["apply"](self.compat, "2571976725", self.selection, self.store, proton=self.proton)
def test_places_files_before_the_prefix_exists_and_returns_overrides(self):
self.component("openal", ["openal32"], {"syswow64/OpenAL32.dll": b"x86", "system32/OpenAL32.dll": b"x64"})
@@ -240,6 +245,24 @@ class WinComponentsTest(unittest.TestCase):
self.assertEqual(GAME_ENV["win_components"](str(self.compat) + "/", "2571976725"), "openal32=n,b")
self.assertEqual(GAME_ENV["win_components"]("", "2571976725"), "")
def test_game_env_hands_the_proton_folder_to_the_mono_check(self):
self.component("framework", ["mscoree=n"], {
"drive_c/windows/Microsoft.NET/assembly/GAC_MSIL/System/v4/System.dll": b"system",
})
self.mono("System")
self.pfx.parent.mkdir(parents=True)
user = self.compat / "pfx/user.reg"
user.write_text("WINE REGISTRY Version 2\n")
self.pick("framework")
globals_ = GAME_ENV["win_components"].__globals__
real = runpy.run_path(str(BIN / "droiddeck-wincomponents"))
real["apply"].__defaults__ = (self.selection, self.store, self.selection.parent / "no-pending.json", None)
with mock.patch.dict(globals_, {"runpy": mock.Mock(run_path=lambda _path: real)}):
self.assertEqual(GAME_ENV["win_components"](str(self.compat), "2571976725", str(self.proton)),
"mscoree=n,b")
registry = MODULE["RegistryFile"](user)
self.assertEqual(registry.get("Software\\Wine\\Mono\\AsmOverrides", "System"), '"System"="Gac=n"')
def test_bundle_brings_its_parts_and_catalog_names_with_dots_work(self):
self.component("dmband", ["dmband"], {"syswow64/dmband.dll": b"band"})
self.component("dsound", ["dsound=n"], {"syswow64/dsound.dll": b"ds"})
@@ -288,6 +311,7 @@ class WinComponentsTest(unittest.TestCase):
self.component("dotnet48", ["mscoree=n"], {
"drive_c/windows/Microsoft.NET/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll": b"system",
})
self.mono("System")
self.pfx.parent.mkdir(parents=True)
user = self.compat / "pfx/user.reg"
user.write_text("WINE REGISTRY Version 2\n")
@@ -306,6 +330,7 @@ class WinComponentsTest(unittest.TestCase):
"drive_c/windows/assembly/GAC_MSIL/System/v2.0.0.0__b77a5c561934e089/System.dll": b"system",
"drive_c/windows/assembly/GAC/Legacy/v1.0.0.0__1234567890abcdef/Legacy.dll": b"legacy",
})
self.mono("System", "Legacy", home="dist/share/wine/mono/wine-mono-7.4.0")
self.pfx.parent.mkdir(parents=True)
user = self.compat / "pfx/user.reg"
user.write_text("WINE REGISTRY Version 2\n")
@@ -321,6 +346,7 @@ class WinComponentsTest(unittest.TestCase):
"drive_c/windows/Microsoft.NET/assembly/GAC_MSIL/System/v4/System.dll": b"system",
"drive_c/windows/Microsoft.NET/assembly/GAC_MSIL/System.Core/v4/System.Core.dll": b"core",
})
self.mono("System", "System.Core")
key = "Software\\Wine\\Mono\\AsmOverrides"
(self.store / "framework/registry.json").write_text(json.dumps({"values": [
{"hive": "HKCU", "key": key, "name": "System", "type": "sz", "data": "Gac=y"},
@@ -350,6 +376,7 @@ class WinComponentsTest(unittest.TestCase):
gac = "drive_c/windows/Microsoft.NET/assembly/GAC_MSIL/System/v4/System.dll"
self.component("framework", ["mscoree=n"], {gac: b"system"})
self.component("other", ["other=n"], {gac: b"other"})
self.mono("System")
self.pfx.parent.mkdir(parents=True)
user = self.compat / "pfx/user.reg"
original = "WINE REGISTRY Version 2\n"
@@ -361,6 +388,54 @@ class WinComponentsTest(unittest.TestCase):
self.apply()
self.assertEqual(user.read_text(), original)
def test_gac_assemblies_missing_from_mono_keep_the_windows_gac(self):
self.component("framework", ["mscoree=n"], {
"drive_c/windows/Microsoft.NET/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll": b"system",
"drive_c/windows/Microsoft.NET/assembly/GAC_MSIL/Vendor.Engine/v4.0_1.0.0.0__0123456789abcdef/Vendor.Engine.dll": b"vendor",
"drive_c/windows/assembly/GAC/stdole/7.0.3300.0__b03f5f7f11d50a3a/stdole.dll": b"stdole",
})
self.mono("System")
self.pfx.parent.mkdir(parents=True)
user = self.compat / "pfx/user.reg"
user.write_text("WINE REGISTRY Version 2\n")
self.pick("framework")
self.apply()
registry = MODULE["RegistryFile"](user)
key = "Software\\Wine\\Mono\\AsmOverrides"
self.assertEqual(registry.get(key, "System"), '"System"="Gac=n"')
self.assertIsNone(registry.get(key, "Vendor.Engine"))
self.assertIsNone(registry.get(key, "stdole"))
def test_no_mono_runtime_found_leaves_mono_settings_alone(self):
self.component("framework", ["mscoree=n"], {
"drive_c/windows/Microsoft.NET/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll": b"system",
})
(self.proton / "files/share/wine/mono/wine-mono/lib/mono/gac").mkdir(parents=True)
self.pfx.parent.mkdir(parents=True)
user = self.compat / "pfx/user.reg"
original = "WINE REGISTRY Version 2\n"
user.write_text(original)
self.pick("framework")
names, _ = self.apply()
self.assertEqual(names, ["mscoree=n,b"])
self.assertEqual(user.read_text(), original)
def test_a_prefix_mono_install_is_used_before_protons(self):
self.component("framework", ["mscoree=n"], {
"drive_c/windows/Microsoft.NET/assembly/GAC_MSIL/System/v4/System.dll": b"system",
"drive_c/windows/Microsoft.NET/assembly/GAC_MSIL/System.Core/v4/System.Core.dll": b"core",
})
self.mono("System", "System.Core")
(self.pfx / "Mono/mono-2.0/lib/mono/gac/System/4.0.0.0__b77a5c561934e089").mkdir(parents=True)
user = self.compat / "pfx/user.reg"
user.write_text("WINE REGISTRY Version 2\n")
self.pick("framework")
self.apply()
registry = MODULE["RegistryFile"](user)
key = "Software\\Wine\\Mono\\AsmOverrides"
self.assertEqual(registry.get(key, "System"), '"System"="Gac=n"')
self.assertIsNone(registry.get(key, "System.Core"))
def test_a_wine_placeholder_file_is_not_a_native_dll(self):
self.component("dotnet48", ["mscoree=n"], {})
for arch in ("system32", "syswow64"):