fix(libs): allow socket receives into watched guest memory #4272
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4272"
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 Ondra97 on 2026-10-12T03:42:56Z.
What
Socket receives into CPU-writable guest direct memory fail after Windows write tracking protects the destination pages. libkernel reports
EFAULT, while libSceNet translates the nativeWSAEFAULTintoEIO.Bracket native
recvandrecvfromwith the existingGuestArena::HostWriteguard in both libraries. The destination stays writable throughout a blocking call and remains visible to write tracking when the call finishes. A genuinely read-only destination returnsEFAULTwithout consuming queued data. Zero-byte calls use an empty guard range so they keep their existing behavior. SocketreadandsceKernelReadinherit the fix throughGuestSockets::Read.Add Windows integration tests for all six APIs over UDP and TCP, and update the write-watch debt entry. Related PR #4092 changes timeout error translation in the same SceNet functions; its patch applies cleanly alongside this fix and neither change depends on the other.
Tested
Windows x86-64, Release, supported WinLibs GCC 15.2.0 UCRT/POSIX/SEH r7; standalone tests through the real libkernel, libc and libSceNet APIs.
EFAULT/EIO.BUILD_TESTING=ON, including the patched libraries, completed successfully.MSG_PEEK, zero-byte operations, errno preservation,EAGAIN, read-only destinations, dirty tracking, and collection while a receive is blocked.Linux/macOS runtime and a PS5 title were not run locally.
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 MarcZX10 on 2026-10-12T03:45:09Z.
Review: COMMENTED
I found one remaining watched-output path in the recvfrom variants. The new
HostWriteguard coversbuf, but after a successful receiverecvfrom_nid_postfixcallsGuestAddress(peer, address, length)andsceNetRecvfromcallsnative_to_guest_address(peer, from, fromlen); both write the address bytes and returned length directly. If either output points into write-protected watched guest memory, that write can still fault (or bypass the tracker). Could you add a regression with the optional address and length outputs in watched guest memory and guard those writes too?Imported from boykopovar/AnyPS5. Originally posted by Ondra97 on 2026-10-12T04:12:36Z.
@MarcZX100 Added the regression coverage in 1e429dc.
For both
recvfrom_nid_postfixandsceNetRecvfrom, the IPv4 UDP tests now put the sender address and returned length on separate watched guest direct-memory pages, independently of the payload buffer. They cover a watched address, a watched length, and both together. Each case verifies the returned data, address and length, errno preservation, the expected dirty-page counts (4/4/8), a clean second collection, and rearmed read-only protection.All six output scenarios pass with the current Windows implementation. These outputs are CPU writes; the existing Windows exception handler calls
GuestArenaHandleWriteand resumes those writes while recording them. I did not reproduce a crash or lost tracking for CPU-writable watched output pages. This commit adds regression coverage; the production address-copy code is unchanged.Validated with the supported WinLibs GCC 15.2.0 Release build: full build passed, all 12 UDP/TCP regression tests passed ten consecutive runs each, and conventions passed. Linux/macOS runtime behavior has not been verified locally.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-12T04:14:25Z.
Review: COMMENTED
Thanks for adding the watched address and length cases. I rechecked the Windows write-watch path:
GuestArenaHandleWriterecords these CPU writes and resumes execution, and your new regressions exercise the address and length outputs independently and together. That resolves my earlier concern; I have no further issue on those outputs.