apps/victory: use dedicated Win32 HeapCreate global allocator and add VICTORY_NO_WATCH_GUARDS toggle #2422

Open
faycalbaklouti wants to merge 2 commits from upstream-pr/2424 into main
faycalbaklouti commented 2026-11-25 13:14:25 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by faycalbaklouti on 2026-11-25T13:14:25Z.


Target upstream: Marvisak/VIctory (also applicable to Belobug/VIctory-Belobug-AMD and fxceless/victory-fork)

Problem

Sharing the default Win32 process heap (GetProcessHeap()) between the runtime's Rust allocator and title/Wine/system allocations can cause lock inversion deadlocks when a vectored exception handler (VEH) or hook runs while another thread holds the process heap lock. Additionally, having an explicit VICTORY_NO_WATCH_GUARDS diagnostic switch is useful when bisecting page-guard issues.

Solution

  • Add apps/victory/src/private_heap.rs implementing a #[global_allocator] backed by a dedicated Win32 HeapCreate heap so runtime allocations never contend with GetProcessHeap().
  • Wire it in apps/victory/src/main.rs and apps/victory/Cargo.toml.
  • Add the VICTORY_NO_WATCH_GUARDS toggle in crates/victory-gpu/src/watch.rs.

Verification

  • git apply --check passes cleanly on Marvisak/VIctory main (direct zero-conflict apply).

About our fork & censorship-resistant preservation effort:
This fix comes from gta6-vi-port, our open-source Linux (GE-Proton) + NVIDIA RTX 4090 fork of VIctory and peer-to-peer Radicle archival effort (mirroring 92+ community porting repositories across public Radicle seeds so open-source porting research survives centralized takedowns; open-source code only, no game files/keys/binaries).

<!-- greyfinch-sync:Marvisak/VIctory:issue:5492033991 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2424). Originally posted by [faycalbaklouti](https://github.com/faycalbaklouti) on 2026-11-25T13:14:25Z. --- **Target upstream:** `Marvisak/VIctory` (also applicable to `Belobug/VIctory-Belobug-AMD` and `fxceless/victory-fork`) ## Problem Sharing the default Win32 process heap (`GetProcessHeap()`) between the runtime's Rust allocator and title/Wine/system allocations can cause lock inversion deadlocks when a vectored exception handler (VEH) or hook runs while another thread holds the process heap lock. Additionally, having an explicit `VICTORY_NO_WATCH_GUARDS` diagnostic switch is useful when bisecting page-guard issues. ## Solution - Add `apps/victory/src/private_heap.rs` implementing a `#[global_allocator]` backed by a dedicated Win32 `HeapCreate` heap so runtime allocations never contend with `GetProcessHeap()`. - Wire it in `apps/victory/src/main.rs` and `apps/victory/Cargo.toml`. - Add the `VICTORY_NO_WATCH_GUARDS` toggle in `crates/victory-gpu/src/watch.rs`. ## Verification - `git apply --check` passes cleanly on `Marvisak/VIctory` `main` (direct zero-conflict apply). --- **About our fork & censorship-resistant preservation effort:** This fix comes from **[gta6-vi-port](https://github.com/go2afri/gta6-vi-port)**, our open-source Linux (GE-Proton) + NVIDIA RTX 4090 fork of VIctory and peer-to-peer Radicle archival effort (mirroring 92+ community porting repositories across public Radicle seeds so open-source porting research survives centralized takedowns; open-source code only, no game files/keys/binaries). - **Canonical Radicle repo:** https://radicle.network/nodes/rosa.radicle.network/rad:z39ofPhQC1siudH9BF3xsmAMmUqxc (`rad:z39ofPhQC1siudH9BF3xsmAMmUqxc`) - **Live 1080p development stream:** https://vdo.ninja/?view=gta6rtx4090live1080p60 (Tor v3 `.onion` VP9+Opus viewer: `http://kwnoaeecpmxd6eetqfa7fxlymvxnh5du2i6wxr44t4mc7cgch5pw23id.onion/`)
DenRakEiw commented 2026-11-25 13:18:36 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-25T13:18:36Z.

Review: APPROVED


Verified against origin/main (940d32f) on Windows 11:

  • Dedicated Win32 HeapCreate global allocator (private_heap.rs) and VICTORY_NO_WATCH_GUARDS toggle compile cleanly and pass all allocator, alignment, and watch tests.
  • cargo test -p victory: 16/16 passed (14 unit including all 4 private_heap::tests + 2 census).
  • cargo test -p victory-gpu watch::tests: 6/6 passed.
  • cargo clippy -p victory -p victory-gpu --all-targets -- -D warnings: 0 warnings.
  • cargo xtask policy: 184 files ok.

AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6058333509 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2424#pullrequestreview-6058333509). Originally posted by [DenRakEiw](https://github.com/DenRakEiw) on 2026-11-25T13:18:36Z. **Review:** APPROVED --- Verified against `origin/main` (`940d32f`) on Windows 11: - Dedicated Win32 `HeapCreate` global allocator (`private_heap.rs`) and `VICTORY_NO_WATCH_GUARDS` toggle compile cleanly and pass all allocator, alignment, and watch tests. - `cargo test -p victory`: 16/16 passed (14 unit including all 4 `private_heap::tests` + 2 census). - `cargo test -p victory-gpu watch::tests`: 6/6 passed. - `cargo clippy -p victory -p victory-gpu --all-targets -- -D warnings`: 0 warnings. - `cargo xtask policy`: 184 files ok. AI-assisted (Gemini 4 Neon).
catminou4 commented 2026-11-25 13:19:33 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T13:19:33Z.

Review: COMMENTED


apps/victory: private HeapCreate global allocator to avoid AB-BA deadlock between the process heap lock and GUARDS VEH (+317). Static review only: victory-gpu/victory-hle are Windows-only (D3D12/windows-sys); not compiled or tested on this macOS arm64 host. rustc 1.98.1. Sound motivation; the deadlock scenario is plausible with a vectored exception handler touching Rust collections. Windows-only, needs validation.

<!-- greyfinch-sync:Marvisak/VIctory:review:6058347067 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2424#pullrequestreview-6058347067). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T13:19:33Z. **Review:** COMMENTED --- apps/victory: private HeapCreate global allocator to avoid AB-BA deadlock between the process heap lock and GUARDS VEH (+317). Static review only: victory-gpu/victory-hle are Windows-only (D3D12/windows-sys); not compiled or tested on this macOS arm64 host. rustc 1.98.1. Sound motivation; the deadlock scenario is plausible with a vectored exception handler touching Rust collections. Windows-only, needs validation.
Marvisak commented 2026-11-25 16:09:46 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T15:32:27Z.


Automated triage for the maintainers.

This pull request no longer merges cleanly into main (conflicts in crates/victory-gpu/src/watch.rs). It will be reviewed once it is rebased onto the current main. The earlier verdict (needs-work) was for an older state of main.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7167001443 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2424#issuecomment-7167001443). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T15:32:27Z. --- <!-- victory-triage v1 head=1954093b9effe0569973ef644bab9deae4276035 verdict=needs-rebase at=2026-11-25T16:04:40Z --> Automated triage for the maintainers. This pull request no longer merges cleanly into `main` (conflicts in `crates/victory-gpu/src/watch.rs`). It will be reviewed once it is rebased onto the current `main`. The earlier verdict (needs-work) was for an older state of `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
kotekompotek commented 2026-11-25 17:05:19 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T16:54:32Z.


Both halves check out:

Private heap — the over-alignment math is subtly right but worth the comment being explicit: size + align is only sufficient because HeapAlloc already returns 16-aligned blocks and HEADER_SIZE = 8, which bounds offset ≤ align (an unaligned base would need size + align + HEADER - 1). Lazy CAS init and the back-pointer scheme are sound; realloc correctly avoids HeapReAlloc for over-aligned blocks where the header would move.

VICTORY_NO_WATCH_GUARDS — early None from track matches the existing "untracked" path, so callers degrade the same way as runtime_memory misses. The trade-off is correctly scoped as an env toggle: writes stop being observed, so stale textures are the expected symptom while it sidesteps the AB-BA deadlock with GUARDS.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7168712984 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2424#issuecomment-7168712984). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-25T16:54:32Z. --- Both halves check out: **Private heap** — the over-alignment math is subtly right but worth the comment being explicit: `size + align` is only sufficient because `HeapAlloc` already returns 16-aligned blocks and `HEADER_SIZE = 8`, which bounds `offset ≤ align` (an unaligned base would need `size + align + HEADER - 1`). Lazy CAS init and the back-pointer scheme are sound; realloc correctly avoids `HeapReAlloc` for over-aligned blocks where the header would move. **`VICTORY_NO_WATCH_GUARDS`** — early `None` from `track` matches the existing "untracked" path, so callers degrade the same way as `runtime_memory` misses. The trade-off is correctly scoped as an env toggle: writes stop being observed, so stale textures are the expected symptom while it sidesteps the AB-BA deadlock with `GUARDS`.
faycalbaklouti commented 2026-11-30 19:17:44 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by faycalbaklouti on 2026-11-30T19:17:44Z.


The prepared head ae18536c1a6e is directly based on mirror main 63bcca43. Both registration paths now call track_as, and the diagnostic opt-out is checked there (watch.rs:322,328,332). It is off by default. When enabled it disables this write observation, so it is a diagnostic choice rather than a rendering fix.

The allocator documents the back-pointer alignment bound in private_heap.rs:93–97. The earlier Windows review applied to the prior patch; no suite has been run on this rebased head while the benchmark holds the compute lock.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7289158138 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2424#issuecomment-7289158138). Originally posted by [faycalbaklouti](https://github.com/faycalbaklouti) on 2026-11-30T19:17:44Z. --- The prepared head `ae18536c1a6e` is directly based on mirror main `63bcca43`. Both registration paths now call `track_as`, and the diagnostic opt-out is checked there (`watch.rs:322,328,332`). It is off by default. When enabled it disables this write observation, so it is a diagnostic choice rather than a rendering fix. The allocator documents the back-pointer alignment bound in `private_heap.rs:93–97`. The earlier Windows review applied to the prior patch; no suite has been run on this rebased head while the benchmark holds the compute lock.
faycalbaklouti commented 2026-11-30 20:34:31 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by faycalbaklouti on 2026-11-30T20:34:31Z.


At e36072c02f85: Default Clippy passed on the old head, but --all-features enabled diagnostics and registered PrivateHeap and CountingAlloc simultaneously. There is now one registration. All four allocator operations use the private Win32 heap; diagnostics keeps the original successful-allocation, resize, free and large-allocation reporting. The new GPU library test checks private-heap ownership and exact live-byte deltas.

With Rust 1.98.1, targeting x86_64-pc-windows-msvc with cargo-xwin and running the Windows tests under Wine:

  • cargo clippy --workspace --all-targets --locked -- -D warnings: exit 0
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: exit 0
  • cargo test --workspace --locked: exit 101

Regression test: test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 251 filtered out; finished in 0.00s.

The full workspace test did not pass under Wine. Unchanged main reproduced all five reported failures: DLL thread attach, two stand-in window tests, loopback, and an NTFS hard-link expectation. The workspace run then stalled in a nested game-save child and was stopped; later tests remain unverified. This is not a claim that Windows CI is green.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7291140001 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2424#issuecomment-7291140001). Originally posted by [faycalbaklouti](https://github.com/faycalbaklouti) on 2026-11-30T20:34:31Z. --- At `e36072c02f85`: Default Clippy passed on the old head, but `--all-features` enabled diagnostics and registered `PrivateHeap` and `CountingAlloc` simultaneously. There is now one registration. All four allocator operations use the private Win32 heap; diagnostics keeps the original successful-allocation, resize, free and large-allocation reporting. The new GPU library test checks private-heap ownership and exact live-byte deltas. With Rust 1.98.1, targeting `x86_64-pc-windows-msvc` with cargo-xwin and running the Windows tests under Wine: - `cargo clippy --workspace --all-targets --locked -- -D warnings`: exit 0 - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`: exit 0 - `cargo test --workspace --locked`: exit 101 Regression test: `test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 251 filtered out; finished in 0.00s`. The full workspace test did **not** pass under Wine. Unchanged main reproduced all five reported failures: DLL thread attach, two stand-in window tests, loopback, and an NTFS hard-link expectation. The workspace run then stalled in a nested game-save child and was stopped; later tests remain unverified. This is not a claim that Windows CI is green.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/2424:upstream-pr/2424'
git switch 'upstream-pr/2424'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/2424'
git switch 'upstream-pr/2424'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2424'
git switch 'upstream-pr/2424'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2424'
git switch 'main'
git merge --squash 'upstream-pr/2424'
git switch 'main'
git merge --ff-only 'upstream-pr/2424'
git switch 'main'
git merge 'upstream-pr/2424'
git push origin 'main'
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
Marvisak/VIctory!2422
No description provided.