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