feat(libkernel_sys): implement kmq_notify registration #9302

Open
DavidSamir wants to merge 20 commits from upstream-pr/9302 into main
DavidSamir commented 2026-10-21 17:51:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by DavidSamir on 2026-10-21T17:51:27Z.


What

Builds on #9297 and implements kmq_notify registration in libkernel_sys/Mqueue.cpp, following FreeBSD 11 sys/kern/uipc_mqueue.c (kern_kmq_notify, mqueue_send_notification). Until #9297 (and #9284 under it) merges, this PR's diff also shows their commits. This PR's own change is the last three commits.

  • Validation, before the descriptor is checked: a sigev_notify other than SIGEV_NONE, SIGEV_SIGNAL or SIGEV_THREAD_ID gives EINVAL, and for the two signal forms a sigev_signo outside 1..128 gives EINVAL.
  • The descriptor: one that isn't a queue gives EBADF, for a NULL sigevent as well.
  • A NULL sigevent: removes only the calling descriptor's own registration; from another descriptor it does nothing and returns 0.
  • Registering: any existing registration on the queue gives EBUSY, even from the same descriptor.
  • When a registration is consumed:
    • at once, on registering, when the queue already holds messages and no receiver waits;
    • by a send that finds no waiting receiver;
    • by a receive that leaves messages behind with no receiver waiting.
  • Closing the owner descriptor removes its registration, through #9284's close observer.
  • Waiting receivers: the queue now counts them, so a send either wakes a waiting receiver or consumes the notification, as mqueue_send does.

SIGEV_NONE is fully implemented. SIGEV_SIGNAL and SIGEV_THREAD_ID registrations throw, because delivering a guest signal with its sigev_value is not modelled. A debt line records that.

Tested

Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7, Release. This is a CPU-side export, so no GPU is involved.

  • guest_kernel_sys_mqueue gains Notify():
    • each EINVAL kind, including EINVAL winning over a bad descriptor;
    • EBADF, and EBUSY from both descriptors of the queue;
    • consumption on registering with a non-empty queue, and consumption by a send;
    • removal by the owner only, and removal on closing the owner.
  • With #9297's code the test aborts with kmq_notify_nid_postfix not implemented. On this branch it passes, 3 of 3 runs. guest_kernel_sys_ksem still passes, and tools/check_conventions.py passes.
  • Overlap: tools/pr_overlap.py crashes on this machine's partial clone, so it was replaced by a check against an index of every open PR's diff plus git merge-tree. This branch merges cleanly with main and with #9160, #9195, #9162, #9156, #9171, #9273, #9242, #9141, #9103 and #8987.

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: #9297
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4955956460 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9302). Originally posted by [DavidSamir](https://github.com/DavidSamir) on 2026-10-21T17:51:27Z. --- ### What Builds on #9297 and implements `kmq_notify` registration in `libkernel_sys/Mqueue.cpp`, following FreeBSD 11 `sys/kern/uipc_mqueue.c` (`kern_kmq_notify`, `mqueue_send_notification`). **Until #9297 (and #9284 under it) merges, this PR's diff also shows their commits.** This PR's own change is the last three commits. - **Validation, before the descriptor is checked:** a `sigev_notify` other than `SIGEV_NONE`, `SIGEV_SIGNAL` or `SIGEV_THREAD_ID` gives `EINVAL`, and for the two signal forms a `sigev_signo` outside 1..128 gives `EINVAL`. - **The descriptor:** one that isn't a queue gives `EBADF`, for a NULL `sigevent` as well. - **A NULL `sigevent`:** removes only the calling descriptor's own registration; from another descriptor it does nothing and returns 0. - **Registering:** any existing registration on the queue gives `EBUSY`, even from the same descriptor. - **When a registration is consumed:** - at once, on registering, when the queue already holds messages and no receiver waits; - by a send that finds no waiting receiver; - by a receive that leaves messages behind with no receiver waiting. - **Closing the owner descriptor** removes its registration, through #9284's close observer. - **Waiting receivers:** the queue now counts them, so a send either wakes a waiting receiver or consumes the notification, as `mqueue_send` does. `SIGEV_NONE` is fully implemented. `SIGEV_SIGNAL` and `SIGEV_THREAD_ID` registrations throw, because delivering a guest signal with its `sigev_value` is not modelled. A debt line records that. ### Tested Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7, Release. This is a CPU-side export, so no GPU is involved. - `guest_kernel_sys_mqueue` gains `Notify()`: - each `EINVAL` kind, including `EINVAL` winning over a bad descriptor; - `EBADF`, and `EBUSY` from both descriptors of the queue; - consumption on registering with a non-empty queue, and consumption by a send; - removal by the owner only, and removal on closing the owner. - With #9297's code the test aborts with `kmq_notify_nid_postfix not implemented`. On this branch it passes, 3 of 3 runs. `guest_kernel_sys_ksem` still passes, and `tools/check_conventions.py` passes. - Overlap: `tools/pr_overlap.py` crashes on this machine's partial clone, so it was replaced by a check against an index of every open PR's diff plus `git merge-tree`. This branch merges cleanly with `main` and with #9160, #9195, #9162, #9156, #9171, #9273, #9242, #9141, #9103 and #8987. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: #9297 - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-21 17:52:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-21T17:52:12Z.


Progress report (0c6a5bd → c045c1e)

📈 System libraries: 42.21% (+0.11%, +12 implemented, -7 removed functions)

✅ 12 implemented
Library Name
libkernel ksem_destroy_nid_postfix
libkernel ksem_getvalue_nid_postfix
libkernel ksem_init_nid_postfix
libkernel ksem_post_nid_postfix
libkernel ksem_timedwait_nid_postfix
libkernel ksem_trywait_nid_postfix
libkernel ksem_wait_nid_postfix
libkernel_sys kmq_open_nid_postfix
libkernel_sys kmq_setattr_nid_postfix
libkernel_sys kmq_timedreceive_nid_postfix
libkernel_sys kmq_timedsend_nid_postfix
libkernel_sys kmq_unlink_nid_postfix
🗑️ 7 removed
Library Name
libkernel_sys ksem_destroy_nid_postfix
libkernel_sys ksem_getvalue_nid_postfix
libkernel_sys ksem_init_nid_postfix
libkernel_sys ksem_post_nid_postfix
libkernel_sys ksem_timedwait_nid_postfix
libkernel_sys ksem_trywait_nid_postfix
libkernel_sys ksem_wait_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6322761182 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9302#issuecomment-6322761182). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-21T17:52:12Z. --- <!-- progress-report --> ### Progress report (0c6a5bd → c045c1e) 📈 **System libraries**: 42.21% (+0.11%, +12 implemented, -7 removed functions) <details> <summary>✅ 12 implemented</summary> | Library | Name | | - | - | | libkernel | `ksem_destroy_nid_postfix` | | libkernel | `ksem_getvalue_nid_postfix` | | libkernel | `ksem_init_nid_postfix` | | libkernel | `ksem_post_nid_postfix` | | libkernel | `ksem_timedwait_nid_postfix` | | libkernel | `ksem_trywait_nid_postfix` | | libkernel | `ksem_wait_nid_postfix` | | libkernel_sys | `kmq_open_nid_postfix` | | libkernel_sys | `kmq_setattr_nid_postfix` | | libkernel_sys | `kmq_timedreceive_nid_postfix` | | libkernel_sys | `kmq_timedsend_nid_postfix` | | libkernel_sys | `kmq_unlink_nid_postfix` | </details> <details> <summary>🗑️ 7 removed</summary> | Library | Name | | - | - | | libkernel_sys | `ksem_destroy_nid_postfix` | | libkernel_sys | `ksem_getvalue_nid_postfix` | | libkernel_sys | `ksem_init_nid_postfix` | | libkernel_sys | `ksem_post_nid_postfix` | | libkernel_sys | `ksem_timedwait_nid_postfix` | | libkernel_sys | `ksem_trywait_nid_postfix` | | libkernel_sys | `ksem_wait_nid_postfix` | </details>
DavidSamir commented 2026-10-22 02:06:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by DavidSamir on 2026-10-22T02:06:23Z.


Linux: Ubuntu 24.04.1 LTS (WSL2), GCC 13.3.0, Release; head c045c1e91 merged onto main 8c26eac3c.

  • guest_kernel_sys_ksem and guest_kernel_sys_mqueue passes 3/3.
  • No negative control is listed in this PR's text, so none was run.

Run from the PC (Windows host, Linux in WSL2), not from the PR author's machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6330943523 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9302#issuecomment-6330943523). Originally posted by [DavidSamir](https://github.com/DavidSamir) on 2026-10-22T02:06:23Z. --- Linux: Ubuntu 24.04.1 LTS (WSL2), GCC 13.3.0, Release; head `c045c1e91` merged onto `main` `8c26eac3c`. - `guest_kernel_sys_ksem` and `guest_kernel_sys_mqueue` passes 3/3. - No negative control is listed in this PR's text, so none was run. Run from the PC (Windows host, Linux in WSL2), not from the PR author's machine.
CnRJay commented 2026-11-01 20:01:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-11-01T20:01:20Z.

Review: COMMENTED


Only SIGEV_NONE is actually implemented; the SIGEV_SIGNAL and SIGEV_THREAD_ID registrations throw, so the path a real title would use is the one that is not there.

Also, this carries #9297's and #9284's commits, so it cannot be reviewed on its own until those land.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5729961715 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9302#pullrequestreview-5729961715). Originally posted by [CnRJay](https://github.com/CnRJay) on 2026-11-01T20:01:20Z. **Review:** COMMENTED --- Only `SIGEV_NONE` is actually implemented; the `SIGEV_SIGNAL` and `SIGEV_THREAD_ID` registrations throw, so the path a real title would use is the one that is not there. Also, this carries #9297's and #9284's commits, so it cannot be reviewed on its own until those land.
MarcZX10 commented 2026-11-23 02:20:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-23T02:20:19Z.

Review: COMMENTED


Reviewed — comments

Nothing blocks this; the points below are optional.

What I ran

Reviewed head c045c1e91fe983f7e3e513692110e15b16470953 from the prepared diff and targeted source reads using repo_read.py. No build or tests were run; test results in the description are author-reported.

Results

Check Result Note
Diff and changed-file inventory passed 12 changed files listed; all included
Queue notification logic passed Registration and consumption paths inspected
Build and tests not run Reported results were not independently verified

Findings

Blocking

None.

Non-blocking

  • kmq_timedsend_nid_postfix constructs its byte vector from message and message + length before locking. For a valid zero-length send with message == nullptr, forming message + length is undefined behavior. Handle the zero-length case without pointer arithmetic. (core/libs/prx/libkernel_sys/Mqueue.cpp:230)

Not verified

  • Build, tests, and platform behavior were not run or independently confirmed. The description reports Windows 11 test runs.
  • Read: core/libs/CMakeLists.txt, core/libs/prx/libkernel/CMakeLists.txt, core/libs/prx/libkernel/Equeue/Equeue.cpp, core/libs/prx/libkernel/File/src/Stdio.cpp, core/libs/prx/libkernel/Semaphore/include/Ksem.hpp, core/libs/prx/libkernel/Semaphore/src/Ksem.cpp, core/libs/prx/libkernel_sys/CMakeLists.txt, core/libs/prx/libkernel_sys/Export.Discovery.cpp, core/libs/prx/libkernel_sys/Mqueue.cpp, core/libs/tests/GuestKernelSysKsem.cpp, core/libs/tests/GuestKernelSysMqueue.cpp, docs/dev/debt/libkernel.md, and docs/dev/debt/libkernel_sys.md (changed hunks and relevant source ranges only). No changed paths were excluded by manifest.json.

To get this to a good state

Nothing is required. The zero-length send edge case is optional feedback.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6015884187 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9302#pullrequestreview-6015884187). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-23T02:20:19Z. **Review:** COMMENTED --- # Reviewed — comments Nothing blocks this; the points below are optional. ## What I ran Reviewed head `c045c1e91fe983f7e3e513692110e15b16470953` from the prepared diff and targeted source reads using `repo_read.py`. No build or tests were run; test results in the description are author-reported. ## Results | Check | Result | Note | |---|---|---| | Diff and changed-file inventory | passed | 12 changed files listed; all included | | Queue notification logic | passed | Registration and consumption paths inspected | | Build and tests | not run | Reported results were not independently verified | ## Findings ### Blocking None. ### Non-blocking - `kmq_timedsend_nid_postfix` constructs its byte vector from `message` and `message + length` before locking. For a valid zero-length send with `message == nullptr`, forming `message + length` is undefined behavior. Handle the zero-length case without pointer arithmetic. (`core/libs/prx/libkernel_sys/Mqueue.cpp:230`) ## Not verified - Build, tests, and platform behavior were not run or independently confirmed. The description reports Windows 11 test runs. - Read: `core/libs/CMakeLists.txt`, `core/libs/prx/libkernel/CMakeLists.txt`, `core/libs/prx/libkernel/Equeue/Equeue.cpp`, `core/libs/prx/libkernel/File/src/Stdio.cpp`, `core/libs/prx/libkernel/Semaphore/include/Ksem.hpp`, `core/libs/prx/libkernel/Semaphore/src/Ksem.cpp`, `core/libs/prx/libkernel_sys/CMakeLists.txt`, `core/libs/prx/libkernel_sys/Export.Discovery.cpp`, `core/libs/prx/libkernel_sys/Mqueue.cpp`, `core/libs/tests/GuestKernelSysKsem.cpp`, `core/libs/tests/GuestKernelSysMqueue.cpp`, `docs/dev/debt/libkernel.md`, and `docs/dev/debt/libkernel_sys.md` (changed hunks and relevant source ranges only). No changed paths were excluded by `manifest.json`. ## To get this to a good state Nothing is required. The zero-length send edge case is optional feedback.
ligmaSec commented 2026-12-03 20:26:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T20:26:23Z.

Review: COMMENTED


kmq_notify retains the Open returned by Find, then locks the queue and publishes the numeric descriptor. Descriptor close can erase that Open and finish clearing the notifier between those steps. The queue can then retain a notification for a closed descriptor. Could registration recheck the descriptor identity under the same synchronization as close before publishing it? FreeBSD holds the descriptor table lock through that recheck and acquisition of the queue lock. FreeBSD registration code

Source review at c045c1e91f. The trial merge conflicts in kernel CMake, equeue and stdio.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6177876070 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9302#pullrequestreview-6177876070). Originally posted by [ligmaSec](https://github.com/ligmaSec) on 2026-12-03T20:26:23Z. **Review:** COMMENTED --- `kmq_notify` retains the `Open` returned by `Find`, then locks the queue and publishes the numeric descriptor. Descriptor close can erase that `Open` and finish clearing the notifier between those steps. The queue can then retain a notification for a closed descriptor. Could registration recheck the descriptor identity under the same synchronization as close before publishing it? FreeBSD holds the descriptor table lock through that recheck and acquisition of the queue lock. [FreeBSD registration code](https://github.com/freebsd/freebsd-src/blob/releng/11.0/sys/kern/uipc_mqueue.c#L2204-L2235) Source review at `c045c1e91f`. The trial merge conflicts in kernel CMake, equeue and stdio. AI-assisted: yes.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/9302:upstream-pr/9302'
git switch 'upstream-pr/9302'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/9302'
git switch 'upstream-pr/9302'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/9302'
git switch 'upstream-pr/9302'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/9302'
git switch 'main'
git merge --squash 'upstream-pr/9302'
git switch 'main'
git merge --ff-only 'upstream-pr/9302'
git switch 'main'
git merge 'upstream-pr/9302'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!9302
No description provided.