Let a thread resume at the instruction after a syscall - #210
Merged
Conversation
Sinan-Karakaya
force-pushed
the
fix/syscall-resume-entry
branch
from
August 18, 2026 09:25
3a4a82d to
2b20434
Compare
ran-j
requested changes
Aug 18, 2026
A syscall can hand control back to the scheduler before the instruction after it runs. SetSyscall lets the guest install its own handler for a syscall number; dispatchSyscallOverride then suspends the calling thread and queues that handler as a GuestInvocation. When the invocation finishes, EeScheduler resumes the parent thread at the address the generated code stored just before calling handleSyscall -- the instruction right after the syscall. The analyzer never marked that address as an entry point. It queues resume entries for JAL and JALR only, so no generated function could be re-entered there, EeScheduler's hasFunction() check failed, and the thread was made dormant instead of resumed. The thread simply stops; because the scheduler then drains normally and run() returns, it looks like a clean shutdown rather than a fault, which makes it awkward to recognise. This is reachable during early boot on a real title. Dragon Quest VIII hits it in crt0: the Metrowerks startup code installs a handler for syscall 0x83 and immediately issues it, and execution ends there, roughly ten functions into the binary. Note the offset is +4, not the +8 used for JAL and JALR -- syscall has no delay slot. (cherry picked from commit becb2be5bd0dc3deebeec8454df21ea7d7062b45)
Sinan-Karakaya
force-pushed
the
fix/syscall-resume-entry
branch
from
August 18, 2026 20:26
2b20434 to
851d9ac
Compare
ran-j
approved these changes
Aug 18, 2026
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.
A syscall can hand control back to the scheduler before the instruction after it runs.
SetSyscalllets the guest install its own handler for a syscall number;dispatchSyscallOverridethen suspends the calling thread and queues that handler as aGuestInvocation. When the invocation finishes,EeSchedulerresumes the parent thread at the address the generated code stored just before callinghandleSyscall— the instruction right after the syscall.The analyzer never marked that address as an entry point.
queueResumeEntryTarget()is reached forOPCODE_JALandSPECIAL_JALRonly, so no generated function could be re-entered there,EeSchedulershasFunction()check failed, and the thread was made dormant instead of resumed.The failure is quiet, which is the annoying part: the thread just stops, the scheduler drains normally, and
run()returns 0. It looks like a clean shutdown rather than a fault.This is reachable during early boot on a real title. Dragon Quest VIII (SLUS-21207) hits it in crt0 — the Metrowerks startup code installs a handler for syscall
0x83and immediately issues it, so execution ends about ten functions into the binary:0x120a40is the four-instruction syscall wrapper (addiu $v1, $zero, 0x83/syscall/jr $ra/ delay slot) and0x120a48is itsjr $ra. That binary has 175 syscall sites, none of which had a resume entry.Note the offset is +4, not +8: syscall has no delay slot.
Adds a test covering both the resume entry and the offset.