feat(libkernel_sys): implement POSIX message queues #9297
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9297"
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 DavidSamir on 2026-10-21T17:45:25Z.
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 #9160, #9195, #9162, #9161, #9156, #9171, #9273, #9242, #9019, #9008, #9097, #9141, #9103, #8987 and #7121. The one conflict is with #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)Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-21T17:46:19Z.
Progress report (
0c6a5bd→d07deaa)📈 System libraries: 42.21% (+0.11%, +12 implemented, -7 removed functions)
✅ 12 implemented
ksem_destroy_nid_postfixksem_getvalue_nid_postfixksem_init_nid_postfixksem_post_nid_postfixksem_timedwait_nid_postfixksem_trywait_nid_postfixksem_wait_nid_postfixkmq_open_nid_postfixkmq_setattr_nid_postfixkmq_timedreceive_nid_postfixkmq_timedsend_nid_postfixkmq_unlink_nid_postfix🗑️ 7 removed
ksem_destroy_nid_postfixksem_getvalue_nid_postfixksem_init_nid_postfixksem_post_nid_postfixksem_timedwait_nid_postfixksem_trywait_nid_postfixksem_wait_nid_postfixImported from boykopovar/AnyPS5. Originally posted by DavidSamir on 2026-10-22T02:06:22Z.
Linux: Ubuntu 24.04.1 LTS (WSL2), GCC 13.3.0, Release; head
d07deaa18merged ontomain8c26eac3c.guest_kernel_sys_ksemandguest_kernel_sys_mqueuepasses 3/3.Run from the PC (Windows host, Linux in WSL2), not from the PR author's machine.
Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-24T15:32:47Z.
Review: COMMENTED
Checked against main
b607bfdc8band FreeBSD 11.4.0sys/kern/uipc_mqueue.c(kern_kmq_open,kern_kmq_setattr,mqueue_send/_mqueue_send,mqueue_receive/_mqueue_recv,sys_kmq_unlink); I reviewed only the mqueue commits:tv_nseccheck only when the call has to wait.kmq_timedreceive(Mqueue.cpp:233) copies intobufferwithout checking it. After a send,kmq_timedreceive(fd, NULL, 1024, NULL, NULL)writes through a null pointer, where FreeBSD'smqueue_savemsgcopyout returnsEFAULT.kmq_timedsendalready returnsEFAULTfor NULL at :209; could receive do the same?Deadline(:126-128) turnstv_secinto int64 nanoseconds, so atv_secabove about 9.2e9 (e.g.{INT64_MAX, 0}used as "forever") is signed overflow. I couldn't run this; reading it suggests the deadline could wrap and time out at once, where FreeBSD subtracts the current time and clamps intvtohz. Could the conversion saturate?mqueue_allocreturnsENFILEonce 100 queues exist (kern.mqueue.maxmq). Here there's no limit, so it may be worth adding to the debt line.git merge-treeshows a conflict inlibkernel_sys/Export.Discovery.cpp, where main addedktimer_*stubs next to theksem_*ones. It's from the stacked #9293 part, but it will need resolving.Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.
Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-11-01T20:01:19Z.
Review: COMMENTED
Correction (2026-11-01): this review's claim that maintainers close PRs without a title ID is wrong. CONTRIBUTING allows
Unblocks: none; a title is only required when the PR fixes a title. The technical points below are unaffected.Two points.
No title evidence. The template says
Unblocks: noneand the body names no title ID and no log line showing a title reaching akmq_*export on main. Export-only PRs without that tend to be closed, so a title ID plus the log line (queue at 700+ or the import being resolved) is needed here.kmq_timedreceive_nid_postfixdoes not checkbuffer.kmq_timedsend_nid_postfixreturnsEFAULTfor a nullmessagewith a non-zero length, but the receive side only checkslength < msgsizeand then doesstd::memcpy(buffer, entry.bytes.data(), entry.bytes.size())after the message has already been dequeued. A nullbuffercrashes the host instead of failing the call, and the message is lost. The pointer should be validated before the message is removed fromqueue.messages.The unsynchronised
Open::nonblockingwrite inkmq_setattr_nid_postfixthat oneandonlydean raised is still there in this head as far as I can see:open->nonblocking = ...is assigned outsidequeue.lockwhileWaitForreads it under it.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-23T02:21:15Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
Changes are required before merge: validate
kmq_timedreceiveoutput pointers before removing a message from the queue.What I ran
Reviewed head
d07deaa187134d4e2482a5f48aeea9f1f5601ab3using the prepared diff andrepo_read.pyat the pinned head. No commands or tests were run by me; reported test results below are from the PR description.Results
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.
Pull request closed