libkernel: AvailableDirectMemorySize reports first gap, Mprotect rejects host stack memory #3143

Closed
opened 2026-10-10 23:00:02 +00:00 by xXPBSXx · 5 comments
xXPBSXx commented 2026-10-10 23:00:02 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-10T23:00:02Z.


AI-assisted (Claude Code), reviewed by the contributor.

Two small libkernel findings from running RE4 (PPSA07411) on Windows. Each has its own branch on current main, a regression test in core/libs/tests/GuestMemory.cpp (both tests fail without the change, pass with it) and passes tools/check_conventions.py.

  1. sceKernelAvailableDirectMemorySize returned the first free gap in the range instead of the largest free block. The title got about 1.9 MiB reported and then failed a 96 MiB allocation. Branch: https://github.com/xXPBSXx/AnyPS5/tree/fix/libkernel-available-direct-memory-largest-block (it now returns EAGAIN when nothing fits).
  2. sceKernelMprotect on committed private host memory outside the guest registry (a thread stack) threw instead of applying the native protection. Branch: https://github.com/xXPBSXx/AnyPS5/tree/fix/libkernel-mprotect-host-memory

Not verified: that these two alone get RE4 further; other blockers remain. Not opened as PRs because intake is paused for new contributors; a maintainer is welcome to carry the commits.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5796049662 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/3143). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-10T23:00:02Z. --- AI-assisted (Claude Code), reviewed by the contributor. Two small libkernel findings from running RE4 (PPSA07411) on Windows. Each has its own branch on current `main`, a regression test in `core/libs/tests/GuestMemory.cpp` (both tests fail without the change, pass with it) and passes `tools/check_conventions.py`. 1. `sceKernelAvailableDirectMemorySize` returned the first free gap in the range instead of the largest free block. The title got about 1.9 MiB reported and then failed a 96 MiB allocation. Branch: https://github.com/xXPBSXx/AnyPS5/tree/fix/libkernel-available-direct-memory-largest-block (it now returns EAGAIN when nothing fits). 2. `sceKernelMprotect` on committed private host memory outside the guest registry (a thread stack) threw instead of applying the native protection. Branch: https://github.com/xXPBSXx/AnyPS5/tree/fix/libkernel-mprotect-host-memory Not verified: that these two alone get RE4 further; other blockers remain. Not opened as PRs because intake is paused for new contributors; a maintainer is welcome to carry the commits.
reyani-dev commented 2026-10-11 05:42:54 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by reyani-dev on 2026-10-11T05:42:54Z.


Carried the first fix (sceKernelAvailableDirectMemorySize, aace6a3f) as #3292 with your commit unchanged. On Windows 11 (GCC 15.2), guest_memory passes 3/3 and fails at the first largest-block check with Export.cpp reverted to main. I didn't carry the mprotect fix because #2982 (TheAggie) changes the same thread-stack protection path.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6105932507 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/3143#issuecomment-6105932507). Originally posted by [reyani-dev](https://github.com/reyani-dev) on 2026-10-11T05:42:54Z. --- Carried the first fix (`sceKernelAvailableDirectMemorySize`, `aace6a3f`) as #3292 with your commit unchanged. On Windows 11 (GCC 15.2), `guest_memory` passes 3/3 and fails at the first largest-block check with `Export.cpp` reverted to `main`. I didn't carry the `mprotect` fix because #2982 (TheAggie) changes the same thread-stack protection path.
xXPBSXx commented 2026-10-11 07:13:09 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-11T07:13:09Z.


Evidence that the sceKernelAvailableDirectMemorySize change matters beyond RE4: Sifu (PPSA03001, #3209) faulted in RenderThread 1 on a free-list head of 0xFFFFFFFFFFFFFFFF; with this branch it runs on, and with only that file's change reverted it faults again at the same address (same build otherwise). Details in #3209.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6106563473 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/3143#issuecomment-6106563473). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-11T07:13:09Z. --- Evidence that the `sceKernelAvailableDirectMemorySize` change matters beyond RE4: Sifu (PPSA03001, #3209) faulted in `RenderThread 1` on a free-list head of `0xFFFFFFFFFFFFFFFF`; with this branch it runs on, and with only that file's change reverted it faults again at the same address (same build otherwise). Details in #3209. AI-assisted (Claude Code).
adriadam10 commented 2026-10-11 07:27:11 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T07:27:11Z.


Fixed in part by #3292: sceKernelAvailableDirectMemorySize now reports the largest free block, covered by guest_memory; the sceKernelMprotect on host thread stacks item is still open (see #2982).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6106669859 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/3143#issuecomment-6106669859). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T07:27:11Z. --- Fixed in part by #3292: `sceKernelAvailableDirectMemorySize` now reports the largest free block, covered by `guest_memory`; the `sceKernelMprotect` on host thread stacks item is still open (see #2982).
xXPBSXx commented 2026-10-11 08:21:37 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-11T08:21:37Z.


Thanks again @AchrafReyani for #3292. The other half of this issue, sceKernelMprotect on committed host memory outside the guest registry (a thread stack), is not on main yet. I rebased it onto current main (1be0a7ce): https://github.com/xXPBSXx/AnyPS5/tree/fix/libkernel-mprotect-host-memory-v2 (one commit, test CheckMprotectOfHostMemoryOutsideTheGuestRegistry, guest_memory and the conventions check pass). Windows only, as before.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6107081099 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/3143#issuecomment-6107081099). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-11T08:21:37Z. --- Thanks again @AchrafReyani for #3292. The other half of this issue, `sceKernelMprotect` on committed host memory outside the guest registry (a thread stack), is not on `main` yet. I rebased it onto current `main` (1be0a7ce): https://github.com/xXPBSXx/AnyPS5/tree/fix/libkernel-mprotect-host-memory-v2 (one commit, test `CheckMprotectOfHostMemoryOutsideTheGuestRegistry`, `guest_memory` and the conventions check pass). Windows only, as before. AI-assisted (Claude Code).
xXPBSXx commented 2026-10-11 23:33:11 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-11T23:33:11Z.


Both parts of this issue are on main: sceKernelAvailableDirectMemorySize reports the largest free block (#3292, merged 2026-10-11, carried from this branch) and sceKernelMprotect sets the native protection of committed host memory outside the guest registry (#3788, merged 2026-10-11) with a Windows test (CheckMprotectOfHostMemoryOutsideTheGuestRegistry) and a test for the first part (CheckAvailableDirectMemoryIsLargestFreeBlock) in guest_memory. Closing.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6115146743 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/3143#issuecomment-6115146743). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-11T23:33:11Z. --- Both parts of this issue are on `main`: `sceKernelAvailableDirectMemorySize` reports the largest free block (#3292, merged 2026-10-11, carried from this branch) and `sceKernelMprotect` sets the native protection of committed host memory outside the guest registry (#3788, merged 2026-10-11) with a Windows test (`CheckMprotectOfHostMemoryOutsideTheGuestRegistry`) and a test for the first part (`CheckAvailableDirectMemoryIsLargestFreeBlock`) in `guest_memory`. Closing. AI-assisted (Claude Code).
Sign in to join this conversation.
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#3143
No description provided.