fix(libkernel): fcntl F_GETOWN and F_SETOWN store and return the owner of a pipe #18457

Merged
xXPBSXx merged 7 commits from upstream-pr/18457 into main 2026-11-24 21:39:20 +00:00
xXPBSXx commented 2026-11-11 15:55:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-11-11T15:55:17Z.


What

fcntl threw for F_GETOWN and F_SETOWN on every descriptor. On a PS5 the read end of a fresh pipe answers F_GETOWN with 0, takes F_SETOWN with the caller's own pid, returns that pid from F_GETOWN, and takes F_SETOWN with 0 (cases 2.1 to 2.4, lines 12 to 15 of the raw output). This does the same on a pipe: the owner is stored with the descriptor's other shared state, F_GETOWN returns it, and no signal is sent. Every other kind of descriptor still throws, since only a pipe was measured. The test now pins 0, a set value and 0 again, and the entry in docs/dev/debt/libkernel.md states the measurement in place of "throw".

The console was given its own pid, while the test sets 4242; what the console does with another pid, an invalid pid or a negative process group was not measured. Only the read end of the pipe was measured, and whether a duplicated descriptor shares the owner is not pinned by the test. No title is shown to call either command: of the 22 titles that import fcntl, no direct call site shows 5 or 6 as the command (a static scan of the executables, not a run; calls through a function pointer or with a computed command are not covered). A title process was not measured.

Tested

Measured on a PS5 with firmware 11.60 (kernel_get_fw_version 0x11600005), from a homebrew payload process (ps5-payload-sdk v0.45, elfldr), on 2026-11-11 at 13:31 UTC. A title process may differ. The cases are 2.1 to 2.4, lines 12 to 15 of the raw output in the first comment; the calls were made through sceKernelFcntl on the read end of a pipe.

Call PS5, payload process, firmware 11.60 AnyPS5 main before here
F_GETOWN on a fresh pipe 0 (line 12) throws 0
F_SETOWN with the caller's pid 0 (line 13) throws 0
F_GETOWN after that the pid that was set (line 14) throws the value that was set
F_SETOWN with 0 0 (line 15) throws 0
F_GETOWN or F_SETOWN on any other descriptor not measured throws throws

On main 58493333d4c1, Linux (WSL, Release), built for the targets guest_kernel_fcntl and guest_kernel_fcntl_sync with ninja returning 0 for each commit: with only the test commit guest_kernel_fcntl aborts (1 of 2 targets fails), and with the fix and with the documentation commit both pass in 3 of 3 runs each. tools/check_conventions.py passes with no error on each of the three commits, with one debt-length warning on the last: the changed entry is 4385 characters, up from 4199, and it was already far over the limit. The probe source and its raw output are in the first comment. Not tested: Windows, macOS, the CI runner, a title process, any other firmware, a duplicated descriptor, the write end of a pipe, a pid other than the caller's, and any descriptor other than a pipe.

Overlap: 124 open pull requests change at least one of core/libs/prx/libkernel/File/src/DescriptorControl.cpp, core/libs/tests/GuestKernelFcntl.cpp and docs/dev/debt/libkernel.md. I merged this head and each of them with main (5a6eb85be835) on 2026-11-11 at 15:13 UTC: 73 merge cleanly with main and with this head, 51 already conflict with main without this pull request, and none conflicts only with this head.

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 (documentation only)
  • AI-assisted: yes

AI-assisted (Claude Code).

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5262547988 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18457). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-11-11T15:55:17Z. --- ### What `fcntl` threw for `F_GETOWN` and `F_SETOWN` on every descriptor. On a PS5 the read end of a fresh pipe answers `F_GETOWN` with 0, takes `F_SETOWN` with the caller's own pid, returns that pid from `F_GETOWN`, and takes `F_SETOWN` with 0 (cases 2.1 to 2.4, lines 12 to 15 of the raw output). This does the same on a pipe: the owner is stored with the descriptor's other shared state, `F_GETOWN` returns it, and no signal is sent. Every other kind of descriptor still throws, since only a pipe was measured. The test now pins 0, a set value and 0 again, and the entry in `docs/dev/debt/libkernel.md` states the measurement in place of "throw". The console was given its own pid, while the test sets 4242; what the console does with another pid, an invalid pid or a negative process group was not measured. Only the read end of the pipe was measured, and whether a duplicated descriptor shares the owner is not pinned by the test. No title is shown to call either command: of the 22 titles that import `fcntl`, no direct call site shows 5 or 6 as the command (a static scan of the executables, not a run; calls through a function pointer or with a computed command are not covered). A title process was not measured. ### Tested Measured on a PS5 with firmware 11.60 (`kernel_get_fw_version` 0x11600005), from a homebrew payload process (ps5-payload-sdk v0.45, elfldr), on 2026-11-11 at 13:31 UTC. A title process may differ. The cases are 2.1 to 2.4, lines 12 to 15 of the raw output in the first comment; the calls were made through `sceKernelFcntl` on the read end of a pipe. | Call | PS5, payload process, firmware 11.60 | AnyPS5 `main` before | here | |---|---|---|---| | `F_GETOWN` on a fresh pipe | 0 (line 12) | throws | 0 | | `F_SETOWN` with the caller's pid | 0 (line 13) | throws | 0 | | `F_GETOWN` after that | the pid that was set (line 14) | throws | the value that was set | | `F_SETOWN` with 0 | 0 (line 15) | throws | 0 | | `F_GETOWN` or `F_SETOWN` on any other descriptor | not measured | throws | throws | On `main` `58493333d4c1`, Linux (WSL, Release), built for the targets `guest_kernel_fcntl` and `guest_kernel_fcntl_sync` with `ninja` returning 0 for each commit: with only the test commit `guest_kernel_fcntl` aborts (1 of 2 targets fails), and with the fix and with the documentation commit both pass in 3 of 3 runs each. `tools/check_conventions.py` passes with no error on each of the three commits, with one `debt-length` warning on the last: the changed entry is 4385 characters, up from 4199, and it was already far over the limit. The probe source and its raw output are in the first comment. Not tested: Windows, macOS, the CI runner, a title process, any other firmware, a duplicated descriptor, the write end of a pipe, a pid other than the caller's, and any descriptor other than a pipe. Overlap: 124 open pull requests change at least one of `core/libs/prx/libkernel/File/src/DescriptorControl.cpp`, `core/libs/tests/GuestKernelFcntl.cpp` and `docs/dev/debt/libkernel.md`. I merged this head and each of them with `main` (`5a6eb85be835`) on 2026-11-11 at 15:13 UTC: 73 merge cleanly with `main` and with this head, 51 already conflict with `main` without this pull request, and none conflicts only with this head. ### 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 <!-- #PR, or none --> - [x] Fixes: none <!-- issue it closes as Fixes #N, or none --> - [x] Unblocks: none <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> - [x] GPUs tested: n/a (documentation only) <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> - [x] AI-assisted: yes <!-- yes / no --> AI-assisted (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
PrivacyOnion commented 2026-11-11 15:57:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-11T15:57:27Z.

Review: CHANGES_REQUESTED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 58689dcb61:

  • Conventions: tools/check_conventions.py passed; git diff --check clean.
  • Build: guest_kernel_fcntl_tests built cleanly.
  • CTest (guest_kernel_fcntl, guest_kernel_fcntl_sync):
    1/2 Test #4541: guest_kernel_fcntl_sync ..........***Not Run   0.00 sec
    2/2 Test #4539: guest_kernel_fcntl ...............   Passed    0.02 sec
    50% tests passed, 1 tests failed out of 2
    
    The following tests FAILED:
    
  • Minor: please drop the Generated with footer from the description; the AI-assisted checkbox can stay.

Requesting changes for the points above.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5861565798 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18457#pullrequestreview-5861565798). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-11T15:57:27Z. **Review:** CHANGES_REQUESTED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `58689dcb61`: - **Conventions**: `tools/check_conventions.py` passed; `git diff --check` clean. - **Build**: `guest_kernel_fcntl_tests` built cleanly. - **CTest** (`guest_kernel_fcntl`, `guest_kernel_fcntl_sync`): ``` 1/2 Test #4541: guest_kernel_fcntl_sync ..........***Not Run 0.00 sec 2/2 Test #4539: guest_kernel_fcntl ............... Passed 0.02 sec 50% tests passed, 1 tests failed out of 2 ``` ``` The following tests FAILED: ``` - Minor: please drop the `Generated with` footer from the description; the AI-assisted checkbox can stay. Requesting changes for the points above.
PrivacyOnion commented 2026-11-11 18:38:36 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-11T18:38:36Z.

Review: CHANGES_REQUESTED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 58689dcb61:

  • Conventions: tools/check_conventions.py passed; git diff --check clean.
  • Build: guest_kernel_fcntl_tests built cleanly.
  • CTest (guest_kernel_fcntl, guest_kernel_fcntl_sync):
    1/2 Test #4541: guest_kernel_fcntl_sync ..........   Passed    0.04 sec
    2/2 Test #4539: guest_kernel_fcntl ...............   Passed    0.06 sec
    100% tests passed, 0 tests failed out of 2
    
  • Negative control: with core/libs/prx/libkernel/File/src/DescriptorControl.cpp reverted to main and the new tests kept, the suite fails:
    1/2 Test #4541: guest_kernel_fcntl_sync ..........   Passed    0.05 sec
    2/2 Test #4539: guest_kernel_fcntl ...............Subprocess aborted***Exception:   0.35 sec
    50% tests passed, 1 tests failed out of 2
    
    Restoring the change makes it pass again.
  • Code reading:
    • Verified in core/libs/prx/libkernel/File/src/DescriptorControl.cpp:543-544 that invalid and negative descriptors properly fail with GuestEbadf (EBADF, 9) via Classify returning std::nullopt.
    • Verified in core/libs/prx/libkernel/File/src/DescriptorControl.cpp:545 that descriptors whose Kind is not Kind::Pipe call Unsupported and throw std::runtime_error, matching the technical debt documented in docs/dev/debt/libkernel.md.
    • Verified concurrency synchronization in core/libs/prx/libkernel/File/src/DescriptorControl.cpp:546, ensuring g_mutex is locked across Materialize(fd) and owner dereference/mutation.
    • Verified 64-bit to 32-bit integer conversion on LP64 and LLP64 platforms in core/libs/prx/libkernel/File/src/DescriptorControl.cpp:549, confirming static_cast(argument) stores 32-bit pid_t and process group values without platform-specific truncation mismatches.
    • Verified AGENTS.md repository compliance across all modified files, confirming zero comments were introduced in core/libs/prx/libkernel/File/src/DescriptorControl.cpp and core/libs/tests/GuestKernelFcntl.cpp.
    • Verified in core/libs/tests/GuestKernelFcntl.cpp:599-613 that PipeOwnerRoundTrips exercises F_GETOWN (5) and F_SETOWN (6) on a pipe descriptor and cleanly closes both ends.
  • Concerns:
    • core/libs/prx/libkernel/File/src/DescriptorControl.cpp:546: Entry::owner is default-initialized to nullptr in struct Entry (line 121) and only instantiated on demand in Fcntl. When a pipe descriptor is duplicated via dup, dup2, F_DUPFD, or F_DUP2FD before F_SETOWN or F_GETOWN is called on the source descriptor, ShareDescriptor copies a nullptr into the duplicate's Entry. Subsequent execution of fcntl(pipe[0], SetOwnerCommand, 4242) allocates a std::shared_ptr solely for pipe[0], leaving the duplicated descriptor's owner as nullptr; a subsequent fcntl(dup_fd, GetOwnerCommand) returns 0 instead of 4242 and allocates a distinct, unshared std::shared_ptr. Conversely, if F_SETOWN or F_GETOWN is executed before duplication, the shared_ptr is copied and the descriptors share ownership. The ownership state of duplicated descriptors therefore inconsistently decouples depending strictly on call ordering.
  • Minor: please drop the Generated with footer from the description; the AI-assisted checkbox can stay.

Requesting changes for the points above.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5863728300 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18457#pullrequestreview-5863728300). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-11T18:38:36Z. **Review:** CHANGES_REQUESTED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `58689dcb61`: - **Conventions**: `tools/check_conventions.py` passed; `git diff --check` clean. - **Build**: `guest_kernel_fcntl_tests` built cleanly. - **CTest** (`guest_kernel_fcntl`, `guest_kernel_fcntl_sync`): ``` 1/2 Test #4541: guest_kernel_fcntl_sync .......... Passed 0.04 sec 2/2 Test #4539: guest_kernel_fcntl ............... Passed 0.06 sec 100% tests passed, 0 tests failed out of 2 ``` - **Negative control**: with `core/libs/prx/libkernel/File/src/DescriptorControl.cpp` reverted to `main` and the new tests kept, the suite fails: ``` 1/2 Test #4541: guest_kernel_fcntl_sync .......... Passed 0.05 sec 2/2 Test #4539: guest_kernel_fcntl ...............Subprocess aborted***Exception: 0.35 sec 50% tests passed, 1 tests failed out of 2 ``` Restoring the change makes it pass again. - **Code reading**: - Verified in core/libs/prx/libkernel/File/src/DescriptorControl.cpp:543-544 that invalid and negative descriptors properly fail with GuestEbadf (EBADF, 9) via Classify returning std::nullopt. - Verified in core/libs/prx/libkernel/File/src/DescriptorControl.cpp:545 that descriptors whose Kind is not Kind::Pipe call Unsupported and throw std::runtime_error, matching the technical debt documented in docs/dev/debt/libkernel.md. - Verified concurrency synchronization in core/libs/prx/libkernel/File/src/DescriptorControl.cpp:546, ensuring g_mutex is locked across Materialize(fd) and owner dereference/mutation. - Verified 64-bit to 32-bit integer conversion on LP64 and LLP64 platforms in core/libs/prx/libkernel/File/src/DescriptorControl.cpp:549, confirming static_cast<int>(argument) stores 32-bit pid_t and process group values without platform-specific truncation mismatches. - Verified AGENTS.md repository compliance across all modified files, confirming zero comments were introduced in core/libs/prx/libkernel/File/src/DescriptorControl.cpp and core/libs/tests/GuestKernelFcntl.cpp. - Verified in core/libs/tests/GuestKernelFcntl.cpp:599-613 that PipeOwnerRoundTrips exercises F_GETOWN (5) and F_SETOWN (6) on a pipe descriptor and cleanly closes both ends. - **Concerns**: - core/libs/prx/libkernel/File/src/DescriptorControl.cpp:546: Entry::owner is default-initialized to nullptr in struct Entry (line 121) and only instantiated on demand in Fcntl. When a pipe descriptor is duplicated via dup, dup2, F_DUPFD, or F_DUP2FD before F_SETOWN or F_GETOWN is called on the source descriptor, ShareDescriptor copies a nullptr into the duplicate's Entry. Subsequent execution of fcntl(pipe[0], SetOwnerCommand, 4242) allocates a std::shared_ptr<int> solely for pipe[0], leaving the duplicated descriptor's owner as nullptr; a subsequent fcntl(dup_fd, GetOwnerCommand) returns 0 instead of 4242 and allocates a distinct, unshared std::shared_ptr<int>. Conversely, if F_SETOWN or F_GETOWN is executed before duplication, the shared_ptr is copied and the descriptors share ownership. The ownership state of duplicated descriptors therefore inconsistently decouples depending strictly on call ordering. - Minor: please drop the `Generated with` footer from the description; the AI-assisted checkbox can stay. Requesting changes for the points above.
MarcZX10 commented 2026-11-12 14:26:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-12T14:26:34Z.

Review: CHANGES_REQUESTED


Reviewed — changes requested

One blocking defect: F_SETOWN on a pipe is not shared with a descriptor made by dup when the owner was set after the dup, so F_GETOWN on the copy can return 0 where the original returns the pid.

What I ran

  • Head 58689dcb617519056cc71424128daa41ada97d33, base main. Read the run folder (description.md, commits.md, manifest.json, files.json, diff.patch) and the house sections "Readable reviews", "Standard PR response format" and "Accuracy and evidence".
  • Repository reads through the reader, at head:
repo_read.py search "Classify" core/libs/prx/libkernel/File/src/DescriptorControl.cpp
repo_read.py search "Materialize" core/libs/prx/libkernel/File/src/DescriptorControl.cpp
repo_read.py search "DuplicateFrom" core/libs/prx/libkernel/File/src/DescriptorControl.cpp
repo_read.py search "make_shared" core/libs/prx/libkernel/File/src/DescriptorControl.cpp
repo_read.py search "ShareDescriptor" core/libs/prx/libkernel/File/src/DescriptorControl.cpp
repo_read.py search "ShareDescriptor" core/libs/prx/libkernel
repo_read.py search "Entry{" core/libs/prx/libkernel/File/src/DescriptorControl.cpp
repo_read.py search "pipe_nid_postfix" core/libs/tests/GuestKernelFcntl.cpp
repo_read.py cat core/libs/prx/libkernel/File/src/DescriptorControl.cpp 115 135
repo_read.py cat core/libs/prx/libkernel/File/src/DescriptorControl.cpp 136 175
repo_read.py cat core/libs/prx/libkernel/File/src/DescriptorControl.cpp 180 190
repo_read.py cat core/libs/prx/libkernel/File/src/DescriptorControl.cpp 296 335
repo_read.py cat core/libs/prx/libkernel/File/src/DescriptorControl.cpp 380 390
repo_read.py cat core/libs/prx/libkernel/File/src/DescriptorControl.cpp 520 560
repo_read.py cat core/libs/prx/libkernel/File/src/DescriptorControl.cpp 618 640
  • Not built and no tests run in this review.

Results

Check Result Note
Build and guest_kernel_fcntl tests not run author-reported only
F_GETOWN/F_SETOWN on a pipe, read passed stores and returns the owner
Owner shared across dup failed depends on call order (see Findings)
Comments in code passed none added in the diff

Findings

Blocking

  • core/libs/prx/libkernel/File/src/DescriptorControl.cpp:548: the owner is created lazily, on the first F_GETOWN or F_SETOWN (if (!owner) owner = std::make_shared<int>(0);). The status pointer is created with every entry (the initializer at line 611, and InitialEntry at lines 187 and 344). ShareDescriptor (lines 626 to 628) copies the whole Entry, so the copy shares the owner only if it already existed. Failing sequence: pipe(p), d = dup(p[0]), fcntl(p[0], F_SETOWN, 100), then fcntl(d, F_GETOWN) returns 0 where the original returns 100. This was read from the code, not run. The description says the owner is "stored with the descriptor's other shared state", and the status flags are shared by dup as in an open file description, so the owner should match.

Non-blocking

  • core/libs/tests/GuestKernelFcntl.cpp:602: PipeOwnerRoundTrips covers one descriptor only. It has no case for a duplicate, with the owner set before and after dup, and no case that F_GETOWN on a non-pipe still throws. The first case would have caught the blocking finding.
  • docs/dev/debt/libkernel.md:358: the entry does not say whether a duplicate shares the owner. Once the finding is fixed, the entry should say so.

Sources

Not verified

  • Builds and the test runs on Linux, Windows and the CI runner: author-reported, not repeated here.
  • The PS5 measurements (firmware 11.60, cases 2.1 to 2.4): the raw output is in the first PR comment, which is not in the diff.
  • The overlap counts (124 open pull requests; 73 and 51) and the debt-length warning: not checked.
  • The Windows branch of Classify (FILE_TYPE_PIPE) for F_SETOWN: read, not run.
  • The F_DUPFD path (DuplicateFrom): the owner sharing there was not read in full.
  • Files read: DescriptorControl.cpp at head in the ranges above, plus the diff. GuestKernelFcntl.cpp only through the diff and one reader search. docs/dev/debt/libkernel.md only through the diff. All three files in files.json were reviewed; none was read in full.

To get this to a good state

  • Create the owner with each entry, as the status pointer is, so every duplicate shares it. Set it in the initializer at line 611 and in InitialEntry at lines 187 and 344.
  • Add a test: set the owner on one end, dup it, set it on the original, and read it back through the copy. Add a check that F_GETOWN on a non-pipe still throws.
  • Rerun guest_kernel_fcntl and guest_kernel_fcntl_sync on the new head.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5876104987 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18457#pullrequestreview-5876104987). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-12T14:26:34Z. **Review:** CHANGES_REQUESTED --- # Reviewed — changes requested One blocking defect: F_SETOWN on a pipe is not shared with a descriptor made by `dup` when the owner was set after the `dup`, so F_GETOWN on the copy can return 0 where the original returns the pid. ## What I ran - Head `58689dcb617519056cc71424128daa41ada97d33`, base `main`. Read the run folder (`description.md`, `commits.md`, `manifest.json`, `files.json`, `diff.patch`) and the house sections "Readable reviews", "Standard PR response format" and "Accuracy and evidence". - Repository reads through the reader, at head: ``` repo_read.py search "Classify" core/libs/prx/libkernel/File/src/DescriptorControl.cpp repo_read.py search "Materialize" core/libs/prx/libkernel/File/src/DescriptorControl.cpp repo_read.py search "DuplicateFrom" core/libs/prx/libkernel/File/src/DescriptorControl.cpp repo_read.py search "make_shared" core/libs/prx/libkernel/File/src/DescriptorControl.cpp repo_read.py search "ShareDescriptor" core/libs/prx/libkernel/File/src/DescriptorControl.cpp repo_read.py search "ShareDescriptor" core/libs/prx/libkernel repo_read.py search "Entry{" core/libs/prx/libkernel/File/src/DescriptorControl.cpp repo_read.py search "pipe_nid_postfix" core/libs/tests/GuestKernelFcntl.cpp repo_read.py cat core/libs/prx/libkernel/File/src/DescriptorControl.cpp 115 135 repo_read.py cat core/libs/prx/libkernel/File/src/DescriptorControl.cpp 136 175 repo_read.py cat core/libs/prx/libkernel/File/src/DescriptorControl.cpp 180 190 repo_read.py cat core/libs/prx/libkernel/File/src/DescriptorControl.cpp 296 335 repo_read.py cat core/libs/prx/libkernel/File/src/DescriptorControl.cpp 380 390 repo_read.py cat core/libs/prx/libkernel/File/src/DescriptorControl.cpp 520 560 repo_read.py cat core/libs/prx/libkernel/File/src/DescriptorControl.cpp 618 640 ``` - Not built and no tests run in this review. ## Results | Check | Result | Note | |---|---|---| | Build and `guest_kernel_fcntl` tests | not run | author-reported only | | F_GETOWN/F_SETOWN on a pipe, read | passed | stores and returns the owner | | Owner shared across `dup` | failed | depends on call order (see Findings) | | Comments in code | passed | none added in the diff | ## Findings ### Blocking - `core/libs/prx/libkernel/File/src/DescriptorControl.cpp:548`: the owner is created lazily, on the first F_GETOWN or F_SETOWN (`if (!owner) owner = std::make_shared<int>(0);`). The status pointer is created with every entry (the initializer at line 611, and `InitialEntry` at lines 187 and 344). `ShareDescriptor` (lines 626 to 628) copies the whole `Entry`, so the copy shares the owner only if it already existed. Failing sequence: `pipe(p)`, `d = dup(p[0])`, `fcntl(p[0], F_SETOWN, 100)`, then `fcntl(d, F_GETOWN)` returns 0 where the original returns 100. This was read from the code, not run. The description says the owner is "stored with the descriptor's other shared state", and the status flags are shared by `dup` as in an open file description, so the owner should match. ### Non-blocking - `core/libs/tests/GuestKernelFcntl.cpp:602`: `PipeOwnerRoundTrips` covers one descriptor only. It has no case for a duplicate, with the owner set before and after `dup`, and no case that F_GETOWN on a non-pipe still throws. The first case would have caught the blocking finding. - `docs/dev/debt/libkernel.md:358`: the entry does not say whether a duplicate shares the owner. Once the finding is fixed, the entry should say so. ## Sources - [`DescriptorControl.cpp` at head, lines 545 to 551](https://github.com/boykopovar/AnyPS5/blob/58689dcb617519056cc71424128daa41ada97d33/core/libs/prx/libkernel/File/src/DescriptorControl.cpp#L545-L551) - [`DescriptorControl.cpp` at head, lines 623 to 628 (`ShareDescriptor`)](https://github.com/boykopovar/AnyPS5/blob/58689dcb617519056cc71424128daa41ada97d33/core/libs/prx/libkernel/File/src/DescriptorControl.cpp#L623-L628) - [`Stdio.cpp` at head, line 1048 (caller of `ShareDescriptor`)](https://github.com/boykopovar/AnyPS5/blob/58689dcb617519056cc71424128daa41ada97d33/core/libs/prx/libkernel/File/src/Stdio.cpp#L1048) ## Not verified - Builds and the test runs on Linux, Windows and the CI runner: author-reported, not repeated here. - The PS5 measurements (firmware 11.60, cases 2.1 to 2.4): the raw output is in the first PR comment, which is not in the diff. - The overlap counts (124 open pull requests; 73 and 51) and the `debt-length` warning: not checked. - The Windows branch of `Classify` (`FILE_TYPE_PIPE`) for F_SETOWN: read, not run. - The `F_DUPFD` path (`DuplicateFrom`): the owner sharing there was not read in full. - Files read: `DescriptorControl.cpp` at head in the ranges above, plus the diff. `GuestKernelFcntl.cpp` only through the diff and one reader search. `docs/dev/debt/libkernel.md` only through the diff. All three files in `files.json` were reviewed; none was read in full. ## To get this to a good state - Create the owner with each entry, as the status pointer is, so every duplicate shares it. Set it in the initializer at line 611 and in `InitialEntry` at lines 187 and 344. - Add a test: set the owner on one end, `dup` it, set it on the original, and read it back through the copy. Add a check that F_GETOWN on a non-pipe still throws. - Rerun `guest_kernel_fcntl` and `guest_kernel_fcntl_sync` on the new head.
PrivacyOnion commented 2026-11-21 03:03:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-21T03:03:15Z.

Review: APPROVED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against a764e24c98:

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_kernel_fcntl_tests built cleanly.
  • CTest (guest_kernel_fcntl):
    1/1 Test #5979: guest_kernel_fcntl ...............   Passed    0.02 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libkernel/File/src/DescriptorControl.cpp reverted to main and the new tests kept, the suite fails:
    1/1 Test #5979: guest_kernel_fcntl ...............Subprocess aborted***Exception:   0.52 sec
    0% tests passed, 1 tests failed out of 1
    
    Restoring the change makes it pass again.
  • Code reading:
    • Verified in core/libs/prx/libkernel/File/src/DescriptorControl.cpp:549-550 that Classify returning nullopt (e.g. invalid or negative fd) returns GuestEbadf (EBADF, 9).
    • Verified in core/libs/prx/libkernel/File/src/DescriptorControl.cpp:551 that descriptors not classified as Kind::Pipe call Unsupported() and throw std::runtime_error.
    • Verified thread safety in core/libs/prx/libkernel/File/src/DescriptorControl.cpp:552-557 where g_mutex is acquired before accessing Materialize(fd).owner and updating or reading the shared state.
    • Verified LP64 and LLP64 integer type safety with argument casting from std::intptr_t to int for storing owner PID.
    • Verified docs/dev/debt/changes/fix-kernel-fcntl-pipe-owner.md fragment format and AGENTS.md rule compliance.
    • Verified core/libs/tests/GuestKernelFcntl.cpp:PipeOwnerRoundTrips accurately tests default 0, custom PID round-trip, and resetting to 0.

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6002441428 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18457#pullrequestreview-6002441428). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-21T03:03:15Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `a764e24c98`: - **Conventions**: `tools/check_conventions.py` passed. - **Build**: `guest_kernel_fcntl_tests` built cleanly. - **CTest** (`guest_kernel_fcntl`): ``` 1/1 Test #5979: guest_kernel_fcntl ............... Passed 0.02 sec 100% tests passed, 0 tests failed out of 1 ``` - **Negative control**: with `core/libs/prx/libkernel/File/src/DescriptorControl.cpp` reverted to `main` and the new tests kept, the suite fails: ``` 1/1 Test #5979: guest_kernel_fcntl ...............Subprocess aborted***Exception: 0.52 sec 0% tests passed, 1 tests failed out of 1 ``` Restoring the change makes it pass again. - **Code reading**: - Verified in core/libs/prx/libkernel/File/src/DescriptorControl.cpp:549-550 that Classify returning nullopt (e.g. invalid or negative fd) returns GuestEbadf (EBADF, 9). - Verified in core/libs/prx/libkernel/File/src/DescriptorControl.cpp:551 that descriptors not classified as Kind::Pipe call Unsupported() and throw std::runtime_error. - Verified thread safety in core/libs/prx/libkernel/File/src/DescriptorControl.cpp:552-557 where g_mutex is acquired before accessing Materialize(fd).owner and updating or reading the shared state. - Verified LP64 and LLP64 integer type safety with argument casting from std::intptr_t to int for storing owner PID. - Verified docs/dev/debt/changes/fix-kernel-fcntl-pipe-owner.md fragment format and AGENTS.md rule compliance. - Verified core/libs/tests/GuestKernelFcntl.cpp:PipeOwnerRoundTrips accurately tests default 0, custom PID round-trip, and resetting to 0. Looks Good To Me
MarcZX10 commented 2026-11-21 03:15:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T03:15:58Z.

Review: APPROVED


Reviewed — looks good

The reviewed change implements the reported pipe owner round trip and the available diff and changed files contain no verified blocking defect.

What I ran

Reviewed head a764e24c983980431e72a4eb71801e4a0fd7c64c using repo_read.py to inspect the prepared description, commits, manifest and diff, plus all three changed files and the relevant Materialize, descriptor-sharing and fcntl dispatch code. No commands or tests were run. The PR description reports Linux/WSL Release build and test results; these were not run as part of this review.

Results

Check Result Note
Diff and changed files passed All three changed files read
Reported tests not run Author-reported results only
Runtime behavior not run Console measurement reported by author

Findings

Blocking

None.

Non-blocking

None.

Not verified

No commands or tests were run. The console measurement, title-process behavior, other firmware, write-end behavior, duplicated-descriptor behavior, non-caller and invalid PIDs, and behavior on non-pipe descriptors were not independently verified. The three changed files listed in the manifest were read; no files were excluded by the manifest.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6002497764 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18457#pullrequestreview-6002497764). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-21T03:15:58Z. **Review:** APPROVED --- # Reviewed — looks good The reviewed change implements the reported pipe owner round trip and the available diff and changed files contain no verified blocking defect. ## What I ran Reviewed head `a764e24c983980431e72a4eb71801e4a0fd7c64c` using `repo_read.py` to inspect the prepared description, commits, manifest and diff, plus all three changed files and the relevant `Materialize`, descriptor-sharing and fcntl dispatch code. No commands or tests were run. The PR description reports Linux/WSL Release build and test results; these were not run as part of this review. ## Results | Check | Result | Note | |---|---|---| | Diff and changed files | passed | All three changed files read | | Reported tests | not run | Author-reported results only | | Runtime behavior | not run | Console measurement reported by author | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified No commands or tests were run. The console measurement, title-process behavior, other firmware, write-end behavior, duplicated-descriptor behavior, non-caller and invalid PIDs, and behavior on non-pipe descriptors were not independently verified. The three changed files listed in the manifest were read; no files were excluded by the manifest. ## To get this to a good state Nothing is required.
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!18457
No description provided.