feat(libkernel): implement sem_setname #11267

Merged
kallmek3nny merged 1 commit from upstream-pr/11267 into main 2026-10-29 10:31:35 +00:00
kallmek3nny commented 2026-10-25 23:07:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by kallmek3nny on 2026-10-25T23:07:54Z.


What

Implements sem_setname(sem, name) in libkernel and removes its NotImplemented_nid_no_patch stub and declaration from libkernel_sys. The call copies name into a new PosixSemaphore::name under the semaphore's lock and returns 0. A null or destroyed semaphore returns -1 with EINVAL in errno, as the other sem_* calls do. A null name throws, because the console's result was not measured. FreeBSD has no sem_setname, so the signature follows the libthr *_setname_np calls and is not confirmed on a console or a title. This is recorded in docs/dev/debt/libkernel.md. Nothing reads the name back yet.

Tested

Tested on Windows with an Intel Core i5-14400F. On current main I rebuilt libkernel, libkernel_sys, guest_posix_sem_tests and guest_kernel_sys_tests. Then I ran ctest --test-dir build -R "^guest_kernel_sys$|^guest_posix_sem", and all 3 tests passed: guest_kernel_sys, guest_posix_sem_init and guest_posix_sem_post. The extended semaphore test covers renaming, an empty name, a null name, a null semaphore and a destroyed semaphore. It also checks that renaming keeps the count and leaves the semaphore usable. Not tested on Linux or with a title.

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: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5009620901 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11267). Originally posted by [kallmek3nny](https://github.com/kallmek3nny) on 2026-10-25T23:07:54Z. --- ### What Implements `sem_setname(sem, name)` in libkernel and removes its `NotImplemented_nid_no_patch` stub and declaration from libkernel_sys. The call copies `name` into a new `PosixSemaphore::name` under the semaphore's lock and returns 0. A null or destroyed semaphore returns -1 with `EINVAL` in `errno`, as the other `sem_*` calls do. A null `name` throws, because the console's result was not measured. FreeBSD has no `sem_setname`, so the signature follows the libthr `*_setname_np` calls and is not confirmed on a console or a title. This is recorded in `docs/dev/debt/libkernel.md`. Nothing reads the name back yet. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Tested on Windows with an Intel Core i5-14400F. On current `main` I rebuilt `libkernel`, `libkernel_sys`, `guest_posix_sem_tests` and `guest_kernel_sys_tests`. Then I ran `ctest --test-dir build -R "^guest_kernel_sys$|^guest_posix_sem"`, and all 3 tests passed: `guest_kernel_sys`, `guest_posix_sem_init` and `guest_posix_sem_post`. The extended semaphore test covers renaming, an empty name, a null `name`, a null semaphore and a destroyed semaphore. It also checks that renaming keeps the count and leaves the semaphore usable. Not tested on Linux or with a title. ### 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: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-10-25 23:13:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T23:13:04Z.

Review: CHANGES_REQUESTED


The exact-head diff-check and conventions checker pass. I found two points that need clarification before I can approve:

  1. This moves sem_setname_nid_postfix from libkernel_sys (where the existing export stub is registered) into libkernel, while changing the prototype from parameterless to (void* sem, const char* name). The PR says the signature has not been confirmed on a console or title. Since imports are resolved against a particular PRX/library, a correct implementation under a different library name would not satisfy existing imports, and a guessed arity can mis-handle the call. Please provide evidence for the PS5 library ownership and prototype (for example, the import/export metadata or a checked SDK declaration), or preserve the existing module mapping until verified.

  2. The Tested section says the tests were rebuilt on current main, but the extended GuestPosixSem test calls sem_setname, which this PR adds and current main does not declare. Please clarify the exact commit that was built and tested and provide the focused test output. The hosted product-build jobs are skipped, so that evidence is not available from CI.

I have not found a duplicate implementation. The progress/conventions/intake checks pass, but these ABI and test-evidence gaps prevent a confident review of the exported behavior.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5645827839 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11267#pullrequestreview-5645827839). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-25T23:13:04Z. **Review:** CHANGES_REQUESTED --- The exact-head diff-check and conventions checker pass. I found two points that need clarification before I can approve: 1. This moves `sem_setname_nid_postfix` from `libkernel_sys` (where the existing export stub is registered) into `libkernel`, while changing the prototype from parameterless to `(void* sem, const char* name)`. The PR says the signature has not been confirmed on a console or title. Since imports are resolved against a particular PRX/library, a correct implementation under a different library name would not satisfy existing imports, and a guessed arity can mis-handle the call. Please provide evidence for the PS5 library ownership and prototype (for example, the import/export metadata or a checked SDK declaration), or preserve the existing module mapping until verified. 2. The Tested section says the tests were rebuilt on current `main`, but the extended `GuestPosixSem` test calls `sem_setname`, which this PR adds and current `main` does not declare. Please clarify the exact commit that was built and tested and provide the focused test output. The hosted product-build jobs are skipped, so that evidence is not available from CI. I have not found a duplicate implementation. The progress/conventions/intake checks pass, but these ABI and test-evidence gaps prevent a confident review of the exported behavior.
adriadam10 commented 2026-10-27 07:36:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-27T07:36:40Z.

Review: CHANGES_REQUESTED


Thanks for the PR. @BunnyFl's firmware 13.42 data answers the ABI question and shows the behaviour differs from this implementation:

  • Library and prototype: sem_setname (NID -wUggz2S5yk) is exported by libkernel, and takes (sem, const char* name). Moving the export and the signature are right.
  • Second call: after sem_init the module's first dword is 0xffff736d; sem_setname calls namedobj_create(name, sem, 0x206) and stores (id << 16) | 0x736d there. A second sem_setname on the same semaphore returns -1 with errno 35 (EAGAIN) and makes no syscall. Sem.cpp:186-193 returns 0 and renames, and GuestPosixSem.cpp:121-122 pins that ("semaphore" then "" both succeed). The semaphore should be nameable once; later calls should fail with EAGAIN, with a test for it.
  • Null semaphore: the module faults reading sem+2, it does not return EINVAL. Please throw for a null sem (and keep throwing for a null name, which the module passes to the kernel unchecked), and drop the null-semaphore EINVAL row at GuestPosixSem.cpp:133. A destroyed semaphore was not measured: keep it throwing or note it in the debt entry.
  • docs/dev/debt/libkernel.md: update the sem_setname line to say the name is registered once through namedobj_create, that the kernel side is not modelled here, and cite BunnyFl's measurements instead of "not confirmed".
  • Merge order: pairwise merges with #11236 (docs/dev/debt/libkernel.md) and #10838 (libkernel_sys/include/Api.hpp) conflict; list them on the Depends on line or rebase after they land.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5663612553 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11267#pullrequestreview-5663612553). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-27T07:36:40Z. **Review:** CHANGES_REQUESTED --- Thanks for the PR. @BunnyFl's firmware 13.42 data answers the ABI question and shows the behaviour differs from this implementation: - Library and prototype: `sem_setname` (NID `-wUggz2S5yk`) is exported by `libkernel`, and takes `(sem, const char* name)`. Moving the export and the signature are right. - Second call: after `sem_init` the module's first dword is `0xffff736d`; `sem_setname` calls `namedobj_create(name, sem, 0x206)` and stores `(id << 16) | 0x736d` there. A second `sem_setname` on the same semaphore returns -1 with `errno` 35 (`EAGAIN`) and makes no syscall. `Sem.cpp:186-193` returns 0 and renames, and `GuestPosixSem.cpp:121-122` pins that (`"semaphore"` then `""` both succeed). The semaphore should be nameable once; later calls should fail with `EAGAIN`, with a test for it. - Null semaphore: the module faults reading `sem+2`, it does not return `EINVAL`. Please throw for a null `sem` (and keep throwing for a null `name`, which the module passes to the kernel unchecked), and drop the null-semaphore `EINVAL` row at `GuestPosixSem.cpp:133`. A destroyed semaphore was not measured: keep it throwing or note it in the debt entry. - `docs/dev/debt/libkernel.md`: update the `sem_setname` line to say the name is registered once through `namedobj_create`, that the kernel side is not modelled here, and cite BunnyFl's measurements instead of "not confirmed". - Merge order: pairwise merges with #11236 (`docs/dev/debt/libkernel.md`) and #10838 (`libkernel_sys/include/Api.hpp`) conflict; list them on the `Depends on` line or rebase after they land.
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!11267
No description provided.