feat(libkernel): implement pselect over select #9273
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9273"
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-21T17:09:01Z.
What
pselectwas a discovery stub inlibkernel_systhat threwNotImplemented. It is now implemented in libkernel, inlibkernel/Socket/src/Pselect.cppbesideselect, and the libkernel_sys stub is removed. It is built on libkernel'sselectandsigprocmask, as FreeBSD 11sys_pselect/kern_pselect(sys/kern/sys_generic.c) do:TIMESPEC_TO_TIMEVAL's truncation (tv_usec = tv_nsec / 1000), andselect's own timeval check rejects what FreeBSD'sitimerfixrejects. Sotv_nsecof 1,000,000,000 or more givesEINVAL, 999,999,999 is accepted, andnfds < 0givesEINVAL.sigmaskis installed withSIG_SETMASKbefore the wait and the previous mask is restored after it, keepingselect'serrno. Asigprocmaskfailure returns -1 before any wait.Moved to libkernel so libkernel imports reach it on Windows. The PS5 3.20 export lists have
pselectin libkernel as well as libkernel_sys, and on Windows a libkernel import never searches libkernel_sys (WindowsEntryStubBuilder.cpp:175). With the libkernel export and no libkernel_sys stub, both imports reach it, and the duplicate-export rule holds. The code is unchanged by the move.A debt line in
libkernel.mdrecords that the mask swap is not atomic with the wait: a signal that becomes deliverable between the swap and the wait is not guaranteed to interrupt it.Tested
Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7, Release. This is a CPU-side export, so no GPU is involved.
guest_kernel_sys_pselect(core/libs/tests/GuestKernelSysPselect.cpp), on a pipe:SIGUSR1blocked throughsigmaskand the original mask back afterwards;tv_nsec999,999,999 and with a NULL timeout;tv_nsec1,000,000,000 givesEINVALwith the mask restored;nfds-1 givesEINVAL.mainthe test aborts withpselect_nid_postfix not implemented. On this branch it passes, 3 of 3 runs.guest_kernel_sysstill passes, andtools/check_conventions.py --base origin/mainpasses.Pselect.cppremoved from libkernel's sources, the test fails to link (undefined reference to pselect_nid_postfix), so it reaches libkernel's export.pselectis exported by libkernel only.tools/pr_overlap.pycrashes on this machine's partial clone, so I rangit merge-treeagainst every open PR that touches these files. Removing the libkernel_sys stub conflicts textually with #9160 and with my #9156, which edit the neighbouring stubs. That's a one-line resolution, by mergingmainafter either lands. Everything else merges cleanly.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 github-actions[bot] on 2026-10-21T17:09:49Z.
Progress report (
0c6a5bd→375b53d)📈 System libraries: 42.11% (+0.01%, +1 implemented, -1 removed functions)
✅ 1 implemented
pselect_nid_postfix🗑️ 1 removed
pselect_nid_postfixImported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-21T19:43:44Z.
Independent Windows run of this PR (data only).
Environment: Windows 10 Pro 10.0.19045, Ryzen 7 5800X3D, WinLibs GCC 15.2.0 r7 (MinGW-w64 UCRT), Release, BUILD_TESTING=ON. Merge-tree of the PR head against
mainis clean. I built onlyguest_kernel_sys_pselect_tests;ctest -N -R guest_kernel_sys_pselectlists exactly one test.PR head tested:
17650eed5f911ead4c7c32edf3a3d4815d56bca9.Results (3 runs each):
guest_kernel_sys_pselectpasses 3/3.core/libs/prx/libkernel_sys/Export.Discovery.cppwith the version from the PR's merge base (d34da5d694), then rebuilt. The test fails 3/3 (exit 0xc0000409). I restored the PR's files afterwards.Not run: other platforms, the other tests in the same family, the full repository CTest, and any title or console run.
AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by DavidSamir on 2026-10-22T02:06:17Z.
Linux: Ubuntu 24.04.1 LTS (WSL2), GCC 13.3.0, Release; head
375b53d91merged ontomain8c26eac3c.guest_kernel_sys_pselectpasses 3/3.pselect_nid_postfixrenamed inPselect.cpp(instead of removing the file from the sources), the test fails to link:undefined reference to pselect_nid_postfix, as listed.Run from the PC (Windows host, Linux in WSL2), not from the PR author's machine.
Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-22T18:32:53Z.
Review: COMMENTED
Checked against main
a6646f8464and FreeBSD release/11.4.0sys/kern/sys_generic.c(sys_pselect/kern_pselect,kern_select):TIMESPEC_TO_TIMEVAL(truncation, also for small negativetv_nsec). TheEINVALcases fortv_nsec >= 1000000000andnfds < 0matchkern_select's checks, and the mask is restored witherrnokept. Thanks for the clear tests.select_nid_postfix(Socket.cpp) has noEINTRpath; it waits until a descriptor is ready or the timeout ends. And_sigprocmask(Signals.cpp:583-586) runs the handler of a pending signal thatSIG_SETMASKunblocks synchronously, inside the call. So by my reading the usual pselect idiom doesn't interrupt the wait: blockSIGUSR1,raise(SIGUSR1), thenpselect(0, NULL, NULL, NULL, &{0, 300000000}, &empty). FreeBSD returns -1/EINTRat once (kern_selectsleeps withPCATCH). Here the handler runs insidesigprocmask, thenselectwaits the full 300 ms and returns 0, and with a NULL timeout it wouldn't return. Apthread_killfrom another thread during the wait only marks the signal pending, so it doesn't end the wait either. I didn't get to run a probe for this, so it's from reading the code.EINTRwhensigmaskunblocks a signal that is already pending?sigpendingbefore the swap gives that set: let the swap deliver it, restore the mask and skip the wait. That would cover the idiom above.selecthas noEINTRpath. It could also say that the mask swapped here is the process-wide one, so it applies to every thread for the duration of the wait.Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.