hle/acphal: fix APU range overflow/overlap, SHAPE rollback, and XApuConnect OOM #90
No reviewers
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!90
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/90/head"
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?
@certified-retart on GitHub · 2026-11-23 02:57 UTC · original
certified-retart:fix/acphal-overflow-and-oom→main· +316 −32 · 1 files · 1 commits · merged 2026-11-23 10:47 UTCSummary
Hardens overflow handling, range allocation, rollback cleanup, and OOM propagation in
hle::acphal:Apu::address):(size.max(1) + 0xFFF) & !0xFFFoverflowedu32(panicking in debug builds or stallingself.nextat+0in release) and wrappingself.nextcould cause new APU ranges to crossu32::MAXor overlap live mappings, breakingApuMapApuAddressreverse lookups.Apu::addressis now fallible (Option<u32>), rejects ranges that cannot fit without wrappingu32, scans past live regions when reclaiming space fromAPU_BASE, reuses existing regions for non-owned mappings only when the full requested span is covered, and always registers ownedApuAllocentries distinctly (ApuFreealso prefers matching owned entries).ApuAllocfrees itsVirtualAllocblock on APU range exhaustion.alloc_aligned.vainApuMapVirtualAddresswithE_INVALIDARG.Instant::checked_subinChannel::popinstead of panickingnow - FRAME * 8.AcpHalAllocateShapeContexts:counts[i].checked_mul(CONTEXT_BYTES)products upfront instead ofsaturating_mul.ApuAllocallocations on failure without leaking or disturbing previously live SHAPE contexts, publishes output pointers underSHAPE.lock(), and frees replaced prior allocations outside the lock.XApuConnectOOM & partial-resource cleanup:E_OUTOFMEMORYinstead of silently returningS_OKwithoutput.data == NULLwhenalloc_aligned,CreateEventW, orchannels.try_reserve_exactfails, releasing any already-acquired buffer/event and clearingoutputand*handle.Verification
cargo test -p xcl --lib hle::acphal -- --test-threads=1: 6 passed; 0 failedapu_address_prevents_overflow_overlap_and_rejects_null_va(verifiesu32::MAXrejection, non-overlapping wraparound past live regions, owned vs unowned separation, and nullvarejection).shape_contexts_overflow_and_partial_failure_roll_back(verifiescounts[i] * CONTEXT_BYTESoverflow, realApuAllocrollback on partial failure, preservation of live allocations on failed replacement, and cleanup on successful replacement).xapu_connect_returns_oom_and_cleans_up_on_failure(verifiesE_OUTOFMEMORY, output clearing, andVirtualQueryMEM_FREErelease of the data buffer when event creation fails).@Lum7nt on GitHub · 2026-11-23 05:56 UTC · original
Tested this branch locally on Windows — all 6 tests in
hle::acphalpass cleanly.Key improvements verified:
APU_LIMITprevention ensures memory mappings do not wrap or overlap live regions, preventing corruptedApuMapApuAddressreverse lookups.XApuConnectpropagatesE_OUTOFMEMORYand releases allocated buffers when event creation or channel reservation fails.Clean and well-tested hardening for the APU subsystem.
@ivall on GitHub · 2026-11-23 10:48 UTC · original
Merged. XDefiant sets up its APU heap / SHAPE contexts / XApuConnect through this at start and still runs. Tested on Windows 11 with an RX 9070 (RDNA4):
cargo test --workspacegreen with the retail samples (shader pack, console DLLs, texture archive), lib tests also withXCL_SPLIT_WAVE64=1; Unicorn Overlord and XDefiant run with this round merged. Thanks!