fix(libkernel): rewind Windows directory descriptors on lseek #3452
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3452"
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 LeandroLP23 on 2026-10-11T10:51:55Z.
Carrying @husseinkad's fix for #3102 (they can't open PRs yet). The change is theirs: the commits of
husseinkad:fix/kernel-windows-directory-rewindcherry-picked onto currentmainwithout conflicts, authorship kept.What
On Windows a guest directory descriptor sits on the NUL device, so
lseekon it did nothing and a secondgetdentsafterlseek(fd, 0, SEEK_SET)returned 0 entries.File::SeekDirectoryDescriptornow handleslseekon directory descriptors (rewinding the snapshot, as FreeBSD'sgetdirentries(2)allows), outside the shared lock and with offset overflow reported; TechnicalDebt describes the Windows snapshot lifetime. Linux hosts already used the reallseek. Details and the reproduction are in #3102.Tested
Windows 11 (26300), WinLibs GCC 15.2.0 r7, Release, on
main24cb0d24:guest_directory_rewindpasses 3/3 and fails withmain'sDirectoryDescriptor.cppandOpen.cpp. With this PR and the other two of this batch merged together,ctest -E agc_passes 453/454; the one failure,windows_exceptions, fails the same way on plainmain(#3411). Conventions and test registration pass.Fork CI (run): the three relinker jobs pass. Windows fails only
windows_exceptions, which fails on plainmaintoo (#3411). Linux failsagc_driver_image_address_dimension,agc_driver_image_plane_address_on_line_implicit_lodandguest_kernel_stack_protect, the same three in all three runs of this batch (#3106, #3102 and #3067 fixes, unrelated changes), so they come frommain. This run also had oneguest_ampr_markersfailure on Windows, the intermittent #3371.Fixes #3102
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-11T11:05:10Z.
Code review location:
core/libs/prx/libkernel/File/src/Open.cpp; line 220sceKernelLseekmaps native failures throughSceIoErrorFromErrno(errno)below this branch. Throwing here leaks a host exception across the guest API and skips that established error mapping. Could this return the same guest error value for directory seeks, and have the negative/overflow tests assert that result instead of expectingstd::runtime_error?Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T11:49:09Z.
Review: CHANGES_REQUESTED
Thanks for carrying this. Checked the diff against
main; build and ctest are green on Linux, butguest_directory_rewindis Windows-only so it can't run here. One thing to fix, which @MarcZX100 raised inline and is still open:core/libs/prx/libkernel/File/src/Open.cpp:220: a negative target orSEEK_CURoverflow throwsstd::runtime_error, while every othersceKernelLseekfailure returnsSceIoErrorFromErrno(errno)(line 226). Return that value for directory seeks too (EINVALfor a negative target,EOVERFLOWfor the overflow), and haveGuestDirectoryRewind.cpp:93-98assert the returned error instead of expecting an exception.DirectoryDescriptor.cpp:102:errno = GuestEoverflow(84) is a guest value, not the host's. Set the hostEOVERFLOWsoSceIoErrorFromErrnomaps it to 84 (as it does atOpen.cpp:129-131).docs/dev/TechnicalDebt.md:365: "throws like any otherlseekfailure" is wrong, and will be wrong in a different way after the change. Say that a negative target returnsEINVALand an overflowEOVERFLOW, and keep theSEEK_ENDthrow.The rest (snapshot rewind outside the shared lock,
getdentsafterlseek(fd, 0, SEEK_SET), descriptor reuse in the test) looks right.Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-11T12:03:35Z.
Thanks @adriadam10 and @MarcZX100, all three addressed in 99fa580d (on top of husseinkad's commits):
sceKernelLseekreturnsSceIoErrorFromErrno(errno)for a failed directory seek instead of throwing, like every otherlseekfailure.SeekDirectoryDescriptorsets the hostEOVERFLOW, so the mapping gives 84; the now unusedGuestEoverflowconstant is gone.GuestDirectoryRewind.cppasserts the returned errors:0x80020016(EINVAL) forlseek(fd, -1, SEEK_SET)andlseek(fd, -4, SEEK_CUR),0x80020054(EOVERFLOW) for theSEEK_CURoverflow.EINVALand the overflowEOVERFLOW; theSEEK_ENDthrow is kept.Windows 11, WinLibs GCC 15.2.0 r7, Release:
guest_directory_rewindpasses 3/3, and fails with the previousOpen.cpp(the throw);guest_filesystemand thegetdentstests pass;ctest -E agc_passes apart fromwindows_exceptions(#3411, also onmain).Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-11T12:18:04Z.
Thanks for addressing the error mapping and test expectations I raised. The Windows run on the rebased head confirms the directory-seek errors are returned correctly, and the prior behavior failed at the same checks. That resolves my review point.
The current red relinker checks appear to come from the missing
3rdparty/imguisubmodule URL onmain, also reported on other PRs; they do not look specific to this change.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T21:05:26Z.
Review: APPROVED
Checked the diff against
main, the error mapping from the earlier review (sceKernelLseekreturnsSceIoErrorFromErrnofor directory seeks,EINVAL/EOVERFLOWcovered in the test) and the TechnicalDebt entry. Build and ctest are green on Linux;guest_directory_rewindis Windows-only and was confirmed on Windows 11 by you and @MarcZX100. Merging.