diff --git a/enumerator/enumerator.go b/enumerator/enumerator.go index 41f88fe..552330e 100644 --- a/enumerator/enumerator.go +++ b/enumerator/enumerator.go @@ -6,7 +6,7 @@ package enumerator -//go:generate go run $GOROOT/src/syscall/mksyscall_windows.go -output syscall_windows.go usb_windows.go +//go:generate go run golang.org/x/sys/windows/mkwinsyscall -output syscall_windows.go usb_windows.go // PortDetails contains detailed information about USB serial port. // Use GetDetailedPortsList function to retrieve it. diff --git a/enumerator/syscall_windows.go b/enumerator/syscall_windows.go index d969274..1dbcd9c 100644 --- a/enumerator/syscall_windows.go +++ b/enumerator/syscall_windows.go @@ -1,4 +1,4 @@ -// MACHINE GENERATED BY 'go generate' COMMAND; DO NOT EDIT +// Code generated by 'go generate'; DO NOT EDIT. package enumerator @@ -11,6 +11,31 @@ import ( var _ unsafe.Pointer +// Do the interface allocations only once for common +// Errno values. +const ( + errnoERROR_IO_PENDING = 997 +) + +var ( + errERROR_IO_PENDING error = syscall.Errno(errnoERROR_IO_PENDING) +) + +// errnoErr returns common boxed Errno values, to prevent +// allocations at runtime. +func errnoErr(e syscall.Errno) error { + switch e { + case 0: + return nil + case errnoERROR_IO_PENDING: + return errERROR_IO_PENDING + } + // TODO: add more here, after collecting data on the common + // error values see on Windows. (perhaps when running + // all.bat?) + return e +} + var ( modsetupapi = windows.NewLazySystemDLL("setupapi.dll") @@ -36,7 +61,7 @@ func _setupDiClassGuidsFromNameInternal(class *uint16, guid *guid, guidSize uint r1, _, e1 := syscall.Syscall6(procSetupDiClassGuidsFromNameW.Addr(), 4, uintptr(unsafe.Pointer(class)), uintptr(unsafe.Pointer(guid)), uintptr(guidSize), uintptr(unsafe.Pointer(requiredSize)), 0, 0) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -49,7 +74,7 @@ func setupDiGetClassDevs(guid *guid, enumerator *string, hwndParent uintptr, fla set = devicesSet(r0) if set == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -61,7 +86,7 @@ func setupDiDestroyDeviceInfoList(set devicesSet) (err error) { r1, _, e1 := syscall.Syscall(procSetupDiDestroyDeviceInfoList.Addr(), 1, uintptr(set), 0, 0) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -73,7 +98,7 @@ func setupDiEnumDeviceInfo(set devicesSet, index uint32, info *devInfoData) (err r1, _, e1 := syscall.Syscall(procSetupDiEnumDeviceInfo.Addr(), 3, uintptr(set), uintptr(index), uintptr(unsafe.Pointer(info))) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -85,7 +110,7 @@ func setupDiGetDeviceInstanceId(set devicesSet, devInfo *devInfoData, devInstanc r1, _, e1 := syscall.Syscall6(procSetupDiGetDeviceInstanceIdW.Addr(), 5, uintptr(set), uintptr(unsafe.Pointer(devInfo)), uintptr(devInstanceId), uintptr(devInstanceIdSize), uintptr(unsafe.Pointer(requiredSize)), 0) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -98,7 +123,7 @@ func setupDiOpenDevRegKey(set devicesSet, devInfo *devInfoData, scope dicsScope, hkey = syscall.Handle(r0) if hkey == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } diff --git a/zsyscall_windows.go b/zsyscall_windows.go index f6005ea..9c42379 100644 --- a/zsyscall_windows.go +++ b/zsyscall_windows.go @@ -1,4 +1,4 @@ -// MACHINE GENERATED BY 'go generate' COMMAND; DO NOT EDIT +// Code generated by 'go generate'; DO NOT EDIT. package serial