From 466971d5456fcc2bffabc2d522be3c97803b8bf5 Mon Sep 17 00:00:00 2001 From: niten94 <127052329+niten94@users.noreply.github.com> Date: Sat, 7 Dec 2024 22:35:17 +0800 Subject: [PATCH] Call ioctl using Syscall, convert pointers in call Replace `syscall.Syscall6` function calls where `syscall.SYS_IOCTL` is passed with `syscall.Syscall` and convert `unsafe.Pointer` to `uintptr` in argument list. --- tscreen_bsd.go | 20 ++++++++++---------- tscreen_darwin.go | 20 ++++++++++---------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/tscreen_bsd.go b/tscreen_bsd.go index b10e2224..4b11227e 100644 --- a/tscreen_bsd.go +++ b/tscreen_bsd.go @@ -29,7 +29,7 @@ func (t *tScreen) termioInit() error { var e error var newtios termiosPrivate var fd uintptr - var tios uintptr + var tios unsafe.Pointer var ioc uintptr t.tiosp = &termiosPrivate{} @@ -40,10 +40,10 @@ func (t *tScreen) termioInit() error { goto failed } - tios = uintptr(unsafe.Pointer(t.tiosp)) + tios = unsafe.Pointer(t.tiosp) ioc = uintptr(syscall.TIOCGETA) fd = uintptr(t.out.(*os.File).Fd()) - if _, _, e1 := syscall.Syscall6(syscall.SYS_IOCTL, fd, ioc, tios, 0, 0, 0); e1 != 0 { + if _, _, e1 := syscall.Syscall(syscall.SYS_IOCTL, fd, ioc, uintptr(tios)); e1 != 0 { e = e1 goto failed } @@ -58,10 +58,10 @@ func (t *tScreen) termioInit() error { newtios.Cflag &^= syscall.CSIZE | syscall.PARENB newtios.Cflag |= syscall.CS8 - tios = uintptr(unsafe.Pointer(&newtios)) + tios = unsafe.Pointer(&newtios) ioc = uintptr(syscall.TIOCSETA) - if _, _, e1 := syscall.Syscall6(syscall.SYS_IOCTL, fd, ioc, tios, 0, 0, 0); e1 != 0 { + if _, _, e1 := syscall.Syscall(syscall.SYS_IOCTL, fd, ioc, uintptr(tios)); e1 != 0 { e = e1 goto failed } @@ -93,8 +93,8 @@ func (t *tScreen) termioFini() { if t.out != nil { fd := uintptr(t.out.(*os.File).Fd()) ioc := uintptr(syscall.TIOCSETAF) - tios := uintptr(unsafe.Pointer(t.tiosp)) - syscall.Syscall6(syscall.SYS_IOCTL, fd, ioc, tios, 0, 0, 0) + tios := unsafe.Pointer(t.tiosp) + syscall.Syscall(syscall.SYS_IOCTL, fd, ioc, uintptr(tios)) t.out.(*os.File).Close() } if t.in != nil { @@ -106,10 +106,10 @@ func (t *tScreen) getWinSize() (int, int, error) { fd := uintptr(t.out.(*os.File).Fd()) dim := [4]uint16{} - dimp := uintptr(unsafe.Pointer(&dim)) + dimp := unsafe.Pointer(&dim) ioc := uintptr(syscall.TIOCGWINSZ) - if _, _, err := syscall.Syscall6(syscall.SYS_IOCTL, - fd, ioc, dimp, 0, 0, 0); err != 0 { + if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, + fd, ioc, uintptr(dimp)); err != 0 { return -1, -1, err } return int(dim[1]), int(dim[0]), nil diff --git a/tscreen_darwin.go b/tscreen_darwin.go index d05479d3..c6a4db47 100644 --- a/tscreen_darwin.go +++ b/tscreen_darwin.go @@ -49,7 +49,7 @@ func (t *tScreen) termioInit() error { var e error var newtios termiosPrivate var fd uintptr - var tios uintptr + var tios unsafe.Pointer var ioc uintptr t.tiosp = &termiosPrivate{} @@ -60,10 +60,10 @@ func (t *tScreen) termioInit() error { goto failed } - tios = uintptr(unsafe.Pointer(t.tiosp)) + tios = unsafe.Pointer(t.tiosp) ioc = uintptr(syscall.TIOCGETA) fd = uintptr(t.out.(*poller.FD).Sysfd()) - if _, _, e1 := syscall.Syscall6(syscall.SYS_IOCTL, fd, ioc, tios, 0, 0, 0); e1 != 0 { + if _, _, e1 := syscall.Syscall(syscall.SYS_IOCTL, fd, ioc, uintptr(tios)); e1 != 0 { e = e1 goto failed } @@ -78,10 +78,10 @@ func (t *tScreen) termioInit() error { newtios.Cflag &^= syscall.CSIZE | syscall.PARENB newtios.Cflag |= syscall.CS8 - tios = uintptr(unsafe.Pointer(&newtios)) + tios = unsafe.Pointer(&newtios) ioc = uintptr(syscall.TIOCSETA) - if _, _, e1 := syscall.Syscall6(syscall.SYS_IOCTL, fd, ioc, tios, 0, 0, 0); e1 != 0 { + if _, _, e1 := syscall.Syscall(syscall.SYS_IOCTL, fd, ioc, uintptr(tios)); e1 != 0 { e = e1 goto failed } @@ -113,8 +113,8 @@ func (t *tScreen) termioFini() { if t.out != nil { fd := uintptr(t.out.(*poller.FD).Sysfd()) ioc := uintptr(syscall.TIOCSETAF) - tios := uintptr(unsafe.Pointer(t.tiosp)) - syscall.Syscall6(syscall.SYS_IOCTL, fd, ioc, tios, 0, 0, 0) + tios := unsafe.Pointer(t.tiosp) + syscall.Syscall(syscall.SYS_IOCTL, fd, ioc, uintptr(tios)) t.out.(*poller.FD).Close() } @@ -127,10 +127,10 @@ func (t *tScreen) getWinSize() (int, int, error) { fd := uintptr(t.out.(*poller.FD).Sysfd()) dim := [4]uint16{} - dimp := uintptr(unsafe.Pointer(&dim)) + dimp := unsafe.Pointer(&dim) ioc := uintptr(syscall.TIOCGWINSZ) - if _, _, err := syscall.Syscall6(syscall.SYS_IOCTL, - fd, ioc, dimp, 0, 0, 0); err != 0 { + if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, + fd, ioc, uintptr(dimp)); err != 0 { return -1, -1, err } return int(dim[1]), int(dim[0]), nil