Repository navigation
Add fcontext support for arm64e (AAPCS/Mach-O) - #345
Open
oskarwirga wants to merge 1 commit into
Open
oskarwirga wants to merge 1 commit into
oskarwirga wants to merge 1 commit into
Conversation
On arm64e, C function pointers are signed with pointer authentication. make_fcontext stored the context function's pointer unchanged, and jump_fcontext branched to it with a plain ret, so the first switch into a new context branched to the still-signed address and crashed. ontop_fcontext had the same problem with the ontop function. On arm64e, make_fcontext now authenticates the pointer and re-signs it with the address of the slot it is stored in, trapping if authentication fails, as clang does. jump_fcontext and ontop_fcontext sign the PC they save the same way, so jump_fcontext can resume any context with braa, and ontop_fcontext branches to the ontop function with braaz. Nothing changes for arm64. Assisted-by: Claude
oskarwirga
marked this pull request as ready for review
November 11, 2026 00: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.
On arm64e, C function pointers are signed with pointer authentication.
make_fcontextstored the context function's pointer unchanged, andjump_fcontextbranched to it with a plainret, so the first switch into a new context branched to the still-signed address and crashed.ontop_fcontexthad the same problem with the ontop function.On arm64e,
make_fcontextnow authenticates the pointer and re-signs it with the address of the slot it's stored in, trapping if authentication fails, as clang does.jump_fcontextandontop_fcontextsign the PC they save the same way, sojump_fcontextcan resume any context withbraa, andontop_fcontextbranches to the ontop function withbraaz.This change is gated and only affects arm64e.The existing tests cover this once they're built for arm64e:
test_fcontext,test_fiber,test_callccandtest_fp_terminatorall crash on develop and pass with this change (M4 Mac, Xcode 27.1). We found the crash in an arm64e build of a large iOS app.Note: This PR was AI Assisted w/ Claude