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

Closed
ahmetbagci8 wants to merge 660 commits from upstream-pr/437 into main
ahmetbagci8 commented 2026-11-29 11:23:35 +00:00 (Migrated from github.com)

Imported from TaynanGT/Vice-Tay. Originally posted by ahmetbagci8 on 2026-11-29T11:23:35Z.


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)
<!-- greyfinch-sync:TaynanGT/Vice-Tay:issue:5550223563 --> Imported from [TaynanGT/Vice-Tay](https://github.com/TaynanGT/Vice-Tay/pull/437). Originally posted by [ahmetbagci8](https://github.com/ahmetbagci8) on 2026-11-29T11:23:35Z. --- ## 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)
TaynanGT commented 2026-11-29 11:35:21 +00:00 (Migrated from github.com)

Imported from TaynanGT/Vice-Tay. Originally posted by TaynanGT on 2026-11-29T11:35:21Z.


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.

<!-- greyfinch-sync:TaynanGT/Vice-Tay:comment:7255214183 --> Imported from [TaynanGT/Vice-Tay](https://github.com/TaynanGT/Vice-Tay/pull/437#issuecomment-7255214183). Originally posted by [TaynanGT](https://github.com/TaynanGT) on 2026-11-29T11:35:21Z. --- 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.
Kal0s-design commented 2026-11-29 12:57:58 +00:00 (Migrated from github.com)

Imported from TaynanGT/Vice-Tay. Originally posted by Kal0s-design on 2026-11-29T12:57:58Z.

Review: COMMENTED


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

<!-- greyfinch-sync:TaynanGT/Vice-Tay:review:6102970969 --> Imported from [TaynanGT/Vice-Tay](https://github.com/TaynanGT/Vice-Tay/pull/437#pullrequestreview-6102970969). Originally posted by [Kal0s-design](https://github.com/Kal0s-design) on 2026-11-29T12:57:58Z. **Review:** COMMENTED --- 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
TaynanGT commented 2026-11-29 19:03:57 +00:00 (Migrated from github.com)

Imported from TaynanGT/Vice-Tay. Originally posted by TaynanGT on 2026-11-29T19:03:57Z.


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.

<!-- greyfinch-sync:TaynanGT/Vice-Tay:comment:7260978359 --> Imported from [TaynanGT/Vice-Tay](https://github.com/TaynanGT/Vice-Tay/pull/437#issuecomment-7260978359). Originally posted by [TaynanGT](https://github.com/TaynanGT) on 2026-11-29T19:03:57Z. --- 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 commented 2026-11-30 17:07:07 +00:00 (Migrated from github.com)

Imported from TaynanGT/Vice-Tay. Originally posted by TaynanGT on 2026-11-30T17:07:07Z.


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.

<!-- greyfinch-sync:TaynanGT/Vice-Tay:comment:7285746149 --> Imported from [TaynanGT/Vice-Tay](https://github.com/TaynanGT/Vice-Tay/pull/437#issuecomment-7285746149). Originally posted by [TaynanGT](https://github.com/TaynanGT) on 2026-11-30T17:07:07Z. --- `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

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
TaynanGT/Vice-Tay!437
No description provided.