fix: preserve nonvolatile registers across native LoadSeg handoff - #603
Open
benletchford wants to merge 1 commit into
Open
fix: preserve nonvolatile registers across native LoadSeg handoff#603benletchford wants to merge 1 commit into
benletchford wants to merge 1 commit into
Conversation
benletchford
marked this pull request as ready for review
August 14, 2026 02:28
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.
Summary
_LoadSeghands execution back to the original patched jump-table entryRoot cause
The native
_LoadSegpath deliberately abandons the patch handler's stack frame when it restores the original caller stack, as fixed by #358. That also bypasses the handler's cleanup code. Systemless did not restore the nonvolatile registers that cleanup would have restored, so an internal handler A6 could reach the original caller and make a laterUNLKconsume an invalid return address.Inside Macintosh: Operating System Utilities (1994), chapter 8, permits Toolbox routines to alter D0-D2, A0, and A1, which makes D3-D7 and A2-A6 the preserved set modeled here.
Validation
cargo fmt --all -- --checkcargo test --lib(2949 passed, 3 ignored)Invalid PC $98FE03FFcheckpoint and reaches an application-controlledExitToShellCloses #602.