Skip to content

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

Closed

Description

@xXPBSXx

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.

Activity

  1. reyani-dev commented on Oct 11, 2026

    @reyani-dev
    Contributor

    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.

  2. xXPBSXx commented on Oct 11, 2026

    @xXPBSXx
    ContributorAuthor

    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).

  3. adriadam10 commented on Oct 11, 2026

    @adriadam10
    Collaborator

    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).

  4. xXPBSXx commented on Oct 11, 2026

    @xXPBSXx
    ContributorAuthor

    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 (1be0a7c): 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).

  5. xXPBSXx commented on Oct 11, 2026

    @xXPBSXx
    ContributorAuthor

    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 up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions