-
Notifications
You must be signed in to change notification settings - Fork 4
Callback dispatcher bypasses crosscall2 — crashes on C-created threads #16
Copy link
Copy link
Closed
Labels
arch: amd64x86-64 specific (System V / Win64 ABI)x86-64 specific (System V / Win64 ABI)arch: arm64ARM64 specific (AAPCS64 ABI)ARM64 specific (AAPCS64 ABI)area: callbacksC-to-Go callback trampolinesC-to-Go callback trampolinesarea: fakecgoFake CGO runtime integrationFake CGO runtime integrationeffort: 5Large, 2-3 daysLarge, 2-3 dayspriority: mediumNormal priorityNormal prioritystatus: confirmedVerified, ready for workVerified, ready for worktype: bugSomething isn't workingSomething isn't workingtype: enhancementImprove existing featureImprove existing feature
Milestone
Metadata
Metadata
Assignees
Labels
arch: amd64x86-64 specific (System V / Win64 ABI)x86-64 specific (System V / Win64 ABI)arch: arm64ARM64 specific (AAPCS64 ABI)ARM64 specific (AAPCS64 ABI)area: callbacksC-to-Go callback trampolinesC-to-Go callback trampolinesarea: fakecgoFake CGO runtime integrationFake CGO runtime integrationeffort: 5Large, 2-3 daysLarge, 2-3 dayspriority: mediumNormal priorityNormal prioritystatus: confirmedVerified, ready for workVerified, ready for worktype: bugSomething isn't workingSomething isn't workingtype: enhancementImprove existing featureImprove existing feature
Type
Fields
Give feedbackNo fields configured for issues without a type.
Summary
The callback dispatcher (both AMD64 and ARM64) calls
callbackWrapdirectly viaCALL/BL, bypassing thecrosscall2 → runtime·load_g → runtime·cgocallbackchain that purego and Go runtime use for proper C-to-Go transitions.This works correctly when callbacks arrive on Go-managed threads (the primary WebGPU use case), but will crash if a C library invokes the callback from its own internally-created thread (G = nil).
Current behavior
Expected behavior
Callbacks should work regardless of which thread invokes them, matching purego's behavior.
Potential impact without crosscall2
Solution
Replace direct
BL ·callbackWrap/CALL ·callbackWrapwithBL crosscall2/CALL crosscall2in both dispatchers, following the purego pattern:Files to change
ffi/callback_amd64.s— AMD64 dispatcherffi/callback_arm64.s— ARM64 dispatcherffi/callback.go— addcallbackWrap_callclosure (AMD64)ffi/callback_arm64.go— addcallbackWrap_callclosure (ARM64)Context
Discovered during ARM64 trampoline fix (BL→MOVD+B, see #15). The direct call approach was inherited from the initial implementation and is documented in
TASK-012-crosscall2-integration.md.