fix(libkernel): set guest errno on failure in sceKernel file calls #24960

Merged
birdmarty merged 3 commits from upstream-pr/24960 into main 2026-11-25 04:32:34 +00:00
birdmarty commented 2026-11-21 13:12:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by birdmarty on 2026-11-21T13:12:03Z.


What

Set guest errno (*__error()) on failure and preserve it on success across the POSIX-paired sceKernel* file and descriptor calls in libkernel.

On the PS5 console, libkernel's sceKernel* wrappers return 0x80020000 | errno on failure and also store that errno in *__error() (already recorded in docs/dev/debt/libkernel.md for sceKernelFcntl on firmware 13.60, sceKernelGetAppInfo on firmware 12.70/13.09, sceKernelGetProcessAbiType on firmware 13.60, and in libkernel_sys.md for sceKernelGetAppCategoryType on firmware 13.590.001). In AnyPS5, sceKernelFcntl and sceKernelFtruncate already behaved this way because they delegated to their POSIX implementations, and sceKernelClose/Read/Write/Readv/Writev did so only for guest sockets, while the remaining sceKernel* file calls returned 0x8002xxxx without setting *__error(). Because __error() aliases host errno, internal host calls (such as std::filesystem::exists in sceKernelMkdir) could also overwrite *__error() with ENOENT even when a sceKernel* call succeeded.

Guest code that calls sceKernelMkdir (or another sceKernel* file call) and inspects *__error() on a nonzero return (for example checking *__error() == EEXIST after sceKernelMkdir returns 0x80020011) therefore saw a stale errno instead of 17.

This reverses the rule an earlier change applied to sceKernelReadv: 829f40c523 (a follow-up to #13798) made it keep errno when its iovec copy faults, on the reasoning that a call reporting the fault through its return code should not touch the guest's errno, and guest_output_pointer_fault checks that. On the console the sceKernel* wrappers return 0x80020000 | errno with errno set (the measurements above), and a readv whose iovec array cannot be read fails in the kernel with EFAULT, so sceKernelReadv now sets errno to 14 like the other wrapped calls, and the test's sceKernelReadv check expects 14. The checked copy helpers themselves (GuestCopyIn/GuestCopyOut, GuestSocketReadGuest, CopyIovecs) still keep errno on a fault, and the test's checks of them are unchanged. That this readv EFAULT path sets errno on the console is inferred from those wrappers, not measured.

Changes

  • core/libs/prx/libkernel/File/src/Stdio.cpp, core/libs/prx/libkernel/File/src/Open.cpp: wrap the POSIX-paired sceKernel* file/descriptor calls (sceKernelOpen, Close, Read, Write, Lseek, Stat, Unlink, Fstat, Fsync, Fdatasync, Getdirentries, Getdents, Mkdir, Rmdir, Rename, Chmod, Fchmod, Truncate, Ftruncate, Utimes, Futimes, Pread, Pwrite, Readv, Writev, Preadv, Pwritev, Rdup) with File::RunKernelFileCall (core/libs/prx/libkernel/File/include/File.hpp), which saves *__error() before the call, stores static_cast<int>(result) & 0xffff in *__error() when result < 0, and restores the saved errno when result >= 0. sceKernelOpen, sceKernelClose and sceKernelLseek are wrapped whole, so errno is set after their failure logging.
  • core/libs/tests/GuestKernelFileErrno.cpp and core/libs/prx/libkernel/tests/cmake/guest_kernel_file_errno_tests.cmake: add guest_kernel_file_errno, verifying that each of these calls sets the matching guest errno on failure (including sceKernelMkdir on an existing directory setting errno == 17 over a prior ENOENT) and leaves a preset errno untouched on success.
  • core/libs/tests/GuestOutputPointerFault.cpp: sceKernelReadv over an unreadable iovec array now expects errno 14 (see above); its checks of the copy helpers keeping errno are unchanged.
  • docs/dev/debt/changes/fix-libkernel-file-calls-set-errno.md: note that individual per-error-path console measurement for each wrapper (including user-space argument checks and host-safety EFAULT copies) has not been done.

Tested

Windows 11 Pro (build 26300), Intel Core i9-9900K, MinGW-w64 GCC 15.3.0, Release build with tests, based on origin/main 8ab98849d5.

  • Without the fix (origin/main 8ab98849d5 Stdio.cpp and Open.cpp built with the new test): guest_kernel_file_errno fails immediately at line 70 (GuestKernelFileErrno failed at line 70 (guest errno 2)), where sceKernelMkdir on a new directory clobbered the sentinel errno to 2 (and on an existing directory leaves errno at 2 instead of 17).
  • With the fix (37052d92e0):
    • guest_kernel_file_errno and 13 related file/kernel tests: 14/14 passed (guest_kernel_file_errno, guest_filesystem, guest_kernel_sync, guest_posix_scalar_io, guest_kernel_sys_dup, guest_truncate, guest_truncate_race, guest_truncate_extend, guest_file_timestamps, kernel_error, guest_kernel_errors, guest_path_name_length, guest_sce_v2_filesystem_calls, guest_kernel_sys).
    • guest_file_lock_*: 7/7 passed.
    • guest_fios2: 1/1 passed.
    • public_headers: passed.
  • Follow-up commit (53fe6e13e4: shared helper, errno after logging, guest_output_pointer_fault update): the Windows CI run on 37052d92e0 failed only guest_output_pointer_fault (its sceKernelReadv check expected the old kept errno). With the follow-up, on the same base, 104 file, descriptor and kernel tests passed and 1 skipped itself (guest_fopen_errors): guest_kernel_file_errno, guest_output_pointer_fault, guest_filesystem, guest_filesystem_error, guest_kernel_fstat, guest_kernel_pread_pwrite, guest_kernel_rename, guest_fstat_fault, guest_fstat_fault_syscall, guest_file_vector, guest_file_vector_memory, guest_truncate*, guest_fios2*, guest_file_lock_*, guest_kernel_sys*, guest_posix_scalar_io, guest_sce_v2_filesystem_calls, guest_path_name_length, guest_rename_dot, guest_app_info, kernel_error and the others in the same groups.
  • Third commit (ffc0cb860c): the second commit had wrapped sceKernelOpen in a lambda, so its three log lines were tagged operator(); sceKernelOpen now sets errno at each return through File::KernelFileResult, after its logging. 104/104 of the same tests pass (on main e60b2f74ad with my other open PRs), and a Forza Horizon 5 log shows 9,305 [src/Open.cpp:406 sceKernelOpen] lines and no operator() tag.
  • py -3 tools/check_conventions.py --base origin/main: All conventions checks passed.
  • py -3 tools/debt_fold.py --check: fails only on an unrelated pre-existing main fragment (docs/dev/debt/changes/feat-libwebrtc-rnn-vad.md:3); this branch's fragment passed check_conventions.py.
  • py -3 tools/pr_overlap.py --names sceKernelMkdir and --branch fix/libkernel-file-calls-set-errno (2,179 open PRs): no open PR implements this change. Textual overlaps on Open.cpp are unrelated (#12682 read cancellation, #24487/#24488 ksem id checks); the 12 conflicted PRs touching Stdio.cpp/Open.cpp (#6936, #7121, #7447, #9293, #9297, #9302, #12688, #12700, #12965, #15037, #18190, #23799) and the library-split/mirroring PRs (#18112, #18190, #24322, #24910, #24917) were checked and none overlap functionally.
  • Not tested: Linux and macOS host builds (Windows host only), and per-call console measurements beyond the existing libkernel debt notes.

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: PPSA22327 #25152
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5428145904 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24960). Originally posted by [birdmarty](https://github.com/birdmarty) on 2026-11-21T13:12:03Z. --- ### What Set guest `errno` (`*__error()`) on failure and preserve it on success across the POSIX-paired `sceKernel*` file and descriptor calls in `libkernel`. On the PS5 console, `libkernel`'s `sceKernel*` wrappers return `0x80020000 | errno` on failure and also store that `errno` in `*__error()` (already recorded in `docs/dev/debt/libkernel.md` for `sceKernelFcntl` on firmware 13.60, `sceKernelGetAppInfo` on firmware 12.70/13.09, `sceKernelGetProcessAbiType` on firmware 13.60, and in `libkernel_sys.md` for `sceKernelGetAppCategoryType` on firmware 13.590.001). In AnyPS5, `sceKernelFcntl` and `sceKernelFtruncate` already behaved this way because they delegated to their POSIX implementations, and `sceKernelClose`/`Read`/`Write`/`Readv`/`Writev` did so only for guest sockets, while the remaining `sceKernel*` file calls returned `0x8002xxxx` without setting `*__error()`. Because `__error()` aliases host `errno`, internal host calls (such as `std::filesystem::exists` in `sceKernelMkdir`) could also overwrite `*__error()` with `ENOENT` even when a `sceKernel*` call succeeded. Guest code that calls `sceKernelMkdir` (or another `sceKernel*` file call) and inspects `*__error()` on a nonzero return (for example checking `*__error() == EEXIST` after `sceKernelMkdir` returns `0x80020011`) therefore saw a stale `errno` instead of `17`. This reverses the rule an earlier change applied to `sceKernelReadv`: 829f40c523 (a follow-up to #13798) made it keep `errno` when its iovec copy faults, on the reasoning that a call reporting the fault through its return code should not touch the guest's `errno`, and `guest_output_pointer_fault` checks that. On the console the `sceKernel*` wrappers return `0x80020000 | errno` with `errno` set (the measurements above), and a readv whose iovec array cannot be read fails in the kernel with `EFAULT`, so `sceKernelReadv` now sets `errno` to 14 like the other wrapped calls, and the test's `sceKernelReadv` check expects 14. The checked copy helpers themselves (`GuestCopyIn`/`GuestCopyOut`, `GuestSocketReadGuest`, `CopyIovecs`) still keep `errno` on a fault, and the test's checks of them are unchanged. That this readv `EFAULT` path sets `errno` on the console is inferred from those wrappers, not measured. #### Changes - `core/libs/prx/libkernel/File/src/Stdio.cpp`, `core/libs/prx/libkernel/File/src/Open.cpp`: wrap the POSIX-paired `sceKernel*` file/descriptor calls (`sceKernelOpen`, `Close`, `Read`, `Write`, `Lseek`, `Stat`, `Unlink`, `Fstat`, `Fsync`, `Fdatasync`, `Getdirentries`, `Getdents`, `Mkdir`, `Rmdir`, `Rename`, `Chmod`, `Fchmod`, `Truncate`, `Ftruncate`, `Utimes`, `Futimes`, `Pread`, `Pwrite`, `Readv`, `Writev`, `Preadv`, `Pwritev`, `Rdup`) with `File::RunKernelFileCall` (`core/libs/prx/libkernel/File/include/File.hpp`), which saves `*__error()` before the call, stores `static_cast<int>(result) & 0xffff` in `*__error()` when `result < 0`, and restores the saved `errno` when `result >= 0`. `sceKernelOpen`, `sceKernelClose` and `sceKernelLseek` are wrapped whole, so `errno` is set after their failure logging. - `core/libs/tests/GuestKernelFileErrno.cpp` and `core/libs/prx/libkernel/tests/cmake/guest_kernel_file_errno_tests.cmake`: add `guest_kernel_file_errno`, verifying that each of these calls sets the matching guest `errno` on failure (including `sceKernelMkdir` on an existing directory setting `errno == 17` over a prior `ENOENT`) and leaves a preset `errno` untouched on success. - `core/libs/tests/GuestOutputPointerFault.cpp`: `sceKernelReadv` over an unreadable iovec array now expects `errno` 14 (see above); its checks of the copy helpers keeping `errno` are unchanged. - `docs/dev/debt/changes/fix-libkernel-file-calls-set-errno.md`: note that individual per-error-path console measurement for each wrapper (including user-space argument checks and host-safety `EFAULT` copies) has not been done. ### Tested Windows 11 Pro (build 26300), Intel Core i9-9900K, MinGW-w64 GCC 15.3.0, Release build with tests, based on `origin/main` 8ab98849d5. - **Without the fix** (`origin/main` 8ab98849d5 `Stdio.cpp` and `Open.cpp` built with the new test): `guest_kernel_file_errno` fails immediately at line 70 (`GuestKernelFileErrno failed at line 70 (guest errno 2)`), where `sceKernelMkdir` on a new directory clobbered the sentinel `errno` to `2` (and on an existing directory leaves `errno` at `2` instead of `17`). - **With the fix** (37052d92e0): - `guest_kernel_file_errno` and 13 related file/kernel tests: 14/14 passed (`guest_kernel_file_errno`, `guest_filesystem`, `guest_kernel_sync`, `guest_posix_scalar_io`, `guest_kernel_sys_dup`, `guest_truncate`, `guest_truncate_race`, `guest_truncate_extend`, `guest_file_timestamps`, `kernel_error`, `guest_kernel_errors`, `guest_path_name_length`, `guest_sce_v2_filesystem_calls`, `guest_kernel_sys`). - `guest_file_lock_*`: 7/7 passed. - `guest_fios2`: 1/1 passed. - `public_headers`: passed. - **Follow-up commit** (53fe6e13e4: shared helper, `errno` after logging, `guest_output_pointer_fault` update): the Windows CI run on 37052d92e0 failed only `guest_output_pointer_fault` (its `sceKernelReadv` check expected the old kept `errno`). With the follow-up, on the same base, 104 file, descriptor and kernel tests passed and 1 skipped itself (`guest_fopen_errors`): `guest_kernel_file_errno`, `guest_output_pointer_fault`, `guest_filesystem`, `guest_filesystem_error`, `guest_kernel_fstat`, `guest_kernel_pread_pwrite`, `guest_kernel_rename`, `guest_fstat_fault`, `guest_fstat_fault_syscall`, `guest_file_vector`, `guest_file_vector_memory`, `guest_truncate*`, `guest_fios2*`, `guest_file_lock_*`, `guest_kernel_sys*`, `guest_posix_scalar_io`, `guest_sce_v2_filesystem_calls`, `guest_path_name_length`, `guest_rename_dot`, `guest_app_info`, `kernel_error` and the others in the same groups. - **Third commit** (ffc0cb860c): the second commit had wrapped `sceKernelOpen` in a lambda, so its three log lines were tagged `operator()`; `sceKernelOpen` now sets `errno` at each return through `File::KernelFileResult`, after its logging. 104/104 of the same tests pass (on `main` e60b2f74ad with my other open PRs), and a Forza Horizon 5 log shows 9,305 `[src/Open.cpp:406 sceKernelOpen]` lines and no `operator()` tag. - `py -3 tools/check_conventions.py --base origin/main`: `All conventions checks passed.` - `py -3 tools/debt_fold.py --check`: fails only on an unrelated pre-existing `main` fragment (`docs/dev/debt/changes/feat-libwebrtc-rnn-vad.md:3`); this branch's fragment passed `check_conventions.py`. - `py -3 tools/pr_overlap.py --names sceKernelMkdir` and `--branch fix/libkernel-file-calls-set-errno` (2,179 open PRs): no open PR implements this change. Textual overlaps on `Open.cpp` are unrelated (#12682 read cancellation, #24487/#24488 ksem id checks); the 12 conflicted PRs touching `Stdio.cpp`/`Open.cpp` (#6936, #7121, #7447, #9293, #9297, #9302, #12688, #12700, #12965, #15037, #18190, #23799) and the library-split/mirroring PRs (#18112, #18190, #24322, #24910, #24917) were checked and none overlap functionally. - Not tested: Linux and macOS host builds (Windows host only), and per-call console measurements beyond the existing `libkernel` debt notes. ### 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: PPSA22327 #25152 - [x] GPUs tested: n/a - [x] AI-assisted: yes
PrivacyOnion commented 2026-11-21 13:15:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-21T13:15:44Z.

Review: APPROVED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 37052d92e0:

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_kernel_file_errno_tests built cleanly.
  • CTest (guest_kernel_file_errno):
    1/1 Test #6125: guest_kernel_file_errno ..........   Passed    0.01 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libkernel/File/src/Open.cpp, core/libs/prx/libkernel/File/src/Stdio.cpp reverted to main and the new tests kept, the suite fails:
    1/1 Test #6125: guest_kernel_file_errno ..........Subprocess aborted***Exception:   1.07 sec
    0% tests passed, 1 tests failed out of 1
    
    Restoring the change makes it pass again.
  • Code reading:
    • Verified that KernelFileResult and RunKernelFileCall in Open.cpp and Stdio.cpp consistently preserve *__error_nid_postfix() on success (>= 0) and update it with the low 16-bits errno on failure (< 0) across all wrapped functions.
    • Verified that sceKernelOpen correctly wraps all return paths (InvalidOpenFlags, CopyGuestPath_nid_no_patch, empty copy, IsRandomDevicePath, ResolvePathError_nid_no_patch, OpenNative) with KernelFileResult(savedErrno, ...).
    • Verified that 64-bit return APIs (sceKernelRead, sceKernelWrite, sceKernelLseek, sceKernelPread, sceKernelPwrite, sceKernelReadv, sceKernelWritev, sceKernelPreadv, sceKernelPwritev) properly cast negative int64 error codes (& 0xffff) without signed truncation issues or sign-extension corruption.
    • Checked that nested or internal calls (such as sceKernelGetdents delegating to sceKernelGetdirentries, or sceKernelRead calling KernelRead for empty buffer checks) do not double-clobber or erroneously mutate guest errno on intermediate paths.
    • Confirmed that AGENTS.md compliance is respected: no comments added, technical debt fragment correctly placed in docs/dev/debt/changes/fix-libkernel-file-calls-set-errno.md, and new test suite guest_kernel_file_errno properly integrated into CMake.

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6005388404 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24960#pullrequestreview-6005388404). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-21T13:15:44Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `37052d92e0`: - **Conventions**: `tools/check_conventions.py` passed. - **Build**: `guest_kernel_file_errno_tests` built cleanly. - **CTest** (`guest_kernel_file_errno`): ``` 1/1 Test #6125: guest_kernel_file_errno .......... Passed 0.01 sec 100% tests passed, 0 tests failed out of 1 ``` - **Negative control**: with `core/libs/prx/libkernel/File/src/Open.cpp`, `core/libs/prx/libkernel/File/src/Stdio.cpp` reverted to `main` and the new tests kept, the suite fails: ``` 1/1 Test #6125: guest_kernel_file_errno ..........Subprocess aborted***Exception: 1.07 sec 0% tests passed, 1 tests failed out of 1 ``` Restoring the change makes it pass again. - **Code reading**: - Verified that KernelFileResult and RunKernelFileCall in Open.cpp and Stdio.cpp consistently preserve *__error_nid_postfix() on success (>= 0) and update it with the low 16-bits errno on failure (< 0) across all wrapped functions. - Verified that sceKernelOpen correctly wraps all return paths (InvalidOpenFlags, CopyGuestPath_nid_no_patch, empty copy, IsRandomDevicePath, ResolvePathError_nid_no_patch, OpenNative) with KernelFileResult(savedErrno, ...). - Verified that 64-bit return APIs (sceKernelRead, sceKernelWrite, sceKernelLseek, sceKernelPread, sceKernelPwrite, sceKernelReadv, sceKernelWritev, sceKernelPreadv, sceKernelPwritev) properly cast negative int64 error codes (& 0xffff) without signed truncation issues or sign-extension corruption. - Checked that nested or internal calls (such as sceKernelGetdents delegating to sceKernelGetdirentries, or sceKernelRead calling KernelRead for empty buffer checks) do not double-clobber or erroneously mutate guest errno on intermediate paths. - Confirmed that AGENTS.md compliance is respected: no comments added, technical debt fragment correctly placed in docs/dev/debt/changes/fix-libkernel-file-calls-set-errno.md, and new test suite guest_kernel_file_errno properly integrated into CMake. Looks Good To Me
MarcZX10 commented 2026-11-21 13:19:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T13:19:29Z.

Review: COMMENTED


Reviewed — no blocking findings

The changed code and test files were inspected, but the review is incomplete because the full diffs and all changed-file contents were not examined; no formal approval is justified.

What I ran

  • Reviewed head 37052d92e02e2a8c63d3b31add74a70e274e9772 using the pinned repo_read.py reader.
  • No tests or build commands were run.

Results

Check Result Note
Diff inspection not run Only part of the diff was read
Tests not run No commands executed

Findings

Blocking

None identified in the inspected portions.

Non-blocking

None.

Not verified

The full contents of the changed files and the remaining diff were not read. Files listed as reviewed in the manifest: Open.cpp, Stdio.cpp, guest_kernel_file_errno_tests.cmake, GuestKernelFileErrno.cpp, and fix-libkernel-file-calls-set-errno.md. No files were excluded according to the file listing.

To get this to a good state

Nothing is required. Complete inspection of the remaining diff and changed-file contents before making a formal review decision.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6005408250 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24960#pullrequestreview-6005408250). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-21T13:19:29Z. **Review:** COMMENTED --- # Reviewed — no blocking findings The changed code and test files were inspected, but the review is incomplete because the full diffs and all changed-file contents were not examined; no formal approval is justified. ## What I ran - Reviewed head `37052d92e02e2a8c63d3b31add74a70e274e9772` using the pinned `repo_read.py` reader. - No tests or build commands were run. ## Results | Check | Result | Note | |---|---|---| | Diff inspection | not run | Only part of the diff was read | | Tests | not run | No commands executed | ## Findings ### Blocking None identified in the inspected portions. ### Non-blocking None. ## Not verified The full contents of the changed files and the remaining diff were not read. Files listed as reviewed in the manifest: `Open.cpp`, `Stdio.cpp`, `guest_kernel_file_errno_tests.cmake`, `GuestKernelFileErrno.cpp`, and `fix-libkernel-file-calls-set-errno.md`. No files were excluded according to the file listing. ## To get this to a good state Nothing is required. Complete inspection of the remaining diff and changed-file contents before making a formal review decision.
PrivacyOnion commented 2026-11-21 14:50:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-21T14:50:04Z.

Review: APPROVED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 53fe6e13e4:

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_kernel_file_errno_tests, guest_output_pointer_fault_tests built cleanly.
  • CTest (guest_output_pointer_fault, guest_output_pointer_fault_syscall, guest_kernel_file_errno):
    1/3 Test #6033: guest_output_pointer_fault ...........   Passed    0.02 sec
    2/3 Test #6034: guest_output_pointer_fault_syscall ...   Passed    0.06 sec
    3/3 Test #6129: guest_kernel_file_errno ..............   Passed    0.04 sec
    100% tests passed, 0 tests failed out of 3
    
  • Negative control: with core/libs/prx/libkernel/File/include/File.hpp, core/libs/prx/libkernel/File/src/Open.cpp, core/libs/prx/libkernel/File/src/Stdio.cpp reverted to main and the new tests kept, the suite fails:
    1/3 Test #6034: guest_output_pointer_fault_syscall ...Subprocess aborted***Exception:   0.77 sec
    2/3 Test #6129: guest_kernel_file_errno ..............Subprocess aborted***Exception:   0.91 sec
    3/3 Test #6033: guest_output_pointer_fault ...........Subprocess aborted***Exception:   0.83 sec
    0% tests passed, 3 tests failed out of 3
    
    Restoring the change makes it pass again.
  • Code reading:
    • Verified that RunKernelFileCall correctly captures saved errno, executes the call, preserves saved errno when result >= 0, and updates *__error_nid_postfix() with static_cast(result) & 0xffff on error (< 0) across all wrapped functions in File.hpp, Open.cpp, and Stdio.cpp.
    • Checked 64-bit return APIs (sceKernelRead, sceKernelWrite, sceKernelLseek, sceKernelPread, sceKernelPwrite, sceKernelReadv, sceKernelWritev, sceKernelPreadv, sceKernelPwritev) to ensure error values are negative int64_t and the bitmasking & 0xffff preserves the low 16 bits without sign or truncation anomalies.
    • Verified that sceKernelGetdents calls sceKernelGetdirentries, which itself is wrapped with RunKernelFileCall, avoiding unintended errno corruption.
    • Checked AGENTS.md technical debt fragment in docs/dev/debt/changes/fix-libkernel-file-calls-set-errno.md and confirmed strict compliance with repository conventions and no illegal comments added.
    • Audited GuestKernelFileErrno.cpp test coverage to verify that POSIX file wrappers correctly preserve guest errno on success and set guest errno on failure.

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6006113602 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24960#pullrequestreview-6006113602). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-21T14:50:04Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `53fe6e13e4`: - **Conventions**: `tools/check_conventions.py` passed. - **Build**: `guest_kernel_file_errno_tests`, `guest_output_pointer_fault_tests` built cleanly. - **CTest** (`guest_output_pointer_fault`, `guest_output_pointer_fault_syscall`, `guest_kernel_file_errno`): ``` 1/3 Test #6033: guest_output_pointer_fault ........... Passed 0.02 sec 2/3 Test #6034: guest_output_pointer_fault_syscall ... Passed 0.06 sec 3/3 Test #6129: guest_kernel_file_errno .............. Passed 0.04 sec 100% tests passed, 0 tests failed out of 3 ``` - **Negative control**: with `core/libs/prx/libkernel/File/include/File.hpp`, `core/libs/prx/libkernel/File/src/Open.cpp`, `core/libs/prx/libkernel/File/src/Stdio.cpp` reverted to `main` and the new tests kept, the suite fails: ``` 1/3 Test #6034: guest_output_pointer_fault_syscall ...Subprocess aborted***Exception: 0.77 sec 2/3 Test #6129: guest_kernel_file_errno ..............Subprocess aborted***Exception: 0.91 sec 3/3 Test #6033: guest_output_pointer_fault ...........Subprocess aborted***Exception: 0.83 sec 0% tests passed, 3 tests failed out of 3 ``` Restoring the change makes it pass again. - **Code reading**: - Verified that RunKernelFileCall correctly captures saved errno, executes the call, preserves saved errno when result >= 0, and updates *__error_nid_postfix() with static_cast<int>(result) & 0xffff on error (< 0) across all wrapped functions in File.hpp, Open.cpp, and Stdio.cpp. - Checked 64-bit return APIs (sceKernelRead, sceKernelWrite, sceKernelLseek, sceKernelPread, sceKernelPwrite, sceKernelReadv, sceKernelWritev, sceKernelPreadv, sceKernelPwritev) to ensure error values are negative int64_t and the bitmasking & 0xffff preserves the low 16 bits without sign or truncation anomalies. - Verified that sceKernelGetdents calls sceKernelGetdirentries, which itself is wrapped with RunKernelFileCall, avoiding unintended errno corruption. - Checked AGENTS.md technical debt fragment in docs/dev/debt/changes/fix-libkernel-file-calls-set-errno.md and confirmed strict compliance with repository conventions and no illegal comments added. - Audited GuestKernelFileErrno.cpp test coverage to verify that POSIX file wrappers correctly preserve guest errno on success and set guest errno on failure. Looks Good To Me
Superseabas commented 2026-11-22 11:54:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Superseabas on 2026-11-22T11:54:47Z.

Review: APPROVED


Windows check of head ffc0cb860c with GCC 16, merged onto main 7eb79b0c48 (clean merge).

Setup: Windows 11 Home 10.0.26200, Ryzen 7 7700X, WinLibs GCC 16.2.0 (x86_64-ucrt-posix-seh, r3), CMake 4.4.4, Ninja 1.13.2, Release full build, run from PowerShell. This was built together with #22140, which touches other files.

  • File, descriptor and kernel-error tests, the description's set (guest_kernel_file_errno, guest_output_pointer_fault, guest_filesystem*, guest_kernel_fstat, guest_kernel_pread_pwrite, guest_kernel_rename, guest_fstat_fault*, guest_file_vector*, guest_truncate*, guest_fios2*, guest_file_lock_*, guest_kernel_sys, guest_posix_scalar_io, guest_sce_v2_filesystem_calls, guest_path_name_length, guest_rename_dot, guest_app_info, guest_kernel_sync, guest_kernel_sys_dup, guest_file_timestamps, guest_kernel_errors, kernel_error): main 37 of 37, and with this PR 38 of 38 in 3 of 3 runs. The extra one is guest_kernel_file_errno.
  • Red check: with File::KernelFileResult keeping the saved errno on failure too (both overloads: = result < 0 ? (… & 0xffff) : saved; → = saved;), guest_kernel_file_errno aborts (0xc0000409).

The approach reads right to me. One helper sets errno to the low 16 bits of the 0x8002xxxx result after the call's own logging, and restores the caller's errno on success, so host calls like the std::filesystem checks inside sceKernelMkdir no longer leak ENOENT into the guest. The sceKernelReadv change from keeping errno to setting 14 is explained in the description, and the fragment notes that the per-path console behaviour isn't measured.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6012077139 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24960#pullrequestreview-6012077139). Originally posted by [Superseabas](https://github.com/Superseabas) on 2026-11-22T11:54:47Z. **Review:** APPROVED --- Windows check of head `ffc0cb860c` with GCC 16, merged onto `main` `7eb79b0c48` (clean merge). **Setup:** Windows 11 Home 10.0.26200, Ryzen 7 7700X, WinLibs GCC 16.2.0 (`x86_64-ucrt-posix-seh`, r3), CMake 4.4.4, Ninja 1.13.2, Release full build, run from PowerShell. This was built together with #22140, which touches other files. - **File, descriptor and kernel-error tests**, the description's set (`guest_kernel_file_errno`, `guest_output_pointer_fault`, `guest_filesystem*`, `guest_kernel_fstat`, `guest_kernel_pread_pwrite`, `guest_kernel_rename`, `guest_fstat_fault*`, `guest_file_vector*`, `guest_truncate*`, `guest_fios2*`, `guest_file_lock_*`, `guest_kernel_sys`, `guest_posix_scalar_io`, `guest_sce_v2_filesystem_calls`, `guest_path_name_length`, `guest_rename_dot`, `guest_app_info`, `guest_kernel_sync`, `guest_kernel_sys_dup`, `guest_file_timestamps`, `guest_kernel_errors`, `kernel_error`): `main` 37 of 37, and with this PR 38 of 38 in 3 of 3 runs. The extra one is `guest_kernel_file_errno`. - **Red check:** with `File::KernelFileResult` keeping the saved `errno` on failure too (both overloads: `= result < 0 ? (… & 0xffff) : saved;` → `= saved;`), `guest_kernel_file_errno` aborts (`0xc0000409`). The approach reads right to me. One helper sets `errno` to the low 16 bits of the `0x8002xxxx` result after the call's own logging, and restores the caller's `errno` on success, so host calls like the `std::filesystem` checks inside `sceKernelMkdir` no longer leak `ENOENT` into the guest. The `sceKernelReadv` change from keeping `errno` to setting 14 is explained in the description, and the fragment notes that the per-path console behaviour isn't measured. AI-assisted: yes (Claude Code)
MarcZX10 commented 2026-11-22 12:17:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-22T12:17:50Z.

Review: COMMENTED


Reviewed — comments

Nothing blocks this; the points below are optional.

What I ran

Reviewed head ffc0cb860ca36c68411523599ead1f73987fe168 using repo_read.py tools. No commands or tests were run by me; test results in the PR description are author-reported.

Results

Check Result Note
Changed code review passed Inspected all seven changed files
Automated checks not run No build or tests run in this review
Console behavior not run Per-call firmware measurements remain unverified

Findings

Blocking

None.

Non-blocking

  • The test exercises successful sceKernelGetdirentries/sceKernelGetdents only as failure cases for invalid descriptors, and does not cover sceKernelOpen's random-device path. Adding success and error cases for those branches would strengthen the wrapper coverage. Relevant changed wrappers: core/libs/prx/libkernel/File/src/Stdio.cpp:1736 and core/libs/prx/libkernel/File/src/Open.cpp:407.
  • The PR description says readv’s iovec-copy EFAULT errno behavior on console is inferred rather than measured. Keep that distinction explicit until firmware measurement confirms it.

Not verified

  • No tests or builds were run by me; Windows results and convention checks are reported by the author.
  • No PS5 console behavior was measured in this review.
  • All seven changed files listed as reviewed in manifest.json were read: File.hpp, Open.cpp, Stdio.cpp, guest_kernel_file_errno_tests.cmake, GuestKernelFileErrno.cpp, GuestOutputPointerFault.cpp, and fix-libkernel-file-calls-set-errno.md. files.json was not available through the reader; no exclusions are listed in the manifest.

To get this to a good state

Nothing is required.

Optional: extend the test to cover successful directory-entry reads and the random-device open branch, and measure the readv copy-fault errno behavior on console.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6012153823 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24960#pullrequestreview-6012153823). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-22T12:17:50Z. **Review:** COMMENTED --- # Reviewed — comments Nothing blocks this; the points below are optional. ## What I ran Reviewed head `ffc0cb860ca36c68411523599ead1f73987fe168` using `repo_read.py` tools. No commands or tests were run by me; test results in the PR description are author-reported. ## Results | Check | Result | Note | |---|---|---| | Changed code review | passed | Inspected all seven changed files | | Automated checks | not run | No build or tests run in this review | | Console behavior | not run | Per-call firmware measurements remain unverified | ## Findings ### Blocking None. ### Non-blocking - The test exercises successful `sceKernelGetdirentries`/`sceKernelGetdents` only as failure cases for invalid descriptors, and does not cover `sceKernelOpen`'s random-device path. Adding success and error cases for those branches would strengthen the wrapper coverage. Relevant changed wrappers: `core/libs/prx/libkernel/File/src/Stdio.cpp:1736` and `core/libs/prx/libkernel/File/src/Open.cpp:407`. - The PR description says readv’s iovec-copy `EFAULT` errno behavior on console is inferred rather than measured. Keep that distinction explicit until firmware measurement confirms it. ## Not verified - No tests or builds were run by me; Windows results and convention checks are reported by the author. - No PS5 console behavior was measured in this review. - All seven changed files listed as reviewed in `manifest.json` were read: `File.hpp`, `Open.cpp`, `Stdio.cpp`, `guest_kernel_file_errno_tests.cmake`, `GuestKernelFileErrno.cpp`, `GuestOutputPointerFault.cpp`, and `fix-libkernel-file-calls-set-errno.md`. `files.json` was not available through the reader; no exclusions are listed in the manifest. ## To get this to a good state Nothing is required. Optional: extend the test to cover successful directory-entry reads and the random-device open branch, and measure the readv copy-fault errno behavior on console.
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!24960
No description provided.