vicrec: one seam for the address-space calls, so the restore builds on Windows #2

Closed
github-bot wants to merge 1 commit from github-bot/gh-2 into main AGit
Owner

@⁠borosf on GitHub · 2026-11-30 12:01 UTC · original
borosf:platform-windows-vicrec → main · +339 −61 · 5 files · 1 commits · closed without merging

The restore maps title memory at the title's own addresses, and until now reached the system calls directly: mmap PROT_NONE|MAP_NORESERVE to reserve, mmap PROT_RW for memory the recorder held outside the listed regions, mprotect to commit a granule, /proc/self/maps for the mapping list, and std::os::unix::fs::FileExt for the capture reads. That is why vicrec was the first crate to stop a Windows build, with twenty errors, before umem or vkback were even reached.

Windows has the same powers with different calls, and two steps where Linux has one.

Linux Windows
mmap(PROT_NONE, MAP_NORESERVE, MAP_FIXED_NOREPLACE) VirtualAlloc(MEM_RESERVE, PAGE_NOACCESS)
mmap(PROT_READ|PROT_WRITE, MAP_FIXED_NOREPLACE) VirtualAlloc(MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE)
mprotect(PROT_READ|PROT_WRITE) VirtualAlloc(MEM_COMMIT, PAGE_READWRITE)
/proc/self/maps VirtualQuery walk, names from GetMappedFileNameW
read_exact_at seek_read, looped (it returns short reads)

src/platform.rs is that seam, one imp per system. The granule is 64 KiB (restore.rs GRANULE), which is exactly Windows' allocation granularity, so one granule of the restore is one Windows allocation and a commit can never straddle two — the two systems' granularities agree here by luck, not by design, and the file says so.

Neither side may move: every caller writes at the title's address, so a call that cannot get that address fails instead of landing elsewhere — MAP_FIXED_NOREPLACE on Linux, a non-null base on Windows, which fails when the range is in use (ERROR_INVALID_ADDRESS is reported as "in use").

No behaviour change on Linux: the same flags, the same error text, the same order of bookkeeping and call.

Verified

Windows 11, rustc 1.100.0, x86_64-pc-windows-msvc:

cargo check                                    ok
cargo check --target x86_64-unknown-linux-gnu  ok
cargo clippy --all-targets                     no warnings
cargo test                                     2 passed, 0 failed
rustfmt --check src/platform.rs src/restore.rs clean

restore_small_pieces is the one that matters: it maps real granules through this seam, so the Windows path is exercised by a test, not only compiled.

What this is not

It is not the Windows port; it is step 0 of it — one crate's worth of seam, in the shape the rest can follow (umem next, 36 platform lines; vkback 63). I opened #1 with the seam inventory and the two decisions I think are the maintainer's rather than mine (the 64-lane mesh requirement in pipejob, and whether umem's dma-buf chunk model should be inverted on Windows so the section is the allocator). This PR does not prejudge either.

AI-assisted: yes.

**@⁠borosf** on GitHub · 2026-11-30 12:01 UTC · [original](https://github.com/vktory6/VKtory/pull/2) `borosf:platform-windows-vicrec` → `main` · +339 −61 · 5 files · 1 commits · closed without merging The restore maps title memory at the title's own addresses, and until now reached the system calls directly: `mmap` `PROT_NONE|MAP_NORESERVE` to reserve, `mmap` `PROT_RW` for memory the recorder held outside the listed regions, `mprotect` to commit a granule, `/proc/self/maps` for the mapping list, and `std::os::unix::fs::FileExt` for the capture reads. That is why `vicrec` was the first crate to stop a Windows build, with twenty errors, before `umem` or `vkback` were even reached. Windows has the same powers with different calls, and two steps where Linux has one. | Linux | Windows | |---|---| | `mmap(PROT_NONE, MAP_NORESERVE, MAP_FIXED_NOREPLACE)` | `VirtualAlloc(MEM_RESERVE, PAGE_NOACCESS)` | | `mmap(PROT_READ\|PROT_WRITE, MAP_FIXED_NOREPLACE)` | `VirtualAlloc(MEM_RESERVE\|MEM_COMMIT, PAGE_READWRITE)` | | `mprotect(PROT_READ\|PROT_WRITE)` | `VirtualAlloc(MEM_COMMIT, PAGE_READWRITE)` | | `/proc/self/maps` | `VirtualQuery` walk, names from `GetMappedFileNameW` | | `read_exact_at` | `seek_read`, looped (it returns short reads) | `src/platform.rs` is that seam, one `imp` per system. The granule is 64 KiB (`restore.rs` `GRANULE`), which is exactly Windows' allocation granularity, so one granule of the restore is one Windows allocation and a commit can never straddle two — the two systems' granularities agree here by luck, not by design, and the file says so. Neither side may move: every caller writes at the title's address, so a call that cannot get that address fails instead of landing elsewhere — `MAP_FIXED_NOREPLACE` on Linux, a non-null base on Windows, which fails when the range is in use (`ERROR_INVALID_ADDRESS` is reported as "in use"). **No behaviour change on Linux:** the same flags, the same error text, the same order of bookkeeping and call. ### Verified Windows 11, rustc 1.100.0, `x86_64-pc-windows-msvc`: ``` cargo check ok cargo check --target x86_64-unknown-linux-gnu ok cargo clippy --all-targets no warnings cargo test 2 passed, 0 failed rustfmt --check src/platform.rs src/restore.rs clean ``` `restore_small_pieces` is the one that matters: it maps real granules through this seam, so the Windows path is exercised by a test, not only compiled. ### What this is not It is not the Windows port; it is step 0 of it — one crate's worth of seam, in the shape the rest can follow (`umem` next, 36 platform lines; `vkback` 63). I opened #1 with the seam inventory and the two decisions I think are the maintainer's rather than mine (the 64-lane mesh requirement in `pipejob`, and whether `umem`'s dma-buf chunk model should be inverted on Windows so the section is the allocator). This PR does not prejudge either. AI-assisted: yes.
The restore maps title memory at the title's own addresses, which reached
libc directly: mmap PROT_NONE + MAP_NORESERVE to reserve, mmap PROT_RW for
the upload arena, mprotect to commit a granule, /proc/self/maps for the
mapping list, and std::os::unix FileExt for the capture reads. Windows has
the same powers with different calls, in two steps rather than one.

src/platform.rs holds the seam, one implementation per system:

  Linux                          Windows
  mmap(PROT_NONE, NORESERVE)     VirtualAlloc(MEM_RESERVE, PAGE_NOACCESS)
  mmap(PROT_RW)                  VirtualAlloc(MEM_RESERVE|MEM_COMMIT, PAGE_RW)
  mprotect(PROT_RW)              VirtualAlloc(MEM_COMMIT, PAGE_RW)
  /proc/self/maps                VirtualQuery walk + GetMappedFileNameW
  read_exact_at                  seek_read, looped (it fills what it can)

The granule is 64 KiB (restore.rs GRANULE), exactly Windows' allocation
granularity, so one granule of the restore is one Windows allocation and a
commit can never straddle two. Neither side may move: every caller writes at
the title's address, and a call that cannot get that address fails instead of
landing elsewhere - MAP_FIXED_NOREPLACE on Linux, a non-null base on Windows,
which fails when the range is in use.

No behaviour change on Linux: the same flags, the same errors, the same order.

Verified on a Windows 11 host (rustc 1.100.0, msvc target):
  cargo check                                    ok
  cargo check --target x86_64-unknown-linux-gnu  ok
  cargo clippy --all-targets                     no warnings
  cargo test                                     2 passed (restore_small_pieces maps real granules)
  rustfmt --check                                clean

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-30 12:05:04 +00:00
Author
Owner

@⁠vktory6 on GitHub · 2026-11-30 18:59 UTC · original

Thanks. Though, I'm thinking about getting rid of the entire file-capture toolchain so I'll have to leave you hanging until I've decided 100% for or against it.

**@⁠vktory6** on GitHub · 2026-11-30 18:59 UTC · [original](https://github.com/vktory6/VKtory/pull/2#issuecomment-7288677839) Thanks. Though, I'm thinking about getting rid of the entire [file-capture toolchain](https://github.com/vktory6/VKtory/blob/main/docs/ROADMAP.md#retire-the-file-capture-toolchain) so I'll have to leave you hanging until I've decided 100% for or against it.
Author
Owner

@⁠borosf on GitHub · 2026-11-30 19:03 UTC · original

Nah, that's totally fine. Ping me when you've decided. A W11 port will broaden the horizon and number of contributors.

**@⁠borosf** on GitHub · 2026-11-30 19:03 UTC · [original](https://github.com/vktory6/VKtory/pull/2#issuecomment-7288775055) Nah, that's totally fine. Ping me when you've decided. A W11 port will broaden the horizon and number of contributors.
Author
Owner

@⁠vktory6 on GitHub · 2026-11-30 19:04 UTC · original

I agree, I'd love to have a W11 port, but I think the most realistic way there is to have someone fork the whole repo, spend a few days getting it to feature parity on W11 and then I'll see how to reintegrate the two repos properly.

**@⁠vktory6** on GitHub · 2026-11-30 19:04 UTC · [original](https://github.com/vktory6/VKtory/pull/2#issuecomment-7288806628) I agree, I'd love to have a W11 port, but I think the most realistic way there is to have someone fork the whole repo, spend a few days getting it to feature parity on W11 and then I'll see how to reintegrate the two repos properly.
Author
Owner

@⁠borosf on GitHub · 2026-11-30 19:06 UTC · original

I agree, I'd love to have a W11 port, but I think the most realistic way there is to have someone fork the whole repo, spend a few days getting it to feature parity on W11 and then I'll see how to reintegrate the two repos properly.

That seems like a great idea. Will work on it if I have the time 😄

**@⁠borosf** on GitHub · 2026-11-30 19:06 UTC · [original](https://github.com/vktory6/VKtory/pull/2#issuecomment-7288857577) > I agree, I'd love to have a W11 port, but I think the most realistic way there is to have someone fork the whole repo, spend a few days getting it to feature parity on W11 and then I'll see how to reintegrate the two repos properly. That seems like a great idea. Will work on it if I have the time 😄
github-bot closed this pull request 2026-11-30 19:27:33 +00:00
Author
Owner

@⁠borosf on GitHub · 2026-11-30 19:24 UTC · original

Withdrawing this one - no upstream PRs from our side. Your fork-the-whole-repo route is the one we are taking: full fork, private, feature parity on Windows first, reintegration talk later. Thanks for the quick reply.

**@⁠borosf** on GitHub · 2026-11-30 19:24 UTC · [original](https://github.com/vktory6/VKtory/pull/2#issuecomment-7289347759) Withdrawing this one - no upstream PRs from our side. Your fork-the-whole-repo route is the one we are taking: full fork, private, feature parity on Windows first, reintegration talk later. Thanks for the quick reply.

Pull request closed

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