fix(libkernel): translate host errno in the file functions' SCE errors #3681

Merged
zmeizy merged 1 commit from upstream-pr/3681 into main 2026-10-11 21:51:05 +00:00
zmeizy commented 2026-10-11 15:18:44 +00:00 (Migrated from github.com)

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


What

SceErrorFromErrno in libkernel/File/src/Stdio.cpp builds 0x80020000 | errno from the host errno. It passes values up to 34 through unchanged and turns everything else into EIO. Up to 34, Linux and FreeBSD numbering agree except for 11: Linux EAGAIN is 11, which is FreeBSD EDEADLK. Above 34 the two differ, so real errors were reported as EIO. For example, a non-blocking sceKernelReadv on an empty pipe returned 0x8002000b (EDEADLK) instead of 0x80020023 (EAGAIN). sceKernelMkdir with a too-long name returned EIO instead of ENAMETOOLONG (0x8002003f). The POSIX wrappers derive the guest errno from these codes, so readv and mkdir reported the wrong errno as well.

This maps the host values that differ to their FreeBSD numbers, using the host's own macros, so the mapping is the same on Linux and Windows:

  • EAGAIN → 35
  • EDEADLK → 11
  • ENAMETOOLONG → 63
  • ENOTEMPTY → 66
  • ELOOP → 62
  • EDQUOT → 69
  • EOVERFLOW → 84

Values up to 34 still pass through, and anything else still becomes EIO. The guest constants the file passes in itself are unchanged.

Sources: FreeBSD sys/sys/errno.h for the guest numbers. Open.cpp's SceIoErrorFromErrno already applies the same values for EAGAIN, EDEADLK, EDQUOT and EOVERFLOW.

Related: #2144 rewrites the separate mapping in Open.cpp; this PR changes only Stdio.cpp's. Both add an ErrorEagain constant and #include <fcntl.h> to GuestFileVector.cpp (#2144 for sceKernelRead, this PR for sceKernelReadv), so whichever merges second drops the duplicate constant.

Tested

Ubuntu 24.04, GCC 13.3, on main a11c8f7f.

  • guest_file_vector: new check that a non-blocking sceKernelReadv on an empty pipe returns 0x80020023 and readv sets errno 35 (skipped on Windows, which has no O_NONBLOCK pipes).
  • guest_filesystem: new check that sceKernelMkdir with a 300-character name returns 0x8002003f and mkdir sets errno 63.
  • Both tests abort on main without the change and pass with it.
  • Full ctest --timeout 120 --parallel 4 with the change: 832 tests. 4 fail, none related to this change:
    • guest_truncate: the container runs as root, which ignores the read-only bit.
    • guest_kernel_stack_protect: also fails on main; #3520 fixes it.
    • Two lavapipe image-sampling tests.

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:4820095199 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3681). Originally posted by [zmeizy](https://github.com/zmeizy) on 2026-10-11T15:18:44Z. --- ### What `SceErrorFromErrno` in `libkernel/File/src/Stdio.cpp` builds `0x80020000 | errno` from the host `errno`. It passes values up to 34 through unchanged and turns everything else into `EIO`. Up to 34, Linux and FreeBSD numbering agree except for 11: Linux `EAGAIN` is 11, which is FreeBSD `EDEADLK`. Above 34 the two differ, so real errors were reported as `EIO`. For example, a non-blocking `sceKernelReadv` on an empty pipe returned `0x8002000b` (`EDEADLK`) instead of `0x80020023` (`EAGAIN`). `sceKernelMkdir` with a too-long name returned `EIO` instead of `ENAMETOOLONG` (`0x8002003f`). The POSIX wrappers derive the guest `errno` from these codes, so `readv` and `mkdir` reported the wrong `errno` as well. This maps the host values that differ to their FreeBSD numbers, using the host's own macros, so the mapping is the same on Linux and Windows: - `EAGAIN` → 35 - `EDEADLK` → 11 - `ENAMETOOLONG` → 63 - `ENOTEMPTY` → 66 - `ELOOP` → 62 - `EDQUOT` → 69 - `EOVERFLOW` → 84 Values up to 34 still pass through, and anything else still becomes `EIO`. The guest constants the file passes in itself are unchanged. Sources: FreeBSD `sys/sys/errno.h` for the guest numbers. `Open.cpp`'s `SceIoErrorFromErrno` already applies the same values for `EAGAIN`, `EDEADLK`, `EDQUOT` and `EOVERFLOW`. Related: #2144 rewrites the separate mapping in `Open.cpp`; this PR changes only `Stdio.cpp`'s. Both add an `ErrorEagain` constant and `#include <fcntl.h>` to `GuestFileVector.cpp` (#2144 for `sceKernelRead`, this PR for `sceKernelReadv`), so whichever merges second drops the duplicate constant. ### Tested Ubuntu 24.04, GCC 13.3, on `main` `a11c8f7f`. - `guest_file_vector`: new check that a non-blocking `sceKernelReadv` on an empty pipe returns `0x80020023` and `readv` sets `errno` 35 (skipped on Windows, which has no `O_NONBLOCK` pipes). - `guest_filesystem`: new check that `sceKernelMkdir` with a 300-character name returns `0x8002003f` and `mkdir` sets `errno` 63. - Both tests abort on `main` without the change and pass with it. - Full `ctest --timeout 120 --parallel 4` with the change: 832 tests. 4 fail, none related to this change: - `guest_truncate`: the container runs as root, which ignores the read-only bit. - `guest_kernel_stack_protect`: also fails on `main`; #3520 fixes it. - Two lavapipe image-sampling tests. ### 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:51:01 +00:00 (Migrated from github.com)

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


Checked the errno mapping against FreeBSD sys/sys/errno.h (EAGAIN 35, EDEADLK 11, ENAMETOOLONG 63, ELOOP 62, ENOTEMPTY 66, EDQUOT 69, EOVERFLOW 84) and against Open.cpp's existing mapping; build and ctest of core/libs pass, and both new checks fail when the Stdio.cpp change is reverted. Merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6114192611 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3681#issuecomment-6114192611). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T21:51:01Z. --- Checked the errno mapping against FreeBSD `sys/sys/errno.h` (EAGAIN 35, EDEADLK 11, ENAMETOOLONG 63, ELOOP 62, ENOTEMPTY 66, EDQUOT 69, EOVERFLOW 84) and against `Open.cpp`'s existing mapping; build and ctest of `core/libs` pass, and both new checks fail when the `Stdio.cpp` change is reverted. 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!3681
No description provided.