blob: 9d7e97106cc1889db9d0ef1cde2f7ce0e90b271e [file] [log] [blame]
package abigen
import "fmt"
// SysType represents the type of an argument or vDSO-exported syscall function
// return value.
type SysType struct {
Name SysTypeName // Name represents the name of the type.
Array bool // Array is true when the type represents an array.
ArraySize string // When Array is true, ArraySize represents the size of the array.
}
// SysTypeName represents the name of a SysType.
type SysTypeName int
const (
zxVoid SysTypeName = iota
zxAny
zxBool
zxUint
zxInt
zxChar
zxUint8
zxInt16
zxUint16
zxInt32
zxUint32
zxInt64
zxUint64
zxUintptr
zxSize
zxStatus
zxClock
zxTime
zxDuration
zxKOID
zxHandle
zxSignals
zxSignalsState
zxSMCParameters
zxSMCResult
zxWaitItem
zxRights
zxVAddr
zxPAddr
zxProcessInfo
zxExceptionStatus
zxExceptionBehaviour
zxFunctionPtr
zxRRec
zxChannelCallArgs
zxFIFOState
zxVMOption
)
var sysTypeNames = map[string]SysTypeName{
"any": zxAny,
"void": zxVoid,
"bool": zxBool,
"unsigned int": zxUint,
"int": zxInt,
"char": zxChar,
"uint8_t": zxUint8,
"int16_t": zxInt16,
"int32_t": zxInt32,
"int64_t": zxInt64,
"uint16_t": zxUint16,
"uint32_t": zxUint32,
"uint64_t": zxUint64,
"uintptr_t": zxUintptr,
"size_t": zxSize,
"zx_status_t": zxStatus, // int32_t
"zx_clock_t": zxUint32,
"zx_time_t": zxTime, // uint64_t monotonic time
"zx_duration_t": zxDuration, // uint64_t nanoseconds
"zx_koid_t": zxKOID,
"zx_handle_t": zxHandle, // int32_t
"zx_futex_t": zxInt,
"zx_signals_t": zxSignals,
"zx_signals_state_t": zxSignalsState,
"zx_wait_item_t": zxWaitItem,
"zx_rights_t": zxRights,
"zx_vaddr_t": zxVAddr,
"zx_paddr_t": zxPAddr,
"zx_smc_parameters_t": zxSMCParameters,
"zx_smc_result_t": zxSMCResult,
"zx_process_info_t": zxProcessInfo,
"zx_exception_status_t": zxExceptionStatus,
"zx_exception_behaviour_t": zxExceptionBehaviour,
"zx_function_pointer": zxFunctionPtr,
"zx_rrec_t": zxRRec,
"zx_channel_call_args_t": zxChannelCallArgs,
"zx_fifo_state_t": zxFIFOState,
"zx_vm_option_t": zxVMOption,
// TODO(dhobsd): Remove the following temporary types. They could be blacklisted, but this is easier.
"zx_cache_policy_t": zxInt,
"zx_port_packet_t": zxInt,
"zx_pci_init_arg_t": zxInt,
"zx_pci_irq_mode_t": zxInt,
"zx_pci_resource_t": zxInt,
"zx_pcie_device_info_t": zxInt,
"zx_pcie_get_nth_info_t": zxInt,
"zx_vcpu_create_args_t": zxInt,
"zx_system_powerctl_arg_t": zxInt,
"zx_handle_info_t": zxInt,
"zx_profile_info_t": zxInt,
"zx_pci_bar_t": zxInt,
}
// Size returns the size (in bytes) of the type. Its argument represents the size of the register
// on the machine for which the type is generated.
func (t SysType) Size() int {
if t.Array {
return 8
}
switch t.Name {
case zxFunctionPtr:
return 8
case zxVoid:
return 0
case zxAny:
return 0
case zxBool:
return 1
case zxInt, zxUint, zxUintptr, zxSize:
return 8
case zxChar, zxUint8:
return 1
case zxInt16, zxUint16:
return 2
case zxInt32, zxUint32:
return 4
case zxInt64, zxUint64:
return 8
case zxStatus:
return 4
case zxClock:
return 4
case zxTime:
return 8
case zxDuration:
return 8
case zxKOID:
return 8
case zxHandle:
return 4
case zxSignals:
return 4
case zxRights:
return 4
case zxVMOption:
return 4
case zxVAddr, zxPAddr:
return 8
case zxProcessInfo:
panic("cannot pass zxprocess_info")
case zxExceptionStatus, zxExceptionBehaviour:
return 4
default:
panic(fmt.Sprintf("UNKNOWN(%s)", t.Name))
}
}
func (t SysType) goType() string {
switch t.Name {
case zxVoid:
return "BAD(void)"
case zxAny:
return "BAD(any)"
case zxBool:
return "bool"
case zxUint:
return "uint"
case zxInt:
return "int"
case zxChar, zxUint8:
return "uint8"
case zxInt16:
return "int16"
case zxUint16:
return "uint16"
case zxInt32:
return "int32"
case zxUint32:
return "uint32"
case zxInt64:
return "int64"
case zxUint64:
return "uint64"
case zxUintptr:
return "uintptr"
case zxStatus:
return "Status"
case zxClock:
return "Clock"
case zxTime:
return "Time"
case zxDuration:
return "Duration"
case zxKOID:
return "Koid"
case zxHandle:
return "Handle"
case zxSignals:
return "Signals"
case zxWaitItem:
return "WaitItem"
case zxRights:
return "Rights"
case zxVAddr:
return "Vaddr"
case zxPAddr:
return "Paddr"
case zxSize:
return "uint"
case zxProcessInfo:
return "ProcessInfo"
case zxExceptionStatus:
return "ExceptionStatus"
case zxExceptionBehaviour:
return "ExceptionBehaviour"
case zxRRec:
return "Rrec"
case zxChannelCallArgs:
return "ChannelCallArgs"
case zxFIFOState:
return "FIFOState"
case zxSMCParameters:
return "SMCParameters"
case zxSMCResult:
return "SMCResult"
case zxVMOption:
return "VMFlag"
default:
panic(fmt.Sprintf("UNKNOWN(%s)", t.Name))
}
}
// GoType returns the Go type name for the corresponding SysType.
func (t SysType) GoType() string {
if t.Array {
if t.Name == zxAny {
return "unsafe.Pointer"
}
return fmt.Sprintf("*%s", t.goType())
}
return t.goType()
}
// NativeType returns a size-compatible Go native type for the SysType.
func (t SysType) NativeType() string {
if t.Array {
return "unsafe.Pointer"
}
switch t.Name {
case zxVoid:
return "BAD(void)"
case zxAny:
return "uintptr"
case zxBool:
return "bool"
case zxUint:
return "uint"
case zxInt:
return "int"
case zxChar, zxUint8:
return "uint8"
case zxInt16:
return "int16"
case zxUint16:
return "uint16"
case zxInt32:
return "int32"
case zxUint32:
return "uint32"
case zxInt64:
return "int64"
case zxUint64:
return "uint64"
case zxUintptr:
return "uintptr"
case zxStatus:
return "int32"
case zxClock:
return "uint32"
case zxTime:
return "int64"
case zxDuration:
return "int64"
case zxKOID:
return "uint64"
case zxHandle:
return "uint32"
case zxSignals:
return "uint32"
case zxWaitItem:
return "uintptr"
case zxRights:
return "uint32"
case zxVAddr:
return "uintptr"
case zxPAddr:
return "uintptr"
case zxSize:
return "uint"
case zxProcessInfo:
return "uintptr"
case zxExceptionStatus:
return "uintptr"
case zxExceptionBehaviour:
return "uintptr"
case zxRRec:
return "uintptr"
case zxChannelCallArgs:
return "uintptr"
case zxFIFOState:
return "uintptr"
case zxSMCParameters:
return "uintptr"
case zxSMCResult:
return "uintptr"
case zxVMOption:
return "uint32"
default:
panic(fmt.Sprintf("UNKNOWN(%s)", t.Name))
}
}