fix(libkernel): close guest sockets in sceKernelClose #4053
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4053"
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 nikowolf123 on 2026-10-11T22:15:10Z.
What
sceKernelClosepassed every descriptor to the hostclose. Guest socket descriptors start at0x10000000(GuestSockets::FirstDescriptor) and are not host descriptors, sosceKernelCloseon an open guest socket returnedSCE_KERNEL_ERROR_EBADF, left the entry in the guest socket table and kept the host socket and its equeue registrations, which onlyGuestSockets::Closedrops. The call neither closed the socket nor threw.Guest sockets now go to
GuestSockets::Close, asclosedoes and assceKernelReadandsceKernelWritedo since #1727. A closed or unknown socket still returnsSCE_KERNEL_ERROR_EBADF. FreeBSDkern_closecloses a descriptor of any type. Only the guest socket table hands out descriptors from0x10000000(socket,accept,socketpair,dup,dup2).#1795 also routed guest sockets in
sceKernelClose, returning-1instead of the kernel error; it was closed as a duplicate of #1711 for its socketpair part. Open #3764 addsEqueueDescriptorClosed(d)as the first line ofsceKernelCloseand conflicts with this line; the socket check should stay first, sinceGuestSockets::Closealready callsEqueueDescriptorClosed.Tested
Ubuntu 26.04 on WSL2, GCC 15.2.0, CMake 4.2.3, Ninja, Release,
BUILD_TESTING=ON,ANYPS5_ENABLE_SPIRV_TOOLS=ON, lavapipe withANYPS5_REQUIRE_VULKAN=1, onmainaf0b52ebb. No title or homebrew.guest_socket_read_writecloses the listener withsceKernelClose, then checks that a secondsceKernelClosereturnsSCE_KERNEL_ERROR_EBADFandclosefails withEBADF. Without the fix it aborts at the first new check (0x80020009); with it, it passes./proc/self/fdaroundsceKernelCloseon a new TCP socket: 6, 7, 7 without the fix; 6, 7, 6 with it.ctest, 909 tests. Three GPU tests behave the same in 3 of 3 runs onaf0b52ebbwith and without this change:agc_vector_windowandagc_driver_prepared_shaders_registered_workgroup_syncfail, andagc_driver_packed_float16_nativeskips for a reasontools/check_skips.pydoes not expect. Every other test passes or skips as expected.python3 tools/check_conventions.py --base origin/main: all checks passed.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 Dextroid17 on 2026-10-12T01:29:18Z.
#4053: the fix applies a pattern that's already working elsewhere in this file rather than inventing new logic —
close_nid_postfix,sceKernelRead, andsceKernelWritealready route guest-socket-range descriptors toGuestSockets::Closethe same way this adds forsceKernelClose, and a closed or unknown socket still returns the sameEBADFbefore and after, so there's no behavior change for anything that already worked.The conflict with open #3764 is real but lower-severity than it might read: #3764 does add
EqueueDescriptorClosed(d)as the very first line, at the same position this PR's socket check would occupy, so the two will textually conflict on merge. But tracing whatEqueueDescriptorClosedactually does, calling it twice (once from #3764's line, once again insideGuestSockets::Close) is harmless — it's an idempotent erase-if over the equeue's event list, not a refcount decrement or a free. So whichever lands second just needs the socket check to run before the redundant equeue call, which is a one-line reordering, not a functional fix.#4154: the no-op treatment is safe, and it's consistent with how this function already treats every other advisory-only hint in range —
MADV_DONTNEEDis already accepted as a pure no-op, andMADV_PROTECT's real FreeBSD semantics (don't kill this process under swap pressure) is exactly the kind of hint a host can't grant anyway, so ignoring it only forgoes a hint, not a requirement. The value 10 matches FreeBSD's own ordering forMADV_PROTECT. One cosmetic note: removing this throw leaves theGuestAdviceCoreconstant with no remaining reference — dead but harmless, since nothing in this build is-Werror=unused.Written with AI assistance.
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-12T02:56:11Z.
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)core/libs/prx/libkernel/File/src/Open.cppL214