Home | History | Annotate | Download | only in syscall
      1 // Copyright 2009 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_DUP2
      8 
      9 //sys	Dup2(oldfd int, newfd int) (err error)
     10 //sys	Fchown(fd int, uid int, gid int) (err error)
     11 //sys	Fstat(fd int, stat *Stat_t) (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 //sysnb	InotifyInit() (fd int, err error)
     20 //sys	Ioperm(from int, num int, on int) (err error)
     21 //sys	Iopl(level int) (err error)
     22 //sys	Lchown(path string, uid int, gid int) (err error)
     23 //sys	Listen(s int, n int) (err error)
     24 //sys	Lstat(path string, stat *Stat_t) (err error)
     25 //sys	Pread(fd int, p []byte, offset int64) (n int, err error) = SYS_PREAD64
     26 //sys	Pwrite(fd int, p []byte, offset int64) (n int, err error) = SYS_PWRITE64
     27 //sys	Seek(fd int, offset int64, whence int) (off int64, err error) = SYS_LSEEK
     28 //sys	Select(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (n int, err error)
     29 //sys	sendfile(outfd int, infd int, offset *int64, count int) (written int, err error)
     30 //sys	Setfsgid(gid int) (err error)
     31 //sys	Setfsuid(uid int) (err error)
     32 //sysnb	Setregid(rgid int, egid int) (err error)
     33 //sysnb	Setresgid(rgid int, egid int, sgid int) (err error)
     34 //sysnb	Setresuid(ruid int, euid int, suid int) (err error)
     35 //sysnb	Setrlimit(resource int, rlim *Rlimit) (err error)
     36 //sysnb	Setreuid(ruid int, euid int) (err error)
     37 //sys	Shutdown(fd int, how int) (err error)
     38 //sys	Splice(rfd int, roff *int64, wfd int, woff *int64, len int, flags int) (n int64, err error)
     39 //sys	Stat(path string, stat *Stat_t) (err error)
     40 //sys	Statfs(path string, buf *Statfs_t) (err error)
     41 //sys	SyncFileRange(fd int, off int64, n int64, flags int) (err error)
     42 //sys	Truncate(path string, length int64) (err error)
     43 //sys	accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error)
     44 //sys	accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error)
     45 //sys	bind(s int, addr unsafe.Pointer, addrlen _Socklen) (err error)
     46 //sys	connect(s int, addr unsafe.Pointer, addrlen _Socklen) (err error)
     47 //sysnb	getgroups(n int, list *_Gid_t) (nn int, err error)
     48 //sysnb	setgroups(n int, list *_Gid_t) (err error)
     49 //sys	getsockopt(s int, level int, name int, val unsafe.Pointer, vallen *_Socklen) (err error)
     50 //sys	setsockopt(s int, level int, name int, val unsafe.Pointer, vallen uintptr) (err error)
     51 //sysnb	socket(domain int, typ int, proto int) (fd int, err error)
     52 //sysnb	socketpair(domain int, typ int, proto int, fd *[2]int32) (err error)
     53 //sysnb	getpeername(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error)
     54 //sysnb	getsockname(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error)
     55 //sys	recvfrom(fd int, p []byte, flags int, from *RawSockaddrAny, fromlen *_Socklen) (n int, err error)
     56 //sys	sendto(s int, buf []byte, flags int, to unsafe.Pointer, addrlen _Socklen) (err error)
     57 //sys	recvmsg(s int, msg *Msghdr, flags int) (n int, err error)
     58 //sys	sendmsg(s int, msg *Msghdr, flags int) (n int, err error)
     59 //sys	mmap(addr uintptr, length uintptr, prot int, flags int, fd int, offset int64) (xaddr uintptr, err error)
     60 
     61 //go:noescape
     62 func gettimeofday(tv *Timeval) (err Errno)
     63 
     64 func Gettimeofday(tv *Timeval) (err error) {
     65 	errno := gettimeofday(tv)
     66 	if errno != 0 {
     67 		return errno
     68 	}
     69 	return nil
     70 }
     71 
     72 func Getpagesize() int { return 4096 }
     73 
     74 func Time(t *Time_t) (tt Time_t, err error) {
     75 	var tv Timeval
     76 	errno := gettimeofday(&tv)
     77 	if errno != 0 {
     78 		return 0, errno
     79 	}
     80 	if t != nil {
     81 		*t = Time_t(tv.Sec)
     82 	}
     83 	return Time_t(tv.Sec), nil
     84 }
     85 
     86 func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
     87 
     88 func NsecToTimespec(nsec int64) (ts Timespec) {
     89 	ts.Sec = nsec / 1e9
     90 	ts.Nsec = nsec % 1e9
     91 	return
     92 }
     93 
     94 func TimevalToNsec(tv Timeval) int64 { return int64(tv.Sec)*1e9 + int64(tv.Usec)*1e3 }
     95 
     96 func NsecToTimeval(nsec int64) (tv Timeval) {
     97 	nsec += 999 // round up to microsecond
     98 	tv.Sec = nsec / 1e9
     99 	tv.Usec = nsec % 1e9 / 1e3
    100 	return
    101 }
    102 
    103 //sysnb	pipe(p *[2]_C_int) (err error)
    104 
    105 func Pipe(p []int) (err error) {
    106 	if len(p) != 2 {
    107 		return EINVAL
    108 	}
    109 	var pp [2]_C_int
    110 	err = pipe(&pp)
    111 	p[0] = int(pp[0])
    112 	p[1] = int(pp[1])
    113 	return
    114 }
    115 
    116 //sysnb pipe2(p *[2]_C_int, flags int) (err error)
    117 
    118 func Pipe2(p []int, flags int) (err error) {
    119 	if len(p) != 2 {
    120 		return EINVAL
    121 	}
    122 	var pp [2]_C_int
    123 	err = pipe2(&pp, flags)
    124 	p[0] = int(pp[0])
    125 	p[1] = int(pp[1])
    126 	return
    127 }
    128 
    129 func (r *PtraceRegs) PC() uint64 { return r.Rip }
    130 
    131 func (r *PtraceRegs) SetPC(pc uint64) { r.Rip = pc }
    132 
    133 func (iov *Iovec) SetLen(length int) {
    134 	iov.Len = uint64(length)
    135 }
    136 
    137 func (msghdr *Msghdr) SetControllen(length int) {
    138 	msghdr.Controllen = uint64(length)
    139 }
    140 
    141 func (cmsg *Cmsghdr) SetLen(length int) {
    142 	cmsg.Len = uint64(length)
    143 }
    144