libkernel: Windows getdirentries stores 0 in basep instead of the read offset (FreeBSD stores it only on success); fix branch ready #5237
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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 husseinkad on 2026-10-13T15:23:30Z.
The Windows
getdirentries/sceKernelGetdirentriesstores 0 in*basepon every call. FreeBSD 11.4kern_getdirentriesstores the descriptor offset the read started at, and only when the call succeeds. A guest that usesbasepto remember its position in a directory (to resume or seek later) always sees 0 here, and a failed call overwrites it.Fix branch: https://github.com/husseinkad/AnyPS5/tree/fix/libkernel-getdirentries-basep (one commit on current main:
File/src/Stdio.cpp,tests/GuestDirectoryBuffer.cppwith a newCheckBase, and one sentence indocs/dev/debt/libkernel.mdline 106 that would otherwise be false). On Windowsbasepnow holds the entry index before the read, the same valuelseekreturns and accepts; the Linux path stored it before the host read and now stores it only on success.Checks:
CheckBasefails on main (abort) and passes with the change;guest_directory,guest_directory_bufferandguest_fdopendirpass.sceKernelGetdirentriesandgetdirentries_nid_postfixagainst main: directories with 0, 1, 5, 50 and 500 entries and 12 buffer sizes from 12 bytes to 64 KiB. Before every call*basepafter the call equals the entries consumed so far andlseek(fd, 0, SEEK_CUR)agrees (main had 39 mismatches, the branch none). A NULLbasepis safe;basepis untouched on a too-small buffer (EINVAL), a null buffer (EFAULT), a closed fd and a regular file (main wrote 0). Afterlseekto 0 or 3basepis 0 or 3; at the end of the directory it reports the total entry count. Two descriptors on one directory each start at 0, and 8 threads on one descriptor read the right total with no crash.check_conventions.pyis clean andpr_overlap.pyreports only #4999 on the one debt-doc line (a one-line text conflict: #4999'sEBADFpath leavesbasepuntouched, which matches this branch, so merge #4999 first or drop the doc hunk).Not covered: the cursor read and the listing read take separate locks, so two threads reading one descriptor can see a stale
basep(noted in the debt entry; FreeBSD serialises withfoffset_lock). The Linux change was read, not built or run. An invalid fd returnsENOTDIRrather thanEBADF, the same as main (#4999 covers it). Only Windows was built and run.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-13T15:41:05Z.
I opened PR #5253, carrying Hussein Kadhim's
basepfix with his original commit author preserved. I added a Linux regression check proving a too-small-buffer failure leavesbasepuntouched; that assertion fails on unchangedmainand passes with the fix.Linux validation:
guest_directory_entriespassed (1/1),guest_directoryandguest_fdopendirpassed (2/2), and the convention check passed. The successful-offset regression is Windows-only; the issue report records it passing on Windows. I could not cross-configure the Windows target locally because the MinGWlibgcc_s_seh-1.dllruntime is missing. This PR depends on #4999 only for the shared debt-file edit's merge order.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T06:54:18Z.
Closing: no title is known to reach this, and functions are only changed when a title needs them. If a title stops on or misbehaves because of it on current main, comment here with the title ID and the log line.