feat(libc): implement telldir and seekdir #6211

Merged
milescoviello merged 1 commit from upstream-pr/6211 into main 2026-10-18 18:58:32 +00:00
milescoviello commented 2026-10-15 03:49:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-15T03:49:58Z.


What

Link's Awakening for PS5 (PPSA99670, catalog release) does not start on main:

./app.elf: symbol lookup error: ./app.elf: undefined symbol: RZA5RZawY04

RZA5RZawY04 is telldir (tools/nid_names.py --nid RZA5RZawY04). The executable also imports seekdir (7WoI+lVawlc). libc exports neither, so loading stops before the title runs. No other catalog title imports them.

libc now implements both on the host directory stream that opendir already holds, under the stream's lock, the same way rewinddir does: _wtelldir/_wseekdir on Windows, telldir/seekdir elsewhere. The position is the host's cookie, which the guest only passes back to seekdir on the same stream. A null stream sets EBADF, as readdir and rewinddir already do.

guest_directory now reads one entry, takes telldir, reads the next entry and the rest of the stream, then checks that seekdir back returns that same next entry, and checks the null stream for both calls.

Tested

Ubuntu 24.04, GCC 13.3, Release, on main a077a88df:

  • guest_directory passes 5/5. Without the libc change it does not link (undefined reference to telldir_nid_postfix). With seekdir made a no-op it aborts at the check after the seek.
  • All 376 guest_* tests pass.
  • PPSA99670, relinked with --to-intel, run on Linux (RTX 4070 Ti): main stops at 0 s on the error above. With this change it runs the full 90 s. It reaches its own setup screen (Game module missing; run setup on a computer, since no game data is installed) and submits about 600 frames per 10 s. In a 60 s run with a temporary print in each directory call (not part of this PR), it calls none of opendir, readdir, telldir, seekdir or closedir on that screen, so the title only proves that the exports load. The test covers the calls themselves.
  • @babyhuey ran head 6025f0050 on Windows 11 with an RTX 3080 (comment). guest_directory passes 5 of 5. On main, Link's Awakening (PPSA99670, catalog 0.1.0) fails to load with telldir and seekdir unresolved; with this PR it runs 60 s twice at about 60 fps, showing its game-files setup page.
  • tools/check_conventions.py --base upstream/main passes, and tools/pr_overlap.py --branch fix/libc-telldir-seekdir finds no overlap.

macOS: @simonbbby ran this Directory.cpp on macOS 27.2 arm64 in a standalone harness. 82 of 82 saved positions round-trip and the null-stream checks pass, and making seekdir or telldir a no-op fails it. @nicolasfalesy found a catalog title that needs this: Link's Awakening for PS5 (PPSA99670, 0.1.0). On Linux with an Intel Arc GPU (Mesa ANV), main 5d9dcc42d stops at load with ./app.elf: symbol lookup error: ./app.elf: undefined symbol: RZA5RZawY04 (telldir). With this PR it loads and runs the whole 40 s, to its own Game module missing screen, since no game files were installed for the test.

Not checked on a console.

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 under Silent stubs in their library's technical debt file
  • 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
  • Unblocks: none
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4867904714 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6211). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-15T03:49:58Z. --- ### What Link's Awakening for PS5 (PPSA99670, catalog release) does not start on `main`: ``` ./app.elf: symbol lookup error: ./app.elf: undefined symbol: RZA5RZawY04 ``` `RZA5RZawY04` is `telldir` (`tools/nid_names.py --nid RZA5RZawY04`). The executable also imports `seekdir` (`7WoI+lVawlc`). libc exports neither, so loading stops before the title runs. No other catalog title imports them. libc now implements both on the host directory stream that `opendir` already holds, under the stream's lock, the same way `rewinddir` does: `_wtelldir`/`_wseekdir` on Windows, `telldir`/`seekdir` elsewhere. The position is the host's cookie, which the guest only passes back to `seekdir` on the same stream. A null stream sets `EBADF`, as `readdir` and `rewinddir` already do. `guest_directory` now reads one entry, takes `telldir`, reads the next entry and the rest of the stream, then checks that `seekdir` back returns that same next entry, and checks the null stream for both calls. ### Tested Ubuntu 24.04, GCC 13.3, Release, on `main` a077a88df: - `guest_directory` passes 5/5. Without the libc change it does not link (`undefined reference to telldir_nid_postfix`). With `seekdir` made a no-op it aborts at the check after the seek. - All 376 `guest_*` tests pass. - PPSA99670, relinked with `--to-intel`, run on Linux (RTX 4070 Ti): `main` stops at 0 s on the error above. With this change it runs the full 90 s. It reaches its own setup screen (`Game module missing; run setup on a computer`, since no game data is installed) and submits about 600 frames per 10 s. In a 60 s run with a temporary print in each directory call (not part of this PR), it calls none of `opendir`, `readdir`, `telldir`, `seekdir` or `closedir` on that screen, so the title only proves that the exports load. The test covers the calls themselves. - @babyhuey ran head 6025f0050 on Windows 11 with an RTX 3080 ([comment](https://github.com/boykopovar/AnyPS5/pull/6211#issuecomment-6251819831)). `guest_directory` passes 5 of 5. On `main`, Link's Awakening (PPSA99670, catalog 0.1.0) fails to load with `telldir` and `seekdir` unresolved; with this PR it runs 60 s twice at about 60 fps, showing its game-files setup page. - `tools/check_conventions.py --base upstream/main` passes, and `tools/pr_overlap.py --branch fix/libc-telldir-seekdir` finds no overlap. macOS: @simonbbby [ran this `Directory.cpp` on macOS 27.2 arm64](https://github.com/boykopovar/AnyPS5/pull/6211#issuecomment-6184361919) in a standalone harness. 82 of 82 saved positions round-trip and the null-stream checks pass, and making `seekdir` or `telldir` a no-op fails it. @nicolasfalesy [found a catalog title that needs this](https://github.com/boykopovar/AnyPS5/pull/6211#issuecomment-6206823620): Link's Awakening for PS5 (PPSA99670, 0.1.0). On Linux with an Intel Arc GPU (Mesa ANV), `main` 5d9dcc42d stops at load with `./app.elf: symbol lookup error: ./app.elf: undefined symbol: RZA5RZawY04` (`telldir`). With this PR it loads and runs the whole 40 s, to its own `Game module missing` screen, since no game files were installed for the test. Not checked on a console. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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 under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [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] Unblocks: none - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-actions[bot] commented 2026-10-15 03:50:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T03:50:41Z.


Progress report (f219248 → 6025f00)

➖ System libraries: 89.65% (+0.0%, +2 implemented functions)

✅ 2 implemented
Library Name
libc seekdir_nid_postfix
libc telldir_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6183975369 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6211#issuecomment-6183975369). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-15T03:50:41Z. --- <!-- progress-report --> ### Progress report (f219248 → 6025f00) ➖ **System libraries**: 89.65% (+0.0%, +2 implemented functions) <details> <summary>✅ 2 implemented</summary> | Library | Name | | - | - | | libc | `seekdir_nid_postfix` | | libc | `telldir_nid_postfix` | </details>
simonbbby commented 2026-10-15 04:23:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by simonbbby on 2026-10-15T04:23:21Z.


Independent macOS POSIX helper check at exact head 7bf7ece122f9f976f71306ff2f2dd076802015cb: macOS 27.2 (26B5112a), native arm64, Apple clang 21.0.0.

I built a standalone harness including this head's actual Directory.cpp, with -std=c++20 -O2 -arch arm64 -ffunction-sections -fdata-sections -Icore/libs -Wl,-dead_strip. The harness creates the real Directory wrapper around a native stream, then calls the production telldir_nid_postfix, seekdir_nid_postfix, readdir_nid_postfix and rewinddir_nid_postfix; there are no replacement implementations of those calls. Unused full-runtime functions are dead-stripped, so guest path resolution and loader initialization are not exercised.

A scratch directory has 80 files with spaces/non-ASCII names, plus . and ... The probe saves the cookie before each read, reaches EOF, then seeks to every saved cookie and checks that the same next entry is returned. It also checks rewind and both null-handle errno == 9 cases.

  • PR source: 82/82 cookies round-trip, rewind and null-handle checks pass; 5/5 fresh-process runs after restoration.
  • Mutation in a scratch copy: make SeekNative a no-op → exit 1, seekdir cookie did not restore the expected entry.
  • Separate mutation: make TellNative return 0 → the same expected failure.
  • Restored the included source byte-for-byte from the clean PR checkout and rebuilt before the five passing runs.

This adds host macOS cookie/stream semantics coverage, not a full guest_directory CTest, guest x86-64 ABI, title, Windows or console result. An x86-64 build of the same probe compiles, but executing it on this Mac fails with Bad CPU type in executable, so no Rosetta result is counted. Compilation emits the existing C-linkage warnings from General.hpp; no warning-free-build claim.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6184361919 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6211#issuecomment-6184361919). Originally posted by [simonbbby](https://github.com/simonbbby) on 2026-10-15T04:23:21Z. --- Independent **macOS POSIX helper** check at exact head **`7bf7ece122f9f976f71306ff2f2dd076802015cb`**: macOS 27.2 (26B5112a), native arm64, Apple clang 21.0.0. I built a standalone harness including this head's actual `Directory.cpp`, with `-std=c++20 -O2 -arch arm64 -ffunction-sections -fdata-sections -Icore/libs -Wl,-dead_strip`. The harness creates the real `Directory` wrapper around a native stream, then calls the production `telldir_nid_postfix`, `seekdir_nid_postfix`, `readdir_nid_postfix` and `rewinddir_nid_postfix`; there are no replacement implementations of those calls. Unused full-runtime functions are dead-stripped, so guest path resolution and loader initialization are not exercised. A scratch directory has 80 files with spaces/non-ASCII names, plus `.` and `..`. The probe saves the cookie before each read, reaches EOF, then seeks to every saved cookie and checks that the same next entry is returned. It also checks rewind and both null-handle `errno == 9` cases. - PR source: **82/82 cookies round-trip**, rewind and null-handle checks pass; **5/5 fresh-process runs** after restoration. - Mutation in a scratch copy: make `SeekNative` a no-op → exit 1, `seekdir cookie did not restore the expected entry`. - Separate mutation: make `TellNative` return 0 → the same expected failure. - Restored the included source byte-for-byte from the clean PR checkout and rebuilt before the five passing runs. This adds host macOS cookie/stream semantics coverage, **not** a full `guest_directory` CTest, guest x86-64 ABI, title, Windows or console result. An x86-64 build of the same probe compiles, but executing it on this Mac fails with `Bad CPU type in executable`, so no Rosetta result is counted. Compilation emits the existing C-linkage warnings from `General.hpp`; no warning-free-build claim.
milescoviello commented 2026-10-15 04:25:36 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-15T04:25:36Z.


Thanks for the macOS run, and for mutating both calls. I added it to the description.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6184388429 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6211#issuecomment-6184388429). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-15T04:25:36Z. --- Thanks for the macOS run, and for mutating both calls. I added it to the description. AI-assisted: yes
github-actions[bot] commented 2026-10-15 12:16:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T12:16:44Z.


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 6044 core/libs/tests/GuestDirectory.cpp
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6191833384 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6211#issuecomment-6191833384). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-15T12:16:44Z. --- <!-- pr-overlap --> 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 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `core/libs/tests/GuestDirectory.cpp` |
nicolasfalesy commented 2026-10-16 02:40:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by nicolasfalesy on 2026-10-16T02:40:46Z.


A title that reaches this: Link's Awakening for PS5 (PPSA99670) from the homebrew catalog, on Linux (Intel Arc, Mesa ANV).

  • main 5d9dcc42d: stops at load with ./app.elf: symbol lookup error: ./app.elf: undefined symbol: RZA5RZawY04 (telldir, libc).
  • main 5d9dcc42d + this PR: it loads and runs for the whole 40 s test, to its own check, [Link's Awakening] [game module] Game module missing; run setup on a computer, then copy its private package (shown on its Game Files screen; no game files were installed for the test). It was stopped by the test after 40 s.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6206823620 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6211#issuecomment-6206823620). Originally posted by [nicolasfalesy](https://github.com/nicolasfalesy) on 2026-10-16T02:40:46Z. --- A title that reaches this: **Link's Awakening for PS5 (PPSA99670)** from the homebrew catalog, on Linux (Intel Arc, Mesa ANV). - `main` 5d9dcc42d: stops at load with `./app.elf: symbol lookup error: ./app.elf: undefined symbol: RZA5RZawY04` (`telldir`, libc). - `main` 5d9dcc42d + this PR: it loads and runs for the whole 40 s test, to its own check, `[Link's Awakening] [game module] Game module missing; run setup on a computer, then copy its private package` (shown on its `Game Files` screen; no game files were installed for the test). It was stopped by the test after 40 s. AI-assisted: yes
milescoviello commented 2026-10-16 02:42:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-16T02:42:14Z.


Thank you, @nicolasfalesy. A catalog title with a before-and-after run on Intel Arc is exactly the evidence this needed. I've added it to the description.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6206840271 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6211#issuecomment-6206840271). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-16T02:42:14Z. --- Thank you, @nicolasfalesy. A catalog title with a before-and-after run on Intel Arc is exactly the evidence this needed. I've added it to the description. AI-assisted: yes
babyhuey commented 2026-10-18 15:41:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-18T15:41:46Z.


Windows run of head 6025f0050, merged onto main e5f18ea99 (clean merge). Windows 11, RTX 3080, WinLibs GCC 15.2, Release:

  • guest_directory passes 5/5 (--repeat until-fail:5); no warnings in libc/src/Directory.cpp or GuestDirectory.cpp.
  • Link's Awakening for PS5 (PPSA99670, catalog v0.1.0), 2 runs of 60 s each:
    • main: fails to load with unresolved RZA5RZawY04 (telldir) and 7WoI+lVawlc (seekdir) from libSceLibcInternal (0xC0000139, no window). Windows resolves every import at load, so both are needed.
    • With this PR: both resolve and it runs the full 60 s at 59.99 and 59.95 fps (3339 and 3345 frames), with no UCRT or FATAL reports. The window draws the game's "Game Files" setup page ("Status: Game module missing; run setup on a computer, then copy its private package"), the expected screen without user-supplied game files.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6251819831 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6211#issuecomment-6251819831). Originally posted by [babyhuey](https://github.com/babyhuey) on 2026-10-18T15:41:46Z. --- Windows run of head `6025f0050`, merged onto `main` `e5f18ea99` (clean merge). Windows 11, RTX 3080, WinLibs GCC 15.2, Release: - `guest_directory` passes 5/5 (`--repeat until-fail:5`); no warnings in `libc/src/Directory.cpp` or `GuestDirectory.cpp`. - Link's Awakening for PS5 (PPSA99670, catalog v0.1.0), 2 runs of 60 s each: - `main`: fails to load with unresolved `RZA5RZawY04` (`telldir`) and `7WoI+lVawlc` (`seekdir`) from libSceLibcInternal (`0xC0000139`, no window). Windows resolves every import at load, so both are needed. - With this PR: both resolve and it runs the full 60 s at 59.99 and 59.95 fps (3339 and 3345 frames), with no UCRT or FATAL reports. The window draws the game's "Game Files" setup page ("Status: Game module missing; run setup on a computer, then copy its private package"), the expected screen without user-supplied game files. AI-assisted: yes
milescoviello commented 2026-10-18 15:42:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-18T15:42:23Z.


Thanks @babyhuey for the Windows run. It covers the load-time failure, which I could only describe from Linux. I added it to the description.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6251826089 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6211#issuecomment-6251826089). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-18T15:42:23Z. --- Thanks @babyhuey for the Windows run. It covers the load-time failure, which I could only describe from Linux. I added it to the description. AI-assisted: yes (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!6211
No description provided.