refactor(libc): share the guest errno failure return #26274

Closed
LeandroLP23 wants to merge 1 commit from upstream-pr/26274 into main
LeandroLP23 commented 2026-11-23 15:45:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-11-23T15:45:13Z.


What

Eighteen functions in libkernel, libkernel_sys and libScePosixForWebKit have the same body: they set the guest errno through __error_nid_postfix() and return -1. They go by six names (Fail, Failure, PosixFailure, SysarchFailure, SchedFailure, _fail).

  • libc/include/GuestErrno.hpp, which declares __error_nid_postfix, gets that body once, as inline int FailWithGuestErrno(int error).
  • Three copies are replaced by it, in the files where no open pull request conflicts with the change: SysarchFailure in libkernel/System/src/Process.cpp, Fail in libkernel_sys/NamedObject.cpp and Failure in libScePosixForWebKit/Filesystem.cpp. Their callers call FailWithGuestErrno with the same argument.
  • The other 15 copies are left as they are, because open pull requests change the lines around their callers. Renaming those calls now would make each of them conflict. They can switch to the helper as those pull requests land.
  • Two similar functions are not copies and stay: Fail in libkernel/Pthread/Posix/Sem.cpp writes the host errno, and Fail in libkernel/System/src/ThermalSensors.cpp returns a kernel error code.

29 lines removed and 22 added.

No change in behaviour.

Tested

Windows 11 (10.0.26300), WinLibs GCC 15.2.0 r7, Release. ctest -R 'kernel|named_?object|resolver_access|guest_posix', with its 132 build outputs from tools/select_tests.py targets: 178 of 178 on main c3aec4c2f3 and 178 of 178 with this change applied to it. tools/check_conventions.py passes. tools/pr_overlap.py --branch finds no overlap with the 2585 open pull requests.

Not run: Linux and macOS.

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 and the licence notice of code adapted from upstream (see AGENTS.md)
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • 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
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5456262120 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/26274). Originally posted by [LeandroLP23](https://github.com/LeandroLP23) on 2026-11-23T15:45:13Z. --- ### What Eighteen functions in `libkernel`, `libkernel_sys` and `libScePosixForWebKit` have the same body: they set the guest `errno` through `__error_nid_postfix()` and return -1. They go by six names (`Fail`, `Failure`, `PosixFailure`, `SysarchFailure`, `SchedFailure`, `_fail`). - `libc/include/GuestErrno.hpp`, which declares `__error_nid_postfix`, gets that body once, as `inline int FailWithGuestErrno(int error)`. - Three copies are replaced by it, in the files where no open pull request conflicts with the change: `SysarchFailure` in `libkernel/System/src/Process.cpp`, `Fail` in `libkernel_sys/NamedObject.cpp` and `Failure` in `libScePosixForWebKit/Filesystem.cpp`. Their callers call `FailWithGuestErrno` with the same argument. - The other 15 copies are left as they are, because open pull requests change the lines around their callers. Renaming those calls now would make each of them conflict. They can switch to the helper as those pull requests land. - Two similar functions are not copies and stay: `Fail` in `libkernel/Pthread/Posix/Sem.cpp` writes the host `errno`, and `Fail` in `libkernel/System/src/ThermalSensors.cpp` returns a kernel error code. 29 lines removed and 22 added. No change in behaviour. ### Tested Windows 11 (10.0.26300), WinLibs GCC 15.2.0 r7, Release. `ctest -R 'kernel|named_?object|resolver_access|guest_posix'`, with its 132 build outputs from `tools/select_tests.py targets`: 178 of 178 on `main` `c3aec4c2f3` and 178 of 178 with this change applied to it. `tools/check_conventions.py` passes. `tools/pr_overlap.py --branch` finds no overlap with the 2585 open pull requests. Not run: Linux and macOS. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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) and the licence notice of code adapted from upstream (see AGENTS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [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] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes

Pull request closed

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!26274
No description provided.