]> Cypherpunks.ru repositories - gostls13.git/commitdiff
syscall: introduce IoctlPtr for exec_unix tests
authorDmitri Goutnik <dgoutnik@gmail.com>
Mon, 20 Feb 2023 11:55:42 +0000 (06:55 -0500)
committerGopher Robot <gobot@golang.org>
Tue, 21 Feb 2023 23:33:24 +0000 (23:33 +0000)
Avoid passing Go pointers as uintptr in exec_unix_test.go by introducing
syscall.IoctlPtr() which accepts arg as unsafe.Pointer.

For #44834
Fixes #58609

Change-Id: I6d0ded023e5f3c9989783aee7075bb88100d9ec2
Reviewed-on: https://go-review.googlesource.com/c/go/+/469675
Run-TryBot: Dmitri Goutnik <dgoutnik@gmail.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>

src/syscall/exec_aix_test.go
src/syscall/exec_libc.go
src/syscall/exec_solaris_test.go
src/syscall/exec_unix_test.go
src/syscall/export_darwin_test.go
src/syscall/export_unix_test.go

index f2d54a40bd196903fe5403a47deee90492e0e2ea..e8eeae193b1db482a8b7b3ab67bc19f5de0dcc4d 100644 (file)
@@ -34,4 +34,4 @@ func Getpgrp() (pgrp int) {
        return
 }
 
-var Ioctl = ioctl
+var IoctlPtr = ioctlPtr
index f8769b9aba340b4ef887f3866949948b9244df23..0f8a7b53750489f1879bd410eaf484d267436091 100644 (file)
@@ -305,3 +305,7 @@ childerror:
                exit(253)
        }
 }
+
+func ioctlPtr(fd, req uintptr, arg unsafe.Pointer) (err Errno) {
+       return ioctl(fd, req, uintptr(arg))
+}
index 90e5349bf458db4eeb5996888081dcc1bc63aabd..0c653f71da2d2dcc2a2508fc7f3915c44124782d 100644 (file)
@@ -34,4 +34,4 @@ func Getpgrp() (pgrp int) {
        return
 }
 
-var Ioctl = ioctl
+var IoctlPtr = ioctlPtr
index 4253cda5cb6c7d6af0f0340b9817759c46f12226..942a254cb9d1a1146ab39913bdec19d700d6cae4 100644 (file)
@@ -177,7 +177,7 @@ func TestForeground(t *testing.T) {
        // equivalent.
        fpgrp := int32(0)
 
-       errno := syscall.Ioctl(tty.Fd(), syscall.TIOCGPGRP, uintptr(unsafe.Pointer(&fpgrp)))
+       errno := syscall.IoctlPtr(tty.Fd(), syscall.TIOCGPGRP, unsafe.Pointer(&fpgrp))
        if errno != 0 {
                t.Fatalf("TIOCGPGRP failed with error code: %s", errno)
        }
@@ -214,7 +214,7 @@ func TestForeground(t *testing.T) {
 
        // This call fails on darwin/arm64. The failure doesn't matter, though.
        // This is just best effort.
-       syscall.Ioctl(tty.Fd(), syscall.TIOCSPGRP, uintptr(unsafe.Pointer(&fpgrp)))
+       syscall.IoctlPtr(tty.Fd(), syscall.TIOCSPGRP, unsafe.Pointer(&fpgrp))
 }
 
 func TestForegroundSignal(t *testing.T) {
@@ -228,7 +228,7 @@ func TestForegroundSignal(t *testing.T) {
        // equivalent.
        fpgrp := int32(0)
 
-       errno := syscall.Ioctl(tty.Fd(), syscall.TIOCGPGRP, uintptr(unsafe.Pointer(&fpgrp)))
+       errno := syscall.IoctlPtr(tty.Fd(), syscall.TIOCGPGRP, unsafe.Pointer(&fpgrp))
        if errno != 0 {
                t.Fatalf("TIOCGPGRP failed with error code: %s", errno)
        }
@@ -239,7 +239,7 @@ func TestForegroundSignal(t *testing.T) {
 
        defer func() {
                signal.Ignore(syscall.SIGTTIN, syscall.SIGTTOU)
-               syscall.Ioctl(tty.Fd(), syscall.TIOCSPGRP, uintptr(unsafe.Pointer(&fpgrp)))
+               syscall.IoctlPtr(tty.Fd(), syscall.TIOCSPGRP, unsafe.Pointer(&fpgrp))
                signal.Reset()
        }()
 
index 40d18f9144b1e1ee62b05ef68bea3bf8a4839236..0cf992bb00600636507499b884f413bb4d625da2 100644 (file)
@@ -4,8 +4,10 @@
 
 package syscall
 
-func Ioctl(fd, req, arg uintptr) Errno {
-       err := ioctl(int(fd), int(req), int(arg))
+import "unsafe"
+
+func IoctlPtr(fd, req uintptr, arg unsafe.Pointer) Errno {
+       err := ioctlPtr(int(fd), uint(req), arg)
        if err != nil {
                return err.(Errno)
        }
index 2f678d25664bc3283b8977a756be939559c57615..c7486af5957b0f7ad9701f30dcf0e16df60aa3f0 100644 (file)
@@ -6,7 +6,9 @@
 
 package syscall
 
-func Ioctl(fd, req, arg uintptr) (err Errno) {
-       _, _, err = Syscall(SYS_IOCTL, fd, req, arg)
+import "unsafe"
+
+func IoctlPtr(fd, req uintptr, arg unsafe.Pointer) (err Errno) {
+       _, _, err = Syscall(SYS_IOCTL, fd, req, uintptr(arg))
        return err
 }