Runtime / Loader / Platform: static TLS alignment & attach races, eh::dump_threads deadlock & VEH bounds, C-unwind FFI boundaries, AVX2 check, and hybrid CPU affinity / PLS quota #106
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl#106
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@raylitebull on GitHub · 2026-11-23 11:15 UTC · original
Summary
Verified several PE loader, static TLS, exception-handling, and host-platform edge cases during an audit of
crates/xcl/src/(onmain60599a9) that warrant focused follow-up PRs:1. Static TLS edge cases (
crates/xcl/src/tls.rs,crates/xcl/src/main.rs,crates/xcl/src/loader.rs)on_thread_attach()IMAGES.try_read()contention: If a game DLL with static TLS is being installed (IMAGES.write()), concurrently attaching OS/game threads hitWouldBlockand silently skip copying all mapped TLS templates, leavingthread_localvariables zeroed..CRT$XLYordering aftertake_slot_zero:XCL_TLS_CALLBACKis placed in.CRT$XLY, which runs after Ruststd's.CRT$XLBcallback. Oncetake_slot_zerorewritesxcl.exe's_tls_indextok, any.CRT$XLB...CRT$XLXcallback on a new thread reads slotk(the title's carrier block) beforeexchange_for_new_threadswaps slots0andk.take_slot_zeroThreadLocalStoragePointerUAF window &MOVEDstale TEBs: Rawarr = *(teb + 0x58)pointers are held acrossSleep(20)without suspending threads (vulnerable if a thread loads a TLS DLL and reallocates its TLS pointer array), andTerminateThreadleaves stale TEBs inMOVED.IMAGE_TLS_DIRECTORY64.Characteristicsalignment & uncheckedAddressOfIndex == 0:tls.rshardcodesCharacteristics = 0in the carrier DLL (dropping 32B/64B alignment required by AVX2/cache-linethread_locals), and callback-only TLS directories withaddress_of_index == 0dereferenceadj(0).2. Exception-handling & diagnostic safety (
crates/xcl/src/eh.rs)dump_threads()deadlock: Allocates (Vec/format!) and callsRtlLookupFunctionEntry,GetModuleHandleExW(Loader Lock), andGetThreadDescription/LocalFree(Process Heap lock) while holding another thread suspended viaSuspendThread. CapturingCONTEXTon the stack and callingResumeThreadimmediately before symbolizing/formatting avoids deadlocking if the target held the heap or loader lock.cpp_exception_loggerVEH crash risk: Performs unboundedCStr::from_ptrafter checking onlyreadable(s, 1)(and assumes[object + 8]isstd::exception::whatfor every thrown C++ object), which can fault inside the VEH near a guard/unmapped page and turn a caught C++ exception fatal; also lacks null checks oninfo/ExceptionRecord/ContextRecord.watch_writes/start_probes: Missingsnap != INVALID_HANDLE_VALUEandSuspendThread(h) != u32::MAXguards.3. PE loader bounds & failure cleanup (
crates/xcl/src/pe.rs,crates/xcl/src/loader.rs)pe.rs::relocations(andthunks/imports/delay_imports/exports) use uncheckedu32addition without verifyingblock <= d.size - pos(panic in debug / potential infinite loop in release on malformed reloc blocks).loader.rsregisters mapped modules beforepe.imports()/tls_install()without unregistering (or freeing on TLS error) on failure, and caches DLLs whoseDllMain(PROCESS_ATTACH)returnedFALSEinMAPPEDso a secondload_game_dllreturnsOk(m).4. FFI
-unwindboundaries, startup CPUID check, and PC-sized platform values-unwindextern "system"/extern "C"boundaries:XMemAlloc/XMemFreeguest hooks (hle/kernelx.rs),console_wndproc(hle/user.rs),DllMain/TlsCallback(loader.rs), and blockingGameInput::RegisterDeviceCallback(hle/gameinput.rs) cross non--unwindRust frames; C++/SEH exceptions unwinding across them abort or skipDropguards.host.rs/launcher.rs): Retail Xbox Series X|S binaries assume Zen 2 (AVX2/FMA/F16C/BMI1/BMI2/POPCNT/SSE4.2/LZCNT); detecting missing ISA features at startup and printing a clear error avoids opaque0xC000001Dcrashes on unsupported CPUs.hle/kernelx.rs):SetThreadAffinityMask/SetThreadGroupAffinity/GetSystemInfo/GlobalMemoryStatusExcurrently fall through unshimmed to Windows, which can fail on <7-core CPUs, pin console 7-core masks onto E-cores on hybrid Intel CPUs, or report PC-sized logical CPU counts / RAM.S:\PLS disk space quota (vfs_hooks.rs):GetDiskFreeSpaceExW/Areports the full host NVMe volume instead of clampingS:\toconfig.pls_mb.Config::load_or_create(config.rs) overwritesxcl.tomlon any read error (not justErrorKind::NotFound), andConfig::resolvematches"auto"/"advanced"case-sensitively;report::write_final(report.rs) can dropcrashifWRITE_LOCK.try_lock()fails concurrently;RegisterClassExA(hle/user.rs) omitscbSizevalidation andconsole_windowpassesSWP_NOSIZEafter subclassingWM_GETMINMAXINFO.github-bot referenced this issue2026-11-26 04:29:54 +00:00
github-bot referenced this issue2026-11-26 04:52:20 +00:00
github-bot referenced this issue2026-11-26 04:53:40 +00:00
github-bot referenced this issue2026-11-26 04:53:49 +00:00
@ivall on GitHub · 2026-11-23 11:42 UTC · original
Thanks. Triage against current
main:Config::load_or_createoverwritingxcl.tomlon any read error – confirmed, fixed inea4bd62(only a missing file gets the defaults; an unreadable one is an error).S:\free space – true that it reports the host volume; titles compare it against what they need, so a larger answer is harmless. Low priority.@ivall on GitHub · 2026-11-23 21:14 UTC · original
Progress: #141 (a DLL that failed to load is not left registered), #148 (title_memory in any case), #183 (TLS without an index variable) and #147 (crash report below a module's base) are merged; #196 (TLS Characteristics alignment / attach contention) and #197 (system-unwind across guest re-entry) are open.
@yous0serious on GitHub · 2026-11-23 21:15 UTC · original
The hybrid CPU affinity item: #221 clamps
SetThreadAffinityMask/SetThreadGroupAffinitymasks that name processors outside the process's affinity (the case triaged above as worth clamping). Masks made from the PC's processors pass unchanged, so the title still sees the PC's processors.Measured on an i7-13700KF: Windows fails such a mask with
ERROR_INVALID_PARAMETERwhen none of its processors exists (0xFF000000on 24 processors), or when any is outside a limited process mask (0x7F/0x3F/0x40understart /affinity F). The E-core concern above does not hold there: Windows numbers the P-core threads first (0–15), so console masks (bits 0–13) land on P-cores.The other items of this issue are not touched by #221.
@mariuslozo-boop on GitHub · 2026-11-23 21:36 UTC · original
A crash in
eh::dump_threads(XCL_THREAD_DUMP_AT), adding to the dump_threads item here.On main
d4f17cawithXCL_THREAD_DUMP_AT=90,180,270and a retail title running (RTX 5070 Ti, Windows 11 26300), the dumps at 90 s and 180 s were fine. At 270.052 s, the dump thread itself crashed and took the process down:ntdll+0x1ff2ais insideRtlVirtualUnwind2:mov rcx, qword ptr [r8]withr8 = 0xf8. While walking a suspended thread's stack, the unwinder dereferences a near-null context pointer.eh::unwindstarts from a context it should not trust, or a frame without a valid function entry. The read happens insideRtlVirtualUnwind, so no check inunwindafter the call can catch it.AI-assisted (Claude Code). No game files attached.
@notquiteog on GitHub · 2026-11-24 17:41 UTC · original
A field occurrence that fits the
dump_threads()deadlock in section 2, onmain9e3831e(release,cargo build --release --workspace), Windows 11 26100, RTX 5060 Ti,XCL_NETWORK=0, retail title 1.0.2.1.The title takes its usual watchdog exit (
+0x23cf683, #846) at 104.8 s.xcl.logends on that line:Nothing follows it: no
on the stack:list, noprocess ends with status …line, no thread dump, and no crash-reporter lines. The process stayed alive for another 8+ minutes until my harness killed it at its 10-minute cap.For comparison, on the same machine and title the same exit was handled normally three times: twice on
077ce40and once on the theaustinayers fork at76d3b9f. Each time the log has the stack, a full per-thread dump andprocess ends with status 0xc0000005within about 1 s, and the process exits. So it's intermittent, as a lock held by a suspended thread would be.eh.rsdid not change between077ce40and9e3831e.I don't have a dump of the hung process, so this is consistent with the suspended-thread heap/loader-lock deadlock described above rather than proof of it. One practical effect: a run that should end in ~1 s after the title's fatal exit instead hangs indefinitely, so unattended test runs need their own timeout.
@pickles976 on GitHub · 2026-11-26 06:46 UTC · original
Follow-through on the
dump_threads()recommendation: resuming before symbolization avoids the original lock problem, but resuming before unwinding leaves the stack live.Current
mainb49be1836844fe0b0cdb3211dce3cb7fb4e21ac7still hasResumeThread(h)ateh.rs:681, thenunwind(&mut c.0, 14)at685;unwindreads the original RSP and callsRtlVirtualUnwindat644. Capturing CONTEXT alone does not freeze the stack bytes subsequently read by the unwinder.Runtime evidence, not a clean-main reproduction: local mixed
1bfa05d9214cf5f68e602233072d8786fd3c529a(#2573 + sparse 4MiB pools/#735/#850 integration), witheh.rsunchanged, fresh release build,XCL_THREAD_DUMP_AT=12,24andXCL_ACTIVITY=1. Instead of the previous title watchdog exception, this attempt logged a different early AV:ntdll.dll+0x38a26, read address0xf0. One55-thread dump was emitted; the second scheduled sample was not reached.xcl.exe+0x54e01d.xcl::eh::dump_threads+0x21d.+0x54e017calls IAT+0x821b60; PE imports resolve that slot tokernel32!RtlVirtualUnwind.xcl+0x4bc83value resolves tod3d12x::frame::clock_thread+0x4c3. The report's stack scan is heuristic, not a certified call chain.This implicates the diagnostic unwinding call; a changed live stack is an inference, not an independently proven trigger. It also does not prove the cause of the separate GPU-telemetry timeout that stopped this run at18.38s. The guard requested scope kill in8ms; no kernel journal entries in the inspected interval; a later bounded GPU query recovered. I will not rerun this unchanged dump probe or use these stacks to assert a title/GPU root cause.
A safe follow-up needs stable stack data plus lock-safe unwinding/symbolization. Simply moving all the existing work back under
SuspendThreadreintroduces the heap/loader-lock risk identified here.Local artifacts
.compat-xcl/logs/20261126T063124Z-{console.log,resources.csv,guard-events.jsonl}and20261126T063124Z-xcl-dump.asm.txt. Wine11.0, NVIDIA590.48.1 / RTX4060 Laptop8GiB,16GiB RAM; diagnostic relaxed vkd3d-proton3.2.02576c0b4adfae4a+(assertions disabled; allocator/list vtable identity checks removed, null checks retained), not stock-runtime certification. Unchanged GPU6000MiB/RAM-available2048MiB/disk-available10GiB guards and9GiB cgroup/512MiB swap caps. No code PR/push or title patch.