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 )
14
15 func setTimespec(sec, nsec int64) Timespec {
16 return Timespec{Sec: int32(sec), Nsec: int32(nsec)}
17 }
18
19 func setTimeval(sec, usec int64) Timeval {
20 return Timeval{Sec: int32(sec), Usec: int32(usec)}
21 }
22
23
24
25 func seek(fd int, offset int64, whence int) (newoffset int64, err Errno)
26
27 func Seek(fd int, offset int64, whence int) (newoffset int64, err error) {
28 newoffset, errno := seek(fd, offset, whence)
29 if errno != 0 {
30 return 0, errno
31 }
32 return newoffset, nil
33 }
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 func Stat(path string, stat *Stat_t) (err error) {
87 return fstatat(_AT_FDCWD, path, stat, 0)
88 }
89
90 func Lchown(path string, uid int, gid int) (err error) {
91 return Fchownat(_AT_FDCWD, path, uid, gid, _AT_SYMLINK_NOFOLLOW)
92 }
93
94 func Lstat(path string, stat *Stat_t) (err error) {
95 return fstatat(_AT_FDCWD, path, stat, _AT_SYMLINK_NOFOLLOW)
96 }
97
98 func Fstatfs(fd int, buf *Statfs_t) (err error) {
99 _, _, e := Syscall(SYS_FSTATFS64, uintptr(fd), unsafe.Sizeof(*buf), uintptr(unsafe.Pointer(buf)))
100 if e != 0 {
101 err = e
102 }
103 return
104 }
105
106 func Statfs(path string, buf *Statfs_t) (err error) {
107 pathp, err := BytePtrFromString(path)
108 if err != nil {
109 return err
110 }
111 _, _, e := Syscall(SYS_STATFS64, uintptr(unsafe.Pointer(pathp)), unsafe.Sizeof(*buf), uintptr(unsafe.Pointer(buf)))
112 if e != 0 {
113 err = e
114 }
115 return
116 }
117
118 func mmap(addr uintptr, length uintptr, prot int, flags int, fd int, offset int64) (xaddr uintptr, err error) {
119 page := uintptr(offset / 4096)
120 if offset != int64(page)*4096 {
121 return 0, EINVAL
122 }
123 return mmap2(addr, length, prot, flags, fd, page)
124 }
125
126 type rlimit32 struct {
127 Cur uint32
128 Max uint32
129 }
130
131
132
133 const rlimInf32 = ^uint32(0)
134 const rlimInf64 = ^uint64(0)
135
136 func Getrlimit(resource int, rlim *Rlimit) (err error) {
137 err = prlimit(0, resource, nil, rlim)
138 if err != ENOSYS {
139 return err
140 }
141
142 rl := rlimit32{}
143 err = getrlimit(resource, &rl)
144 if err != nil {
145 return
146 }
147
148 if rl.Cur == rlimInf32 {
149 rlim.Cur = rlimInf64
150 } else {
151 rlim.Cur = uint64(rl.Cur)
152 }
153
154 if rl.Max == rlimInf32 {
155 rlim.Max = rlimInf64
156 } else {
157 rlim.Max = uint64(rl.Max)
158 }
159 return
160 }
161
162
163
164 func setrlimit(resource int, rlim *Rlimit) (err error) {
165 err = prlimit(0, resource, rlim, nil)
166 if err != ENOSYS {
167 return err
168 }
169
170 rl := rlimit32{}
171 if rlim.Cur == rlimInf64 {
172 rl.Cur = rlimInf32
173 } else if rlim.Cur < uint64(rlimInf32) {
174 rl.Cur = uint32(rlim.Cur)
175 } else {
176 return EINVAL
177 }
178 if rlim.Max == rlimInf64 {
179 rl.Max = rlimInf32
180 } else if rlim.Max < uint64(rlimInf32) {
181 rl.Max = uint32(rlim.Max)
182 } else {
183 return EINVAL
184 }
185
186 return setrlimit1(resource, &rl)
187 }
188
189
190 func rawSetrlimit(resource int, rlim *Rlimit) Errno {
191 _, _, errno := RawSyscall6(SYS_PRLIMIT64, 0, uintptr(resource), uintptr(unsafe.Pointer(rlim)), 0, 0, 0)
192 if errno != ENOSYS {
193 return errno
194 }
195
196 rl := rlimit32{}
197 if rlim.Cur == rlimInf64 {
198 rl.Cur = rlimInf32
199 } else if rlim.Cur < uint64(rlimInf32) {
200 rl.Cur = uint32(rlim.Cur)
201 } else {
202 return EINVAL
203 }
204 if rlim.Max == rlimInf64 {
205 rl.Max = rlimInf32
206 } else if rlim.Max < uint64(rlimInf32) {
207 rl.Max = uint32(rlim.Max)
208 } else {
209 return EINVAL
210 }
211
212 _, _, errno = RawSyscall(SYS_SETRLIMIT, uintptr(resource), uintptr(unsafe.Pointer(rlim)), 0)
213 return errno
214 }
215
216 func (r *PtraceRegs) PC() uint64 { return uint64(r.Uregs[15]) }
217
218 func (r *PtraceRegs) SetPC(pc uint64) { r.Uregs[15] = uint32(pc) }
219
220 func (iov *Iovec) SetLen(length int) {
221 iov.Len = uint32(length)
222 }
223
224 func (msghdr *Msghdr) SetControllen(length int) {
225 msghdr.Controllen = uint32(length)
226 }
227
228 func (cmsg *Cmsghdr) SetLen(length int) {
229 cmsg.Len = uint32(length)
230 }
231
View as plain text