feat(libkernel): implement tcgetsid #9242

Merged
DavidSamir merged 8 commits from upstream-pr/9242 into main 2026-11-03 08:09:32 +00:00
DavidSamir commented 2026-10-21 16:23:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by DavidSamir on 2026-10-21T16:23:21Z.


What

Implements tcgetsid in libkernel, so that libkernel and libkernel_sys imports both reach it. libkernel_sys/Export.Discovery.cpp declared it as a stub that threw NotImplemented.

The PS5 3.20 export lists have tcgetsid in libkernel as well as libkernel_sys. On Windows an import of libkernel never searches libkernel_sys (WindowsEntryStubBuilder.cpp only falls back from libkernel_sys to libkernel), so an implementation in libkernel_sys alone would be unreachable for a title that imports it from libkernel. On Linux and macOS the lookup is global, so libkernel_sys importers reach the libkernel one too.

Reference: FreeBSD 11 lib/libc/gen/termios.c defines tcgetsid(fd) as _ioctl(fd, TIOCGSID, &s), returning -1 on failure and s otherwise. TIOCGSID is _IOR('t', 99, int) in sys/ttycom.h.

It sits beside its siblings in libkernel/File/src/Terminal.cpp and fails the way they (tcgetattr, tcdrain, tcflush, tcgetpgrp, ...) do on a descriptor that is not a terminal, through the same TerminalError helper:

  • EBADF for a descriptor that is not open;
  • EOPNOTSUPP for a local socket and EADDRNOTAVAIL for an internet socket, as FreeBSD's socket ioctl answers;
  • ENOTTY for anything else.

Terminals are not modelled, so it never returns a session id.

A pipe or FIFO gets ENOTTY and does not throw as tcgetpgrp does: FreeBSD's pipe_ioctl (sys/kern/sys_pipe.c, stable/11) answers FIONBIO, FIOASYNC, FIONREAD, FIOSETOWN, FIOGETOWN, TIOCSPGRP and TIOCGPGRP, and returns ENOTTY for everything else, including TIOCGSID.

Building it on the generic ioctl path was not an option: File::Ioctl answers every terminal-group request with ENOTTY, which would give a socket a different error from the one its sibling terminal calls give.

Tested

Windows 11, WinLibs GCC 15.2.0, Release. Head 028ccac177:

  • guest_terminal now covers tcgetsid next to tcgetpgrp: a regular file, standard streams 0 to 2, an internet socket, both ends of a local socketpair, a directory, -1, and the same descriptors after they are closed, plus both ends of a pipe, which get ENOTTY where tcgetpgrp throws. It passes.
  • With libkernel's Terminal.cpp from before the move (no tcgetsid in libkernel), guest_terminal_tests does not link: undefined reference to tcgetsid_nid_postfix.
  • guest_kernel_sys and guest_termios_speed still pass.
  • python tools/check_conventions.py --base origin/main passes.

Merge checks with git merge-tree: clean against main, #8987, #9008, #9019, #9097, #9103, #9141, #9156, #9160, #9161, #9162 and #9171. tools/pr_overlap.py did not finish on this machine (stopped after 25 and then 55 minutes); the branch was checked against the diffs of all open pull requests on 2026-10-21 instead.

Overlap with #9566 (the tcgetpgrp and tcsetpgrp on pipes follow-up): both add pipe and termios checks in core/libs/tests/GuestTerminal.cpp, one hunk. There is no dependency between them; whichever merges second keeps both blocks, as agreed with its author.

Not run on Linux or macOS.

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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4954831650 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9242). Originally posted by [DavidSamir](https://github.com/DavidSamir) on 2026-10-21T16:23:21Z. --- ### What Implements `tcgetsid` in `libkernel`, so that `libkernel` and `libkernel_sys` imports both reach it. `libkernel_sys/Export.Discovery.cpp` declared it as a stub that threw `NotImplemented`. The PS5 3.20 export lists have `tcgetsid` in `libkernel` as well as `libkernel_sys`. On Windows an import of `libkernel` never searches `libkernel_sys` (`WindowsEntryStubBuilder.cpp` only falls back from `libkernel_sys` to `libkernel`), so an implementation in `libkernel_sys` alone would be unreachable for a title that imports it from `libkernel`. On Linux and macOS the lookup is global, so `libkernel_sys` importers reach the `libkernel` one too. Reference: FreeBSD 11 [`lib/libc/gen/termios.c`](https://github.com/freebsd/freebsd-src/blob/stable/11/lib/libc/gen/termios.c) defines `tcgetsid(fd)` as `_ioctl(fd, TIOCGSID, &s)`, returning -1 on failure and `s` otherwise. `TIOCGSID` is `_IOR('t', 99, int)` in `sys/ttycom.h`. It sits beside its siblings in `libkernel/File/src/Terminal.cpp` and fails the way they (`tcgetattr`, `tcdrain`, `tcflush`, `tcgetpgrp`, ...) do on a descriptor that is not a terminal, through the same `TerminalError` helper: - `EBADF` for a descriptor that is not open; - `EOPNOTSUPP` for a local socket and `EADDRNOTAVAIL` for an internet socket, as FreeBSD's socket ioctl answers; - `ENOTTY` for anything else. Terminals are not modelled, so it never returns a session id. A pipe or FIFO gets `ENOTTY` and does not throw as `tcgetpgrp` does: FreeBSD's `pipe_ioctl` (`sys/kern/sys_pipe.c`, stable/11) answers `FIONBIO`, `FIOASYNC`, `FIONREAD`, `FIOSETOWN`, `FIOGETOWN`, `TIOCSPGRP` and `TIOCGPGRP`, and returns `ENOTTY` for everything else, including `TIOCGSID`. Building it on the generic `ioctl` path was not an option: `File::Ioctl` answers every terminal-group request with `ENOTTY`, which would give a socket a different error from the one its sibling terminal calls give. ### Tested Windows 11, WinLibs GCC 15.2.0, Release. Head `028ccac177`: - `guest_terminal` now covers `tcgetsid` next to `tcgetpgrp`: a regular file, standard streams 0 to 2, an internet socket, both ends of a local socketpair, a directory, `-1`, and the same descriptors after they are closed, plus both ends of a pipe, which get `ENOTTY` where `tcgetpgrp` throws. It passes. - With `libkernel`'s `Terminal.cpp` from before the move (no `tcgetsid` in `libkernel`), `guest_terminal_tests` does not link: `undefined reference` to `tcgetsid_nid_postfix`. - `guest_kernel_sys` and `guest_termios_speed` still pass. - `python tools/check_conventions.py --base origin/main` passes. Merge checks with `git merge-tree`: clean against `main`, #8987, #9008, #9019, #9097, #9103, #9141, #9156, #9160, #9161, #9162 and #9171. `tools/pr_overlap.py` did not finish on this machine (stopped after 25 and then 55 minutes); the branch was checked against the diffs of all open pull requests on 2026-10-21 instead. Overlap with #9566 (the `tcgetpgrp` and `tcsetpgrp` on pipes follow-up): both add pipe and termios checks in `core/libs/tests/GuestTerminal.cpp`, one hunk. There is no dependency between them; whichever merges second keeps both blocks, as agreed with its author. Not run on Linux or macOS. ### 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
harisibrar1 commented 2026-10-24 12:47:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-24T12:47:44Z.

Review: APPROVED


Checked against main 39a36bbec8 and FreeBSD 11.4 lib/libc/gen/termios.c, sys/sys/ttycom.h and sys/kern/sys_pipe.c:

  • It still merges cleanly. Main hasn't touched Terminal.cpp or GuestTerminal.cpp since your base, and still only has the throwing libkernel_sys stub (Export.Discovery.cpp:2432).
  • tcgetsid matches termios.c (_ioctl(fd, TIOCGSID, &s), -1 on failure), and reusing TerminalError keeps the errno values consistent with tcgetattr and the other terminal calls on main.
  • The pipe result is right: 11.4's pipe_ioctl answers TIOCGPGRP/TIOCSPGRP but returns ENOTTY for TIOCGSID.
  • Small nit: the debt link points at stable/11. Pinning it to release/11.4.0 or a commit, like the neighbouring entries, would keep it stable.

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

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5638288541 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9242#pullrequestreview-5638288541). Originally posted by [harisibrar1](https://github.com/harisibrar1) on 2026-10-24T12:47:44Z. **Review:** APPROVED --- Checked against main 39a36bbec8 and FreeBSD 11.4 lib/libc/gen/termios.c, sys/sys/ttycom.h and sys/kern/sys_pipe.c: - It still merges cleanly. Main hasn't touched `Terminal.cpp` or `GuestTerminal.cpp` since your base, and still only has the throwing `libkernel_sys` stub (Export.Discovery.cpp:2432). - `tcgetsid` matches termios.c (`_ioctl(fd, TIOCGSID, &s)`, -1 on failure), and reusing `TerminalError` keeps the errno values consistent with `tcgetattr` and the other terminal calls on main. - The pipe result is right: 11.4's `pipe_ioctl` answers TIOCGPGRP/TIOCSPGRP but returns ENOTTY for TIOCGSID. - Small nit: the debt link points at `stable/11`. Pinning it to `release/11.4.0` or a commit, like the neighbouring entries, would keep it stable. Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.
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!9242
No description provided.