Source file
src/syscall/syscall_linux_arm.go
1
2
3
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
25
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
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 type rlimit32 struct {
128 Cur uint32
129 Max uint32
130 }
131
132
133
134 const rlimInf32 = ^uint32(0)
135 const rlimInf64 = ^uint64(0)
136
137 func Getrlimit(resource int, rlim *Rlimit) (err error) {
138 err = prlimit(0, resource, nil, rlim)
139 if err != ENOSYS {
140 return err
141 }
142
143 rl := rlimit32{}
144 err = getrlimit(resource, &rl)
145 if err != nil {
146 return
147 }
148
149 if rl.Cur == rlimInf32 {
150 rlim.Cur = rlimInf64
151 } else {
152 rlim.Cur = uint64(rl.Cur)
153 }
154
155 if rl.Max == rlimInf32 {
156 rlim.Max = rlimInf64
157 } else {
158 rlim.Max = uint64(rl.Max)
159 }
160 return
161 }
162
163
164
165 func setrlimit(resource int, rlim *Rlimit) (err error) {
166 err = prlimit(0, resource, rlim, nil)
167 if err != ENOSYS {
168 return err
169 }
170
171 rl := rlimit32{}
172 if rlim.Cur == rlimInf64 {
173 rl.Cur = rlimInf32
174 } else if rlim.Cur < uint64(rlimInf32) {
175 rl.Cur = uint32(rlim.Cur)
176 } else {
177 return EINVAL
178 }
179 if rlim.Max == rlimInf64 {
180 rl.Max = rlimInf32
181 } else if rlim.Max < uint64(rlimInf32) {
182 rl.Max = uint32(rlim.Max)
183 } else {
184 return EINVAL
185 }
186
187 return setrlimit1(resource, &rl)
188 }
189
190
191 func rawSetrlimit(resource int, rlim *Rlimit) Errno {
192 _, _, errno := RawSyscall6(SYS_PRLIMIT64, 0, uintptr(resource), uintptr(unsafe.Pointer(rlim)), 0, 0, 0)
193 if errno != ENOSYS {
194 return errno
195 }
196
197 rl := rlimit32{}
198 if rlim.Cur == rlimInf64 {
199 rl.Cur = rlimInf32
200 } else if rlim.Cur < uint64(rlimInf32) {
201 rl.Cur = uint32(rlim.Cur)
202 } else {
203 return EINVAL
204 }
205 if rlim.Max == rlimInf64 {
206 rl.Max = rlimInf32
207 } else if rlim.Max < uint64(rlimInf32) {
208 rl.Max = uint32(rlim.Max)
209 } else {
210 return EINVAL
211 }
212
213 _, _, errno = RawSyscall(SYS_SETRLIMIT, uintptr(resource), uintptr(unsafe.Pointer(rlim)), 0)
214 return errno
215 }
216
217 func (r *PtraceRegs) PC() uint64 { return uint64(r.Uregs[15]) }
218
219 func (r *PtraceRegs) SetPC(pc uint64) { r.Uregs[15] = uint32(pc) }
220
221 func (iov *Iovec) SetLen(length int) {
222 iov.Len = uint32(length)
223 }
224
225 func (msghdr *Msghdr) SetControllen(length int) {
226 msghdr.Controllen = uint32(length)
227 }
228
229 func (cmsg *Cmsghdr) SetLen(length int) {
230 cmsg.Len = uint32(length)
231 }
232
View as plain text