feat(libkernel): map regular files with mmap on Linux #5053
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5053"
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 YossiYad on 2026-10-13T09:49:42Z.
What
On Linux,
mmapmaps only shared memory descriptors (shm_open) and fails withEOPNOTSUPPfor every other descriptor, including regular files. SQLite in WAL mode maps its-shmindex file withmmap(MAP_SHARED), so that failure becomesdisk I/O error: Dusklight (PPSA99305) logsFailed to set pragmas: disk I/O errorandSQLite DB init failedfor its GPU cache and pipeline cache at every start and runs without them. With strace, the guest'smmapof the 32 KiB-shmfile stops at the descriptor check after theF_DUPFD_CLOEXEC/F_GETFLvalidation; no hostmmapis attempted.mmapaccepts a regular file's descriptor (hostfstatreportsS_ISREG) besides shared memory descriptors, with the existing access checks (EACCESfor a shared writable mapping of a read-only descriptor) and the existingDoMapFileBackedpath, shared or private.guest_memorymaps a two-page file shared (reads both pages, a write reaches the file), private (a write stays in the mapping), at a page offset, and through a read-only descriptor (shared writable fails withEACCES, read-only works); a pipe still fails withEOPNOTSUPP.mmap(2), shadPS4'sMemoryManager::MapFilefor regular files), that console behaviour is not measured, that other descriptor kinds still fail, and that Windows maps no files.Tested
Linux (Bazzite 44 host, Fedora 44 distrobox, GCC 16.2.1, Ninja, Release,
-DBUILD_TESTING=ON), based onmainbb9a4d8a:libs, and fullctest: 1017 pass, 8 skip, 1 fail. The failure isagc_driver_tessellation(SEGFAULT), which fails the same way on unchangedmainon this machine.guest_memoryagainst unchangedmain'sPosixMemory.cppfails at the shared mapping of the regular file, and passes with the change.--trap-sdk-syscall-stubs; it needs the posix_spawn exports of #3651 to load, so that PR was merged locally for the title run only): before the change the log has the twodisk I/O errorfailures above; with it,SQLite cache init succeeded,dawn_cache.db-walandpipeline_cache.db-walare written, and nodisk I/Oline remains. Without a disc image the title stays at its menu, as expected.tools/check_conventions.py --base upstream/main,git diff --checkandtools/pr_overlap.py(no overlap) pass. Windows and macOS were not run; this change does not touch their paths.Checklist
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 repositoryImported from boykopovar/AnyPS5. Originally posted by simonbronk on 2026-10-13T16:19:44Z.
Tested on Linux x86-64 (Ubuntu 24.04 in a Colima VM with Rosetta on Apple M4, GCC 13.3), this PR (
3f12dcef3) merged intomain39890031e, Release build withBUILD_TESTING=ON.ctest: 1062/1069 pass, including the tests incore/libs/tests/GuestMemory.cpp. The only failures are the 7 that also fail onmainin this environment (Rosetta and VM limits:guest_math,amd64_only_converter,agc_driver_depth_compare_copy,tls_function_coverage_register_address_loads,linux_executable_exports,linux_entry_argv,linux_input_program_headers). No new failures.AI-assisted: yes (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-13T17:59:43Z.
Linux title check (Ubuntu 24.04, GCC 13, Release, headless), head 3f12dcef on its base:
guest_memorypasses 5/5 (--repeat until-fail:5). Dusklight (PPSA99305, catalog release): onmainb8683834its GPU cache logsFailed to start transaction: disk I/O errorandSQLite DB init failedright after it opensdawn_cache.db-shm. With this PR it logsSQLite cache init succeeded. Both runs then stop at the headlessDisplayWindowthrow, as far as a run without a display gets.Imported from boykopovar/AnyPS5. Originally posted by YossiYad on 2026-10-13T20:00:32Z.
Thanks @simonbronk and @babyhuey for the runs. Dusklight (PPSA99305) going from
disk I/O error/SQLite DB init failedonmaintoSQLite cache init succeededwith the PR is exactly the case this is for: Dawn's WAL index (dawn_cache.db-shm) is a regular-filemmap, whichmaincan't serve. The headlessDisplayWindowthrow after is as far as a no-display run gets, so that's the expected stop.On the overlap with #5186: it's docs-only and adjacent. #5186 edits the
ioctlbullet indocs/dev/debt/libkernel.md, while this PR adds a separate "Regular file mappings" bullet two lines above it. There's no shared code, exports or new files (the bot's own table shows nothing in those columns), so there's no dependency between them, just a one-line textual conflict in that doc for whoever merges second.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T11:21:48Z.
Checked on the PR merged onto current main:
guest_memoryand the scoped test run (166 tests) pass, and withPosixMemory.cppreverted the newCheckRegularFileMappingfails, so it pins the change. Access checks,EOPNOTSUPPfor a pipe and the debt entry look right; the Dusklight runs by @simonbronk and @babyhuey confirm the SQLite WAL case. Merging.Imported from boykopovar/AnyPS5. Originally posted by YossiYad on 2026-10-14T11:52:20Z.
Thanks @adriadam10 for checking it, including the revert of
PosixMemory.cpp. It still merges cleanly onto the latestmain(e464db9e3); on that treeguest_memorypasses and the fullctesthere shows onlyagc_driver_tessellation, which segfaults on this machine without any change.