mirror of
https://github.com/rwinkhart/sys.git
synced 2026-08-28 04:46:44 -04:00
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>
This commit is contained in:
+3
-5
@@ -27,9 +27,7 @@ func IoctlSetInt(fd int, req uint, value int) error {
|
|||||||
func IoctlSetWinsize(fd int, req uint, value *Winsize) error {
|
func IoctlSetWinsize(fd int, req uint, value *Winsize) error {
|
||||||
// TODO: if we get the chance, remove the req parameter and
|
// TODO: if we get the chance, remove the req parameter and
|
||||||
// hardcode TIOCSWINSZ.
|
// hardcode TIOCSWINSZ.
|
||||||
err := ioctl(fd, req, uintptr(unsafe.Pointer(value)))
|
return ioctlPtr(fd, req, unsafe.Pointer(value))
|
||||||
runtime.KeepAlive(value)
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// IoctlSetTermios performs an ioctl on fd with a *Termios.
|
// 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.
|
// for those, IoctlRetInt should be used instead of this function.
|
||||||
func IoctlGetInt(fd int, req uint) (int, error) {
|
func IoctlGetInt(fd int, req uint) (int, error) {
|
||||||
var value int
|
var value int
|
||||||
err := ioctl(fd, req, uintptr(unsafe.Pointer(&value)))
|
err := ioctlPtr(fd, req, unsafe.Pointer(&value))
|
||||||
return value, err
|
return value, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func IoctlGetWinsize(fd int, req uint) (*Winsize, error) {
|
func IoctlGetWinsize(fd int, req uint) (*Winsize, error) {
|
||||||
var value Winsize
|
var value Winsize
|
||||||
err := ioctl(fd, req, uintptr(unsafe.Pointer(&value)))
|
err := ioctlPtr(fd, req, unsafe.Pointer(&value))
|
||||||
return &value, err
|
return &value, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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" {
|
if sysname == "select" {
|
||||||
// select is a keyword of Go. Its name is
|
// select is a keyword of Go. Its name is
|
||||||
// changed to c_select.
|
// changed to c_select.
|
||||||
|
|||||||
@@ -190,7 +190,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onlyCommon := false
|
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.
|
// This function call another syscall which is already implemented.
|
||||||
// Therefore, the gc and gccgo part must not be generated.
|
// Therefore, the gc and gccgo part must not be generated.
|
||||||
onlyCommon = true
|
onlyCommon = true
|
||||||
|
|||||||
@@ -162,12 +162,14 @@ func main() {
|
|||||||
|
|
||||||
sysname = strings.ToLower(sysname) // All libc functions are lowercase.
|
sysname = strings.ToLower(sysname) // All libc functions are lowercase.
|
||||||
|
|
||||||
// Runtime import of function to allow cross-platform builds.
|
if funct != "ioctlPtrRet" {
|
||||||
dynimports += fmt.Sprintf("//go:cgo_import_dynamic libc_%s %s \"%s.so\"\n", sysname, sysname, modname)
|
// Runtime import of function to allow cross-platform builds.
|
||||||
// Link symbol to proc address variable.
|
dynimports += fmt.Sprintf("//go:cgo_import_dynamic libc_%s %s \"%s.so\"\n", sysname, sysname, modname)
|
||||||
linknames += fmt.Sprintf("//go:linkname %s libc_%s\n", sysvarname, sysname)
|
// Link symbol to proc address variable.
|
||||||
// Library proc address variable.
|
linknames += fmt.Sprintf("//go:linkname %s libc_%s\n", sysvarname, sysname)
|
||||||
vars = append(vars, sysvarname)
|
// Library proc address variable.
|
||||||
|
vars = append(vars, sysvarname)
|
||||||
|
}
|
||||||
|
|
||||||
// Go function header.
|
// Go function header.
|
||||||
outlist := strings.Join(out, ", ")
|
outlist := strings.Join(out, ", ")
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ package unix
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"runtime"
|
|
||||||
"syscall"
|
"syscall"
|
||||||
"unsafe"
|
"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) }
|
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 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 {
|
func IoctlCtlInfo(fd int, ctlInfo *CtlInfo) error {
|
||||||
err := ioctl(fd, CTLIOCGINFO, uintptr(unsafe.Pointer(ctlInfo)))
|
return ioctlPtr(fd, CTLIOCGINFO, unsafe.Pointer(ctlInfo))
|
||||||
runtime.KeepAlive(ctlInfo)
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// IfreqMTU is struct ifreq used to get or set a network device's MTU.
|
// 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) {
|
func IoctlGetIfreqMTU(fd int, ifname string) (*IfreqMTU, error) {
|
||||||
var ifreq IfreqMTU
|
var ifreq IfreqMTU
|
||||||
copy(ifreq.Name[:], ifname)
|
copy(ifreq.Name[:], ifname)
|
||||||
err := ioctl(fd, SIOCGIFMTU, uintptr(unsafe.Pointer(&ifreq)))
|
err := ioctlPtr(fd, SIOCGIFMTU, unsafe.Pointer(&ifreq))
|
||||||
return &ifreq, err
|
return &ifreq, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// IoctlSetIfreqMTU performs the SIOCSIFMTU ioctl operation on fd to set the MTU
|
// IoctlSetIfreqMTU performs the SIOCSIFMTU ioctl operation on fd to set the MTU
|
||||||
// of the network device specified by ifreq.Name.
|
// of the network device specified by ifreq.Name.
|
||||||
func IoctlSetIfreqMTU(fd int, ifreq *IfreqMTU) error {
|
func IoctlSetIfreqMTU(fd int, ifreq *IfreqMTU) error {
|
||||||
err := ioctl(fd, SIOCSIFMTU, uintptr(unsafe.Pointer(ifreq)))
|
return ioctlPtr(fd, SIOCSIFMTU, unsafe.Pointer(ifreq))
|
||||||
runtime.KeepAlive(ifreq)
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//sys sysctl(mib []_C_int, old *byte, oldlen *uintptr, new *byte, newlen uintptr) (err error) = SYS_SYSCTL
|
//sys sysctl(mib []_C_int, old *byte, oldlen *uintptr, new *byte, newlen uintptr) (err error) = SYS_SYSCTL
|
||||||
|
|||||||
@@ -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 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
|
//sys sysctl(mib []_C_int, old *byte, oldlen *uintptr, new *byte, newlen uintptr) (err error) = SYS___SYSCTL
|
||||||
|
|
||||||
|
|||||||
@@ -20,3 +20,11 @@ func ioctl(fd int, req uint, arg uintptr) (err error) {
|
|||||||
}
|
}
|
||||||
return
|
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
|
||||||
|
}
|
||||||
|
|||||||
@@ -13,7 +13,6 @@
|
|||||||
package unix
|
package unix
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"runtime"
|
|
||||||
"syscall"
|
"syscall"
|
||||||
"unsafe"
|
"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 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
|
//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) {
|
func IoctlGetPtmget(fd int, req uint) (*Ptmget, error) {
|
||||||
var value Ptmget
|
var value Ptmget
|
||||||
err := ioctl(fd, req, uintptr(unsafe.Pointer(&value)))
|
err := ioctlPtr(fd, req, unsafe.Pointer(&value))
|
||||||
runtime.KeepAlive(value)
|
|
||||||
return &value, err
|
return &value, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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 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
|
//sys sysctl(mib []_C_int, old *byte, oldlen *uintptr, new *byte, newlen uintptr) (err error) = SYS___SYSCTL
|
||||||
|
|
||||||
|
|||||||
@@ -560,14 +560,12 @@ func ioctlPtr(fd int, req uint, arg unsafe.Pointer) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func IoctlSetTermio(fd int, req uint, value *Termio) error {
|
func IoctlSetTermio(fd int, req uint, value *Termio) error {
|
||||||
err := ioctl(fd, req, uintptr(unsafe.Pointer(value)))
|
return ioctlPtr(fd, req, unsafe.Pointer(value))
|
||||||
runtime.KeepAlive(value)
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func IoctlGetTermio(fd int, req uint) (*Termio, error) {
|
func IoctlGetTermio(fd int, req uint) (*Termio, error) {
|
||||||
var value Termio
|
var value Termio
|
||||||
err := ioctl(fd, req, uintptr(unsafe.Pointer(&value)))
|
err := ioctlPtr(fd, req, unsafe.Pointer(&value))
|
||||||
return &value, err
|
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 {
|
func IoctlSetString(fd int, req uint, val string) error {
|
||||||
bs := make([]byte, len(val)+1)
|
bs := make([]byte, len(val)+1)
|
||||||
copy(bs[:len(bs)-1], val)
|
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])
|
runtime.KeepAlive(&bs[0])
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -1124,7 +1122,7 @@ func (l *Lifreq) GetLifruUint() uint {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func IoctlLifreq(fd int, req uint, l *Lifreq) error {
|
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
|
// Strioctl Helpers
|
||||||
@@ -1135,5 +1133,5 @@ func (s *Strioctl) SetInt(i int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func IoctlSetStrioctlRetInt(fd int, req uint, s *Strioctl) (int, error) {
|
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))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 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 munmap(addr uintptr, length uintptr) (err error) = SYS_MUNMAP
|
||||||
//sys ioctl(fd int, req uint, arg uintptr) (err error) = SYS_IOCTL
|
//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 Access(path string, mode uint32) (err error) = SYS___ACCESS_A
|
||||||
//sys Chdir(path string) (err error) = SYS___CHDIR_A
|
//sys Chdir(path string) (err error) = SYS___CHDIR_A
|
||||||
|
|||||||
@@ -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
|
// 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) {
|
func Access(path string, mode uint32) (err error) {
|
||||||
var _p0 *byte
|
var _p0 *byte
|
||||||
_p0, err = BytePtrFromString(path)
|
_p0, err = BytePtrFromString(path)
|
||||||
|
|||||||
Reference in New Issue
Block a user