Skip to content

feat: crosscall2 integration for C-thread callback support#18

Merged
kolkov merged 3 commits into
mainfrom
feat/v0.4.0-crosscall2-integration
Feb 27, 2026
Merged

feat: crosscall2 integration for C-thread callback support#18
kolkov merged 3 commits into
mainfrom
feat/v0.4.0-crosscall2-integration

Conversation

@kolkov

@kolkov kolkov commented Feb 27, 2026

Copy link
Copy Markdown
Contributor

Summary

Changes

Commit 1: fakecgo register fixes

  • ARM64: R26→R9, R2→R9 (callee-saved/argument→volatile), added SAVE/RESTORE macros
  • AMD64: DX→R11, CX→R11, BX→R11 (argument/callee-saved→volatile), JMP tail calls

Commit 2: crosscall2 integration

  • callbackWrap_call closure for ABIInternal fn ptr from assembly
  • ARM64 dispatcher rewrite: FSTPD paired saves, go_asm.h struct offsets, BL crosscall2
  • AMD64 dispatcher rewrite: PUSH_REGS_HOST_TO_ABI0, 24-byte cgocallback gap, CALL crosscall2
  • ABI header files (abi_arm64.h, abi_amd64.h) copied to ffi/ for assembly includes
  • README: advantages table vs purego, crosscall2 callbacks, v0.4.0 roadmap
  • CHANGELOG, ROADMAP updated for v0.4.0

Verification

  • go build ./... — all 5 platforms compile (Windows/Linux/macOS × AMD64/ARM64)
  • go test -v -cover ./ffi ./types — all tests pass, 89.6% coverage
  • golangci-lint run — 0 issues
  • Cross-compile verified: linux/amd64, linux/arm64, darwin/amd64, darwin/arm64

Test plan

  • CI passes on all 3 platforms (Linux, Windows, macOS)
  • Verify callbacks work on Go-managed threads (existing tests)
  • Test on Apple Silicon M3 Pro with wgpu-native C-thread callbacks
  • Verify no regression in FFI call performance benchmarks

ARM64: R26→R9 (callee-saved→volatile), R2→R9 (argument→volatile),
add SAVE/RESTORE macros for threadentry callee-saved registers.

AMD64: DX→R11 (argument→volatile), CX→R11, BX→R11 (callee-saved→volatile),
JMP tail calls for notify/bindm, PUSH_REGS_HOST_TO_ABI0 for threadentry.
Dispatchers route through crosscall2 → runtime·load_g → runtime·cgocallback.
Supports callbacks from C-library-created threads (Metal, wgpu-native).

- Add callbackWrap_call closure for ABIInternal fn ptr from assembly
- Rewrite ARM64 dispatcher: FSTPD paired saves, go_asm.h offsets
- Rewrite AMD64 dispatcher: PUSH_REGS_HOST_TO_ABI0, 24-byte gap
- Copy abi_arm64.h / abi_amd64.h to ffi/ for assembly includes
- Update README: advantages table, crosscall2 callbacks, v0.4.0 roadmap
- Update CHANGELOG, ROADMAP for v0.4.0 release
@kolkov kolkov merged commit 6fe9a0b into main Feb 27, 2026
8 checks passed
@kolkov kolkov deleted the feat/v0.4.0-crosscall2-integration branch February 27, 2026 09:34
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.

Callback dispatcher bypasses crosscall2 — crashes on C-created threads

1 participant