fix(libkernel_sys): translate host errors to guest errno numbers #3685

Merged
zmeizy merged 1 commit from upstream-pr/3685 into main 2026-10-11 21:50:41 +00:00
zmeizy commented 2026-10-11 15:20:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by zmeizy on 2026-10-11T15:20:07Z.


What

GuestError in libkernel_sys/Export.cpp turns a std::error_code from std::filesystem into the guest errno. It passed host values up to 34 through unchanged and reported everything else as EIO. As a result, readlink set errno 5 (EIO) for:

  • a name that is too long, instead of 63 (ENAMETOOLONG);
  • a symbolic link loop in the path, instead of 62 (ELOOP).

A host EAGAIN (11 on Linux and Windows) would also have come out as the guest's EDEADLK.

This compares the error condition with the portable std::errc values whose numbers differ between the host and FreeBSD, and maps them:

  • resource_unavailable_try_again → 35
  • resource_deadlock_would_occur → 11
  • too_many_symbolic_link_levels → 62
  • filename_too_long → 63
  • directory_not_empty → 66
  • value_too_large → 84

The rest is unchanged.

Overlap: #3611 (implement pathconf) adds the same GuestEloop and GuestEnametoolong constants, plus a PathError helper that maps only those two values for pathconf. The two merge without a textual conflict but then define the constants twice, so whichever merges second drops its copies.

Source: FreeBSD sys/sys/errno.h for the guest numbers.

Tested

Ubuntu 24.04, GCC 13.3, on main 12c22662.

  • guest_kernel_sys: new checks:
    • readlink on a path with a 300-character name sets errno 63.
    • readlink through a two-link loop (loopA → loopB → loopA) sets errno 62.
    • Both are skipped on Windows, where the host errors for these cases differ.
  • The test aborts on main without the change and passes with it.
  • guest_filesystem and guest_kernel_stack_protect pass.

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 (n/a)
  • 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 (n/a)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes

🤖 Generated with Claude Code

https://claude.ai/code/session_01Ha6Tsy62AFUyp9a5Mf7vjA

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4820103943 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3685). Originally posted by [zmeizy](https://github.com/zmeizy) on 2026-10-11T15:20:07Z. --- ### What `GuestError` in `libkernel_sys/Export.cpp` turns a `std::error_code` from `std::filesystem` into the guest `errno`. It passed host values up to 34 through unchanged and reported everything else as `EIO`. As a result, `readlink` set `errno` 5 (`EIO`) for: - a name that is too long, instead of 63 (`ENAMETOOLONG`); - a symbolic link loop in the path, instead of 62 (`ELOOP`). A host `EAGAIN` (11 on Linux and Windows) would also have come out as the guest's `EDEADLK`. This compares the error condition with the portable `std::errc` values whose numbers differ between the host and FreeBSD, and maps them: - `resource_unavailable_try_again` → 35 - `resource_deadlock_would_occur` → 11 - `too_many_symbolic_link_levels` → 62 - `filename_too_long` → 63 - `directory_not_empty` → 66 - `value_too_large` → 84 The rest is unchanged. Overlap: #3611 (`implement pathconf`) adds the same `GuestEloop` and `GuestEnametoolong` constants, plus a `PathError` helper that maps only those two values for `pathconf`. The two merge without a textual conflict but then define the constants twice, so whichever merges second drops its copies. Source: FreeBSD `sys/sys/errno.h` for the guest numbers. ### Tested Ubuntu 24.04, GCC 13.3, on `main` `12c22662`. - `guest_kernel_sys`: new checks: - `readlink` on a path with a 300-character name sets `errno` 63. - `readlink` through a two-link loop (`loopA` → `loopB` → `loopA`) sets `errno` 62. - Both are skipped on Windows, where the host errors for these cases differ. - The test aborts on `main` without the change and passes with it. - `guest_filesystem` and `guest_kernel_stack_protect` pass. ### 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) (n/a) - [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 (n/a) - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01Ha6Tsy62AFUyp9a5Mf7vjA
adriadam10 commented 2026-10-11 21:50:36 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T21:50:36Z.


Checked the six mappings against FreeBSD sys/sys/errno.h (EDEADLK 11, EAGAIN 35, ELOOP 62, ENAMETOOLONG 63, ENOTEMPTY 66, EOVERFLOW 84), built on Linux and ran guest_kernel_sys (passes; fails with the Export.cpp change reverted). Merging.

Note for #3611: it defines GuestEloop/GuestEnametoolong too and conflicts with this in Export.cpp; after this lands it should reuse these constants and GuestError.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6114188836 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3685#issuecomment-6114188836). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T21:50:36Z. --- Checked the six mappings against FreeBSD `sys/sys/errno.h` (EDEADLK 11, EAGAIN 35, ELOOP 62, ENAMETOOLONG 63, ENOTEMPTY 66, EOVERFLOW 84), built on Linux and ran `guest_kernel_sys` (passes; fails with the `Export.cpp` change reverted). Merging. Note for #3611: it defines `GuestEloop`/`GuestEnametoolong` too and conflicts with this in `Export.cpp`; after this lands it should reuse these constants and `GuestError`.
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!3685
No description provided.