Compare commits

..
8 changed files with 61 additions and 114 deletions

No files matched your search

+3 -10
View File
@@ -4130,20 +4130,13 @@ 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) fakeinput_chk_fail();
if (count > buflen) __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);
}
@@ -4397,13 +4390,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) fakeinput_chk_fail();
if (fdslen / sizeof(*fds) < nfds) __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) fakeinput_chk_fail();
if (fdslen / sizeof(*fds) < nfds) __chk_fail();
return ppoll(fds, nfds, timeout, sigmask);
}
@@ -133,6 +133,7 @@ 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
@@ -150,6 +151,23 @@ 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,6 +3,7 @@ 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
@@ -135,4 +136,38 @@ 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))
}
}
@@ -979,7 +979,7 @@ def launched(argv):
def shares_sign_in(argv):
return any(arg.lower() in ("-sso", "-launcherlogin") for arg in argv[1:])
return "-sso" in (arg.lower() for arg in argv[1:])
def agent_up(processes):
@@ -993,7 +993,6 @@ class Tidy:
self.gone = AGENT_GONE if gone is None else gone
self.game_since = None
self.closed_for_game = False
self.retained_for_sign_in = False
self.agent_seen = False
self.agent_lost = None
@@ -1002,23 +1001,19 @@ class Tidy:
games = [argv for _, argv in processes if launched(argv)]
if games:
self.game_since = self.game_since if self.game_since is not None else now
client_open = any(is_client(argv) for _, argv in own)
cleanup_pending = not self.closed_for_game or (self.retained_for_sign_in and not client_open)
if own and cleanup_pending and now - self.game_since >= self.settle:
if own and not self.closed_for_game and now - self.game_since >= self.settle:
self.closed_for_game, self.agent_seen, self.agent_lost = True, False, None
self.retained_for_sign_in = False
if keeps_open(steam_root()):
say("Battle.net is set to stay open as a game launches: left open")
return False
if client_open and any(shares_sign_in(argv) for argv in games):
self.retained_for_sign_in = True
if any(is_client(argv) for _, argv in own) and any(shares_sign_in(argv) for argv in games):
say("Battle.net stayed open beside a game signing in with its token: left open")
return False
say("the game is up: closing what is left of Battle.net (%d process(es)) to leave it their memory" % len(own))
stop(own)
return True
return False
self.game_since, self.closed_for_game, self.retained_for_sign_in = None, False, False
self.game_since, self.closed_for_game = None, False
if not any(is_client(argv) for _, argv in processes):
self.agent_seen, self.agent_lost = False, None
elif agent_up(processes):
@@ -84,9 +84,6 @@ 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];
-61
View File
@@ -689,13 +689,6 @@ class ProcessTest(Temp):
self.assertFalse(BNET["shares_sign_in"](["D2R.exe", "-uid", "osi"]))
self.assertFalse(BNET["shares_sign_in"](["-sso.exe"]))
def test_sign_in_flags_are_whole_arguments_after_the_program(self):
for argv in (["Example.exe", "-launcherlogin"], ["Example.exe", "-LAUNCHERLOGIN"]):
self.assertTrue(BNET["shares_sign_in"](argv))
for argv in ([], ["-launcherlogin"], ["Example.exe", "--launcherlogin"],
["Example.exe", "-launcherlogin=false"], ["Example.exe", "path/-launcherlogin"]):
self.assertFalse(BNET["shares_sign_in"](argv))
def test_battle_net_takes_work_once_its_agent_is_up(self):
client = (1, ["C:\\Program Files (x86)\\Battle.net\\Battle.net.exe"])
agent = (2, ["C:\\ProgramData\\Battle.net\\Agent\\Agent.9824\\Agent.exe"])
@@ -877,51 +870,6 @@ class TidyTest(unittest.TestCase):
self.assertEqual(self.stopped, [])
self.assertEqual(self.notified, [])
def test_launcher_sign_in_keeps_the_client_without_a_time_limit(self):
for flag in ("-launcherlogin", "-LAUNCHERLOGIN"):
with self.subTest(flag=flag):
game = (6, ["C:\\Games\\Example.exe", flag, "-uid", "example"])
tidy = BNET["Tidy"](settle=20, gone=30)
up = [self.CLIENT, self.PAGE, self.AGENT, game]
self.assertEqual(self.run_tidy(tidy, [(0, up), (20, up), (120, up), (3600, up)]),
[False, False, False, False])
self.assertEqual(self.stopped, [])
self.assertEqual(self.notified, [])
def test_launcher_sign_in_still_reclaims_helpers_after_the_client_exits(self):
game = (6, ["C:\\Games\\Example.exe", "-launcherlogin", "-uid", "example"])
tidy = BNET["Tidy"](settle=20, gone=30)
self.run_tidy(tidy, [(0, [self.CLIENT, self.AGENT, game]),
(5, [self.AGENT, game]), (20, [self.AGENT, game])])
self.assertEqual(self.stopped, [[3]])
def test_sign_in_helpers_are_reclaimed_after_a_post_settle_client_exit(self):
for flag in ("-sso", "-launcherlogin"):
with self.subTest(flag=flag):
self.stopped.clear()
game = (6, ["C:\\Games\\Example.exe", flag, "-uid", "example"])
tidy = BNET["Tidy"](settle=20, gone=30)
up = [self.CLIENT, self.PAGE, self.AGENT, self.WINE, game]
remaining = [self.AGENT, self.WINE, game]
closed = self.run_tidy(tidy, [(0, up), (20, up), (29, up), (30, remaining),
(40, remaining)])
self.assertEqual(closed, [False, False, False, True, False])
self.assertEqual(self.stopped, [[3]])
self.assertEqual(self.notified, [])
def test_stay_open_preference_preserves_helpers_after_a_post_settle_client_exit(self):
for flag in ("-sso", "-launcherlogin"):
with self.subTest(flag=flag):
game = (6, ["C:\\Games\\Example.exe", flag, "-uid", "example"])
tidy = BNET["Tidy"](settle=20, gone=30)
up = [self.CLIENT, self.AGENT, game]
with mock.patch.dict(BNET, {"keeps_open": lambda root: True}):
closed = self.run_tidy(tidy, [(0, up), (20, up), (30, [self.AGENT, game]),
(120, [self.AGENT, game])])
self.assertEqual(closed, [False, False, False, False])
self.assertEqual(self.stopped, [])
self.assertEqual(self.notified, [])
def test_what_battle_net_left_beside_such_a_game_once_closed_itself_is_stopped(self):
d4 = (6, ["C:\\Program Files (x86)\\Diablo IV\\Diablo IV.exe", "-sso", "-launch", "-uid", "fenris"])
tidy = BNET["Tidy"](settle=20, gone=30)
@@ -1233,15 +1181,6 @@ class LaunchTest(Harness):
self.assertEqual(BNET["launch"](self.root, "Fen"), 0)
self.assertEqual([c for c in self.calls if c[0] == "stop"], [("stop", [10, 11, 12, 13, 14, 30])])
def test_launcher_sign_in_keeps_the_client_until_the_game_exits(self):
self.install()
up = self.clients() + [(30, self.AGENT)]
game = (40, ["C:\\Games\\Example.exe", "-launcherlogin", "-uid", "example"])
self.states = [[], [], up, up + [game], up + [game], up + [game], up, up]
with mock.patch.dict(BNET, {"GAME_SETTLE": 0}):
self.assertEqual(BNET["launch"](self.root, "Example"), 0)
self.assertEqual([c for c in self.calls if c[0] == "stop"], [("stop", [10, 11, 12, 13, 14, 30])])
def test_a_game_installed_in_battle_nets_folder_is_followed_not_stopped(self):
self.install()
up = self.clients() + [(30, self.AGENT)]
+1 -1
View File
@@ -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, "static VkImage effects_run(")
body = function_body(self.source, "VkImage vkp_effects_run(")
prepare = body.index("pipelines_ensure(spatial, s)")
scene = body.index("scene_ensure(scene, scene_w, scene_h)")
self.assertLess(prepare, scene)
-30
View File
@@ -1,30 +0,0 @@
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()