feat(libkernel): answer tcgetpgrp and tcsetpgrp on a pipe with its SIGIO owner #9566

Open
DavidSamir wants to merge 9 commits from upstream-pr/9566 into main
DavidSamir commented 2026-10-22 02:31:51 +00:00 (Migrated from github.com)

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


What

Builds on #9557. Until #9557 merges, this PR's diff also shows its commit. This PR's own change is the last commit.

tcgetpgrp and tcsetpgrp threw on a host pipe or FIFO above descriptor 2, because the pipe's SIGIO owner was not modelled. #9557 now keeps that owner, so they follow FreeBSD 11:

  • The libc side: tcsetpgrp is _ioctl(fd, TIOCSPGRP, &pgrp) and tcgetpgrp is _ioctl(fd, TIOCGPGRP, &s) (lib/libc/gen/termios.c:82-99).
  • The pipe side: pipe_ioctl answers TIOCSPGRP with fsetown(-pgrp) and TIOCGPGRP with -fgetown() (sys/kern/sys_pipe.c:1402-1410). So these use the same owner as F_SETOWN/FIOSETOWN, with the sign reversed: after F_SETOWN(pid), tcgetpgrp returns -pid.

How:

  • Terminal.cpp: on a host pipe or FIFO at descriptor 3 or above, tcgetpgrp and tcsetpgrp call File::PipeProcessGroup and File::SetPipeProcessGroup instead of throwing. The same fsetown rules apply: 0 clears, our own process group is stored, and any other group gives ESRCH. Descriptors 0 to 2 keep their documented ENOTTY, since they're taken as non-terminals that aren't pipes.
  • DescriptorControl.cpp: the two helpers. The raw TIOCSPGRP (0x80047476) and TIOCGPGRP (0x40047477) ioctls now give the same answer on such a pipe, ahead of the terminal-group ENOTTY.
  • The debt line for the terminal functions (docs/dev/debt/libkernel.md:128) replaces its "throw on a host pipe" clause.

Tested

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

guest_terminal (core/libs/tests/GuestTerminal.cpp): in the pipe loop, the two checks that expected a throw now check:

  • a group of 0 at first, then setting and getting our group;
  • ESRCH for another group, with the owner kept;
  • F_SETOWN(pid) making tcgetpgrp return -pid, and the reverse;
  • the TIOCSPGRP/TIOCGPGRP ioctls;
  • clearing with 0.

Results:

  • guest_terminal and guest_kernel_fcntl_owner pass, 3 of 3 runs. guest_kernel_fcntl and guest_dup pass.
  • Negative controls:
    • with the pipe branch disabled, the test fails at line 120;
    • without the sign reversal between group and owner, it fails at line 121.
  • tools/check_conventions.py: 0 errors. It warns that the terminal debt entry (now 1047 characters, from 1131 on main) and the fcntl entry are long; both were already over 1000 on main.
  • Overlap: tools/pr_overlap.py --branch plus git merge-tree. The code merges cleanly with #9131, #7121, #8520, #9019 and #9561. Textual conflicts:
    • #9242 (tcgetsid, also ours) adds tcgetsid checks right after the two GuestTerminal.cpp lines this PR has to change, and edits the same debt entry. Agreed with its author on the board: no dependency either way; whichever lands second keeps both blocks of checks and both debt changes.
    • #8641 and #9491 edit the terminal debt entry (libkernel.md:127-129). #9491's author (EagleBearerYS) agreed on this PR that neither waits: whichever merges second keeps both entries.
    • The fcntl debt line (:218) comes from #9557 and is shared with #8544, #9256, #9109 and #9561.

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: #9557 (orders with #9242 and #9491 agreed: no dependency, see Overlap)
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4961207776 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9566). Originally posted by [DavidSamir](https://github.com/DavidSamir) on 2026-10-22T02:31:51Z. --- ### What Builds on #9557. **Until #9557 merges, this PR's diff also shows its commit.** This PR's own change is the last commit. `tcgetpgrp` and `tcsetpgrp` threw on a host pipe or FIFO above descriptor 2, because the pipe's SIGIO owner was not modelled. #9557 now keeps that owner, so they follow FreeBSD 11: - **The libc side:** `tcsetpgrp` is `_ioctl(fd, TIOCSPGRP, &pgrp)` and `tcgetpgrp` is `_ioctl(fd, TIOCGPGRP, &s)` (`lib/libc/gen/termios.c:82-99`). - **The pipe side:** `pipe_ioctl` answers `TIOCSPGRP` with `fsetown(-pgrp)` and `TIOCGPGRP` with `-fgetown()` (`sys/kern/sys_pipe.c:1402-1410`). So these use the same owner as `F_SETOWN`/`FIOSETOWN`, with the sign reversed: after `F_SETOWN(pid)`, `tcgetpgrp` returns `-pid`. How: - **`Terminal.cpp`:** on a host pipe or FIFO at descriptor 3 or above, `tcgetpgrp` and `tcsetpgrp` call `File::PipeProcessGroup` and `File::SetPipeProcessGroup` instead of throwing. The same `fsetown` rules apply: 0 clears, our own process group is stored, and any other group gives `ESRCH`. Descriptors 0 to 2 keep their documented `ENOTTY`, since they're taken as non-terminals that aren't pipes. - **`DescriptorControl.cpp`:** the two helpers. The raw `TIOCSPGRP` (`0x80047476`) and `TIOCGPGRP` (`0x40047477`) ioctls now give the same answer on such a pipe, ahead of the terminal-group `ENOTTY`. - **The debt line** for the terminal functions (`docs/dev/debt/libkernel.md:128`) replaces its "throw on a host pipe" clause. ### Tested Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7, Release. This is CPU-side, so no GPU is involved. `guest_terminal` (`core/libs/tests/GuestTerminal.cpp`): in the pipe loop, the two checks that expected a throw now check: - a group of 0 at first, then setting and getting our group; - `ESRCH` for another group, with the owner kept; - `F_SETOWN(pid)` making `tcgetpgrp` return `-pid`, and the reverse; - the `TIOCSPGRP`/`TIOCGPGRP` ioctls; - clearing with 0. Results: - `guest_terminal` and `guest_kernel_fcntl_owner` pass, 3 of 3 runs. `guest_kernel_fcntl` and `guest_dup` pass. - Negative controls: - with the pipe branch disabled, the test fails at line 120; - without the sign reversal between group and owner, it fails at line 121. - `tools/check_conventions.py`: 0 errors. It warns that the terminal debt entry (now 1047 characters, from 1131 on `main`) and the `fcntl` entry are long; both were already over 1000 on `main`. - Overlap: `tools/pr_overlap.py --branch` plus `git merge-tree`. The code merges cleanly with #9131, #7121, #8520, #9019 and #9561. Textual conflicts: - #9242 (`tcgetsid`, also ours) adds `tcgetsid` checks right after the two `GuestTerminal.cpp` lines this PR has to change, and edits the same debt entry. Agreed with its author on the board: no dependency either way; whichever lands second keeps both blocks of checks and both debt changes. - #8641 and #9491 edit the terminal debt entry (`libkernel.md:127-129`). #9491's author (EagleBearerYS) agreed on this PR that neither waits: whichever merges second keeps both entries. - The `fcntl` debt line (`:218`) comes from #9557 and is shared with #8544, #9256, #9109 and #9561. ### 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: #9557 (orders with #9242 and #9491 agreed: no dependency, see Overlap) - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
jotitadev commented 2026-10-22 03:39:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-22T03:39:04Z.

Review: COMMENTED


First run on Linux (the PR is tested on Windows only). Ubuntu 26.04, x86_64, Intel i7-8700, GCC 15.2.0, Release, BUILD_TESTING=ON, head e846772a9 merged --no-commit onto current origin/main (6ef5a1c4c).

  • Build: ok.
  • ctest -R "guest_kernel_fcntl_owner|guest_terminal" with the PR: both pass.
  • Negative control (revert DescriptorControl.cpp/.hpp and Terminal.cpp to origin/main, keep the tests): both abort with the real assert
terminate called after throwing an instance of 'std::runtime_error'
  what():  fcntl: F_GETOWN on a pipe is not implemented, fd=6
  • Restoring the PR implementation: both pass again.

So the pipe SIGIO-owner path (F_GETOWN/F_SETOWN, FIO[GS]ETOWN, TIOC[GS]PGRP) is exercised on Linux and the tests genuinely fail without it.

Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5608980951 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9566#pullrequestreview-5608980951). Originally posted by [jotitadev](https://github.com/jotitadev) on 2026-10-22T03:39:04Z. **Review:** COMMENTED --- First run on Linux (the PR is tested on Windows only). Ubuntu 26.04, x86_64, Intel i7-8700, GCC 15.2.0, Release, `BUILD_TESTING=ON`, head e846772a9 merged `--no-commit` onto current `origin/main` (6ef5a1c4c). - Build: ok. - `ctest -R "guest_kernel_fcntl_owner|guest_terminal"` with the PR: both pass. - Negative control (revert `DescriptorControl.cpp`/`.hpp` and `Terminal.cpp` to `origin/main`, keep the tests): both abort with the real assert ``` terminate called after throwing an instance of 'std::runtime_error' what(): fcntl: F_GETOWN on a pipe is not implemented, fd=6 ``` - Restoring the PR implementation: both pass again. So the pipe SIGIO-owner path (`F_GETOWN`/`F_SETOWN`, `FIO[GS]ETOWN`, `TIOC[GS]PGRP`) is exercised on Linux and the tests genuinely fail without it. Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
MarcZX10 commented 2026-10-22 04:00:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T04:00:05Z.

Review: CHANGES_REQUESTED


The pipe SIGIO owner path is covered by focused owner/terminal tests, including the group/owner sign reversal, and the reported Linux negative-control run exercises the implementation. The declared #9557 prerequisite is correct. Hosted conventions, eligibility, intake, labels and report checks pass; product and relinker jobs are skipped. I did not run tests locally.

I cannot complete the overlap requirement yet. The PR description identifies a direct GuestTerminal.cpp overlap with #9242 and says whichever lands second should rebase, but it does not record agreement with #9242’s author or an agreed order. Please coordinate with that author; if either change must land first, state the order and add the corresponding Depends on entry. Preserve both sets of tests through the merge. The other overlap rows you list should likewise have an explicit agreed integration order wherever the actual changed lines conflict.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5609095276 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9566#pullrequestreview-5609095276). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-22T04:00:05Z. **Review:** CHANGES_REQUESTED --- The pipe SIGIO owner path is covered by focused owner/terminal tests, including the group/owner sign reversal, and the reported Linux negative-control run exercises the implementation. The declared #9557 prerequisite is correct. Hosted conventions, eligibility, intake, labels and report checks pass; product and relinker jobs are skipped. I did not run tests locally. I cannot complete the overlap requirement yet. The PR description identifies a direct `GuestTerminal.cpp` overlap with #9242 and says whichever lands second should rebase, but it does not record agreement with #9242’s author or an agreed order. Please coordinate with that author; if either change must land first, state the order and add the corresponding `Depends on` entry. Preserve both sets of tests through the merge. The other overlap rows you list should likewise have an explicit agreed integration order wherever the actual changed lines conflict.
MarcZX10 commented 2026-10-22 04:00:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T04:00:06Z.


The PR description identifies the GuestTerminal.cpp overlap with #9242 but does not record an agreed order with its author. Please coordinate before merge; if one must land first, state the order and add the matching Depends on entry. Keep both test additions through the rebase. The declared #9557 prerequisite is appropriate.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6332347082 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9566#issuecomment-6332347082). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-22T04:00:06Z. --- The PR description identifies the `GuestTerminal.cpp` overlap with #9242 but does not record an agreed order with its author. Please coordinate before merge; if one must land first, state the order and add the matching `Depends on` entry. Keep both test additions through the rebase. The declared #9557 prerequisite is appropriate.
harisibrar1 commented 2026-10-22 06:01:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-22T06:01:35Z.

Review: COMMENTED


Checked against main 4a17c7175, #9557's head c37556087 (this PR's parent commit), and FreeBSD releng/11.4 (sys/kern/sys_pipe.c:1401-1410, lib/libc/gen/termios.c):

  • The sign reversal between owner and group matches pipe_ioctl, and tcgetpgrp/tcsetpgrp reuse the #9557 rules. Nothing here duplicates #9557; it just needs to land after it.
  • The ioctl, _ioctl debt entry (docs/dev/debt/libkernel.md:220) still says every group-t termios request fails with ENOTTY. With this PR, TIOCSPGRP and TIOCGPGRP on a pipe above fd 2 now succeed (DescriptorControl.cpp:601-609). Could that entry mention the exception?
  • Nit: -group in SetPipeProcessGroup and -*static_cast<const int*>(argument) (:602) overflow for INT_MIN. The result happens to be ESRCH, as on FreeBSD, but it depends on undefined behaviour. An explicit INT_MIN → ESRCH check would make it well-defined.

Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5609874155 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9566#pullrequestreview-5609874155). Originally posted by [harisibrar1](https://github.com/harisibrar1) on 2026-10-22T06:01:35Z. **Review:** COMMENTED --- Checked against main 4a17c7175, #9557's head c37556087 (this PR's parent commit), and FreeBSD releng/11.4 (`sys/kern/sys_pipe.c:1401-1410`, `lib/libc/gen/termios.c`): - The sign reversal between owner and group matches `pipe_ioctl`, and `tcgetpgrp`/`tcsetpgrp` reuse the #9557 rules. Nothing here duplicates #9557; it just needs to land after it. - The `ioctl, _ioctl` debt entry (`docs/dev/debt/libkernel.md:220`) still says every group-`t` termios request fails with `ENOTTY`. With this PR, `TIOCSPGRP` and `TIOCGPGRP` on a pipe above fd 2 now succeed (`DescriptorControl.cpp:601-609`). Could that entry mention the exception? - Nit: `-group` in `SetPipeProcessGroup` and `-*static_cast<const int*>(argument)` (`:602`) overflow for `INT_MIN`. The result happens to be `ESRCH`, as on FreeBSD, but it depends on undefined behaviour. An explicit `INT_MIN` → `ESRCH` check would make it well-defined. Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.
EagleBearerYS commented 2026-10-22 06:07:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-22T06:07:35Z.


@DavidSamir a merge-order note: #9491 adds a sceKernelWaitSema/sceKernelSignalSema entry to docs/dev/debt/libkernel.md right before the tcsendbreak … tcsetpgrp entry this PR changes, and the two conflict in that file only. Their code doesn't meet. Neither needs to wait for the other: if this PR merges first, #9491 rebases and keeps your entry, and if #9491 merges first, I can put the resolved file on a branch of my fork for you to take.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6334016836 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9566#issuecomment-6334016836). Originally posted by [EagleBearerYS](https://github.com/EagleBearerYS) on 2026-10-22T06:07:35Z. --- @DavidSamir a merge-order note: #9491 adds a `sceKernelWaitSema`/`sceKernelSignalSema` entry to `docs/dev/debt/libkernel.md` right before the `tcsendbreak … tcsetpgrp` entry this PR changes, and the two conflict in that file only. Their code doesn't meet. Neither needs to wait for the other: if this PR merges first, #9491 rebases and keeps your entry, and if #9491 merges first, I can put the resolved file on a branch of my fork for you to take.
DavidSamir commented 2026-10-22 08:04:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by DavidSamir on 2026-10-22T08:04:24Z.


Thanks @MarcZX10 and @harisibrar1. New commits, no force-push:

  • Merge of #9557's updated head: brings in its checked FIOSETOWN/FIONBIO copy-in.
  • ecd4a973f9:
    • tcsetpgrp and TIOCSPGRP go through one setter that fails INT_MIN with ESRCH before negating, so the result no longer depends on undefined behaviour. As @harisibrar1 said, the old code already gave ESRCH on this compiler, so the new GuestTerminal case (tcsetpgrp(end, INT_MIN) fails with ESRCH and keeps the group) passes either way. A negative control can't tell them apart here; it guards the UB.
    • TIOCSPGRP now copies its argument in with the same checked read as FIOSETOWN. GuestTerminal checks that an unreadable pointer (0x10) gives EFAULT and leaves the owner unchanged.
    • The ioctl, _ioctl debt line now names the exception: TIOCSPGRP and TIOCGPGRP on a pipe above descriptor 2 set and read the pipe's SIGIO group, as pipe_ioctl does.
  • ecd4a973f9: merges current main.

Re-run on the merge (Windows 11, WinLibs GCC 15.2): guest_terminal, guest_kernel_fcntl, guest_kernel_fcntl_owner and guest_append_writes pass, and check_conventions.py reports 0 errors. Its 3 warnings are debt entries already over 1000 characters on main.

On the overlaps: #9242 is ours as well (the same fork), so we'll order the two GuestTerminal.cpp changes between us and record it. @EagleBearerYS, thanks for the #9491 note. Either order works as you describe, and whichever lands second keeps both entries.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6335874459 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9566#issuecomment-6335874459). Originally posted by [DavidSamir](https://github.com/DavidSamir) on 2026-10-22T08:04:24Z. --- Thanks @MarcZX10 and @harisibrar1. New commits, no force-push: - **Merge of #9557's updated head:** brings in its checked `FIOSETOWN`/`FIONBIO` copy-in. - **`ecd4a973f9`:** - `tcsetpgrp` and `TIOCSPGRP` go through one setter that fails `INT_MIN` with `ESRCH` before negating, so the result no longer depends on undefined behaviour. As @harisibrar1 said, the old code already gave `ESRCH` on this compiler, so the new `GuestTerminal` case (`tcsetpgrp(end, INT_MIN)` fails with `ESRCH` and keeps the group) passes either way. A negative control can't tell them apart here; it guards the UB. - `TIOCSPGRP` now copies its argument in with the same checked read as `FIOSETOWN`. `GuestTerminal` checks that an unreadable pointer (`0x10`) gives `EFAULT` and leaves the owner unchanged. - The `ioctl, _ioctl` debt line now names the exception: `TIOCSPGRP` and `TIOCGPGRP` on a pipe above descriptor 2 set and read the pipe's `SIGIO` group, as `pipe_ioctl` does. - **`ecd4a973f9`:** merges current `main`. Re-run on the merge (Windows 11, WinLibs GCC 15.2): `guest_terminal`, `guest_kernel_fcntl`, `guest_kernel_fcntl_owner` and `guest_append_writes` pass, and `check_conventions.py` reports 0 errors. Its 3 warnings are debt entries already over 1000 characters on `main`. On the overlaps: #9242 is ours as well (the same fork), so we'll order the two `GuestTerminal.cpp` changes between us and record it. @EagleBearerYS, thanks for the #9491 note. Either order works as you describe, and whichever lands second keeps both entries. AI-assisted: yes
jotitadev commented 2026-10-22 09:01:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-22T09:01:39Z.

Review: COMMENTED


Re-ran on Linux at ecd4a973f (follow-up to my earlier run at e846772a9). The new ReadGuestInt uses the process_vm_readv branch here, which the Windows run doesn't exercise.

Ubuntu 26.04, x86_64, i7-8700, GCC 15.2.0, Release, head merged --no-commit onto origin/main 7e2ba73e4.

  • ctest -R "guest_kernel_fcntl|guest_terminal": 3/3 pass.
  • Control: DescriptorControl.cpp from e846772a9, tests from ecd4a973f: guest_terminal and guest_kernel_fcntl_owner both die with SIGSEGV (the new 0x10 argument cases dereferenced directly). With the head's file both pass, so process_vm_readv returns EFAULT cleanly for the unreadable pointer.
  • ASan+UBSan build (-fsanitize=address,undefined -fno-sanitize-recover=undefined, -O1): with the head, both tests pass with no reports. With the e846772a9 DescriptorControl.cpp, guest_terminal stops at the new INT_MIN case with:
DescriptorControl.cpp:464:25: runtime error: negation of -2147483648 cannot be represented in type 'int'

So the INT_MIN check in SetProcessGroup removes a real UB that UBSan flags on this path.

Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5611705070 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9566#pullrequestreview-5611705070). Originally posted by [jotitadev](https://github.com/jotitadev) on 2026-10-22T09:01:39Z. **Review:** COMMENTED --- Re-ran on Linux at ecd4a973f (follow-up to my earlier run at e846772a9). The new `ReadGuestInt` uses the `process_vm_readv` branch here, which the Windows run doesn't exercise. Ubuntu 26.04, x86_64, i7-8700, GCC 15.2.0, Release, head merged `--no-commit` onto `origin/main` 7e2ba73e4. - `ctest -R "guest_kernel_fcntl|guest_terminal"`: 3/3 pass. - Control: `DescriptorControl.cpp` from e846772a9, tests from ecd4a973f: `guest_terminal` and `guest_kernel_fcntl_owner` both die with SIGSEGV (the new `0x10` argument cases dereferenced directly). With the head's file both pass, so `process_vm_readv` returns `EFAULT` cleanly for the unreadable pointer. - ASan+UBSan build (`-fsanitize=address,undefined -fno-sanitize-recover=undefined`, `-O1`): with the head, both tests pass with no reports. With the e846772a9 `DescriptorControl.cpp`, `guest_terminal` stops at the new `INT_MIN` case with: ``` DescriptorControl.cpp:464:25: runtime error: negation of -2147483648 cannot be represented in type 'int' ``` So the `INT_MIN` check in `SetProcessGroup` removes a real UB that UBSan flags on this path. Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
DavidSamir commented 2026-10-22 09:05:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by DavidSamir on 2026-10-22T09:05:26Z.


@MarcZX10 the integration order is now recorded in the description:

  • #9242 is ours (same fork); its author agreed that neither waits, and whichever lands second keeps both GuestTerminal.cpp blocks. #9242's description says the same.
  • @EagleBearerYS agreed the same for #9491 above.

The prerequisite stays #9557.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6336994162 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9566#issuecomment-6336994162). Originally posted by [DavidSamir](https://github.com/DavidSamir) on 2026-10-22T09:05:26Z. --- @MarcZX10 the integration order is now recorded in the description: - #9242 is ours (same fork); its author agreed that neither waits, and whichever lands second keeps both `GuestTerminal.cpp` blocks. #9242's description says the same. - @EagleBearerYS agreed the same for #9491 above. The prerequisite stays #9557. AI-assisted: yes
DavidSamir commented 2026-10-22 09:20:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by DavidSamir on 2026-10-22T09:20:41Z.


@jotitadev thank you, especially for the UBSan run. It shows the INT_MIN negation was real undefined behaviour (negation of -2147483648 cannot be represented in type 'int'), not just a theoretical one, and that the new check removes it. I had written that no negative control could show this; yours does.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6337296392 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9566#issuecomment-6337296392). Originally posted by [DavidSamir](https://github.com/DavidSamir) on 2026-10-22T09:20:41Z. --- @jotitadev thank you, especially for the UBSan run. It shows the `INT_MIN` negation was real undefined behaviour (`negation of -2147483648 cannot be represented in type 'int'`), not just a theoretical one, and that the new check removes it. I had written that no negative control could show this; yours does. AI-assisted: yes
harisibrar1 commented 2026-10-22 12:54:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-22T12:54:58Z.

Review: APPROVED


Rechecked at ecd4a973f:

  • SetProcessGroup now returns ESRCH for INT_MIN before negating (DescriptorControl.cpp:470-473), and the stored owner can only be 0 or ±pid, so the remaining -GetSigioOwner negations are safe too. The result still matches FreeBSD's fsetown.
  • TIOCSPGRP now goes through the checked ReadGuestInt (:641-644), and the ioctl, _ioctl debt entry names the TIOCSPGRP/TIOCGPGRP exception on a pipe above fd 2. Both of my points are addressed; it still needs to land after #9557.

Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5614478809 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9566#pullrequestreview-5614478809). Originally posted by [harisibrar1](https://github.com/harisibrar1) on 2026-10-22T12:54:58Z. **Review:** APPROVED --- Rechecked at ecd4a973f: - `SetProcessGroup` now returns `ESRCH` for `INT_MIN` before negating (DescriptorControl.cpp:470-473), and the stored owner can only be 0 or ±pid, so the remaining `-GetSigioOwner` negations are safe too. The result still matches FreeBSD's `fsetown`. - `TIOCSPGRP` now goes through the checked `ReadGuestInt` (:641-644), and the `ioctl, _ioctl` debt entry names the `TIOCSPGRP`/`TIOCGPGRP` exception on a pipe above fd 2. Both of my points are addressed; it still needs to land after #9557. Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.
MarcZX10 commented 2026-10-22 14:24:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T14:24:40Z.

Review: CHANGES_REQUESTED


The earlier technical findings are addressed in this head: the INT_MIN case is rejected before negation, TIOCSPGRP uses checked guest copy-in, and the debt text records the pipe ioctl exception. I verified the current #9557 head f8698a0b663a95a51f59839c42e245bf0f5598e0 is an ancestor of this PR, so the declared prerequisite is present. #9242 and #9491 remain open at 028ccac1 and d1604d79; the stated no-wait agreements cover their test/debt overlaps.

Current upstream/main is 329efe1bfdaff116c57cdf62718026ee4f5521ae. This PR is 6 ahead / 56 behind, merge-tree is clean, and current-base git diff --check passes. The current conventions run has zero errors and only the reported inherited debt-length warnings. Main has updated docs/dev/debt/libkernel.md since the PR base, while the changed C++ and test files have no intervening main edits. Please refresh from current main and let conventions run again before merge; then rerun the focused terminal/owner tests if the rebase changes the tested tree. The Windows and Linux/ASan/UBSan runs in the discussion are reporter-run on the current code head; I did not run a local project build here.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5615788251 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9566#pullrequestreview-5615788251). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-22T14:24:40Z. **Review:** CHANGES_REQUESTED --- The earlier technical findings are addressed in this head: the `INT_MIN` case is rejected before negation, `TIOCSPGRP` uses checked guest copy-in, and the debt text records the pipe ioctl exception. I verified the current #9557 head `f8698a0b663a95a51f59839c42e245bf0f5598e0` is an ancestor of this PR, so the declared prerequisite is present. #9242 and #9491 remain open at `028ccac1` and `d1604d79`; the stated no-wait agreements cover their test/debt overlaps. Current upstream/main is `329efe1bfdaff116c57cdf62718026ee4f5521ae`. This PR is 6 ahead / 56 behind, merge-tree is clean, and current-base `git diff --check` passes. The current conventions run has zero errors and only the reported inherited debt-length warnings. Main has updated `docs/dev/debt/libkernel.md` since the PR base, while the changed C++ and test files have no intervening main edits. Please refresh from current main and let conventions run again before merge; then rerun the focused terminal/owner tests if the rebase changes the tested tree. The Windows and Linux/ASan/UBSan runs in the discussion are reporter-run on the current code head; I did not run a local project build here.
MarcZX10 commented 2026-11-17 01:20:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-17T01:20:59Z.

Review: COMMENTED


Reviewed — no blocking findings

Nothing blocks this; the points below are optional.

What I ran

Head 0bc531a0a29be507638f5edaa51645a8169aed4f, base main. Static review only: no build and no test run.

python3 repo_read.py search g_mutex core/libs/prx/libkernel/File
python3 repo_read.py search GuestCopyIn_nid_no_patch core/libs/prx/libkernel
python3 repo_read.py search HostWrite core/libs/prx/libkernel
python3 repo_read.py search GuestArenaPrepareHostRead core/libs/prx/libkernel

Files read: all 7 in files.json under reviewed, none excluded. Terminal.cpp was read in full. DescriptorControl.cpp was read through its changed hunks, plus its head lines 120–159 and 380–439. CMakeLists.txt, GuestKernelFcntlOwner.cpp, GuestTerminal.cpp and libkernel.md were read through their changed hunks only.

Results

Check Result Note
Build not run No builds in this review
Tests not run Author reports a Windows run only
Changed code read passed 7 of 7 files, see above
Lock order and helpers passed No nested lock; helpers exist
Conventions script not run Author reports 0 errors

Findings

Blocking

None.

Non-blocking

  • core/libs/prx/libkernel/File/src/DescriptorControl.cpp:621: on Linux, ReadGuestInt throws when process_vm_readv fails with an errno other than EFAULT. The FIONBIO path now reads its argument through this helper (core/libs/prx/libkernel/File/src/DescriptorControl.cpp:654), where it used GuestCopyIn_nid_no_patch before. If the host refuses the call, FIONBIO throws instead of returning a guest error. I did not read the Linux implementation of GuestCopyIn_nid_no_patch, so I cannot say whether the old path could fail the same way.

Sources

Not verified

  • Nothing was compiled or run here. The Linux branch (process_vm_readv) and the macOS branch (mach_vm_read_overwrite) of ReadGuestInt have not been compiled by anyone in this review.
  • The author's Windows run of guest_terminal and guest_kernel_fcntl_owner is author-reported and was not repeated here.
  • The lib/libc/gen/termios.c side of tcgetpgrp and tcsetpgrp, cited in the description, was not read.
  • The FreeBSD behaviour cited in the description and the debt entries (sys_pipe.c) was not checked.
  • The overlap check and the check_conventions.py result are author-reported and were not run.

To get this to a good state

Nothing is required.

Optional: on Linux, return a guest fault for any process_vm_readv failure, or document the throw in the libkernel debt file, so that a restricted host does not turn FIONBIO into an exception.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5931011303 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9566#pullrequestreview-5931011303). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-17T01:20:59Z. **Review:** COMMENTED --- # Reviewed — no blocking findings Nothing blocks this; the points below are optional. ## What I ran Head `0bc531a0a29be507638f5edaa51645a8169aed4f`, base `main`. Static review only: no build and no test run. ``` python3 repo_read.py search g_mutex core/libs/prx/libkernel/File python3 repo_read.py search GuestCopyIn_nid_no_patch core/libs/prx/libkernel python3 repo_read.py search HostWrite core/libs/prx/libkernel python3 repo_read.py search GuestArenaPrepareHostRead core/libs/prx/libkernel ``` Files read: all 7 in `files.json` under `reviewed`, none excluded. `Terminal.cpp` was read in full. `DescriptorControl.cpp` was read through its changed hunks, plus its head lines 120–159 and 380–439. `CMakeLists.txt`, `GuestKernelFcntlOwner.cpp`, `GuestTerminal.cpp` and `libkernel.md` were read through their changed hunks only. ## Results | Check | Result | Note | |---|---|---| | Build | not run | No builds in this review | | Tests | not run | Author reports a Windows run only | | Changed code read | passed | 7 of 7 files, see above | | Lock order and helpers | passed | No nested lock; helpers exist | | Conventions script | not run | Author reports 0 errors | ## Findings **Blocking** None. **Non-blocking** - `core/libs/prx/libkernel/File/src/DescriptorControl.cpp:621`: on Linux, `ReadGuestInt` throws when `process_vm_readv` fails with an errno other than `EFAULT`. The `FIONBIO` path now reads its argument through this helper (`core/libs/prx/libkernel/File/src/DescriptorControl.cpp:654`), where it used `GuestCopyIn_nid_no_patch` before. If the host refuses the call, `FIONBIO` throws instead of returning a guest error. I did not read the Linux implementation of `GuestCopyIn_nid_no_patch`, so I cannot say whether the old path could fail the same way. ## Sources - [Linux read helper, pinned](https://github.com/boykopovar/AnyPS5/blob/0bc531a0a29be507638f5edaa51645a8169aed4f/core/libs/prx/libkernel/File/src/DescriptorControl.cpp#L621) - [Descriptor table mutex, pinned](https://github.com/boykopovar/AnyPS5/blob/0bc531a0a29be507638f5edaa51645a8169aed4f/core/libs/prx/libkernel/File/src/DescriptorControl.cpp#L135) - [Pipe-only process group check, pinned](https://github.com/boykopovar/AnyPS5/blob/0bc531a0a29be507638f5edaa51645a8169aed4f/core/libs/prx/libkernel/File/src/Terminal.cpp#L81-L83) ## Not verified - Nothing was compiled or run here. The Linux branch (`process_vm_readv`) and the macOS branch (`mach_vm_read_overwrite`) of `ReadGuestInt` have not been compiled by anyone in this review. - The author's Windows run of `guest_terminal` and `guest_kernel_fcntl_owner` is author-reported and was not repeated here. - The `lib/libc/gen/termios.c` side of `tcgetpgrp` and `tcsetpgrp`, cited in the description, was not read. - The FreeBSD behaviour cited in the description and the debt entries (`sys_pipe.c`) was not checked. - The overlap check and the `check_conventions.py` result are author-reported and were not run. ## To get this to a good state Nothing is required. Optional: on Linux, return a guest fault for any `process_vm_readv` failure, or document the throw in the libkernel debt file, so that a restricted host does not turn `FIONBIO` into an exception.
MarcZX10 commented 2026-11-17 10:07:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-17T10:07:21Z.

Review: CHANGES_REQUESTED


Reviewed — changes requested

Changes are required before merge: the debt register now holds duplicate entries that contradict each other on the behaviour this PR changes.

What I ran

  • Head SHA: fd2ec30a36 (base main).
  • Read the full diff.patch, description.md, commits.md and manifest.json from the review folder.
  • Read the house rules sections "Readable reviews", "Accuracy and evidence" and "Standard PR response format".
  • Repository reads at head through the reader (repo_read.py): search for the debt entries, the mutex and Materialize in DescriptorControl.cpp, the fcntl_nid_postfix declarations; cat of DescriptorControl.cpp lines 136–150 and 396–406.
  • No build and no test run in this review.

Results

Check Result Note
Full diff read passed 428 lines, all 8 changed files
Debt register at head failed Duplicate, contradictory entries
Lock order in GetSigioOwner / Owner passed Materialize takes no lock, so no self-deadlock
Build and CTest not run Not built here
Author's test report not run Author-reported only, not reproduced

Findings

Blocking

  • docs/dev/debt/libkernel.md:189 (added at diff lines 408–410): the PR adds a new tcsendbreak, tcdrain, tcflush, tcflow, tcgetpgrp, tcsetpgrp entry, but the old entry stays at docs/dev/debt/libkernel.md:194. The new entry says tcgetpgrp and tcsetpgrp use the pipe's SIGIO owner; the old one says they throw on a host pipe. The same goes for sem_setname (187 and 191) and kevent measurements (188 and 192): the copies disagree on what a null name returns (EINVAL at 191, a throw at 187).
    • Failure scenario: a reader of the debt register gets two opposite answers for tcgetpgrp on a pipe. The code now implements the pipe-owner answer, so the entry at 194 is stale.
    • Fix: keep one entry per export. Drop the old tcsendbreak entry at 194 and the old copies at 191–192, and check Pthread/Posix/Sem.cpp and Equeue/src/Kqueue.cpp at head to decide which sem_setname and kevent text is right. Those two are unrelated to this PR, so they belong in a separate change or should be removed from this one.

Non-blocking

  • description.md says the terminal entry sits at docs/dev/debt/libkernel.md:128 and that its throw clause is replaced. The diff touches lines 187–189 and 355–361 only, and the old entry is at 194. Point the description at the real lines once the duplicates are gone.

Not verified

  • Build, CTest, and the new guest_kernel_fcntl_owner test under CMake on any host.
  • The author's test results (guest_terminal and guest_kernel_fcntl_owner, 3 of 3 runs, and the negative controls at lines 120 and 121). Author-reported only.
  • The author's character counts for the terminal debt entry (1047 against 1131).
  • Host behaviour of the calls the code relies on: process_vm_readv on Linux, mach_vm_read_overwrite on macOS, ReadProcessMemory on Windows.
  • std::erase_if on std::map and the <map> and <memory> includes; the ENVIRONMENT_MODIFICATION block in CMakeLists.txt for Windows.
  • The PS5 claims in the debt entries. These cannot be checked from the repository.
  • The overlap claims against #9557, #9242, #9491, #9131, #7121, #8520, #9019 and #9561.
  • Files read: the four review-folder files and the diff in full, plus the head text of DescriptorControl.cpp at 136–150 and 396–406. Not read: the files/ full texts, files.json, the head text of Terminal.cpp, CMakeLists.txt, the two test files, and Api.hpp beyond the grep. Lockfiles, minified files, dist/, build/ and .svg are excluded from the diff by rule.

To get this to a good state

  • Remove the duplicate debt entries so each export has one entry with one answer (see the blocking finding).
  • Fix the description's pointer to the debt entry.
  • On the new head, rerun guest_terminal and guest_kernel_fcntl_owner and attach the output.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5936470623 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9566#pullrequestreview-5936470623). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-17T10:07:21Z. **Review:** CHANGES_REQUESTED --- # Reviewed — changes requested Changes are required before merge: the debt register now holds duplicate entries that contradict each other on the behaviour this PR changes. **What I ran** - Head SHA: fd2ec30a36e81f6bdabc94616c1eea4b78b8e763 (base main). - Read the full `diff.patch`, `description.md`, `commits.md` and `manifest.json` from the review folder. - Read the house rules sections "Readable reviews", "Accuracy and evidence" and "Standard PR response format". - Repository reads at head through the reader (`repo_read.py`): `search` for the debt entries, the mutex and `Materialize` in `DescriptorControl.cpp`, the `fcntl_nid_postfix` declarations; `cat` of `DescriptorControl.cpp` lines 136–150 and 396–406. - No build and no test run in this review. **Results** | Check | Result | Note | |---|---|---| | Full diff read | passed | 428 lines, all 8 changed files | | Debt register at head | failed | Duplicate, contradictory entries | | Lock order in `GetSigioOwner` / `Owner` | passed | `Materialize` takes no lock, so no self-deadlock | | Build and CTest | not run | Not built here | | Author's test report | not run | Author-reported only, not reproduced | **Findings** **Blocking** - `docs/dev/debt/libkernel.md:189` (added at diff lines 408–410): the PR adds a new `tcsendbreak, tcdrain, tcflush, tcflow, tcgetpgrp, tcsetpgrp` entry, but the old entry stays at `docs/dev/debt/libkernel.md:194`. The new entry says `tcgetpgrp` and `tcsetpgrp` use the pipe's SIGIO owner; the old one says they throw on a host pipe. The same goes for `sem_setname` (187 and 191) and `kevent measurements` (188 and 192): the copies disagree on what a null name returns (`EINVAL` at 191, a throw at 187). - Failure scenario: a reader of the debt register gets two opposite answers for `tcgetpgrp` on a pipe. The code now implements the pipe-owner answer, so the entry at 194 is stale. - Fix: keep one entry per export. Drop the old `tcsendbreak` entry at 194 and the old copies at 191–192, and check `Pthread/Posix/Sem.cpp` and `Equeue/src/Kqueue.cpp` at head to decide which `sem_setname` and `kevent` text is right. Those two are unrelated to this PR, so they belong in a separate change or should be removed from this one. **Non-blocking** - `description.md` says the terminal entry sits at `docs/dev/debt/libkernel.md:128` and that its throw clause is replaced. The diff touches lines 187–189 and 355–361 only, and the old entry is at 194. Point the description at the real lines once the duplicates are gone. **Not verified** - Build, CTest, and the new `guest_kernel_fcntl_owner` test under CMake on any host. - The author's test results (`guest_terminal` and `guest_kernel_fcntl_owner`, 3 of 3 runs, and the negative controls at lines 120 and 121). Author-reported only. - The author's character counts for the terminal debt entry (1047 against 1131). - Host behaviour of the calls the code relies on: `process_vm_readv` on Linux, `mach_vm_read_overwrite` on macOS, `ReadProcessMemory` on Windows. - `std::erase_if` on `std::map` and the `<map>` and `<memory>` includes; the `ENVIRONMENT_MODIFICATION` block in `CMakeLists.txt` for Windows. - The PS5 claims in the debt entries. These cannot be checked from the repository. - The overlap claims against #9557, #9242, #9491, #9131, #7121, #8520, #9019 and #9561. - Files read: the four review-folder files and the diff in full, plus the head text of `DescriptorControl.cpp` at 136–150 and 396–406. Not read: the `files/` full texts, `files.json`, the head text of `Terminal.cpp`, `CMakeLists.txt`, the two test files, and `Api.hpp` beyond the grep. Lockfiles, minified files, `dist/`, `build/` and `.svg` are excluded from the diff by rule. **To get this to a good state** - Remove the duplicate debt entries so each export has one entry with one answer (see the blocking finding). - Fix the description's pointer to the debt entry. - On the new head, rerun `guest_terminal` and `guest_kernel_fcntl_owner` and attach the output.
ligmaSec commented 2026-12-03 12:02:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T12:02:55Z.

Review: COMMENTED


Compiled the changed descriptor and terminal sources with GuestKernelFcntlOwner and GuestTerminal against the existing Linux PRXs. Both fixtures passed, including process-group handling on the pipe endpoints.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6169387344 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9566#pullrequestreview-6169387344). Originally posted by [ligmaSec](https://github.com/ligmaSec) on 2026-12-03T12:02:55Z. **Review:** COMMENTED --- Compiled the changed descriptor and terminal sources with `GuestKernelFcntlOwner` and `GuestTerminal` against the existing Linux PRXs. Both fixtures passed, including process-group handling on the pipe endpoints. 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/9566:upstream-pr/9566'
git switch 'upstream-pr/9566'

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/9566'
git switch 'upstream-pr/9566'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/9566'
git switch 'upstream-pr/9566'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/9566'
git switch 'main'
git merge --squash 'upstream-pr/9566'
git switch 'main'
git merge --ff-only 'upstream-pr/9566'
git switch 'main'
git merge 'upstream-pr/9566'
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!9566
No description provided.