fix(libkernel): fail read, write and seek on a ksem id as FreeBSD 11.4's ksem_ops does #24487
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/24487"
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 brajankw on 2026-11-20T17:28:42Z.
What
A ksem id is a descriptor reserved on the host null device here, so
readreturned 0,writethe length, andlseekandpread0. FreeBSD 11.4'sksem_opsreads and writes throughinvfo_rdwrand is not seekable:read,write,readv,writevand theirsceKernelforms fail withEOPNOTSUPP; a zero-length read returns 0 first, asdofilereadfinishes it before the file's read, while a zero-length write fails.lseek,pread,pwrite,preadv,pwritevand theirsceKernelforms fail withESPIPE, before thewhenceand offset checks, askern_lseekanswersESPIPEbeforefo_seekseeswhence.lseekno longer checkswhencefirst for a ksem id; a kqueue, a socket or a pipe still getsEINVALthere for a badwhence, as before.EFAULT, asinvfo_rdwrtouches no buffer. #24486, now merged, does the same for a kqueue on the same line.invfo_rdwr.IsKsemDescriptor, which this uses, is replaced byDuplicateKsemDescriptorin open #22191. The two merge without a textual conflict, but whichever lands second needs a rebase that keeps a ksem predicate, or the build breaks. I will rebase this as soon as #22191 lands.TransfersinGuestKernelSysKsem.cppcalls every POSIX andsceKernelread, write and seek entry point, including a badwhence, zero-lengthpreadandpwrite,preadvwith count 0 andpwritevwith a zero-length vector; the semaphore's value is unchanged afterwards.Tested
Linux (Debian 13, GCC 14.2.0, Release). Head
f78c18f92a, rebased ontomain14e9b90825after #24960 merged; the only conflict wassceKernelLseek, which #24960 wraps inFile::RunKernelFileCall. The runs after the first two bullets are from earlier heads.f78c18f92a, with #24488 on top:ctest -R '^guest_(kernel_sys_ksem|kqueue|kqueue_cleared_race)$': 3/3 passed. This head addssceKernelWritev,sceKernelPwriteandsceKernelPreadvcalls toTransfers.dc5a8ef290, merged with my eight other updated branches ontomainbd9a6c00a6:ctestover the 23 tests these branches touch (guest_kernel_ioctl_fionread,guest_kernel_ioctl_device_type,guest_kernel_fcntl*,guest_kernel_app_archive_*,guest_kernel_sys_ksem,guest_kqueue,guest_equeue_events,guest_socket_events,guest_system_configuration,guest_socket_pair,guest_recvmsg_memory,guest_kernel_sys_cpuset,np_uds_events,guest_np_uds_*andguest_np_trophy_*): all pass. With thelseekchange reverted,guest_kernel_sys_ksemfails at the newlseek(d, 0, 7)check.main84e16538d4,guest_kernel_sys_ksemfails at the first newreadcheck.f00eb79b35,ctestoverguest_kernel_sys_ksem,guest_kqueue,guest_kernel_sys,guest_filesystem,guest_file_vector,guest_kernel_sys_aio,guest_equeue_events,guest_kernel_fcntl,guest_kernel_ioctl_fionreadandguest_kernel_ioctl_device_type: all 10 pass.ctest(6393 tests,-j 12) on this branch and my other eleven branches of this round, merged ontomain84e16538d4: 6378 passed. The 15 failures also fail onmainin this environment:.gitdirectory, network access or a passwd entry for the user:conventions_git_errors,test_script_registration,web_library_assets,title_run,title_run_identity,guest_kernel_sys_login,guest_net_ctl,guest_getloginandguest_getlogin_no_session;agc_driverGPU cases fail the same way onmain:prepared_shaderswith itsindirect,uncachedanddebugforms, andstorage_file_write;agc_driver_image_table_packed_guardsis unstable onmainas well (2 of 10 runs passed on its own onmain3f4693be43).python3 tools/check_conventions.py --base origin/main: passed.python3 tools/pr_overlap.py --branch fix/libkernel-ksem-read-write-seek: #22191 adds a call in the same place ofGuestKernelSysKsem.cpp'smain(line 300), so whichever lands second needs a rebase, which also covers theIsKsemDescriptorpoint above; could not compare #6936, #7121, #7447, #9293, #9297, #9302, #12682, #12688, #12700, #12965 and #15037, which conflict withmain; none of them changes the ksem or kqueue checks this touches.python3 tools/pr_overlap.py --branchon the stack atad4b485923(#24488 on this head): only #22191 (the testmainline above) is listed as conflicting.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 PrivacyOnion on 2026-11-20T17:56:08Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
f00eb79b35:tools/check_conventions.pypassed.guest_kernel_sys_ksem_tests,guest_kqueue_testsbuilt cleanly.guest_kernel_sys_ksem,guest_kqueue,guest_kqueue_cleared_race):core/libs/prx/libkernel/File/src/Open.cpp,core/libs/prx/libkernel/File/src/Stdio.cppreverted tomainand the new tests kept, the suite fails: Restoring the change makes it pass again.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T05:38:26Z.
Review: COMMENTED
Reviewed — comments
The review covered all four changed files at head
f00eb79b35838a3e76f7870c9f5a8bfee207e1e5; one test gap remains, so a formal approval is not justified.What I ran
Read the prepared diff and all changed files at the pinned head through
repo_read.py. No commands or tests were run during this review.Results
Findings
Blocking
None.
Non-blocking
Transferstest exercisespreadv/pwritevwith one nonempty vector, but does not test zero-vector or zero-length positioned I/O. These calls go throughPositionedArgumentErrorbefore any transfer and should returnESPIPEfor a ksem descriptor regardless of offset or vector length. Add cases for zero-lengthpread/pwriteand zero-countpreadv/pwritevto pin that behavior. Changed line:core/libs/tests/GuestKernelSysKsem.cpp:317.Not verified
files.jsonwas not available in the prepared review bundle; the manifest lists four changed files, and all four full file texts were read.To get this to a good state
Nothing is required. Optional: add zero-length and zero-count positioned-I/O cases to
Transfers.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T09:29:09Z.
Review: COMMENTED
Reviewed — no blocking findings
The descriptor-specific transfer and seek handling matches the intended ksem behavior in the inspected paths; I did not run checks on this head, so a formal approval is not justified.
What I ran
Reviewed head
dc5a8ef290c7f4b2571611d8ffb5a7a0e281b69eusingrepo_read.pyto inspect the prepared review packet and targeted source ranges. No tests or build commands were run. The author reports test results in the PR description; these were not independently verified.Results
Negative control
Not run in this review. The author reports that the new test failed on the prior main revision.
Findings
Blocking
None.
Non-blocking
GuestKernelSysKsem.cppdoes not directly exercisesceKernelWritev,sceKernelPreadv, orsceKernelPwrite; adding those cases would cover the remaining public entry points.Sources
Open.cpp: the read, write, and seek branches check ksem descriptors before host buffer handling orwhencevalidation.Stdio.cpp: positioned transfers returnESPIPEfor ksem descriptors; vector transfers reuse the kqueue result behavior.GuestKernelSysKsem.cpp: added tests cover POSIX andsceKerneltransfer/seek behavior, including zero-length operations.Not verified
files.jsonwas not available through the review reader. The manifest lists three changed files, all marked included; I inspected changed code inOpen.cpp,Stdio.cpp, andGuestKernelSysKsem.cpp. No excluded changed file was listed in the manifest.To get this to a good state
Nothing is required. Optional: add direct coverage for the remaining public entry points noted above.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T11:38:22Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the implementation handles the ksem transfer and seek cases described, and the inspected tests cover the stated edge cases.
What I ran
Reviewed head
f78c18f92a4bc99249a5536d60946e6e7271d4c9using the prepared diff and pinned repository reader. No commands or tests were run.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
No tests were run. The author reports focused tests passed, but those results were not independently confirmed. The excluded-file manifest was unavailable, so excluded files are not verified. Read:
Open.cpp,Stdio.cpp,GuestKernelSysKsem.cpp, andKsem.hpp. All three changed files marked included inmanifest.jsonwere read, though only targeted ranges in the production files. No excluded files were read.To get this to a good state
Nothing is required.