feat(libkernel): implement shm_open for anonymous objects #1860
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1860"
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 overlordxrz-source on 2026-10-08T22:16:10Z.
What
libkerneldoes not exportshm_open(QuJYZ2KVGGQ). ccleste (PPSA59322) stops on it at load onmain.Its bundled Mesa calls it in two places, both with
SHM_ANON:shm_open(SHM_ANON, O_RDWR | O_CREAT | O_CLOEXEC, 0600), thenftruncate, thencloseon failure. This is Mesa's FreeBSDos_create_anonymous_file. Its caller thenmmaps the descriptorMAP_SHARED.shm_open(SHM_ANON, O_RDWR [| O_CLOEXEC], 0600).shm_openis added in the newlibkernel/File/src/SharedMemory.cpp, following FreeBSD 11'skern_shm_open(sys/kern/uipc_shm.c):O_RDONLYorO_RDWR. Flags other thanO_ACCMODE | O_CREAT | O_EXCL | O_TRUNC | O_CLOEXECare rejected. Both returnEINVAL, before the path is looked at.SHM_ANONwithO_RDONLYreturnsEINVAL.SHM_ANONwithO_RDWRreturns a new descriptor for a zero-length object. Each object is a host anonymous file: amemfdon Linux, and on Windows a delete-on-close temporary file opened with_O_TEMPORARY | _O_SHORT_LIVED. Because the guest descriptor is the host CRT descriptor, the existingftruncate,read/write,pread/pwrite,fstatandclosework on it unchanged.EMFILE,ENFILEandENOMEMfrom the host are returned as the guest errors; any other host failure throws. The guesterrnois kept on success.NotImplemented_nid_no_patch). No title is known to open one.mmapis unchanged. It accepts only private anonymous mappings and fails a mapping of a descriptor withEOPNOTSUPP. Soos_create_anonymous_filenow succeeds, and the caller'sMAP_SHAREDmapping fails on its error path (it checks forMAP_FAILED) instead of the title failing to load. Shared file mappings are a separate change.docs/dev/TechnicalDebt.mdrecords this, the ignored mode and the named-object gap.Log
I don't have a console, and I couldn't run the title here: the host is aarch64 and the project needs x86-64. The stop is from @SleglJan's run of the homebrew catalog on
main4b6ab6bbin #1578 (comment). Each title was relinked with--registryand run for 8 s on Linux. In the table of first stops,shm_openis the stop for PPSA59322 ccleste, with no open PR. That run reports the stop asapp.elf: symbol lookup error: app.elf: undefined symbol: QuJYZ2KVGGQ.PPSA59322.zip, sha25696861b81…fb43, matching the catalog recordThe call sites and arguments come from its unwrapped
eboot.bin: the relocation forQuJYZ2KVGGQ, then thecall/jmp qword ptr [rip+…]through that slot. Theftruncate(ih4CD9-gghM),closeandmmap(BPE9s9vQQXo) slots were resolved the same way.If someone with the title can post the next stop with this PR applied, I'll add it here.
Tested
aarch64 Debian 13 host. The full project cannot be built here because it needs x86-64.
core/libs/tests/GuestShmOpen.cpp(guest_shm_open) checks:O_RDWR, andO_CREAT | O_EXCL | O_TRUNC | O_CLOEXEC) give distinct descriptors and leaveerrnounchangedftruncateto 16 KiB, data written withpwritereads back, the last byte is zero and a read at the end returns 0EINVALforO_RDONLY,O_CREATalone,O_WRONLY, access mode 3,O_APPENDandO_NONBLOCK, and for bad flags on a named pathSharedMemory.cppwith host-backed stand-ins for the guestftruncate/pread/pwrite/close, which the CMake test takes fromlibkernel.O_RDONLYaccepted, no flag check, and a named path accepted.SharedMemory.cppand the test compile for x86_64-linux-gnu and x86_64-windows-gnu with-Wall -Wextra. The only warnings are the existing-Wreturn-type-c-linkageones fromGeneral.hpp. The Windows_wsopen_spath is compiled but not run.python3 tools/check_conventions.py --base origin/mainpasses.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)Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-08T22:16:31Z.
Progress report (
c963432→e607b1c)📉 System libraries: 85.67% (-0.03%, +1 declared functions)
🆕 1 declared as stubs
shm_open_nid_postfixImported from boykopovar/AnyPS5. Originally posted by overlordxrz-source on 2026-10-10T01:38:29Z.
Rig results for this PR (Linux, homebrew catalog). Plain
mainat 7a7eb369 vsmain+ #1860 (plus our #2028 and #2140) at e908ea61:mainQuJYZ2KVGGQ(shm_open)1nTKA7pN1jw(utime)QuJYZ2KVGGQ(shm_open)1nTKA7pN1jw(utime)QuJYZ2KVGGQ(shm_open)1nTKA7pN1jw(utime)No regressions in the other titles between the two builds.
AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-10T01:55:09Z.
Checked on current
mainee501326with this PR (0e19deb3) merged, Linux (Ubuntu 24.04, GCC 13) and Windows 11 (MinGW-w64 GCC from WinLibs), Release.The branch conflicts with
mainonly indocs/dev/TechnicalDebt.md:mainrewrote the Windows host-pointer import entry right above the newshm_openentry. Keepingmain's version of that entry and adding theshm_openline resolves it.guest_shm_openpasses 5/5 on both (--repeat until-fail:5); no CRT assertion dialog on Windows.shm_openonmainand gets past it on both:app.elf: symbol lookup error: app.elf: undefined symbol: 1nTKA7pN1jw(utime)FAIL: unresolved ELF import 1nTKA7pN1jw (utime) from libSceLibcInternal.prxImported from boykopovar/AnyPS5. Originally posted by overlordxrz-source on 2026-10-10T02:06:18Z.
Thanks @babyhuey for testing on both platforms. Rebased onto current
main. The only conflict was the libkernel source list in CMakeLists.txt (main added OpenFileLimit.cpp, so both are kept).TechnicalDebt.mdnow keeps main's Windows host-pointer entry with theshm_openline added, as you described. No code changes.AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T06:07:21Z.
Checked the flag validation against FreeBSD stable/11
kern_shm_open(access mode, accepted flag mask,SHM_ANON+O_RDONLY→EINVAL): matches. Built on Linux andguest_shm_openpasses; it does not link without the change. Named objects throw, the ignored mode and the missing sharedmmapare in TechnicalDebt, and @babyhuey's Linux and Windows runs (test 5/5, vkQuake pastshm_open) cover the Windows path. Merging.