mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-05 20:45:43 +00:00
Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
717c47f58d | ||
|
|
d7898360e3 | ||
|
|
fcd197934a |
No files matched your search
@@ -4130,13 +4130,20 @@ EXPORT ssize_t read(int fd, void *buf, size_t count) {
|
||||
return read_input(fd, buf, count);
|
||||
}
|
||||
|
||||
// glibc's fortify failure; bionic (DroidDeck-Bionic preloads this library into its Wine processes) has no
|
||||
// __chk_fail, and a library naming it there cannot be loaded, which stops every Wine program from starting.
|
||||
#if defined(__BIONIC__)
|
||||
[[noreturn]] static void fakeinput_chk_fail(void) { abort(); }
|
||||
#else
|
||||
extern "C" [[noreturn]] void __chk_fail(void);
|
||||
[[noreturn]] static void fakeinput_chk_fail(void) { __chk_fail(); }
|
||||
#endif
|
||||
|
||||
/* Programs built with _FORTIFY_SOURCE (Flatpak runtimes among them) call these instead of read, poll
|
||||
* and ppoll, and glibc's versions go straight to the kernel. */
|
||||
EXPORT ssize_t __read_chk(int fd, void *buf, size_t count, size_t buflen) {
|
||||
static auto next_read_chk = reinterpret_cast<ssize_t (*)(int, void *, size_t, size_t)>(dlsym(RTLD_NEXT, "__read_chk"));
|
||||
if (count > buflen) __chk_fail();
|
||||
if (count > buflen) fakeinput_chk_fail();
|
||||
if (next_read_chk && !is_fake_input_fd(fd)) return next_read_chk(fd, buf, count, buflen);
|
||||
return read_input(fd, buf, count);
|
||||
}
|
||||
@@ -4390,13 +4397,13 @@ EXPORT int ppoll(struct pollfd *fds, nfds_t nfds,
|
||||
}
|
||||
|
||||
EXPORT int __poll_chk(struct pollfd *fds, nfds_t nfds, int timeout, size_t fdslen) {
|
||||
if (fdslen / sizeof(*fds) < nfds) __chk_fail();
|
||||
if (fdslen / sizeof(*fds) < nfds) fakeinput_chk_fail();
|
||||
return poll(fds, nfds, timeout);
|
||||
}
|
||||
|
||||
EXPORT int __ppoll_chk(struct pollfd *fds, nfds_t nfds, const struct timespec *timeout,
|
||||
const sigset_t *sigmask, size_t fdslen) {
|
||||
if (fdslen / sizeof(*fds) < nfds) __chk_fail();
|
||||
if (fdslen / sizeof(*fds) < nfds) fakeinput_chk_fail();
|
||||
return ppoll(fds, nfds, timeout, sigmask);
|
||||
}
|
||||
|
||||
|
||||
@@ -133,7 +133,6 @@ object NativeGuest {
|
||||
* Rescanned when dpkg's state or a library directory changes.
|
||||
*/
|
||||
fun syncLibraryDirs(root: File) {
|
||||
includeRunpathConf(root)
|
||||
val conf = File(root, RUNPATH_CONF)
|
||||
val signature = (listOf("var/lib/dpkg/status", "usr/lib", "usr/local/lib", "usr/lib/aarch64-linux-gnu")
|
||||
.joinToString(",") { File(root, it).lastModified().toString() }) + "," + conf.parentFile.list()?.size
|
||||
@@ -151,23 +150,6 @@ object NativeGuest {
|
||||
stamp.writeText(signature)
|
||||
}
|
||||
|
||||
private fun includeRunpathConf(root: File) {
|
||||
val ldConf = File(root, "etc/ld.so.conf")
|
||||
val text = if (ldConf.isFile) ldConf.readText() else ""
|
||||
if (ldConfIncludes(text, "/$RUNPATH_CONF")) return
|
||||
ldConf.parentFile?.mkdirs()
|
||||
ldConf.writeText(text + (if (text.isEmpty() || text.endsWith("\n")) "" else "\n") + "include /$RUNPATH_CONF\n")
|
||||
}
|
||||
|
||||
internal fun ldConfIncludes(text: String, file: String): Boolean {
|
||||
val target = java.nio.file.Paths.get(file)
|
||||
return text.lineSequence().map { it.substringBefore('#').trim() }
|
||||
.filter { it.length > 8 && it.startsWith("include") && it[7].isWhitespace() }
|
||||
.flatMap { it.substring(8).trim().split(Regex("\\s+")).asSequence() }
|
||||
.map { if (it.startsWith("/")) it else "/etc/$it" }
|
||||
.any { pattern -> runCatching { java.nio.file.FileSystems.getDefault().getPathMatcher("glob:$pattern").matches(target) }.getOrDefault(false) }
|
||||
}
|
||||
|
||||
/** What a rootfs needs before anything runs in it natively; cheap once done. */
|
||||
@Synchronized
|
||||
fun prepare(context: Context, root: File) {
|
||||
|
||||
@@ -3,7 +3,6 @@ package com.droiddeck.launcher.runtime
|
||||
import java.io.File
|
||||
import java.nio.file.Files
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
|
||||
@@ -136,38 +135,4 @@ class NativeGuestTest {
|
||||
assertEquals("/mnt/droiddeck-sd/steamapps/compatdata/2",
|
||||
NativeGuest.guestLinkTarget("/data/user/0/app/files/steam-libraries/x/steamapps/compatdata/2", linkRoot, binds))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aRuntimeWhoseLdSoConfListsOnlyItsDirectoriesIncludesTheRunpathDirectories() {
|
||||
val root = rootWithLoader()
|
||||
File(root, "etc").mkdirs()
|
||||
File(root, "etc/ld.so.conf").writeText("/usr/local/lib\n/usr/lib\n/usr/lib32")
|
||||
NativeGuest.syncLibraryDirs(root)
|
||||
assertEquals("/usr/local/lib\n/usr/lib\n/usr/lib32\ninclude /etc/ld.so.conf.d/zz-droiddeck-native.conf\n",
|
||||
File(root, "etc/ld.so.conf").readText())
|
||||
NativeGuest.syncLibraryDirs(root)
|
||||
assertEquals(1, File(root, "etc/ld.so.conf").readLines().count { it.startsWith("include") })
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aRuntimeThatAlreadyIncludesLdSoConfDKeepsItsLdSoConf() {
|
||||
val root = rootWithLoader()
|
||||
File(root, "etc").mkdirs()
|
||||
val ubuntu = "include /etc/ld.so.conf.d/*.conf\n\n"
|
||||
File(root, "etc/ld.so.conf").writeText(ubuntu)
|
||||
NativeGuest.syncLibraryDirs(root)
|
||||
assertEquals(ubuntu, File(root, "etc/ld.so.conf").readText())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun anIncludeReachesTheRunpathConfThroughAbsoluteAndRelativePatterns() {
|
||||
val conf = "/etc/ld.so.conf.d/zz-droiddeck-native.conf"
|
||||
assertTrue(NativeGuest.ldConfIncludes("include /etc/ld.so.conf.d/*.conf", conf))
|
||||
assertTrue(NativeGuest.ldConfIncludes("include ld.so.conf.d/*.conf", conf))
|
||||
assertTrue(NativeGuest.ldConfIncludes("/usr/lib\ninclude\t/etc/other.conf /etc/ld.so.conf.d/zz-*.conf", conf))
|
||||
assertFalse(NativeGuest.ldConfIncludes("/usr/local/lib\n/usr/lib\n", conf))
|
||||
assertFalse(NativeGuest.ldConfIncludes("# include /etc/ld.so.conf.d/*.conf", conf))
|
||||
assertFalse(NativeGuest.ldConfIncludes("include /etc/ld.so.conf.d/*.cfg", conf))
|
||||
assertFalse(NativeGuest.ldConfIncludes("include /usr/lib/ld.so.conf.d/*.conf", conf))
|
||||
}
|
||||
}
|
||||
@@ -336,7 +336,7 @@ FRAME_LIMIT_JS = r"""
|
||||
service = null;
|
||||
}
|
||||
if (!service || !settings?.clientSettings || typeof SteamClient.Settings?.SetSetting !== "function") return "unavailable";
|
||||
const self = { timer: null };
|
||||
const self = { timer: null, wanted: null, written: null };
|
||||
const write = value => (__SET_SETTING__)(21002, value);
|
||||
self.check = async () => {
|
||||
let rates;
|
||||
@@ -349,9 +349,15 @@ FRAME_LIMIT_JS = r"""
|
||||
}
|
||||
if (!Array.isArray(rates) || rates.length === 0) return;
|
||||
const current = settings.clientSettings;
|
||||
if (!current.gamescope_enable_app_target_framerate || rates.includes(current.gamescope_app_target_framerate)) return;
|
||||
const value = current.gamescope_app_target_framerate;
|
||||
if (value !== self.written) self.wanted = value;
|
||||
if (!current.gamescope_enable_app_target_framerate) return;
|
||||
const fitting = rates.filter(rate => rate <= self.wanted);
|
||||
const next = fitting.length ? Math.max(...fitting) : Math.min(...rates);
|
||||
if (next === value) return;
|
||||
try {
|
||||
await write(Math.max(...rates));
|
||||
await write(next);
|
||||
self.written = next;
|
||||
} catch (e) {
|
||||
}
|
||||
};
|
||||
|
||||
@@ -84,6 +84,9 @@ static void check_generated_settings_and_layout(void) {
|
||||
g_vk.CmdBindPipeline = bind_pipeline; g_vk.CmdBindDescriptorSets = bind_sets;
|
||||
g_vk.CmdPushConstants = push; g_vk.CmdDraw = draw; g_vk.CmdEndRenderPass = end_pass;
|
||||
g_vk.CmdBlitImage = blit;
|
||||
g_rp = (VkRenderPass)(uintptr_t)5;
|
||||
g_pipe[P_SGSR] = (VkPipeline)(uintptr_t)6;
|
||||
g_pipe[P_COLOR] = (VkPipeline)(uintptr_t)7;
|
||||
g_ready = 1;
|
||||
for (int k = 0; k < 2; k++) {
|
||||
struct fx_target *t = &g_contexts[1].targets[k];
|
||||
|
||||
@@ -32,7 +32,7 @@ class LazyEffectPipelineSourceTest(unittest.TestCase):
|
||||
self.assertIn("effect pipelines are created when needed", body)
|
||||
|
||||
def test_pipelines_are_prepared_before_effect_chain_resources_and_draws(self):
|
||||
body = function_body(self.source, "VkImage vkp_effects_run(")
|
||||
body = function_body(self.source, "static VkImage effects_run(")
|
||||
prepare = body.index("pipelines_ensure(spatial, s)")
|
||||
scene = body.index("scene_ensure(scene, scene_w, scene_h)")
|
||||
self.assertLess(prepare, scene)
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
from pathlib import Path
|
||||
import re
|
||||
import unittest
|
||||
|
||||
SOURCE = Path(__file__).resolve().parents[2] / "app/src/main/cpp/fakeinput_steam.cpp"
|
||||
|
||||
|
||||
def code_only(text):
|
||||
"""The source without its comments and string literals."""
|
||||
text = re.sub(r"/\*.*?\*/", " ", text, flags=re.S)
|
||||
text = re.sub(r"//[^\n]*", " ", text)
|
||||
return re.sub(r'"(?:\\.|[^"\\\n])*"', '""', text)
|
||||
|
||||
|
||||
class FakeinputBionicTest(unittest.TestCase):
|
||||
# DroidDeck-Bionic preloads this library into its Wine processes (tools/bionic-runtime/build.sh). bionic
|
||||
# exports no __chk_fail: a library that names it there cannot be loaded, so no Wine program starts
|
||||
# ("cannot locate symbol "__chk_fail"").
|
||||
def test_glibcs_fortify_failure_is_named_only_off_bionic(self):
|
||||
code = code_only(SOURCE.read_text())
|
||||
guarded = re.compile(r"#if defined\(__BIONIC__\)\n(?P<bionic>.*?)#else\n(?P<glibc>.*?)#endif\n", re.S)
|
||||
blocks = [m for m in guarded.finditer(code) if "__chk_fail" in m.group("glibc")]
|
||||
self.assertTrue(blocks, "the glibc-only __chk_fail is behind #if defined(__BIONIC__) ... #else")
|
||||
for block in blocks:
|
||||
self.assertNotIn("__chk_fail", block.group("bionic"))
|
||||
self.assertNotIn("__chk_fail", guarded.sub("", code))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -55,30 +55,33 @@ const change = async next => { rates = next; notify.forEach(callback => callback
|
||||
assert.strictEqual(eval(script), 'installed');
|
||||
assert.strictEqual(eval(script), 'present');
|
||||
await fire();
|
||||
assert.deepStrictEqual(writes, [144], 'a remembered limit the panel does not offer moves to the highest value');
|
||||
assert.deepStrictEqual(writes, [72], 'a remembered limit the panel does not offer moves to the highest offered rate below it');
|
||||
await fire();
|
||||
assert.deepStrictEqual(writes, [144], 'unchanged choices are not written again');
|
||||
assert.deepStrictEqual(writes, [72], 'unchanged choices are not written again');
|
||||
await change([24, 30, 40, 60, 120]);
|
||||
await fire();
|
||||
assert.deepStrictEqual(writes, [72, 120], 'the chosen limit comes back once the panel offers it again');
|
||||
settingsStore.clientSettings.gamescope_app_target_framerate = 72;
|
||||
await change([24, 30, 40, 60, 120]);
|
||||
await fire();
|
||||
assert.deepStrictEqual(writes, [144, 120], '72 is not offered at 120 Hz');
|
||||
assert.deepStrictEqual(writes, [72, 120, 60], '72 is not offered at 120 Hz: the cap is lowered to 60, not lifted');
|
||||
settingsStore.clientSettings.gamescope_app_target_framerate = 60;
|
||||
await change([12, 15, 20, 30, 60]);
|
||||
await fire();
|
||||
assert.deepStrictEqual(writes, [144, 120], '60 is still offered at 60 Hz and is kept');
|
||||
assert.deepStrictEqual(writes, [72, 120, 60], '60 is still offered at 60 Hz and is kept');
|
||||
await change([18, 24, 36, 72]);
|
||||
await change([24, 30, 40, 60, 120]);
|
||||
await fire();
|
||||
assert.deepStrictEqual(writes, [144, 120], 'a passing rate during a mode switch is not acted on');
|
||||
assert.deepStrictEqual(writes, [72, 120, 60], 'a passing rate during a mode switch is not acted on');
|
||||
settingsStore.clientSettings.gamescope_enable_app_target_framerate = false;
|
||||
settingsStore.clientSettings.gamescope_app_target_framerate = 72;
|
||||
await change([36, 48, 144]);
|
||||
await fire();
|
||||
assert.deepStrictEqual(writes, [144, 120], 'nothing changes while Steam has the frame limit turned off');
|
||||
assert.deepStrictEqual(writes, [72, 120, 60], 'nothing changes while Steam has the frame limit turned off');
|
||||
settingsStore.clientSettings.gamescope_enable_app_target_framerate = true;
|
||||
window.__droiddeckFrameLimit.schedule();
|
||||
await fire();
|
||||
assert.deepStrictEqual(writes, [144, 120, 144], 'turning the limit on after a rate change moves an unoffered value');
|
||||
assert.deepStrictEqual(writes, [72, 120, 60, 48], 'turning the limit on after a rate change lowers an unoffered value');
|
||||
settingsStore.clientSettings.gamescope_app_target_framerate = 72;
|
||||
const setSetting = SteamClient.Settings.SetSetting;
|
||||
SteamClient.Settings.SetSetting = () => { throw new Error('busy'); };
|
||||
@@ -87,7 +90,7 @@ const change = async next => { rates = next; notify.forEach(callback => callback
|
||||
SteamClient.Settings.SetSetting = setSetting;
|
||||
window.__droiddeckFrameLimit.schedule();
|
||||
await fire();
|
||||
assert.deepStrictEqual(writes, [144, 120, 144, 144], 'a failed write is tried again on the next check');
|
||||
assert.deepStrictEqual(writes, [72, 120, 60, 48, 48], 'a failed write is tried again on the next check');
|
||||
settingsStore.clientSettings.gamescope_app_target_framerate = 72;
|
||||
SteamClient.Settings.SetSetting = () => Promise.reject(new Error('busy'));
|
||||
window.__droiddeckFrameLimit.schedule();
|
||||
@@ -95,7 +98,18 @@ const change = async next => { rates = next; notify.forEach(callback => callback
|
||||
SteamClient.Settings.SetSetting = setSetting;
|
||||
window.__droiddeckFrameLimit.schedule();
|
||||
await fire();
|
||||
assert.deepStrictEqual(writes, [144, 120, 144, 144, 144], 'a rejected write is caught and tried again');
|
||||
assert.deepStrictEqual(writes, [72, 120, 60, 48, 48, 48], 'a rejected write is caught and tried again');
|
||||
settingsStore.clientSettings.gamescope_app_target_framerate = 60;
|
||||
await change([33, 55, 165]);
|
||||
await fire();
|
||||
assert.deepStrictEqual(writes, [72, 120, 60, 48, 48, 48, 55], 'a 60 fps limit on a panel held at 165 Hz becomes 55, not 165');
|
||||
await change([24, 30, 40, 60, 120]);
|
||||
await fire();
|
||||
assert.deepStrictEqual(writes, [72, 120, 60, 48, 48, 48, 55, 60], 'the 60 fps limit returns when 120 Hz is available again');
|
||||
settingsStore.clientSettings.gamescope_app_target_framerate = 20;
|
||||
await change([36, 48, 144]);
|
||||
await fire();
|
||||
assert.deepStrictEqual(writes, [72, 120, 60, 48, 48, 48, 55, 60, 36], 'a limit below every offered rate moves to the lowest one');
|
||||
delete window.__droiddeckFrameLimit;
|
||||
webpackChunksteamui.push = ([, , callback]) => callback(webpack({ 1: modules[1], 2: modules[2] }));
|
||||
assert.strictEqual(eval(script), 'unavailable');
|
||||
@@ -104,7 +118,7 @@ const change = async next => { rates = next; notify.forEach(callback => callback
|
||||
|
||||
|
||||
class FrameLimitSyncTest(unittest.TestCase):
|
||||
def test_limit_is_kept_when_offered_and_moved_to_the_highest_value_otherwise(self):
|
||||
def test_limit_is_kept_when_offered_and_lowered_to_the_nearest_offered_rate_otherwise(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
script = Path(directory) / "frame_limit.js"
|
||||
script.write_text(LIVE["FRAME_LIMIT_JS"])
|
||||
|
||||
Reference in new issue
Block a user