From 396c9fc8fb0ce27fc7a1ff136dc5af797bba258a Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Tue, 1 Aug 2017 10:50:40 +0200 Subject: [PATCH] unix: add ioctl functions on Darwin Add IoctlGetInt/IoctlSetInt, IoctlGetTermios/IoctlSetTermios and IoctlGetWinsize/IoctlSetWinsize on Darwin. These are similar to the already existing implementations on Linux and Solaris. Generated on Mac OS 10.11 (Darwin 15.6.0). Change-Id: I2d4cc957c840836fcc2ccb71c67631420f4a2eb1 Reviewed-on: https://go-review.googlesource.com/52410 Reviewed-by: Brad Fitzpatrick Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- unix/syscall_darwin.go | 39 +++++++++++++++++++++++++++++++++++ unix/types_darwin.go | 2 ++ unix/zsyscall_darwin_386.go | 10 +++++++++ unix/zsyscall_darwin_amd64.go | 10 +++++++++ unix/zsyscall_darwin_arm.go | 14 +++++++++++-- unix/zsyscall_darwin_arm64.go | 12 ++++++++++- unix/ztypes_darwin_386.go | 7 +++++++ unix/ztypes_darwin_amd64.go | 7 +++++++ unix/ztypes_darwin_arm.go | 7 +++++++ unix/ztypes_darwin_arm64.go | 7 +++++++ 10 files changed, 112 insertions(+), 3 deletions(-) diff --git a/unix/syscall_darwin.go b/unix/syscall_darwin.go index 4ee4b31d..26b83602 100644 --- a/unix/syscall_darwin.go +++ b/unix/syscall_darwin.go @@ -195,6 +195,45 @@ func Getfsstat(buf []Statfs_t, flags int) (n int, err error) { func Kill(pid int, signum syscall.Signal) (err error) { return kill(pid, int(signum), 1) } +//sys ioctl(fd int, req uint, arg uintptr) (err error) + +// ioctl itself should not be exposed directly, but additional get/set +// functions for specific types are permissible. + +// IoctlSetInt performs an ioctl operation which sets an integer value +// on fd, using the specified request number. +func IoctlSetInt(fd int, req uint, value int) error { + return ioctl(fd, req, uintptr(value)) +} + +func IoctlSetWinsize(fd int, req uint, value *Winsize) error { + return ioctl(fd, req, uintptr(unsafe.Pointer(value))) +} + +func IoctlSetTermios(fd int, req uint, value *Termios) error { + return ioctl(fd, req, uintptr(unsafe.Pointer(value))) +} + +// IoctlGetInt performs an ioctl operation which gets an integer value +// from fd, using the specified request number. +func IoctlGetInt(fd int, req uint) (int, error) { + var value int + err := ioctl(fd, req, uintptr(unsafe.Pointer(&value))) + return value, err +} + +func IoctlGetWinsize(fd int, req uint) (*Winsize, error) { + var value Winsize + err := ioctl(fd, req, uintptr(unsafe.Pointer(&value))) + return &value, err +} + +func IoctlGetTermios(fd int, req uint) (*Termios, error) { + var value Termios + err := ioctl(fd, req, uintptr(unsafe.Pointer(&value))) + return &value, err +} + /* * Exposed directly */ diff --git a/unix/types_darwin.go b/unix/types_darwin.go index 74ff1ac9..415124d4 100644 --- a/unix/types_darwin.go +++ b/unix/types_darwin.go @@ -242,6 +242,8 @@ type BpfHdr C.struct_bpf_hdr type Termios C.struct_termios +type Winsize C.struct_winsize + // fchmodat-like syscalls. const ( diff --git a/unix/zsyscall_darwin_386.go b/unix/zsyscall_darwin_386.go index 2198f0bf..92708acc 100644 --- a/unix/zsyscall_darwin_386.go +++ b/unix/zsyscall_darwin_386.go @@ -298,6 +298,16 @@ func kill(pid int, signum int, posix int) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT +func ioctl(fd int, req uint, arg uintptr) (err error) { + _, _, e1 := Syscall(SYS_IOCTL, uintptr(fd), uintptr(req), uintptr(arg)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + func Access(path string, mode uint32) (err error) { var _p0 *byte _p0, err = BytePtrFromString(path) diff --git a/unix/zsyscall_darwin_amd64.go b/unix/zsyscall_darwin_amd64.go index d5af9247..44fc14f8 100644 --- a/unix/zsyscall_darwin_amd64.go +++ b/unix/zsyscall_darwin_amd64.go @@ -298,6 +298,16 @@ func kill(pid int, signum int, posix int) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT +func ioctl(fd int, req uint, arg uintptr) (err error) { + _, _, e1 := Syscall(SYS_IOCTL, uintptr(fd), uintptr(req), uintptr(arg)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + func Access(path string, mode uint32) (err error) { var _p0 *byte _p0, err = BytePtrFromString(path) diff --git a/unix/zsyscall_darwin_arm.go b/unix/zsyscall_darwin_arm.go index d516409d..f4566bd3 100644 --- a/unix/zsyscall_darwin_arm.go +++ b/unix/zsyscall_darwin_arm.go @@ -1,5 +1,5 @@ -// mksyscall.pl -l32 -tags darwin,arm syscall_bsd.go syscall_darwin.go syscall_darwin_arm.go -// MACHINE GENERATED BY THE COMMAND ABOVE; DO NOT EDIT +// mksyscall.pl -tags darwin,arm syscall_bsd.go syscall_darwin.go syscall_darwin_arm.go +// Code generated by the command above; see README.md. DO NOT EDIT. // +build darwin,arm @@ -298,6 +298,16 @@ func kill(pid int, signum int, posix int) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT +func ioctl(fd int, req uint, arg uintptr) (err error) { + _, _, e1 := Syscall(SYS_IOCTL, uintptr(fd), uintptr(req), uintptr(arg)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + func Access(path string, mode uint32) (err error) { var _p0 *byte _p0, err = BytePtrFromString(path) diff --git a/unix/zsyscall_darwin_arm64.go b/unix/zsyscall_darwin_arm64.go index e97759c3..9274b9ae 100644 --- a/unix/zsyscall_darwin_arm64.go +++ b/unix/zsyscall_darwin_arm64.go @@ -1,5 +1,5 @@ // mksyscall.pl -tags darwin,arm64 syscall_bsd.go syscall_darwin.go syscall_darwin_arm64.go -// MACHINE GENERATED BY THE COMMAND ABOVE; DO NOT EDIT +// Code generated by the command above; see README.md. DO NOT EDIT. // +build darwin,arm64 @@ -298,6 +298,16 @@ func kill(pid int, signum int, posix int) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT +func ioctl(fd int, req uint, arg uintptr) (err error) { + _, _, e1 := Syscall(SYS_IOCTL, uintptr(fd), uintptr(req), uintptr(arg)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + func Access(path string, mode uint32) (err error) { var _p0 *byte _p0, err = BytePtrFromString(path) diff --git a/unix/ztypes_darwin_386.go b/unix/ztypes_darwin_386.go index 062bdff2..e61d78a5 100644 --- a/unix/ztypes_darwin_386.go +++ b/unix/ztypes_darwin_386.go @@ -447,6 +447,13 @@ type Termios struct { Ospeed uint32 } +type Winsize struct { + Row uint16 + Col uint16 + Xpixel uint16 + Ypixel uint16 +} + const ( AT_FDCWD = -0x2 AT_REMOVEDIR = 0x80 diff --git a/unix/ztypes_darwin_amd64.go b/unix/ztypes_darwin_amd64.go index 590067f0..2619155f 100644 --- a/unix/ztypes_darwin_amd64.go +++ b/unix/ztypes_darwin_amd64.go @@ -457,6 +457,13 @@ type Termios struct { Ospeed uint64 } +type Winsize struct { + Row uint16 + Col uint16 + Xpixel uint16 + Ypixel uint16 +} + const ( AT_FDCWD = -0x2 AT_REMOVEDIR = 0x80 diff --git a/unix/ztypes_darwin_arm.go b/unix/ztypes_darwin_arm.go index 66df363c..be3efa32 100644 --- a/unix/ztypes_darwin_arm.go +++ b/unix/ztypes_darwin_arm.go @@ -447,3 +447,10 @@ type Termios struct { Ispeed uint32 Ospeed uint32 } + +type Winsize struct { + Row uint16 + Col uint16 + Xpixel uint16 + Ypixel uint16 +} diff --git a/unix/ztypes_darwin_arm64.go b/unix/ztypes_darwin_arm64.go index 85d56eab..8756d04a 100644 --- a/unix/ztypes_darwin_arm64.go +++ b/unix/ztypes_darwin_arm64.go @@ -455,3 +455,10 @@ type Termios struct { Ispeed uint64 Ospeed uint64 } + +type Winsize struct { + Row uint16 + Col uint16 + Xpixel uint16 + Ypixel uint16 +}