Skip to content

Commit 10499f4

Browse files
committed
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 <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Run-TryBot: Dmitri Goutnik <[email protected]> Reviewed-by: Bryan Mills <[email protected]>
1 parent 92c4c39 commit 10499f4

12 files changed

+45
-31
lines changed

unix/ioctl_zos.go

+3-5
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ func IoctlSetInt(fd int, req uint, value int) error {
2727
func IoctlSetWinsize(fd int, req uint, value *Winsize) error {
2828
// TODO: if we get the chance, remove the req parameter and
2929
// hardcode TIOCSWINSZ.
30-
err := ioctl(fd, req, uintptr(unsafe.Pointer(value)))
31-
runtime.KeepAlive(value)
32-
return err
30+
return ioctlPtr(fd, req, unsafe.Pointer(value))
3331
}
3432

3533
// IoctlSetTermios performs an ioctl on fd with a *Termios.
@@ -51,13 +49,13 @@ func IoctlSetTermios(fd int, req uint, value *Termios) error {
5149
// for those, IoctlRetInt should be used instead of this function.
5250
func IoctlGetInt(fd int, req uint) (int, error) {
5351
var value int
54-
err := ioctl(fd, req, uintptr(unsafe.Pointer(&value)))
52+
err := ioctlPtr(fd, req, unsafe.Pointer(&value))
5553
return value, err
5654
}
5755

5856
func IoctlGetWinsize(fd int, req uint) (*Winsize, error) {
5957
var value Winsize
60-
err := ioctl(fd, req, uintptr(unsafe.Pointer(&value)))
58+
err := ioctlPtr(fd, req, unsafe.Pointer(&value))
6159
return &value, err
6260
}
6361

unix/mksyscall_aix_ppc.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ func main() {
217217
}
218218
}
219219

220-
if funct != "fcntl" && funct != "FcntlInt" && funct != "readlen" && funct != "writelen" {
220+
if funct != "fcntl" && funct != "FcntlInt" && funct != "readlen" && funct != "writelen" && funct != "ioctlPtr" {
221221
if sysname == "select" {
222222
// select is a keyword of Go. Its name is
223223
// changed to c_select.

unix/mksyscall_aix_ppc64.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ func main() {
190190
}
191191

192192
onlyCommon := false
193-
if funct == "readlen" || funct == "writelen" || funct == "FcntlInt" || funct == "FcntlFlock" {
193+
if funct == "readlen" || funct == "writelen" || funct == "FcntlInt" || funct == "FcntlFlock" || funct == "ioctlPtr" {
194194
// This function call another syscall which is already implemented.
195195
// Therefore, the gc and gccgo part must not be generated.
196196
onlyCommon = true

unix/mksyscall_solaris.go

+8-6
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,14 @@ func main() {
162162

163163
sysname = strings.ToLower(sysname) // All libc functions are lowercase.
164164

165-
// Runtime import of function to allow cross-platform builds.
166-
dynimports += fmt.Sprintf("//go:cgo_import_dynamic libc_%s %s \"%s.so\"\n", sysname, sysname, modname)
167-
// Link symbol to proc address variable.
168-
linknames += fmt.Sprintf("//go:linkname %s libc_%s\n", sysvarname, sysname)
169-
// Library proc address variable.
170-
vars = append(vars, sysvarname)
165+
if funct != "ioctlPtrRet" {
166+
// Runtime import of function to allow cross-platform builds.
167+
dynimports += fmt.Sprintf("//go:cgo_import_dynamic libc_%s %s \"%s.so\"\n", sysname, sysname, modname)
168+
// Link symbol to proc address variable.
169+
linknames += fmt.Sprintf("//go:linkname %s libc_%s\n", sysvarname, sysname)
170+
// Library proc address variable.
171+
vars = append(vars, sysvarname)
172+
}
171173

172174
// Go function header.
173175
outlist := strings.Join(out, ", ")

unix/syscall_darwin.go

+4-8
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ package unix
1414

1515
import (
1616
"fmt"
17-
"runtime"
1817
"syscall"
1918
"unsafe"
2019
)
@@ -376,11 +375,10 @@ func Flistxattr(fd int, dest []byte) (sz int, err error) {
376375
func Kill(pid int, signum syscall.Signal) (err error) { return kill(pid, int(signum), 1) }
377376

378377
//sys ioctl(fd int, req uint, arg uintptr) (err error)
378+
//sys ioctlPtr(fd int, req uint, arg unsafe.Pointer) (err error) = SYS_IOCTL
379379

380380
func IoctlCtlInfo(fd int, ctlInfo *CtlInfo) error {
381-
err := ioctl(fd, CTLIOCGINFO, uintptr(unsafe.Pointer(ctlInfo)))
382-
runtime.KeepAlive(ctlInfo)
383-
return err
381+
return ioctlPtr(fd, CTLIOCGINFO, unsafe.Pointer(ctlInfo))
384382
}
385383

386384
// IfreqMTU is struct ifreq used to get or set a network device's MTU.
@@ -394,16 +392,14 @@ type IfreqMTU struct {
394392
func IoctlGetIfreqMTU(fd int, ifname string) (*IfreqMTU, error) {
395393
var ifreq IfreqMTU
396394
copy(ifreq.Name[:], ifname)
397-
err := ioctl(fd, SIOCGIFMTU, uintptr(unsafe.Pointer(&ifreq)))
395+
err := ioctlPtr(fd, SIOCGIFMTU, unsafe.Pointer(&ifreq))
398396
return &ifreq, err
399397
}
400398

401399
// IoctlSetIfreqMTU performs the SIOCSIFMTU ioctl operation on fd to set the MTU
402400
// of the network device specified by ifreq.Name.
403401
func IoctlSetIfreqMTU(fd int, ifreq *IfreqMTU) error {
404-
err := ioctl(fd, SIOCSIFMTU, uintptr(unsafe.Pointer(ifreq)))
405-
runtime.KeepAlive(ifreq)
406-
return err
402+
return ioctlPtr(fd, SIOCSIFMTU, unsafe.Pointer(ifreq))
407403
}
408404

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

unix/syscall_dragonfly.go

+1
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ func Getfsstat(buf []Statfs_t, flags int) (n int, err error) {
172172
}
173173

174174
//sys ioctl(fd int, req uint, arg uintptr) (err error)
175+
//sys ioctlPtr(fd int, req uint, arg unsafe.Pointer) (err error) = SYS_IOCTL
175176

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

unix/syscall_hurd.go

+8
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,11 @@ func ioctl(fd int, req uint, arg uintptr) (err error) {
2020
}
2121
return
2222
}
23+
24+
func ioctlPtr(fd int, req uint, arg unsafe.Pointer) (err error) {
25+
r0, er := C.ioctl(C.int(fd), C.ulong(req), C.uintptr_t(uintptr(arg)))
26+
if r0 == -1 && er != nil {
27+
err = er
28+
}
29+
return
30+
}

unix/syscall_netbsd.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
package unix
1414

1515
import (
16-
"runtime"
1716
"syscall"
1817
"unsafe"
1918
)
@@ -178,13 +177,13 @@ func sendfile(outfd int, infd int, offset *int64, count int) (written int, err e
178177
}
179178

180179
//sys ioctl(fd int, req uint, arg uintptr) (err error)
180+
//sys ioctlPtr(fd int, req uint, arg unsafe.Pointer) (err error) = SYS_IOCTL
181181

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

184184
func IoctlGetPtmget(fd int, req uint) (*Ptmget, error) {
185185
var value Ptmget
186-
err := ioctl(fd, req, uintptr(unsafe.Pointer(&value)))
187-
runtime.KeepAlive(value)
186+
err := ioctlPtr(fd, req, unsafe.Pointer(&value))
188187
return &value, err
189188
}
190189

unix/syscall_openbsd.go

+1
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ func Getfsstat(buf []Statfs_t, flags int) (n int, err error) {
152152
}
153153

154154
//sys ioctl(fd int, req uint, arg uintptr) (err error)
155+
//sys ioctlPtr(fd int, req uint, arg unsafe.Pointer) (err error) = SYS_IOCTL
155156

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

unix/syscall_solaris.go

+5-7
Original file line numberDiff line numberDiff line change
@@ -560,14 +560,12 @@ func ioctlPtr(fd int, req uint, arg unsafe.Pointer) (err error) {
560560
}
561561

562562
func IoctlSetTermio(fd int, req uint, value *Termio) error {
563-
err := ioctl(fd, req, uintptr(unsafe.Pointer(value)))
564-
runtime.KeepAlive(value)
565-
return err
563+
return ioctlPtr(fd, req, unsafe.Pointer(value))
566564
}
567565

568566
func IoctlGetTermio(fd int, req uint) (*Termio, error) {
569567
var value Termio
570-
err := ioctl(fd, req, uintptr(unsafe.Pointer(&value)))
568+
err := ioctlPtr(fd, req, unsafe.Pointer(&value))
571569
return &value, err
572570
}
573571

@@ -1090,7 +1088,7 @@ func IoctlSetIntRetInt(fd int, req uint, arg int) (int, error) {
10901088
func IoctlSetString(fd int, req uint, val string) error {
10911089
bs := make([]byte, len(val)+1)
10921090
copy(bs[:len(bs)-1], val)
1093-
err := ioctl(fd, req, uintptr(unsafe.Pointer(&bs[0])))
1091+
err := ioctlPtr(fd, req, unsafe.Pointer(&bs[0]))
10941092
runtime.KeepAlive(&bs[0])
10951093
return err
10961094
}
@@ -1124,7 +1122,7 @@ func (l *Lifreq) GetLifruUint() uint {
11241122
}
11251123

11261124
func IoctlLifreq(fd int, req uint, l *Lifreq) error {
1127-
return ioctl(fd, req, uintptr(unsafe.Pointer(l)))
1125+
return ioctlPtr(fd, req, unsafe.Pointer(l))
11281126
}
11291127

11301128
// Strioctl Helpers
@@ -1135,5 +1133,5 @@ func (s *Strioctl) SetInt(i int) {
11351133
}
11361134

11371135
func IoctlSetStrioctlRetInt(fd int, req uint, s *Strioctl) (int, error) {
1138-
return ioctlRet(fd, req, uintptr(unsafe.Pointer(s)))
1136+
return ioctlPtrRet(fd, req, unsafe.Pointer(s))
11391137
}

unix/syscall_zos_s390x.go

+1
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ func (cmsg *Cmsghdr) SetLen(length int) {
214214
//sys mmap(addr uintptr, length uintptr, prot int, flag int, fd int, pos int64) (ret uintptr, err error) = SYS_MMAP
215215
//sys munmap(addr uintptr, length uintptr) (err error) = SYS_MUNMAP
216216
//sys ioctl(fd int, req uint, arg uintptr) (err error) = SYS_IOCTL
217+
//sys ioctlPtr(fd int, req uint, arg unsafe.Pointer) (err error) = SYS_IOCTL
217218

218219
//sys Access(path string, mode uint32) (err error) = SYS___ACCESS_A
219220
//sys Chdir(path string) (err error) = SYS___CHDIR_A

unix/zsyscall_zos_s390x.go

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)