Home | History | Annotate | Download | only in syscall
      1 // Copyright 2015 The Go Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style
      3 // license that can be found in the LICENSE file.
      4 
      5 package syscall
      6 
      7 const _SYS_dup = SYS_DUP3
      8 
      9 //sys	Fchown(fd int, uid int, gid int) (err error)
     10 //sys	Fstat(fd int, stat *Stat_t) (err error)
     11 //sys	Fstatat(fd int, path string, stat *Stat_t, flags int) (err error)
     12 //sys	Fstatfs(fd int, buf *Statfs_t) (err error)
     13 //sys	Ftruncate(fd int, length int64) (err error)
     14 //sysnb	Getegid() (egid int)
     15 //sysnb	Geteuid() (euid int)
     16 //sysnb	Getgid() (gid int)
     17 //sysnb	Getrlimit(resource int, rlim *Rlimit) (err error)
     18 //sysnb	Getuid() (uid int)
     19 //sys	Listen(s int, n int) (err error)
     20 //sys	Pread(fd int, p []byte, offset int64) (n int, err error) = SYS_PREAD64
     21 //sys	Pwrite(fd int, p []byte, offset int64) (n int, err error) = SYS_PWRITE64
     22 //sys	Seek(fd int, offset int64, whence int) (off int64, err error) = SYS_LSEEK
     23 //sys	Select(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (n int, err error) = SYS_PSELECT6
     24 //sys	sendfile(outfd int, infd int, offset *int64, count int) (written int, err error)
     25 //sys	Setfsgid(gid int) (err error)
     26 //sys	Setfsuid(uid int) (err error)
     27 //sysnb	Setregid(rgid int, egid int) (err error)
     28 //sysnb	Setresgid(rgid int, egid int, sgid int) (err error)
     29 //sysnb	Setresuid(ruid int, euid int, suid int) (err error)
     30 //sysnb	Setrlimit(resource int, rlim *Rlimit) (err error)
     31 //sysnb	Setreuid(ruid int, euid int) (err error)
     32 //sys	Shutdown(fd int, how int) (err error)
     33 //sys	Splice(rfd int, roff *int64, wfd int, woff *int64, len int, flags int) (n int64, err error)
     34 
     35 func Stat(path string, stat *Stat_t) (err error) {
     36 	return Fstatat(_AT_FDCWD, path, stat, 0)
     37 }
     38 
     39 func Lchown(path string, uid int, gid int) (err error) {
     40 	return Fchownat(_AT_FDCWD, path, uid, gid, _AT_SYMLINK_NOFOLLOW)
     41 }
     42 
     43 func Lstat(path string, stat *Stat_t) (err error) {
     44 	return Fstatat(_AT_FDCWD, path, stat, _AT_SYMLINK_NOFOLLOW)
     45 }
     46 
     47 //sys	Statfs(path string, buf *Statfs_t) (err error)
     48 //sys	SyncFileRange(fd int, off int64, n int64, flags int) (err error) = SYS_SYNC_FILE_RANGE2
     49 //sys	Truncate(path string, length int64) (err error)
     50 //sys	accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error)
     51 //sys	accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error)
     52 //sys	bind(s int, addr unsafe.Pointer, addrlen _Socklen) (err error)
     53 //sys	connect(s int, addr unsafe.Pointer, addrlen _Socklen) (err error)
     54 //sysnb	getgroups(n int, list *_Gid_t) (nn int, err error)
     55 //sysnb	setgroups(n int, list *_Gid_t) (err error)
     56 //sys	getsockopt(s int, level int, name int, val unsafe.Pointer, vallen *_Socklen) (err error)
     57 //sys	setsockopt(s int, level int, name int, val unsafe.Pointer, vallen uintptr) (err error)
     58 //sysnb	socket(domain int, typ int, proto int) (fd int, err error)
     59 //sysnb	socketpair(domain int, typ int, proto int, fd *[2]int32) (err error)
     60 //sysnb	getpeername(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error)
     61 //sysnb	getsockname(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error)
     62 //sys	recvfrom(fd int, p []byte, flags int, from *RawSockaddrAny, fromlen *_Socklen) (n int, err error)
     63 //sys	sendto(s int, buf []byte, flags int, to unsafe.Pointer, addrlen _Socklen) (err error)
     64 //sys	recvmsg(s int, msg *Msghdr, flags int) (n int, err error)
     65 //sys	sendmsg(s int, msg *Msghdr, flags int) (n int, err error)
     66 //sys	mmap(addr uintptr, length uintptr, prot int, flags int, fd int, offset int64) (xaddr uintptr, err error)
     67 
     68 func Getpagesize() int { return 65536 }
     69 
     70 //sysnb	Gettimeofday(tv *Timeval) (err error)
     71 //sysnb	Time(t *Time_t) (tt Time_t, err error)
     72 
     73 func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
     74 
     75 func NsecToTimespec(nsec int64) (ts Timespec) {
     76 	ts.Sec = nsec / 1e9
     77 	ts.Nsec = nsec % 1e9
     78 	return
     79 }
     80 
     81 func TimevalToNsec(tv Timeval) int64 { return int64(tv.Sec)*1e9 + int64(tv.Usec)*1e3 }
     82 
     83 func NsecToTimeval(nsec int64) (tv Timeval) {
     84 	nsec += 999 // round up to microsecond
     85 	tv.Sec = nsec / 1e9
     86 	tv.Usec = nsec % 1e9 / 1e3
     87 	return
     88 }
     89 
     90 func Pipe(p []int) (err error) {
     91 	if len(p) != 2 {
     92 		return EINVAL
     93 	}
     94 	var pp [2]_C_int
     95 	err = pipe2(&pp, 0)
     96 	p[0] = int(pp[0])
     97 	p[1] = int(pp[1])
     98 	return
     99 }
    100 
    101 //sysnb pipe2(p *[2]_C_int, flags int) (err error)
    102 
    103 func Pipe2(p []int, flags int) (err error) {
    104 	if len(p) != 2 {
    105 		return EINVAL
    106 	}
    107 	var pp [2]_C_int
    108 	err = pipe2(&pp, flags)
    109 	p[0] = int(pp[0])
    110 	p[1] = int(pp[1])
    111 	return
    112 }
    113 
    114 func (r *PtraceRegs) PC() uint64 { return r.Pc }
    115 
    116 func (r *PtraceRegs) SetPC(pc uint64) { r.Pc = pc }
    117 
    118 func (iov *Iovec) SetLen(length int) {
    119 	iov.Len = uint64(length)
    120 }
    121 
    122 func (msghdr *Msghdr) SetControllen(length int) {
    123 	msghdr.Controllen = uint64(length)
    124 }
    125 
    126 func (cmsg *Cmsghdr) SetLen(length int) {
    127 	cmsg.Len = uint64(length)
    128 }
    129 
    130 func InotifyInit() (fd int, err error) {
    131 	return InotifyInit1(0)
    132 }
    133 
    134 // TODO(dfc): constants that should be in zsysnum_linux_arm64.go, remove
    135 // these when the deprecated syscalls that the syscall package relies on
    136 // are removed.
    137 const (
    138 	SYS_GETPGRP      = 1060
    139 	SYS_UTIMES       = 1037
    140 	SYS_FUTIMESAT    = 1066
    141 	SYS_PAUSE        = 1061
    142 	SYS_USTAT        = 1070
    143 	SYS_UTIME        = 1063
    144 	SYS_LCHOWN       = 1032
    145 	SYS_TIME         = 1062
    146 	SYS_EPOLL_CREATE = 1042
    147 	SYS_EPOLL_WAIT   = 1069
    148 )
    149