Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Kernel] Fix NORMAL mutex self-relock inconsistency between fast and slow lock paths - #884

Open
theantipopau wants to merge 1 commit into
sharpemu:mainfrom
theantipopau:fix/pthread-normal-mutex-selflock-consistency
Open

theantipopau wants to merge 1 commit into
sharpemu:mainfrom
theantipopau:fix/pthread-normal-mutex-selflock-consistency

Conversation

@theantipopau

Copy link
Copy Markdown

What this does

Fixes a narrow but real inconsistency in PthreadMutexLockCore (KernelPthreadCompatExports.cs). There are two places that handle the same case — a thread calling scePthreadMutexLock on a MutexTypeNormal mutex it already owns — and they disagreed.

Background

  • #451 added an uncontended fast-path check (before acquiring state.SyncRoot) that treats self-relock on a NORMAL mutex as compatibility recursion: increment the recursion count, return OK.
  • #748 later found that behavior was starving other threads on some title, and deliberately reverted the other copy of this same check — the one inside the SyncRoot-protected slow path — back to a real EDEADLK. Good, evidence-based fix, explained clearly in that PR's commit message.
  • But #748's revert didn't touch the fast-path copy from #451, since it's a separate if block earlier in the same function. So since #748, the actual outcome of a NORMAL self-relock has depended on which of the two checks a given call happens to reach — OK via the fast path, EDEADLOCK via the slow path — rather than on anything about guest behavior.

This PR makes the fast path match the slow path's current (intentional, evidence-based) behavior: real EDEADLK, no silent recursion.

Testing

AI assistance disclosure

I used Claude Code (Anthropic) to help investigate KernelPthreadCompatExports.cs, trace the git history of both self-relock checks (via git log -p -L) to understand why they diverged, write the fix and the new test, and draft this PR description. I reviewed the code change, the git history it's based on, and the test/real-game verification myself and can explain and defend it in review.

Checklist

  • I have read and followed CONTRIBUTING.md.
  • I tested my changes or marked the testing section as N/A.
  • I wrote this pull request description myself and did not paste AI-generated explanations. (see AI assistance disclosure above — I did not write this text myself)
  • I listed the game(s) I tested (or marked the testing section as N/A).

🤖 Generated with Claude Code

…slow lock paths

sharpemu#748 deliberately reverted NORMAL pthread mutex self-relock from silent
compatibility recursion back to a real EDEADLK, because the permissive
behavior was starving other threads on some titles. That revert only
updated the SyncRoot-protected check in PthreadMutexLockCore; an earlier
uncontended-fast-path copy of the same self-owned/MutexTypeNormal case
(added by sharpemu#451, before sharpemu#748 existed) still returns OK and increments
the recursion count.

Since sharpemu#748, whether a self-relock on a NORMAL mutex returns OK or
EDEADLK depended entirely on which of the two duplicate checks handled
the call, rather than on guest behavior. Aligns the fast path with the
SyncRoot-protected one so the outcome is consistent regardless of which
check is reached.

Tested against real dumps (Stray PPSA02101, Paw Patrol: Grand Prix
PPSA05521) that hit this exact self-relock case in a
scePthreadMutexLock retry loop. This fix does not change their observed
behavior — both were already reaching the SyncRoot-protected check,
which already returned EDEADLK before this change — confirming the
inconsistency was real but narrower than initially suspected. Filing
as a standalone correctness fix; the actual cause of those two titles'
hangs is still open (see sharpemu#519, sharpemu#875).

Co-Authored-By: Claude Sonnet 5 <[email protected]>
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.

1 participant