Skip to content

Add fcontext support for arm64e (AAPCS/Mach-O) - #345

Open
oskarwirga wants to merge 1 commit into
boostorg:developfrom
oskarwirga:arm64e-ptrauth
Open

oskarwirga wants to merge 1 commit into
boostorg:developfrom
oskarwirga:arm64e-ptrauth

Conversation

@oskarwirga

@oskarwirga oskarwirga commented Nov 10, 2026 •

Copy link
Copy Markdown

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's 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.This change is gated and only affects arm64e.

The existing tests cover this once they're built for arm64e: test_fcontext, test_fiber, test_callcc and test_fp_terminator all 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

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
oskarwirga marked this pull request as ready for review November 11, 2026 00:28
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