feat!: errno always-capture — CallFunction returns (syscall.Errno, error) (v0.6.0)#61
Merged
Conversation
…60) Add CallFunctionErrno/CallFunctionErrnoContext to the public API. Errno is captured inside the assembly trampoline immediately after the C function returns, before the Go runtime can migrate the goroutine to another OS thread. Architecture: - Extend syscallArgs struct with errno/errnoFn fields at the end (no ABI break) - AMD64 Unix: call __errno_location/__error in assembly after saving returns, guarded by TESTQ so regular CallFunction has zero extra cost - ARM64: same pattern using CBZ guard; R19/R20 are callee-saved across the call - FunctionCallerErrno optional interface allows type assertion without changing existing FunctionCaller; unsupported arches fall back to plain Execute - errno_stubs_amd64.s / errno_stubs_arm64.s: JMP trampolines to dynamic symbols goffi_errno_location (same pattern as internal/dl stubs) - Windows: stub returns errno=0; use GetLastError/syscall.SyscallN third return value for Win32 errors instead Platforms: Linux/macOS/FreeBSD amd64+arm64 (errno capture); Windows (stub). All 8 cross-compile targets verified. Tests: TestCallFunctionErrnoBasic validates ENOENT capture; TestCallFunctionErrnoSuccess validates zero errno.
BREAKING: CallFunction/CallFunctionContext now return (syscall.Errno, error). Callers that don't need errno use: _, err := ffi.CallFunction(...) errno is captured inside the assembly trampoline immediately after the C function returns, before Go runtime can migrate to a different OS thread. Cost: ~3-5 ns per call (CALL __errno_location + MOVL). This makes goffi the first pure-Go FFI with correct errno capture on Linux. Opt-in CallFunctionErrno removed -- always-capture is the enterprise approach.
- CHANGELOG: v0.6.0 entry with breaking changes and migration guide - README: update all CallFunction examples to (_, err) pattern, add errno feature - ARCHITECTURE: document errno capture in Layer 2 section - PERFORMANCE: document +3-5ns errno overhead
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
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.
Summary
CallFunctionandCallFunctionContextnow return(syscall.Errno, error)— errno is always capturedexitsyscallcan migrate goroutine)__errno_location(Linux glibc/musl),__error(macOS/FreeBSD)Why Always-Capture (not opt-in)
Opt-in
CallFunctionErrnois a pit of failure — you don't know you need errno until the function fails, and by then the goroutine may be on a different OS thread. Pre-1.0 = do it right.Cost: ~3-5 ns per call (
CALL __errno_location+MOVL). At 200 calls/frame × 60 FPS = 0.02% of frame budget.Migration
Test plan
go build ./...— cleango test ./...— all passCloses #60