Remove stale owner entry in xmem::arrange when target slice is unowned #437

Closed
github-bot wants to merge 660 commits from github-bot/gh-437 into main AGit
Owner

@⁠ahmetbagci8 on GitHub · 2026-11-29 11:23 UTC · original
ahmetbagci8:fix/xmem-arrange-stale-owner → main · +60038 −5429 · 206 files · 660 commits · closed without merging

Problem

In crates/victory-hle/src/modules/xmem.rs, rrange() builds an owner: HashMap<usize, usize> mapping slice_index -> page_number for the section. When moving *number from slice have to want:

  • If want has an existing owner other, other is moved to have and owner.insert(have, other) overwrites have.
  • If want has no owner (for example, that page was freed via XMemFreePhysicalPages), the if let Some(other) branch does not run and have is left pointing to *number in owner.

On a subsequent iteration that wants have, owner.get(&have) finds the stale *number and overwrites its slice.index, leaving *number at the wrong slice instead of want.

Fix

Remove have from owner in the else branch when want has no current owner, and add a unit test (rrange_clears_stale_owner_when_target_slice_is_unowned) covering the freed-slice case.

Verification

  • cargo test -p victory-hle --lib xmem (19 passed, 0 failed)
  • cargo clippy -p victory-hle --tests (0 warnings)
**@⁠ahmetbagci8** on GitHub · 2026-11-29 11:23 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/437) `ahmetbagci8:fix/xmem-arrange-stale-owner` → `main` · +60038 −5429 · 206 files · 660 commits · closed without merging ## Problem In crates/victory-hle/src/modules/xmem.rs, rrange() builds an owner: HashMap<usize, usize> mapping slice_index -> page_number for the section. When moving *number from slice have to want: - If want has an existing owner other, other is moved to have and owner.insert(have, other) overwrites have. - If want has **no** owner (for example, that page was freed via XMemFreePhysicalPages), the if let Some(other) branch does not run and have is left pointing to *number in owner. On a subsequent iteration that wants have, owner.get(&have) finds the stale *number and overwrites its slice.index, leaving *number at the wrong slice instead of want. ## Fix Remove have from owner in the else branch when want has no current owner, and add a unit test (rrange_clears_stale_owner_when_target_slice_is_unowned) covering the freed-slice case. ## Verification - cargo test -p victory-hle --lib xmem (19 passed, 0 failed) - cargo clippy -p victory-hle --tests (0 warnings)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-29 11:27:22 +00:00
Author
Owner

@⁠TaynanGT on GitHub · 2026-11-29 11:35 UTC · original

Thanks for isolating the stale reverse mapping. The freed-slice regression is useful; please also check that the normal occupied-target swap retains both owners and that subsequent rearrangements cannot see the old entry.

**@⁠TaynanGT** on GitHub · 2026-11-29 11:35 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/437#issuecomment-7255214183) Thanks for isolating the stale reverse mapping. The freed-slice regression is useful; please also check that the normal occupied-target swap retains both owners and that subsequent rearrangements cannot see the old entry.
Author
Owner

@⁠Kal0s-design on GitHub · 2026-11-29 12:57 UTC · original · reviewed

Ran this on Windows. cargo test -p victory-hle --lib gives 223 passed (the xmem group is 19), and cargo clippy -p victory-hle --all-targets -D warnings is clean. With the else branch taken out, the new test fails on the [Some(1), Some(2)] assertion. With it in, it passes.

The fix looks right. Once number leaves have for an unowned want, nothing owns have any more, so leaving owner[have] = number lets a later iteration move number back. The else also covers the case where owner names a page that's no longer in the table, which is the right outcome there too.

AI-assisted: yes

**@⁠Kal0s-design** on GitHub · 2026-11-29 12:57 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/437#pullrequestreview-6102970969) · **reviewed** Ran this on Windows. `cargo test -p victory-hle --lib` gives 223 passed (the xmem group is 19), and `cargo clippy -p victory-hle --all-targets -D warnings` is clean. With the `else` branch taken out, the new test fails on the `[Some(1), Some(2)]` assertion. With it in, it passes. The fix looks right. Once `number` leaves `have` for an unowned `want`, nothing owns `have` any more, so leaving `owner[have] = number` lets a later iteration move `number` back. The `else` also covers the case where `owner` names a page that's no longer in the table, which is the right outcome there too. AI-assisted: yes
Author
Owner

@⁠TaynanGT on GitHub · 2026-11-29 19:03 UTC · original

Thanks for running this natively and confirming the regression fails without the else branch. The new test exercises two consecutive moves into unowned slices, so the stale reverse entry is covered directly. Please keep the existing occupied-target swap coverage alongside it.

**@⁠TaynanGT** on GitHub · 2026-11-29 19:03 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/437#issuecomment-7260978359) Thanks for running this natively and confirming the regression fails without the else branch. The new test exercises two consecutive moves into unowned slices, so the stale reverse entry is covered directly. Please keep the existing occupied-target swap coverage alongside it.
github-bot closed this pull request 2026-11-30 17:08:41 +00:00
Author
Owner

@⁠TaynanGT on GitHub · 2026-11-30 17:07 UTC · original

main has moved to a new line of the code and everything is now named Vice-Tay, so this PR no longer applies as it is (details in #468). If you'd like this change in, please rebuild it on the current main and open a new PR; I'll review it there.

**@⁠TaynanGT** on GitHub · 2026-11-30 17:07 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/437#issuecomment-7285746149) `main` has moved to a new line of the code and everything is now named Vice-Tay, so this PR no longer applies as it is (details in #468). If you'd like this change in, please rebuild it on the current `main` and open a new PR; I'll review it there.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.