fix(libc): place Windows hints inside the system reserved range at the hint #27330
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/27330"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by Jazeupoi on 2026-11-25T21:08:06Z.
What
On Windows, a private anonymous mapping whose address hint lies in 0x7_FFFF_C000–0x10_0000_0000 always got 0x10_0000_0000. The arena marked that whole range as used (
GuestArena.cpp, the system reserved hole), soFindAtOrAboveskipped past it whatever the hint was.ProsperoCraft (PPSA99874 01.000.288) stops there. Its Java 25 runtime uses ZGC, which reserves its heap with hints from 0x8_0000_0000 upward and drops any reservation that does not land at the hint. In its VM trace every attempt gets 0x10_0000_0000: 4287 attempts from
ZGC: reserve requested=0x0000000800000000 bytes=0x0000000600000000to 0xff0000000, thenFailed to reserve 1536M address space for Java heapandJNI_CreateJavaVM returned -4.On Windows the range is no longer a used hole.
FindAtOrAbovesteps over it unless the hint lies inside it, so:MarkUsedthrows, andsceKernelReserveVirtualRangewith a fixed address still returnsSCE_KERNEL_ERROR_ENOMEMthrough the newGuestArenaOverlapsSystemReserved_nid_no_patch), soguest_memory's check at 0x7ffffc000 is unchanged;HighestFreedoes not return a window in the range.The AGC driver memory at 0xfe0000000 lies in that range. On Windows it was committed without being recorded in the arena, which the hole made safe. It is now claimed with
GuestArenaAllocateFromHint_nid_postfixat its address before the commit, and start-up throws if anything already holds it.Linux and macOS keep the range in their used set (and as a host region), so nothing changes there. How the console uses the range is not measured; the debt entry says so.
Tested
Windows 11 (10.0.26300), AMD Ryzen 5 3400G, NVIDIA GeForce RTX 2060 (driver 621.40), WinLibs GCC 15.2, Release,
BUILD_TESTING=ON, onmaine8daa4b6c6. The control runs usemain'sGuestArena.cpp,GuestArena.hpp,DirectMemory.cppandLifecycle.cppwith the new test kept.guest_system_reserved_hint(hints at 0x8_0000_0000 for 24 GiB and 0x9_0000_0000, no hint, a hint below the range, unmap and reuse)ctest -R 'memory|mmap|arena|alloc|mprotect|munmap|madvise|msync|mincore|flexible|heap|stack|ampr|jit|write_watch|system_reserved' -E '^agc_' -j1agc_driver_compute_fs_table_callsandagc_driver_draw_cache_reuse(12 tests;ANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1,VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,VK_LOADER_DEBUG=layer)VUID-VUID-guest_jit_shared_memoryandguest_mmap_executablefail in both columns.ProsperoCraft (PPSA99874 01.000.288), relinked with
--windows --trap-sdk-syscall-stubs --registry, 4 runs of 60 s each:JNI_CreateJavaVMFailed to reserve 1536M address space for Java heap; the launcher showsAccount services could not startA separate stop,
Client083 native launcher display could not startbefore the JVM is created, did not happen in these 8 runs. It happened in 2 earlier runs, one with this change and one without, and is not addressed here.The branch also merges cleanly onto the current
main63b2e14408, which changes none of these files.python3 tools/check_conventions.py --base upstream/main: all checks pass.tools/pr_overlap.py --branch: no confirmed overlap.At
e879b467fb(keeps the AGC driver block out of hinted mappings, after fromthemoonx's review), onmain6b74d9d67bplus #27801:guest_system_reserved_hint, which now also asks for the driver block and for 4 GiB at 0xF_0000_0000, passes 200 of 200; without theGuestArena.cppchange it fails (the driver-block hint returns 0xFE0000000).guest_memory,guest_mmap_executable,guest_jit_shared_memory,guest_mprotect_unmappedandguest_owned_memorypass 20 of 20 each. fceuxs5 (PPSA51855) starts the driver and presents at 60 FPS. The branch merges cleanly ontomaina2d8d409db.At
7e8ab19087(overlapping holes merged before they enter_used, after CodeRabbit's finding), onmain483b81fb5a: on Windowsguest_system_reserved_hint,guest_memory,guest_mmap_executable,guest_jit_shared_memory,guest_mprotect_unmappedandguest_owned_memorypass 50 of 50, and the probes still printdriver=0000000fe0200000andwide=0000001004000000; on Linux (Ubuntu 24.04 under WSL2) the five shared tests pass 50 of 50 (guest_system_reserved_hintis Windows only).At
4b335e6746(fixed reservations are checked against the system reserved range before the remap into a registered range, after MarcZX10's review), onmain483b81fb5a:guest_system_reserved_hintnow also reserves at the hint 0xA_0000_0000 and checks that a fixed reservation over it returnsSCE_KERNEL_ERROR_ENOMEM; the six arena tests pass 20 of 20, and with only theDirectMemory.cppchange reverted the new check fails. ProsperoCraft, 6 runs of 60 s:JNI_CreateJavaVMreturns 0 in 5 with the first ZGC reservation at 0x800000000; the first run stopped before the JVM, cause not known.Not tested: macOS (the shared
FindAtOrAbove,HighestFreeandMarkUsedchecks only change anything when the range is not already used, which is Windows).Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Summary by CodeRabbit
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T21:42:47Z.
Review: APPROVED
Reviewed — looks good
The reviewed change at head
74f91e84b68611da500c38efa010fd7a5390e759addresses Windows hint placement; no blocking defect was verified in the inspected code. Nothing blocks this; the points below are optional.What I ran
repo_read.py; no build or test commands were run.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
core/libs/prx/libSceAgcDriver/Execution/src/Driver/Lifecycle.cpp,core/libs/prx/libc/include/GuestArena.hpp,core/libs/prx/libc/src/GuestArena.cpp,core/libs/prx/libkernel/CMakeLists.txt,core/libs/prx/libkernel/DirectMemory/DirectMemory.cpp,core/libs/tests/GuestSystemReservedHint.cpp, anddocs/dev/debt/changes/fix-windows-hint-in-system-reserved.md.files.jsonwas not present in the review folder, and the manifest lists all seven changed files as included.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by fromthemoonx on 2026-11-27T17:54:13Z.
Review: COMMENTED
Windows run on current
main, since the Tested section ran one8daa4b6c6. Setup: Windows 11 Pro 10.0.26300, WinLibs GCC 15.2.0 r7 UCRT, Release, full tree. Basemain1bc92752d2, head74f91e84b6.main(registration andGuestSystemReservedHint.cpponly):guest_system_reserved_hintfails at line 34 withheap=0000001000000000.main:guest_system_reserved_hint,guest_memory,guest_mmap_executable,guest_jit_shared_memory,guest_mprotect_unmappedandguest_owned_memorypass: 6/6, and 6/6 again on each of 3 repeats. On this machineguest_jit_shared_memoryandguest_mmap_executablepass, so their failures in your table look specific to that machine or to the older base.tools/check_conventions.pypasses on the head.One finding before this lands: the AGC driver memory at
0xfe0000000can now be taken by a guest mapping.MapDriverMemoryruns fromDriver::Driver(), whichDriver::Get()builds lazily, on the firstSubmit,RegisterShaderorRegisterVideoOutput(EntryPoints.cpp). That is after the guest has started. Before this PR, the reserved hole kept every guest mapping out of0xfe0000000. Now a hinted private mapping inside the range is placed at or above its hint. I added two probes to the end of the new test on the merged tree, before any driver exists:The first lands on the driver's 2 MiB block. The second lands right after it only because the first probe already holds it. Without the first probe, a 4 GiB hint at
0xf00000000would cover0xfe0000000as well. If a title or runtime makes such a mapping before its first GPU call,MapDriverMemorynow throwsthe AGC driver memory was not mapped at its fixed addressat the first submit. ZGC's hint walk in your trace reaches0xff0000000, so this is plausible for the ProsperoCraft case if an early reservation fails for another reason.Two ways to keep the old guarantee while still fixing ZGC:
[0xfe0000000, 0xfe0000000 + DriverMemorySpan)as a used hole on Windows, whichMapDriverMemorythen takes over; orEither way, a check in
guest_system_reserved_hintthat a hint at0xfe0000000does not return0xfe0000000would pin it down.AI-assisted: yes (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-27T23:40:15Z.
Review: COMMENTED
Actionable comments posted: 1
8d0db769-e2ce-41d8-bee7-9968bee9cd6dReviewing files that changed from the base of the PR and between
63b2e14408ande879b467fb.core/libs/prx/libSceAgcDriver/Execution/src/Driver/Lifecycle.cppcore/libs/prx/libc/include/GuestArena.hppcore/libs/prx/libc/include/GuestArenaDriverMemory.hppcore/libs/prx/libc/src/GuestArena.cppcore/libs/prx/libkernel/CMakeLists.txtcore/libs/prx/libkernel/DirectMemory/DirectMemory.cppcore/libs/tests/GuestSystemReservedHint.cppdocs/dev/debt/changes/fix-windows-hint-in-system-reserved.mdIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by fromthemoonx on 2026-11-28T00:50:12Z.
Review: APPROVED
Re-ran on Windows after the driver-block fix. Setup: Windows 11 Pro 10.0.26300, WinLibs GCC 15.2.0 r7 UCRT, Release, full tree. Base
main8c02bb89f4, headd34e66d93f.fb9ca51553only rewords the debt note, so these results carry over.main:guest_system_reserved_hint,guest_memory,guest_mmap_executable,guest_jit_shared_memory,guest_mprotect_unmappedandguest_owned_memorypass: 6/6, and 6/6 again on each of 3 repeats. The new probes printdriver=0000000fe0200000andwide=0000001004000000, so neither touches[0xfe0000000, +2 MiB)._holes.emplace_back(AgcDriverMemoryAddress, ...)line removed fromGuestArena.cppgetsdriver=0000000fe0000000and failscheck failed at line 65. The new checks catch the case I raised.tools/check_conventions.pypasses on the head.tools/debt_fold.py --checkexits 0 on the merge.The driver block lies inside the range the arena reserves at start-up, so
GuestArenaCommit_nid_postfixat the fixed address commits pages that are already reserved. A release that overlaps it puts the hole back into_used. Not run here: the AGC driver tests that exercise the newMapDriverMemorycommit path. This machine didn't have the memory for an AGC build this pass.AI-assisted: yes (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-28T12:20:12Z.
Review: APPROVED
Reviewed — looks good
The change implements the Windows hinted allocation path described in the PR; I found no verified blocking defect in the inspected code.
What I ran
Inspected head
fb9ca51553e75f0bfa8e7b938568bc05d359e831usingrepo_read.pyfor the prepared description, commit list, manifest, diff, changed source files, and targeted callers. No build or tests were run in this review.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The PR's reported test runs, merge checks, conventions check, overlap check, and title-specific runtime behavior were not independently verified. No excluded changed files were listed; all eight files marked included in
manifest.jsonwere read.files.jsonwas unavailable as a review-folder document.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-30T04:07:02Z.
Review: COMMENTED
Actionable comments posted: 1
Architecture findings (2)
Advisory architecture findings (2)
87c52ef2-9e32-447a-8923-b3a1e458a698Reviewing files that changed from the base of the PR and between
fb9ca51553and76e527d74f.core/libs/prx/libSceAgcDriver/Execution/src/Driver/Lifecycle.cppcore/libs/prx/libc/src/GuestArena.cppcore/libs/prx/libkernel/DirectMemory/DirectMemory.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-30T04:19:43Z.
Review: APPROVED
Reviewed — looks good
The reviewed changes at head
76e527d74f14cbcf4ae9a46af8a452a0041a8ebeimplement the described Windows hinted allocation behavior, and the inspected paths show no concrete blocking defect; runtime checks were not run in this review.What I ran
No commands were run. I read the prepared review bundle and changed source lines through the pinned-head reader.
Results
Findings
Blocking
None found in the inspected code.
Non-blocking
None.
Not verified
I read all eight changed files listed as
reviewedin the manifest, including every added line. I did not run builds or tests, validate author-reported test output, or verify Linux/macOS and console behavior.files.jsonwas not available as a review document; the review folder listing and manifest showed no excluded changed files.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-12-01T09:03:03Z.
Review: COMMENTED
🏛️ Architecture findings (2)
Advisory architecture findings (2)
💬 Code review
a5f057ab-c1eb-431e-8b50-0a8d98b276f2Reviewing files that changed from the base of the PR and between
76e527d74fandad2025cdfe.core/libs/prx/libc/src/GuestArena.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-12-01T09:47:42Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
Changes are required before merge: reject fixed reservations that overlap the system reserved range, including when they remap an already registered range.
What I ran
Reviewed head
7e8ab190876473165cb886582ecccbdfabf8d27f. Read the prepared description, commits, manifest, diff, and file list; usedrepo_read.pyto inspect targeted source ranges and search for callers. I did not run tests or builds.Results
Negative control
Not run. The author reports the new test fails against the old implementation; I did not verify that result.
Findings
Blocking
core/libs/prx/libkernel/DirectMemory/DirectMemory.cpp:1897: The reserved-range check comes after an early success path. A non-fixed hinted reservation can now be placed in the range and registered; a later fixed reservation over that same registered range can passRemapFixedIntoRegisteredand return success before reaching this check. Move the overlap check before themutation.Coversbranch, and cover this sequence with a regression test.Non-blocking
None.
Sources
Not verified
No tests, builds, or console runs were performed by me. macOS behavior was not verified. All eight changed files listed under
reviewedinfiles.jsonwere inspected at their changed lines; no files were excluded.To get this to a good state
Move the overlap check ahead of the registered-range early return and add a regression test for a fixed reservation over an already registered range inside the system reserved region. Rerun the relevant memory tests on the updated head.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-12-01T11:13:41Z.
Review: APPROVED
Reviewed — looks good
The changed code lets Windows honor hints inside the system-reserved range while keeping the AGC driver block unavailable and rejecting fixed reservations that overlap the range.
What I ran
Reviewed head
4b335e6746db4873bdb90655e05e6e55876e0c79against basemainusing the pinnedrepo_read.pyreader and the prepared diff. No merged-preview check, build, or test was run.Read all changed hunks and relevant source context for the eight changed files listed in
manifest.json;files.jsonlists no excluded files.Results
Negative control
Not run by the reviewer. The author reports reverted-control results in the PR description; those results were not independently verified.
Findings
Blocking
None.
Non-blocking
None.
Sources
Not verified
Tests and author-reported controls were not run by the reviewer. Windows hardware behavior and macOS behavior were not independently confirmed. No changed files were excluded.
To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by Plyxen on 2026-12-03T06:03:39Z.
Review: APPROVED
I read the diff at
4b335e6746. Windows 11, GCC 15.2, merged intomainatcf556db18c3together with other open PRs (so not an isolated build).guest_system_reserved_hint: pass.main's): "System reserved hint check failed at line 41".MarcZX10's change request was resolved by their later approval.
Not checked: a title.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T19:30:55Z.
Review: COMMENTED
The new fixed-range check covers fresh allocation and
DoReserveVirtual, but a fixed remap over an existing hint-placed mapping takes a different path.DoMapDirectandMapAnonymouscan enterRemapFixedIntoRegisteredand return before reachingGuestArenaMarkUsed. Once a hint has populated the reserved range, those paths can still replace it with a fixed mapping. Please apply the documented rule to the existing-mapping path too, or document and exercise the intentional difference between a replacement and a new fixed mapping.Source review at
4b335e6746. I have no native Windows result for this head.AI-assisted: yes.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.