From be8bce2d03a0d5ec485ed28ac236601f0d25f7fa Mon Sep 17 00:00:00 2001 From: Tiago Leal <183942127+tiagonleal@users.noreply.github.com> Date: Sun, 29 Nov 2026 22:13:25 +0000 Subject: [PATCH] Tests: recording-memory tests leave no fake allocator backing behind a_recordings_memory_is_held_for_the_pc_allocator_it_is_on reset its stack-address list on the fake allocator `other` (a Box address + 2), which made alloc_pool record the list as a user of a backing keyed by `other`. Cleanup removed the LISTS entry but never forget_list'ed the list, so forget(other) found the backing busy and only marked it retire_when_free. After the Box was freed, any later test on the same worker whose list reused that stack slot called on_release -> forget_list, the backing became free, and sweep_release_owners dropped ID3D12CommandAllocator::from_raw(other): windows-core checks the vtable pointer alignment and the non-unwinding panic aborted the whole lib test binary (0xc0000409), seen in wait64_flags_do_not_mask_the_recorded_counter. Both reset tests in list_x now clean up with on_release(key) before forgetting the fake allocators, like their neighbours, and the recording-memory test asserts that alloc_pool keeps nothing keyed by its fake ids. The bind test that leaves a recording on the fake `busy` allocator drops that backing without releasing it, as the alloc_pool tests do with their synthetic backings. --- crates/xcl/src/hle/d3d12x/alloc_pool.rs | 19 +++++++++++++++++++ crates/xcl/src/hle/d3d12x/bind.rs | 1 + crates/xcl/src/hle/d3d12x/list_x.rs | 7 +++++-- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/crates/xcl/src/hle/d3d12x/alloc_pool.rs b/crates/xcl/src/hle/d3d12x/alloc_pool.rs index bbb56bdc3f..b5559baa84 100644 --- a/crates/xcl/src/hle/d3d12x/alloc_pool.rs +++ b/crates/xcl/src/hle/d3d12x/alloc_pool.rs @@ -989,6 +989,25 @@ pub(super) fn stand_in_for_test(alloc: usize, pc: usize) { STATE.lock().unwrap().get_or_insert_with(State::default).cur.insert(alloc, pc); } +/// Whether STATE still keys anything by the fake id `raw` (a backing or a recording list). +#[cfg(test)] +pub(super) fn tracks_for_test(raw: usize) -> bool { + STATE.lock().unwrap().as_ref().is_some_and(|s| s.backings.contains_key(&raw) || s.of_list.contains_key(&raw)) +} + +/// Drop the fake backing `raw` and its users' recordings without releasing it: it has no COM +/// object for a later sweep to release. +#[cfg(test)] +pub(super) fn drop_synthetic_for_test(raw: usize) { + let mut g = STATE.lock().unwrap(); + let Some(s) = g.as_mut() else { return }; + if let Some(gone) = s.backings.remove(&raw) { + for l in gone.users { + s.of_list.remove(&l); + } + } +} + /// The PC allocator the title's allocator `alloc` stands for now. pub fn current(alloc: usize) -> usize { if !enabled() { diff --git a/crates/xcl/src/hle/d3d12x/bind.rs b/crates/xcl/src/hle/d3d12x/bind.rs index 05560bd3ae..cba6ffce66 100644 --- a/crates/xcl/src/hle/d3d12x/bind.rs +++ b/crates/xcl/src/hle/d3d12x/bind.rs @@ -7927,6 +7927,7 @@ void main(uint t : SV_GroupIndex) { // (before the assertions: nothing of this test stays) let left = ALLOC_RES.lock().unwrap().as_mut().and_then(|m| m.remove(&busy)); drop(left); + super::super::alloc_pool::drop_synthetic_for_test(busy); assert!(held_done.is_empty(), "the released allocator's buffers do not wait for a Reset that never comes"); assert_eq!(freed, vec![a_raw], "they are kept for reuse"); assert_eq!(held_busy, vec![b_raw], "a list still records on the other: its buffers stay"); diff --git a/crates/xcl/src/hle/d3d12x/list_x.rs b/crates/xcl/src/hle/d3d12x/list_x.rs index 4f3dae2265..9990beaf81 100644 --- a/crates/xcl/src/hle/d3d12x/list_x.rs +++ b/crates/xcl/src/hle/d3d12x/list_x.rs @@ -8114,7 +8114,7 @@ mod tests { ); assert_eq!(super::super::console_list::take_pending_for_test(0x111), vec![0x4444]); - LISTS.lock().unwrap().as_mut().unwrap().remove(&key); + on_release(key); super::super::bind::remove_state_for_test(list); unsafe { super::super::alloc_pool::forget(0x111); @@ -8154,7 +8154,7 @@ mod tests { let held_for_pc = super::super::console_list::take_pending_for_test(pc); let held_for_title = super::super::console_list::take_pending_for_test(title); - LISTS.lock().unwrap().as_mut().unwrap().remove(&key); + on_release(key); super::super::bind::remove_state_for_test(list); super::super::alloc_pool::stand_in_for_test(title, title); unsafe { @@ -8162,6 +8162,9 @@ mod tests { super::super::alloc_pool::forget(pc); super::super::alloc_pool::forget(other); } + // (a backing left on a fake id is released through it when a reused stack address goes) + let left = [key, title, pc, other].map(super::super::alloc_pool::tracks_for_test); + assert_eq!(left, [false; 4], "the test leaves nothing keyed by its fake ids"); assert_eq!(recording_on, pc, "the recording is on the PC allocator the title's allocator stands for"); assert_eq!(held_for_pc, vec![block]); assert!(held_for_title.is_empty());