Documentation
¶
Index ¶
Constants ¶
View Source
const ( // UnixCallingConvention is the System V AMD64 ABI used on Linux, macOS, FreeBSD. UnixCallingConvention CallingConvention = iota + 1 // WindowsCallingConvention is the Win64 (Microsoft x64) calling convention. WindowsCallingConvention // GnuWindowsCallingConvention is the GNU extension to Windows calling convention. GnuWindowsCallingConvention // Convenient aliases for common usage // DefaultCall automatically selects the platform's native calling convention. DefaultCall = CallingConvention(0) // Will be resolved by DefaultConvention() // CDecl is an alias for the C calling convention on the current platform. CDecl = UnixCallingConvention // Updated by init() on Windows // StdCall is Windows-specific (same as WindowsCallingConvention). StdCall = WindowsCallingConvention )
View Source
const ( ReturnVoid = 0 ReturnUInt8 = 1 ReturnUInt16 = 2 ReturnUInt32 = 3 ReturnSInt8 = 4 ReturnSInt16 = 5 ReturnSInt32 = 6 ReturnInt64 = 7 ReturnInXMM32 = 8 ReturnInXMM64 = 9 ReturnViaPointer = 1 << 10 // ARM64 HFA (Homogeneous Floating-point Aggregate) return flags. // HFA structs with 2-4 float/double members are returned in D0-D3. // Use with ReturnInXMM32 (float) or ReturnInXMM64 (double) to indicate element type. ReturnHFA2 = 1 << 11 // 2 elements in D0-D1 ReturnHFA3 = 1 << 12 // 3 elements in D0-D2 ReturnHFA4 = 1 << 13 // 4 elements in D0-D3 )
Return flags constants
Variables ¶
View Source
var ( VoidTypeDescriptor = &TypeDescriptor{Size: 1, Alignment: 1, Kind: VoidType} IntTypeDescriptor = &TypeDescriptor{Size: 4, Alignment: 4, Kind: IntType} FloatTypeDescriptor = &TypeDescriptor{Size: 4, Alignment: 4, Kind: FloatType} DoubleTypeDescriptor = &TypeDescriptor{Size: 8, Alignment: 8, Kind: DoubleType} UInt8TypeDescriptor = &TypeDescriptor{Size: 1, Alignment: 1, Kind: UInt8Type} SInt8TypeDescriptor = &TypeDescriptor{Size: 1, Alignment: 1, Kind: SInt8Type} UInt16TypeDescriptor = &TypeDescriptor{Size: 2, Alignment: 2, Kind: UInt16Type} SInt16TypeDescriptor = &TypeDescriptor{Size: 2, Alignment: 2, Kind: SInt16Type} UInt32TypeDescriptor = &TypeDescriptor{Size: 4, Alignment: 4, Kind: UInt32Type} SInt32TypeDescriptor = &TypeDescriptor{Size: 4, Alignment: 4, Kind: SInt32Type} UInt64TypeDescriptor = &TypeDescriptor{Size: 8, Alignment: 8, Kind: UInt64Type} SInt64TypeDescriptor = &TypeDescriptor{Size: 8, Alignment: 8, Kind: SInt64Type} PointerTypeDescriptor = &TypeDescriptor{Size: 8, Alignment: 8, Kind: PointerType} )
Predefined type descriptors
View Source
var ( ErrUnsupportedArchitecture = errors.New("unsupported architecture") ErrUnsupportedCallingConvention = errors.New("unsupported calling convention") ErrInvalidTypeDefinition = errors.New("invalid type definition") ErrUnsupportedReturnType = errors.New("unsupported return type") )
Error constants
Functions ¶
func RuntimeEnvironment ¶
func RuntimeEnvironment() (os, arch string)
RuntimeEnvironment returns current runtime OS and architecture
Types ¶
type CallInterface ¶
type CallInterface struct {
Convention CallingConvention
ArgCount int
ArgTypes []*TypeDescriptor
ReturnType *TypeDescriptor
Flags int // Return flags
StackBytes uintptr // Required stack space
}
CallInterface represents a prepared function call interface
type CallingConvention ¶
type CallingConvention int
CallingConvention represents function calling conventions used by different platforms.
func DefaultConvention ¶
func DefaultConvention() CallingConvention
DefaultConvention returns the native calling convention for the current platform.
Returns:
- UnixCallingConvention on Linux, macOS, FreeBSD
- WindowsCallingConvention on Windows
Example:
convention := types.DefaultConvention() // or just use types.DefaultCall constant
type TypeDescriptor ¶
type TypeDescriptor struct {
Size uintptr // Size in bytes
Alignment uintptr // Alignment requirement
Kind TypeKind // Type category
Members []*TypeDescriptor // For composite types
}
TypeDescriptor describes FFI type characteristics
Click to show internal directories.
Click to hide internal directories.