feat(libkernel): implement sendfile #3568
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3568"
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 DariusHQ on 2026-10-11T13:26:56Z.
What
sendfile(YA0r4LCkfeY) in libkernel. Nothing in the tree implements it yet.PS5MC (PPSA99420 1.2, VivaLaVent/PS5MC) stops at it at start-up on
main2220effbe(nothing since touches it), Windows, catalog build witheboot.binandsce_module/libc.prxunwrapped as #2605 requires (tracked in #1578):With this branch it goes on to
wcstok(8ngzWNZzFJU):Its only call site is in libmicrohttpd (Kodi's web server,
connection.c), which sends file responses with it.It follows FreeBSD 11's
kern_sendfile.c:offset(to its end whennbytesis 0, only headers and trailers past the end), then trailers;EAGAINafter a partial send, with*sbytessaying how far it got;EINVAL), more than 1024 header or trailer entries (EINVAL) and an unreadable file (EBADF) fail before anything is sent and leave*sbytesalone;EINVAL), an unconnected socket (ENOTCONN) and a descriptor that is not a socket (EBADF, as forsend) fail with*sbytesset to 0, as FreeBSD writes it once the file is open.The file is read with
sceKernelPreadin 64 KiB blocks and sent withsend, soflagsare ignored. TechnicalDebt lists where that differs from FreeBSD: any descriptorsceKernelPreadreads is accepted as the file,ENOTSOCKisEBADF,SF_NODISKIOnever fails withEBUSY, andSF_SYNCreturns once the data is queued.Tested
Windows 11 (26200), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, full build with
BUILD_TESTING=ONonmaina11c8f7f7with four branches merged together: this one and the%#.0o,'flag, positional-argument andsendfilebranches opened alongside it:ctest833/837 passed. The four failures fail the same way onmainhere:windows_exceptions(#3411);guest_kernel_sys:symlinkthrowsFunction not implementedon Windows, which #3510 addresses;guest_filesystem: restoring the directory time fails on Windows, which #3518 addresses;agc_driver_emulated_color_compare: the GPU here cannot sample the sRGB image it uses.guest_sendfile, on asocketpair, checks:*sbytes;nbytespast the end of the file, an offset past the end (headers and trailers only), null header pointer with a count, nullsbytes;*sbytes;EAGAINfrom a non-blocking socket fed a 32 MiB file with no reader, and that the bytes*sbytesreports arrived intact.It passed 10/10 runs. Mutation check, all caught:
*sbyteswritten for an unreadable file;nbytesignored;ESPIPEinstead ofEINVALfor a socket as the file;EAGAIN.tools/import_audit.pyon PS5MC relinked with--windows --registry: absent imports go from 28 to 27.Not run on Linux (no Linux host here). The code is shared; on Linux it sends with
MSG_NOSIGNAL, so a closed peer givesEPIPErather than a hostSIGPIPE.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)Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-11T13:27:23Z.
Progress report (
a11c8f7→bad1903)📈 System libraries: 85.82% (+0.01%, +1 implemented functions)
✅ 1 implemented
sendfile_nid_postfixImported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-11T14:46:09Z.
Checked on Linux (Ubuntu 24.04, GCC 13) and Windows 11 (MinGW-w64 GCC 15.2 from WinLibs), Release, with this PR (
bad19037) merged ontomaina11c8f7f.guest_sendfilepasses 5/5 on both (--repeat until-fail:5); no warnings in the changed files on Windows.sendfileon both. OnmainWindows stops atFAIL: unresolved ELF import YA0r4LCkfeY (sendfile) from libkernel.prx; with this PR it stops atFAIL: unresolved ELF import 8ngzWNZzFJU (wcstok) from libSceLibcInternal.prx(#3583). Linux gives the same:undefined symbol: 8ngzWNZzFJU.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-11T18:36:26Z.
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)docs/dev/TechnicalDebt.mdL605-606Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T21:43:10Z.
Checked on Linux with the PR merged onto current
main: builds,guest_sendfilepasses 5/5, and it doesn't link without the change. Reviewed the header/trailer limits, the*sbyteshandling on each error path, theEAGAINpartial count and the TechnicalDebt entry against FreeBSD 11kern_sendfile.c. Windows runs by @babyhuey and your own cover the MinGW side. Merging.