Skip to content

fix(libc): map ENODATA, ENOSR, ENOSTR, EOTHER, and ETIME in GuestErrnoFromHost - #27924

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
gurtgg:fix-libc-host-errno-extended-codes
Dec 5, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
gurtgg:fix-libc-host-errno-extended-codes

Conversation

@gurtgg

@gurtgg gurtgg commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

What

  • Map #ifdef-guarded ENODATA (1040), ENOSR (1050), ENOSTR (1051), EOTHER (1062), and ETIME (1074) in HostErrnoMap[] inside GuestErrnoFromHost_nid_no_patch (core/libs/prx/libc/src/HostErrno.cpp), matching the extended guest error codes defined in core/libs/prx/libc/src/Errors.cpp (with 1040, 1050, 1051, and 1074 also matching SceV2SyserrorMessage in core/libs/prx/libc/src/exception/StandardExceptions.cpp, which does not define 1062), while keeping ENOTRECOVERABLE (95) and EOWNERDEAD (96) unchanged.
  • Prevents GuestErrnoFromHost_nid_no_patch (called across FileAndHeap.cpp, StandardStreams.cpp, AllocatingStrings.cpp, FormattingWide.cpp, libSceLibcInternal/Spawn.cpp, libScePosixForWebKit/Resolver.cpp, and libkernel/Time/Time.cpp) from falling through error > 0 && error <= 34 and returning GuestEio (5) for those host errnos on Windows UCRT, Linux, and macOS.

Tested

  • guest_atoi (core/libs/tests/GuestAtoi.cpp, errnoCases[]): verifies #ifdef-guarded ENODATA -> 1040, ENOSR -> 1050, ENOSTR -> 1051, EOTHER -> 1062, and ETIME -> 1074 (negative control returning 5 on unmodified main) alongside existing mapped errnos, ENOENT/ERANGE, and 0/-1/9999 fallback to 5.

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 upstream licence notices (tools/check_conventions.py passes)
  • 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
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Negative-control regression test (plus valid/boundary cases) fails against unmodified main and passes after fix
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

Summary by CodeRabbit

  • Bug Fixes
    • Improved compatibility when handling additional system error conditions, including missing data, unavailable streams, and timeouts.
    • Error values are now recognized where supported by the host platform.

@coderabbitai

coderabbitai Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Changes: Errno mappings

Layer / File(s) Summary
Add mappings and test expectations
core/libs/prx/libc/src/HostErrno.cpp, core/libs/tests/GuestAtoi.cpp
HostErrnoMap maps the five host error constants to guest values when each constant is defined. The errnoCases table adds matching expected values.

Suggested labels: libc, prx

Suggested reviewers: boykopovar, al3w0f205, marczx10

Change: Bug fix

Merge Risk: Minimal · up to 9ecd6

This change maps five more host error codes to their guest equivalents so they no longer collapse to a generic I/O error. It is a small, conditionally compiled addition with matching test expectations, and no merge-blocking risk was identified.

Security architecture risk: Minimal · up to 9ecd6

The change gives guest applications more specific error codes for five host errors. It does not add a new way to invoke host operations or change permissions, and the existing fallback remains in place for unmatched errors.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The direct exposure change is limited to callers of the existing translator that receive one of the newly mapped host errors. Those callers can observe a different integer result; the translator itself gains no new host operation or authority.
Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 56fcf725-d551-494f-bf1a-d237b139591f
Commits

Reviewing files that changed from the base of the PR and between fdf873a and 9ecd67a.

Files selected for processing: 2

  • core/libs/prx/libc/src/HostErrno.cpp
  • core/libs/tests/GuestAtoi.cpp

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.

@PrivacyOnion PrivacyOnion left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 9ecd67a22e:

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_atoi_tests built cleanly.
  • CTest (guest_atoi):
    1/1 Test #1482: guest_atoi .......................   Passed    0.01 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libc/src/HostErrno.cpp reverted to main and the new tests kept, the suite fails:
    1/1 Test #1482: guest_atoi .......................***Failed    0.03 sec
    0% tests passed, 1 tests failed out of 1
    
    Restoring the change makes it pass again.
  • Code reading:
    • Verified HostErrnoMap mappings in core/libs/prx/libc/src/HostErrno.cpp: ENODATA -> 1040, ENOSR -> 1050, ENOSTR -> 1051, EOTHER -> 1062, ETIME -> 1074 match the guest error codes defined in Errors.cpp.
    • Verified GuestErrnoFromHost_nid_no_patch linear search properly looks up the host errno and returns the mapped guest errno before the fallback bounds check error > 0 && error <= 34.
    • Verified all macros ENODATA, ENOSR, ENOSTR, EOTHER, and ETIME are cleanly wrapped with #ifdef guards for portability across Linux, Windows UCRT, and macOS.
    • Verified unit test core/libs/tests/GuestAtoi.cpp errnoCases[] adds valid regression cases exercising each newly mapped host error code against its expected guest integer value.
    • Verified compliance with AGENTS.md rules: no prohibited comments added, no unhandled inputs or title-specific workarounds, no extra files or unauthorized submodule modifications.

Looks Good To Me

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — looks good

The change maps the five guarded host errno values to the guest codes and adds matching cases to the existing errno test; both changed files were read at the pinned head.

What I ran

  • Read the prepared description, commit list, manifest, diff, and full text of both changed files through repo_read.py at head 9ecd67a22e8d56b35c56211455d8347f44c35f70.
  • No tests or build commands were run. No merged-preview check was run.

Results

Check Result Note
Changed-file review passed Both changed files read
Tests not run Test additions inspected only
Build and merged preview not run Not checked

Findings

Blocking

None.

Non-blocking

None.

Not verified

Runtime behavior and compilation on Windows UCRT, Linux, and macOS were not verified. Files listed in the manifest as reviewed: core/libs/prx/libc/src/HostErrno.cpp and core/libs/tests/GuestAtoi.cpp; both were read. No files were excluded by the manifest.

To get this to a good state

Nothing is required.

@JJenkx

JJenkx commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Windows at this head (9ecd67a22e8d): guest_atoi passes, 3/3 runs. This is the CTest of the executable that compiles the changed GuestAtoi.cpp.

Setup:

  • Windows 11 22621, Ryzen 9 5950X, MinGW-w64 GCC 15.2 UCRT r7, Release.
  • The exact PR head was built (not merged into main).
  • 3 runs through the shared FIFO.

Which new rows ran here: Each new row in the test is behind #ifdef <name>. This toolchain's <errno.h> defines four of the five (g++ -dM -E):

  • ENODATA 120
  • ENOSR 124
  • ENOSTR 125
  • ETIME 137

EOTHER is not defined, so its row is compiled out on Windows and this run does not exercise it.

AI-assisted: yes.

@Plyxen Plyxen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked head 9ecd67a22e. All on Windows 11 with WinLibs GCC 15.2 (Release), applied to main a163d4b886 together with #27930, #27929, #27926, #27925, #27923, #27922, #27901, #27828, #27771, #27755, #27748, #27682, #27765. tools/check_conventions.py --head and tools/debt_fold.py --check passed and the full build succeeded. guest_atoi passes, and the five values match the guest codes in Errors.cpp (1040, 1050, 1051, 1062, 1074). guest_resolver_system_errors also builds HostErrno.cpp, but it is registered only on Linux, so it did not run here. In the full CPU suite (5,120 tests) the only failures are unrelated:

  • windows_read_trap_unknown fails on main too (fixed in #28028).
  • frame_capture_minimize, jpeg_external_toolchain and guest_pthread_mutex_contention are timeouts under load; they pass when run on their own.
  • guest_audio_in_capture passes 20/20 on main and with #27922.

AI-assisted: yes (Claude Code)

@ligmaSec ligmaSec left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The GuestAtoi fixture passed with the exact HostErrno.cpp change linked into the Linux test. I checked the conditional host errno mappings. The run exercises the values defined by Linux glibc, and the Windows-only branch was outside this run.

AI-assisted: yes.

@oneandonlydean
oneandonlydean merged commit fcad744 into boykopovar:main Dec 5, 2026
22 of 25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants