Skip to content

Commit b13f40e

Browse files
committed
unix: add ioctlPtr with unsafe.Pointer arg on other unices
This is a followup for CL 340915 that adds ioctlPtr for all other UNIX-like platforms. For golang/go#44834 Change-Id: I0ecf84e53f13e5a8da736b3ba7f643262596d23c Reviewed-on: https://go-review.googlesource.com/c/sys/+/469315 Reviewed-by: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Dmitri Goutnik <dgoutnik@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com>
1 parent 3b9b58b commit b13f40e

28 files changed

+233
-12
lines changed

unix/ioctl.go

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
package unix
99

1010
import (
11-
"runtime"
1211
"unsafe"
1312
)
1413

@@ -27,7 +26,7 @@ func IoctlSetInt(fd int, req uint, value int) error {
2726
// passing the integer value directly.
2827
func IoctlSetPointerInt(fd int, req uint, value int) error {
2928
v := int32(value)
30-
return ioctl(fd, req, uintptr(unsafe.Pointer(&v)))
29+
return ioctlPtr(fd, req, unsafe.Pointer(&v))
3130
}
3231

3332
// IoctlSetWinsize performs an ioctl on fd with a *Winsize argument.
@@ -36,19 +35,15 @@ func IoctlSetPointerInt(fd int, req uint, value int) error {
3635
func IoctlSetWinsize(fd int, req uint, value *Winsize) error {
3736
// TODO: if we get the chance, remove the req parameter and
3837
// hardcode TIOCSWINSZ.
39-
err := ioctl(fd, req, uintptr(unsafe.Pointer(value)))
40-
runtime.KeepAlive(value)
41-
return err
38+
return ioctlPtr(fd, req, unsafe.Pointer(value))
4239
}
4340

4441
// IoctlSetTermios performs an ioctl on fd with a *Termios.
4542
//
4643
// The req value will usually be TCSETA or TIOCSETA.
4744
func IoctlSetTermios(fd int, req uint, value *Termios) error {
4845
// TODO: if we get the chance, remove the req parameter.
49-
err := ioctl(fd, req, uintptr(unsafe.Pointer(value)))
50-
runtime.KeepAlive(value)
51-
return err
46+
return ioctlPtr(fd, req, unsafe.Pointer(value))
5247
}
5348

5449
// IoctlGetInt performs an ioctl operation which gets an integer value
@@ -58,18 +53,18 @@ func IoctlSetTermios(fd int, req uint, value *Termios) error {
5853
// for those, IoctlRetInt should be used instead of this function.
5954
func IoctlGetInt(fd int, req uint) (int, error) {
6055
var value int
61-
err := ioctl(fd, req, uintptr(unsafe.Pointer(&value)))
56+
err := ioctlPtr(fd, req, unsafe.Pointer(&value))
6257
return value, err
6358
}
6459

6560
func IoctlGetWinsize(fd int, req uint) (*Winsize, error) {
6661
var value Winsize
67-
err := ioctl(fd, req, uintptr(unsafe.Pointer(&value)))
62+
err := ioctlPtr(fd, req, unsafe.Pointer(&value))
6863
return &value, err
6964
}
7065

7166
func IoctlGetTermios(fd int, req uint) (*Termios, error) {
7267
var value Termios
73-
err := ioctl(fd, req, uintptr(unsafe.Pointer(&value)))
68+
err := ioctlPtr(fd, req, unsafe.Pointer(&value))
7469
return &value, err
7570
}

unix/syscall_aix.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,7 @@ func (w WaitStatus) CoreDump() bool { return w&0x80 == 0x80 }
411411
func (w WaitStatus) TrapCause() int { return -1 }
412412

413413
//sys ioctl(fd int, req uint, arg uintptr) (err error)
414+
//sys ioctlPtr(fd int, req uint, arg unsafe.Pointer) (err error)
414415

415416
// fcntl must never be called with cmd=F_DUP2FD because it doesn't work on AIX
416417
// There is no way to create a custom fcntl and to keep //sys fcntl easily,

unix/syscall_freebsd.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,8 @@ func Getfsstat(buf []Statfs_t, flags int) (n int, err error) {
161161
return
162162
}
163163

164-
//sys ioctl(fd int, req uint, arg uintptr) (err error)
164+
//sys ioctl(fd int, req uint, arg uintptr) (err error) = SYS_IOCTL
165+
//sys ioctlPtr(fd int, req uint, arg unsafe.Pointer) (err error) = SYS_IOCTL
165166

166167
//sys sysctl(mib []_C_int, old *byte, oldlen *uintptr, new *byte, newlen uintptr) (err error) = SYS___SYSCTL
167168

unix/syscall_solaris.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,12 +547,18 @@ func Minor(dev uint64) uint32 {
547547
*/
548548

549549
//sys ioctlRet(fd int, req uint, arg uintptr) (ret int, err error) = libc.ioctl
550+
//sys ioctlPtrRet(fd int, req uint, arg unsafe.Pointer) (ret int, err error) = libc.ioctl
550551

551552
func ioctl(fd int, req uint, arg uintptr) (err error) {
552553
_, err = ioctlRet(fd, req, arg)
553554
return err
554555
}
555556

557+
func ioctlPtr(fd int, req uint, arg unsafe.Pointer) (err error) {
558+
_, err = ioctlPtrRet(fd, req, arg)
559+
return err
560+
}
561+
556562
func IoctlSetTermio(fd int, req uint, value *Termio) error {
557563
err := ioctl(fd, req, uintptr(unsafe.Pointer(value)))
558564
runtime.KeepAlive(value)

unix/zsyscall_aix_ppc.go

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

unix/zsyscall_aix_ppc64.go

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

unix/zsyscall_aix_ppc64_gc.go

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

unix/zsyscall_aix_ppc64_gccgo.go

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

unix/zsyscall_darwin_amd64.go

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

unix/zsyscall_darwin_arm64.go

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)