Repository navigation
aarch64: zero the fiber frame-pointer terminator in make_fcontext - #47
Merged
Merged
Conversation
Algunenano
added a commit
to Algunenano/ClickHouse
that referenced
this pull request
Jul 23, 2026
zeekay
pushed a commit
to hanzoai/datastore
that referenced
this pull request
Sep 11, 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.
Zero the saved frame-pointer slot in the arm64
make_fcontext(bothmachoandelf) so a freshly created fiber starts with a null frame-pointer terminator.Why this is needed
make_fcontextinitializes a fiber's context block but, on arm64, never writes the saved frame-pointer (x29) slot (offset0x90) — it only stores the entry PC (0xa0) and thefinishreturn address (0x98). So a fiber's bottom frame inherits whatever junk was in that memory (fiber stacks are not zeroed; e.g. ClickHouse allocates them withaligned_alloc).That is fine for a CFI-based unwinder (libunwind /
_Unwind_Backtrace), which follows.cfi/compact-unwind info and stops at the fiber entry. But a frame-pointer walker — Apple'sbacktrace()/__thread_stack_pcs,sample,lldb, the macOS crash reporter — blindly chases the x29 chain, reads that uninitialized terminator, and follows it off the fiber stack. When the junk happens to be an aligned, monotonically-increasing, unmapped address, the walk dereferences it and the process dies withSIGSEGVin__thread_stack_pcs.This is the macOS crash in ClickHouse#111579: the frame-pointer-based macOS stack capture faulted while the memory profiler sampled an allocation running on a
boost::contextfiber. Forcing the terminator to0makes any frame-pointer walker stop cleanly at the fiber entry, exactly like a real thread's bottom frame (thread_startleaves fp = 0).Verified with a standalone reproducer built against this exact asm: unpatched
make_fcontext→SIGSEGVinsidebacktrace(); patched → a clean, complete trace.Why arm64 only, not x86_64
x86_64 does not have this problem and must not get the same change:
make_fcontextalready initializes the frame-pointer (rbp) slot — it stores&finishthere (offset0x30onmacho,0x38onelf). The terminator is therefore a defined, mapped code address, not junk; a frame-pointer walker reads it without faulting and stops at the alignment check.trampolinedoespush %rbp; jmp *%rbx, i.e. rbp (=&finish) is used as the fiber function's return address. Zeroing it would push0and crash on every fiber return.Only arm64 leaves the frame-pointer slot uninitialized, so the fix is scoped to the two arm64 backends. The
elfchange is a harmless no-op behaviorally on Linux (which unwinds via CFI) and just keeps the two arm64 backends in sync.Upstream
Not fixed upstream: current
boostorg/contextmaster/developleave the arm64 fp slot uninitialized as well (they assume CFI-based unwinding). Worth proposing upstream.