runtime: reserve startup address space through XMemVirtualAlloc #881

Open
descent81 wants to merge 1 commit from upstream-pr/888 into main
descent81 commented 2026-11-23 16:07:25 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by descent81 on 2026-11-23T16:07:25Z.


Refs #870 and #874. The export table is shared with #880. This is a draft for comparison while that work and the current startup integration settle.

The startup investigation in #874 identified two reserve-only call shapes immediately after graphics virtual-memory configuration. This adds a named XMemVirtualAlloc export for those shapes. The desktop implementation accepts a null base, a 16 or 24 GiB size, and the two reported attribute/protection pairs. It reserves uncommitted address space with Win32 and rejects other input combinations with ERROR_INVALID_PARAMETER. This is a proposed desktop policy for those calls. The existing six export ordinals are preserved.

Verification

Windows x64, MSVC 19.50, base 7198727, tested at b29089c. The source-built EXE imports the new function by name and runs under both the Windows loader and pe_map. It checks the exact size, alignment and state of both live reservations at each size. Unsupported requests must leave both regions intact. The test releases both ranges and confirms it can reserve a released address again. The missing-provider control stops at IAT binding before entry.

Run for both dev and release (replace the preset in both commands):

cmake --build --preset dev --target cpu_xmem_reservation xmem_shim_check pe_map cpu_shim_startup_lifted
ctest --preset dev --no-tests=error -R '^(cpu_native_xmem_reservation|xmem_shim_(exports|allocation|default_allocation|query)|cpu_native_shim_startup|docs_links)$' --output-on-failure

7 passed in Debug and 7 passed in Release, zero skips. The fixture uses only source-built inputs. Later commit and physical-page mapping are outside this reserve-only profile. No title entry was exercised.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5456630893 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/888). Originally posted by [descent81](https://github.com/descent81) on 2026-11-23T16:07:25Z. --- Refs #870 and #874. The export table is shared with #880. This is a draft for comparison while that work and the current startup integration settle. The startup investigation in #874 identified two reserve-only call shapes immediately after graphics virtual-memory configuration. This adds a named `XMemVirtualAlloc` export for those shapes. The desktop implementation accepts a null base, a 16 or 24 GiB size, and the two reported attribute/protection pairs. It reserves uncommitted address space with Win32 and rejects other input combinations with `ERROR_INVALID_PARAMETER`. This is a proposed desktop policy for those calls. The existing six export ordinals are preserved. ### Verification Windows x64, MSVC 19.50, base `7198727`, tested at `b29089c`. The source-built EXE imports the new function by name and runs under both the Windows loader and `pe_map`. It checks the exact size, alignment and state of both live reservations at each size. Unsupported requests must leave both regions intact. The test releases both ranges and confirms it can reserve a released address again. The missing-provider control stops at IAT binding before entry. Run for both `dev` and `release` (replace the preset in both commands): ```powershell cmake --build --preset dev --target cpu_xmem_reservation xmem_shim_check pe_map cpu_shim_startup_lifted ctest --preset dev --no-tests=error -R '^(cpu_native_xmem_reservation|xmem_shim_(exports|allocation|default_allocation|query)|cpu_native_shim_startup|docs_links)$' --output-on-failure ``` 7 passed in Debug and 7 passed in Release, zero skips. The fixture uses only source-built inputs. Later commit and physical-page mapping are outside this reserve-only profile. No title entry was exercised. AI-assisted.
R0Y00 commented 2026-11-24 06:49:25 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T17:50:13Z.


I resolved the conflicts with the current grant and Tools Memory work locally. The reservation now uses an uncommitted PAGE_NOACCESS placeholder. On Windows x64 Release both loaders passed splitting a 64 KiB prefix from each reservation size, replacing it with a section view, writing and reading a word, restoring and coalescing the placeholder, and releasing it. The existing ordinals remain 1–9.

#934 adds the shared backing implementation. I will keep this draft separate and verify the two branches together using the real XMem map/unmap path, including remapping a live page and then releasing the grant. Please share any overlapping change here so we can keep a single reservation patch.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7109252587 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/888#issuecomment-7109252587). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-23T17:50:13Z. --- I resolved the conflicts with the current grant and Tools Memory work locally. The reservation now uses an uncommitted PAGE_NOACCESS placeholder. On Windows x64 Release both loaders passed splitting a 64 KiB prefix from each reservation size, replacing it with a section view, writing and reading a word, restoring and coalescing the placeholder, and releasing it. The existing ordinals remain 1–9. #934 adds the shared backing implementation. I will keep this draft separate and verify the two branches together using the real XMem map/unmap path, including remapping a live page and then releasing the grant. Please share any overlapping change here so we can keep a single reservation patch.
R0Y00 commented 2026-11-24 06:49:26 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T18:05:39Z.


The source-built integration can now map a 64 KiB page directly inside each untouched 16/24 GiB reservation. The shared backend splits the target page, preserves the written word through remapping, and coalesces the range before Win32 release. Keep the compatibility test in this PR, using the actual XMem map/unmap exports from #934. Keep a control for an ordinary reserved range and verify the whole range is reusable at the same address after release.

The prototype records reservation intervals for automatic splitting. Please define how a record stops authorizing splitting after the caller releases the range through Win32. Add a control that releases an XMem reservation, creates an unrelated range over the same address, and verifies that the old record cannot change the new range. If the shim cannot establish ownership after external release, document and scope the supported split or release path before merging. The two currently tested reserve configurations stay the scope of this PR.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7109641610 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/888#issuecomment-7109641610). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-23T18:05:39Z. --- The source-built integration can now map a 64 KiB page directly inside each untouched 16/24 GiB reservation. The shared backend splits the target page, preserves the written word through remapping, and coalesces the range before Win32 release. Keep the compatibility test in this PR, using the actual XMem map/unmap exports from #934. Keep a control for an ordinary reserved range and verify the whole range is reusable at the same address after release. The prototype records reservation intervals for automatic splitting. Please define how a record stops authorizing splitting after the caller releases the range through Win32. Add a control that releases an XMem reservation, creates an unrelated range over the same address, and verifies that the old record cannot change the new range. If the shim cannot establish ownership after external release, document and scope the supported split or release path before merging. The two currently tested reserve configurations stay the scope of this PR.
tedin7 commented 2026-11-27 09:37:20 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-27T09:37:20Z.


This PR now conflicts with main. Conflicting files:

  • docs/experiments.md
  • src/xmem_shim.def
  • tests/xmem_shim_check.cpp

Could you merge main into your branch (a merge commit, no force push needed) and resolve these? Thank you.

AI-assisted; commands listed were executed locally. (git merge-tree origin/main <head>)

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7214897451 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/888#issuecomment-7214897451). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-27T09:37:20Z. --- This PR now conflicts with `main`. Conflicting files: - `docs/experiments.md` - `src/xmem_shim.def` - `tests/xmem_shim_check.cpp` Could you merge `main` into your branch (a merge commit, no force push needed) and resolve these? Thank you. AI-assisted; commands listed were executed locally. (`git merge-tree origin/main <head>`)
Leyukaka commented 2026-12-01 16:20:46 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-12-01T16:20:46Z.


This looks superseded by main: #945 (merged as b3de0f4a0) reserves the XMem address space as mappable placeholders, #934 shares physical page backing across views, and #1098 commits startup blocks through XMemVirtualAlloc. The maintainer's comments here asked for split, remap, coalescing and reuse after a Win32 release; if one of those is still missing on current main, it would fit a focused PR. Otherwise this one can probably be closed. Happy to be corrected if I missed something.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7317449142 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/888#issuecomment-7317449142). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-12-01T16:20:46Z. --- This looks superseded by `main`: #945 (merged as b3de0f4a0) reserves the XMem address space as mappable placeholders, #934 shares physical page backing across views, and #1098 commits startup blocks through `XMemVirtualAlloc`. The maintainer's comments here asked for split, remap, coalescing and reuse after a Win32 release; if one of those is still missing on current `main`, it would fit a focused PR. Otherwise this one can probably be closed. Happy to be corrected if I missed something.
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/888:upstream-pr/888'
git switch 'upstream-pr/888'

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/888'
git switch 'upstream-pr/888'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/888'
git switch 'upstream-pr/888'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/888'
git switch 'main'
git merge --squash 'upstream-pr/888'
git switch 'main'
git merge --ff-only 'upstream-pr/888'
git switch 'main'
git merge 'upstream-pr/888'
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
R0Y00/Xbox2Windows!881
No description provided.