fix(libkernel): drop undefined protection bits in sceKernelMprotect #5770

Merged
simonbronk merged 2 commits from upstream-pr/5770 into main 2026-10-15 15:53:03 +00:00
simonbronk commented 2026-10-14 09:55:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by simonbronk on 2026-10-14T09:55:43Z.


What

Onimusha: Way of the Sword (PPSA27836 01.000.001) maps direct memory with prot=0xf2 and then calls sceKernelMprotect on the same range with 0xfffffff2. LinuxProtFromSce refuses any bit outside 0x3F7, so the title aborts at boot:

[memory] map direct 000000e800a00000+0x10000 phys=0x327f0000 prot=0xf2 flags=0x10 align=0x0
[memory] protect 000000e800a00000+0x10000 prot=0xfffffff2
terminate called after throwing an instance of 'std::invalid_argument'
  what():  Unsupported memory protection bits: -14

FreeBSD 11's sys_mprotect masks the argument (prot = uap->prot & VM_PROT_ALL;, vm_mmap.c#L606) instead of refusing it. sceKernelMprotect now drops the bits outside 0x3F7 the same way. Here the result is 0x3f2, which gives the same host protection as the 0xf2 of the map. The map calls and sceKernelMtypeprotect still refuse undefined bits; the debt entry says so, and that the console was not measured.

Tested

  • Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7, Release, on main 0b97f8b9f: full ctest -j 8, 1142/1142 pass.
  • guest_memory gains CheckMprotectIgnoresUndefinedBits: map flexible memory with 3, protect it with 0xfffffff2, write and read it back. With main's Export.cpp it fails with the title's message (Unsupported memory protection bits: -14); with the change it passes.
  • PPSA27836 on Windows (RTX 5070), relinked with --windows-fixed-base 0x400000000 and with the missing libSceHttp2 export from #5771: it passes this call, creates its GPU device and registers its shaders, and stops later in sceConvertKeycodeGetCharacter (#5726). The stops are listed in #5769.
  • python tools/check_conventions.py --base upstream/main: passes.

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 under Silent stubs in their library's technical debt file — not applicable, no stub
  • 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 — not applicable
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: PPSA27836 #5769 (stop 3; the title also needs #5771 to reach it)
  • GPUs tested: n/a (no AGC, shader recompiler or VideoOut change)
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4856106956 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5770). Originally posted by [simonbronk](https://github.com/simonbronk) on 2026-10-14T09:55:43Z. --- ### What Onimusha: Way of the Sword (PPSA27836 01.000.001) maps direct memory with `prot=0xf2` and then calls `sceKernelMprotect` on the same range with `0xfffffff2`. `LinuxProtFromSce` refuses any bit outside `0x3F7`, so the title aborts at boot: ``` [memory] map direct 000000e800a00000+0x10000 phys=0x327f0000 prot=0xf2 flags=0x10 align=0x0 [memory] protect 000000e800a00000+0x10000 prot=0xfffffff2 terminate called after throwing an instance of 'std::invalid_argument' what(): Unsupported memory protection bits: -14 ``` FreeBSD 11's `sys_mprotect` masks the argument (`prot = uap->prot & VM_PROT_ALL;`, [vm_mmap.c#L606](https://github.com/freebsd/freebsd-src/blob/34bd34750187bae02a0086402c78c031c59dd8b3/sys/vm/vm_mmap.c#L606)) instead of refusing it. `sceKernelMprotect` now drops the bits outside `0x3F7` the same way. Here the result is `0x3f2`, which gives the same host protection as the `0xf2` of the map. The map calls and `sceKernelMtypeprotect` still refuse undefined bits; the debt entry says so, and that the console was not measured. ### Tested - Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7, Release, on `main` 0b97f8b9f: full `ctest -j 8`, 1142/1142 pass. - `guest_memory` gains `CheckMprotectIgnoresUndefinedBits`: map flexible memory with `3`, protect it with `0xfffffff2`, write and read it back. With `main`'s `Export.cpp` it fails with the title's message (`Unsupported memory protection bits: -14`); with the change it passes. - PPSA27836 on Windows (RTX 5070), relinked with `--windows-fixed-base 0x400000000` and with the missing `libSceHttp2` export from #5771: it passes this call, creates its GPU device and registers its shaders, and stops later in `sceConvertKeycodeGetCharacter` (#5726). The stops are listed in #5769. - `python tools/check_conventions.py --base upstream/main`: passes. ### 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 under Silent stubs in their library's technical debt file — not applicable, no stub - [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 — not applicable - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Unblocks: PPSA27836 #5769 (stop 3; the title also needs #5771 to reach it) - [x] GPUs tested: n/a (no AGC, shader recompiler or VideoOut change) - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
simonbronk commented 2026-10-14 19:57:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by simonbronk on 2026-10-14T19:57:38Z.


Rebased onto main 411e5e6d9 (ce074f930). The only conflict was in docs/dev/debt/libkernel.md: main added the sceKernelMprotect gap entry, and both entries are kept. The code is unchanged, and conventions pass.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6177115614 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5770#issuecomment-6177115614). Originally posted by [simonbronk](https://github.com/simonbronk) on 2026-10-14T19:57:38Z. --- Rebased onto `main` 411e5e6d9 (ce074f930). The only conflict was in `docs/dev/debt/libkernel.md`: `main` added the sceKernelMprotect gap entry, and both entries are kept. The code is unchanged, and conventions pass.
github-actions[bot] commented 2026-10-15 12:09:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T12:09:24Z.


Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 3891 core/libs/prx/libkernel/DirectMemory/Export.cpp
core/libs/tests/GuestMemory.cpp
docs/dev/debt/libkernel.md
PR 4156 core/libs/prx/libkernel/DirectMemory/Export.cpp
core/libs/tests/GuestMemory.cpp
docs/dev/debt/libkernel.md
PR 4396 core/libs/prx/libkernel/DirectMemory/Export.cpp
core/libs/tests/GuestMemory.cpp
docs/dev/debt/libkernel.md
PR 4397 core/libs/prx/libkernel/DirectMemory/Export.cpp
core/libs/tests/GuestMemory.cpp
docs/dev/debt/libkernel.md
PR 4422 core/libs/prx/libkernel/DirectMemory/Export.cpp
core/libs/tests/GuestMemory.cpp
docs/dev/debt/libkernel.md
PR 4423 core/libs/prx/libkernel/DirectMemory/Export.cpp
core/libs/tests/GuestMemory.cpp
docs/dev/debt/libkernel.md
PR 4424 core/libs/prx/libkernel/DirectMemory/Export.cpp
core/libs/tests/GuestMemory.cpp
docs/dev/debt/libkernel.md
PR 4449 core/libs/tests/GuestMemory.cpp
PR 4520 core/libs/prx/libkernel/DirectMemory/Export.cpp
core/libs/tests/GuestMemory.cpp
docs/dev/debt/libkernel.md
PR 4521 core/libs/prx/libkernel/DirectMemory/Export.cpp
core/libs/tests/GuestMemory.cpp
docs/dev/debt/libkernel.md
PR 4522 core/libs/prx/libkernel/DirectMemory/Export.cpp
core/libs/tests/GuestMemory.cpp
docs/dev/debt/libkernel.md
PR 4523 core/libs/prx/libkernel/DirectMemory/Export.cpp
core/libs/tests/GuestMemory.cpp
docs/dev/debt/libkernel.md
PR 4566 core/libs/prx/libkernel/DirectMemory/Export.cpp
core/libs/tests/GuestMemory.cpp
docs/dev/debt/libkernel.md
PR 4599 core/libs/prx/libkernel/DirectMemory/Export.cpp
core/libs/tests/GuestMemory.cpp
docs/dev/debt/libkernel.md
PR 4718 core/libs/prx/libkernel/DirectMemory/Export.cpp
core/libs/tests/GuestMemory.cpp
docs/dev/debt/libkernel.md
PR 4740 core/libs/prx/libkernel/DirectMemory/Export.cpp
core/libs/tests/GuestMemory.cpp
docs/dev/debt/libkernel.md
PR 4749 core/libs/prx/libkernel/DirectMemory/Export.cpp
core/libs/tests/GuestMemory.cpp
docs/dev/debt/libkernel.md
PR 4760 core/libs/prx/libkernel/DirectMemory/Export.cpp
core/libs/tests/GuestMemory.cpp
docs/dev/debt/libkernel.md
PR 4813 core/libs/prx/libkernel/DirectMemory/Export.cpp
core/libs/tests/GuestMemory.cpp
docs/dev/debt/libkernel.md
PR 5021 core/libs/prx/libkernel/DirectMemory/Export.cpp
core/libs/tests/GuestMemory.cpp
docs/dev/debt/libkernel.md
PR 5835 docs/dev/debt/libkernel.md
PR 5993 docs/dev/debt/libkernel.md
PR 6044 core/libs/tests/GuestMemory.cpp
PR 6222 core/libs/prx/libkernel/DirectMemory/Export.cpp
docs/dev/debt/libkernel.md
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6191700220 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5770#issuecomment-6191700220). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-15T12:09:24Z. --- <!-- pr-overlap --> Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap. | Pull request | Shared files not compared | |---|---| | [PR 3891](https://www.github.com/boykopovar/AnyPS5/pull/3891) | `core/libs/prx/libkernel/DirectMemory/Export.cpp`<br>`core/libs/tests/GuestMemory.cpp`<br>`docs/dev/debt/libkernel.md` | | [PR 4156](https://www.github.com/boykopovar/AnyPS5/pull/4156) | `core/libs/prx/libkernel/DirectMemory/Export.cpp`<br>`core/libs/tests/GuestMemory.cpp`<br>`docs/dev/debt/libkernel.md` | | [PR 4396](https://www.github.com/boykopovar/AnyPS5/pull/4396) | `core/libs/prx/libkernel/DirectMemory/Export.cpp`<br>`core/libs/tests/GuestMemory.cpp`<br>`docs/dev/debt/libkernel.md` | | [PR 4397](https://www.github.com/boykopovar/AnyPS5/pull/4397) | `core/libs/prx/libkernel/DirectMemory/Export.cpp`<br>`core/libs/tests/GuestMemory.cpp`<br>`docs/dev/debt/libkernel.md` | | [PR 4422](https://www.github.com/boykopovar/AnyPS5/pull/4422) | `core/libs/prx/libkernel/DirectMemory/Export.cpp`<br>`core/libs/tests/GuestMemory.cpp`<br>`docs/dev/debt/libkernel.md` | | [PR 4423](https://www.github.com/boykopovar/AnyPS5/pull/4423) | `core/libs/prx/libkernel/DirectMemory/Export.cpp`<br>`core/libs/tests/GuestMemory.cpp`<br>`docs/dev/debt/libkernel.md` | | [PR 4424](https://www.github.com/boykopovar/AnyPS5/pull/4424) | `core/libs/prx/libkernel/DirectMemory/Export.cpp`<br>`core/libs/tests/GuestMemory.cpp`<br>`docs/dev/debt/libkernel.md` | | [PR 4449](https://www.github.com/boykopovar/AnyPS5/pull/4449) | `core/libs/tests/GuestMemory.cpp` | | [PR 4520](https://www.github.com/boykopovar/AnyPS5/pull/4520) | `core/libs/prx/libkernel/DirectMemory/Export.cpp`<br>`core/libs/tests/GuestMemory.cpp`<br>`docs/dev/debt/libkernel.md` | | [PR 4521](https://www.github.com/boykopovar/AnyPS5/pull/4521) | `core/libs/prx/libkernel/DirectMemory/Export.cpp`<br>`core/libs/tests/GuestMemory.cpp`<br>`docs/dev/debt/libkernel.md` | | [PR 4522](https://www.github.com/boykopovar/AnyPS5/pull/4522) | `core/libs/prx/libkernel/DirectMemory/Export.cpp`<br>`core/libs/tests/GuestMemory.cpp`<br>`docs/dev/debt/libkernel.md` | | [PR 4523](https://www.github.com/boykopovar/AnyPS5/pull/4523) | `core/libs/prx/libkernel/DirectMemory/Export.cpp`<br>`core/libs/tests/GuestMemory.cpp`<br>`docs/dev/debt/libkernel.md` | | [PR 4566](https://www.github.com/boykopovar/AnyPS5/pull/4566) | `core/libs/prx/libkernel/DirectMemory/Export.cpp`<br>`core/libs/tests/GuestMemory.cpp`<br>`docs/dev/debt/libkernel.md` | | [PR 4599](https://www.github.com/boykopovar/AnyPS5/pull/4599) | `core/libs/prx/libkernel/DirectMemory/Export.cpp`<br>`core/libs/tests/GuestMemory.cpp`<br>`docs/dev/debt/libkernel.md` | | [PR 4718](https://www.github.com/boykopovar/AnyPS5/pull/4718) | `core/libs/prx/libkernel/DirectMemory/Export.cpp`<br>`core/libs/tests/GuestMemory.cpp`<br>`docs/dev/debt/libkernel.md` | | [PR 4740](https://www.github.com/boykopovar/AnyPS5/pull/4740) | `core/libs/prx/libkernel/DirectMemory/Export.cpp`<br>`core/libs/tests/GuestMemory.cpp`<br>`docs/dev/debt/libkernel.md` | | [PR 4749](https://www.github.com/boykopovar/AnyPS5/pull/4749) | `core/libs/prx/libkernel/DirectMemory/Export.cpp`<br>`core/libs/tests/GuestMemory.cpp`<br>`docs/dev/debt/libkernel.md` | | [PR 4760](https://www.github.com/boykopovar/AnyPS5/pull/4760) | `core/libs/prx/libkernel/DirectMemory/Export.cpp`<br>`core/libs/tests/GuestMemory.cpp`<br>`docs/dev/debt/libkernel.md` | | [PR 4813](https://www.github.com/boykopovar/AnyPS5/pull/4813) | `core/libs/prx/libkernel/DirectMemory/Export.cpp`<br>`core/libs/tests/GuestMemory.cpp`<br>`docs/dev/debt/libkernel.md` | | [PR 5021](https://www.github.com/boykopovar/AnyPS5/pull/5021) | `core/libs/prx/libkernel/DirectMemory/Export.cpp`<br>`core/libs/tests/GuestMemory.cpp`<br>`docs/dev/debt/libkernel.md` | | [PR 5835](https://www.github.com/boykopovar/AnyPS5/pull/5835) | `docs/dev/debt/libkernel.md` | | [PR 5993](https://www.github.com/boykopovar/AnyPS5/pull/5993) | `docs/dev/debt/libkernel.md` | | [PR 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `core/libs/tests/GuestMemory.cpp` | | [PR 6222](https://www.github.com/boykopovar/AnyPS5/pull/6222) | `core/libs/prx/libkernel/DirectMemory/Export.cpp`<br>`docs/dev/debt/libkernel.md` |
adriadam10 commented 2026-10-15 12:49:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-15T12:49:47Z.


Checked the FreeBSD 11 sys_mprotect mask (prot = uap->prot & VM_PROT_ALL, vm_mmap.c L606), the 0x3F7 mask (0xfffffff2 becomes 0x3f2, same host protection as the 0xf2 map), the debt entry and its section. guest_memory passes on the merged tree and fails without the Export.cpp change; scoped ctest 173/173. Merging once the full Build is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6192456735 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5770#issuecomment-6192456735). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-15T12:49:47Z. --- Checked the FreeBSD 11 `sys_mprotect` mask (`prot = uap->prot & VM_PROT_ALL`, vm_mmap.c L606), the `0x3F7` mask (`0xfffffff2` becomes `0x3f2`, same host protection as the `0xf2` map), the debt entry and its section. `guest_memory` passes on the merged tree and fails without the `Export.cpp` change; scoped ctest 173/173. Merging once the full Build is green.
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!5770
No description provided.