fix(libkernel): report the starting entry index in getdirentries basep on Windows #8591

Merged
xXPBSXx merged 1 commit from upstream-pr/8591 into main 2026-10-20 20:04:26 +00:00
xXPBSXx commented 2026-10-20 17:40:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-20T17:40:59Z.


What

Windows sceKernelGetdirentries stored 0 in *basep on every read. FreeBSD stores the offset the read started at (kern_getdirentries, *basep = loff). ReadDirectoryDescriptor now returns the index of the first entry of the read (the unit lseek takes on these descriptors, see the Windows directory descriptor entry in docs/dev/debt/libkernel.md), and guest_directory_entries is registered on Windows (previously NOT WIN32; it also gets the Windows PATH, unwind section and -fasynchronous-unwind-tables like guest_directory_rewind).
Does not touch the POSIX implementation. Source for the behaviour: FreeBSD 11.4 sys/kern/vfs_syscalls.c kern_getdirentries (loff = auio.uio_offset = foffset; ... *basep = loff).
Fixes #8590

Tested

Windows 10 (10.0.19045), WinLibs GCC 15.2.0 Release, ctest -N -R ^guest_directory_entries$ lists exactly 1 test.

  • Without the fix (library files from upstream/main, CMake registration applied): guest_directory_entries fails 3/3 (Directory entry check failed at line 81, 0xc0000409).
  • With the fix: passes 3/3.
  • Directory test family on the fixed build: guest_directory, guest_directory_buffer, guest_directory_rewind, guest_directory_close, guest_fdopendir, guest_working_directory, windows_working_directory, guest_module_directories: all pass.
  • python tools/check_conventions.py --base upstream/main: passed.
    Not tested: Linux/macOS (only CMake registration lines changed for them: the test stays registered unconditionally; the Windows-only guest_directory_close/positioned_close tests keep their Windows condition). GPUs tested: n/a.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw; no silent stubs added
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source (none added)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: none
  • AI-assisted: yes

AI-assisted (Claude Code).

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4939885579 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8591). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-20T17:40:59Z. --- ### What Windows `sceKernelGetdirentries` stored `0` in `*basep` on every read. FreeBSD stores the offset the read started at (`kern_getdirentries`, `*basep = loff`). `ReadDirectoryDescriptor` now returns the index of the first entry of the read (the unit `lseek` takes on these descriptors, see the Windows directory descriptor entry in `docs/dev/debt/libkernel.md`), and `guest_directory_entries` is registered on Windows (previously `NOT WIN32`; it also gets the Windows `PATH`, unwind section and `-fasynchronous-unwind-tables` like `guest_directory_rewind`). Does not touch the POSIX implementation. Source for the behaviour: FreeBSD 11.4 `sys/kern/vfs_syscalls.c` `kern_getdirentries` (`loff = auio.uio_offset = foffset; ... *basep = loff`). Fixes #8590 ### Tested Windows 10 (10.0.19045), WinLibs GCC 15.2.0 Release, `ctest -N -R ^guest_directory_entries$` lists exactly 1 test. - Without the fix (library files from upstream/main, CMake registration applied): `guest_directory_entries` fails 3/3 (`Directory entry check failed at line 81`, 0xc0000409). - With the fix: passes 3/3. - Directory test family on the fixed build: guest_directory, guest_directory_buffer, guest_directory_rewind, guest_directory_close, guest_fdopendir, guest_working_directory, windows_working_directory, guest_module_directories: all pass. - `python tools/check_conventions.py --base upstream/main`: passed. Not tested: Linux/macOS (only CMake registration lines changed for them: the test stays registered unconditionally; the Windows-only `guest_directory_close`/`positioned_close` tests keep their Windows condition). GPUs tested: n/a. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt - [x] Unimplemented paths throw; no silent stubs added - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source (none added) - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Unblocks: none - [x] AI-assisted: yes AI-assisted (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-actions[bot] commented 2026-10-20 18:15:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-20T18:15:12Z.


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.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 8520 core/libs/prx/libkernel/File/src/DirectoryDescriptor.cpp L156-161
core/libs/prx/libkernel/File/src/Stdio.cpp L1104-1105

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 4972 core/libs/prx/libkernel/CMakeLists.txt
PR 5021 core/libs/prx/libkernel/CMakeLists.txt
core/libs/prx/libkernel/File/src/Stdio.cpp
PR 6044 core/libs/prx/libkernel/CMakeLists.txt
PR 6226 core/libs/prx/libkernel/CMakeLists.txt
PR 6469 core/libs/prx/libkernel/CMakeLists.txt
PR 6879 core/libs/prx/libkernel/File/src/Stdio.cpp
PR 6977 core/libs/prx/libkernel/CMakeLists.txt
core/libs/prx/libkernel/File/src/Stdio.cpp
PR 7121 core/libs/prx/libkernel/File/src/Stdio.cpp
PR 7192 core/libs/prx/libkernel/CMakeLists.txt
PR 7201 core/libs/prx/libkernel/CMakeLists.txt
core/libs/prx/libkernel/File/src/DirectoryDescriptor.cpp
core/libs/prx/libkernel/File/src/Stdio.cpp
PR 7464 core/libs/prx/libkernel/CMakeLists.txt
PR 7530 core/libs/prx/libkernel/File/src/Stdio.cpp
PR 7532 core/libs/prx/libkernel/CMakeLists.txt
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6297900915 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8591#issuecomment-6297900915). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-20T18:15:12Z. --- <!-- pr-overlap --> 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**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | [PR 8520](https://www.github.com/boykopovar/AnyPS5/pull/8520) | `core/libs/prx/libkernel/File/src/DirectoryDescriptor.cpp` [L156-161](https://github.com/boykopovar/AnyPS5/blob/5e113d91f9751dc61161052f9132065728f4f8c7/core/libs/prx/libkernel/File/src/DirectoryDescriptor.cpp#L156-L161)<br>`core/libs/prx/libkernel/File/src/Stdio.cpp` [L1104-1105](https://github.com/boykopovar/AnyPS5/blob/5e113d91f9751dc61161052f9132065728f4f8c7/core/libs/prx/libkernel/File/src/Stdio.cpp#L1104-L1105) | | | Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap. | Pull request | Shared files not compared | |---|---| | [PR 4972](https://www.github.com/boykopovar/AnyPS5/pull/4972) | `core/libs/prx/libkernel/CMakeLists.txt` | | [PR 5021](https://www.github.com/boykopovar/AnyPS5/pull/5021) | `core/libs/prx/libkernel/CMakeLists.txt`<br>`core/libs/prx/libkernel/File/src/Stdio.cpp` | | [PR 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `core/libs/prx/libkernel/CMakeLists.txt` | | [PR 6226](https://www.github.com/boykopovar/AnyPS5/pull/6226) | `core/libs/prx/libkernel/CMakeLists.txt` | | [PR 6469](https://www.github.com/boykopovar/AnyPS5/pull/6469) | `core/libs/prx/libkernel/CMakeLists.txt` | | [PR 6879](https://www.github.com/boykopovar/AnyPS5/pull/6879) | `core/libs/prx/libkernel/File/src/Stdio.cpp` | | [PR 6977](https://www.github.com/boykopovar/AnyPS5/pull/6977) | `core/libs/prx/libkernel/CMakeLists.txt`<br>`core/libs/prx/libkernel/File/src/Stdio.cpp` | | [PR 7121](https://www.github.com/boykopovar/AnyPS5/pull/7121) | `core/libs/prx/libkernel/File/src/Stdio.cpp` | | [PR 7192](https://www.github.com/boykopovar/AnyPS5/pull/7192) | `core/libs/prx/libkernel/CMakeLists.txt` | | [PR 7201](https://www.github.com/boykopovar/AnyPS5/pull/7201) | `core/libs/prx/libkernel/CMakeLists.txt`<br>`core/libs/prx/libkernel/File/src/DirectoryDescriptor.cpp`<br>`core/libs/prx/libkernel/File/src/Stdio.cpp` | | [PR 7464](https://www.github.com/boykopovar/AnyPS5/pull/7464) | `core/libs/prx/libkernel/CMakeLists.txt` | | [PR 7530](https://www.github.com/boykopovar/AnyPS5/pull/7530) | `core/libs/prx/libkernel/File/src/Stdio.cpp` | | [PR 7532](https://www.github.com/boykopovar/AnyPS5/pull/7532) | `core/libs/prx/libkernel/CMakeLists.txt` |
MarcZX10 commented 2026-10-20 18:42:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-20T18:42:35Z.


I manually compared #8520: its Windows sceKernelGetdirentries path also sets basep from a DirectoryDescriptor cursor while adding archived-directory support. It currently does that with a separate SeekDirectoryDescriptor call followed by ReadDirectoryDescriptor; this PR’s out-parameter captures the start under the read lock, avoiding a stale base if two threads share the descriptor. The PRs overlap in this path but are not the same overall feature. Could you coordinate with #8520’s author on merge order and whether that PR should adopt this helper change? #8520 is currently dirty against main and has requested changes.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6298462391 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8591#issuecomment-6298462391). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-20T18:42:35Z. --- I manually compared #8520: its Windows `sceKernelGetdirentries` path also sets `basep` from a `DirectoryDescriptor` cursor while adding archived-directory support. It currently does that with a separate `SeekDirectoryDescriptor` call followed by `ReadDirectoryDescriptor`; this PR’s out-parameter captures the start under the read lock, avoiding a stale base if two threads share the descriptor. The PRs overlap in this path but are not the same overall feature. Could you coordinate with #8520’s author on merge order and whether that PR should adopt this helper change? #8520 is currently dirty against `main` and has requested changes.
xXPBSXx commented 2026-10-20 18:46:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-20T18:46:28Z.


Thanks for comparing it with #8520. You are right that both touch the Windows sceKernelGetdirentries basep path: this PR is the smaller change (ReadDirectoryDescriptor returns the start index under the read lock, and guest_directory_entries is registered on Windows), #8520 adds archived-directory support. I am happy to rebase onto whichever of the two lands first. If #8520's author wants to adopt the out-parameter in ReadDirectoryDescriptor, I have no objection and will then rebase this PR down to the test registration; I have not contacted that author yet.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6298536642 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8591#issuecomment-6298536642). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-20T18:46:28Z. --- Thanks for comparing it with #8520. You are right that both touch the Windows `sceKernelGetdirentries` `basep` path: this PR is the smaller change (`ReadDirectoryDescriptor` returns the start index under the read lock, and `guest_directory_entries` is registered on Windows), #8520 adds archived-directory support. I am happy to rebase onto whichever of the two lands first. If #8520's author wants to adopt the out-parameter in `ReadDirectoryDescriptor`, I have no objection and will then rebase this PR down to the test registration; I have not contacted that author yet. AI-assisted (Claude Code).
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!8591
No description provided.