Repository navigation
feat(libkernel_sys): implement POSIX message queues - #9297
DavidSamir wants to merge 14 commits into
Conversation
…sed and replaced ids
Progress report (0c6a5bd → d07deaa)📈 System libraries: 42.21% (+0.11%, +12 implemented, -7 removed functions) ✅ 12 implemented
🗑️ 7 removed
|
|
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
Exports with a name or library/NID already present in
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
…elative name An absolute host temp path is not mapped by the Linux guest resolver. Found by xXPBSXx on boykopovar#9097.
…lative name An absolute host temp path is not mapped by the Linux guest resolver. Found by xXPBSXx on boykopovar#9097.
The PS5 3.20 export lists have ksem_* in libkernel as well as libkernel_sys, and on Windows a libkernel import never reaches libkernel_sys, so titles importing them from libkernel did not find them. Following pipe1os's review on boykopovar#9284, also: ENOSPC from ksem_init when no descriptor is left, the SEM_MAX limit of 30 with ENOSPC, and dup/dup2 from a ksem id throwing as for a kqueue.
|
Linux: Ubuntu 24.04.1 LTS (WSL2), GCC 13.3.0, Release; head
Run from the PC (Windows host, Linux in WSL2), not from the PR author's machine. |
|
@DavidSamir Mqueue.cpp:202 writes Open::nonblocking after releasing the queue mutex, while WaitFor at :138 reads the plain bool under that mutex. Concurrent mq_setattr and send/receive therefore race. Could you guard the old-attribute snapshot and update under the same queue.lock used by readers, or use an atomic with coherent old-attribute semantics, and add a concurrent setattr/send/receive regression? |
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — changes requested
Changes are required before merge: validate kmq_timedreceive output pointers before removing a message from the queue.
What I ran
Reviewed head d07deaa187134d4e2482a5f48aeea9f1f5601ab3 using the prepared diff and repo_read.py at the pinned head. No commands or tests were run by me; reported test results below are from the PR description.
Results
| Check | Result | Note |
|---|---|---|
| Source review | passed | Changed implementation and tests read |
| Automated checks | not run | PR description reports passing tests |
| Console behavior | not run | CPU-side implementation only |
Findings
Blocking
core/libs/prx/libkernel_sys/Mqueue.cpp:229removes the message before checkingbuffer. If the caller supplies an invalid destination pointer, the subsequent copy at line 233 can fault, and the queued message is already lost. Validate writable output pointers before dequeuing, and returnEFAULTwithout consuming the message when invalid.
Non-blocking
None.
Not verified
No tests or build were run during this review. Windows, other host platforms, and physical-console behavior were not independently verified. All changed files listed in the manifest were read; no files were excluded.
To get this to a good state
Validate the receive buffer before removing a message, then rerun the message queue tests and relevant build checks on the updated head.
|
I am closing this because the POSIX message queue work is on main through #17737, which carries the same files, was rebased onto main, fixes our three review points and credits you. There has been no push here since 21 Oct. If anything from this branch is missing there, please reopen it or open a follow-up and we will look at it. |
What
Builds on #9284 and implements POSIX message queues in a new
libkernel_sys/Mqueue.cpp, following FreeBSD 11sys/kern/uipc_mqueue.c. Until #9284 merges, this PR's diff also shows #9284's commits. This PR's own change is the last three commits.kmq_open(path, flags, mode, const mq_attr*)kmq_timedsend(fd, msg, len, prio, abstime)EINVALforprio >= MQ_PRIO_MAX(64);EMSGSIZEforlen > mq_msgsize;EAGAINwhen full withO_NONBLOCK;EBADFwhen not open for writingkmq_timedreceive(fd, buf, len, prio*, abstime)EMSGSIZEforlen < mq_msgsize;EAGAINwhen empty withO_NONBLOCK;EBADFwhen not open for readingkmq_setattr(fd, attr, oattr)O_NONBLOCKchanges, and othermq_flagsbits giveEINVAL;oattrgets the flags,maxmsg,msgsizeandcurmsgskmq_unlink(path)ENOENTif it is absent; open descriptors keep the queuekmq_open's rules:EINVALfor(flags & O_ACCMODE) == O_ACCMODEorO_EXEC;O_CREATand an attribute,mq_maxmsgmust be 1..100 andmq_msgsize1..16384, orEINVAL; without one, the defaults are 10 and 1024;ENAMETOOLONG) and must be/namewith no second/(EINVAL); a NULL name givesEFAULT;ENOENTfor a missing name withoutO_CREAT, andEEXISTwithO_CREAT | O_EXCL.For both send and receive, as in
mqueue_sendandmqueue_receive, theabstimetv_nseccheck (EINVAL) applies only when the call has to wait. A wait ends withETIMEDOUTat the absoluteCLOCK_REALTIMEdeadline.mq_attris eight 64-bit fields.Each open queue is a descriptor reserved on the host null device, carrying its own access mode and
O_NONBLOCK, with a process-local name table. #9284's close observer drops a descriptor's entry when it is closed or replaced.kmq_notifyfollows in a separate PR. A debt line records the limits: process-local names,modeand permissions not modelled, queue descriptors not usable withselect,pollorkevent, anddupnot giving a queue.This PR conflicts textually with #9293 at adjacent stubs (
kmq_unlinkandksem_closeinExport.Discovery.cpp). It is resolved by a merge ofmainafter either lands.Tested
Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7, Release. These are CPU-side exports, so no GPU is involved.
guest_kernel_sys_mqueue(core/libs/tests/GuestKernelSysMqueue.cpp):kmq_openrule and the default attributes;EMSGSIZE, andEAGAINafterkmq_setattrsetsO_NONBLOCK;abstime, accepted when there is room or a message butEINVALwhen the call has to wait;ETIMEDOUTafter about 150 ms, and a blocked receiver woken by a send;EBADF), andkmq_unlinkwhile descriptors stay open;EBADF).kmq_open_nid_postfix not implemented. On this branch it passes, 3 of 3 runs.guest_kernel_sys_ksemandguest_kernel_sysstill pass, andtools/check_conventions.pypasses.tools/pr_overlap.pycrashes on this machine's partial clone, so it was replaced by a check against an index of every open PR's diff plusgit merge-tree. This branch merges cleanly withmainand with feat(libkernel_sys): identify the initial pthread #9160, feat(libkernel_sys): implement uuidgen #9195, feat(libkernel_sys): implement wait3 and wait4 #9162, feat(libkernel_sys): implement statfs symlinkat and futimesat #9161, feat(libkernel): implement four pthread_attr forms #9156, feat(libkernel): implement getlogin #9171, feat(libkernel): implement pselect over select #9273, feat(libkernel): implement tcgetsid #9242, feat(libkernel_sys): implement pwrite through the shared POSIX provider #9019, feat(libkernel_sys): implement fstat #9008, feat(libkernel_sys): implement sceKernelFlock over flock #9097, feat(libkernel_sys): implement the scePthread scope, atfork and setconcurrency forms #9141, feat(libkernel_sys): implement chown, lchown, fchownat and linkat #9103, feat(libkernel_sys): implement the scePthreadBarrier, cpuclockid, concurrency and msync forms #8987 and feat(libkernel): report open, read and close notes on watched files #7121. The one conflict is with feat(libkernel): implement the named ksem semaphores #9293, as described above.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 repository (attach them to this PR)