fix(libSceNet): keep close-on-exec for fcntl on a sceNetSocket socket as FreeBSD does #16826
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/16826"
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 Ragbie on 2026-11-07T17:22:50Z.
What
On a socket created with
sceNetSocket, guestfcntl(F_GETFD)andfcntl(F_SETFD)failed withEINVAL, whileioctl(FIOCLEX)andioctl(FIONCLEX)already set the close-on-exec flag of the descriptor beneath it (#15890 recorded this indocs/dev/debt/libkernel.md). FreeBSD 11.4 keeps that flag in the descriptor table for every descriptor, whatever the file type:kern_fcntlreads and writesUF_EXCLOSEforF_GETFD/F_SETFD,kern_ioctlchanges the same flag forFIOCLEX/FIONCLEX, and_finstallstarts a new descriptor with it clear unlessO_CLOEXECis given.libSceNet/Export.cpp:ControlSocketStatusForKernelno longer answersF_GETFDandF_SETFD, sofcntltakes them toFile::Fcntl, which reads and writes the recordFIOCLEXalready uses.F_GETFL/F_SETFLstay with libSceNet; every other command still fails withEINVAL, as the debt entry now says.Socket/src/Udp.cpp:KernelReserveSocketNumber_nid_no_patchrecords the new number with the flag clear, andKernelReleaseSocketNumber_nid_no_patchforgets the record before the number is closed. Without the first, the File record of a new socket on Linux and macOS was built from the host descriptor, whichF_DUPFD_CLOEXECcreates withFD_CLOEXEC, soF_GETFDreturned 1. Without the second, a later descriptor reusing the number that does not record itself (for exampleshm_openon Linux) inherited the socket's record.Tested
guest_sce_net(CheckKernelStatusFlags):F_GETFDis 0 on a new socket,F_SETFD/FIONCLEX/FIOCLEXround-trip throughF_GETFD,F_GETFLis unaffected, and a socket that reuses the number of one closed with the flag set starts clear.mainwith the new test (the old expectation was-1/EINVAL), passes with this PR. Fullctest, run as the non-GPU tests (3021) and then the GPU tests (1504): the only failures areselect_tests_MissingCommandTests,agc_driver_image_plane_address_on_line,agc_driver_image_sample_lod_clampandagc_driver_image_sample_lod_clamp_shader_lane, which fail onmainon this machine too, andvulkan_validation_gate_commands, whose symbolic-link case needs a privilege this account lacks. After rebasing ontomain12dafe4160, the 52guest_sce_net,guest_net*,guest_socket*andguest_recvmsg*tests pass.guest_sce_netpasses; an earlier version that only forgot the record on release failed it there (the new socket reported 1), which Windows did not show.python tools/check_conventions.py --base upstream/mainpasses.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 MarcZX10 on 2026-11-21T05:01:11Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the implementation and added test cover the described close-on-exec behavior.
What I ran
Reviewed head
28c672092a1d85a13f6984898f02a7f5868c0ef6. No tests or builds were run. Readdescription.md,commits.md,manifest.json,diff.patch,Export.cpp,Udp.cpp,GuestSceNet.cpp, andDescriptorControl.cpp; all changed files listed in the manifest were included and read.files.jsonwas not available through the reader.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The reported Windows and Linux test runs were not independently reproduced. No other files were excluded according to the manifest.
To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T16:29:38Z.
Review: COMMENTED
This head conflicts with current main in
libSceNet/Export.cppandGuestSceNet.cpp. Main now retains the supportedF_SETFLstatus bits on the native socket and checks their inheritance throughaccept. Keep that status handling and those tests when adding theF_GETFD/F_SETFDfall-through and the descriptor-reuse check. After this test sets status flags,F_GETFLshould still return2 | keptwhile the close-on-exec flag changes independently.Please carry the debt entry change in a fragment under
docs/dev/debt/changes/.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.