D3D12-HLE-APU-HANDLE-LIFETIME-AND-ALIGNMENT: track live APU handles with Arc registry and unaligned guest I/O #2676
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2676"
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?
Imported from ubiquitarianism/leonida. Originally posted by bobcatchris on 2026-11-30T01:44:36Z.
Claimed in #2570 as
D3D12-HLE-APU-HANDLE-LIFETIME-AND-ALIGNMENT(#issuecomment-7260917882).What and why
In
d3d12/crates/leonida-hle/src/modules/apu.rs:Connectionwere handed out as opaque APU handles without tracking live handles, allowing stale or invalid handles to be dereferenced after release. This change tracks live handles in a registry backed byArc<Connection>with proper cleanup on close/drop, rejecting unknown or already-closed handles safely.read_unaligned/write_unalignedinstead of aligned dereferences, eliminating undefined behavior (0xc0000409in debug builds) on unaligned guest pointers.Verification (Red -> Green)
Hardware / OS: native Windows 11 Pro (
10.0.26200), AMD Ryzen 7 7800X3D, Rust1.98.0xc0000409(misaligned pointer dereference) and stale-handle calls were unguarded.main40e7fe69d):cargo test -p leonida-hle --lib apu— ALL PASS (and fullleonida-hle --libPASS).python -I scripts/check_no_game_data.py d3d12/crates/leonida-hle/src/modules/apu.rs— PASS.AI-assisted: Antigravity (Gemini 4 Neon)
Imported from ubiquitarianism/leonida. Originally posted by Kal0s-design on 2026-11-30T11:25:23Z.
Independent Windows verification of
24b7bf5f9onmaind367675c7(clean merge,4ce4aa96f). Native Windows 11, MSVC x64, Rust 1.98.1, debugcargo test -p leonida-hle --lib. Each new test run alone, since an abort takes the whole binary down.main+ only this PR's two test functions.connect_accepts_unaligned_input_output_and_handleaborts withmisaligned pointer dereference: address must be a multiple of 0x4atapu.rs:155, exit0xc0000409.stale_and_foreign_handles_are_rejected_without_uafdies with0xc0000005(access violation) once the freed handle is passed back in.main+ this PR. Both pass; whole crate 220 passed, 2 ignored, 0 failed (main: 218 + these two).Read the change: a call that holds a cloned
Arcwhile another thread disconnects keeps the memory and event alive until it returns, and the ids never repeat (monotonic, never 0), so a stale handle can't land on a newer connection. Theunsafe impl Send/Syncis only needed for the rawmemoryandeventfields;opus-pure's decoder state holds noRc/Cell, it's plain data behind theMutex.GPUs tested: n/a (CPU unit tests). AI-assisted: yes.
Imported from ubiquitarianism/leonida. Originally posted by KelboLive on 2026-11-30T16:05:45Z.
Independent check on Windows (not the author), at
24b7bf5f9.cargo test --locked -p leonida-hle --lib: 220 passed, 0 failed, 2 ignored in 0.73 s.leonida-hleonly; no game run, so this is compile + unit coverage of the handle tracking/unaligned access.Environment: Ryzen 9 7950X3D, Windows 11 Pro 10.0.26200.9711, Rust 1.98.1 pinned.
AI-assisted: yes (opencode).
Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-30T16:22:04Z.
Merged on head
24b7bf5f9. @Kal0s-design ran the red/green on this head (Windows 11, Rust 1.98.1: both new tests abort onmainand pass with this pull request); @KelboLive ran the crate green on this head (220 passed). CPU unit tests, no GPU. CI was green on this head and no test was run by the merger.Merged by MoonEyes. AI-assisted: yes (Claude Code).