fix(libkernel): pread, read and APR reads into write-tracked guest memory through a staging buffer #182
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/182"
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 MichonGoddijn231849 on 2026-09-30T11:50:06Z.
What
On Windows,
preadinto a guest destination thatReadFilerefuses now goes through a staging buffer. WhenReadFilefails withERROR_NOACCESSorERROR_INVALID_USER_BUFFER, the read lands in a host buffer and is copied to the destination. The copy is an ordinary write, so the write tracking's fault handler sees it as usual. A remaining failure now reports the Windows error code as well as errno.The same refusal hits two more read paths, handled the same way:
read(sceKernelRead):_readfails withEINVAL; the read is retried from the same file position into a staging buffer.sceKernelAprSubmitCommandBufferread commands):std::ifstream::readinto the destination fails; it now reads through a 4 MiB staging buffer in chunks.Since the shared-mapping and write-tracking commits (
abb9c85,f7c53a4,5e08eb4), a guest page can be read-only until its first write.ReadFilewrites into it from kernel mode, which doesn't raise the user-mode fault that would lift the protection, so the read fails andpreadthrowserrno=5.Tested
Windows 11 Pro, AMD Ryzen 5 7600 (6-core), NVIDIA GeForce RTX 5080 (driver 32.0.16.1074), 32 GB DDR5-5600, MinGW-w64 GCC 15.2.0.
main: the Story Mode load aborted withpread_nid_postfix: pread failed, fd=81, errno=5, and gets through with this change.mainwith #167 and #134: the character creation head textures (APR) aborted withAPR: read failed for ...head_09_col.chunk1.ctxc, and then the Bink video thread withsceKernelRead: read failed, fd=3, errno=22. Both load with this change.libkernelbuilds.Checklist
main; no other open PR implements the same functions.mdfiles or images added to the repositoryImported from boykopovar/AnyPS5. Originally posted by boykopovar on 2026-10-01T07:55:24Z.
This adds error-driven fallbacks to
readandpread: a failed direct read is retried through a staging buffer. Such fallbacks are not allowed, andEINVALdoes not specifically identify a write-tracking protection fault.Please implement a consistent read path that supports guest memory protection by design across
read,pread, and APR. Choose the appropriate path before performing I/O, rather than retrying after an error. Failures must remain explicit; APR must not silently accept incomplete reads.Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-01T17:26:24Z.
Thanks for the review. Reworked as #232: one read path for read, pread, AIO and APR that pins write-tracked pages before the I/O (no retry after an error), EFAULT for unwritable destinations, and APR throws on short reads.
Pull request closed