Skip to content

feat(libkernel_sys): implement readlink - #1627

Merged
adriadam10 merged 1 commit into
boykopovar:mainfrom
babyhuey:feat/libkernel_sys-readlink
Oct 9, 2026
Merged

adriadam10 merged 1 commit into
boykopovar:mainfrom
babyhuey:feat/libkernel_sys-readlink

Conversation

@babyhuey

@babyhuey babyhuey commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

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

@klosixgaming-arch klosixgaming-arch left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

github-actions Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

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

@babyhuey

babyhuey commented Oct 8, 2026

Copy link
Copy Markdown
Contributor Author

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

@github-actions

github-actions Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

Progress report (54f28f2 → d024717)

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

✅ 1 implemented
Library Name
libkernel_sys readlink_nid_postfix

@babyhuey

babyhuey commented Oct 8, 2026

Copy link
Copy Markdown
Contributor Author

A title that stops on readlink on current main. Linux, Ubuntu 24.04 container, GCC 13, Release, main d64134f (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

babyhuey commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

Same title on Windows. Windows 11, RTX 3080, WinLibs GCC 15.2.0 r7, Release, main f145139 (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.

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 9, 2026
@babyhuey
babyhuey force-pushed the feat/libkernel_sys-readlink branch from 067e235 to c74b3dd Compare October 9, 2026 08:34
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 9, 2026
@babyhuey
babyhuey force-pushed the feat/libkernel_sys-readlink branch from c74b3dd to 36ef0a9 Compare October 9, 2026 17:30
@babyhuey
babyhuey force-pushed the feat/libkernel_sys-readlink branch from 36ef0a9 to d024717 Compare October 9, 2026 21:31
@adriadam10

Copy link
Copy Markdown
Collaborator

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.

@adriadam10
adriadam10 merged commit 5d0b955 into boykopovar:main Oct 9, 2026
6 checks passed
@SleglJan SleglJan mentioned this pull request Oct 10, 2026
9 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants