fix(fex): signal return restores syscall state; CurseForge runs headless (#3040)

* fix(fex): signal return restores the interrupted syscall state

A guest rt_sigreturn goes through FEX's syscall stub, which marks every
static register as spilled. Returning to unchanged JIT code skipped the
stub's reset, so later asynchronous signals skipped the register spill
and guest handlers read stale registers. CoreCLR's GC suspension reads
and redirects that context, which made x86-64 .NET programs fail with
random access violations. Restore the value saved at signal entry.

* fix(addons): run CurseForge headless from the addon browser, without a session

- The CurseForge source starts the app in its own headless gamescope
  (droiddeck-headless, shared with the Battle.net Agent) instead of a hidden
  session: no SessionService, compositor output or ImageReader.
- The helper's start keeps running until the app exits, so the app lives
  for as long as the addon browser holds that guest command; closing the
  dialog asks the app to quit, stops its process group and cancels the
  command, which ends the app, its gamescope and the guest.
- An app the user already has open is reported busy and left alone.
- Removes BackgroundSession and the CompositorHost start path it shared with
  SessionActivity, with their tests.

* fix(addons): bind each CurseForge stop to its launch and keep the inspector URL out of logs

A stop now only acts on the launch that registered it, so a late stop
from a closed browser cannot end a newer launch, and the browser stops
once. Command logs redact the inspector URL. The signal probe reports a
sender thread that cannot start, sets ECX before the measured region and
its test accepts a valid overshoot of the target count.

* fix(fex): unblock the probe signal before sampling
This commit is contained in:
MaxsTechReview authored and GitHub committed 2026-11-22 20:40:30 -05:00
1 parent 6ef8e2274e
commit 527cb85867
21 files changed
+663 -415

No files matched your search

@@ -8,6 +8,7 @@ import org.junit.Assert.assertFalse
import org.junit.Assert.assertNull
import org.junit.Assert.assertThrows
import org.junit.Assert.assertTrue
import org.junit.After
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TemporaryFolder
@@ -21,6 +22,47 @@ import java.io.File
class CurseForgeAppTest {
@get:Rule val temp = TemporaryFolder()
private val original = CurseForgeApp.guest
private val url = "ws://127.0.0.1:43117/0f8fad5b-d9cb-469f-a165-70867728950e"
private val app = UserApps.App("appimage:c", UserApps.Kind.APPIMAGE, "CurseForge", null, null, AppImageManager.LAUNCHER, listOf("/root/apps/curseforge"), feed = CurseForgeApp.FEED)
@After
fun restoreGuest() {
val context = org.robolectric.RuntimeEnvironment.getApplication()
launches.forEach { CurseForgeApp.stop(context, app, null, it) }
holder.get()?.set(true)
CurseForgeApp.guest = original
}
private val launches = mutableListOf<java.util.concurrent.atomic.AtomicBoolean>()
private fun launch(): java.util.concurrent.atomic.AtomicBoolean = java.util.concurrent.atomic.AtomicBoolean(false).also { launches += it }
private val holder = java.util.concurrent.atomic.AtomicReference<java.util.concurrent.atomic.AtomicBoolean?>()
private val released = java.util.concurrent.CountDownLatch(1)
private fun fakeGuest(startExit: Int, ready: Boolean = true): MutableList<List<String>> {
val calls = java.util.Collections.synchronizedList(mutableListOf<List<String>>())
CurseForgeApp.guest = { _, argv, cancelled, onLine ->
calls += argv
when {
argv[0] == CurseForgeApp.HELPER && argv[1] == "start" -> {
if (startExit == 0) {
holder.set(cancelled)
onLine(url)
while (cancelled?.get() != true) Thread.sleep(10)
released.countDown()
} else onLine("busy")
startExit
}
argv[0] == CurseForgeApp.HELPER -> 0
ready -> { onLine(JSONObject().put("ok", true).put("value", """{"value":true}""").toString()); 0 }
else -> { onLine(JSONObject().put("ok", false).put("error", JSONObject().put("code", "DEVTOOLS_UNREACHABLE").put("message", "no")).toString()); 0 }
}
}
return calls
}
private val search = """{"success":true,"injectedCount":0,
"pagination":{"index":0,"pageSize":20,"resultCount":20,"totalCount":150},
"mods":[
@@ -129,7 +171,7 @@ class CurseForgeAppTest {
assertEquals(emptySet<String>(), CurseForgeApp.projectIds(JSONObject()))
assertEquals(CurseForgeApp.Start.READY, CurseForgeApp.startState(0))
assertEquals(CurseForgeApp.Start.BUSY, CurseForgeApp.startState(3))
assertEquals(CurseForgeApp.Start.NO_DISPLAY, CurseForgeApp.startState(4))
assertEquals(CurseForgeApp.Start.FAILED, CurseForgeApp.startState(4))
assertEquals(CurseForgeApp.Start.FAILED, CurseForgeApp.startState(5))
}
@@ -158,4 +200,102 @@ class CurseForgeAppTest {
assertEquals(File(root, target.flavor), WowAddons.flavorDir(target))
}
}
@Test
fun theAppStartsInTheGuestWithoutASessionAndIsAskedThroughItsInspector() {
val calls = fakeGuest(0)
val started = CurseForgeApp.start(org.robolectric.RuntimeEnvironment.getApplication(), app, launch())
assertEquals(CurseForgeApp.Start.READY, started.state)
assertEquals(url, started.inspector)
assertEquals(listOf(CurseForgeApp.HELPER, "start", "/root/apps/curseforge"), calls.first())
val probe = calls[1]
assertEquals(listOf(CurseForgeApp.AGENT, "--cdp-inspector", url), probe.take(3))
assertEquals("10.0", probe[3])
assertTrue(probe[4].contains("InstalledProjectsAppService"))
}
@Test
fun theLaunchLivesUntilItIsStopped() {
fakeGuest(0)
val context = org.robolectric.RuntimeEnvironment.getApplication()
val hold = launch()
assertEquals(CurseForgeApp.Start.READY, CurseForgeApp.start(context, app, hold).state)
assertEquals(false, holder.get()?.get())
assertEquals(1L, released.count)
CurseForgeApp.stop(context, app, url, hold)
assertTrue(released.await(5, java.util.concurrent.TimeUnit.SECONDS))
}
@Test
fun anAppThatIsAlreadyOpenIsNeitherUsedNorStopped() {
val calls = fakeGuest(3)
assertEquals(CurseForgeApp.Start.BUSY, CurseForgeApp.start(org.robolectric.RuntimeEnvironment.getApplication(), app, launch()).state)
assertEquals(listOf(listOf(CurseForgeApp.HELPER, "start", "/root/apps/curseforge")), calls)
}
@Test
fun stoppingAsksTheAppToQuitThenStopsItsHeadlessLaunchOnce() {
val calls = fakeGuest(0)
val context = org.robolectric.RuntimeEnvironment.getApplication()
val hold = launch()
CurseForgeApp.start(context, app, hold)
calls.clear()
CurseForgeApp.stop(context, app, url, hold)
assertEquals(CurseForgeApp.AGENT, calls[0][0])
assertTrue(calls[0][4].contains("shutdown"))
assertEquals(listOf(CurseForgeApp.HELPER, "stop", "/root/apps/curseforge"), calls[1])
assertTrue(hold.get())
calls.clear()
CurseForgeApp.stop(context, app, url, hold)
assertTrue(calls.isEmpty())
}
@Test
fun aLateStopLeavesTheNewerLaunchRunning() {
val calls = fakeGuest(0)
val context = org.robolectric.RuntimeEnvironment.getApplication()
val old = launch()
val newer = launch()
CurseForgeApp.start(context, app, old)
CurseForgeApp.start(context, app, newer)
assertTrue(old.get())
calls.clear()
CurseForgeApp.stop(context, app, url, old)
assertTrue(calls.isEmpty())
assertEquals(false, newer.get())
CurseForgeApp.stop(context, app, null, newer)
assertEquals(listOf(listOf(CurseForgeApp.HELPER, "stop", "/root/apps/curseforge")), calls)
}
@Test
fun aStoppedLaunchNeverStarts() {
val calls = fakeGuest(0)
val hold = launch().apply { set(true) }
assertEquals(CurseForgeApp.Start.FAILED, CurseForgeApp.start(org.robolectric.RuntimeEnvironment.getApplication(), app, hold).state)
assertTrue(calls.isEmpty())
}
@Test
fun anAppWithoutADirectoryIsNeverLaunched() {
val calls = fakeGuest(0)
val bare = UserApps.App("appimage:d", UserApps.Kind.APPIMAGE, "CurseForge", null, null, AppImageManager.LAUNCHER, emptyList(), feed = CurseForgeApp.FEED)
val hold = launch()
assertEquals(CurseForgeApp.Start.FAILED, CurseForgeApp.start(org.robolectric.RuntimeEnvironment.getApplication(), bare, hold).state)
CurseForgeApp.stop(org.robolectric.RuntimeEnvironment.getApplication(), bare, url, hold)
assertTrue(calls.isEmpty())
}
@Test
fun theInspectorUrlIsRedactedFromCommandLogs() {
val line = CurseForgeApp.evalArgv(url, "x", 1_000).joinToString(" ")
assertTrue(line.contains(url))
assertTrue(!GuestCommand.redacted(line, CurseForgeApp.INSPECTOR).contains("127.0.0.1"))
assertTrue(!GuestCommand.redacted(url, CurseForgeApp.INSPECTOR).contains(url))
}
@Test
fun theAgentAnswerIsTheLastJsonLine() {
assertEquals("a", CurseForgeApp.lastJson(listOf("noise", """{"v":"a"}""", "== done"))?.getString("v"))
assertNull(CurseForgeApp.lastJson(listOf("noise")))
}
}