Skip to content

druntime: stop hiding lr/d8-d15 from GC in AArch64 fiber switch - #15

Merged
ljmf00-wekaio merged 2 commits into
weka-1.38from
luis.ferreira/weka-1.38-fix-aarch64-fiber-switch-gc
Aug 11, 2026
Merged

druntime: stop hiding lr/d8-d15 from GC in AArch64 fiber switch#15
ljmf00-wekaio merged 2 commits into
weka-1.38from
luis.ferreira/weka-1.38-fix-aarch64-fiber-switch-gc

Conversation

@ljmf00-wekaio

Copy link
Copy Markdown
Collaborator

No description provided.

ljmf00-wekaio and others added 2 commits August 11, 2026 14:50
fiber_switchContext saves x19-x28, fp, lr and d8-d15 on the fiber's
stack, but reported sp + 9*8 as the stack top (tstack), deliberately
hiding the saved lr and d8-d15 from the GC scan.

On AArch64, d8-d15 are callee-saved, so the compiler is free to keep a
live GC pointer in one of them across a suspension point (e.g. a cheap
fmov d8, x0 spill).  If that saved register holds the only reference to
a heap object, a collection while the fiber is suspended frees memory
that is still reachable, corrupting the program when the fiber resumes
(WEKAPP-581124: weka stats SwitchError on ARM clients).

Report the true sp instead, so the whole save area is scanned, and
adjust initStack to the new convention: reserve the lr/d8-d15 words
below tstack and zero them (they are now GC-scanned, so stale data on
fiber reuse must not be misread as pointers).

Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: Luís Ferreira <luis.ferreira@weka.io>
Parks the sole reference to a canary object in d8 (all other copies
XOR-obfuscated, stack spills and scratch registers scrubbed), yields,
forces collections plus heap churn from the main context, then resumes
and asserts the canary survived.

Fails against the old fiber_switchContext convention (canary collected
because the saved d8 was hidden from the GC scan) and passes with the
true-sp convention.  No-op on non-AArch64 or non-LDC builds.

Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: Luís Ferreira <luis.ferreira@weka.io>
@ljmf00-wekaio
ljmf00-wekaio merged commit b367767 into weka-1.38 Aug 11, 2026
7 of 8 checks passed
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.

2 participants