fix(libkernel): allow sceKernelMprotect on committed host memory outside the guest registry #3788

Merged
xXPBSXx merged 1 commit from upstream-pr/3788 into main 2026-10-11 22:01:52 +00:00
xXPBSXx commented 2026-10-11 16:43:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-11T16:43:32Z.


What

sceKernelMprotect threw "guest protection or unmap range is not registered" for committed private host memory that is not in the guest allocation registry (seen on a thread stack: 0xf8380000+0x580000, prot 0xc2). On Windows it now sets the native protection for such a range and returns 0 when the range is a committed private region that does not overlap any registered guest allocation. Everything else keeps its previous path. Related: #3143.

Tested

  • Windows 10, MinGW/Ninja build of main a11c8f7f7 plus this commit: ctest -R "^guest_memory$" passes, including the new CheckMprotectOfHostMemoryOutsideTheGuestRegistry (VirtualAlloc'd region: protect to read/write, write and read back, read-only, read/write again, native protection checked with VirtualQuery). That check failed before the change (verified on the earlier branch version). python tools/check_conventions.py --base upstream/main passes.
  • Found with Resident Evil 4 (PPSA07411) earlier (the range was a thread stack); this exact branch was not run with the title. Not tested: Linux/macOS (the change is _WIN32 only).

Checklist

  • Based on current main; no other open PR implements the same functions (#1330, #1360 and #3684 touch other code)
  • 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 (none added)
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source (none added)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4820649842 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3788). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-11T16:43:32Z. --- ### What `sceKernelMprotect` threw "guest protection or unmap range is not registered" for committed private host memory that is not in the guest allocation registry (seen on a thread stack: 0xf8380000+0x580000, prot 0xc2). On Windows it now sets the native protection for such a range and returns 0 when the range is a committed private region that does not overlap any registered guest allocation. Everything else keeps its previous path. Related: #3143. ### Tested - Windows 10, MinGW/Ninja build of `main` a11c8f7f7 plus this commit: `ctest -R "^guest_memory$"` passes, including the new `CheckMprotectOfHostMemoryOutsideTheGuestRegistry` (VirtualAlloc'd region: protect to read/write, write and read back, read-only, read/write again, native protection checked with `VirtualQuery`). That check failed before the change (verified on the earlier branch version). `python tools/check_conventions.py --base upstream/main` passes. - Found with Resident Evil 4 (PPSA07411) earlier (the range was a thread stack); this exact branch was not run with the title. Not tested: Linux/macOS (the change is `_WIN32` only). ### Checklist - [x] Based on current `main`; no other open PR implements the same functions (#1330, #1360 and #3684 touch other code) - [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 (none added) - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source (none added) - [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)
adriadam10 commented 2026-10-11 22:01:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T22:01:47Z.


Checked the diff against DoMprotect: the new branch only applies to committed private regions that do not overlap a registered guest allocation (RegionSize >= bytes), everything else keeps its previous path. Linux build and guest_memory pass; the new code and test are _WIN32 only, so the Windows run in the PR description is what covers them. Merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6114302847 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3788#issuecomment-6114302847). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T22:01:47Z. --- Checked the diff against `DoMprotect`: the new branch only applies to committed private regions that do not overlap a registered guest allocation (`RegionSize >= bytes`), everything else keeps its previous path. Linux build and `guest_memory` pass; the new code and test are `_WIN32` only, so the Windows run in the PR description is what covers them. Merging.
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!3788
No description provided.