Source file src/syscall/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 package syscall 6 7 import "unsafe" 8 9 const ( 10 _SYS_setgroups = SYS_SETGROUPS32 11 _SYS_clone3 = 435 12 _SYS_faccessat2 = 439 13 _SYS_fchmodat2 = 452 14 ) 15 16 func setTimespec(sec, nsec int64) Timespec { 17 return Timespec{Sec: int32(sec), Nsec: int32(nsec)} 18 } 19 20 func setTimeval(sec, usec int64) Timeval { 21 return Timeval{Sec: int32(sec), Usec: int32(usec)} 22 } 23 24 // Underlying system call writes to newoffset via pointer. 25 // Implemented in assembly to avoid allocation. 26 func seek(fd int, offset int64, whence int) (newoffset int64, err Errno) 27 28 func Seek(fd int, offset int64, whence int) (newoffset int64, err error) { 29 newoffset, errno := seek(fd, offset, whence) 30 if errno != 0 { 31 return 0, errno 32 } 33 return newoffset, nil 34 } 35 36 //sys accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error) 37 //sys bind(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) 38 //sys connect(s int, addr unsafe.Pointer, addrlen _Socklen) (err error) 39 //sysnb getgroups(n int, list *_Gid_t) (nn int, err error) = SYS_GETGROUPS32 40 //sys getsockopt(s int, level int, name int, val unsafe.Pointer, vallen *_Socklen) (err error) 41 //sys setsockopt(s int, level int, name int, val unsafe.Pointer, vallen uintptr) (err error) 42 //sysnb socket(domain int, typ int, proto int) (fd int, err error) 43 //sysnb getpeername(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error) 44 //sysnb getsockname(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error) 45 //sys recvfrom(fd int, p []byte, flags int, from *RawSockaddrAny, fromlen *_Socklen) (n int, err error) 46 //sys sendto(s int, buf []byte, flags int, to unsafe.Pointer, addrlen _Socklen) (err error) 47 //sysnb socketpair(domain int, typ int, flags int, fd *[2]int32) (err error) 48 //sys recvmsg(s int, msg *Msghdr, flags int) (n int, err error) 49 //sys sendmsg(s int, msg *Msghdr, flags int) (n int, err error) 50 51 // 64-bit file system and 32-bit uid calls 52 // (16-bit uid calls are not always supported in newer kernels) 53 //sys Dup2(oldfd int, newfd int) (err error) 54 //sys Fchown(fd int, uid int, gid int) (err error) = SYS_FCHOWN32 55 //sys Fstat(fd int, stat *Stat_t) (err error) = SYS_FSTAT64 56 //sys fstatat(dirfd int, path string, stat *Stat_t, flags int) (err error) = SYS_FSTATAT64 57 //sysnb Getegid() (egid int) = SYS_GETEGID32 58 //sysnb Geteuid() (euid int) = SYS_GETEUID32 59 //sysnb Getgid() (gid int) = SYS_GETGID32 60 //sysnb Getuid() (uid int) = SYS_GETUID32 61 //sysnb InotifyInit() (fd int, err error) 62 //sys Listen(s int, n int) (err error) 63 //sys Pause() (err error) 64 //sys Renameat(olddirfd int, oldpath string, newdirfd int, newpath string) (err error) 65 //sys sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) = SYS_SENDFILE64 66 //sys Select(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (n int, err error) = SYS__NEWSELECT 67 //sys Setfsgid(gid int) (err error) = SYS_SETFSGID32 68 //sys Setfsuid(uid int) (err error) = SYS_SETFSUID32 69 //sys Shutdown(fd int, how int) (err error) 70 //sys Splice(rfd int, roff *int64, wfd int, woff *int64, len int, flags int) (n int, err error) 71 //sys Ustat(dev int, ubuf *Ustat_t) (err error) 72 73 //sys futimesat(dirfd int, path string, times *[2]Timeval) (err error) 74 //sysnb Gettimeofday(tv *Timeval) (err error) 75 //sysnb Time(t *Time_t) (tt Time_t, err error) 76 //sys Utime(path string, buf *Utimbuf) (err error) 77 //sys utimes(path string, times *[2]Timeval) (err error) 78 79 //sys pread(fd int, p []byte, offset int64) (n int, err error) = SYS_PREAD64 80 //sys pwrite(fd int, p []byte, offset int64) (n int, err error) = SYS_PWRITE64 81 //sys Truncate(path string, length int64) (err error) = SYS_TRUNCATE64 82 //sys Ftruncate(fd int, length int64) (err error) = SYS_FTRUNCATE64 83 84 //sys mmap2(addr uintptr, length uintptr, prot int, flags int, fd int, pageOffset uintptr) (xaddr uintptr, err error) 85 //sys EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error) 86 87 func Stat(path string, stat *Stat_t) (err error) { 88 return fstatat(_AT_FDCWD, path, stat, 0) 89 } 90 91 func Lchown(path string, uid int, gid int) (err error) { 92 return Fchownat(_AT_FDCWD, path, uid, gid, _AT_SYMLINK_NOFOLLOW) 93 } 94 95 func Lstat(path string, stat *Stat_t) (err error) { 96 return fstatat(_AT_FDCWD, path, stat, _AT_SYMLINK_NOFOLLOW) 97 } 98 99 func Fstatfs(fd int, buf *Statfs_t) (err error) { 100 _, _, e := Syscall(SYS_FSTATFS64, uintptr(fd), unsafe.Sizeof(*buf), uintptr(unsafe.Pointer(buf))) 101 if e != 0 { 102 err = e 103 } 104 return 105 } 106 107 func Statfs(path string, buf *Statfs_t) (err error) { 108 pathp, err := BytePtrFromString(path) 109 if err != nil { 110 return err 111 } 112 _, _, e := Syscall(SYS_STATFS64, uintptr(unsafe.Pointer(pathp)), unsafe.Sizeof(*buf), uintptr(unsafe.Pointer(buf))) 113 if e != 0 { 114 err = e 115 } 116 return 117 } 118 119 func mmap(addr uintptr, length uintptr, prot int, flags int, fd int, offset int64) (xaddr uintptr, err error) { 120 page := uintptr(offset / 4096) 121 if offset != int64(page)*4096 { 122 return 0, EINVAL 123 } 124 return mmap2(addr, length, prot, flags, fd, page) 125 } 126 127 func (r *PtraceRegs) PC() uint64 { return uint64(r.Uregs[15]) } 128 129 func (r *PtraceRegs) SetPC(pc uint64) { r.Uregs[15] = uint32(pc) } 130 131 func (iov *Iovec) SetLen(length int) { 132 iov.Len = uint32(length) 133 } 134 135 func (msghdr *Msghdr) SetControllen(length int) { 136 msghdr.Controllen = uint32(length) 137 } 138 139 func (cmsg *Cmsghdr) SetLen(length int) { 140 cmsg.Len = uint32(length) 141 } 142