Skip to content

feat(libkernel_sys): implement POSIX message queues - #94

Open
Thimo188 wants to merge 14 commits into
mainfrom
upstream-pr/9297
Open

Thimo188 wants to merge 14 commits into
mainfrom
upstream-pr/9297

Conversation

@Thimo188

@Thimo188 Thimo188 commented Dec 2, 2026

Copy link
Copy Markdown
Owner

Imported from boykopovar/AnyPS5#9297, originally opened by DavidSamir.

Source commit: d07deaa187134d4e2482a5f48aeea9f1f5601ab3. The import branch preserves this fetched upstream PR snapshot. The description and validation below are copied from upstream; no new code changes or test runs were made for this import. Original reviews, discussions, and attachments remain at the linked upstream PR.


What

Builds on boykopovar#9284 and implements POSIX message queues in a new libkernel_sys/Mqueue.cpp, following FreeBSD 11 sys/kern/uipc_mqueue.c. Until boykopovar#9284 merges, this PR's diff also shows boykopovar#9284's commits. This PR's own change is the last three commits.

Export Behaviour
kmq_open(path, flags, mode, const mq_attr*) see the rules below
kmq_timedsend(fd, msg, len, prio, abstime) EINVAL for prio >= MQ_PRIO_MAX (64); EMSGSIZE for len > mq_msgsize; EAGAIN when full with O_NONBLOCK; EBADF when not open for writing
kmq_timedreceive(fd, buf, len, prio*, abstime) the highest priority first, first in first out within a priority; returns the message length; EMSGSIZE for len < mq_msgsize; EAGAIN when empty with O_NONBLOCK; EBADF when not open for reading
kmq_setattr(fd, attr, oattr) only this descriptor's O_NONBLOCK changes, and other mq_flags bits give EINVAL; oattr gets the flags, maxmsg, msgsize and curmsgs
kmq_unlink(path) removes the name, ENOENT if it is absent; open descriptors keep the queue

kmq_open's rules:

  • EINVAL for (flags & O_ACCMODE) == O_ACCMODE or O_EXEC;
  • with O_CREAT and an attribute, mq_maxmsg must be 1..100 and mq_msgsize 1..16384, or EINVAL; without one, the defaults are 10 and 1024;
  • the name is copied with a 256-byte limit (ENAMETOOLONG) and must be /name with no second / (EINVAL); a NULL name gives EFAULT;
  • ENOENT for a missing name without O_CREAT, and EEXIST with O_CREAT | O_EXCL.

For both send and receive, as in mqueue_send and mqueue_receive, the abstime tv_nsec check (EINVAL) applies only when the call has to wait. A wait ends with ETIMEDOUT at the absolute CLOCK_REALTIME deadline. mq_attr is 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. boykopovar#9284's close observer drops a descriptor's entry when it is closed or replaced. kmq_notify follows in a separate PR. A debt line records the limits: process-local names, mode and permissions not modelled, queue descriptors not usable with select, poll or kevent, and dup not giving a queue.

This PR conflicts textually with boykopovar#9293 at adjacent stubs (kmq_unlink and ksem_close in Export.Discovery.cpp). It is resolved by a merge of main after either lands.

Tested

Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7, Release. These are CPU-side exports, so no GPU is involved.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: feat(libkernel): implement the unnamed ksem semaphores boykopovar/AnyPS5#9284
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

…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.
@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown

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.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 93 core/libs/prx/libkernel/Semaphore/include/Ksem.hpp
core/libs/prx/libkernel/Semaphore/src/Ksem.cpp
core/libs/tests/GuestKernelSysKsem.cpp
PR 95 core/libs/prx/libkernel/Semaphore/include/Ksem.hpp
core/libs/prx/libkernel/Semaphore/src/Ksem.cpp
core/libs/prx/libkernel_sys/Mqueue.cpp
core/libs/tests/GuestKernelSysKsem.cpp
core/libs/tests/GuestKernelSysMqueue.cpp

Exports with a name or library/NID already present in main:

  • ksem_destroy (same library/NID already present: core/libs/prx/libkernel (asSKL30+heA))
  • ksem_getvalue (same library/NID already present: core/libs/prx/libkernel (rOT0UMvtCCA))
  • ksem_init (same library/NID already present: core/libs/prx/libkernel (TEwqtzAmezo))
  • ksem_post (same library/NID already present: core/libs/prx/libkernel (s8gWJrY1W-k))
  • ksem_timedwait (same library/NID already present: core/libs/prx/libkernel (vE+WlomLSh4))
  • ksem_trywait (same library/NID already present: core/libs/prx/libkernel (gVaofuRvLdU))
  • ksem_wait (same library/NID already present: core/libs/prx/libkernel (rQvMIxmFD6A))

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Dec 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs rebase Conflicts with main, rebase needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants