Skip to content

Conversation

@kolkov
Copy link
Contributor

@kolkov kolkov commented Dec 27, 2025

Summary

  • Fixes critical panic when calling C functions with >4 arguments on Windows
  • Functions like vkCreateGraphicsPipelines (6 args) now work correctly
  • Simplified Windows FFI by removing intermediate wrapper

Problem

After v0.3.4 fix for stack overflow, functions with >4 arguments caused:

panic: stack arguments not implemented

Win64 ABI passes:

  • First 4 args: RCX, RDX, R8, R9 (registers)
  • Args 5+: on stack

The previous implementation only handled 4 register args.

Solution

Use syscall.SyscallN(fn, args...) with variadic arguments:

  • Supports unlimited arguments (tested up to 15+)
  • Handles both register and stack arguments automatically
  • Same approach used by purego

Changes

  • internal/arch/amd64/call_windows.go - Use SyscallN directly with args...
  • internal/syscall/syscall_windows_amd64.go - Removed (no longer needed)
  • CHANGELOG.md - Added v0.3.5 entry

Test Plan

  • All tests pass (89.6% coverage)
  • Pre-release script passes
  • FFI overhead: ~64 ns/op (improved)
  • Manual Vulkan testing with >4 arg functions

Affected Vulkan Functions

  • vkCreateGraphicsPipelines (6 args)
  • vkCmdBindVertexBuffers (5 args)
  • vkCmdCopyBuffer (5 args)
  • Many others with >4 parameters

- Functions with >4 args caused panic: stack arguments not implemented
- Win64 ABI: first 4 args in registers (RCX/RDX/R8/R9), args 5+ on stack
- Solution: Use syscall.SyscallN with variadic args directly
- Removed intermediate syscall_windows_amd64.go wrapper
- Affected functions: vkCreateGraphicsPipelines, vkCmdBindVertexBuffers, etc.
@kolkov kolkov merged commit 934decc into main Dec 27, 2025
8 checks passed
@kolkov kolkov deleted the fix/windows-stack-args branch December 27, 2025 11:25
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