fix(libkernel): report reserved virtual ranges in sceKernelVirtualQuery #700

Merged
merwie merged 1 commit from upstream-pr/700 into main 2026-10-06 09:27:37 +00:00
merwie commented 2026-10-05 16:56:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by merwie on 2026-10-05T16:56:21Z.


What

sceKernelReserveVirtualRange registers its range as not readable, and sceKernelVirtualQuery only searches readable registrations (GuestAllocationsAcquire). A query inside a reservation therefore fell through to the host query and returned SCE_KERNEL_ERROR_EACCES.

  • Reserved ranges are tracked in DirectMemory.cpp from DoReserveVirtual (including the fixed re-reserve over a mapping) until DoMapDirect, DoMapAnon or DoMunmap covers them.
  • sceKernelVirtualQuery answers an address inside a reservation first: success, extent of the reserved piece, protection 0, is_committed, is_direct and is_flexible clear.
  • GuestMemory: new CheckReservedRangeIsNotCommitted (a reservation queries as uncommitted; after a fixed direct mapping of its first page, that page is committed and direct and the second page is still a reserved piece). CheckFixedVirtualReservation expected the query on a range re-reserved over a mapping to fail; it now expects the reserved, uncommitted answer.

PPSA12544 (Hollow Knight: Silksong) reserves 1 MiB, queries it, and maps direct memory into it only when the query reports it uncommitted. The error was handled as a failed commit and the allocator then wrote to the inaccessible range (access violation at reserve + 0xfffe0).

Tested

Windows 11, WinLibs GCC 15.2.0 r7, Ryzen 7 9800X3D, Radeon RX 9070 XT.

  • ctest: 286/288 passed, including guest_memory. agc_driver_lds_atomics64 and agc_driver_vopc_compare_table fail on this machine on main as well (Vulkan device tests).
  • PPSA12544 with #698, #699 and stubs for #518's exports: the query now returns the reservation uncommitted, the title allocates and maps direct memory into it (remap fixed 0x210000000+0x100000) and continues until the unknown libkernel export NH6xARDOVv8 throws. Without this change it crashes in the allocator.

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 (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4748254130 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/700). Originally posted by [merwie](https://github.com/merwie) on 2026-10-05T16:56:21Z. --- ### What `sceKernelReserveVirtualRange` registers its range as not readable, and `sceKernelVirtualQuery` only searches readable registrations (`GuestAllocationsAcquire`). A query inside a reservation therefore fell through to the host query and returned `SCE_KERNEL_ERROR_EACCES`. - Reserved ranges are tracked in `DirectMemory.cpp` from `DoReserveVirtual` (including the fixed re-reserve over a mapping) until `DoMapDirect`, `DoMapAnon` or `DoMunmap` covers them. - `sceKernelVirtualQuery` answers an address inside a reservation first: success, extent of the reserved piece, protection 0, `is_committed`, `is_direct` and `is_flexible` clear. - `GuestMemory`: new `CheckReservedRangeIsNotCommitted` (a reservation queries as uncommitted; after a fixed direct mapping of its first page, that page is committed and direct and the second page is still a reserved piece). `CheckFixedVirtualReservation` expected the query on a range re-reserved over a mapping to fail; it now expects the reserved, uncommitted answer. PPSA12544 (Hollow Knight: Silksong) reserves 1 MiB, queries it, and maps direct memory into it only when the query reports it uncommitted. The error was handled as a failed commit and the allocator then wrote to the inaccessible range (access violation at `reserve + 0xfffe0`). ### Tested Windows 11, WinLibs GCC 15.2.0 r7, Ryzen 7 9800X3D, Radeon RX 9070 XT. - `ctest`: 286/288 passed, including `guest_memory`. `agc_driver_lds_atomics64` and `agc_driver_vopc_compare_table` fail on this machine on `main` as well (Vulkan device tests). - PPSA12544 with #698, #699 and stubs for #518's exports: the query now returns the reservation uncommitted, the title allocates and maps direct memory into it (`remap fixed 0x210000000+0x100000`) and continues until the unknown libkernel export `NH6xARDOVv8` throws. Without this change it crashes in the allocator. ### 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 (attach them to this PR) - [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 🤖 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!700
No description provided.