feat(libkernel): export the underscore entry points of the socket, directory and signal calls #8700
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/8700"
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-20T21:31:38Z.
What
maindoes not export 15 libkernel names that the PS5 3.20 libkernel exports:_accept,_bind,_connect,_getdirentries,_getpeername,_getsockname,_getsockopt,_listen,_recvfrom,_recvmsg,_sendmsg,_sendto,_setsockopt,_sigactionand_sigsuspend. A title that imports one fails at startup with a missing import. These are FreeBSD libc's private names for the calls:namespace.hdefinesacceptas_acceptand so on, except forsigaction, whose line is commented out.Each name is now exported and forwards, with the same arguments, to the AnyPS5 export without the underscore, as
_close,_ioctland_nanosleepalready do:_accept(B+zfF7bMswI)acceptacceptadds libthr's cancellation point_bind(4boImm4wxu0)bindbind_connect(KFDGyLj80MY)connectconnectadds a cancellation point_getdirentries(sfKygSjIbI8)getdirentriesgetdirentries_getpeername(rTNM7adVYog)getpeernamegetpeername_getsockname(6Gwl39KKUEI)getsocknamegetsockname_getsockopt(cL2QUlo9Vnk)getsockoptgetsockopt_listen(6EYF3tXjXbU)listenlisten_recvfrom(gPcQ3OrFBUA)recvfromrecvfromadds a cancellation point_recvmsg(PcKApW9kVoQ)recvmsgrecvmsgadds a cancellation point_sendmsg(+L22kkFiXok)sendmsgsendmsgadds a cancellation point_sendto(lvDhwhUC05E)sendtosendtoadds a cancellation point_setsockopt(a4KKvF-ME4M)setsockoptsetsockopt_sigaction(UDCI-WazohQ)sigactionsigactiongoes to libthr's__thr_sigaction, which wraps handlers and rejectsSIGCANCEL(32)_sigsuspend(9zpLsLESzTs)sigsuspendsigsuspendadds a cancellation pointThe AnyPS5 exports without the underscore have no libthr layer. The existing debt entries say so: "file and socket calls are not cancellation points" (Thread cancellation) and "None of the five waits is a cancellation point" (
pause, sigsuspend, sigwait, sigwaitinfo).sigactionreports the guest's own handler and accepts signal 32. So forwarding gives each underscore name the system call's behaviour, as far as the exports without the underscore model it.Results and error values are those of the exports without the underscore, which this PR does not change. The new test checks the following through the underscore names:
_bind: returns0for127.0.0.1:0. Binding the bound socket again givesEINVAL(22). A closed descriptor givesEBADF(9)._listen: returns0on a stream socket. A datagram socket givesEOPNOTSUPP(45), a closed descriptorEBADF._accept: returns a new descriptor and the peer's 16-byte address, which equals the client's_getsockname. A stream socket that is not listening givesEINVAL. A closed descriptor givesEBADFand leaves the address and length untouched._connect: returns0on a stream socket and on a datagram socket. A 15-byteAF_INETaddress givesEINVAL, a closed descriptorEBADF._getsockname,_getpeername: return the 16-byte addresses of both ends of a TCP connection and the peer of a connected datagram socket. A closed descriptor givesEBADFand leaves the outputs untouched._getsockopt,_setsockopt:TCP_NODELAYreads0, then4once set, with length 4.TCP_MAXSEGgivesENOPROTOOPT(42). A closed descriptor givesEBADFand leaves the value and length untouched._sendto,_recvfrom:127.0.0.1and the sender's port);MSG_OOBgivesEOPNOTSUPP;EBADFand leaves the buffer, address and length untouched._sendmsg,_recvmsg:0;MSG_TRUNC(0x10);EFAULT(14);EBADF._getdirentries:.,..and one file with*basep= 0;*basepare thosegetdirentriesreturns from the same position;0with a positive*basep;EINVAL, a null bufferEFAULT, a closed descriptorEBADF; each leaves the buffer and*basepuntouched._sigaction:SIGTERM(15) handler thatraiseruns, and reports the previous and current action;SIGKILL(9) orSIGSTOP(17), giveEINVALand leave the old action untouched._sigsuspend:SIGUSR1(30) is blocked and pending, with a handler set by_sigaction. An empty mask delivers it to the handler and returns-1withEINTR(4), and the blocked mask is restored afterwards.The 12 socket forwarders form one
extern "C"block at the end ofcore/libs/prx/libkernel/Socket/src/Udp.cpp. Many open pull requests edit the bodies of the socket calls in that file, and none edits its end._getdirentriesfollowsgetdirentriesinFile/src/Stdio.cpp._sigactionand_sigsuspendfollow their counterparts inSystem/src/Signals.cpp. The test is a new file,core/libs/tests/GuestUnderscoreEntries.cpp, registered afterguest_socket_connect_listening.Sources (pinned):
libkernel.c: the stubs at L347-L606 include these 15 names, and L7873-L7910 resolve them by the NIDs in the table.compute_nidintools/nid_names.pygives the same NIDs.release/11.4.0, commit 8c639945a4):lib/libc/amd64/SYS.hL39-L50:RSYSCALL(name)defines__sys_namewith the weak aliasesnameand_name;PSEUDO(name)gives it only_name.lib/libc/sys/Makefile.incL33-L81:accept,connect,recvfrom,recvmsg,sendmsg,sendto,sigsuspendand, on amd64,sigactionareINTERPOSED. Their stubs arePSEUDO, and the public name is a C function that calls through__libc_interposing, as inaccept.cL43-L50.bind,getdirentries,getpeername,getsockname,getsockopt,listenandsetsockoptare insys/sys/syscall.mkand are not interposed. The amd64MDASMandNOASMlists do not name them, andlib/libc/syshas no C file for them, so each gets the generatedRSYSCALLstub.lib/libthr/thread/thr_syscalls.cL639-L692 points those slots at libthr.__thr_accept(L98-L110) and theconnect,recvfrom,recvmsg,sendmsgandsendtoversions only wrap__sys_*in_thr_cancel_enterand_thr_cancel_leave.lib/libthr/thread/thr_sig.cL517-L584:__thr_sigactionrejectsSIGCANCELand installsthr_sighandlerwith__sys_sigaction. L621-L644:__thr_sigsuspendis a cancellation point.Symbol.mapexports_sigactionand_sigsuspendinFBSDprivate_1.0. libthr'spthread.maplists neither, andversion_gen.awkL227-L230 makes unlisted symbols local. So the exported_sigsuspendis libc's system call stub, not libthr's internal_sigsuspend.Not verified on a console: that the PS5's underscore entry points take FreeBSD's arguments and behave as the system call without libthr. A new entry in
docs/dev/debt/libkernel.md(Functional, afterioctl, _ioctl) records this, together with two differences from FreeBSD 11.4:_sigactionshares one handler table withsigaction. In FreeBSD,sigactionhands libthr's wrapper to the system call that_sigactionreads back, and rejectsSIGCANCEL(32)._sigsuspend, as insigsuspend. The system call that FreeBSD 11.4 exports as_sigsuspendreturnsEFAULTthere, but libthr defines its own global_sigsuspend(thr_sig.cL613-L619) that dereferences the set (L126-L131). A PS5 libkernel that merges libc's stubs with libthr could export either, so the throw stays until the console's answer is measured.The behaviour of the exports without the underscore keeps its existing entries.
Overlap: no open or closed pull request adds any of these names; I searched for each name in titles and bodies. Some open pull requests change the exports these names forward to, and the underscore names would follow them. None of them changes a case the new test asserts. For example:
accept;getsocknameandgetpeername;recvfrom;getsockoptandsetsockopt;sigactionflags;sigsuspendmask;sendmsg.The new test does not check any case these change. Every open pull request that touches any of the five existing files this PR changes, and still merges with
main2c4b116da, also merges with this branch (three-way merge of those files). #8742 conflicted with the earlier place of the new debt entry, aftergetsid, which it rewrites; the entry now followsioctl, _ioctl.Tested
Linux: WSL2 Ubuntu 26.04 LTS (kernel 6.18.33.2-microsoft-standard-WSL2), g++ (Ubuntu 15.2.0-16ubuntu1) 15.2.0, CMake 4.2.3, Ninja, Release,
-DBUILD_TESTING=ON. I built thelibkernelandguest_underscore_entry_teststargets, with no compiler warnings, and ranctest -R '^guest_underscore_entries$' --output-on-failure --timeout 120:maina6a4101e19:guest_underscore_entriespassed, 1/1 in 0.02 s; again 1/1 at0ac2b0bc6, one commit onmain2c4b116da. The What section lists what it checks.main's library (a6a4101e19plus only the test and its registration):guest_underscore_entry_testsdoes not link.ldreports undefined references to all 15_*_nid_postfixnames, becausemaindoes not define them; there is no stub to throw.tools/check_conventions.py --base origin/mainpasses.tools/progress.py --module libkernelreports 643/681 done functions, up from 628/666 onmain2c4b116da. The 15 functions added as done are the_*_nid_postfixforwarders in the table; no other name changes.g++ -std=gnu++20 -fsyntax-onlypasses on the three changed library sources. It also passes on the test with-Wall -Wextra, with no warnings.Windows: not built. No title was run.
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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by ycbuzi on 2026-10-21T04:58:01Z.
Windows run of c71074de97 merged onto
main1fd67185b6(9f2f7de645, clean), the build the description lists as not done. Windows 11 Home 10.0.26200, MinGW-w64 GCC 15.2.0 (ucrt-posix-seh r7), Release,BUILD_TESTING=ON.Built
libkernelandguest_underscore_entry_testswith no errors or warnings;ctest -R "^guest_underscore_entries$" --repeat until-fail:3: passes every repeat (0.02 s a run). Not run: the negative control againstmain's library, a title.