github.com/go-xe2/third@v1.0.3/golang.org/x/sys/unix/syscall_linux_arm.go (about) 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 arm,linux 6 7 package unix 8 9 import ( 10 "syscall" 11 "unsafe" 12 ) 13 14 func setTimespec(sec, nsec int64) Timespec { 15 return Timespec{Sec: int32(sec), Nsec: int32(nsec)} 16 } 17 18 func setTimeval(sec, usec int64) Timeval { 19 return Timeval{Sec: int32(sec), Usec: int32(usec)} 20 } 21 22 func Pipe(p []int) (err error) { 23 if len(p) != 2 { 24 return EINVAL 25 } 26 var pp [2]_C_int 27 err = pipe2(&pp, 0) 28 p[0] = int(pp[0]) 29 p[1] = int(pp[1]) 30 return 31 } 32 33 //sysnb pipe2(p *[2]_C_int, flags int) (err error) 34 35 func Pipe2(p []int, flags int) (err error) { 36 if len(p) != 2 { 37 return EINVAL 38 } 39 var pp [2]_C_int 40 err = pipe2(&pp, flags) 41 p[0] = int(pp[0]) 42 p[1] = int(pp[1]) 43 return 44 } 45 46 // Underlying system call writes to newoffset via pointer. 47 // Implemented in assembly to avoid allocation. 48 func seek(fd int, offset int64, whence int) (newoffset int64, err syscall.Errno) 49 50 func Seek(fd int, offset int64, whence int) (newoffset int64, err error) { 51 newoffset, errno := seek(fd, offset, whence) 52 if errno != 0 { 53 return 0, errno 54 } 55 return newoffset, nil 56 } 57 58 //sys accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error) 59 //sys accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error) 60 //sys bind(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) 61 //sys connect(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) 62 //sysnb getgroups(n int, list *_Gid_t) (nn int, err error) = SYS_GETGROUPS32 63 //sysnb setgroups(n int, list *_Gid_t) (err error) = SYS_SETGROUPS32 64 //sys getsockopt(s int, level int, name int, val unsafe.Pointer, vallen *_Socklen) (err error) 65 //sys setsockopt(s int, level int, name int, val unsafe.Pointer, vallen uintptr) (err error) 66 //sysnb socket(domain int, typ int, proto int) (fd int, err error) 67 //sysnb getpeername(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error) 68 //sysnb getsockname(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error) 69 //sys recvfrom(fd int, p []byte, flags int, from *RawSockaddrAny, fromlen *_Socklen) (n int, err error) 70 //sys sendto(s int, buf []byte, flags int, to unsafe.Pointer, addrlen _Socklen) (err error) 71 //sysnb socketpair(domain int, typ int, flags int, fd *[2]int32) (err error) 72 //sys recvmsg(s int, msg *Msghdr, flags int) (n int, err error) 73 //sys sendmsg(s int, msg *Msghdr, flags int) (n int, err error) 74 75 // 64-bit file system and 32-bit uid calls 76 // (16-bit uid calls are not always supported in newer kernels) 77 //sys Dup2(oldfd int, newfd int) (err error) 78 //sysnb EpollCreate(size int) (fd int, err error) 79 //sys EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error) 80 //sys Fchown(fd int, uid int, gid int) (err error) = SYS_FCHOWN32 81 //sys Fstat(fd int, stat *Stat_t) (err error) = SYS_FSTAT64 82 //sys Fstatat(dirfd int, path string, stat *Stat_t, flags int) (err error) = SYS_FSTATAT64 83 //sysnb Getegid() (egid int) = SYS_GETEGID32 84 //sysnb Geteuid() (euid int) = SYS_GETEUID32 85 //sysnb Getgid() (gid int) = SYS_GETGID32 86 //sysnb Getuid() (uid int) = SYS_GETUID32 87 //sysnb InotifyInit() (fd int, err error) 88 //sys Lchown(path string, uid int, gid int) (err error) = SYS_LCHOWN32 89 //sys Listen(s int, n int) (err error) 90 //sys Lstat(path string, stat *Stat_t) (err error) = SYS_LSTAT64 91 //sys Pause() (err error) 92 //sys Renameat(olddirfd int, oldpath string, newdirfd int, newpath string) (err error) 93 //sys sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) = SYS_SENDFILE64 94 //sys Select(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (n int, err error) = SYS__NEWSELECT 95 //sys Setfsgid(gid int) (err error) = SYS_SETFSGID32 96 //sys Setfsuid(uid int) (err error) = SYS_SETFSUID32 97 //sysnb Setregid(rgid int, egid int) (err error) = SYS_SETREGID32 98 //sysnb Setresgid(rgid int, egid int, sgid int) (err error) = SYS_SETRESGID32 99 //sysnb Setresuid(ruid int, euid int, suid int) (err error) = SYS_SETRESUID32 100 //sysnb Setreuid(ruid int, euid int) (err error) = SYS_SETREUID32 101 //sys Shutdown(fd int, how int) (err error) 102 //sys Splice(rfd int, roff *int64, wfd int, woff *int64, len int, flags int) (n int, err error) 103 //sys Stat(path string, stat *Stat_t) (err error) = SYS_STAT64 104 //sys Ustat(dev int, ubuf *Ustat_t) (err error) 105 106 //sys futimesat(dirfd int, path string, times *[2]Timeval) (err error) 107 //sysnb Gettimeofday(tv *Timeval) (err error) 108 109 func Time(t *Time_t) (Time_t, error) { 110 var tv Timeval 111 err := Gettimeofday(&tv) 112 if err != nil { 113 return 0, err 114 } 115 if t != nil { 116 *t = Time_t(tv.Sec) 117 } 118 return Time_t(tv.Sec), nil 119 } 120 121 func Utime(path string, buf *Utimbuf) error { 122 tv := []Timeval{ 123 {Sec: buf.Actime}, 124 {Sec: buf.Modtime}, 125 } 126 return Utimes(path, tv) 127 } 128 129 //sys utimes(path string, times *[2]Timeval) (err error) 130 131 //sys Pread(fd int, p []byte, offset int64) (n int, err error) = SYS_PREAD64 132 //sys Pwrite(fd int, p []byte, offset int64) (n int, err error) = SYS_PWRITE64 133 //sys Truncate(path string, length int64) (err error) = SYS_TRUNCATE64 134 //sys Ftruncate(fd int, length int64) (err error) = SYS_FTRUNCATE64 135 136 func Fadvise(fd int, offset int64, length int64, advice int) (err error) { 137 _, _, e1 := Syscall6(SYS_ARM_FADVISE64_64, uintptr(fd), uintptr(advice), uintptr(offset), uintptr(offset>>32), uintptr(length), uintptr(length>>32)) 138 if e1 != 0 { 139 err = errnoErr(e1) 140 } 141 return 142 } 143 144 //sys mmap2(addr uintptr, length uintptr, prot int, flags int, fd int, pageOffset uintptr) (xaddr uintptr, err error) 145 146 func Fstatfs(fd int, buf *Statfs_t) (err error) { 147 _, _, e := Syscall(SYS_FSTATFS64, uintptr(fd), unsafe.Sizeof(*buf), uintptr(unsafe.Pointer(buf))) 148 if e != 0 { 149 err = e 150 } 151 return 152 } 153 154 func Statfs(path string, buf *Statfs_t) (err error) { 155 pathp, err := BytePtrFromString(path) 156 if err != nil { 157 return err 158 } 159 _, _, e := Syscall(SYS_STATFS64, uintptr(unsafe.Pointer(pathp)), unsafe.Sizeof(*buf), uintptr(unsafe.Pointer(buf))) 160 if e != 0 { 161 err = e 162 } 163 return 164 } 165 166 func mmap(addr uintptr, length uintptr, prot int, flags int, fd int, offset int64) (xaddr uintptr, err error) { 167 page := uintptr(offset / 4096) 168 if offset != int64(page)*4096 { 169 return 0, EINVAL 170 } 171 return mmap2(addr, length, prot, flags, fd, page) 172 } 173 174 type rlimit32 struct { 175 Cur uint32 176 Max uint32 177 } 178 179 //sysnb getrlimit(resource int, rlim *rlimit32) (err error) = SYS_UGETRLIMIT 180 181 const rlimInf32 = ^uint32(0) 182 const rlimInf64 = ^uint64(0) 183 184 func Getrlimit(resource int, rlim *Rlimit) (err error) { 185 err = prlimit(0, resource, nil, rlim) 186 if err != ENOSYS { 187 return err 188 } 189 190 rl := rlimit32{} 191 err = getrlimit(resource, &rl) 192 if err != nil { 193 return 194 } 195 196 if rl.Cur == rlimInf32 { 197 rlim.Cur = rlimInf64 198 } else { 199 rlim.Cur = uint64(rl.Cur) 200 } 201 202 if rl.Max == rlimInf32 { 203 rlim.Max = rlimInf64 204 } else { 205 rlim.Max = uint64(rl.Max) 206 } 207 return 208 } 209 210 //sysnb setrlimit(resource int, rlim *rlimit32) (err error) = SYS_SETRLIMIT 211 212 func Setrlimit(resource int, rlim *Rlimit) (err error) { 213 err = prlimit(0, resource, rlim, nil) 214 if err != ENOSYS { 215 return err 216 } 217 218 rl := rlimit32{} 219 if rlim.Cur == rlimInf64 { 220 rl.Cur = rlimInf32 221 } else if rlim.Cur < uint64(rlimInf32) { 222 rl.Cur = uint32(rlim.Cur) 223 } else { 224 return EINVAL 225 } 226 if rlim.Max == rlimInf64 { 227 rl.Max = rlimInf32 228 } else if rlim.Max < uint64(rlimInf32) { 229 rl.Max = uint32(rlim.Max) 230 } else { 231 return EINVAL 232 } 233 234 return setrlimit(resource, &rl) 235 } 236 237 func (r *PtraceRegs) PC() uint64 { return uint64(r.Uregs[15]) } 238 239 func (r *PtraceRegs) SetPC(pc uint64) { r.Uregs[15] = uint32(pc) } 240 241 func (iov *Iovec) SetLen(length int) { 242 iov.Len = uint32(length) 243 } 244 245 func (msghdr *Msghdr) SetControllen(length int) { 246 msghdr.Controllen = uint32(length) 247 } 248 249 func (cmsg *Cmsghdr) SetLen(length int) { 250 cmsg.Len = uint32(length) 251 } 252 253 //sys poll(fds *PollFd, nfds int, timeout int) (n int, err error) 254 255 func Poll(fds []PollFd, timeout int) (n int, err error) { 256 if len(fds) == 0 { 257 return poll(nil, 0, timeout) 258 } 259 return poll(&fds[0], len(fds), timeout) 260 } 261 262 //sys armSyncFileRange(fd int, flags int, off int64, n int64) (err error) = SYS_ARM_SYNC_FILE_RANGE 263 264 func SyncFileRange(fd int, off int64, n int64, flags int) error { 265 // The sync_file_range and arm_sync_file_range syscalls differ only in the 266 // order of their arguments. 267 return armSyncFileRange(fd, flags, off, n) 268 }