feat(libkernel): implement tcgetsid #9242
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9242"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by DavidSamir on 2026-10-21T16:23:21Z.
What
Implements
tcgetsidinlibkernel, so thatlibkernelandlibkernel_sysimports both reach it.libkernel_sys/Export.Discovery.cppdeclared it as a stub that threwNotImplemented.The PS5 3.20 export lists have
tcgetsidinlibkernelas well aslibkernel_sys. On Windows an import oflibkernelnever searcheslibkernel_sys(WindowsEntryStubBuilder.cpponly falls back fromlibkernel_systolibkernel), so an implementation inlibkernel_sysalone would be unreachable for a title that imports it fromlibkernel. On Linux and macOS the lookup is global, solibkernel_sysimporters reach thelibkernelone too.Reference: FreeBSD 11
lib/libc/gen/termios.cdefinestcgetsid(fd)as_ioctl(fd, TIOCGSID, &s), returning -1 on failure andsotherwise.TIOCGSIDis_IOR('t', 99, int)insys/ttycom.h.It sits beside its siblings in
libkernel/File/src/Terminal.cppand fails the way they (tcgetattr,tcdrain,tcflush,tcgetpgrp, ...) do on a descriptor that is not a terminal, through the sameTerminalErrorhelper:EBADFfor a descriptor that is not open;EOPNOTSUPPfor a local socket andEADDRNOTAVAILfor an internet socket, as FreeBSD's socket ioctl answers;ENOTTYfor anything else.Terminals are not modelled, so it never returns a session id.
A pipe or FIFO gets
ENOTTYand does not throw astcgetpgrpdoes: FreeBSD'spipe_ioctl(sys/kern/sys_pipe.c, stable/11) answersFIONBIO,FIOASYNC,FIONREAD,FIOSETOWN,FIOGETOWN,TIOCSPGRPandTIOCGPGRP, and returnsENOTTYfor everything else, includingTIOCGSID.Building it on the generic
ioctlpath was not an option:File::Ioctlanswers every terminal-group request withENOTTY, 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_terminalnow coverstcgetsidnext totcgetpgrp: 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 getENOTTYwheretcgetpgrpthrows. It passes.libkernel'sTerminal.cppfrom before the move (notcgetsidinlibkernel),guest_terminal_testsdoes not link:undefined referencetotcgetsid_nid_postfix.guest_kernel_sysandguest_termios_speedstill pass.python tools/check_conventions.py --base origin/mainpasses.Merge checks with
git merge-tree: clean againstmain, #8987, #9008, #9019, #9097, #9103, #9141, #9156, #9160, #9161, #9162 and #9171.tools/pr_overlap.pydid 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
tcgetpgrpandtcsetpgrpon pipes follow-up): both add pipe and termios checks incore/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
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-24T12:47:44Z.
Review: APPROVED
Checked against main
39a36bbec8and FreeBSD 11.4 lib/libc/gen/termios.c, sys/sys/ttycom.h and sys/kern/sys_pipe.c:Terminal.cpporGuestTerminal.cppsince your base, and still only has the throwinglibkernel_sysstub (Export.Discovery.cpp:2432).tcgetsidmatches termios.c (_ioctl(fd, TIOCGSID, &s), -1 on failure), and reusingTerminalErrorkeeps the errno values consistent withtcgetattrand the other terminal calls on main.pipe_ioctlanswers TIOCGPGRP/TIOCSPGRP but returns ENOTTY for TIOCGSID.stable/11. Pinning it torelease/11.4.0or 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.