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