fix(kernel): keep the file offset in Windows AIO reads and writes #1135
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1135"
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 orbz22 on 2026-10-07T13:30:11Z.
What
On Windows,
NativePread/NativePwriteincore/libs/prx/libkernel/Aio/src/Aio.cppseeked a_dupof the descriptor and read or wrote through it._dupduplicates the OS handle, and a duplicated handle refers to the same file object, so it shares the file position: every AIO request moved the title's own descriptor to the end of the request. The Linux path usespread/pwriteand leaves the offset alone.The Windows path now saves the descriptor's offset, seeks the descriptor itself, transfers, and restores the offset (throwing if the restore fails). Both functions share one helper; the existing size limits and error reporting (
EBADFfor an invalid descriptor, as the batch test withfd == -1checks) are unchanged. The save and restore is not atomic with respect to another thread reading or writing the same descriptor at the same time.GuestAio.cppnow seeks the batch descriptor to offset 2 and checks that it is still 2 after the write batch and after the read batch.Tested
Windows 11, MinGW-w64 GCC 15.2.0 (WinLibs r7), CMake 4.4.4, Ninja 1.13.2, on
e79c971f.Aio.cppfrommain,guest_aio_testsaborts withAio check failed at line 109(the check right after the write batch at offset 8).ctest -R '^guest_aio$' --repeat until-fail:3: passed 3/3.--target libs, fullctest: 393/393 passed.pread/pwritedo not move the offset.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)🤖 Generated with Claude Code
https://claude.ai/code/session_01UTjpbMX7BUFMZZaxJE98zV
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-08T08:02:18Z.
Review: CHANGES_REQUESTED
Checked: build + full ctest green,
guest_aiopasses, Linux/Windows CI green on the head. Two things before merging:Stdio.cppalready hasNativePositioneddoing the same save/seek/restore on Windows (and #1131 extends it). Please reuse that one fromAio.cpp(expose it from libkernel) instead of adding a second copy; ideally rebase this on #1131.read/writeon the same descriptor. Please record that under### Functionalin TechnicalDebt (#1131 has the same line for the vectored calls).Imported from boykopovar/AnyPS5. Originally posted by orbz22 on 2026-10-09T02:20:57Z.
@adriadam10 thanks for the review. Rebased on current
mainand reworked as you asked (6335c068):mainnow has0fb192c4, which givesAio.cppits own overlappedNativePositioned. That version does not restore the file pointer, so an AIO request still moves the descriptor's offset. I removed it andAio.cppnow calls the one inStdio.cpp. That function is exposed asNativePositioned_nid_no_patchand declared inFile/include/File.hpp, insideextern "C"like the other_nid_no_patchhelpers.Aio.cppkeeps theoffset < 0->EINVALcheck that0fb192c4added.### Functionalhas a new line for the AIO submit calls, next to the pread/preadv line from #1131: a concurrentread/writeon the same descriptor can see the moved pointer.GuestAiosets the offset to 2 before the write batch and checks that it is still 2 afterwards.Tested on Windows 11 (WinLibs GCC 15.2):
guest_aio_tests,guest_file_vector_testsandfile_position_testspass.tools/check_conventions.py --base upstream/mainpasses.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-09T22:26:05Z.
Review: APPROVED
Checked: AIO now goes through
NativePositionedfromStdio.cpp(no second copy), theoffset < 0->EINVALcheck is kept, and the TechnicalDebt line is there. Rebased on currentmain(only a TechnicalDebt adjacency conflict, both lines kept); full build + ctest green,guest_aiopasses, Windows/Linux CI green on the previous head. Merging.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-09T22:57:16Z.
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)core/libs/tests/GuestAio.cppL101