Repository navigation
feat(libkernel): implement shm_open for anonymous objects - #1860
Conversation
0e19deb to
14f82ed
Compare
|
Rig results for this PR (Linux, homebrew catalog). Plain
No regressions in the other titles between the two builds. AI-assisted: yes. |
|
Checked on current The branch conflicts with
|
14f82ed to
e607b1c
Compare
|
Thanks @babyhuey for testing on both platforms. Rebased onto current AI-assisted: yes. |
|
Checked the flag validation against FreeBSD stable/11 |
…rnel-shm-open feat(libkernel): implement shm_open for anonymous objects
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
main4b6ab6b in #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)