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
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
)
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
) {
75 err
:= Gettimeofday(&tv
)
82 return Time_t(tv
.Sec
), nil
85 func Utime(path
string, buf
*Utimbuf
) error
{
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))
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
)))
118 func Statfs(path
string, buf
*Statfs_t
) (err error
) {
119 pathp
, err
:= BytePtrFromString(path
)
123 _
, _
, e
:= Syscall(SYS_STATFS64
, uintptr(unsafe
.Pointer(pathp
)), unsafe
.Sizeof(*buf
), uintptr(unsafe
.Pointer(buf
)))
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 {
135 return mmap2(addr
, length
, prot
, flags
, fd
, page
)
138 type rlimit32
struct {
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
)
155 err
= getrlimit(resource
, &rl
)
160 if rl
.Cur
== rlimInf32
{
163 rlim
.Cur
= uint64(rl
.Cur
)
166 if rl
.Max
== rlimInf32
{
169 rlim
.Max
= uint64(rl
.Max
)
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)
183 if rlim
.Cur
== rlimInf64
{
185 } else if rlim
.Cur
< uint64(rlimInf32
) {
186 rl
.Cur
= uint32(rlim
.Cur
)
190 if rlim
.Max
== rlimInf64
{
192 } else if rlim
.Max
< uint64(rlimInf32
) {
193 rl
.Max
= uint32(rlim
.Max
)
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
)
238 // Account for the additional NULL byte added by
239 // BytePtrFromString in kexecFileLoad. The kexec_file_load
240 // syscall expects a NULL-terminated string.
243 return kexecFileLoad(kernelFd
, initrdFd
, cmdlineLen
, cmdline
, flags
)