diff options
Diffstat (limited to 'vendor/golang.org/x/sys/unix/syscall_linux.go')
-rw-r--r-- | vendor/golang.org/x/sys/unix/syscall_linux.go | 241 |
1 files changed, 230 insertions, 11 deletions
diff --git a/vendor/golang.org/x/sys/unix/syscall_linux.go b/vendor/golang.org/x/sys/unix/syscall_linux.go index 84aa8ea..c302f01 100644 --- a/vendor/golang.org/x/sys/unix/syscall_linux.go +++ b/vendor/golang.org/x/sys/unix/syscall_linux.go | |||
@@ -12,6 +12,9 @@ | |||
12 | package unix | 12 | package unix |
13 | 13 | ||
14 | import ( | 14 | import ( |
15 | "encoding/binary" | ||
16 | "net" | ||
17 | "runtime" | ||
15 | "syscall" | 18 | "syscall" |
16 | "unsafe" | 19 | "unsafe" |
17 | ) | 20 | ) |
@@ -36,6 +39,20 @@ func Creat(path string, mode uint32) (fd int, err error) { | |||
36 | return Open(path, O_CREAT|O_WRONLY|O_TRUNC, mode) | 39 | return Open(path, O_CREAT|O_WRONLY|O_TRUNC, mode) |
37 | } | 40 | } |
38 | 41 | ||
42 | //sys FanotifyInit(flags uint, event_f_flags uint) (fd int, err error) | ||
43 | //sys fanotifyMark(fd int, flags uint, mask uint64, dirFd int, pathname *byte) (err error) | ||
44 | |||
45 | func FanotifyMark(fd int, flags uint, mask uint64, dirFd int, pathname string) (err error) { | ||
46 | if pathname == "" { | ||
47 | return fanotifyMark(fd, flags, mask, dirFd, nil) | ||
48 | } | ||
49 | p, err := BytePtrFromString(pathname) | ||
50 | if err != nil { | ||
51 | return err | ||
52 | } | ||
53 | return fanotifyMark(fd, flags, mask, dirFd, p) | ||
54 | } | ||
55 | |||
39 | //sys fchmodat(dirfd int, path string, mode uint32) (err error) | 56 | //sys fchmodat(dirfd int, path string, mode uint32) (err error) |
40 | 57 | ||
41 | func Fchmodat(dirfd int, path string, mode uint32, flags int) (err error) { | 58 | func Fchmodat(dirfd int, path string, mode uint32, flags int) (err error) { |
@@ -55,6 +72,15 @@ func Fchmodat(dirfd int, path string, mode uint32, flags int) (err error) { | |||
55 | // ioctl itself should not be exposed directly, but additional get/set | 72 | // ioctl itself should not be exposed directly, but additional get/set |
56 | // functions for specific types are permissible. | 73 | // functions for specific types are permissible. |
57 | 74 | ||
75 | // IoctlSetPointerInt performs an ioctl operation which sets an | ||
76 | // integer value on fd, using the specified request number. The ioctl | ||
77 | // argument is called with a pointer to the integer value, rather than | ||
78 | // passing the integer value directly. | ||
79 | func IoctlSetPointerInt(fd int, req uint, value int) error { | ||
80 | v := int32(value) | ||
81 | return ioctl(fd, req, uintptr(unsafe.Pointer(&v))) | ||
82 | } | ||
83 | |||
58 | // IoctlSetInt performs an ioctl operation which sets an integer value | 84 | // IoctlSetInt performs an ioctl operation which sets an integer value |
59 | // on fd, using the specified request number. | 85 | // on fd, using the specified request number. |
60 | func IoctlSetInt(fd int, req uint, value int) error { | 86 | func IoctlSetInt(fd int, req uint, value int) error { |
@@ -69,6 +95,12 @@ func ioctlSetTermios(fd int, req uint, value *Termios) error { | |||
69 | return ioctl(fd, req, uintptr(unsafe.Pointer(value))) | 95 | return ioctl(fd, req, uintptr(unsafe.Pointer(value))) |
70 | } | 96 | } |
71 | 97 | ||
98 | func IoctlSetRTCTime(fd int, value *RTCTime) error { | ||
99 | err := ioctl(fd, RTC_SET_TIME, uintptr(unsafe.Pointer(value))) | ||
100 | runtime.KeepAlive(value) | ||
101 | return err | ||
102 | } | ||
103 | |||
72 | // IoctlGetInt performs an ioctl operation which gets an integer value | 104 | // IoctlGetInt performs an ioctl operation which gets an integer value |
73 | // from fd, using the specified request number. | 105 | // from fd, using the specified request number. |
74 | func IoctlGetInt(fd int, req uint) (int, error) { | 106 | func IoctlGetInt(fd int, req uint) (int, error) { |
@@ -89,6 +121,12 @@ func IoctlGetTermios(fd int, req uint) (*Termios, error) { | |||
89 | return &value, err | 121 | return &value, err |
90 | } | 122 | } |
91 | 123 | ||
124 | func IoctlGetRTCTime(fd int) (*RTCTime, error) { | ||
125 | var value RTCTime | ||
126 | err := ioctl(fd, RTC_RD_TIME, uintptr(unsafe.Pointer(&value))) | ||
127 | return &value, err | ||
128 | } | ||
129 | |||
92 | //sys Linkat(olddirfd int, oldpath string, newdirfd int, newpath string, flags int) (err error) | 130 | //sys Linkat(olddirfd int, oldpath string, newdirfd int, newpath string, flags int) (err error) |
93 | 131 | ||
94 | func Link(oldpath string, newpath string) (err error) { | 132 | func Link(oldpath string, newpath string) (err error) { |
@@ -710,6 +748,51 @@ func (sa *SockaddrXDP) sockaddr() (unsafe.Pointer, _Socklen, error) { | |||
710 | return unsafe.Pointer(&sa.raw), SizeofSockaddrXDP, nil | 748 | return unsafe.Pointer(&sa.raw), SizeofSockaddrXDP, nil |
711 | } | 749 | } |
712 | 750 | ||
751 | // This constant mirrors the #define of PX_PROTO_OE in | ||
752 | // linux/if_pppox.h. We're defining this by hand here instead of | ||
753 | // autogenerating through mkerrors.sh because including | ||
754 | // linux/if_pppox.h causes some declaration conflicts with other | ||
755 | // includes (linux/if_pppox.h includes linux/in.h, which conflicts | ||
756 | // with netinet/in.h). Given that we only need a single zero constant | ||
757 | // out of that file, it's cleaner to just define it by hand here. | ||
758 | const px_proto_oe = 0 | ||
759 | |||
760 | type SockaddrPPPoE struct { | ||
761 | SID uint16 | ||
762 | Remote net.HardwareAddr | ||
763 | Dev string | ||
764 | raw RawSockaddrPPPoX | ||
765 | } | ||
766 | |||
767 | func (sa *SockaddrPPPoE) sockaddr() (unsafe.Pointer, _Socklen, error) { | ||
768 | if len(sa.Remote) != 6 { | ||
769 | return nil, 0, EINVAL | ||
770 | } | ||
771 | if len(sa.Dev) > IFNAMSIZ-1 { | ||
772 | return nil, 0, EINVAL | ||
773 | } | ||
774 | |||
775 | *(*uint16)(unsafe.Pointer(&sa.raw[0])) = AF_PPPOX | ||
776 | // This next field is in host-endian byte order. We can't use the | ||
777 | // same unsafe pointer cast as above, because this value is not | ||
778 | // 32-bit aligned and some architectures don't allow unaligned | ||
779 | // access. | ||
780 | // | ||
781 | // However, the value of px_proto_oe is 0, so we can use | ||
782 | // encoding/binary helpers to write the bytes without worrying | ||
783 | // about the ordering. | ||
784 | binary.BigEndian.PutUint32(sa.raw[2:6], px_proto_oe) | ||
785 | // This field is deliberately big-endian, unlike the previous | ||
786 | // one. The kernel expects SID to be in network byte order. | ||
787 | binary.BigEndian.PutUint16(sa.raw[6:8], sa.SID) | ||
788 | copy(sa.raw[8:14], sa.Remote) | ||
789 | for i := 14; i < 14+IFNAMSIZ; i++ { | ||
790 | sa.raw[i] = 0 | ||
791 | } | ||
792 | copy(sa.raw[14:], sa.Dev) | ||
793 | return unsafe.Pointer(&sa.raw), SizeofSockaddrPPPoX, nil | ||
794 | } | ||
795 | |||
713 | func anyToSockaddr(fd int, rsa *RawSockaddrAny) (Sockaddr, error) { | 796 | func anyToSockaddr(fd int, rsa *RawSockaddrAny) (Sockaddr, error) { |
714 | switch rsa.Addr.Family { | 797 | switch rsa.Addr.Family { |
715 | case AF_NETLINK: | 798 | case AF_NETLINK: |
@@ -820,6 +903,22 @@ func anyToSockaddr(fd int, rsa *RawSockaddrAny) (Sockaddr, error) { | |||
820 | SharedUmemFD: pp.Shared_umem_fd, | 903 | SharedUmemFD: pp.Shared_umem_fd, |
821 | } | 904 | } |
822 | return sa, nil | 905 | return sa, nil |
906 | case AF_PPPOX: | ||
907 | pp := (*RawSockaddrPPPoX)(unsafe.Pointer(rsa)) | ||
908 | if binary.BigEndian.Uint32(pp[2:6]) != px_proto_oe { | ||
909 | return nil, EINVAL | ||
910 | } | ||
911 | sa := &SockaddrPPPoE{ | ||
912 | SID: binary.BigEndian.Uint16(pp[6:8]), | ||
913 | Remote: net.HardwareAddr(pp[8:14]), | ||
914 | } | ||
915 | for i := 14; i < 14+IFNAMSIZ; i++ { | ||
916 | if pp[i] == 0 { | ||
917 | sa.Dev = string(pp[14:i]) | ||
918 | break | ||
919 | } | ||
920 | } | ||
921 | return sa, nil | ||
823 | } | 922 | } |
824 | return nil, EAFNOSUPPORT | 923 | return nil, EAFNOSUPPORT |
825 | } | 924 | } |
@@ -905,10 +1004,50 @@ func GetsockoptString(fd, level, opt int) (string, error) { | |||
905 | return string(buf[:vallen-1]), nil | 1004 | return string(buf[:vallen-1]), nil |
906 | } | 1005 | } |
907 | 1006 | ||
1007 | func GetsockoptTpacketStats(fd, level, opt int) (*TpacketStats, error) { | ||
1008 | var value TpacketStats | ||
1009 | vallen := _Socklen(SizeofTpacketStats) | ||
1010 | err := getsockopt(fd, level, opt, unsafe.Pointer(&value), &vallen) | ||
1011 | return &value, err | ||
1012 | } | ||
1013 | |||
1014 | func GetsockoptTpacketStatsV3(fd, level, opt int) (*TpacketStatsV3, error) { | ||
1015 | var value TpacketStatsV3 | ||
1016 | vallen := _Socklen(SizeofTpacketStatsV3) | ||
1017 | err := getsockopt(fd, level, opt, unsafe.Pointer(&value), &vallen) | ||
1018 | return &value, err | ||
1019 | } | ||
1020 | |||
908 | func SetsockoptIPMreqn(fd, level, opt int, mreq *IPMreqn) (err error) { | 1021 | func SetsockoptIPMreqn(fd, level, opt int, mreq *IPMreqn) (err error) { |
909 | return setsockopt(fd, level, opt, unsafe.Pointer(mreq), unsafe.Sizeof(*mreq)) | 1022 | return setsockopt(fd, level, opt, unsafe.Pointer(mreq), unsafe.Sizeof(*mreq)) |
910 | } | 1023 | } |
911 | 1024 | ||
1025 | func SetsockoptPacketMreq(fd, level, opt int, mreq *PacketMreq) error { | ||
1026 | return setsockopt(fd, level, opt, unsafe.Pointer(mreq), unsafe.Sizeof(*mreq)) | ||
1027 | } | ||
1028 | |||
1029 | // SetsockoptSockFprog attaches a classic BPF or an extended BPF program to a | ||
1030 | // socket to filter incoming packets. See 'man 7 socket' for usage information. | ||
1031 | func SetsockoptSockFprog(fd, level, opt int, fprog *SockFprog) error { | ||
1032 | return setsockopt(fd, level, opt, unsafe.Pointer(fprog), unsafe.Sizeof(*fprog)) | ||
1033 | } | ||
1034 | |||
1035 | func SetsockoptCanRawFilter(fd, level, opt int, filter []CanFilter) error { | ||
1036 | var p unsafe.Pointer | ||
1037 | if len(filter) > 0 { | ||
1038 | p = unsafe.Pointer(&filter[0]) | ||
1039 | } | ||
1040 | return setsockopt(fd, level, opt, p, uintptr(len(filter)*SizeofCanFilter)) | ||
1041 | } | ||
1042 | |||
1043 | func SetsockoptTpacketReq(fd, level, opt int, tp *TpacketReq) error { | ||
1044 | return setsockopt(fd, level, opt, unsafe.Pointer(tp), unsafe.Sizeof(*tp)) | ||
1045 | } | ||
1046 | |||
1047 | func SetsockoptTpacketReq3(fd, level, opt int, tp *TpacketReq3) error { | ||
1048 | return setsockopt(fd, level, opt, unsafe.Pointer(tp), unsafe.Sizeof(*tp)) | ||
1049 | } | ||
1050 | |||
912 | // Keyctl Commands (http://man7.org/linux/man-pages/man2/keyctl.2.html) | 1051 | // Keyctl Commands (http://man7.org/linux/man-pages/man2/keyctl.2.html) |
913 | 1052 | ||
914 | // KeyctlInt calls keyctl commands in which each argument is an int. | 1053 | // KeyctlInt calls keyctl commands in which each argument is an int. |
@@ -1288,6 +1427,13 @@ func Mount(source string, target string, fstype string, flags uintptr, data stri | |||
1288 | return mount(source, target, fstype, flags, datap) | 1427 | return mount(source, target, fstype, flags, datap) |
1289 | } | 1428 | } |
1290 | 1429 | ||
1430 | func Sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) { | ||
1431 | if raceenabled { | ||
1432 | raceReleaseMerge(unsafe.Pointer(&ioSync)) | ||
1433 | } | ||
1434 | return sendfile(outfd, infd, offset, count) | ||
1435 | } | ||
1436 | |||
1291 | // Sendto | 1437 | // Sendto |
1292 | // Recvfrom | 1438 | // Recvfrom |
1293 | // Socketpair | 1439 | // Socketpair |
@@ -1302,6 +1448,7 @@ func Mount(source string, target string, fstype string, flags uintptr, data stri | |||
1302 | //sys Chroot(path string) (err error) | 1448 | //sys Chroot(path string) (err error) |
1303 | //sys ClockGetres(clockid int32, res *Timespec) (err error) | 1449 | //sys ClockGetres(clockid int32, res *Timespec) (err error) |
1304 | //sys ClockGettime(clockid int32, time *Timespec) (err error) | 1450 | //sys ClockGettime(clockid int32, time *Timespec) (err error) |
1451 | //sys ClockNanosleep(clockid int32, flags int, request *Timespec, remain *Timespec) (err error) | ||
1305 | //sys Close(fd int) (err error) | 1452 | //sys Close(fd int) (err error) |
1306 | //sys CopyFileRange(rfd int, roff *int64, wfd int, woff *int64, len int, flags int) (n int, err error) | 1453 | //sys CopyFileRange(rfd int, roff *int64, wfd int, woff *int64, len int, flags int) (n int, err error) |
1307 | //sys DeleteModule(name string, flags int) (err error) | 1454 | //sys DeleteModule(name string, flags int) (err error) |
@@ -1362,7 +1509,6 @@ func Getpgrp() (pid int) { | |||
1362 | //sys Pselect(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timespec, sigmask *Sigset_t) (n int, err error) = SYS_PSELECT6 | 1509 | //sys Pselect(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timespec, sigmask *Sigset_t) (n int, err error) = SYS_PSELECT6 |
1363 | //sys read(fd int, p []byte) (n int, err error) | 1510 | //sys read(fd int, p []byte) (n int, err error) |
1364 | //sys Removexattr(path string, attr string) (err error) | 1511 | //sys Removexattr(path string, attr string) (err error) |
1365 | //sys Renameat(olddirfd int, oldpath string, newdirfd int, newpath string) (err error) | ||
1366 | //sys Renameat2(olddirfd int, oldpath string, newdirfd int, newpath string, flags uint) (err error) | 1512 | //sys Renameat2(olddirfd int, oldpath string, newdirfd int, newpath string, flags uint) (err error) |
1367 | //sys RequestKey(keyType string, description string, callback string, destRingid int) (id int, err error) | 1513 | //sys RequestKey(keyType string, description string, callback string, destRingid int) (id int, err error) |
1368 | //sys Setdomainname(p []byte) (err error) | 1514 | //sys Setdomainname(p []byte) (err error) |
@@ -1387,6 +1533,7 @@ func Setgid(uid int) (err error) { | |||
1387 | 1533 | ||
1388 | //sys Setpriority(which int, who int, prio int) (err error) | 1534 | //sys Setpriority(which int, who int, prio int) (err error) |
1389 | //sys Setxattr(path string, attr string, data []byte, flags int) (err error) | 1535 | //sys Setxattr(path string, attr string, data []byte, flags int) (err error) |
1536 | //sys Signalfd(fd int, mask *Sigset_t, flags int) = SYS_SIGNALFD4 | ||
1390 | //sys Statx(dirfd int, path string, flags int, mask int, stat *Statx_t) (err error) | 1537 | //sys Statx(dirfd int, path string, flags int, mask int, stat *Statx_t) (err error) |
1391 | //sys Sync() | 1538 | //sys Sync() |
1392 | //sys Syncfs(fd int) (err error) | 1539 | //sys Syncfs(fd int) (err error) |
@@ -1431,15 +1578,12 @@ func Munmap(b []byte) (err error) { | |||
1431 | // Vmsplice splices user pages from a slice of Iovecs into a pipe specified by fd, | 1578 | // Vmsplice splices user pages from a slice of Iovecs into a pipe specified by fd, |
1432 | // using the specified flags. | 1579 | // using the specified flags. |
1433 | func Vmsplice(fd int, iovs []Iovec, flags int) (int, error) { | 1580 | func Vmsplice(fd int, iovs []Iovec, flags int) (int, error) { |
1434 | n, _, errno := Syscall6( | 1581 | var p unsafe.Pointer |
1435 | SYS_VMSPLICE, | 1582 | if len(iovs) > 0 { |
1436 | uintptr(fd), | 1583 | p = unsafe.Pointer(&iovs[0]) |
1437 | uintptr(unsafe.Pointer(&iovs[0])), | 1584 | } |
1438 | uintptr(len(iovs)), | 1585 | |
1439 | uintptr(flags), | 1586 | n, _, errno := Syscall6(SYS_VMSPLICE, uintptr(fd), uintptr(p), uintptr(len(iovs)), uintptr(flags), 0, 0) |
1440 | 0, | ||
1441 | 0, | ||
1442 | ) | ||
1443 | if errno != 0 { | 1587 | if errno != 0 { |
1444 | return 0, syscall.Errno(errno) | 1588 | return 0, syscall.Errno(errno) |
1445 | } | 1589 | } |
@@ -1518,6 +1662,82 @@ func Faccessat(dirfd int, path string, mode uint32, flags int) (err error) { | |||
1518 | return EACCES | 1662 | return EACCES |
1519 | } | 1663 | } |
1520 | 1664 | ||
1665 | //sys nameToHandleAt(dirFD int, pathname string, fh *fileHandle, mountID *_C_int, flags int) (err error) = SYS_NAME_TO_HANDLE_AT | ||
1666 | //sys openByHandleAt(mountFD int, fh *fileHandle, flags int) (fd int, err error) = SYS_OPEN_BY_HANDLE_AT | ||
1667 | |||
1668 | // fileHandle is the argument to nameToHandleAt and openByHandleAt. We | ||
1669 | // originally tried to generate it via unix/linux/types.go with "type | ||
1670 | // fileHandle C.struct_file_handle" but that generated empty structs | ||
1671 | // for mips64 and mips64le. Instead, hard code it for now (it's the | ||
1672 | // same everywhere else) until the mips64 generator issue is fixed. | ||
1673 | type fileHandle struct { | ||
1674 | Bytes uint32 | ||
1675 | Type int32 | ||
1676 | } | ||
1677 | |||
1678 | // FileHandle represents the C struct file_handle used by | ||
1679 | // name_to_handle_at (see NameToHandleAt) and open_by_handle_at (see | ||
1680 | // OpenByHandleAt). | ||
1681 | type FileHandle struct { | ||
1682 | *fileHandle | ||
1683 | } | ||
1684 | |||
1685 | // NewFileHandle constructs a FileHandle. | ||
1686 | func NewFileHandle(handleType int32, handle []byte) FileHandle { | ||
1687 | const hdrSize = unsafe.Sizeof(fileHandle{}) | ||
1688 | buf := make([]byte, hdrSize+uintptr(len(handle))) | ||
1689 | copy(buf[hdrSize:], handle) | ||
1690 | fh := (*fileHandle)(unsafe.Pointer(&buf[0])) | ||
1691 | fh.Type = handleType | ||
1692 | fh.Bytes = uint32(len(handle)) | ||
1693 | return FileHandle{fh} | ||
1694 | } | ||
1695 | |||
1696 | func (fh *FileHandle) Size() int { return int(fh.fileHandle.Bytes) } | ||
1697 | func (fh *FileHandle) Type() int32 { return fh.fileHandle.Type } | ||
1698 | func (fh *FileHandle) Bytes() []byte { | ||
1699 | n := fh.Size() | ||
1700 | if n == 0 { | ||
1701 | return nil | ||
1702 | } | ||
1703 | return (*[1 << 30]byte)(unsafe.Pointer(uintptr(unsafe.Pointer(&fh.fileHandle.Type)) + 4))[:n:n] | ||
1704 | } | ||
1705 | |||
1706 | // NameToHandleAt wraps the name_to_handle_at system call; it obtains | ||
1707 | // a handle for a path name. | ||
1708 | func NameToHandleAt(dirfd int, path string, flags int) (handle FileHandle, mountID int, err error) { | ||
1709 | var mid _C_int | ||
1710 | // Try first with a small buffer, assuming the handle will | ||
1711 | // only be 32 bytes. | ||
1712 | size := uint32(32 + unsafe.Sizeof(fileHandle{})) | ||
1713 | didResize := false | ||
1714 | for { | ||
1715 | buf := make([]byte, size) | ||
1716 | fh := (*fileHandle)(unsafe.Pointer(&buf[0])) | ||
1717 | fh.Bytes = size - uint32(unsafe.Sizeof(fileHandle{})) | ||
1718 | err = nameToHandleAt(dirfd, path, fh, &mid, flags) | ||
1719 | if err == EOVERFLOW { | ||
1720 | if didResize { | ||
1721 | // We shouldn't need to resize more than once | ||
1722 | return | ||
1723 | } | ||
1724 | didResize = true | ||
1725 | size = fh.Bytes + uint32(unsafe.Sizeof(fileHandle{})) | ||
1726 | continue | ||
1727 | } | ||
1728 | if err != nil { | ||
1729 | return | ||
1730 | } | ||
1731 | return FileHandle{fh}, int(mid), nil | ||
1732 | } | ||
1733 | } | ||
1734 | |||
1735 | // OpenByHandleAt wraps the open_by_handle_at system call; it opens a | ||
1736 | // file via a handle as previously returned by NameToHandleAt. | ||
1737 | func OpenByHandleAt(mountFD int, handle FileHandle, flags int) (fd int, err error) { | ||
1738 | return openByHandleAt(mountFD, handle.fileHandle, flags) | ||
1739 | } | ||
1740 | |||
1521 | /* | 1741 | /* |
1522 | * Unimplemented | 1742 | * Unimplemented |
1523 | */ | 1743 | */ |
@@ -1606,7 +1826,6 @@ func Faccessat(dirfd int, path string, mode uint32, flags int) (err error) { | |||
1606 | // Shmdt | 1826 | // Shmdt |
1607 | // Shmget | 1827 | // Shmget |
1608 | // Sigaltstack | 1828 | // Sigaltstack |
1609 | // Signalfd | ||
1610 | // Swapoff | 1829 | // Swapoff |
1611 | // Swapon | 1830 | // Swapon |
1612 | // Sysfs | 1831 | // Sysfs |