Browse Source

x/sys/unix: add type specific ioctl functions for termios on solaris

The existing code has no way to manipulate termios or winsize structures
on solaris.  This change adds IoctlGetXXX and IoctlSetXXX functions for
int, termios, termio, and winsize.  The embedded awk script in
mkerrors.sh has additional patterns to generate the needed ioctl
constants for these calls.

Fixes golang/go#12574

Change-Id: Ic62a8c698d42c8ca379c90f71e9f27635e7d03b5
Reviewed-on: https://go-review.googlesource.com/14587
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Aram Hăvărneanu <aram@mgk.ro>
Kim Shrier 10 years ago
parent
commit
584c5fee74

+ 3 - 0
unix/mkerrors.sh

@@ -309,6 +309,9 @@ ccflags="$@"
 		$2 ~ /^(NETLINK|NLM|NLMSG|NLA|IFA|IFAN|RT|RTCF|RTN|RTPROT|RTNH|ARPHRD|ETH_P)_/ ||
 		$2 ~ /^SIOC/ ||
 		$2 ~ /^TIOC/ ||
+		$2 ~ /^TCGET/ ||
+		$2 ~ /^TCSET/ ||
+		$2 ~ /^TC(FLSH|SBRK|XONC)$/ ||
 		$2 !~ "RTF_BITS" &&
 		$2 ~ /^(IFF|IFT|NET_RT|RTM|RTF|RTV|RTA|RTAX)_/ ||
 		$2 ~ /^BIOC/ ||

+ 46 - 0
unix/syscall_solaris.go

@@ -515,6 +515,52 @@ func Acct(path string) (err error) {
 	return acct(pathp)
 }
 
+/*
+ * Expose the ioctl function
+ */
+
+//sys	ioctl(fd int, req int, arg uintptr) (err error)
+
+func IoctlSetInt(fd int, req int, value int) (err error) {
+	return ioctl(fd, req, uintptr(value))
+}
+
+func IoctlSetWinsize(fd int, req int, value *Winsize) (err error) {
+	return ioctl(fd, req, uintptr(unsafe.Pointer(value)))
+}
+
+func IoctlSetTermios(fd int, req int, value *Termios) (err error) {
+	return ioctl(fd, req, uintptr(unsafe.Pointer(value)))
+}
+
+func IoctlSetTermio(fd int, req int, value *Termio) (err error) {
+	return ioctl(fd, req, uintptr(unsafe.Pointer(value)))
+}
+
+func IoctlGetInt(fd int, req int) (int, error) {
+	var value int
+	err := ioctl(fd, req, uintptr(unsafe.Pointer(&value)))
+	return value, err
+}
+
+func IoctlGetWinsize(fd int, req int) (*Winsize, error) {
+	var value Winsize
+	err := ioctl(fd, req, uintptr(unsafe.Pointer(&value)))
+	return &value, err
+}
+
+func IoctlGetTermios(fd int, req int) (*Termios, error) {
+	var value Termios
+	err := ioctl(fd, req, uintptr(unsafe.Pointer(&value)))
+	return &value, err
+}
+
+func IoctlGetTermio(fd int, req int) (*Termio, error) {
+	var value Termio
+	err := ioctl(fd, req, uintptr(unsafe.Pointer(&value)))
+	return &value, err
+}
+
 /*
  * Exposed directly
  */

+ 5 - 0
unix/types_solaris.go

@@ -25,6 +25,7 @@ package unix
 #include <limits.h>
 #include <signal.h>
 #include <termios.h>
+#include <termio.h>
 #include <stdio.h>
 #include <unistd.h>
 #include <sys/mman.h>
@@ -253,3 +254,7 @@ const _SC_PAGESIZE = C._SC_PAGESIZE
 // Terminal handling
 
 type Termios C.struct_termios
+
+type Termio C.struct_termio
+
+type Winsize C.struct_winsize

+ 22 - 4
unix/zerrors_solaris_amd64.go

@@ -161,6 +161,14 @@ const (
 	BRKINT                        = 0x2
 	CFLUSH                        = 0xf
 	CLOCAL                        = 0x800
+	CLOCK_HIGHRES                 = 0x4
+	CLOCK_LEVEL                   = 0xa
+	CLOCK_MONOTONIC               = 0x4
+	CLOCK_PROCESS_CPUTIME_ID      = 0x5
+	CLOCK_PROF                    = 0x2
+	CLOCK_REALTIME                = 0x3
+	CLOCK_THREAD_CPUTIME_ID       = 0x2
+	CLOCK_VIRTUAL                 = 0x1
 	CREAD                         = 0x80
 	CS5                           = 0x0
 	CS6                           = 0x10
@@ -168,6 +176,7 @@ const (
 	CS8                           = 0x30
 	CSIZE                         = 0x30
 	CSTART                        = 0x11
+	CSTATUS                       = 0x14
 	CSTOP                         = 0x13
 	CSTOPB                        = 0x40
 	CSUSP                         = 0x1a
@@ -757,9 +766,7 @@ const (
 	SIOCDARP                      = -0x7fdb96e0
 	SIOCDELMULTI                  = -0x7fdf96ce
 	SIOCDELRT                     = -0x7fcf8df5
-	SIOCDIPSECONFIG               = -0x7ffb9669
 	SIOCDXARP                     = -0x7fff9658
-	SIOCFIPSECONFIG               = -0x7ffb966b
 	SIOCGARP                      = -0x3fdb96e1
 	SIOCGDSTINFO                  = -0x3fff965c
 	SIOCGENADDR                   = -0x3fdf96ab
@@ -821,7 +828,6 @@ const (
 	SIOCLIFGETND                  = -0x3f879672
 	SIOCLIFREMOVEIF               = -0x7f879692
 	SIOCLIFSETND                  = -0x7f879671
-	SIOCLIPSECONFIG               = -0x7ffb9668
 	SIOCLOWER                     = -0x7fdf96d7
 	SIOCSARP                      = -0x7fdb96e2
 	SIOCSCTPGOPT                  = -0x3fef9653
@@ -844,7 +850,6 @@ const (
 	SIOCSIFNETMASK                = -0x7fdf96e6
 	SIOCSIP6ADDRPOLICY            = -0x7fff965d
 	SIOCSIPMSFILTER               = -0x7ffb964b
-	SIOCSIPSECONFIG               = -0x7ffb966a
 	SIOCSLGETREQ                  = -0x3fdf96b9
 	SIOCSLIFADDR                  = -0x7f879690
 	SIOCSLIFBRDADDR               = -0x7f879684
@@ -951,6 +956,8 @@ const (
 	SO_VRRP                       = 0x1017
 	SO_WROFF                      = 0x2
 	TCFLSH                        = 0x5407
+	TCGETA                        = 0x5401
+	TCGETS                        = 0x540d
 	TCIFLUSH                      = 0x0
 	TCIOFLUSH                     = 0x2
 	TCOFLUSH                      = 0x1
@@ -977,6 +984,14 @@ const (
 	TCP_RTO_MAX                   = 0x1b
 	TCP_RTO_MIN                   = 0x1a
 	TCSAFLUSH                     = 0x5410
+	TCSBRK                        = 0x5405
+	TCSETA                        = 0x5402
+	TCSETAF                       = 0x5404
+	TCSETAW                       = 0x5403
+	TCSETS                        = 0x540e
+	TCSETSF                       = 0x5410
+	TCSETSW                       = 0x540f
+	TCXONC                        = 0x5406
 	TIOC                          = 0x5400
 	TIOCCBRK                      = 0x747a
 	TIOCCDTR                      = 0x7478
@@ -1052,6 +1067,7 @@ const (
 	VQUIT                         = 0x1
 	VREPRINT                      = 0xc
 	VSTART                        = 0x8
+	VSTATUS                       = 0x10
 	VSTOP                         = 0x9
 	VSUSP                         = 0xa
 	VSWTCH                        = 0x7
@@ -1215,6 +1231,7 @@ const (
 	SIGFREEZE  = syscall.Signal(0x22)
 	SIGHUP     = syscall.Signal(0x1)
 	SIGILL     = syscall.Signal(0x4)
+	SIGINFO    = syscall.Signal(0x29)
 	SIGINT     = syscall.Signal(0x2)
 	SIGIO      = syscall.Signal(0x16)
 	SIGIOT     = syscall.Signal(0x6)
@@ -1415,4 +1432,5 @@ var signals = [...]string{
 	38: "resource Control Exceeded",
 	39: "reserved for JVM 1",
 	40: "reserved for JVM 2",
+	41: "information Request",
 }

+ 11 - 0
unix/zsyscall_solaris_amd64.go

@@ -22,6 +22,7 @@ import (
 //go:cgo_import_dynamic libc_recvmsg recvmsg "libsocket.so"
 //go:cgo_import_dynamic libc_sendmsg sendmsg "libsocket.so"
 //go:cgo_import_dynamic libc_acct acct "libc.so"
+//go:cgo_import_dynamic libc_ioctl ioctl "libc.so"
 //go:cgo_import_dynamic libc_access access "libc.so"
 //go:cgo_import_dynamic libc_adjtime adjtime "libc.so"
 //go:cgo_import_dynamic libc_chdir chdir "libc.so"
@@ -136,6 +137,7 @@ import (
 //go:linkname procrecvmsg libc_recvmsg
 //go:linkname procsendmsg libc_sendmsg
 //go:linkname procacct libc_acct
+//go:linkname procioctl libc_ioctl
 //go:linkname procAccess libc_access
 //go:linkname procAdjtime libc_adjtime
 //go:linkname procChdir libc_chdir
@@ -251,6 +253,7 @@ var (
 	procrecvmsg,
 	procsendmsg,
 	procacct,
+	procioctl,
 	procAccess,
 	procAdjtime,
 	procChdir,
@@ -472,6 +475,14 @@ func acct(path *byte) (err error) {
 	return
 }
 
+func ioctl(fd int, req int, arg uintptr) (err error) {
+	_, _, e1 := sysvicall6(uintptr(unsafe.Pointer(&procioctl)), 3, uintptr(fd), uintptr(req), uintptr(arg), 0, 0, 0)
+	if e1 != 0 {
+		err = e1
+	}
+	return
+}
+
 func Access(path string, mode uint32) (err error) {
 	var _p0 *byte
 	_p0, err = BytePtrFromString(path)

+ 18 - 1
unix/ztypes_solaris_amd64.go

@@ -259,7 +259,7 @@ type Ustat_t struct {
 }
 
 const (
-	AT_FDCWD            = -0x2e6aad
+	AT_FDCWD            = 0xffd19553
 	AT_SYMLINK_NOFOLLOW = 0x1000
 	AT_SYMLINK_FOLLOW   = 0x2000
 	AT_REMOVEDIR        = 0x1
@@ -403,3 +403,20 @@ type Termios struct {
 	Cc        [19]uint8
 	Pad_cgo_0 [1]byte
 }
+
+type Termio struct {
+	Iflag     uint16
+	Oflag     uint16
+	Cflag     uint16
+	Lflag     uint16
+	Line      int8
+	Cc        [8]uint8
+	Pad_cgo_0 [1]byte
+}
+
+type Winsize struct {
+	Row    uint16
+	Col    uint16
+	Xpixel uint16
+	Ypixel uint16
+}