Skip to content

fix(libkernel): register a relinked guest module's image when Linux protects its pages - #5955

Merged
adriadam10 merged 1 commit into
boykopovar:mainfrom
fma-rc:fix/libkernel-linux-guest-module-protect
Oct 16, 2026
Merged

adriadam10 merged 1 commit into
boykopovar:mainfrom
fma-rc:fix/libkernel-linux-guest-module-protect

Conversation

@fma-rc

@fma-rc fma-rc commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

What

On Linux, sceKernelMprotect over pages of a relinked guest module (*.guest.prx) throws, because DoMprotect registers only the main image in the allocation tracker. EA Sports UFC 6 (PPSA23566) stops 7 s after start on current main (e34c479) when code in its Engine.Render.Core2.PlatformPs5.prx protects its own pages:

terminate called after throwing an instance of 'std::runtime_error'
  what():  guest protection or unmap range is not registered

Windows already handles this (IsGuestModuleImage and RegisterImage in DoMprotect, UnregisterImage in dlclose). This does the same on Linux: RegisterImage and UnregisterImage are declared on every platform, the Linux RegisterImage registers the PT_LOAD pages of the loaded object whose base is given (as the main image already is), DoMprotect registers the .guest.prx image that contains the address, and protecting a page of any other loaded object throws std::invalid_argument as on Windows. dlclose drops the image's ranges when the last handle closes. The Windows CheckGuestModuleImageProtection gets a Linux counterpart. As on Windows, a module that is only loaded as another module's dependency keeps its ranges when that module is closed.

Refs #5398 (point 2 there is this case in NHL 26, which loads the same module; the other points stay open). PR 5143 is in the same function but does something else: it skips the unregistered parts of a range and returns EINVAL when nothing is registered, which would leave the module's pages unprotected.

Tested

Platform Tests Result
Linux, GCC 16.2.1, main e34c479 + this PR ctest -R guest_ (16, incl. guest_memory) pass
Windows Server 2025, WinLibs GCC 15.2 UCRT, same base, previous revision (later changes are Linux-only) full ctest (1198) pass

guest_memory fails on main with the line above and passes with the change. UFC 6 on Linux with the change passes the 8 s stop and presents its first window.

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
  • 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
  • Unblocks: PPSA23566
  • GPUs tested: n/a
  • AI-assisted: yes

0xcrstn added a commit to 0xcrstn/AnyPS5 that referenced this pull request Oct 15, 2026
…t (fma-rc)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
0xcrstn added a commit to 0xcrstn/AnyPS5 that referenced this pull request Oct 15, 2026
…he FPS candidate

Brings in ufc6/feedback (origin/main 760ffa6, boykopovar#6197, boykopovar#4286, boykopovar#5955) on top
of the four FPS topics and boykopovar#6168. Conflict resolutions:
- Execution Draw.cpp: keep the binding plan's single Regions() collection
  after the stage loop, adding the regions of reused or data-hit stages, and
  upstream's data-hit counters and cacheDrawStages signature.
- Graphics Draw.cpp: recordDrawCommands takes both upstream's firstIndex and
  the dirty-record bound state; a stencil replay, like a face or channel
  split, drops the bound state.
- The binding plan falls back to the full capture for stages whose plan uses
  image tables (ShaderMemory::UsesImageTables).

Unbuilt and untested.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Oct 15, 2026
@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 1835 core/libs/prx/libc/src/GuestAllocations.cpp L249-262, L264-266

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 1324 core/libs/prx/libc/include/GuestAllocations.hpp
core/libs/prx/libc/src/GuestAllocations.cpp
PR 4449 core/libs/prx/libkernel/DirectMemory/DirectMemory.cpp
core/libs/tests/GuestMemory.cpp
PR 5021 core/libs/prx/libc/include/GuestAllocations.hpp
core/libs/prx/libc/src/GuestAllocations.cpp
core/libs/prx/libkernel/DirectMemory/DirectMemory.cpp
core/libs/prx/libkernel/Module/src/DynamicLoader.cpp
core/libs/tests/GuestMemory.cpp
PR 6044 core/libs/tests/GuestMemory.cpp
PR 6222 core/libs/prx/libc/src/GuestAllocations.cpp
core/libs/prx/libkernel/DirectMemory/DirectMemory.cpp
core/libs/prx/libkernel/Module/src/DynamicLoader.cpp
PR 6447 core/libs/prx/libc/include/GuestAllocations.hpp
PR 6565 core/libs/prx/libc/src/GuestAllocations.cpp
core/libs/tests/GuestMemory.cpp
PR 6879 core/libs/prx/libc/src/GuestAllocations.cpp
core/libs/prx/libkernel/DirectMemory/DirectMemory.cpp
core/libs/prx/libkernel/Module/src/DynamicLoader.cpp

@adriadam10 adriadam10 self-assigned this Oct 16, 2026
@adriadam10

Copy link
Copy Markdown
Collaborator

Checked on Linux (build + scoped ctest, guest_memory passes; it fails without the change) and read the shared GuestAllocations refactor against the Windows path. Merging once the full Build is green.

@adriadam10
adriadam10 merged commit 5b70a50 into boykopovar:main Oct 16, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants