feat(libkernel): implement tcgetattr and tcsetattr #1738
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1738"
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 SleglJan on 2026-10-08T17:55:25Z.
What
Adds
tcgetattrandtcsetattrto libkernel, in a newFile/src/Terminal.cpp, on the assumption that a title's descriptors are never terminals: a title runs without a controlling terminal, and what the console gives it as descriptors 0 to 2 is unknown (recorded in TechnicalDebt). The errors are the ones FreeBSD 11'stermios.candioctlpath give for a descriptor that is not a terminal:ENOTTY, andtcgetattrleaves thetermiosuntouched, asTIOCGETAcopies out only on success. A guest socket gets what its protocol's control routine returns to a termios ioctl,EADDRNOTAVAILforAF_INET(in_controlwithout an interface) andEOPNOTSUPPotherwise (in6_control,pru_control_notsupp).tcsetattrgivesEINVALfor an action other thanTCSANOW,TCSADRAINorTCSAFLUSH, with or withoutTCSASOFT, before anything else;EFAULTfor a nulltermios, whichsys_ioctlcopies in before it looks at the descriptor. WithTCSASOFTand a nulltermiosFreeBSD's libc faults while copying it, so that case throws.EBADF) when it is negative, a closed guest socket, or a host descriptor the host does not know:fcntl(F_GETFD)on Linux,_get_osfhandleon Windows under the thread-local invalid-parameter handler, asNativeCloseinOpen.cppdoes.Of the 34 relinked titles in the homebrew catalog (#1578), 16 import
tcgetattrandtcsetattrand one stops attcgetattronmain4b6ab6bb, PPSA99728 OpenRCT2 Native Port: relinked withmain's relinker and run for 8 s in a bubblewrap sandbox on Linux, it dies in the host loader withapp.elf: symbol lookup error: app.elf: undefined symbol: 5kBfZ40bAuk.Overlap: #1613 adds
isattyto libScePosixForWebKit through the host'sisatty, which can say yes to a host terminal on descriptors 0 to 2 where this says no; the two should agree once either lands. #1645 and #1192 insert source lines next toStdio.cppinlibkernel/CMakeLists.txt; this one goes afterNativeStat.cpp, so none of the three overlap. #1727 and #1091 add declarations toSocketRuntime.hppwhere this addsFamily; whichever merges second rebases one line.Tested
BUILD_TESTING=ONandANYPS5_ENABLE_SPIRV_TOOLS=ONon this branch (based onmain2b297842):ctest --repeat until-fail:3468/468;tools/check_test_registration.pyandtools/check_conventions.py --base upstream/mainpass.guest_terminaltest:ENOTTYwith an untouchedtermiosfromtcgetattr, and fromtcsetattrwith every valid action, on a file opened throughopen, descriptors 0, 1 and 2 and both ends of apipe;EADDRNOTAVAILon anAF_INETsocket with thetermiosuntouched;EINVALfor actions 3, -1 andTCSASOFT | 3even on an invalid descriptor;EFAULTfor a nulltermioseven on an invalid descriptor;EBADFfor -1, a closed socket and a closed file. Written before the implementation; it failed on the two unresolved exports and passes with it.libkernel.prxexports the NIDs (5kBfZ40bAuk,La7xW-jcZwQ).tools/import_audit.pyon five of the 16 catalog titles, absent imports onmain4b005b22→ this branch: PPSA17641 SymphonyStation5 35 → 33, PPSA97510 PSXS5 72 → 70, PPSA99000 ProsperoStore 40 → 38, PPSA99009 ProsperoLichess 37 → 35, PPSA99039 EVO Player 24 → 22. None of them loads yet; the remaining imports are listed in #1578.main6b56175a), run 37822114975:guest_terminalpasses its three repeats, full suite 474/474. The only host call there is_get_osfhandleunder the invalid-parameter guard; the UCRT keeps descriptors 0 to 2 open in a child process, so the test'sENOTTYchecks on them hold.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-08T18:18:08Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)__error_nid_postfix__error_nid_postfixcore/libs/prx/libkernel/CMakeLists.txtL134__error_nid_postfix__error_nid_postfixImported from boykopovar/AnyPS5. Originally posted by hikazey on 2026-10-08T19:22:23Z.
Windows run, since the description lists Linux only: Windows 11 Pro (26200), MinGW-w64 GCC 15.2.0 (WinLibs r7, the CI build), Release, configured like CI, Ryzen 9 5900X. This commit merged onto
mainb858fdc4; onlydocs/dev/TechnicalDebt.mdneeded an auto-merge.guest_terminalHostOpenforced totrue(closed host descriptors no longerEBADF), test keptSo the Windows-only branch,
_get_osfhandleunder the thread-local invalid-parameter handler, runs without tripping the CRT's invalid-parameter abort. It's also what the test'sEBADFcases depend on: they fail as soon as that check is bypassed. Descriptors 0–2 underctestreportENOTTYhere too.AI-assisted: yes (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by nauroth on 2026-10-09T11:49:17Z.
Second Linux run, on current main: Ubuntu 24.04, GCC 13.3.0, glibc 2.39, Release. The commit cherry-picks cleanly onto
d70b899andguest_terminalpasses 3/3 with--repeat until-fail:3.Since the description names the kernel routines without linking them, I checked the socket error codes against FreeBSD stable/11:
sys/kern/sys_socket.c,soo_ioctl: thedefault:case routes group'i'toifioctl,'r'tortioctl_fib, and everything else topru_controlwithifp = 0.TIOCGETA/TIOCSETA*are group't', so they reachpru_control.sys/netinet/in.c,in_control: the first statement isif (ifp == NULL) return (EADDRNOTAVAIL);→AF_INETgets 49.sys/netinet6/in6.c,in6_control: after the twoifp-independent switches it doesif (ifp == NULL) return (EOPNOTSUPP);→AF_INET6gets 45, same aspru_control_notsuppfor the other families.The
tcsetattrordering also matches:EINVALfor a bad action comes from libc'stermios.cbefore any ioctl, andEFAULTfor a nulltermioscomes from thecopyininsys_ioctl, which runs beforefget, so it wins overEBADF. Nothing to change.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-09T21:22:15Z.
Checked against FreeBSD 11 (
termios.c,vn_ioctl,in_control): error codes and validation order match. Rebased on currentmain(clean), full build + ctest 523/523,guest_terminalpasses. Windows/Linux runs by @hikazey and @nauroth also cover it.Added one commit:
docs/dev/TechnicalDebt.md: moved thetcgetattr, tcsetattrentry from the end of "Unknown function info" (detached from the list by a blank line) into the list, to avoid adjacency conflicts.Merging once CI is green.
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-09T21:56:34Z.
Progress report (
870ac04→96418e0)📈 System libraries: 85.24% (+0.01%, +2 implemented functions)
✅ 2 implemented
tcgetattr_nid_postfixtcsetattr_nid_postfix