feat(libkernel): implement getdents and getdirentries #1634

Merged
babyhuey merged 2 commits from upstream-pr/1634 into main 2026-10-09 21:18:45 +00:00
babyhuey commented 2026-10-08 15:22:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-08T15:22:39Z.


What

Implements getdents (2G6i6hMIUUY) and getdirentries (f09KvIPy-QY) in libkernel. Part of #1578: PPSA99039 (EVO-PLAYER-PS5) imports both.

They return the same FreeBSD 11 dirent records as sceKernelGetdents and sceKernelGetdirentries, with the FreeBSD 11 signatures (int nbytes, 64-bit *basep), and report failures as -1 with errno through PosixResult instead of an SCE error code.

Not changed here: on a descriptor that is not a directory, FreeBSD kern_getdirentries returns EINVAL, while sceKernelGetdirentries currently returns ENOTDIR (from getdents64 on Linux and ReadDirectoryDescriptor on Windows). The wrappers pass on whatever it returns.

Tested

Linux (Ubuntu 24.04, GCC 13, Release): guest_directory_entries passes with --repeat until-fail:3. It now reads the test directory with both calls (same records and byte count as sceKernelGetdents, *basep 0 after rewinding, 0 at the end) and checks EINVAL for a buffer too small or zero bytes and EFAULT for a null buffer. The test fails when getdents returns the SCE code. That test is registered on Linux only; the wrappers are shared and Windows keeps its existing sceKernelGetdirentries. Windows: Stdio.cpp compiles with MinGW-w64 GCC 13 (-Wall -Wextra -fsyntax-only); not run on Windows. check_conventions.py passes. No title run.

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 (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4789035990 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1634). Originally posted by [babyhuey](https://github.com/babyhuey) on 2026-10-08T15:22:39Z. --- ### What Implements `getdents` (`2G6i6hMIUUY`) and `getdirentries` (`f09KvIPy-QY`) in libkernel. Part of #1578: PPSA99039 (EVO-PLAYER-PS5) imports both. They return the same FreeBSD 11 `dirent` records as `sceKernelGetdents` and `sceKernelGetdirentries`, with the FreeBSD 11 signatures (`int nbytes`, 64-bit `*basep`), and report failures as -1 with `errno` through `PosixResult` instead of an SCE error code. Not changed here: on a descriptor that is not a directory, FreeBSD `kern_getdirentries` returns `EINVAL`, while `sceKernelGetdirentries` currently returns `ENOTDIR` (from `getdents64` on Linux and `ReadDirectoryDescriptor` on Windows). The wrappers pass on whatever it returns. ### Tested Linux (Ubuntu 24.04, GCC 13, Release): `guest_directory_entries` passes with `--repeat until-fail:3`. It now reads the test directory with both calls (same records and byte count as `sceKernelGetdents`, `*basep` 0 after rewinding, 0 at the end) and checks `EINVAL` for a buffer too small or zero bytes and `EFAULT` for a null buffer. The test fails when `getdents` returns the SCE code. That test is registered on Linux only; the wrappers are shared and Windows keeps its existing `sceKernelGetdirentries`. Windows: `Stdio.cpp` compiles with MinGW-w64 GCC 13 (`-Wall -Wextra -fsyntax-only`); not run on Windows. `check_conventions.py` passes. No title run. ### 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](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
klosixgaming-arch commented 2026-10-08 15:32:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by klosixgaming-arch on 2026-10-08T15:32:50Z.

Review: APPROVED


LGTM. Clean implementation of getdents and getdirentries as POSIX-style wrappers around the existing sceKernel functions, using PosixResult for proper error code conversion. The test coverage is thorough - verifying both new functions return identical results to their sceKernel counterparts while also testing edge cases (buffer too small, null buffer, zero bytes) with correct errno values. Good addition to support EVO-PLAYER-PS5's import requirements.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5459117337 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1634#pullrequestreview-5459117337). Originally posted by [klosixgaming-arch](https://github.com/klosixgaming-arch) on 2026-10-08T15:32:50Z. **Review:** APPROVED --- LGTM. Clean implementation of getdents and getdirentries as POSIX-style wrappers around the existing sceKernel functions, using PosixResult for proper error code conversion. The test coverage is thorough - verifying both new functions return identical results to their sceKernel counterparts while also testing edge cases (buffer too small, null buffer, zero bytes) with correct errno values. Good addition to support EVO-PLAYER-PS5's import requirements.
SleglJan commented 2026-10-08 15:59:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by SleglJan on 2026-10-08T15:59:29Z.


Confirmed on Linux on top of current main.

main 4b005b22 + 9104f396 (clean merge), CachyOS (kernel 7.2.9, GCC 16.2.1, btrfs), full build with BUILD_TESTING=ON and ANYPS5_ENABLE_SPIRV_TOOLS=ON: full ctest 467/467; guest_directory_entries 3/3 under --repeat until-fail:3; tools/check_conventions.py --base main --head 9104f396 passes; the patched libkernel.prx exports 2G6i6hMIUUY and f09KvIPy-QY.

I had the same two wrappers written independently before seeing this PR (same shape over sceKernelGetdirentries with PosixResult), so I ran my test against this branch too; it passes 3/3. It checks two things guest_directory_entries does not, in case you want them:

  • getdents on a descriptor after sceKernelClose returns -1 with errno 9, and getdirentries the same;
  • errno is left untouched by successful calls (set a sentinel before, compare after), and the second getdirentries call on a 48-byte buffer returns more than 0 with *basep different from the first call's 0.

tools/import_audit.py on catalog titles, absent imports before → after with this branch: PPSA59322 ccleste 50 → 49, PPSA68091 Ruffle Flash 71 → 70, PPSA99010 vkQuake 51 → 50, PPSA99039 EVO Player 24 → 22, PPSA99505 Jelly5 30 → 28.

AI-assisted: yes (Claude Code); the runs and counts above were checked by hand.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6063878347 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1634#issuecomment-6063878347). Originally posted by [SleglJan](https://github.com/SleglJan) on 2026-10-08T15:59:29Z. --- Confirmed on Linux on top of current `main`. `main` 4b005b22 + 9104f396 (clean merge), CachyOS (kernel 7.2.9, GCC 16.2.1, btrfs), full build with `BUILD_TESTING=ON` and `ANYPS5_ENABLE_SPIRV_TOOLS=ON`: full `ctest` 467/467; `guest_directory_entries` 3/3 under `--repeat until-fail:3`; `tools/check_conventions.py --base main --head 9104f396` passes; the patched `libkernel.prx` exports `2G6i6hMIUUY` and `f09KvIPy-QY`. I had the same two wrappers written independently before seeing this PR (same shape over `sceKernelGetdirentries` with `PosixResult`), so I ran my test against this branch too; it passes 3/3. It checks two things `guest_directory_entries` does not, in case you want them: - `getdents` on a descriptor after `sceKernelClose` returns -1 with errno 9, and `getdirentries` the same; - errno is left untouched by successful calls (set a sentinel before, compare after), and the second `getdirentries` call on a 48-byte buffer returns more than 0 with `*basep` different from the first call's 0. `tools/import_audit.py` on catalog titles, absent imports before → after with this branch: PPSA59322 ccleste 50 → 49, PPSA68091 Ruffle Flash 71 → 70, PPSA99010 vkQuake 51 → 50, PPSA99039 EVO Player 24 → 22, PPSA99505 Jelly5 30 → 28. AI-assisted: yes (Claude Code); the runs and counts above were checked by hand.
babyhuey commented 2026-10-08 16:07:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-08T16:07:28Z.


Thanks for running it end to end. Added both checks in 620947b4: EBADF from both calls after close, and errno left alone on success with *basep moving forward on the second getdirentries call.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6064022924 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1634#issuecomment-6064022924). Originally posted by [babyhuey](https://github.com/babyhuey) on 2026-10-08T16:07:28Z. --- Thanks for running it end to end. Added both checks in 620947b4: EBADF from both calls after close, and errno left alone on success with `*basep` moving forward on the second `getdirentries` call.
babyhuey commented 2026-10-08 17:37:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-08T17:37:09Z.


Fork CI while the upstream run waits for approval: Build run, all jobs green on 620947b4 (Linux 467/467, Windows 457/457, relinker on Linux, macOS and Windows). It builds the branch head, not the merge with main.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6065573775 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1634#issuecomment-6065573775). Originally posted by [babyhuey](https://github.com/babyhuey) on 2026-10-08T17:37:09Z. --- Fork CI while the upstream run waits for approval: [Build run](https://github.com/babyhuey/AnyPS5/actions/runs/37812359257), all jobs green on 620947b4 (Linux 467/467, Windows 457/457, relinker on Linux, macOS and Windows). It builds the branch head, not the merge with `main`.
LeandroLP23 commented 2026-10-08 20:16:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-08T20:16:21Z.


Run with the title on Windows. EVO Player (PPSA99039 v0.10.0) on main stops at FAIL: unresolved ELF import 2G6i6hMIUUY from libkernel.prx (getdents). With this PR it stops at the next one, 6kPnj51T62Y from libSceVideoOut.prx (sceVideoOutGetResolutionStatus, #1714). With this PR and #1714 together it reaches +F7C-hdk7+E from libkernel.prx (sigemptyset).

Windows 11, Radeon 860M, MinGW-w64 GCC 15.2.0, Release, main 4b6ab6bb; title relinked with relinker --windows and run with the patched build/core/libs/libs/*.prx.

Tested with AI assistance (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6068252784 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1634#issuecomment-6068252784). Originally posted by [LeandroLP23](https://github.com/LeandroLP23) on 2026-10-08T20:16:21Z. --- Run with the title on Windows. EVO Player (PPSA99039 v0.10.0) on `main` stops at `FAIL: unresolved ELF import 2G6i6hMIUUY from libkernel.prx` (`getdents`). With this PR it stops at the next one, `6kPnj51T62Y` from `libSceVideoOut.prx` (`sceVideoOutGetResolutionStatus`, #1714). With this PR and #1714 together it reaches `+F7C-hdk7+E` from `libkernel.prx` (`sigemptyset`). Windows 11, Radeon 860M, MinGW-w64 GCC 15.2.0, Release, `main` 4b6ab6bb; title relinked with `relinker --windows` and run with the patched `build/core/libs/libs/*.prx`. Tested with AI assistance (Claude Code).
github-actions[bot] commented 2026-10-08 21:22:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-08T21:22:07Z.


Progress report (f8c2f07 → 7d130d1)

📈 System libraries: 84.7% (+0.01%, +2 implemented functions)

✅ 2 implemented
Library Name
libkernel getdents_nid_postfix
libkernel getdirentries_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6069301474 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1634#issuecomment-6069301474). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-08T21:22:07Z. --- <!-- progress-report --> ### Progress report (f8c2f07 → 7d130d1) 📈 **System libraries**: 84.7% (+0.01%, +2 implemented functions) <details> <summary>✅ 2 implemented</summary> | Library | Name | | - | - | | libkernel | `getdents_nid_postfix` | | libkernel | `getdirentries_nid_postfix` | </details>
babyhuey commented 2026-10-08 22:57:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-08T22:57:43Z.


One more title that stops on getdents on current main, alongside @LeandroLP23's EVO Player run on Windows above. Linux, Ubuntu 24.04 container, GCC 13, Release, main d64134f0 (relinker and libs); titles from the homebrew catalog, relinked for Linux and run from the title folder.

Title main with this branch
PPSA92280 Capy Mobile 0.5.0 app.elf: symbol lookup error: app.elf: undefined symbol: 2G6i6hMIUUY (getdents) next stop 3QIPIh-GDjw (rewind)

The "with this branch" build also had my other open PRs merged; only this branch exports 2G6i6hMIUUY.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6070703105 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1634#issuecomment-6070703105). Originally posted by [babyhuey](https://github.com/babyhuey) on 2026-10-08T22:57:43Z. --- One more title that stops on `getdents` on current `main`, alongside @LeandroLP23's EVO Player run on Windows above. Linux, Ubuntu 24.04 container, GCC 13, Release, `main` d64134f0 (`relinker` and `libs`); titles from the homebrew catalog, relinked for Linux and run from the title folder. | Title | `main` | with this branch | |---|---|---| | PPSA92280 Capy Mobile 0.5.0 | `app.elf: symbol lookup error: app.elf: undefined symbol: 2G6i6hMIUUY` (`getdents`) | next stop `3QIPIh-GDjw` (`rewind`) | The "with this branch" build also had my other open PRs merged; only this branch exports `2G6i6hMIUUY`.
babyhuey commented 2026-10-09 01:26:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-09T01:26:40Z.


Capy Mobile on Windows as well. Windows 11, RTX 3080, WinLibs GCC 15.2.0 r7, Release, main f1451396 (relinker and libs); titles relinked with --windows.

Title main with this branch
PPSA92280 Capy Mobile 0.5.0 FAIL: unresolved ELF import 2G6i6hMIUUY from libkernel.prx (getdents) FAIL: unresolved ELF import 3QIPIh-GDjw from libSceLibcInternal.prx (rewind)

As on Linux, the second build also had my other open PRs merged; only this branch exports 2G6i6hMIUUY.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6072368292 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1634#issuecomment-6072368292). Originally posted by [babyhuey](https://github.com/babyhuey) on 2026-10-09T01:26:40Z. --- Capy Mobile on Windows as well. Windows 11, RTX 3080, WinLibs GCC 15.2.0 r7, Release, `main` f1451396 (`relinker` and `libs`); titles relinked with `--windows`. | Title | `main` | with this branch | |---|---|---| | PPSA92280 Capy Mobile 0.5.0 | `FAIL: unresolved ELF import 2G6i6hMIUUY from libkernel.prx` (`getdents`) | `FAIL: unresolved ELF import 3QIPIh-GDjw from libSceLibcInternal.prx` (`rewind`) | As on Linux, the second build also had my other open PRs merged; only this branch exports `2G6i6hMIUUY`.
adriadam10 commented 2026-10-09 21:18:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-09T21:18:42Z.


Checked on a build of the PR merged onto current main: full ctest 520/520, guest_directory_entries passes, and without the wrappers the test doesn't link, so it does exercise the change. Errno values (EINVAL/EFAULT/EBADF) and the success-leaves-errno-alone behaviour match the other PosixResult wrappers. Also confirmed by @SleglJan (Linux) and @LeandroLP23 (EVO Player on Windows); merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6089429094 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1634#issuecomment-6089429094). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-09T21:18:42Z. --- Checked on a build of the PR merged onto current `main`: full ctest 520/520, `guest_directory_entries` passes, and without the wrappers the test doesn't link, so it does exercise the change. Errno values (EINVAL/EFAULT/EBADF) and the success-leaves-errno-alone behaviour match the other `PosixResult` wrappers. Also confirmed by @SleglJan (Linux) and @LeandroLP23 (EVO Player on Windows); merging.
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!1634
No description provided.