fix: semaphore syscalls return sid on success instead of KE_OK#136
Open
smmathews wants to merge 3 commits into
Open
fix: semaphore syscalls return sid on success instead of KE_OK#136smmathews wants to merge 3 commits into
smmathews wants to merge 3 commits into
Conversation
The PS2 EE BIOS returns the semaphore ID on success for all semaphore syscalls, not zero. PollSema, WaitSema, SignalSema, and DeleteSema were all returning KE_OK (0) on success, which breaks games that compare the return value against the semaphore ID. DQ8's init code polls a mutex semaphore at 0x12A670 and checks the result against the semaphore ID using bne. With KE_OK returned, the comparison always fails and the game spins forever at PC 0x164978 and never starts. Other games that follow the same EE BIOS convention would hit the same problem. CreateSema already returned the ID correctly; this brings the other four operations in line with the same convention. The fix is five changes in Sync.cpp: the four return sites are updated to return sid, and the count-decrement guard in WaitSema is changed from ret == 0 to ret >= 0. The guard change is necessary because ret is now seeded to sid (a positive value) on the success path, and the old equality check would have silently stopped decrementing the semaphore count. Error paths (KE_WAIT_DELETE, KE_RELEASE_WAIT) are negative and still correctly bypass the decrement. Tests are updated to expect sid instead of KE_OK on success paths, and new test cases cover the blocked-wait-then-signal path (the actual DQ8 scenario), force-release via ReleaseWaitThread, and the count-decrement guard directly.
Owner
|
Hey, I will review this one later. Also why you close your other PR ? |
Author
|
I'm going to take a different approach on the other PR, I think it was a little too conservative.
Also, I'm working on the PR test fix. I appreciate the review, thanks.
…On Fri, Jun 19, 2026, 9:15 PM Ranieri ***@***.***> wrote:
*ran-j* left a comment (ran-j/PS2Recomp#136)
<#136 (comment)>
Hey, I will review this one later.
Also why you close your other PR ?
—
Reply to this email directly, view it on GitHub
<#136?email_source=notifications&email_token=AADMNGEKNBAVV53KNJPB57L5AXQTNA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTINZVGU4DEOBTGYY2M4TFMFZW63VGMF2XI2DPOKSWK5TFNZ2KYZTPN52GK4S7MNWGSY3L#issuecomment-4755828361>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AADMNGHN3EVZABDTDZTCEW35AXQTNAVCNFSNUABFKJSXA33TNF2G64TZHM4TMNBZHA2TGNRSHNEXG43VMU5TINZQGM4TAMZYHE22C5QC>
.
Triage notifications, keep track of coding agent tasks and review pull
requests on the go with GitHub Mobile for iOS
<https://github.com/notifications/mobile/ios/AADMNGDB2QDWBJGRCFWKKPL5AXQTNA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTINZVGU4DEOBTGYY2M4TFMFZW63VGMF2XI2DPOKSWK5TFNZ2KUZTPN52GK4S7NFXXG>
and Android
<https://github.com/notifications/mobile/android/AADMNGFUZXK6QSFYRY2UHUL5AXQTNA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTINZVGU4DEOBTGYY2M4TFMFZW63VGMF2XI2DPOKSWK5TFNZ2K4ZTPN52GK4S7MFXGI4TPNFSA>.
Download it today!
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Two test files were not updated alongside the semaphore return-value change. PollSema and SignalSema now return sid on success; update the four assertions that expected KE_OK on those success paths.
Owner
|
Nice I see https://github.com/ps2dev/ps2sdk/blob/master/ee/kernel/include/kernel.h#L423 declare |
ran-j
requested changes
Jun 20, 2026
| } | ||
|
|
||
| if (ret == 0 && sema->count > 0) | ||
| if (ret >= 0 && sema->count > 0) |
Owner
There was a problem hiding this comment.
I think is better to check ret == sid
ret is seeded to sid on success and only ever overwritten with negative error codes, so ret == sid precisely expresses "this wait acquired this semaphore" — more explicit than the looser ret >= 0. Suggested by ran-j in PR review.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What's wrong
On the real PS2 EE BIOS, the semaphore syscalls return the semaphore ID on success, not zero. Our implementations of `PollSema`, `WaitSema`, `SignalSema`, and `DeleteSema` were all returning `KE_OK` (0) on success instead.
Why it matters
DQ8 is what surfaced this. Its init code at `0x12A670` polls a mutex semaphore and compares the result against the semaphore ID (`bne $v1, $v0`). When `PollSema` returns `KE_OK` instead of the ID, that comparison never matches, so the game spins forever at `PC 0x164978` and never finishes initializing. With the correct return value it proceeds normally.
This isn't DQ8-specific. The standard EE SDK semaphore pattern relies on the success return being the sema ID, so any game built against it can hit the same problem. `CreateSema` already returned the ID on success; the other four operations were just inconsistent with it.
What changed
Five edits in `ps2xRuntime/src/lib/Kernel/Syscalls/Sync.cpp`:
`ReferSemaStatus` is intentionally left returning `KE_OK` — it's a query, not an acquire/release operation, and the convention only applies to the state-changing ops.
References
Public docs are thorough for `CreateSema` but sparse on the success return values of the other four. The behavior is inferred from game code plus two sources that are consistent with it:
Tests
Existing semaphore tests updated to expect `sid` on success paths. New cases added: