aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitri Goutnik <dgoutnik@gmail.com>2023-02-24 10:27:54 -0500
committerDmitri Goutnik <dgoutnik@gmail.com>2023-02-24 21:46:34 +0000
commit10499f4574a3c651bf6328415a89d27531035432 (patch)
treeefd75826495723d840c58c0300dcc56f7bca9905
parent92c4c39f76b9a9df34c8a64fb56390964eeef31c (diff)
downloadgolang-x-sys-10499f4574a3c651bf6328415a89d27531035432.tar.gz
unix: add ioctlPtr with unsafe.Pointer arg on other unices (cont)
CL 469315 missed a few conversions, this CL adds them. While here, also update syscall wrapper generators. For golang/go#44834 Change-Id: I4418a8c177ee6d1a269c1cc2c806b199dc7ccf0b Reviewed-on: https://go-review.googlesource.com/c/sys/+/471119 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Dmitri Goutnik <dgoutnik@gmail.com> Reviewed-by: Bryan Mills <bcmills@google.com>
-rw-r--r--unix/ioctl_zos.go8
-rw-r--r--unix/mksyscall_aix_ppc.go2
-rw-r--r--unix/mksyscall_aix_ppc64.go2
-rw-r--r--unix/mksyscall_solaris.go14
-rw-r--r--unix/syscall_darwin.go12
-rw-r--r--unix/syscall_dragonfly.go1
-rw-r--r--unix/syscall_hurd.go8
-rw-r--r--unix/syscall_netbsd.go5
-rw-r--r--unix/syscall_openbsd.go1
-rw-r--r--unix/syscall_solaris.go12
-rw-r--r--unix/syscall_zos_s390x.go1
-rw-r--r--unix/zsyscall_zos_s390x.go10
12 files changed, 45 insertions, 31 deletions
diff --git a/unix/ioctl_zos.go b/unix/ioctl_zos.go
index 5384e7d..6532f09 100644
--- a/unix/ioctl_zos.go
+++ b/unix/ioctl_zos.go
@@ -27,9 +27,7 @@ func IoctlSetInt(fd int, req uint, value int) error {
func IoctlSetWinsize(fd int, req uint, value *Winsize) error {
// TODO: if we get the chance, remove the req parameter and
// hardcode TIOCSWINSZ.
- err := ioctl(fd, req, uintptr(unsafe.Pointer(value)))
- runtime.KeepAlive(value)
- return err
+ return ioctlPtr(fd, req, unsafe.Pointer(value))
}
// IoctlSetTermios performs an ioctl on fd with a *Termios.
@@ -51,13 +49,13 @@ func IoctlSetTermios(fd int, req uint, value *Termios) error {
// for those, IoctlRetInt should be used instead of this function.
func IoctlGetInt(fd int, req uint) (int, error) {
var value int
- err := ioctl(fd, req, uintptr(unsafe.Pointer(&value)))
+ err := ioctlPtr(fd, req, 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)))
+ err := ioctlPtr(fd, req, unsafe.Pointer(&value))
return &value, err
}
diff --git a/unix/mksyscall_aix_ppc.go b/unix/mksyscall_aix_ppc.go
index e3e0dd2..1fe7d92 100644
--- a/unix/mksyscall_aix_ppc.go
+++ b/unix/mksyscall_aix_ppc.go
@@ -217,7 +217,7 @@ func main() {
}
}
- if funct != "fcntl" && funct != "FcntlInt" && funct != "readlen" && funct != "writelen" {
+ if funct != "fcntl" && funct != "FcntlInt" && funct != "readlen" && funct != "writelen" && funct != "ioctlPtr" {
if sysname == "select" {
// select is a keyword of Go. Its name is
// changed to c_select.
diff --git a/unix/mksyscall_aix_ppc64.go b/unix/mksyscall_aix_ppc64.go
index bfadfd6..b9c6563 100644
--- a/unix/mksyscall_aix_ppc64.go
+++ b/unix/mksyscall_aix_ppc64.go
@@ -190,7 +190,7 @@ func main() {
}
onlyCommon := false
- if funct == "readlen" || funct == "writelen" || funct == "FcntlInt" || funct == "FcntlFlock" {
+ if funct == "readlen" || funct == "writelen" || funct == "FcntlInt" || funct == "FcntlFlock" || funct == "ioctlPtr" {
// This function call another syscall which is already implemented.
// Therefore, the gc and gccgo part must not be generated.
onlyCommon = true
diff --git a/unix/mksyscall_solaris.go b/unix/mksyscall_solaris.go
index d5634b1..7db8c8a 100644
--- a/unix/mksyscall_solaris.go
+++ b/unix/mksyscall_solaris.go
@@ -162,12 +162,14 @@ func main() {
sysname = strings.ToLower(sysname) // All libc functions are lowercase.
- // Runtime import of function to allow cross-platform builds.
- dynimports += fmt.Sprintf("//go:cgo_import_dynamic libc_%s %s \"%s.so\"\n", sysname, sysname, modname)
- // Link symbol to proc address variable.
- linknames += fmt.Sprintf("//go:linkname %s libc_%s\n", sysvarname, sysname)
- // Library proc address variable.
- vars = append(vars, sysvarname)
+ if funct != "ioctlPtrRet" {
+ // Runtime import of function to allow cross-platform builds.
+ dynimports += fmt.Sprintf("//go:cgo_import_dynamic libc_%s %s \"%s.so\"\n", sysname, sysname, modname)
+ // Link symbol to proc address variable.
+ linknames += fmt.Sprintf("//go:linkname %s libc_%s\n", sysvarname, sysname)
+ // Library proc address variable.
+ vars = append(vars, sysvarname)
+ }
// Go function header.
outlist := strings.Join(out, ", ")
diff --git a/unix/syscall_darwin.go b/unix/syscall_darwin.go
index 192b071..7064d6e 100644
--- a/unix/syscall_darwin.go
+++ b/unix/syscall_darwin.go
@@ -14,7 +14,6 @@ package unix
import (
"fmt"
- "runtime"
"syscall"
"unsafe"
)
@@ -376,11 +375,10 @@ func Flistxattr(fd int, dest []byte) (sz 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)
+//sys ioctlPtr(fd int, req uint, arg unsafe.Pointer) (err error) = SYS_IOCTL
func IoctlCtlInfo(fd int, ctlInfo *CtlInfo) error {
- err := ioctl(fd, CTLIOCGINFO, uintptr(unsafe.Pointer(ctlInfo)))
- runtime.KeepAlive(ctlInfo)
- return err
+ return ioctlPtr(fd, CTLIOCGINFO, unsafe.Pointer(ctlInfo))
}
// IfreqMTU is struct ifreq used to get or set a network device's MTU.
@@ -394,16 +392,14 @@ type IfreqMTU struct {
func IoctlGetIfreqMTU(fd int, ifname string) (*IfreqMTU, error) {
var ifreq IfreqMTU
copy(ifreq.Name[:], ifname)
- err := ioctl(fd, SIOCGIFMTU, uintptr(unsafe.Pointer(&ifreq)))
+ err := ioctlPtr(fd, SIOCGIFMTU, unsafe.Pointer(&ifreq))
return &ifreq, err
}
// IoctlSetIfreqMTU performs the SIOCSIFMTU ioctl operation on fd to set the MTU
// of the network device specified by ifreq.Name.
func IoctlSetIfreqMTU(fd int, ifreq *IfreqMTU) error {
- err := ioctl(fd, SIOCSIFMTU, uintptr(unsafe.Pointer(ifreq)))
- runtime.KeepAlive(ifreq)
- return err
+ return ioctlPtr(fd, SIOCSIFMTU, unsafe.Pointer(ifreq))
}
//sys sysctl(mib []_C_int, old *byte, oldlen *uintptr, new *byte, newlen uintptr) (err error) = SYS_SYSCTL
diff --git a/unix/syscall_dragonfly.go b/unix/syscall_dragonfly.go
index a41111a..221efc2 100644
--- a/unix/syscall_dragonfly.go
+++ b/unix/syscall_dragonfly.go
@@ -172,6 +172,7 @@ func Getfsstat(buf []Statfs_t, flags int) (n int, err error) {
}
//sys ioctl(fd int, req uint, arg uintptr) (err error)
+//sys ioctlPtr(fd int, req uint, arg unsafe.Pointer) (err error) = SYS_IOCTL
//sys sysctl(mib []_C_int, old *byte, oldlen *uintptr, new *byte, newlen uintptr) (err error) = SYS___SYSCTL
diff --git a/unix/syscall_hurd.go b/unix/syscall_hurd.go
index 4ffb648..381fd46 100644
--- a/unix/syscall_hurd.go
+++ b/unix/syscall_hurd.go
@@ -20,3 +20,11 @@ func ioctl(fd int, req uint, arg uintptr) (err error) {
}
return
}
+
+func ioctlPtr(fd int, req uint, arg unsafe.Pointer) (err error) {
+ r0, er := C.ioctl(C.int(fd), C.ulong(req), C.uintptr_t(uintptr(arg)))
+ if r0 == -1 && er != nil {
+ err = er
+ }
+ return
+}
diff --git a/unix/syscall_netbsd.go b/unix/syscall_netbsd.go
index 35a3ad7..e66865d 100644
--- a/unix/syscall_netbsd.go
+++ b/unix/syscall_netbsd.go
@@ -13,7 +13,6 @@
package unix
import (
- "runtime"
"syscall"
"unsafe"
)
@@ -178,13 +177,13 @@ func sendfile(outfd int, infd int, offset *int64, count int) (written int, err e
}
//sys ioctl(fd int, req uint, arg uintptr) (err error)
+//sys ioctlPtr(fd int, req uint, arg unsafe.Pointer) (err error) = SYS_IOCTL
//sys sysctl(mib []_C_int, old *byte, oldlen *uintptr, new *byte, newlen uintptr) (err error) = SYS___SYSCTL
func IoctlGetPtmget(fd int, req uint) (*Ptmget, error) {
var value Ptmget
- err := ioctl(fd, req, uintptr(unsafe.Pointer(&value)))
- runtime.KeepAlive(value)
+ err := ioctlPtr(fd, req, unsafe.Pointer(&value))
return &value, err
}
diff --git a/unix/syscall_openbsd.go b/unix/syscall_openbsd.go
index 9b67b90..5e9de23 100644
--- a/unix/syscall_openbsd.go
+++ b/unix/syscall_openbsd.go
@@ -152,6 +152,7 @@ func Getfsstat(buf []Statfs_t, flags int) (n int, err error) {
}
//sys ioctl(fd int, req uint, arg uintptr) (err error)
+//sys ioctlPtr(fd int, req uint, arg unsafe.Pointer) (err error) = SYS_IOCTL
//sys sysctl(mib []_C_int, old *byte, oldlen *uintptr, new *byte, newlen uintptr) (err error) = SYS___SYSCTL
diff --git a/unix/syscall_solaris.go b/unix/syscall_solaris.go
index e224385..dc1f3d7 100644
--- a/unix/syscall_solaris.go
+++ b/unix/syscall_solaris.go
@@ -560,14 +560,12 @@ func ioctlPtr(fd int, req uint, arg unsafe.Pointer) (err error) {
}
func IoctlSetTermio(fd int, req uint, value *Termio) error {
- err := ioctl(fd, req, uintptr(unsafe.Pointer(value)))
- runtime.KeepAlive(value)
- return err
+ return ioctlPtr(fd, req, unsafe.Pointer(value))
}
func IoctlGetTermio(fd int, req uint) (*Termio, error) {
var value Termio
- err := ioctl(fd, req, uintptr(unsafe.Pointer(&value)))
+ err := ioctlPtr(fd, req, unsafe.Pointer(&value))
return &value, err
}
@@ -1090,7 +1088,7 @@ func IoctlSetIntRetInt(fd int, req uint, arg int) (int, error) {
func IoctlSetString(fd int, req uint, val string) error {
bs := make([]byte, len(val)+1)
copy(bs[:len(bs)-1], val)
- err := ioctl(fd, req, uintptr(unsafe.Pointer(&bs[0])))
+ err := ioctlPtr(fd, req, unsafe.Pointer(&bs[0]))
runtime.KeepAlive(&bs[0])
return err
}
@@ -1124,7 +1122,7 @@ func (l *Lifreq) GetLifruUint() uint {
}
func IoctlLifreq(fd int, req uint, l *Lifreq) error {
- return ioctl(fd, req, uintptr(unsafe.Pointer(l)))
+ return ioctlPtr(fd, req, unsafe.Pointer(l))
}
// Strioctl Helpers
@@ -1135,5 +1133,5 @@ func (s *Strioctl) SetInt(i int) {
}
func IoctlSetStrioctlRetInt(fd int, req uint, s *Strioctl) (int, error) {
- return ioctlRet(fd, req, uintptr(unsafe.Pointer(s)))
+ return ioctlPtrRet(fd, req, unsafe.Pointer(s))
}
diff --git a/unix/syscall_zos_s390x.go b/unix/syscall_zos_s390x.go
index 68b2f3e..8adcf39 100644
--- a/unix/syscall_zos_s390x.go
+++ b/unix/syscall_zos_s390x.go
@@ -214,6 +214,7 @@ func (cmsg *Cmsghdr) SetLen(length int) {
//sys mmap(addr uintptr, length uintptr, prot int, flag int, fd int, pos int64) (ret uintptr, err error) = SYS_MMAP
//sys munmap(addr uintptr, length uintptr) (err error) = SYS_MUNMAP
//sys ioctl(fd int, req uint, arg uintptr) (err error) = SYS_IOCTL
+//sys ioctlPtr(fd int, req uint, arg unsafe.Pointer) (err error) = SYS_IOCTL
//sys Access(path string, mode uint32) (err error) = SYS___ACCESS_A
//sys Chdir(path string) (err error) = SYS___CHDIR_A
diff --git a/unix/zsyscall_zos_s390x.go b/unix/zsyscall_zos_s390x.go
index f207945..07bfe2e 100644
--- a/unix/zsyscall_zos_s390x.go
+++ b/unix/zsyscall_zos_s390x.go
@@ -267,6 +267,16 @@ func ioctl(fd int, req uint, arg uintptr) (err error) {
// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
+func ioctlPtr(fd int, req uint, arg unsafe.Pointer) (err error) {
+ _, _, e1 := syscall_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)