Skip to content

Synchronization waits retain their objects and completed notifications - #1284

Closed
rastapasta wants to merge 1 commit into
seedds:mainfrom
rastapasta:fix/kernel-wait-lifetimes
Closed

rastapasta wants to merge 1 commit into
seedds:mainfrom
rastapasta:fix/kernel-wait-lifetimes

Conversation

@rastapasta

Copy link
Copy Markdown
Contributor

What and why

A wait kept caller memory and recyclable handle slots instead of retaining the objects it was waiting on. Closing or reusing a handle could redirect it, and clearing an event before the waiter resumed could erase an already delivered notification.

Resolve and retain the complete wait list, record completion under the scheduler lock, and release object references when the wait ends. Preserve validation, readiness, timeout and cancellation ordering. ResetSignal now rejects thread handles with InvalidHandle and reserves InvalidState for an already-clear readable event.

Threading reference. The deterministic tests hold the scheduler lock across notification and clear/close, so they exercise the race without timing sleeps.

Checked

  • This branch on current main: all seven t_sync_wait groups pass normally, under ASan/UBSan, and under TSan. The tests cover notification completion, endpoint types, wait-list validation/snapshots, cancellation, handle reuse and thread lifetime. Documentation and usage-map tests pass; C lint has no new findings.
  • Before the original local correction, five wait groups and the endpoint check reproduced the failures. No game-specific failure or performance improvement is claimed.
  • iPhone source compile: 261 files, zero failures. Device: Apple M2, macOS 27.0.1, Xcode 27.2. No iPhone hardware run.
  • regress.py impact origin/main..HEAD completed. The five-game check selected Ocarina, Wonder, Dark Souls, Hades and Mario Kart World to cover synchronization across several engines and graphics paths. It stops at preflight with exit 2: only Ocarina has a local Mac build. Metal cache cleanup was skipped to preserve the ongoing shader build. Game regression coverage remains outstanding.
  • The full host suite passed on the earlier combined local changes; this rebased branch received the focused checks above.

Docs

  • Updated existing reference documentation and regenerated the symptom index.
  • No shader-chain change.
  • No game files, keys or extracted data included. No new Markdown files.

WaitSynchronization retains the resolved objects rather than caller memory and recyclable handle slots. Complete waits under the scheduler lock so clearing an event before the waiter resumes cannot erase its notification. Keep closed objects alive until their final wait reference is released.

Reject thread handles in ResetSignal and distinguish an already-clear readable event from an invalid handle. Add deterministic notification, cancellation, close/reuse and endpoint tests to normal and sanitizer targets.
@github-actions github-actions Bot added host The Horizon host: SVCs, services, threads, memory (dm/host) docs Documentation labels Nov 5, 2026
@rastapasta
rastapasta force-pushed the fix/kernel-wait-lifetimes branch from 785868f to ff1367d Compare November 5, 2026 06:27
seedds added a commit that referenced this pull request Nov 7, 2026
…ignal that completed it, as Horizon's KSynchronizationObject::Wait: a signal followed by a clear before the waiter resumed timed out the wait, a closed and reused handle redirected it, and a wait on a thread whose handle was closed never completed; every handle is validated up front (more than 64 is out of range, the pseudo-handle and an event's write end are invalid), a ready object and a zero-time poll precede a pending cancellation, the retained list lives in the thread's record, and ResetSignal on a thread is an invalid handle (PR #1284)

Co-authored-by: Michael Straßburger <1259904+rastapasta@users.noreply.github.com>
@seedds

seedds commented Nov 7, 2026

Copy link
Copy Markdown
Owner

Thank you. Landed on main as db206a4, with you as co-author. The change matches Horizon's KSynchronizationObject::Wait, and t_sync_wait reproduces six of its seven groups on the old host.

Changes on top of the PR:

  • The retained wait list is kept in the thread's record (thr_t.wobjs) instead of on the SVC stack, as the kernel keeps it in its per-thread sync object buffer.
  • The ResetSignal entry is merged into the WaitSynchronization entry in docs/reference/threads.md, and its count is corrected to six of seven groups.

Checked: the host unit tests, the thread-sanitizer suite (tsan-threads) and the docs tests all pass. In quick regression runs, NieR:Automata and Return of the Obra Dinn matched main on frames and fps with no new red lines on the final runs. One Obra Dinn run with the change logged a single GPU hang watchdog (1 of 5,400 command buffers). It did not repeat and is not linked to this change.

@seedds seedds closed this Nov 7, 2026
Know-It-All-Brother pushed a commit to Know-It-All-Brother/nxnative that referenced this pull request Nov 9, 2026
…ignal that completed it, as Horizon's KSynchronizationObject::Wait: a signal followed by a clear before the waiter resumed timed out the wait, a closed and reused handle redirected it, and a wait on a thread whose handle was closed never completed; every handle is validated up front (more than 64 is out of range, the pseudo-handle and an event's write end are invalid), a ready object and a zero-time poll precede a pending cancellation, the retained list lives in the thread's record, and ResetSignal on a thread is an invalid handle (PR seedds#1284)

Co-authored-by: Michael Straßburger <1259904+rastapasta@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation host The Horizon host: SVCs, services, threads, memory (dm/host)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants