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