mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-02 02:55:42 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c3e59c1b7c |
No files matched your search
@@ -81,6 +81,10 @@ STEAM_VERBS = ("run", "waitforexitandrun")
|
||||
ESCAPE = re.compile(rb"\\([0-7]{3})")
|
||||
DEVICE_FONTS = "/usr/local/share/fonts/android"
|
||||
FONT_RULES = "/etc/fonts/conf.d/66-droiddeck-device-fonts.conf"
|
||||
PROC_MAPS = "/proc/self/maps"
|
||||
JVM_DEPTH = 6
|
||||
X86_ZGC_ADDRESS_BITS = 45
|
||||
WITHOUT_ZGC = "-XX:+UnlockExperimentalVMOptions -XX:-UseZGC"
|
||||
|
||||
|
||||
def say(message):
|
||||
@@ -749,6 +753,47 @@ def vulkan_thunk_loads(fex, folder):
|
||||
return True
|
||||
|
||||
|
||||
def host_address_bits():
|
||||
try:
|
||||
with open(PROC_MAPS) as maps:
|
||||
ends = [int(line.split("-", 1)[1].split(None, 1)[0], 16) for line in maps if "-" in line]
|
||||
except (OSError, ValueError, IndexError):
|
||||
return None
|
||||
return max(ends).bit_length() if ends else None
|
||||
|
||||
|
||||
def bundled_zgc_jvm(folder):
|
||||
seen = 0
|
||||
base = folder.rstrip("/").count("/")
|
||||
for directory, dirs, files in os.walk(folder):
|
||||
seen += 1
|
||||
if seen > SCAN_LIMIT:
|
||||
return None
|
||||
if directory.count("/") - base >= JVM_DEPTH:
|
||||
dirs[:] = []
|
||||
jvm = os.path.join(directory, "libjvm.so")
|
||||
if "libjvm.so" in files and elf_arch(jvm) == "x86_64":
|
||||
try:
|
||||
with open(jvm, "rb") as f:
|
||||
if b"UseZGC" in f.read():
|
||||
return jvm
|
||||
except OSError:
|
||||
pass
|
||||
return None
|
||||
|
||||
|
||||
def without_zgc(guest, folder):
|
||||
bits = host_address_bits()
|
||||
if bits is None or bits >= X86_ZGC_ADDRESS_BITS:
|
||||
return
|
||||
jvm = bundled_zgc_jvm(folder)
|
||||
if not jvm:
|
||||
return
|
||||
guest["_JAVA_OPTIONS"] = " ".join(part for part in (guest.get("_JAVA_OPTIONS"), WITHOUT_ZGC) if part)
|
||||
say("%s: ZGC cannot reserve its x86 heap in this device's %d-bit address space, so Java uses its default collector"
|
||||
% (jvm, bits))
|
||||
|
||||
|
||||
def required_runtime(program):
|
||||
text = read_text(os.path.join(os.path.dirname(program), "toolmanifest.vdf")) or ""
|
||||
match = re.search(r'"require_tool_appid"\s+"(\d+)"', text)
|
||||
@@ -777,6 +822,7 @@ def launch(command, env, mode, decide=None):
|
||||
and vulkan_thunk_loads(fex, folder):
|
||||
guest["LD_LIBRARY_PATH"] = ":".join(["/usr/" + VULKAN_PIN_DIR] + split_paths(guest.get("LD_LIBRARY_PATH")))
|
||||
thunks = "on, its own Vulkan loader too"
|
||||
without_zgc(guest, folder)
|
||||
say("running %s with %s (runtime %s, thunks %s)" % (program, fex["bin"], guest.get("FEX_ROOTFS", "none"), thunks))
|
||||
return os.execve(fex["bin"], [fex["bin"], program] + command[1:], guest)
|
||||
|
||||
|
||||
@@ -984,15 +984,10 @@ def valve_picks(steam_root):
|
||||
return sorted(picks, key=int)
|
||||
|
||||
|
||||
def launch_platforms(entry):
|
||||
return {part.strip() for option in entry.get("launch_options", ())
|
||||
for part in option["oslist"].split(",") if part.strip()}
|
||||
|
||||
|
||||
def tool_platforms(steam_root):
|
||||
entries = appinfo_entries(os.path.join(steam_root, "appcache", "appinfo.vdf"))
|
||||
platforms = {app: entry["oslist"] | launch_platforms(entry) for app, entry in entries.items() if entry["type"] == "tool"}
|
||||
return {app: found for app, found in platforms.items() if found & {"linux", "windows"}}
|
||||
return {app: entry["oslist"] for app, entry in entries.items()
|
||||
if entry["type"] == "tool" and entry["oslist"] & {"linux", "windows"}}
|
||||
|
||||
|
||||
def native_targets(steam_root, apps):
|
||||
@@ -1232,16 +1227,8 @@ def plan_mapping(current, installed, runnable, default, auto, native=None, picks
|
||||
changes["0"] = default
|
||||
for app in sorted((set(current) | installed | picks | set(auto) | set(overrides) | native_choices | set(tools)) - {"0"}, key=app_order):
|
||||
name = current.get(app, "")
|
||||
if app in tools and "linux" in tools[app]:
|
||||
if "windows" not in tools[app]:
|
||||
if name and (name.lower() in runnable or "proton" in name.lower()):
|
||||
changes[app] = None
|
||||
continue
|
||||
if app in overrides:
|
||||
target = overrides[app]
|
||||
if target is not DEFERRED_GAME_TOOL and (target or None) != (name or None):
|
||||
changes[app] = target or None
|
||||
elif name and (name == auto.get(app) or unrunnable(name, runnable) or name.lower() in removed):
|
||||
if app in tools and "linux" in tools[app] and "windows" not in tools[app]:
|
||||
if name and (name.lower() in runnable or "proton" in name.lower()):
|
||||
changes[app] = None
|
||||
continue
|
||||
if app in overrides:
|
||||
|
||||
@@ -52,6 +52,7 @@ class FexTestCase(unittest.TestCase):
|
||||
"FONT_RULES": str(self.tmp / "66-droiddeck-device-fonts.conf"),
|
||||
"OWN_FEX": str(self.tmp / "own"),
|
||||
"OWN_FEX_TAG": str(self.tmp / "own/share/fex-emu/.droiddeck-tag"),
|
||||
"PROC_MAPS": str(self.tmp / "maps"),
|
||||
}
|
||||
patcher = mock.patch.dict(G, patches)
|
||||
patcher.start()
|
||||
@@ -1269,6 +1270,48 @@ class LaunchTest(FexTestCase):
|
||||
native.assert_called_once()
|
||||
emulated.assert_not_called()
|
||||
|
||||
def test_a_bundled_java_runtime_leaves_zgc_when_its_x86_heap_cannot_fit(self):
|
||||
self.fex_tool()
|
||||
self.runtime()
|
||||
maps = self.tmp / "maps"
|
||||
|
||||
def host(top):
|
||||
maps.write_text("5580000000-5580001000 r-xp 00000000 fe:00 1 /usr/bin/python3\n"
|
||||
"%x-%x rw-p 00000000 00:00 0 [stack]\n" % (top - 0x21000, top))
|
||||
|
||||
def app(name, jvm=elf(62) + b"\0UseZGC\0UseG1GC\0", where="usr/lib/game/runtime/lib/server"):
|
||||
run = self.write(self.tmp / name / "AppRun", "#!/bin/sh\n", 0o755)
|
||||
if jvm is not None:
|
||||
self.write(self.tmp / name / where / "libjvm.so", jvm)
|
||||
return run
|
||||
|
||||
def started(program, env=None):
|
||||
with mock.patch("os.execve") as emulated:
|
||||
_, said = self.quiet(FEX["launch"], [str(program)], dict(env or {}), "on")
|
||||
return emulated.call_args[0][2], said
|
||||
|
||||
host(0x7FFFFFF000)
|
||||
env, said = started(app("zgc"))
|
||||
self.assertEqual(env["_JAVA_OPTIONS"], "-XX:+UnlockExperimentalVMOptions -XX:-UseZGC")
|
||||
self.assertIn("39-bit address space", said)
|
||||
env, _ = started(app("zgc"), {"_JAVA_OPTIONS": "-Xmx2g"})
|
||||
self.assertEqual(env["_JAVA_OPTIONS"], "-Xmx2g -XX:+UnlockExperimentalVMOptions -XX:-UseZGC")
|
||||
env, _ = started(app("jdk8", where="jre/lib/amd64/server", jvm=elf(62) + b"\0UseG1GC\0"))
|
||||
self.assertNotIn("_JAVA_OPTIONS", env)
|
||||
env, _ = started(app("arm-jvm", jvm=elf(183) + b"\0UseZGC\0"))
|
||||
self.assertNotIn("_JAVA_OPTIONS", env)
|
||||
env, said = started(app("no-java", jvm=None), {"_JAVA_OPTIONS": "-Xmx2g"})
|
||||
self.assertEqual(env["_JAVA_OPTIONS"], "-Xmx2g")
|
||||
self.assertNotIn("ZGC", said)
|
||||
env, _ = started(app("too-deep", where="a/b/c/d/e/f/g/server"))
|
||||
self.assertNotIn("_JAVA_OPTIONS", env)
|
||||
host(0xFFFFFFFFF000)
|
||||
env, _ = started(app("zgc"))
|
||||
self.assertNotIn("_JAVA_OPTIONS", env)
|
||||
maps.unlink()
|
||||
env, _ = started(app("zgc"))
|
||||
self.assertNotIn("_JAVA_OPTIONS", env)
|
||||
|
||||
def test_programs_that_bring_a_new_enough_runtime_get_the_vulkan_thunk(self):
|
||||
tool = self.fex_tool()
|
||||
self.runtime()
|
||||
|
||||
@@ -73,56 +73,6 @@ class ToolPlatformsTest(unittest.TestCase):
|
||||
self.assertEqual(auto["900001"], TOOL)
|
||||
self.assertEqual(auto["976730"], TOOL)
|
||||
|
||||
def add_launch_only_linux_tool(self):
|
||||
self.entries[900007] = {"common": {"type": "Tool", "oslist": "windows"}, "config": {"launch": {
|
||||
"0": {"executable": "bin\\win64\\start.exe", "config": {"oslist": "windows"}},
|
||||
"1": {"executable": "bin\\start.sh", "config": {"oslist": "linux", "osarch": "64"}},
|
||||
}}}
|
||||
self.write_appinfo()
|
||||
|
||||
def test_linux_launch_entry_counts_as_a_linux_platform(self):
|
||||
self.add_launch_only_linux_tool()
|
||||
self.assertEqual(self.platforms()["900007"], {"windows", "linux"})
|
||||
self.assertEqual(self.platforms()["900001"], {"windows"})
|
||||
|
||||
def test_tool_with_a_linux_build_is_not_given_proton_before_install(self):
|
||||
self.add_launch_only_linux_tool()
|
||||
changes, auto = self.plan({"0": TOOL})
|
||||
self.assertNotIn("900007", changes)
|
||||
self.assertNotIn("900007", auto)
|
||||
self.assertEqual(changes["900001"], TOOL)
|
||||
|
||||
def test_own_proton_mapping_on_a_tool_with_a_linux_build_is_cleared(self):
|
||||
self.add_launch_only_linux_tool()
|
||||
changes, auto = self.plan({"0": TOOL, "900007": TOOL}, {"900007": TOOL})
|
||||
self.assertIsNone(changes["900007"])
|
||||
self.assertNotIn("900007", auto)
|
||||
|
||||
def test_user_selection_on_a_tool_with_a_linux_build_survives(self):
|
||||
self.add_launch_only_linux_tool()
|
||||
for name in (TOOL, "custom-windows"):
|
||||
with self.subTest(name=name):
|
||||
changes, auto = self.plan({"0": TOOL, "900007": name}, {"976730": TOOL})
|
||||
self.assertNotIn("900007", changes)
|
||||
|
||||
def test_stale_tool_on_a_tool_with_a_linux_build_is_cleared(self):
|
||||
self.add_launch_only_linux_tool()
|
||||
for name, removed in (("GE-Proton11-7", ("GE-Proton11-7",)), ("proton_9", ())):
|
||||
with self.subTest(name=name):
|
||||
changes, auto = self.plan({"0": TOOL, "900007": name}, removed=removed)
|
||||
self.assertIsNone(changes["900007"])
|
||||
self.assertNotIn("900007", auto)
|
||||
|
||||
def test_explicit_request_on_a_tool_with_a_linux_build_is_applied(self):
|
||||
self.add_launch_only_linux_tool()
|
||||
changes, auto = self.plan({"0": TOOL}, overrides={"900007": TOOL})
|
||||
self.assertEqual(changes["900007"], TOOL)
|
||||
changes, auto = self.plan({"0": TOOL, "900007": TOOL}, overrides={"900007": None})
|
||||
self.assertIsNone(changes["900007"])
|
||||
changes, auto = self.plan({"0": TOOL, "900007": TOOL}, overrides={"900007": TOOL})
|
||||
self.assertNotIn("900007", changes)
|
||||
self.assertNotIn("900007", auto)
|
||||
|
||||
def test_removed_ge_proton_is_cleared_with_or_without_saved_ownership(self):
|
||||
for saved in ({}, {"1826330": "GE-Proton11-7"}):
|
||||
with self.subTest(saved=saved):
|
||||
|
||||
Reference in new issue
Block a user