feat(libkernel): implement lstat #1624

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

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


What

Implements lstat (DRGXpDDh8Ng) in libkernel. Part of #1578: PPSA99039 (EVO-PLAYER-PS5) imports it.

  • Paths go through PathError and ResolvePath_nid_no_patch like stat; a null sb fails with EFAULT.
  • Linux uses host lstat, so a symbolic link reports S_IFLNK and its own size, and a dangling link succeeds. Errors map through SceErrorFromErrno, so ENOENT and ENOTDIR reach the guest instead of the single ENOENT sceKernelStat returns.
  • Windows has no CRT lstat. Anything that is not a symbolic link is identical to stat; a symbolic link calls NotImplemented_nid_no_patch.
  • File::FillLinkStat sits next to FillFileStat in NativeStat.cpp.

Tested

Linux (Ubuntu 24.04, GCC 13, Release): guest_filesystem passes with --repeat until-fail:3. It now checks lstat on a file, a directory, a missing path, an empty path, null arguments, and (Linux only) a link, a dangling link and a path through a file (ENOTDIR). The test fails when host lstat is replaced by stat. check_conventions.py passes. Windows: the changed files compile 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:4788881217 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1624). Originally posted by [babyhuey](https://github.com/babyhuey) on 2026-10-08T15:11:21Z. --- ### What Implements `lstat` (`DRGXpDDh8Ng`) in libkernel. Part of #1578: PPSA99039 (EVO-PLAYER-PS5) imports it. - Paths go through `PathError` and `ResolvePath_nid_no_patch` like `stat`; a null `sb` fails with `EFAULT`. - Linux uses host `lstat`, so a symbolic link reports `S_IFLNK` and its own size, and a dangling link succeeds. Errors map through `SceErrorFromErrno`, so `ENOENT` and `ENOTDIR` reach the guest instead of the single `ENOENT` `sceKernelStat` returns. - Windows has no CRT `lstat`. Anything that is not a symbolic link is identical to `stat`; a symbolic link calls `NotImplemented_nid_no_patch`. - `File::FillLinkStat` sits next to `FillFileStat` in `NativeStat.cpp`. ### Tested Linux (Ubuntu 24.04, GCC 13, Release): `guest_filesystem` passes with `--repeat until-fail:3`. It now checks `lstat` on a file, a directory, a missing path, an empty path, null arguments, and (Linux only) a link, a dangling link and a path through a file (`ENOTDIR`). The test fails when host `lstat` is replaced by `stat`. `check_conventions.py` passes. Windows: the changed files compile 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:35:31 +00:00 (Migrated from github.com)

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

Review: APPROVED


LGTM. Clean implementation of lstat following FreeBSD semantics with proper platform-specific handling - host lstat on Linux for correct symlink behavior, and NotImplemented_nid_no_patch for Windows symbolic links (since Windows has no CRT lstat). The test coverage is excellent - testing regular files, directories, missing/empty/null arguments, and on Linux specifically validating symlink vs stat differences (S_IFLNK mode bits, dangling symlinks succeeding with lstat but failing with stat, path-through-file ENOTDIR errors). Good addition to support EVO-PLAYER-PS5's import requirements.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5459150308 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1624#pullrequestreview-5459150308). Originally posted by [klosixgaming-arch](https://github.com/klosixgaming-arch) on 2026-10-08T15:35:31Z. **Review:** APPROVED --- LGTM. Clean implementation of lstat following FreeBSD semantics with proper platform-specific handling - host lstat on Linux for correct symlink behavior, and NotImplemented_nid_no_patch for Windows symbolic links (since Windows has no CRT lstat). The test coverage is excellent - testing regular files, directories, missing/empty/null arguments, and on Linux specifically validating symlink vs stat differences (S_IFLNK mode bits, dangling symlinks succeeding with lstat but failing with stat, path-through-file ENOTDIR errors). Good addition to support EVO-PLAYER-PS5's import requirements.
babyhuey commented 2026-10-08 17:37:02 +00:00 (Migrated from github.com)

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


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

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6065571952 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1624#issuecomment-6065571952). Originally posted by [babyhuey](https://github.com/babyhuey) on 2026-10-08T17:37:02Z. --- Fork CI while the upstream run waits for approval: [Build run](https://github.com/babyhuey/AnyPS5/actions/runs/37812343221), all jobs green on 4b9eb4ef (Linux 466/466, Windows 457/457, relinker on Linux, macOS and Windows). It builds the branch head, not the merge with `main`.
MarcZX10 commented 2026-10-08 21:06:49 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-08T21:06:49Z.


The overlap bot correctly found that #1795 also adds lstat_nid_postfix and the NativeStat path. The implementations are not equivalent: #1624 has Linux symlink/dangling-link coverage and explicitly rejects Windows symlink semantics as unimplemented, while #1795 currently falls back to stat on Windows. Since #1795’s lstat is separate from its socketpair change, please coordinate so only one reviewed lstat implementation remains; the socketpair change can proceed independently. This head is now 104 commits behind current main 0447793, so CONTRIBUTING requires a rebase and fresh checks before final review.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6069060375 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1624#issuecomment-6069060375). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-08T21:06:49Z. --- The overlap bot correctly found that #1795 also adds `lstat_nid_postfix` and the `NativeStat` path. The implementations are not equivalent: #1624 has Linux symlink/dangling-link coverage and explicitly rejects Windows symlink semantics as unimplemented, while #1795 currently falls back to `stat` on Windows. Since #1795’s `lstat` is separate from its `socketpair` change, please coordinate so only one reviewed `lstat` implementation remains; the socketpair change can proceed independently. This head is now 104 commits behind current `main` 0447793, so CONTRIBUTING requires a rebase and fresh checks before final review.
github-actions[bot] commented 2026-10-08 21:13:57 +00:00 (Migrated from github.com)

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


Progress report (54f28f2 → 903f50a)

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

✅ 1 implemented
Library Name
libkernel lstat_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6069169919 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1624#issuecomment-6069169919). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-08T21:13:57Z. --- <!-- progress-report --> ### Progress report (54f28f2 → 903f50a) 📈 **System libraries**: 85.31% (+0.01%, +1 implemented functions) <details> <summary>✅ 1 implemented</summary> | Library | Name | | - | - | | libkernel | `lstat_nid_postfix` | </details>
babyhuey commented 2026-10-08 21:20:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-08T21:20:40Z.


Rebased onto main (81204de9); guest_filesystem passes locally and fork CI is running on the new head. Agreed on keeping one lstat, thanks for raising it on #1795.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6069279857 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1624#issuecomment-6069279857). Originally posted by [babyhuey](https://github.com/babyhuey) on 2026-10-08T21:20:40Z. --- Rebased onto `main` (81204de9); `guest_filesystem` passes locally and [fork CI](https://github.com/babyhuey/AnyPS5/actions/runs/37845996551) is running on the new head. Agreed on keeping one `lstat`, thanks for raising it on #1795.
MarcZX10 commented 2026-10-08 21:48:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-08T21:48:59Z.


The linked fork CI run 37845996551 completed successfully for head 81204de9 (Linux, Windows and all relinker jobs). This is useful evidence, but does not populate upstream PR checks. Current main is now 94b1eecb; this branch is 7 commits behind (merge base 364a56b). Please rebase before merge and refresh checks on the final head.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6069702039 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1624#issuecomment-6069702039). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-08T21:48:59Z. --- The linked fork CI run `37845996551` completed successfully for head `81204de9` (Linux, Windows and all relinker jobs). This is useful evidence, but does not populate upstream PR checks. Current `main` is now `94b1eecb`; this branch is 7 commits behind (merge base `364a56b`). Please rebase before merge and refresh checks on the final head.
babyhuey commented 2026-10-08 22:57:39 +00:00 (Migrated from github.com)

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


Titles that stop on lstat 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
PPSA68091 Ruffle Flash 1.2.0 app.elf: symbol lookup error: app.elf: undefined symbol: DRGXpDDh8Ng (lstat) next stop IuxnUuXk6Bg
PPSA99000 ProsperoStore 1.000.040 app.elf: symbol lookup error: app.elf: undefined symbol: DRGXpDDh8Ng (lstat) next stop +F7C-hdk7+E (sigemptyset)

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

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6070702243 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1624#issuecomment-6070702243). Originally posted by [babyhuey](https://github.com/babyhuey) on 2026-10-08T22:57:39Z. --- Titles that stop on `lstat` 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 | |---|---|---| | PPSA68091 Ruffle Flash 1.2.0 | `app.elf: symbol lookup error: app.elf: undefined symbol: DRGXpDDh8Ng` (`lstat`) | next stop `IuxnUuXk6Bg` | | PPSA99000 ProsperoStore 1.000.040 | `app.elf: symbol lookup error: app.elf: undefined symbol: DRGXpDDh8Ng` (`lstat`) | next stop `+F7C-hdk7+E` (`sigemptyset`) | The "with this branch" build also had my other open PRs merged; only this branch exports `DRGXpDDh8Ng`.
babyhuey commented 2026-10-09 01:26:38 +00:00 (Migrated from github.com)

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


Same two titles 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
PPSA68091 Ruffle Flash 1.2.0 FAIL: unresolved ELF import DRGXpDDh8Ng from libkernel.prx (lstat) FAIL: unresolved ELF import IuxnUuXk6Bg from libkernel.prx
PPSA99000 ProsperoStore 1.000.040 FAIL: unresolved ELF import DRGXpDDh8Ng from libkernel.prx (lstat) FAIL: unresolved ELF import +F7C-hdk7+E from libkernel.prx (sigemptyset)

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

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6072367960 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1624#issuecomment-6072367960). Originally posted by [babyhuey](https://github.com/babyhuey) on 2026-10-09T01:26:38Z. --- Same two titles 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 | |---|---|---| | PPSA68091 Ruffle Flash 1.2.0 | `FAIL: unresolved ELF import DRGXpDDh8Ng from libkernel.prx` (`lstat`) | `FAIL: unresolved ELF import IuxnUuXk6Bg from libkernel.prx` | | PPSA99000 ProsperoStore 1.000.040 | `FAIL: unresolved ELF import DRGXpDDh8Ng from libkernel.prx` (`lstat`) | `FAIL: unresolved ELF import +F7C-hdk7+E from libkernel.prx` (`sigemptyset`) | As on Linux, the second build also had my other open PRs merged; only this branch exports `DRGXpDDh8Ng`.
popcoder565 commented 2026-10-09 10:00:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by popcoder565 on 2026-10-09T10:00:48Z.


First Windows run, since the description says it was only compiled with MinGW. Setup: Windows 10 (19045), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release. #1624, #1628, #1633 and #1634 merged together onto main b7218b3c.

guest_filesystem passes, including this PR's lstat cases for a file, a directory, a missing name, an empty name and null pointers. The symlink cases are #ifndef _WIN32, so they didn't run here.

🤖 Addressed by Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6078683754 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1624#issuecomment-6078683754). Originally posted by [popcoder565](https://github.com/popcoder565) on 2026-10-09T10:00:48Z. --- First Windows run, since the description says it was only compiled with MinGW. Setup: Windows 10 (19045), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release. #1624, #1628, #1633 and #1634 merged together onto `main` b7218b3c. `guest_filesystem` passes, including this PR's `lstat` cases for a file, a directory, a missing name, an empty name and null pointers. The symlink cases are `#ifndef _WIN32`, so they didn't run here. _🤖 Addressed by [Claude Code](https://claude.com/claude-code)_
adriadam10 commented 2026-10-09 21:52:00 +00:00 (Migrated from github.com)

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


Checked on Linux (merged onto current main): build and guest_filesystem pass, and the test no longer links without the change. Error mapping (ENOENT/ENOTDIR/EFAULT), the link/dangling-link cases and the Windows throw on symlinks look right, and the third-party Windows and title runs in the thread agree. Merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6089865663 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1624#issuecomment-6089865663). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-09T21:52:00Z. --- Checked on Linux (merged onto current `main`): build and `guest_filesystem` pass, and the test no longer links without the change. Error mapping (`ENOENT`/`ENOTDIR`/`EFAULT`), the link/dangling-link cases and the Windows throw on symlinks look right, and the third-party Windows and title runs in the thread agree. 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!1624
No description provided.