feat(libkernel): support sceKernelMprotect on foreign guest module images on Windows #5109
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5109"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by pushkarreddyy on 2026-10-13T11:55:19Z.
What
Supports
sceKernelMprotectmemory protection changes on Windows for foreign guest module images (.prx,.debug_prx,.sprx,.suprx, and images with.elf0section headers) in addition to.guest.prx.Addresses Dying Light 2: Stay Human (
PPSA02262, Issue #1794 Section 4) where bundled NVIDIA Real-time DenoiserslibNRD.prxcallssceKernelMprotecton its own image (prot=0x12and0x11) and previously terminated with:Host system libraries (such as
kernel32.dll) without guest image markers or suffixes continue to be rejected withstd::invalid_argument.Tested
core/libs/tests/GuestMemory.cpp(CheckGuestModuleImageProtection):GuestAllocationsfor.prxand.debug_prxmodule copieskernel32.dllcontinues to be rejected withstd::invalid_argumentdlcloseunregisters the guest allocation range cleanlypython tools/check_conventions.py --base origin/mainpassed with 0 findings and 0 errorsChecklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by pushkarreddyy on 2026-10-14T02:13:27Z.
Calling on @adriadam10, @oneandonlydean, and @MarcZX100 for review / merge clearance:
All CI checks passing and rebased clean on
origin/main. AddsVirtualProtectsupport for guest module images with foreign allocation bases on Windows.Imported from boykopovar/AnyPS5. Originally posted by pushkarreddyy on 2026-10-14T02:14:42Z.
Calling on @adriadam10, @oneandonlydean, and @MarcZX100 for review / merge clearance:
All CI checks passing and rebased clean on
origin/main. AddsVirtualProtectsupport for guest module images with foreign allocation bases on Windows.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T02:34:10Z.
Matching
.prxalso matches the emulator's own libraries (they're built with that suffix on Windows), so a guestsceKernelMprotectcould change the protection oflibkernel.prxand the rest. Can you drop the suffix list and decide by the.elf0section only, asModuleInfo.cppalready does for relinked images? The test then needs a relinked module rather than a renamed copy of the host-built one.Imported from boykopovar/AnyPS5. Originally posted by pushkarreddyy on 2026-10-14T02:43:01Z.
@oneandonlydean Thanks for the review! Dropped the suffix list entirely —
IsGuestModuleImagenow decides strictly by the.elf0section in the PE headers, matchingModuleInfo.cpp.Also updated the test fixture
guest_memory_moduleto place its buffer into.elf0, verified that host libraries (libkernel.prx,kernel32.dll) without.elf0are strictly rejected, and rebased cleanly onto latestorigin/main.Imported from boykopovar/AnyPS5. Originally posted by pushkarreddyy on 2026-10-14T02:50:36Z.
@oneandonlydean Updated to identify guest module images strictly by the .elf0 PE section header (mirroring ModuleInfo.cpp), completely removing the filename suffix check so host PRXs like libkernel.prx cannot be mutated. Also added unit test verification asserting that host libkernel.prx (&sceKernelMprotect) is rejected.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T03:00:09Z.
Both points are in, thanks. The rebase had replaced the
Memory protection bits 0x100 and 0x200entry indocs/dev/debt/libkernel.mdwith the new one; I pushed a commit putting it back next to yours. No other change.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T03:12:30Z.
The Windows build failed
guest_memory: the shared test module got the.elf0section, soCheckGuestModuleUsesFlexibleMemoryno longer saw its data counted. I pushed a commit giving the mprotect test its own module with.elf0and leaving the shared one as on main.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T03:26:43Z.
The Windows run then hit the test's own
sceKernelMprotect(&sceKernelMprotect, ...): on Windows that address is the import stub in the test executable, so it made the test's code read-only. It now takes libkernel's image fromGetModuleHandleA("libkernel.prx").