feat(libkernel_sys): implement readlink #1627

Merged
babyhuey merged 1 commit from upstream-pr/1627 into main 2026-10-09 21:52:38 +00:00
babyhuey commented 2026-10-08 15:15:30 +00:00 (Migrated from github.com)

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


What

Implements readlink (pd02UI9TbOA) in libkernel_sys. Part of #1578: PPSA99001 (ProsperoRadio) imports it from libkernel_sys, which only had the placeholder export. On Windows an import is looked up in its own module and then libc, so it has to live in libkernel_sys.

  • Follows FreeBSD kern_readlinkat/kern_readlink_vp: a path that is not a symbolic link fails with EINVAL, a zero bufsiz returns 0, a longer target is truncated to bufsiz without a terminator, and bufsiz above SSIZE_MAX fails with EINVAL. A null path fails with EFAULT, an empty one with ENOENT.
  • The path goes through ResolvePath_nid_no_patch. The target is read with std::filesystem::read_symlink and returned with / separators, then copied into the guest buffer, so no host call writes guest memory directly.
  • Host errors map to guest errno values up to 34 and EIO otherwise, as SceErrorFromErrno does in libkernel.

Tested

Linux (Ubuntu 24.04, GCC 13, Release): new guest_kernel_sys passes with --repeat until-fail:3. It covers a file, a directory, a missing path, empty and null paths, and a link: full target, truncation, zero size, null buffer, and a case-insensitive guest path. Where symbolic links can't be created (Windows without the privilege) it prints that the link cases were not tested. The test fails when truncation is removed. check_test_registration.py and check_conventions.py pass. Windows: Export.cpp compiles with MinGW-w64 GCC 13 (-Wall -Wextra -fsyntax-only); not run on Windows. 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:4788938738 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1627). Originally posted by [babyhuey](https://github.com/babyhuey) on 2026-10-08T15:15:30Z. --- ### What Implements `readlink` (`pd02UI9TbOA`) in libkernel_sys. Part of #1578: PPSA99001 (ProsperoRadio) imports it from `libkernel_sys`, which only had the placeholder export. On Windows an import is looked up in its own module and then libc, so it has to live in libkernel_sys. - Follows FreeBSD `kern_readlinkat`/`kern_readlink_vp`: a path that is not a symbolic link fails with `EINVAL`, a zero `bufsiz` returns 0, a longer target is truncated to `bufsiz` without a terminator, and `bufsiz` above `SSIZE_MAX` fails with `EINVAL`. A null path fails with `EFAULT`, an empty one with `ENOENT`. - The path goes through `ResolvePath_nid_no_patch`. The target is read with `std::filesystem::read_symlink` and returned with `/` separators, then copied into the guest buffer, so no host call writes guest memory directly. - Host errors map to guest errno values up to 34 and `EIO` otherwise, as `SceErrorFromErrno` does in libkernel. ### Tested Linux (Ubuntu 24.04, GCC 13, Release): new `guest_kernel_sys` passes with `--repeat until-fail:3`. It covers a file, a directory, a missing path, empty and null paths, and a link: full target, truncation, zero size, null buffer, and a case-insensitive guest path. Where symbolic links can't be created (Windows without the privilege) it prints that the link cases were not tested. The test fails when truncation is removed. `check_test_registration.py` and `check_conventions.py` pass. Windows: `Export.cpp` compiles with MinGW-w64 GCC 13 (`-Wall -Wextra -fsyntax-only`); not run on Windows. 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:34:41 +00:00 (Migrated from github.com)

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

Review: APPROVED


LGTM. Thorough implementation of readlink following FreeBSD semantics with proper argument validation, path resolution, symlink status checking, and error mapping via GuestError. The test coverage is excellent - testing non-symlink paths, missing/empty/null paths, full reading, truncation, zero-size buffer, null buffer cases, and case-insensitive path handling on Windows. Good graceful degradation when symlinks aren't available (Windows without privilege). Clean addition to libkernel_sys for ProsperoRadio's import requirements.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5459139971 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1627#pullrequestreview-5459139971). Originally posted by [klosixgaming-arch](https://github.com/klosixgaming-arch) on 2026-10-08T15:34:41Z. **Review:** APPROVED --- LGTM. Thorough implementation of readlink following FreeBSD semantics with proper argument validation, path resolution, symlink status checking, and error mapping via GuestError. The test coverage is excellent - testing non-symlink paths, missing/empty/null paths, full reading, truncation, zero-size buffer, null buffer cases, and case-insensitive path handling on Windows. Good graceful degradation when symlinks aren't available (Windows without privilege). Clean addition to libkernel_sys for ProsperoRadio's import requirements.
github-actions[bot] commented 2026-10-08 15:39:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-08T15:39:14Z.


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
#1641 __error_nid_postfix
#1675 __error_nid_postfix
#1686 core/libs/CMakeLists.txt L133
#1727 __error_nid_postfix
#1729 __error_nid_postfix
#1738 __error_nid_postfix
#1772 __error_nid_postfix
#1795 core/libs/CMakeLists.txt L133
#1828 core/libs/CMakeLists.txt L133
#1841 __error_nid_postfix
#1860 __error_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6063507778 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1627#issuecomment-6063507778). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-08T15:39:14Z. --- <!-- 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 | |---|---|---|---| | #1641 | | `__error_nid_postfix` | | | #1675 | | `__error_nid_postfix` | | | #1686 | `core/libs/CMakeLists.txt` [L133](https://github.com/boykopovar/AnyPS5/blob/f145139676a48306681d3a4d5fabf83938759daf/core/libs/CMakeLists.txt#L133) | | | | #1727 | | `__error_nid_postfix` | | | #1729 | | `__error_nid_postfix` | | | #1738 | | `__error_nid_postfix` | | | #1772 | | `__error_nid_postfix` | | | #1795 | `core/libs/CMakeLists.txt` [L133](https://github.com/boykopovar/AnyPS5/blob/f145139676a48306681d3a4d5fabf83938759daf/core/libs/CMakeLists.txt#L133) | | | | #1828 | `core/libs/CMakeLists.txt` [L133](https://github.com/boykopovar/AnyPS5/blob/f145139676a48306681d3a4d5fabf83938759daf/core/libs/CMakeLists.txt#L133) | | | | #1841 | | `__error_nid_postfix` | | | #1860 | | `__error_nid_postfix` | |
babyhuey commented 2026-10-08 17:37:04 +00:00 (Migrated from github.com)

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


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

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6065572463 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1627#issuecomment-6065572463). Originally posted by [babyhuey](https://github.com/babyhuey) on 2026-10-08T17:37:04Z. --- Fork CI while the upstream run waits for approval: [Build run](https://github.com/babyhuey/AnyPS5/actions/runs/37812347804), all jobs green on a2de24b9 (Linux 467/467, Windows 458/458, relinker on Linux, macOS and Windows). It builds the branch head, not the merge with `main`.
github-actions[bot] commented 2026-10-08 21:26:30 +00:00 (Migrated from github.com)

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


Progress report (54f28f2 → d024717)

📈 System libraries: 85.31% (+0.01%, +1 implemented functions)

✅ 1 implemented
Library Name
libkernel_sys readlink_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6069366962 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1627#issuecomment-6069366962). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-08T21:26:30Z. --- <!-- progress-report --> ### Progress report (54f28f2 → d024717) 📈 **System libraries**: 85.31% (+0.01%, +1 implemented functions) <details> <summary>✅ 1 implemented</summary> | Library | Name | | - | - | | libkernel_sys | `readlink_nid_postfix` | </details>
babyhuey commented 2026-10-08 22:57:41 +00:00 (Migrated from github.com)

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


A title that stops on readlink on current main. 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
PPSA99010 vkQuake 1.0 app.elf: symbol lookup error: app.elf: undefined symbol: pd02UI9TbOA (readlink) next stop QuJYZ2KVGGQ (shm_open)

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

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6070702581 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1627#issuecomment-6070702581). Originally posted by [babyhuey](https://github.com/babyhuey) on 2026-10-08T22:57:41Z. --- A title that stops on `readlink` on current `main`. 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 | |---|---|---| | PPSA99010 vkQuake 1.0 | `app.elf: symbol lookup error: app.elf: undefined symbol: pd02UI9TbOA` (`readlink`) | next stop `QuJYZ2KVGGQ` (`shm_open`) | The "with this branch" build also had my other open PRs merged; only this branch exports `pd02UI9TbOA`.
babyhuey commented 2026-10-09 01:26:39 +00:00 (Migrated from github.com)

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


Same title on Windows. 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
PPSA99010 vkQuake 1.0 FAIL: unresolved ELF import pd02UI9TbOA from libkernel_sys.prx (readlink) FAIL: unresolved ELF import QuJYZ2KVGGQ from libkernel.prx (shm_open)

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

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6072368118 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1627#issuecomment-6072368118). Originally posted by [babyhuey](https://github.com/babyhuey) on 2026-10-09T01:26:39Z. --- Same title on Windows. 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 | |---|---|---| | PPSA99010 vkQuake 1.0 | `FAIL: unresolved ELF import pd02UI9TbOA from libkernel_sys.prx` (`readlink`) | `FAIL: unresolved ELF import QuJYZ2KVGGQ from libkernel.prx` (`shm_open`) | As on Linux, the second build also had my other open PRs merged; only this branch exports `pd02UI9TbOA`.
adriadam10 commented 2026-10-09 21:52:35 +00:00 (Migrated from github.com)

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


Checked on Linux (merged onto current main): build and ctest green (524/524, guest_kernel_sys included); the test no longer links without the readlink export. Error codes and truncation match FreeBSD kern_readlinkat, and the vkQuake runs on Linux and Windows back it up. Merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6089872843 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1627#issuecomment-6089872843). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-09T21:52:35Z. --- Checked on Linux (merged onto current `main`): build and ctest green (524/524, `guest_kernel_sys` included); the test no longer links without the `readlink` export. Error codes and truncation match FreeBSD `kern_readlinkat`, and the vkQuake runs on Linux and Windows back it up. 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!1627
No description provided.