Skip to content

fix(libkernel): keep errno across timed condition waits on macOS - #2138

Open
Thimo188 wants to merge 1 commit into
mainfrom
upstream-pr/28369
Open

Thimo188 wants to merge 1 commit into
mainfrom
upstream-pr/28369

Conversation

@Thimo188

@Thimo188 Thimo188 commented Dec 3, 2026 •

Copy link
Copy Markdown
Owner

Imported from boykopovar/AnyPS5#28369, originally opened by Jazeupoi.

Source commit: e44c9a2e173ffb2b8c41b7de985549203dc944d9. The import branch preserves this fetched upstream PR snapshot. The description and validation below are copied from upstream; no new code changes or test runs were made for this import. Original reviews, discussions, and attachments remain at the linked upstream PR.


What

On macOS guest_event_flag_wake aborts on every run. Its read-only timeout case (added in boykopovar#22055) expects sceKernelWaitEventFlag to return SCE_KERNEL_ERROR_EFAULT with errno unchanged, and the call returns EFAULT with errno at 316. TimedWait::Condition waits through std::condition_variable_any; when that wait times out on macOS, libpthread leaves the raw __psynch_cvwait status in errno: 316 is ETIMEDOUT (60) with ECVCLEARED (0x100). glibc's condition wait does not touch errno, which is why the test passes on Linux.

Condition::Wait and Condition::WaitUntil now save errno before the wait and restore it afterwards, so a guest call that waits keeps the errno it was called with on every host.

Tested

macOS 27.0.1, Apple M4, x86_64 Release under Rosetta 2, Apple clang 21.0.0. The tree was main 1b8f79a5b5 plus boykopovar#26739, boykopovar#27739 and boykopovar#17425, which macOS needs to build; none of them touches this code, and TimedWait.hpp, EventFlag.cpp and the test are unchanged up to b3c7769bc5.

  • guest_event_flag_wake: 50/50. Without the change: 0/3, aborting on the read-only timeout check (rc=0x8002000e errno=316 pattern=0x5 timeout=1000).
  • The 408 tests whose working directory is libkernel: no new failures compared with main. The 8 that still fail on this Mac also fail without the change, and each already has an open PR or issue.
  • The 111 wait-related libkernel tests (semaphores, condition variables, mutexes, event flags, sleeps): 5 rounds each, all pass.
  • Linux and Windows: not run yet; I will add them here.

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 (Claude Code)

Summary by CodeRabbit

  • Bug Fixes
    • Condition waits using coarse timing now preserve the thread’s error status before and after waiting.
    • Timed waits continue to indicate whether they ended due to a timeout, keeping timeout results clear and consistent for applications that rely on them. This update applies to both regular and deadline-based waits and does not change their public declarations or the way callers start a wait.

@coderabbitai

coderabbitai Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Changes: Coarse wait errno preservation

Layer / File(s) Summary
Save and restore errno around waits
core/libs/prx/libkernel/Time/include/TimedWait.hpp
The coarse Condition::Wait and Condition::WaitUntil paths save and restore errno. The header now includes <cerrno>, and WaitUntil retains its existing signaled-result calculation.

Change: Bug fix

Merge Risk: Minimal · up to e44c9

The change preserves the guest thread's errno across condition waits, which fixes a reported macOS abort in the event-flag wake path. No concrete merge-blocking risk was identified.

Security architecture risk: Minimal · up to e44c9

libkernel now preserves the calling thread’s errno across coarse condition waits that return normally. Timeout reporting is unchanged, and the change does not expand guest access or require operator action.

Security review details

Security Blast Radius

  • inferred — The changed effect is confined to what callers observe in their own thread’s errno after an existing coarse wait. The implementation adds no route to the wait and does not change which callers can use it.
Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Usage-based review receipt

  • Mode: Continue automatically
  • Reviewed files: 1
  • Waived: $0.25 (charged $0.00)
  • View usage details

Note

This review exceeded your plan’s limits and used usage-based reviews—free during trial, billed after paid activation unless disabled. Manage usage-based reviews.

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: c54c8f2d-65b5-49e3-8e4c-f6e8095fb4a3
Commits

Reviewing files that changed from the base of the PR and between 4131f51 and e44c9a2.

Files selected for processing: 1

  • core/libs/prx/libkernel/Time/include/TimedWait.hpp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants