Force SSBS for Proton games (libssbs.so), switch under FEX preset (#328)

* Force SSBS for a game's Wine: libssbs.so, opt in per game

Wine's arm64 signal code resumes threads from a Windows CONTEXT whose
Cpsr never carries PSTATE.SSBS, so every signal return leaves the
thread running with speculative store bypass disabled - slower on cores
such as Oryon. Bannerlator fixes it in its own Wine builds
(force_ssbs.diff, Sonicadvance1) and with an LD_PRELOAD adapter for
layers it cannot rebuild. DroidDeck's Protons (Valve, GE, CachyOS ARM64)
come prebuilt from Steam but run the same aarch64 Wine signal path, so
the adapter applies here: tools/linuxfs/ssbs/ssbs_adapter.c, the same
source built for glibc (+ sysv_signal), staged to
/usr/local/lib/libssbs.so.

droiddeck-game-env preloads it when the game's (or the shared)
environment sets DROIDDECK_FORCE_SSBS=1, and only into an ARM64 Proton.
Off unless asked for: the gain is unproven on Snapdragon 8 Gen 3.

For testing: SSBS_ADAPTER_OBSERVE=1 counts without changing anything
(the baseline) and SSBS_ADAPTER_DEBUG=1 logs the fixes; both also count
signals that ARRIVE while a thread runs without SSBS, which shows
whether anything besides signal returns clears it. Checked on an ARM64
Linux kernel: a handler that clears SSBS left 4 of 5 later signals
arriving with it clear; with the adapter, 0 of 5.

* Force SSBS: a switch under the FEX preset in Steam settings

Steam settings > Games gets "Force SSBS" right under the FEX preset, off
unless turned on. Like the preset it goes into the game environment's
defaults (DROIDDECK_FORCE_SSBS=1), published at once and read by
droiddeck-game-env on the next game launch, so a game's own environment
can still set it to 0.

Measured on the device with the adapter's counters (AYANEO Pocket FIT,
DiRT 3 on GE-Proton11-7-aarch64): observing only, 8192 of 8277 signals
found the thread running without SSBS; with the adapter, none did - it
keeps the bit set everywhere Wine clears it, as a rebuilt ntdll would.
The speed-up itself is reported on Oryon cores and was not measurable on
the FIT's 8 Gen 3, hence off by default.

---------

Co-authored-by: The412Banner <the412banner@users.noreply.github.com>
This commit is contained in:
The412BannerandThe412Banner authored and GitHub committed 2026-10-06 09:27:15 -04:00
1 parent a1b01a04a8
commit bc01b77752
13 files changed
+283 -6

No files matched your search

+24
View File
@@ -461,3 +461,27 @@ class DirectAudioPrefixTest(unittest.TestCase):
if __name__ == "__main__":
unittest.main()
class ForceSsbsTest(unittest.TestCase):
def test_libssbs_is_preloaded_only_when_asked_and_only_into_arm64_proton(self):
with tempfile.TemporaryDirectory() as tmp:
arm = Path(tmp) / "arm"
(arm / "files/lib/wine/aarch64-unix").mkdir(parents=True)
x86 = Path(tmp) / "x86"
(x86 / "files/lib/wine/x86_64-unix").mkdir(parents=True)
lib = Path(tmp) / "libssbs.so"
lib.write_bytes(b"\x7fELF")
g = MODULE["force_ssbs"].__globals__
old = g["SSBS_LIB"]
g["SSBS_LIB"] = str(lib)
try:
env = {"LD_PRELOAD": "/usr/local/lib/libblsession.so"}
self.assertEqual(MODULE["force_ssbs"]([str(arm / "proton"), "waitforexitandrun"], env), env)
on = dict(env, DROIDDECK_FORCE_SSBS="1")
got = MODULE["force_ssbs"]([str(arm / "proton"), "waitforexitandrun"], on)
self.assertEqual(got["LD_PRELOAD"], "/usr/local/lib/libblsession.so:" + str(lib))
self.assertEqual(MODULE["force_ssbs"]([str(arm / "proton")], got)["LD_PRELOAD"], got["LD_PRELOAD"])
self.assertEqual(MODULE["force_ssbs"]([str(x86 / "proton")], on), on)
finally:
g["SSBS_LIB"] = old