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