fix(libc): reserve the guest arena at its fixed range around what Windows already placed in it #231

Merged
MichonGoddijn231849 merged 1 commit from upstream-pr/231 into main 2026-10-02 19:15:26 +00:00
MichonGoddijn231849 commented 2026-10-01 17:25:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-01T17:25:58Z.


What

Replaces #196, following the review there: one arena reservation path that keeps the required range, without relocating or shrinking.

On Windows the arena used to search for a free base and size, starting at 0x200000000. Windows places thread stacks and other reservations at random low addresses before libc starts, so the search often moved the arena up (to 0x2200000000) or shrank it. Guest mappings at the fixed low addresses titles use then fell outside it, and the process aborted with shared mapping outside the guest arena.

The arena is now always [0x200000000, 0x7200000000):

  • The range is walked once with VirtualQuery. Every free, allocation-granularity-aligned piece is reserved as a placeholder.
  • What Windows already placed in the range, and the unaligned slivers next to it, become holes: used ranges that Allocate skips, MarkUsed refuses to overlap, and Release never frees. The system-reserved range is one of them, as before.
  • A failed VirtualQuery or a failed reservation throws a std::system_error. There is no other layout to fall back to.

Tested

Windows 11 Pro, AMD Ryzen 5 7600, NVIDIA GeForce RTX 5080 (driver 32.0.16.1074), 32 GB DDR5-5600, MinGW-w64 GCC 15.2.0.

  • GTA V (PPSA04264), with #167 and the read fix:
    • Without this change, the first of four launches aborted at start with shared mapping outside the guest arena; the earlier #196 runs had 3 of 4.
    • With it, 8 of 8 launches start and reach the world.
  • ctest: all tests pass.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes. Written with Claude (Anthropic) under my direction; I reviewed and tested it.

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4707183770 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/231). Originally posted by [MichonGoddijn231849](https://github.com/MichonGoddijn231849) on 2026-10-01T17:25:58Z. --- ### What Replaces #196, following the review there: one arena reservation path that keeps the required range, without relocating or shrinking. On Windows the arena used to search for a free base and size, starting at 0x200000000. Windows places thread stacks and other reservations at random low addresses before libc starts, so the search often moved the arena up (to 0x2200000000) or shrank it. Guest mappings at the fixed low addresses titles use then fell outside it, and the process aborted with `shared mapping outside the guest arena`. The arena is now always [0x200000000, 0x7200000000): - The range is walked once with `VirtualQuery`. Every free, allocation-granularity-aligned piece is reserved as a placeholder. - What Windows already placed in the range, and the unaligned slivers next to it, become holes: used ranges that `Allocate` skips, `MarkUsed` refuses to overlap, and `Release` never frees. The system-reserved range is one of them, as before. - A failed `VirtualQuery` or a failed reservation throws a `std::system_error`. There is no other layout to fall back to. ### Tested Windows 11 Pro, AMD Ryzen 5 7600, NVIDIA GeForce RTX 5080 (driver 32.0.16.1074), 32 GB DDR5-5600, MinGW-w64 GCC 15.2.0. - GTA V (PPSA04264), with #167 and the read fix: - Without this change, the first of four launches aborted at start with `shared mapping outside the guest arena`; the earlier #196 runs had 3 of 4. - With it, 8 of 8 launches start and reach the world. - `ctest`: all tests pass. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in TechnicalDebt - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes. Written with Claude (Anthropic) under my direction; I reviewed and tested it. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
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
boykopovar/AnyPS5!231
No description provided.