mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-06 21:15:43 +00:00
Feat: Improve ARMv8.0 Steam compatibility with LSE emulation (#3720)
* feat: emulate LSE atomics so the Steam client starts on ARMv8.0 CPUs * fix: keep NZCV across patched LSE min/max stubs and catch st* aliases * fix: fail the LSE check when objdump fails * fix: validate the CASP pair on a mismatch in the LSE emulator * fix: sandboxes switch on the LSE emulator when it is preloaded * fix: keep the MaliBridge pointer from main * Handle LSE atomics before preload constructors * Support early LSE handling in root guest processes * Fix LSE-Emu signal and patching review findings * Assert CASP and min/max sites use patched stubs * Correct patch test statistics regexes * Validate SIGILL syscall ABI and retain active state on restore failure * Preserve the previous SIGILL disposition during early install * Synchronize instruction fetch on generated LSE stubs * Address LSE-Emu follow-up review findings * Fix missing LSE signal handler state declarations * Honor application signal mask when forwarding SIGILL * Preserve SA_RESETHAND mask during handler forwarding * Fix LSE opt-out after early handler install * Avoid recursive SIGILL forwarding during LSE emulation * Fix LSE SIGILL handler re-entry tracking * Honor SA_NODEFER in forwarded SIGILL mask * Preserve nested SIGILL delivery semantics * Preserve explicit SIGILL mask with SA_NODEFER * Reduce LSE patch contention across threads * Guard nested faults before acquiring patch lock * Fix early SIGILL restore and wake patch waiters * Preserve libc restorer when restoring application SIGILL * Wait for concurrent LSE patch instead of skipping * Fix LSE patch lock release and fork recovery * Avoid reinstalling the early SIGILL handler * chore: retrigger CI * Avoid proc maps reads in concurrent SIGILL patching * Prevent late IFUNC handler install when emulation is disabled * Clarify cached mapping lookup * Move cached map declarations before find_gap * Default LSE instruction patching to off * Document conservative LSE emulation default * Keep LSE instruction patching opt-in in sandbox preload * Document default and opt-in LSE emulation checks * Assert LSE patching remains opt-in in sandbox tests * Align LSE device checks with SDK 34 patching behavior * Check expected mprotect failures in opt-in device run * Clarify LSE emulator device validation criteria * Specify controlled SDK mprotect validation * fix(lse-emu): publish SIGILL actions atomically * fix(runtime): honor LSE_EMU=0 before preload * test(runtime): keep LSE preload disabled when opted out * fix(runtime): fully honor LSE_EMU=0 opt-out * test(runtime): verify LSE opt-out removes inherited preload * fix(runtime): filter inherited LSE preload without preload file * fix(lse-emu): use bounded signal-safe action snapshots * fix(runtime): split inherited preloads on spaces and colons * test(runtime): cover both LSE preload entry orders * fix(lse-emu): recycle displaced SIGILL snapshots * fix(preload): preserve colliding path cache entries * test(lse-emu): report patch failure details * fix(lse-emu): serialize action snapshot publishers * fix(lse-emu): fall back to reachable arena mapping * fix(lse-emu): make signal action publication nonblocking * refactor(lse-emu): remove obsolete publisher lock * Fix SIGILL snapshot retirement and honor session LSE opt-out * Preserve the Java staging API and isolate the SIGILL stress test * fix(nativeguest): filter LSE preload when disabled * fix(lse-emu): tighten seccomp and signal setup * fix(session): preserve active LSE override while staging * fix(lse-emu): return atomically displaced signal actions * fix(lse-emu): stage raw signal masks safely * fix(lse-emu): distinguish seccomp listener success * fix(lse-emu): publish seccomp veto atomically * fix(lse-emu): fail closed on RX restore errors * fix(lse-emu): keep stack-using atomic stubs on trap path * fix(lse-emu): allow patching with inherited seccomp * test(lse-emu): cover LDAPR patch path * test(lse-emu): assert LDAPR-only patching * fix(nativeguest): filter disabled LSE from preload chains * docs(lse-emu): define inherited seccomp patch policy * fix(lse-emu): emulate LDAPR trap fallback * refactor(lse-emu): remove unused seccomp query * fix(nativeguest): release filtered preload chain in scope * test(lse-emu): allow forwarded udf diagnostic * fix(nativeguest): avoid unsafe preload fallback when disabled * test(lse-emu): match full zero instruction field * test(lse-emu): match complete instruction diagnostics * Keep nested native preloads from duplicating host libraries * fix(nativeguest): fail exec when disabled preload cannot map * fix(nativeguest): stop exec when preload mapping fails * fix(nativeguest): propagate preload filter allocation failures * Consume only the selected one-shot SIGILL action * Reclaim abandoned SIGILL action slots after fork * Revalidate the live file mapping before optional LSE patching --------- Co-authored-by: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com>
This commit is contained in:
1 parent
73fac3723f
commit
88d44b0dc6
27 files changed
+2263
-40
No files matched your search
@@ -0,0 +1,17 @@
|
||||
package com.droiddeck.launcher.core
|
||||
|
||||
import java.io.File
|
||||
|
||||
object CpuFeatures {
|
||||
internal fun lacksAtomics(cpuInfo: String): Boolean {
|
||||
val cores = cpuInfo.lineSequence()
|
||||
.filter { it.substringBefore(':').trim() == "Features" }
|
||||
.map { it.substringAfter(':').trim().split(Regex("\\s+")) }
|
||||
.toList()
|
||||
return cores.isNotEmpty() && cores.any { "atomics" !in it }
|
||||
}
|
||||
|
||||
val lacksAtomics: Boolean by lazy {
|
||||
runCatching { lacksAtomics(File("/proc/cpuinfo").readText()) }.getOrDefault(false)
|
||||
}
|
||||
}
|
||||
@@ -288,12 +288,26 @@ object BwrapSpawner {
|
||||
}
|
||||
|
||||
private fun preload(session: List<Bind>, rootfs: String, env: MutableMap<String, String>): List<Bind> {
|
||||
val libs = FileUtils.readString(File(rootfs, "etc/ld.so.preload"))?.lines()
|
||||
?.map { it.trim() }?.filter { it.startsWith("/") && File(rootfs + it).isFile } ?: return emptyList()
|
||||
if (libs.isEmpty()) return emptyList()
|
||||
val configured = FileUtils.readString(File(rootfs, "etc/ld.so.preload"))?.lines()
|
||||
?.map { it.trim() }?.filter { it.startsWith("/") && File(rootfs + it).isFile } ?: emptyList()
|
||||
val lseDisabled = env["LSE_EMU"] == "0"
|
||||
val libs = configured.filterNot { lseDisabled && it.endsWith("/liblse_emu.so") }
|
||||
val inherited = env["LD_PRELOAD"]?.split(Regex("[\\s:]+"))
|
||||
?.filter { it.isNotEmpty() && !(lseDisabled && it.substringAfterLast('/') == "liblse_emu.so") }
|
||||
?: emptyList()
|
||||
if (libs.isEmpty()) {
|
||||
if (lseDisabled) {
|
||||
if (inherited.isEmpty()) env.remove("LD_PRELOAD")
|
||||
else env["LD_PRELOAD"] = inherited.joinToString(":")
|
||||
}
|
||||
return emptyList()
|
||||
}
|
||||
val binds = ArrayList<Bind>()
|
||||
val paths = libs.map { lib -> "$PRELOAD_DIR/${lib.substringAfterLast('/')}".also { binds.add(Bind(rootfs + lib, it)) } }
|
||||
env["LD_PRELOAD"] = (paths + listOfNotNull(env["LD_PRELOAD"]?.takeIf { it.isNotBlank() })).joinToString(":")
|
||||
env["LD_PRELOAD"] = (paths + inherited).joinToString(":")
|
||||
if (libs.any { it.endsWith("/liblse_emu.so") }) {
|
||||
env.putIfAbsent("LSE_EMU", "1")
|
||||
}
|
||||
File(rootfs, NET_LINK).takeIf { it.isFile }?.let { binds.add(Bind(it.path, "/$NET_LINK")) }
|
||||
env["FAKE_EVDEV_DIR"]?.let { File(it).parent }?.let { dev ->
|
||||
binds.addAll(bindsFor(session, rootfs, dev, dev))
|
||||
|
||||
@@ -104,8 +104,11 @@ object NativeGuest {
|
||||
private fun hostProgram(root: File, program: String): File = File(root, program.removePrefix("/"))
|
||||
|
||||
/** The environment of the session process: the hook's root, the mounts proot used to make, the preload list. */
|
||||
fun sessionEnvironment(root: File, binds: List<String>, program: String, hostname: String? = null): Map<String, String> {
|
||||
val preload = preloadList(root)
|
||||
fun sessionEnvironment(
|
||||
root: File, binds: List<String>, program: String, hostname: String? = null, lseEmu: String? = null,
|
||||
): Map<String, String> {
|
||||
val preload = preloadList(root).filterNot { lseEmu == "0" && it.substringAfterLast('/') == "liblse_emu.so" }
|
||||
val lse = lseEmu ?: "1".takeIf { preload.any { it.substringAfterLast('/') == "liblse_emu.so" } }
|
||||
return linkedMapOf(
|
||||
"DDNATV_ROOT" to root.path,
|
||||
"DDNATV_EXEC" to execLoader.orEmpty(),
|
||||
@@ -113,6 +116,7 @@ object NativeGuest {
|
||||
"DDNATV_HOSTNAME" to hostname.orEmpty(),
|
||||
"DDNATV_BINDS" to binds.joinToString("|") { if (it.contains(':')) it else "$it:$it" },
|
||||
"DDNATV_PRELOAD" to preload.joinToString(":"),
|
||||
"LSE_EMU" to lse.orEmpty(),
|
||||
"LD_PRELOAD" to (preload.map { File(root, it.removePrefix("/")).path } + hook(root).path).joinToString(":"),
|
||||
).filterValues { it.isNotEmpty() }
|
||||
}
|
||||
|
||||
@@ -343,7 +343,8 @@ object BottomDesktop {
|
||||
LinuxRuntime.commandWithBinds(context, current.root, binds, guest)
|
||||
}
|
||||
val environment = if (current.nativeUserland) {
|
||||
com.droiddeck.launcher.runtime.NativeGuest.sessionEnvironment(current.root, binds, guest.first(), SessionPrefs.guestHostname(context))
|
||||
val lseEmu = current.guest.lastOrNull { it.startsWith("LSE_EMU=") }?.substringAfter('=')
|
||||
com.droiddeck.launcher.runtime.NativeGuest.sessionEnvironment(current.root, binds, guest.first(), SessionPrefs.guestHostname(context), lseEmu)
|
||||
.map { (k, v) -> "$k=$v" }.toTypedArray()
|
||||
} else current.hostEnvironment
|
||||
val line = command.joinToString(" ") { it.replace("\\", "\\\\").replace(" ", "\\ ") }
|
||||
|
||||
@@ -5,6 +5,7 @@ import android.content.Context
|
||||
import android.os.Environment
|
||||
import android.util.Log
|
||||
import com.droiddeck.launcher.R
|
||||
import com.droiddeck.launcher.core.CpuFeatures
|
||||
import com.droiddeck.launcher.core.FileUtils
|
||||
import com.droiddeck.launcher.runtime.BwrapSpawner
|
||||
import com.droiddeck.launcher.runtime.DesktopCatalog
|
||||
@@ -22,6 +23,10 @@ object SessionFiles {
|
||||
private const val NO_PAD_SWITCH = "Download/droiddeck-no-pad"
|
||||
const val DIRECTAUDIO_DIR = "usr/local/lib/directaudio"
|
||||
private const val STAGED_LEDGER = "usr/local/.droiddeck-staged"
|
||||
internal const val LSE_EMU = "usr/local/lib/droiddeck-lse/liblse_emu.so"
|
||||
|
||||
internal fun lsePreload(lacksAtomics: Boolean, staged: Boolean, lseEmu: String? = null): String =
|
||||
if (lacksAtomics && staged && lseEmu != "0") "/$LSE_EMU\n" else ""
|
||||
private const val IME_MANIFEST = "usr/local/share/droiddeck/ime-files.json"
|
||||
private const val IME_DEFAULT_MODE = 420
|
||||
val DIRECTAUDIO_SETS = arrayOf("linux-wine11", "linux-wine11-systhread")
|
||||
@@ -102,10 +107,23 @@ object SessionFiles {
|
||||
}
|
||||
|
||||
private val STAGE_LOCK = Any()
|
||||
@Volatile private var activeSessionLseEmu: String? = null
|
||||
|
||||
fun stage(context: Context, root: File, startsSession: Boolean = false) = synchronized(STAGE_LOCK) { stageNow(context, root, startsSession) }
|
||||
fun stage(context: Context, root: File, startsSession: Boolean = false) =
|
||||
stage(context, root, startsSession, lseEmu = null)
|
||||
|
||||
private fun stageNow(context: Context, root: File, startsSession: Boolean) {
|
||||
fun stage(context: Context, root: File, startsSession: Boolean, lseEmu: String?) =
|
||||
synchronized(STAGE_LOCK) {
|
||||
val selection = if (startsSession) {
|
||||
activeSessionLseEmu = lseEmu
|
||||
lseEmu
|
||||
} else {
|
||||
lseEmu ?: activeSessionLseEmu
|
||||
}
|
||||
stageNow(context, root, startsSession, selection)
|
||||
}
|
||||
|
||||
private fun stageNow(context: Context, root: File, startsSession: Boolean, lseEmu: String?) {
|
||||
if (DesktopCatalog.desktopInstalled(root) && !DesktopCatalog.desktopFromPack(root)) try { DesktopCatalog.cleanLegacy(context) }
|
||||
catch (e: Exception) { Log.w(TAG, "LXQt cleanup will retry next session", e) }
|
||||
GameEnvironmentStore.publish(context)
|
||||
@@ -281,6 +299,7 @@ object SessionFiles {
|
||||
"usr/local/lib/droiddeck-pipewire.tzst" to "usr/local/lib/droiddeck-pipewire.tzst",
|
||||
"usr/local/share/licenses/dwarfs/LICENSE" to "usr/local/share/licenses/dwarfs/LICENSE",
|
||||
"usr/local/share/licenses/uruntime/LICENSE" to "usr/local/share/licenses/uruntime/LICENSE",
|
||||
LSE_EMU to LSE_EMU,
|
||||
) + mangoapp + xclipse.map { it to it } + maliCompat + msitools.map { it to it } + vr + gpuLoad + fexPreloads).filter { (asset, _) ->
|
||||
val dir = asset.substringBeforeLast('/')
|
||||
runCatching { context.assets.list("linuxfs/$dir")?.contains(asset.substringAfterLast('/')) == true }.getOrDefault(false)
|
||||
@@ -343,7 +362,8 @@ object SessionFiles {
|
||||
stageImeFiles(context, root, ledger)
|
||||
ledger.save()
|
||||
for (old in arrayOf("aarch64-unix", "aarch64-windows", "i386-windows")) File(root, "$DIRECTAUDIO_DIR/lib/wine/$old").deleteRecursively()
|
||||
val preload = StringBuilder("/usr/local/lib/libddsession.so\n")
|
||||
val preload = StringBuilder(lsePreload(CpuFeatures.lacksAtomics, File(root, LSE_EMU).isFile, lseEmu))
|
||||
preload.append("/usr/local/lib/libddsession.so\n")
|
||||
if (!File(Environment.getExternalStorageDirectory(), NO_PAD_SWITCH).exists()) {
|
||||
preload.append("/usr/local/lib/libfakeinput.so\n")
|
||||
}
|
||||
|
||||
@@ -566,6 +566,7 @@ class SessionService : Service() {
|
||||
.onFailure { Log.w(TAG, "agent environment skipped", it) }
|
||||
val agentEnvironment = nextAgentEnvironment.getOrDefault(emptyList())
|
||||
val customEnvironment = extraEnv()
|
||||
val lseEmu = (customEnvironment + agentEnvironment).lastOrNull { it.startsWith("LSE_EMU=") }?.substringAfter('=')
|
||||
try {
|
||||
if (systemVulkan) {
|
||||
SystemVulkanDriver.prepare(this)
|
||||
@@ -575,7 +576,7 @@ class SessionService : Service() {
|
||||
}
|
||||
pruneSystemVulkanRuntime()
|
||||
}
|
||||
SessionFiles.stage(this, root, startsSession = true)
|
||||
SessionFiles.stage(this, root, startsSession = true, lseEmu = lseEmu)
|
||||
} catch (error: Exception) {
|
||||
Log.e(TAG, "Could not prepare the session graphics runtime", error)
|
||||
failSession(gen, "GRAPHICS_RUNTIME_FAILED", getString(R.string.session_graphics_runtime_failed), -1)
|
||||
@@ -830,7 +831,7 @@ class SessionService : Service() {
|
||||
if (drives > 0) Log.i(TAG, "$drives Wine drive links given their guest paths back")
|
||||
val hostEnv = if (nativeUserland) HostEnvironment().also { env ->
|
||||
Log.i(TAG, "native userland: no proot (${sessionBindSpecs.size} mounts)")
|
||||
com.droiddeck.launcher.runtime.NativeGuest.sessionEnvironment(root, sessionBindSpecs, guest.first(), SessionPrefs.guestHostname(this))
|
||||
com.droiddeck.launcher.runtime.NativeGuest.sessionEnvironment(root, sessionBindSpecs, guest.first(), SessionPrefs.guestHostname(this), lseEmu)
|
||||
.forEach { (k, v) -> env[k] = v }
|
||||
} else prootEnv
|
||||
|
||||
|
||||
Reference in new issue
Block a user