feat(libkernel): answer tcgetpgrp and tcsetpgrp on a pipe with its SIGIO owner #9566
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9566"
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-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.
tcgetpgrpandtcsetpgrpthrew 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:tcsetpgrpis_ioctl(fd, TIOCSPGRP, &pgrp)andtcgetpgrpis_ioctl(fd, TIOCGPGRP, &s)(lib/libc/gen/termios.c:82-99).pipe_ioctlanswersTIOCSPGRPwithfsetown(-pgrp)andTIOCGPGRPwith-fgetown()(sys/kern/sys_pipe.c:1402-1410). So these use the same owner asF_SETOWN/FIOSETOWN, with the sign reversed: afterF_SETOWN(pid),tcgetpgrpreturns-pid.How:
Terminal.cpp: on a host pipe or FIFO at descriptor 3 or above,tcgetpgrpandtcsetpgrpcallFile::PipeProcessGroupandFile::SetPipeProcessGroupinstead of throwing. The samefsetownrules apply: 0 clears, our own process group is stored, and any other group givesESRCH. Descriptors 0 to 2 keep their documentedENOTTY, since they're taken as non-terminals that aren't pipes.DescriptorControl.cpp: the two helpers. The rawTIOCSPGRP(0x80047476) andTIOCGPGRP(0x40047477) ioctls now give the same answer on such a pipe, ahead of the terminal-groupENOTTY.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:ESRCHfor another group, with the owner kept;F_SETOWN(pid)makingtcgetpgrpreturn-pid, and the reverse;TIOCSPGRP/TIOCGPGRPioctls;Results:
guest_terminalandguest_kernel_fcntl_ownerpass, 3 of 3 runs.guest_kernel_fcntlandguest_duppass.tools/check_conventions.py: 0 errors. It warns that the terminal debt entry (now 1047 characters, from 1131 onmain) and thefcntlentry are long; both were already over 1000 onmain.tools/pr_overlap.py --branchplusgit merge-tree. The code merges cleanly with #9131, #7121, #8520, #9019 and #9561. Textual conflicts:tcgetsid, also ours) addstcgetsidchecks right after the twoGuestTerminal.cpplines 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.libkernel.md:127-129). #9491's author (EagleBearerYS) agreed on this PR that neither waits: whichever merges second keeps both entries.fcntldebt line (:218) comes from #9557 and is shared with #8544, #9256, #9109 and #9561.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 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, heade846772a9merged--no-commitonto currentorigin/main(6ef5a1c4c).ctest -R "guest_kernel_fcntl_owner|guest_terminal"with the PR: both pass.DescriptorControl.cpp/.hppandTerminal.cpptoorigin/main, keep the tests): both abort with the real assertSo 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.
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.cppoverlap 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 correspondingDepends onentry. 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.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T04:00:06Z.
The PR description identifies the
GuestTerminal.cppoverlap 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 matchingDepends onentry. Keep both test additions through the rebase. The declared #9557 prerequisite is appropriate.Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-22T06:01:35Z.
Review: COMMENTED
Checked against main
4a17c7175, #9557's headc37556087(this PR's parent commit), and FreeBSD releng/11.4 (sys/kern/sys_pipe.c:1401-1410,lib/libc/gen/termios.c):pipe_ioctl, andtcgetpgrp/tcsetpgrpreuse the #9557 rules. Nothing here duplicates #9557; it just needs to land after it.ioctl, _ioctldebt entry (docs/dev/debt/libkernel.md:220) still says every group-ttermios request fails withENOTTY. With this PR,TIOCSPGRPandTIOCGPGRPon a pipe above fd 2 now succeed (DescriptorControl.cpp:601-609). Could that entry mention the exception?-groupinSetPipeProcessGroupand-*static_cast<const int*>(argument)(:602) overflow forINT_MIN. The result happens to beESRCH, as on FreeBSD, but it depends on undefined behaviour. An explicitINT_MIN→ESRCHcheck would make it well-defined.Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.
Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-22T06:07:35Z.
@DavidSamir a merge-order note: #9491 adds a
sceKernelWaitSema/sceKernelSignalSemaentry todocs/dev/debt/libkernel.mdright before thetcsendbreak … tcsetpgrpentry 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.Imported from boykopovar/AnyPS5. Originally posted by DavidSamir on 2026-10-22T08:04:24Z.
Thanks @MarcZX10 and @harisibrar1. New commits, no force-push:
FIOSETOWN/FIONBIOcopy-in.ecd4a973f9:tcsetpgrpandTIOCSPGRPgo through one setter that failsINT_MINwithESRCHbefore negating, so the result no longer depends on undefined behaviour. As @harisibrar1 said, the old code already gaveESRCHon this compiler, so the newGuestTerminalcase (tcsetpgrp(end, INT_MIN)fails withESRCHand keeps the group) passes either way. A negative control can't tell them apart here; it guards the UB.TIOCSPGRPnow copies its argument in with the same checked read asFIOSETOWN.GuestTerminalchecks that an unreadable pointer (0x10) givesEFAULTand leaves the owner unchanged.ioctl, _ioctldebt line now names the exception:TIOCSPGRPandTIOCGPGRPon a pipe above descriptor 2 set and read the pipe'sSIGIOgroup, aspipe_ioctldoes.ecd4a973f9: merges currentmain.Re-run on the merge (Windows 11, WinLibs GCC 15.2):
guest_terminal,guest_kernel_fcntl,guest_kernel_fcntl_ownerandguest_append_writespass, andcheck_conventions.pyreports 0 errors. Its 3 warnings are debt entries already over 1000 characters onmain.On the overlaps: #9242 is ours as well (the same fork), so we'll order the two
GuestTerminal.cppchanges 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
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 ate846772a9). The newReadGuestIntuses theprocess_vm_readvbranch here, which the Windows run doesn't exercise.Ubuntu 26.04, x86_64, i7-8700, GCC 15.2.0, Release, head merged
--no-commitontoorigin/main7e2ba73e4.ctest -R "guest_kernel_fcntl|guest_terminal": 3/3 pass.DescriptorControl.cppfrome846772a9, tests fromecd4a973f:guest_terminalandguest_kernel_fcntl_ownerboth die with SIGSEGV (the new0x10argument cases dereferenced directly). With the head's file both pass, soprocess_vm_readvreturnsEFAULTcleanly for the unreadable pointer.-fsanitize=address,undefined -fno-sanitize-recover=undefined,-O1): with the head, both tests pass with no reports. With thee846772a9DescriptorControl.cpp,guest_terminalstops at the newINT_MINcase with:So the
INT_MINcheck inSetProcessGroupremoves 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.
Imported from boykopovar/AnyPS5. Originally posted by DavidSamir on 2026-10-22T09:05:26Z.
@MarcZX10 the integration order is now recorded in the description:
GuestTerminal.cppblocks. #9242's description says the same.The prerequisite stays #9557.
AI-assisted: yes
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_MINnegation 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
Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-22T12:54:58Z.
Review: APPROVED
Rechecked at
ecd4a973f:SetProcessGroupnow returnsESRCHforINT_MINbefore negating (DescriptorControl.cpp:470-473), and the stored owner can only be 0 or ±pid, so the remaining-GetSigioOwnernegations are safe too. The result still matches FreeBSD'sfsetown.TIOCSPGRPnow goes through the checkedReadGuestInt(:641-644), and theioctl, _ioctldebt entry names theTIOCSPGRP/TIOCGPGRPexception 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.
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_MINcase is rejected before negation,TIOCSPGRPuses checked guest copy-in, and the debt text records the pipe ioctl exception. I verified the current #9557 headf8698a0b663a95a51f59839c42e245bf0f5598e0is an ancestor of this PR, so the declared prerequisite is present. #9242 and #9491 remain open at028ccac1andd1604d79; 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-basegit diff --checkpasses. The current conventions run has zero errors and only the reported inherited debt-length warnings. Main has updateddocs/dev/debt/libkernel.mdsince 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.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, basemain. Static review only: no build and no test run.Files read: all 7 in
files.jsonunderreviewed, none excluded.Terminal.cppwas read in full.DescriptorControl.cppwas read through its changed hunks, plus its head lines 120–159 and 380–439.CMakeLists.txt,GuestKernelFcntlOwner.cpp,GuestTerminal.cppandlibkernel.mdwere read through their changed hunks only.Results
Findings
Blocking
None.
Non-blocking
core/libs/prx/libkernel/File/src/DescriptorControl.cpp:621: on Linux,ReadGuestIntthrows whenprocess_vm_readvfails with an errno other thanEFAULT. TheFIONBIOpath now reads its argument through this helper (core/libs/prx/libkernel/File/src/DescriptorControl.cpp:654), where it usedGuestCopyIn_nid_no_patchbefore. If the host refuses the call,FIONBIOthrows instead of returning a guest error. I did not read the Linux implementation ofGuestCopyIn_nid_no_patch, so I cannot say whether the old path could fail the same way.Sources
Not verified
process_vm_readv) and the macOS branch (mach_vm_read_overwrite) ofReadGuestInthave not been compiled by anyone in this review.guest_terminalandguest_kernel_fcntl_owneris author-reported and was not repeated here.lib/libc/gen/termios.cside oftcgetpgrpandtcsetpgrp, cited in the description, was not read.sys_pipe.c) was not checked.check_conventions.pyresult 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_readvfailure, or document the throw in the libkernel debt file, so that a restricted host does not turnFIONBIOinto an exception.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
fd2ec30a36(base main).diff.patch,description.md,commits.mdandmanifest.jsonfrom the review folder.repo_read.py):searchfor the debt entries, the mutex andMaterializeinDescriptorControl.cpp, thefcntl_nid_postfixdeclarations;catofDescriptorControl.cpplines 136–150 and 396–406.Results
GetSigioOwner/OwnerMaterializetakes no lock, so no self-deadlockFindings
Blocking
docs/dev/debt/libkernel.md:189(added at diff lines 408–410): the PR adds a newtcsendbreak, tcdrain, tcflush, tcflow, tcgetpgrp, tcsetpgrpentry, but the old entry stays atdocs/dev/debt/libkernel.md:194. The new entry saystcgetpgrpandtcsetpgrpuse the pipe's SIGIO owner; the old one says they throw on a host pipe. The same goes forsem_setname(187 and 191) andkevent measurements(188 and 192): the copies disagree on what a null name returns (EINVALat 191, a throw at 187).tcgetpgrpon a pipe. The code now implements the pipe-owner answer, so the entry at 194 is stale.tcsendbreakentry at 194 and the old copies at 191–192, and checkPthread/Posix/Sem.cppandEqueue/src/Kqueue.cppat head to decide whichsem_setnameandkeventtext 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.mdsays the terminal entry sits atdocs/dev/debt/libkernel.md:128and 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
guest_kernel_fcntl_ownertest under CMake on any host.guest_terminalandguest_kernel_fcntl_owner, 3 of 3 runs, and the negative controls at lines 120 and 121). Author-reported only.process_vm_readvon Linux,mach_vm_read_overwriteon macOS,ReadProcessMemoryon Windows.std::erase_ifonstd::mapand the<map>and<memory>includes; theENVIRONMENT_MODIFICATIONblock inCMakeLists.txtfor Windows.DescriptorControl.cppat 136–150 and 396–406. Not read: thefiles/full texts,files.json, the head text ofTerminal.cpp,CMakeLists.txt, the two test files, andApi.hppbeyond the grep. Lockfiles, minified files,dist/,build/and.svgare excluded from the diff by rule.To get this to a good state
guest_terminalandguest_kernel_fcntl_ownerand attach the output.Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T12:02:55Z.
Review: COMMENTED
Compiled the changed descriptor and terminal sources with
GuestKernelFcntlOwnerandGuestTerminalagainst the existing Linux PRXs. Both fixtures passed, including process-group handling on the pipe endpoints.AI-assisted: yes.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.