David K. Bainbridge | 215e024 | 2017-09-05 23:18:24 -0700 | [diff] [blame^] | 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 | // +build sparc64,linux |
| 6 | |
| 7 | package unix |
| 8 | |
| 9 | import ( |
| 10 | "sync/atomic" |
| 11 | "syscall" |
| 12 | ) |
| 13 | |
| 14 | //sys EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error) |
| 15 | //sys Dup2(oldfd int, newfd int) (err error) |
| 16 | //sys Fchown(fd int, uid int, gid int) (err error) |
| 17 | //sys Fstat(fd int, stat *Stat_t) (err error) |
| 18 | //sys Fstatfs(fd int, buf *Statfs_t) (err error) |
| 19 | //sys Ftruncate(fd int, length int64) (err error) |
| 20 | //sysnb Getegid() (egid int) |
| 21 | //sysnb Geteuid() (euid int) |
| 22 | //sysnb Getgid() (gid int) |
| 23 | //sysnb Getrlimit(resource int, rlim *Rlimit) (err error) |
| 24 | //sysnb Getuid() (uid int) |
| 25 | //sysnb InotifyInit() (fd int, err error) |
| 26 | //sys Lchown(path string, uid int, gid int) (err error) |
| 27 | //sys Listen(s int, n int) (err error) |
| 28 | //sys Lstat(path string, stat *Stat_t) (err error) |
| 29 | //sys Pause() (err error) |
| 30 | //sys Pread(fd int, p []byte, offset int64) (n int, err error) = SYS_PREAD64 |
| 31 | //sys Pwrite(fd int, p []byte, offset int64) (n int, err error) = SYS_PWRITE64 |
| 32 | //sys Seek(fd int, offset int64, whence int) (off int64, err error) = SYS_LSEEK |
| 33 | //sys Select(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (n int, err error) |
| 34 | //sys sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) |
| 35 | //sys Setfsgid(gid int) (err error) |
| 36 | //sys Setfsuid(uid int) (err error) |
| 37 | //sysnb Setregid(rgid int, egid int) (err error) |
| 38 | //sysnb Setresgid(rgid int, egid int, sgid int) (err error) |
| 39 | //sysnb Setresuid(ruid int, euid int, suid int) (err error) |
| 40 | //sysnb Setrlimit(resource int, rlim *Rlimit) (err error) |
| 41 | //sysnb Setreuid(ruid int, euid int) (err error) |
| 42 | //sys Shutdown(fd int, how int) (err error) |
| 43 | //sys Splice(rfd int, roff *int64, wfd int, woff *int64, len int, flags int) (n int64, err error) |
| 44 | //sys Stat(path string, stat *Stat_t) (err error) |
| 45 | //sys Statfs(path string, buf *Statfs_t) (err error) |
| 46 | //sys SyncFileRange(fd int, off int64, n int64, flags int) (err error) |
| 47 | //sys Truncate(path string, length int64) (err error) |
| 48 | //sys accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error) |
| 49 | //sys accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error) |
| 50 | //sys bind(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) |
| 51 | //sys connect(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) |
| 52 | //sysnb getgroups(n int, list *_Gid_t) (nn int, err error) |
| 53 | //sysnb setgroups(n int, list *_Gid_t) (err error) |
| 54 | //sys getsockopt(s int, level int, name int, val unsafe.Pointer, vallen *_Socklen) (err error) |
| 55 | //sys setsockopt(s int, level int, name int, val unsafe.Pointer, vallen uintptr) (err error) |
| 56 | //sysnb socket(domain int, typ int, proto int) (fd int, err error) |
| 57 | //sysnb socketpair(domain int, typ int, proto int, fd *[2]int32) (err error) |
| 58 | //sysnb getpeername(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error) |
| 59 | //sysnb getsockname(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error) |
| 60 | //sys recvfrom(fd int, p []byte, flags int, from *RawSockaddrAny, fromlen *_Socklen) (n int, err error) |
| 61 | //sys sendto(s int, buf []byte, flags int, to unsafe.Pointer, addrlen _Socklen) (err error) |
| 62 | //sys recvmsg(s int, msg *Msghdr, flags int) (n int, err error) |
| 63 | //sys sendmsg(s int, msg *Msghdr, flags int) (n int, err error) |
| 64 | //sys mmap(addr uintptr, length uintptr, prot int, flags int, fd int, offset int64) (xaddr uintptr, err error) |
| 65 | |
| 66 | func sysconf(name int) (n int64, err syscall.Errno) |
| 67 | |
| 68 | // pageSize caches the value of Getpagesize, since it can't change |
| 69 | // once the system is booted. |
| 70 | var pageSize int64 // accessed atomically |
| 71 | |
| 72 | func Getpagesize() int { |
| 73 | n := atomic.LoadInt64(&pageSize) |
| 74 | if n == 0 { |
| 75 | n, _ = sysconf(_SC_PAGESIZE) |
| 76 | atomic.StoreInt64(&pageSize, n) |
| 77 | } |
| 78 | return int(n) |
| 79 | } |
| 80 | |
| 81 | func Ioperm(from int, num int, on int) (err error) { |
| 82 | return ENOSYS |
| 83 | } |
| 84 | |
| 85 | func Iopl(level int) (err error) { |
| 86 | return ENOSYS |
| 87 | } |
| 88 | |
| 89 | //sysnb Gettimeofday(tv *Timeval) (err error) |
| 90 | |
| 91 | func Time(t *Time_t) (tt Time_t, err error) { |
| 92 | var tv Timeval |
| 93 | err = Gettimeofday(&tv) |
| 94 | if err != nil { |
| 95 | return 0, err |
| 96 | } |
| 97 | if t != nil { |
| 98 | *t = Time_t(tv.Sec) |
| 99 | } |
| 100 | return Time_t(tv.Sec), nil |
| 101 | } |
| 102 | |
| 103 | //sys Utime(path string, buf *Utimbuf) (err error) |
| 104 | |
| 105 | func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) } |
| 106 | |
| 107 | func NsecToTimespec(nsec int64) (ts Timespec) { |
| 108 | ts.Sec = nsec / 1e9 |
| 109 | ts.Nsec = nsec % 1e9 |
| 110 | return |
| 111 | } |
| 112 | |
| 113 | func NsecToTimeval(nsec int64) (tv Timeval) { |
| 114 | nsec += 999 // round up to microsecond |
| 115 | tv.Sec = nsec / 1e9 |
| 116 | tv.Usec = int32(nsec % 1e9 / 1e3) |
| 117 | return |
| 118 | } |
| 119 | |
| 120 | func (r *PtraceRegs) PC() uint64 { return r.Tpc } |
| 121 | |
| 122 | func (r *PtraceRegs) SetPC(pc uint64) { r.Tpc = pc } |
| 123 | |
| 124 | func (iov *Iovec) SetLen(length int) { |
| 125 | iov.Len = uint64(length) |
| 126 | } |
| 127 | |
| 128 | func (msghdr *Msghdr) SetControllen(length int) { |
| 129 | msghdr.Controllen = uint64(length) |
| 130 | } |
| 131 | |
| 132 | func (cmsg *Cmsghdr) SetLen(length int) { |
| 133 | cmsg.Len = uint64(length) |
| 134 | } |
| 135 | |
| 136 | //sysnb pipe(p *[2]_C_int) (err error) |
| 137 | |
| 138 | func Pipe(p []int) (err error) { |
| 139 | if len(p) != 2 { |
| 140 | return EINVAL |
| 141 | } |
| 142 | var pp [2]_C_int |
| 143 | err = pipe(&pp) |
| 144 | p[0] = int(pp[0]) |
| 145 | p[1] = int(pp[1]) |
| 146 | return |
| 147 | } |
| 148 | |
| 149 | //sysnb pipe2(p *[2]_C_int, flags int) (err error) |
| 150 | |
| 151 | func Pipe2(p []int, flags int) (err error) { |
| 152 | if len(p) != 2 { |
| 153 | return EINVAL |
| 154 | } |
| 155 | var pp [2]_C_int |
| 156 | err = pipe2(&pp, flags) |
| 157 | p[0] = int(pp[0]) |
| 158 | p[1] = int(pp[1]) |
| 159 | return |
| 160 | } |
| 161 | |
| 162 | //sys poll(fds *PollFd, nfds int, timeout int) (n int, err error) |
| 163 | |
| 164 | func Poll(fds []PollFd, timeout int) (n int, err error) { |
| 165 | if len(fds) == 0 { |
| 166 | return poll(nil, 0, timeout) |
| 167 | } |
| 168 | return poll(&fds[0], len(fds), timeout) |
| 169 | } |