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