Migrate Sirupsen to sirupsen.
This commit is contained in:
parent
c134dcd6fe
commit
fb4ba7af2b
684 changed files with 92394 additions and 33943 deletions
522
vendor/golang.org/x/sys/unix/syscall_linux.go
generated
vendored
522
vendor/golang.org/x/sys/unix/syscall_linux.go
generated
vendored
|
@ -16,6 +16,13 @@ import (
|
|||
"unsafe"
|
||||
)
|
||||
|
||||
// SyscallNoError may be used instead of Syscall for syscalls that don't fail.
|
||||
func SyscallNoError(trap, a1, a2, a3 uintptr) (r1, r2 uintptr)
|
||||
|
||||
// RawSyscallNoError may be used instead of RawSyscall for syscalls that don't
|
||||
// fail.
|
||||
func RawSyscallNoError(trap, a1, a2, a3 uintptr) (r1, r2 uintptr)
|
||||
|
||||
/*
|
||||
* Wrapped
|
||||
*/
|
||||
|
@ -36,6 +43,59 @@ func Creat(path string, mode uint32) (fd int, err error) {
|
|||
return Open(path, O_CREAT|O_WRONLY|O_TRUNC, mode)
|
||||
}
|
||||
|
||||
//sys fchmodat(dirfd int, path string, mode uint32) (err error)
|
||||
|
||||
func Fchmodat(dirfd int, path string, mode uint32, flags int) (err error) {
|
||||
// Linux fchmodat doesn't support the flags parameter. Mimick glibc's behavior
|
||||
// and check the flags. Otherwise the mode would be applied to the symlink
|
||||
// destination which is not what the user expects.
|
||||
if flags&^AT_SYMLINK_NOFOLLOW != 0 {
|
||||
return EINVAL
|
||||
} else if flags&AT_SYMLINK_NOFOLLOW != 0 {
|
||||
return EOPNOTSUPP
|
||||
}
|
||||
return fchmodat(dirfd, path, mode)
|
||||
}
|
||||
|
||||
//sys ioctl(fd int, req uint, arg uintptr) (err error)
|
||||
|
||||
// ioctl itself should not be exposed directly, but additional get/set
|
||||
// functions for specific types are permissible.
|
||||
|
||||
// IoctlSetInt performs an ioctl operation which sets an integer value
|
||||
// on fd, using the specified request number.
|
||||
func IoctlSetInt(fd int, req uint, value int) error {
|
||||
return ioctl(fd, req, uintptr(value))
|
||||
}
|
||||
|
||||
func IoctlSetWinsize(fd int, req uint, value *Winsize) error {
|
||||
return ioctl(fd, req, uintptr(unsafe.Pointer(value)))
|
||||
}
|
||||
|
||||
func IoctlSetTermios(fd int, req uint, value *Termios) error {
|
||||
return ioctl(fd, req, uintptr(unsafe.Pointer(value)))
|
||||
}
|
||||
|
||||
// IoctlGetInt performs an ioctl operation which gets an integer value
|
||||
// from fd, using the specified request number.
|
||||
func IoctlGetInt(fd int, req uint) (int, error) {
|
||||
var value int
|
||||
err := ioctl(fd, req, uintptr(unsafe.Pointer(&value)))
|
||||
return value, err
|
||||
}
|
||||
|
||||
func IoctlGetWinsize(fd int, req uint) (*Winsize, error) {
|
||||
var value Winsize
|
||||
err := ioctl(fd, req, uintptr(unsafe.Pointer(&value)))
|
||||
return &value, err
|
||||
}
|
||||
|
||||
func IoctlGetTermios(fd int, req uint) (*Termios, error) {
|
||||
var value Termios
|
||||
err := ioctl(fd, req, uintptr(unsafe.Pointer(&value)))
|
||||
return &value, err
|
||||
}
|
||||
|
||||
//sys Linkat(olddirfd int, oldpath string, newdirfd int, newpath string, flags int) (err error)
|
||||
|
||||
func Link(oldpath string, newpath string) (err error) {
|
||||
|
@ -69,10 +129,10 @@ func Ppoll(fds []PollFd, timeout *Timespec, sigmask *Sigset_t) (n int, err error
|
|||
return ppoll(&fds[0], len(fds), timeout, sigmask)
|
||||
}
|
||||
|
||||
//sys readlinkat(dirfd int, path string, buf []byte) (n int, err error)
|
||||
//sys Readlinkat(dirfd int, path string, buf []byte) (n int, err error)
|
||||
|
||||
func Readlink(path string, buf []byte) (n int, err error) {
|
||||
return readlinkat(AT_FDCWD, path, buf)
|
||||
return Readlinkat(AT_FDCWD, path, buf)
|
||||
}
|
||||
|
||||
func Rename(oldpath string, newpath string) (err error) {
|
||||
|
@ -80,24 +140,20 @@ func Rename(oldpath string, newpath string) (err error) {
|
|||
}
|
||||
|
||||
func Rmdir(path string) error {
|
||||
return unlinkat(AT_FDCWD, path, AT_REMOVEDIR)
|
||||
return Unlinkat(AT_FDCWD, path, AT_REMOVEDIR)
|
||||
}
|
||||
|
||||
//sys symlinkat(oldpath string, newdirfd int, newpath string) (err error)
|
||||
//sys Symlinkat(oldpath string, newdirfd int, newpath string) (err error)
|
||||
|
||||
func Symlink(oldpath string, newpath string) (err error) {
|
||||
return symlinkat(oldpath, AT_FDCWD, newpath)
|
||||
return Symlinkat(oldpath, AT_FDCWD, newpath)
|
||||
}
|
||||
|
||||
func Unlink(path string) error {
|
||||
return unlinkat(AT_FDCWD, path, 0)
|
||||
return Unlinkat(AT_FDCWD, path, 0)
|
||||
}
|
||||
|
||||
//sys unlinkat(dirfd int, path string, flags int) (err error)
|
||||
|
||||
func Unlinkat(dirfd int, path string, flags int) error {
|
||||
return unlinkat(dirfd, path, flags)
|
||||
}
|
||||
//sys Unlinkat(dirfd int, path string, flags int) (err error)
|
||||
|
||||
//sys utimes(path string, times *[2]Timeval) (err error)
|
||||
|
||||
|
@ -143,8 +199,7 @@ func UtimesNano(path string, ts []Timespec) error {
|
|||
// in 2.6.22, Released, 8 July 2007) then fall back to utimes
|
||||
var tv [2]Timeval
|
||||
for i := 0; i < 2; i++ {
|
||||
tv[i].Sec = ts[i].Sec
|
||||
tv[i].Usec = ts[i].Nsec / 1000
|
||||
tv[i] = NsecToTimeval(TimespecToNsec(ts[i]))
|
||||
}
|
||||
return utimes(path, (*[2]Timeval)(unsafe.Pointer(&tv[0])))
|
||||
}
|
||||
|
@ -207,7 +262,7 @@ func Getgroups() (gids []int, err error) {
|
|||
return nil, nil
|
||||
}
|
||||
|
||||
// Sanity check group count. Max is 1<<16 on Linux.
|
||||
// Sanity check group count. Max is 1<<16 on Linux.
|
||||
if n < 0 || n > 1<<20 {
|
||||
return nil, EINVAL
|
||||
}
|
||||
|
@ -242,8 +297,8 @@ type WaitStatus uint32
|
|||
// 0x7F (stopped), or a signal number that caused an exit.
|
||||
// The 0x80 bit is whether there was a core dump.
|
||||
// An extra number (exit code, signal causing a stop)
|
||||
// is in the high bits. At least that's the idea.
|
||||
// There are various irregularities. For example, the
|
||||
// is in the high bits. At least that's the idea.
|
||||
// There are various irregularities. For example, the
|
||||
// "continued" status is 0xFFFF, distinguishing itself
|
||||
// from stopped via the core dump bit.
|
||||
|
||||
|
@ -304,10 +359,14 @@ func Wait4(pid int, wstatus *WaitStatus, options int, rusage *Rusage) (wpid int,
|
|||
return
|
||||
}
|
||||
|
||||
func Mkfifo(path string, mode uint32) (err error) {
|
||||
func Mkfifo(path string, mode uint32) error {
|
||||
return Mknod(path, mode|S_IFIFO, 0)
|
||||
}
|
||||
|
||||
func Mkfifoat(dirfd int, path string, mode uint32) error {
|
||||
return Mknodat(dirfd, path, mode|S_IFIFO, 0)
|
||||
}
|
||||
|
||||
func (sa *SockaddrInet4) sockaddr() (unsafe.Pointer, _Socklen, error) {
|
||||
if sa.Port < 0 || sa.Port > 0xFFFF {
|
||||
return nil, 0, EINVAL
|
||||
|
@ -416,6 +475,168 @@ func (sa *SockaddrHCI) sockaddr() (unsafe.Pointer, _Socklen, error) {
|
|||
return unsafe.Pointer(&sa.raw), SizeofSockaddrHCI, nil
|
||||
}
|
||||
|
||||
// SockaddrCAN implements the Sockaddr interface for AF_CAN type sockets.
|
||||
// The RxID and TxID fields are used for transport protocol addressing in
|
||||
// (CAN_TP16, CAN_TP20, CAN_MCNET, and CAN_ISOTP), they can be left with
|
||||
// zero values for CAN_RAW and CAN_BCM sockets as they have no meaning.
|
||||
//
|
||||
// The SockaddrCAN struct must be bound to the socket file descriptor
|
||||
// using Bind before the CAN socket can be used.
|
||||
//
|
||||
// // Read one raw CAN frame
|
||||
// fd, _ := Socket(AF_CAN, SOCK_RAW, CAN_RAW)
|
||||
// addr := &SockaddrCAN{Ifindex: index}
|
||||
// Bind(fd, addr)
|
||||
// frame := make([]byte, 16)
|
||||
// Read(fd, frame)
|
||||
//
|
||||
// The full SocketCAN documentation can be found in the linux kernel
|
||||
// archives at: https://www.kernel.org/doc/Documentation/networking/can.txt
|
||||
type SockaddrCAN struct {
|
||||
Ifindex int
|
||||
RxID uint32
|
||||
TxID uint32
|
||||
raw RawSockaddrCAN
|
||||
}
|
||||
|
||||
func (sa *SockaddrCAN) sockaddr() (unsafe.Pointer, _Socklen, error) {
|
||||
if sa.Ifindex < 0 || sa.Ifindex > 0x7fffffff {
|
||||
return nil, 0, EINVAL
|
||||
}
|
||||
sa.raw.Family = AF_CAN
|
||||
sa.raw.Ifindex = int32(sa.Ifindex)
|
||||
rx := (*[4]byte)(unsafe.Pointer(&sa.RxID))
|
||||
for i := 0; i < 4; i++ {
|
||||
sa.raw.Addr[i] = rx[i]
|
||||
}
|
||||
tx := (*[4]byte)(unsafe.Pointer(&sa.TxID))
|
||||
for i := 0; i < 4; i++ {
|
||||
sa.raw.Addr[i+4] = tx[i]
|
||||
}
|
||||
return unsafe.Pointer(&sa.raw), SizeofSockaddrCAN, nil
|
||||
}
|
||||
|
||||
// SockaddrALG implements the Sockaddr interface for AF_ALG type sockets.
|
||||
// SockaddrALG enables userspace access to the Linux kernel's cryptography
|
||||
// subsystem. The Type and Name fields specify which type of hash or cipher
|
||||
// should be used with a given socket.
|
||||
//
|
||||
// To create a file descriptor that provides access to a hash or cipher, both
|
||||
// Bind and Accept must be used. Once the setup process is complete, input
|
||||
// data can be written to the socket, processed by the kernel, and then read
|
||||
// back as hash output or ciphertext.
|
||||
//
|
||||
// Here is an example of using an AF_ALG socket with SHA1 hashing.
|
||||
// The initial socket setup process is as follows:
|
||||
//
|
||||
// // Open a socket to perform SHA1 hashing.
|
||||
// fd, _ := unix.Socket(unix.AF_ALG, unix.SOCK_SEQPACKET, 0)
|
||||
// addr := &unix.SockaddrALG{Type: "hash", Name: "sha1"}
|
||||
// unix.Bind(fd, addr)
|
||||
// // Note: unix.Accept does not work at this time; must invoke accept()
|
||||
// // manually using unix.Syscall.
|
||||
// hashfd, _, _ := unix.Syscall(unix.SYS_ACCEPT, uintptr(fd), 0, 0)
|
||||
//
|
||||
// Once a file descriptor has been returned from Accept, it may be used to
|
||||
// perform SHA1 hashing. The descriptor is not safe for concurrent use, but
|
||||
// may be re-used repeatedly with subsequent Write and Read operations.
|
||||
//
|
||||
// When hashing a small byte slice or string, a single Write and Read may
|
||||
// be used:
|
||||
//
|
||||
// // Assume hashfd is already configured using the setup process.
|
||||
// hash := os.NewFile(hashfd, "sha1")
|
||||
// // Hash an input string and read the results. Each Write discards
|
||||
// // previous hash state. Read always reads the current state.
|
||||
// b := make([]byte, 20)
|
||||
// for i := 0; i < 2; i++ {
|
||||
// io.WriteString(hash, "Hello, world.")
|
||||
// hash.Read(b)
|
||||
// fmt.Println(hex.EncodeToString(b))
|
||||
// }
|
||||
// // Output:
|
||||
// // 2ae01472317d1935a84797ec1983ae243fc6aa28
|
||||
// // 2ae01472317d1935a84797ec1983ae243fc6aa28
|
||||
//
|
||||
// For hashing larger byte slices, or byte streams such as those read from
|
||||
// a file or socket, use Sendto with MSG_MORE to instruct the kernel to update
|
||||
// the hash digest instead of creating a new one for a given chunk and finalizing it.
|
||||
//
|
||||
// // Assume hashfd and addr are already configured using the setup process.
|
||||
// hash := os.NewFile(hashfd, "sha1")
|
||||
// // Hash the contents of a file.
|
||||
// f, _ := os.Open("/tmp/linux-4.10-rc7.tar.xz")
|
||||
// b := make([]byte, 4096)
|
||||
// for {
|
||||
// n, err := f.Read(b)
|
||||
// if err == io.EOF {
|
||||
// break
|
||||
// }
|
||||
// unix.Sendto(hashfd, b[:n], unix.MSG_MORE, addr)
|
||||
// }
|
||||
// hash.Read(b)
|
||||
// fmt.Println(hex.EncodeToString(b))
|
||||
// // Output: 85cdcad0c06eef66f805ecce353bec9accbeecc5
|
||||
//
|
||||
// For more information, see: http://www.chronox.de/crypto-API/crypto/userspace-if.html.
|
||||
type SockaddrALG struct {
|
||||
Type string
|
||||
Name string
|
||||
Feature uint32
|
||||
Mask uint32
|
||||
raw RawSockaddrALG
|
||||
}
|
||||
|
||||
func (sa *SockaddrALG) sockaddr() (unsafe.Pointer, _Socklen, error) {
|
||||
// Leave room for NUL byte terminator.
|
||||
if len(sa.Type) > 13 {
|
||||
return nil, 0, EINVAL
|
||||
}
|
||||
if len(sa.Name) > 63 {
|
||||
return nil, 0, EINVAL
|
||||
}
|
||||
|
||||
sa.raw.Family = AF_ALG
|
||||
sa.raw.Feat = sa.Feature
|
||||
sa.raw.Mask = sa.Mask
|
||||
|
||||
typ, err := ByteSliceFromString(sa.Type)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
name, err := ByteSliceFromString(sa.Name)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
copy(sa.raw.Type[:], typ)
|
||||
copy(sa.raw.Name[:], name)
|
||||
|
||||
return unsafe.Pointer(&sa.raw), SizeofSockaddrALG, nil
|
||||
}
|
||||
|
||||
// SockaddrVM implements the Sockaddr interface for AF_VSOCK type sockets.
|
||||
// SockaddrVM provides access to Linux VM sockets: a mechanism that enables
|
||||
// bidirectional communication between a hypervisor and its guest virtual
|
||||
// machines.
|
||||
type SockaddrVM struct {
|
||||
// CID and Port specify a context ID and port address for a VM socket.
|
||||
// Guests have a unique CID, and hosts may have a well-known CID of:
|
||||
// - VMADDR_CID_HYPERVISOR: refers to the hypervisor process.
|
||||
// - VMADDR_CID_HOST: refers to other processes on the host.
|
||||
CID uint32
|
||||
Port uint32
|
||||
raw RawSockaddrVM
|
||||
}
|
||||
|
||||
func (sa *SockaddrVM) sockaddr() (unsafe.Pointer, _Socklen, error) {
|
||||
sa.raw.Family = AF_VSOCK
|
||||
sa.raw.Port = sa.Port
|
||||
sa.raw.Cid = sa.CID
|
||||
|
||||
return unsafe.Pointer(&sa.raw), SizeofSockaddrVM, nil
|
||||
}
|
||||
|
||||
func anyToSockaddr(rsa *RawSockaddrAny) (Sockaddr, error) {
|
||||
switch rsa.Addr.Family {
|
||||
case AF_NETLINK:
|
||||
|
@ -485,6 +706,14 @@ func anyToSockaddr(rsa *RawSockaddrAny) (Sockaddr, error) {
|
|||
sa.Addr[i] = pp.Addr[i]
|
||||
}
|
||||
return sa, nil
|
||||
|
||||
case AF_VSOCK:
|
||||
pp := (*RawSockaddrVM)(unsafe.Pointer(rsa))
|
||||
sa := &SockaddrVM{
|
||||
CID: pp.Cid,
|
||||
Port: pp.Port,
|
||||
}
|
||||
return sa, nil
|
||||
}
|
||||
return nil, EAFNOSUPPORT
|
||||
}
|
||||
|
@ -579,10 +808,142 @@ func GetsockoptUcred(fd, level, opt int) (*Ucred, error) {
|
|||
return &value, err
|
||||
}
|
||||
|
||||
func GetsockoptTCPInfo(fd, level, opt int) (*TCPInfo, error) {
|
||||
var value TCPInfo
|
||||
vallen := _Socklen(SizeofTCPInfo)
|
||||
err := getsockopt(fd, level, opt, unsafe.Pointer(&value), &vallen)
|
||||
return &value, err
|
||||
}
|
||||
|
||||
// GetsockoptString returns the string value of the socket option opt for the
|
||||
// socket associated with fd at the given socket level.
|
||||
func GetsockoptString(fd, level, opt int) (string, error) {
|
||||
buf := make([]byte, 256)
|
||||
vallen := _Socklen(len(buf))
|
||||
err := getsockopt(fd, level, opt, unsafe.Pointer(&buf[0]), &vallen)
|
||||
if err != nil {
|
||||
if err == ERANGE {
|
||||
buf = make([]byte, vallen)
|
||||
err = getsockopt(fd, level, opt, unsafe.Pointer(&buf[0]), &vallen)
|
||||
}
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
return string(buf[:vallen-1]), nil
|
||||
}
|
||||
|
||||
func SetsockoptIPMreqn(fd, level, opt int, mreq *IPMreqn) (err error) {
|
||||
return setsockopt(fd, level, opt, unsafe.Pointer(mreq), unsafe.Sizeof(*mreq))
|
||||
}
|
||||
|
||||
// Keyctl Commands (http://man7.org/linux/man-pages/man2/keyctl.2.html)
|
||||
|
||||
// KeyctlInt calls keyctl commands in which each argument is an int.
|
||||
// These commands are KEYCTL_REVOKE, KEYCTL_CHOWN, KEYCTL_CLEAR, KEYCTL_LINK,
|
||||
// KEYCTL_UNLINK, KEYCTL_NEGATE, KEYCTL_SET_REQKEY_KEYRING, KEYCTL_SET_TIMEOUT,
|
||||
// KEYCTL_ASSUME_AUTHORITY, KEYCTL_SESSION_TO_PARENT, KEYCTL_REJECT,
|
||||
// KEYCTL_INVALIDATE, and KEYCTL_GET_PERSISTENT.
|
||||
//sys KeyctlInt(cmd int, arg2 int, arg3 int, arg4 int, arg5 int) (ret int, err error) = SYS_KEYCTL
|
||||
|
||||
// KeyctlBuffer calls keyctl commands in which the third and fourth
|
||||
// arguments are a buffer and its length, respectively.
|
||||
// These commands are KEYCTL_UPDATE, KEYCTL_READ, and KEYCTL_INSTANTIATE.
|
||||
//sys KeyctlBuffer(cmd int, arg2 int, buf []byte, arg5 int) (ret int, err error) = SYS_KEYCTL
|
||||
|
||||
// KeyctlString calls keyctl commands which return a string.
|
||||
// These commands are KEYCTL_DESCRIBE and KEYCTL_GET_SECURITY.
|
||||
func KeyctlString(cmd int, id int) (string, error) {
|
||||
// We must loop as the string data may change in between the syscalls.
|
||||
// We could allocate a large buffer here to reduce the chance that the
|
||||
// syscall needs to be called twice; however, this is unnecessary as
|
||||
// the performance loss is negligible.
|
||||
var buffer []byte
|
||||
for {
|
||||
// Try to fill the buffer with data
|
||||
length, err := KeyctlBuffer(cmd, id, buffer, 0)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// Check if the data was written
|
||||
if length <= len(buffer) {
|
||||
// Exclude the null terminator
|
||||
return string(buffer[:length-1]), nil
|
||||
}
|
||||
|
||||
// Make a bigger buffer if needed
|
||||
buffer = make([]byte, length)
|
||||
}
|
||||
}
|
||||
|
||||
// Keyctl commands with special signatures.
|
||||
|
||||
// KeyctlGetKeyringID implements the KEYCTL_GET_KEYRING_ID command.
|
||||
// See the full documentation at:
|
||||
// http://man7.org/linux/man-pages/man3/keyctl_get_keyring_ID.3.html
|
||||
func KeyctlGetKeyringID(id int, create bool) (ringid int, err error) {
|
||||
createInt := 0
|
||||
if create {
|
||||
createInt = 1
|
||||
}
|
||||
return KeyctlInt(KEYCTL_GET_KEYRING_ID, id, createInt, 0, 0)
|
||||
}
|
||||
|
||||
// KeyctlSetperm implements the KEYCTL_SETPERM command. The perm value is the
|
||||
// key handle permission mask as described in the "keyctl setperm" section of
|
||||
// http://man7.org/linux/man-pages/man1/keyctl.1.html.
|
||||
// See the full documentation at:
|
||||
// http://man7.org/linux/man-pages/man3/keyctl_setperm.3.html
|
||||
func KeyctlSetperm(id int, perm uint32) error {
|
||||
_, err := KeyctlInt(KEYCTL_SETPERM, id, int(perm), 0, 0)
|
||||
return err
|
||||
}
|
||||
|
||||
//sys keyctlJoin(cmd int, arg2 string) (ret int, err error) = SYS_KEYCTL
|
||||
|
||||
// KeyctlJoinSessionKeyring implements the KEYCTL_JOIN_SESSION_KEYRING command.
|
||||
// See the full documentation at:
|
||||
// http://man7.org/linux/man-pages/man3/keyctl_join_session_keyring.3.html
|
||||
func KeyctlJoinSessionKeyring(name string) (ringid int, err error) {
|
||||
return keyctlJoin(KEYCTL_JOIN_SESSION_KEYRING, name)
|
||||
}
|
||||
|
||||
//sys keyctlSearch(cmd int, arg2 int, arg3 string, arg4 string, arg5 int) (ret int, err error) = SYS_KEYCTL
|
||||
|
||||
// KeyctlSearch implements the KEYCTL_SEARCH command.
|
||||
// See the full documentation at:
|
||||
// http://man7.org/linux/man-pages/man3/keyctl_search.3.html
|
||||
func KeyctlSearch(ringid int, keyType, description string, destRingid int) (id int, err error) {
|
||||
return keyctlSearch(KEYCTL_SEARCH, ringid, keyType, description, destRingid)
|
||||
}
|
||||
|
||||
//sys keyctlIOV(cmd int, arg2 int, payload []Iovec, arg5 int) (err error) = SYS_KEYCTL
|
||||
|
||||
// KeyctlInstantiateIOV implements the KEYCTL_INSTANTIATE_IOV command. This
|
||||
// command is similar to KEYCTL_INSTANTIATE, except that the payload is a slice
|
||||
// of Iovec (each of which represents a buffer) instead of a single buffer.
|
||||
// See the full documentation at:
|
||||
// http://man7.org/linux/man-pages/man3/keyctl_instantiate_iov.3.html
|
||||
func KeyctlInstantiateIOV(id int, payload []Iovec, ringid int) error {
|
||||
return keyctlIOV(KEYCTL_INSTANTIATE_IOV, id, payload, ringid)
|
||||
}
|
||||
|
||||
//sys keyctlDH(cmd int, arg2 *KeyctlDHParams, buf []byte) (ret int, err error) = SYS_KEYCTL
|
||||
|
||||
// KeyctlDHCompute implements the KEYCTL_DH_COMPUTE command. This command
|
||||
// computes a Diffie-Hellman shared secret based on the provide params. The
|
||||
// secret is written to the provided buffer and the returned size is the number
|
||||
// of bytes written (returning an error if there is insufficient space in the
|
||||
// buffer). If a nil buffer is passed in, this function returns the minimum
|
||||
// buffer length needed to store the appropriate data. Note that this differs
|
||||
// from KEYCTL_READ's behavior which always returns the requested payload size.
|
||||
// See the full documentation at:
|
||||
// http://man7.org/linux/man-pages/man3/keyctl_dh_compute.3.html
|
||||
func KeyctlDHCompute(params *KeyctlDHParams, buffer []byte) (size int, err error) {
|
||||
return keyctlDH(KEYCTL_DH_COMPUTE, params, buffer)
|
||||
}
|
||||
|
||||
func Recvmsg(fd int, p, oob []byte, flags int) (n, oobn int, recvflags int, from Sockaddr, err error) {
|
||||
var msg Msghdr
|
||||
var rsa RawSockaddrAny
|
||||
|
@ -590,17 +951,22 @@ func Recvmsg(fd int, p, oob []byte, flags int) (n, oobn int, recvflags int, from
|
|||
msg.Namelen = uint32(SizeofSockaddrAny)
|
||||
var iov Iovec
|
||||
if len(p) > 0 {
|
||||
iov.Base = (*byte)(unsafe.Pointer(&p[0]))
|
||||
iov.Base = &p[0]
|
||||
iov.SetLen(len(p))
|
||||
}
|
||||
var dummy byte
|
||||
if len(oob) > 0 {
|
||||
var sockType int
|
||||
sockType, err = GetsockoptInt(fd, SOL_SOCKET, SO_TYPE)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
// receive at least one normal byte
|
||||
if len(p) == 0 {
|
||||
if sockType != SOCK_DGRAM && len(p) == 0 {
|
||||
iov.Base = &dummy
|
||||
iov.SetLen(1)
|
||||
}
|
||||
msg.Control = (*byte)(unsafe.Pointer(&oob[0]))
|
||||
msg.Control = &oob[0]
|
||||
msg.SetControllen(len(oob))
|
||||
}
|
||||
msg.Iov = &iov
|
||||
|
@ -633,21 +999,26 @@ func SendmsgN(fd int, p, oob []byte, to Sockaddr, flags int) (n int, err error)
|
|||
}
|
||||
}
|
||||
var msg Msghdr
|
||||
msg.Name = (*byte)(unsafe.Pointer(ptr))
|
||||
msg.Name = (*byte)(ptr)
|
||||
msg.Namelen = uint32(salen)
|
||||
var iov Iovec
|
||||
if len(p) > 0 {
|
||||
iov.Base = (*byte)(unsafe.Pointer(&p[0]))
|
||||
iov.Base = &p[0]
|
||||
iov.SetLen(len(p))
|
||||
}
|
||||
var dummy byte
|
||||
if len(oob) > 0 {
|
||||
var sockType int
|
||||
sockType, err = GetsockoptInt(fd, SOL_SOCKET, SO_TYPE)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
// send at least one normal byte
|
||||
if len(p) == 0 {
|
||||
if sockType != SOCK_DGRAM && len(p) == 0 {
|
||||
iov.Base = &dummy
|
||||
iov.SetLen(1)
|
||||
}
|
||||
msg.Control = (*byte)(unsafe.Pointer(&oob[0]))
|
||||
msg.Control = &oob[0]
|
||||
msg.SetControllen(len(oob))
|
||||
}
|
||||
msg.Iov = &iov
|
||||
|
@ -677,7 +1048,7 @@ func ptracePeek(req int, pid int, addr uintptr, out []byte) (count int, err erro
|
|||
|
||||
var buf [sizeofPtr]byte
|
||||
|
||||
// Leading edge. PEEKTEXT/PEEKDATA don't require aligned
|
||||
// Leading edge. PEEKTEXT/PEEKDATA don't require aligned
|
||||
// access (PEEKUSER warns that it might), but if we don't
|
||||
// align our reads, we might straddle an unmapped page
|
||||
// boundary and not get the bytes leading up to the page
|
||||
|
@ -716,6 +1087,10 @@ func PtracePeekData(pid int, addr uintptr, out []byte) (count int, err error) {
|
|||
return ptracePeek(PTRACE_PEEKDATA, pid, addr, out)
|
||||
}
|
||||
|
||||
func PtracePeekUser(pid int, addr uintptr, out []byte) (count int, err error) {
|
||||
return ptracePeek(PTRACE_PEEKUSR, pid, addr, out)
|
||||
}
|
||||
|
||||
func ptracePoke(pokeReq int, peekReq int, pid int, addr uintptr, data []byte) (count int, err error) {
|
||||
// As for ptracePeek, we need to align our accesses to deal
|
||||
// with the possibility of straddling an invalid page.
|
||||
|
@ -775,6 +1150,10 @@ func PtracePokeData(pid int, addr uintptr, data []byte) (count int, err error) {
|
|||
return ptracePoke(PTRACE_POKEDATA, PTRACE_PEEKDATA, pid, addr, data)
|
||||
}
|
||||
|
||||
func PtracePokeUser(pid int, addr uintptr, data []byte) (count int, err error) {
|
||||
return ptracePoke(PTRACE_POKEUSR, PTRACE_PEEKUSR, pid, addr, data)
|
||||
}
|
||||
|
||||
func PtraceGetRegs(pid int, regsout *PtraceRegs) (err error) {
|
||||
return ptrace(PTRACE_GETREGS, pid, 0, uintptr(unsafe.Pointer(regsout)))
|
||||
}
|
||||
|
@ -814,38 +1193,24 @@ func Reboot(cmd int) (err error) {
|
|||
return reboot(LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, cmd, "")
|
||||
}
|
||||
|
||||
func clen(n []byte) int {
|
||||
for i := 0; i < len(n); i++ {
|
||||
if n[i] == 0 {
|
||||
return i
|
||||
}
|
||||
}
|
||||
return len(n)
|
||||
}
|
||||
|
||||
func ReadDirent(fd int, buf []byte) (n int, err error) {
|
||||
return Getdents(fd, buf)
|
||||
}
|
||||
|
||||
func ParseDirent(buf []byte, max int, names []string) (consumed int, count int, newnames []string) {
|
||||
origlen := len(buf)
|
||||
count = 0
|
||||
for max != 0 && len(buf) > 0 {
|
||||
dirent := (*Dirent)(unsafe.Pointer(&buf[0]))
|
||||
buf = buf[dirent.Reclen:]
|
||||
if dirent.Ino == 0 { // File absent in directory.
|
||||
continue
|
||||
}
|
||||
bytes := (*[10000]byte)(unsafe.Pointer(&dirent.Name[0]))
|
||||
var name = string(bytes[0:clen(bytes[:])])
|
||||
if name == "." || name == ".." { // Useless names
|
||||
continue
|
||||
}
|
||||
max--
|
||||
count++
|
||||
names = append(names, name)
|
||||
func direntIno(buf []byte) (uint64, bool) {
|
||||
return readInt(buf, unsafe.Offsetof(Dirent{}.Ino), unsafe.Sizeof(Dirent{}.Ino))
|
||||
}
|
||||
|
||||
func direntReclen(buf []byte) (uint64, bool) {
|
||||
return readInt(buf, unsafe.Offsetof(Dirent{}.Reclen), unsafe.Sizeof(Dirent{}.Reclen))
|
||||
}
|
||||
|
||||
func direntNamlen(buf []byte) (uint64, bool) {
|
||||
reclen, ok := direntReclen(buf)
|
||||
if !ok {
|
||||
return 0, false
|
||||
}
|
||||
return origlen - len(buf), count, names
|
||||
return reclen - uint64(unsafe.Offsetof(Dirent{}.Name)), true
|
||||
}
|
||||
|
||||
//sys mount(source string, target string, fstype string, flags uintptr, data *byte) (err error)
|
||||
|
@ -871,22 +1236,24 @@ func Mount(source string, target string, fstype string, flags uintptr, data stri
|
|||
* Direct access
|
||||
*/
|
||||
//sys Acct(path string) (err error)
|
||||
//sys AddKey(keyType string, description string, payload []byte, ringid int) (id int, err error)
|
||||
//sys Adjtimex(buf *Timex) (state int, err error)
|
||||
//sys Chdir(path string) (err error)
|
||||
//sys Chroot(path string) (err error)
|
||||
//sys ClockGettime(clockid int32, time *Timespec) (err error)
|
||||
//sys Close(fd int) (err error)
|
||||
//sys CopyFileRange(rfd int, roff *int64, wfd int, woff *int64, len int, flags int) (n int, err error)
|
||||
//sys Dup(oldfd int) (fd int, err error)
|
||||
//sys Dup3(oldfd int, newfd int, flags int) (err error)
|
||||
//sysnb EpollCreate(size int) (fd int, err error)
|
||||
//sysnb EpollCreate1(flag int) (fd int, err error)
|
||||
//sysnb EpollCtl(epfd int, op int, fd int, event *EpollEvent) (err error)
|
||||
//sys Eventfd(initval uint, flags int) (fd int, err error) = SYS_EVENTFD2
|
||||
//sys Exit(code int) = SYS_EXIT_GROUP
|
||||
//sys Faccessat(dirfd int, path string, mode uint32, flags int) (err error)
|
||||
//sys Fallocate(fd int, mode uint32, off int64, len int64) (err error)
|
||||
//sys Fchdir(fd int) (err error)
|
||||
//sys Fchmod(fd int, mode uint32) (err error)
|
||||
//sys Fchmodat(dirfd int, path string, mode uint32, flags int) (err error)
|
||||
//sys Fchownat(dirfd int, path string, uid int, gid int, flags int) (err error)
|
||||
//sys fcntl(fd int, cmd int, arg int) (val int, err error)
|
||||
//sys Fdatasync(fd int) (err error)
|
||||
|
@ -903,7 +1270,9 @@ func Getpgrp() (pid int) {
|
|||
//sysnb Getpid() (pid int)
|
||||
//sysnb Getppid() (ppid int)
|
||||
//sys Getpriority(which int, who int) (prio int, err error)
|
||||
//sys Getrandom(buf []byte, flags int) (n int, err error)
|
||||
//sysnb Getrusage(who int, rusage *Rusage) (err error)
|
||||
//sysnb Getsid(pid int) (sid int, err error)
|
||||
//sysnb Gettid() (tid int)
|
||||
//sys Getxattr(path string, attr string, dest []byte) (sz int, err error)
|
||||
//sys InotifyAddWatch(fd int, pathname string, mask uint32) (watchdesc int, err error)
|
||||
|
@ -911,16 +1280,22 @@ func Getpgrp() (pid int) {
|
|||
//sysnb InotifyRmWatch(fd int, watchdesc uint32) (success int, err error)
|
||||
//sysnb Kill(pid int, sig syscall.Signal) (err error)
|
||||
//sys Klogctl(typ int, buf []byte) (n int, err error) = SYS_SYSLOG
|
||||
//sys Lgetxattr(path string, attr string, dest []byte) (sz int, err error)
|
||||
//sys Listxattr(path string, dest []byte) (sz int, err error)
|
||||
//sys Llistxattr(path string, dest []byte) (sz int, err error)
|
||||
//sys Lremovexattr(path string, attr string) (err error)
|
||||
//sys Lsetxattr(path string, attr string, data []byte, flags int) (err error)
|
||||
//sys Mkdirat(dirfd int, path string, mode uint32) (err error)
|
||||
//sys Mknodat(dirfd int, path string, mode uint32, dev int) (err error)
|
||||
//sys Nanosleep(time *Timespec, leftover *Timespec) (err error)
|
||||
//sys PivotRoot(newroot string, putold string) (err error) = SYS_PIVOT_ROOT
|
||||
//sysnb prlimit(pid int, resource int, old *Rlimit, newlimit *Rlimit) (err error) = SYS_PRLIMIT64
|
||||
//sysnb prlimit(pid int, resource int, newlimit *Rlimit, old *Rlimit) (err error) = SYS_PRLIMIT64
|
||||
//sys Prctl(option int, arg2 uintptr, arg3 uintptr, arg4 uintptr, arg5 uintptr) (err error)
|
||||
//sys Pselect(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timespec, sigmask *Sigset_t) (n int, err error) = SYS_PSELECT6
|
||||
//sys read(fd int, p []byte) (n int, err error)
|
||||
//sys Removexattr(path string, attr string) (err error)
|
||||
//sys Renameat(olddirfd int, oldpath string, newdirfd int, newpath string) (err error)
|
||||
//sys RequestKey(keyType string, description string, callback string, destRingid int) (id int, err error)
|
||||
//sys Setdomainname(p []byte) (err error)
|
||||
//sys Sethostname(p []byte) (err error)
|
||||
//sysnb Setpgid(pid int, pgid int) (err error)
|
||||
|
@ -943,7 +1318,9 @@ func Setgid(uid int) (err error) {
|
|||
|
||||
//sys Setpriority(which int, who int, prio int) (err error)
|
||||
//sys Setxattr(path string, attr string, data []byte, flags int) (err error)
|
||||
//sys Statx(dirfd int, path string, flags int, mask int, stat *Statx_t) (err error)
|
||||
//sys Sync()
|
||||
//sys Syncfs(fd int) (err error)
|
||||
//sysnb Sysinfo(info *Sysinfo_t) (err error)
|
||||
//sys Tee(rfd int, wfd int, len int, flags int) (n int64, err error)
|
||||
//sysnb Tgkill(tgid int, tid int, sig syscall.Signal) (err error)
|
||||
|
@ -978,14 +1355,33 @@ func Munmap(b []byte) (err error) {
|
|||
//sys Madvise(b []byte, advice int) (err error)
|
||||
//sys Mprotect(b []byte, prot int) (err error)
|
||||
//sys Mlock(b []byte) (err error)
|
||||
//sys Munlock(b []byte) (err error)
|
||||
//sys Mlockall(flags int) (err error)
|
||||
//sys Msync(b []byte, flags int) (err error)
|
||||
//sys Munlock(b []byte) (err error)
|
||||
//sys Munlockall() (err error)
|
||||
|
||||
// Vmsplice splices user pages from a slice of Iovecs into a pipe specified by fd,
|
||||
// using the specified flags.
|
||||
func Vmsplice(fd int, iovs []Iovec, flags int) (int, error) {
|
||||
n, _, errno := Syscall6(
|
||||
SYS_VMSPLICE,
|
||||
uintptr(fd),
|
||||
uintptr(unsafe.Pointer(&iovs[0])),
|
||||
uintptr(len(iovs)),
|
||||
uintptr(flags),
|
||||
0,
|
||||
0,
|
||||
)
|
||||
if errno != 0 {
|
||||
return 0, syscall.Errno(errno)
|
||||
}
|
||||
|
||||
return int(n), nil
|
||||
}
|
||||
|
||||
/*
|
||||
* Unimplemented
|
||||
*/
|
||||
// AddKey
|
||||
// AfsSyscall
|
||||
// Alarm
|
||||
// ArchPrctl
|
||||
|
@ -1001,7 +1397,6 @@ func Munmap(b []byte) (err error) {
|
|||
// EpollCtlOld
|
||||
// EpollPwait
|
||||
// EpollWaitOld
|
||||
// Eventfd
|
||||
// Execve
|
||||
// Fgetxattr
|
||||
// Flistxattr
|
||||
|
@ -1020,23 +1415,16 @@ func Munmap(b []byte) (err error) {
|
|||
// IoGetevents
|
||||
// IoSetup
|
||||
// IoSubmit
|
||||
// Ioctl
|
||||
// IoprioGet
|
||||
// IoprioSet
|
||||
// KexecLoad
|
||||
// Keyctl
|
||||
// Lgetxattr
|
||||
// Llistxattr
|
||||
// LookupDcookie
|
||||
// Lremovexattr
|
||||
// Lsetxattr
|
||||
// Mbind
|
||||
// MigratePages
|
||||
// Mincore
|
||||
// ModifyLdt
|
||||
// Mount
|
||||
// MovePages
|
||||
// Mprotect
|
||||
// MqGetsetattr
|
||||
// MqNotify
|
||||
// MqOpen
|
||||
|
@ -1048,8 +1436,6 @@ func Munmap(b []byte) (err error) {
|
|||
// Msgget
|
||||
// Msgrcv
|
||||
// Msgsnd
|
||||
// Msync
|
||||
// Newfstatat
|
||||
// Nfsservctl
|
||||
// Personality
|
||||
// Pselect6
|
||||
|
@ -1060,7 +1446,6 @@ func Munmap(b []byte) (err error) {
|
|||
// Readahead
|
||||
// Readv
|
||||
// RemapFilePages
|
||||
// RequestKey
|
||||
// RestartSyscall
|
||||
// RtSigaction
|
||||
// RtSigpending
|
||||
|
@ -1071,11 +1456,9 @@ func Munmap(b []byte) (err error) {
|
|||
// RtSigtimedwait
|
||||
// SchedGetPriorityMax
|
||||
// SchedGetPriorityMin
|
||||
// SchedGetaffinity
|
||||
// SchedGetparam
|
||||
// SchedGetscheduler
|
||||
// SchedRrGetInterval
|
||||
// SchedSetaffinity
|
||||
// SchedSetparam
|
||||
// SchedYield
|
||||
// Security
|
||||
|
@ -1109,7 +1492,6 @@ func Munmap(b []byte) (err error) {
|
|||
// Utimensat
|
||||
// Vfork
|
||||
// Vhangup
|
||||
// Vmsplice
|
||||
// Vserver
|
||||
// Waitid
|
||||
// _Sysctl
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue