fix(libkernel): count guest module segments against the flexible memory budget #3713
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3713"
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 SleglJan on 2026-10-11T15:49:43Z.
What
Refs #2883.
sceKernelAvailableFlexibleMemorySizeand the flexible maps count only explicit flexible mappings, so onmainthe whole 448 MiB is available while the title's own code and data are loaded. The Last of Us Part II Remastered (PPSA15508) computes its code and data size as its 448 MiB budget minus the available size minus a 10 MiB module allowance; with 448 MiB available the unsigned result wraps and the title stops at start-up. PPSA15508 v02.001.010, relinked onmaina11c8f7f7, Linux, Release, RTX 3080:after which the process ends with SIGSEGV (exit status 139). With this branch the stop is gone on Linux (see Tested).
.guest.prxmodule now count against the budget while they are loaded, both forsceKernelAvailableFlexibleMemorySizeand for the flexible maps (sceKernelMapFlexibleMemory, the named variants andsceKernelBatchMap2), which now returnENOMEMat the same limit. Reference: shadPS4module.cppL165 maps each segment of a module asVMAType::Flexibleunless the module comes from its system module directory (VMAType::Code), and its flexible usage counts everyFlexiblemapping. Host system libraries are not counted here either.p_memsztop_align, 16 KiB for these images). On Linux the relinker maps its own block (import stubs, dynamic tables) read/write/execute, maps an ELFPT_LOADwithout permissions read/write/execute in the executable and drops it from guest modules, and adds a header block at file offset 0 to the executable; thosePT_LOADs are skipped. On Windows only the.elfsections with a protection count, the sectionssceKernelGetModuleInfotakes a relinked image's segments from. ThePT_LOADwithout permissions holds the dynamic linking data (PT_DYNAMIClies in it in both PPSA15508 images); shadPS4 reads the PS4 equivalent,PT_SCE_DYNLIBDATA, into host memory instead of a flexible mapping.memory.cppL519-L524 returnsEINVAL,module.cppL168-L169 asserts). Recorded in TechnicalDebt; this change adds no throw for it.libc.prx1.09 MiB, the same as the permissionedPT_LOADs of the original ELFs, so with no flexible mapping yetsceKernelAvailableFlexibleMemorySizereports 337.05 MiB (0x1510C000). The title's own Memory Stats output in the run below printsCode And Global Data : 100.95 MB, against its 146 MiB limit. Counting the two segments without permissions as well would add about 5.4 MiB.Overlap: live lists re-checked on 2026-10-11 (258 open; the 500 newest closed, #2797-#3699, 298 of them merged; the 800 newest merged, #1494-#3511), titles and files grepped for DirectMemory, Flexible and ModuleInfo. No pull request counts module segments against the flexible budget. Merged #952 (
sceKernelReleaseFlexibleMemory) changed the flexible accounting, for released ranges only. Open #3514 caches unwind tables inModuleInfo.cppand applies cleanly on top of this branch. #3321 lists fork commit 369cfec (fix/flexible-memory-replacement-accounting), which corrects the counter when a fixed mapping replaces a flexible range; it was not opened upstream, and it rewrites_mapFlexible, so it would conflict with this change.Tested
BUILD_TESTING=ONandANYPS5_ENABLE_SPIRV_TOOLS=ON, this branch onmaina11c8f7f7: the 444 tests outside the GPU, shader and video-out groups pass (ctest -E 'agc|spirv|shader|vulkan|Vulkan|video_out|videoout'), and so doesagc_driver_pm4, which checks that the GDS is not charged to the flexible budget. The other GPU tests were not run.guest_memory: the new check loads theguest_memory_module.guest.prxfixture (64 KiB data array; now built on Linux too), requires the available size to drop by at least 64 KiB, a flexible map of the previous available size to fail withENOMEM, and the size to return afterdlclose. Without the implementation it fails at the first of these; with it, it passes.sceKernelGetModuleInfoalready does, but it now runs on every flexible map and size query:EnumProcessModules, thenGetModuleFileNameWtwice for each loaded.prx, without pinning the modules. A module unloaded during the walk can make it throw or read unmapped headers (the same racesceKernelGetModuleListalready has), and the cost grows with the number of loaded modules.tools/check_conventions.py --base upstream/mainandgit diff --checkpass.Code and Data section is too largeline no longer appears and the title runs on to its next stop, an unimplemented import outside this PR (sceSslLoadCert not implemented, exit status 134).Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
https://claude.ai/code/session_01Fnrk5Dazjb2tLooVSpdRQq
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T21:54:48Z.
Checked on the PR merged onto current main: scoped build and ctest (112 tests) pass,
guest_memoryfails without the change and passes with it, conventions and the TechnicalDebt entry are in place. The Windows path and the title run were not verified here; the deviations from shadPS4 and the unmeasured PS5 behaviour are recorded in TechnicalDebt. Merging.