github.com/Andyfoo/golang/x/sys@v0.0.0-20190901054642-57c1bf301704/unix/syscall_linux_mipsx.go (about) 1 // Copyright 2016 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 linux 6 // +build mips mipsle 7 8 package unix 9 10 import ( 11 "syscall" 12 "unsafe" 13 ) 14 15 func Syscall9(trap, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2 uintptr, err syscall.Errno) 16 17 //sys Dup2(oldfd int, newfd int) (err error) 18 //sysnb EpollCreate(size int) (fd int, err error) 19 //sys EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error) 20 //sys Fadvise(fd int, offset int64, length int64, advice int) (err error) = SYS_FADVISE64 21 //sys Fchown(fd int, uid int, gid int) (err error) 22 //sys Ftruncate(fd int, length int64) (err error) = SYS_FTRUNCATE64 23 //sysnb Getegid() (egid int) 24 //sysnb Geteuid() (euid int) 25 //sysnb Getgid() (gid int) 26 //sysnb Getuid() (uid int) 27 //sys Lchown(path string, uid int, gid int) (err error) 28 //sys Listen(s int, n int) (err error) 29 //sys Pread(fd int, p []byte, offset int64) (n int, err error) = SYS_PREAD64 30 //sys Pwrite(fd int, p []byte, offset int64) (n int, err error) = SYS_PWRITE64 31 //sys Renameat(olddirfd int, oldpath string, newdirfd int, newpath string) (err error) 32 //sys Select(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (n int, err error) = SYS__NEWSELECT 33 //sys sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) = SYS_SENDFILE64 34 //sys Setfsgid(gid int) (err error) 35 //sys Setfsuid(uid int) (err error) 36 //sysnb Setregid(rgid int, egid int) (err error) 37 //sysnb Setresgid(rgid int, egid int, sgid int) (err error) 38 //sysnb Setresuid(ruid int, euid int, suid int) (err error) 39 //sysnb Setreuid(ruid int, euid int) (err error) 40 //sys Shutdown(fd int, how int) (err error) 41 //sys Splice(rfd int, roff *int64, wfd int, woff *int64, len int, flags int) (n int, err error) 42 //sys SyncFileRange(fd int, off int64, n int64, flags int) (err error) 43 //sys Truncate(path string, length int64) (err error) = SYS_TRUNCATE64 44 //sys Ustat(dev int, ubuf *Ustat_t) (err error) 45 //sys accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error) 46 //sys accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error) 47 //sys bind(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) 48 //sys connect(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) 49 //sysnb getgroups(n int, list *_Gid_t) (nn int, err error) 50 //sysnb setgroups(n int, list *_Gid_t) (err error) 51 //sys getsockopt(s int, level int, name int, val unsafe.Pointer, vallen *_Socklen) (err error) 52 //sys setsockopt(s int, level int, name int, val unsafe.Pointer, vallen uintptr) (err error) 53 //sysnb socket(domain int, typ int, proto int) (fd int, err error) 54 //sysnb socketpair(domain int, typ int, proto int, fd *[2]int32) (err error) 55 //sysnb getpeername(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error) 56 //sysnb getsockname(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error) 57 //sys recvfrom(fd int, p []byte, flags int, from *RawSockaddrAny, fromlen *_Socklen) (n int, err error) 58 //sys sendto(s int, buf []byte, flags int, to unsafe.Pointer, addrlen _Socklen) (err error) 59 //sys recvmsg(s int, msg *Msghdr, flags int) (n int, err error) 60 //sys sendmsg(s int, msg *Msghdr, flags int) (n int, err error) 61 62 //sysnb InotifyInit() (fd int, err error) 63 //sys Ioperm(from int, num int, on int) (err error) 64 //sys Iopl(level int) (err error) 65 66 //sys futimesat(dirfd int, path string, times *[2]Timeval) (err error) 67 //sysnb Gettimeofday(tv *Timeval) (err error) 68 //sysnb Time(t *Time_t) (tt Time_t, err error) 69 //sys Utime(path string, buf *Utimbuf) (err error) 70 //sys utimes(path string, times *[2]Timeval) (err error) 71 72 //sys Lstat(path string, stat *Stat_t) (err error) = SYS_LSTAT64 73 //sys Fstat(fd int, stat *Stat_t) (err error) = SYS_FSTAT64 74 //sys Fstatat(dirfd int, path string, stat *Stat_t, flags int) (err error) = SYS_FSTATAT64 75 //sys Stat(path string, stat *Stat_t) (err error) = SYS_STAT64 76 77 //sys Pause() (err error) 78 79 func Fstatfs(fd int, buf *Statfs_t) (err error) { 80 _, _, e := Syscall(SYS_FSTATFS64, uintptr(fd), unsafe.Sizeof(*buf), uintptr(unsafe.Pointer(buf))) 81 if e != 0 { 82 err = errnoErr(e) 83 } 84 return 85 } 86 87 func Statfs(path string, buf *Statfs_t) (err error) { 88 p, err := BytePtrFromString(path) 89 if err != nil { 90 return err 91 } 92 _, _, e := Syscall(SYS_STATFS64, uintptr(unsafe.Pointer(p)), unsafe.Sizeof(*buf), uintptr(unsafe.Pointer(buf))) 93 if e != 0 { 94 err = errnoErr(e) 95 } 96 return 97 } 98 99 func Seek(fd int, offset int64, whence int) (off int64, err error) { 100 _, _, e := Syscall6(SYS__LLSEEK, uintptr(fd), uintptr(offset>>32), uintptr(offset), uintptr(unsafe.Pointer(&off)), uintptr(whence), 0) 101 if e != 0 { 102 err = errnoErr(e) 103 } 104 return 105 } 106 107 func setTimespec(sec, nsec int64) Timespec { 108 return Timespec{Sec: int32(sec), Nsec: int32(nsec)} 109 } 110 111 func setTimeval(sec, usec int64) Timeval { 112 return Timeval{Sec: int32(sec), Usec: int32(usec)} 113 } 114 115 //sysnb pipe2(p *[2]_C_int, flags int) (err error) 116 117 func Pipe2(p []int, flags int) (err error) { 118 if len(p) != 2 { 119 return EINVAL 120 } 121 var pp [2]_C_int 122 err = pipe2(&pp, flags) 123 p[0] = int(pp[0]) 124 p[1] = int(pp[1]) 125 return 126 } 127 128 //sysnb pipe() (p1 int, p2 int, err error) 129 130 func Pipe(p []int) (err error) { 131 if len(p) != 2 { 132 return EINVAL 133 } 134 p[0], p[1], err = pipe() 135 return 136 } 137 138 //sys mmap2(addr uintptr, length uintptr, prot int, flags int, fd int, pageOffset uintptr) (xaddr uintptr, err error) 139 140 func mmap(addr uintptr, length uintptr, prot int, flags int, fd int, offset int64) (xaddr uintptr, err error) { 141 page := uintptr(offset / 4096) 142 if offset != int64(page)*4096 { 143 return 0, EINVAL 144 } 145 return mmap2(addr, length, prot, flags, fd, page) 146 } 147 148 const rlimInf32 = ^uint32(0) 149 const rlimInf64 = ^uint64(0) 150 151 type rlimit32 struct { 152 Cur uint32 153 Max uint32 154 } 155 156 //sysnb getrlimit(resource int, rlim *rlimit32) (err error) = SYS_GETRLIMIT 157 158 func Getrlimit(resource int, rlim *Rlimit) (err error) { 159 err = prlimit(0, resource, nil, rlim) 160 if err != ENOSYS { 161 return err 162 } 163 164 rl := rlimit32{} 165 err = getrlimit(resource, &rl) 166 if err != nil { 167 return 168 } 169 170 if rl.Cur == rlimInf32 { 171 rlim.Cur = rlimInf64 172 } else { 173 rlim.Cur = uint64(rl.Cur) 174 } 175 176 if rl.Max == rlimInf32 { 177 rlim.Max = rlimInf64 178 } else { 179 rlim.Max = uint64(rl.Max) 180 } 181 return 182 } 183 184 //sysnb setrlimit(resource int, rlim *rlimit32) (err error) = SYS_SETRLIMIT 185 186 func Setrlimit(resource int, rlim *Rlimit) (err error) { 187 err = prlimit(0, resource, rlim, nil) 188 if err != ENOSYS { 189 return err 190 } 191 192 rl := rlimit32{} 193 if rlim.Cur == rlimInf64 { 194 rl.Cur = rlimInf32 195 } else if rlim.Cur < uint64(rlimInf32) { 196 rl.Cur = uint32(rlim.Cur) 197 } else { 198 return EINVAL 199 } 200 if rlim.Max == rlimInf64 { 201 rl.Max = rlimInf32 202 } else if rlim.Max < uint64(rlimInf32) { 203 rl.Max = uint32(rlim.Max) 204 } else { 205 return EINVAL 206 } 207 208 return setrlimit(resource, &rl) 209 } 210 211 func (r *PtraceRegs) PC() uint64 { return r.Epc } 212 213 func (r *PtraceRegs) SetPC(pc uint64) { r.Epc = pc } 214 215 func (iov *Iovec) SetLen(length int) { 216 iov.Len = uint32(length) 217 } 218 219 func (msghdr *Msghdr) SetControllen(length int) { 220 msghdr.Controllen = uint32(length) 221 } 222 223 func (cmsg *Cmsghdr) SetLen(length int) { 224 cmsg.Len = uint32(length) 225 } 226 227 //sys poll(fds *PollFd, nfds int, timeout int) (n int, err error) 228 229 func Poll(fds []PollFd, timeout int) (n int, err error) { 230 if len(fds) == 0 { 231 return poll(nil, 0, timeout) 232 } 233 return poll(&fds[0], len(fds), timeout) 234 }