Repository navigation
feat(libkernel): implement sendfile - #3568
Merged
Merged
Conversation
PS5MC (PPSA99420) stops at start-up on sendfile. It follows FreeBSD 11: headers, the file range and trailers go to a connected stream socket, the file offset does not move, a non-blocking socket fails with EAGAIN after a partial send, and *sbytes reports what was sent. The checks and the point where *sbytes is written follow kern_sendfile.c.
9 tasks done
Contributor
|
Checked on Linux (Ubuntu 24.04, GCC 13) and Windows 11 (MinGW-w64 GCC 15.2 from WinLibs), Release, with this PR (bad1903) merged onto
|
9 tasks done
Collaborator
|
Checked on Linux with the PR merged onto current |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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(Windows: windows_exceptions fails since #1423, unwinding through runtime DLL frames (std::call_once) no longer reaches the catch #3411);guest_kernel_sys:symlinkthrowsFunction not implementedon Windows, which fix(libkernel_sys): create symlinks with CreateSymbolicLinkW on Windows #3510 addresses;guest_filesystem: restoring the directory time fails on Windows, which test(libkernel): don't require restoring the directory time on Windows #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)