Compare commits

..
Author SHA1 Message Date
The412BannerandThe412Banner d7898360e3 fix(input): keep the glibc-only __chk_fail out of the bionic build (#3492)
DroidDeck-Bionic preloads libfakeinput.so into its Wine processes
(tools/bionic-runtime/build.sh builds fakeinput_steam.cpp for bionic). The
fortified read/poll/ppoll entry points (#2916) call glibc's __chk_fail, which
bionic does not export, so the bionic build of the library cannot be loaded:
"CANNOT LINK EXECUTABLE .../wine: cannot locate symbol "__chk_fail"" and no
Wine program starts. Every DroidDeck-Bionic pack built from main since #2916 is
affected (r67 predates it).

The bounds failures now go through fakeinput_chk_fail(): abort() on bionic,
__chk_fail() as before on glibc. tools/tests/test_fakeinput_bionic.py fails if
__chk_fail is named outside the non-bionic branch again.

Co-authored-by: The412Banner <the412banner@users.noreply.github.com>
2026-11-30 19:48:33 -05:00
LunaDL fcd197934a test: fix effects source cache harness initialization (#3490) 2026-11-30 18:15:04 -05:00
6 changed files with 44 additions and 57 deletions

No files matched your search

+10 -3
View File
@@ -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))
}
}
@@ -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];
+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, "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)
+30
View File
@@ -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()