Source file src/pkg/syscall/syscall_linux_arm.go
1
2
3
4
5 package syscall
6
7 import "unsafe"
8
9 const (
10 _SYS_dup = SYS_DUP2
11 _SYS_setgroups = SYS_SETGROUPS32
12 )
13
14 func setTimespec(sec, nsec int64) Timespec {
15 return Timespec{Sec: int32(sec), Nsec: int32(nsec)}
16 }
17
18 func setTimeval(sec, usec int64) Timeval {
19 return Timeval{Sec: int32(sec), Usec: int32(usec)}
20 }
21
22
23
24 func Pipe(p []int) (err error) {
25 if len(p) != 2 {
26 return EINVAL
27 }
28 var pp [2]_C_int
29
30 err = pipe2(&pp, 0)
31 if err == ENOSYS {
32 err = pipe(&pp)
33 }
34 p[0] = int(pp[0])
35 p[1] = int(pp[1])
36 return
37 }
38
39
40
41 func Pipe2(p []int, flags int) (err error) {
42 if len(p) != 2 {
43 return EINVAL
44 }
45 var pp [2]_C_int
46 err = pipe2(&pp, flags)
47 p[0] = int(pp[0])
48 p[1] = int(pp[1])
49 return
50 }
51
52
53
54 func seek(fd int, offset int64, whence int) (newoffset int64, err Errno)
55
56 func Seek(fd int, offset int64, whence int) (newoffset int64, err error) {
57 newoffset, errno := seek(fd, offset, whence)
58 if errno != 0 {
59 return 0, errno
60 }
61 return newoffset, nil
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116 func Stat(path string, stat *Stat_t) (err error) {
117 return fstatat(_AT_FDCWD, path, stat, 0)
118 }
119
120 func Lchown(path string, uid int, gid int) (err error) {
121 return Fchownat(_AT_FDCWD, path, uid, gid, _AT_SYMLINK_NOFOLLOW)
122 }
123
124 func Lstat(path string, stat *Stat_t) (err error) {
125 return fstatat(_AT_FDCWD, path, stat, _AT_SYMLINK_NOFOLLOW)
126 }
127
128 func Fstatfs(fd int, buf *Statfs_t) (err error) {
129 _, _, e := Syscall(SYS_FSTATFS64, uintptr(fd), unsafe.Sizeof(*buf), uintptr(unsafe.Pointer(buf)))
130 if e != 0 {
131 err = e
132 }
133 return
134 }
135
136 func Statfs(path string, buf *Statfs_t) (err error) {
137 pathp, err := BytePtrFromString(path)
138 if err != nil {
139 return err
140 }
141 _, _, e := Syscall(SYS_STATFS64, uintptr(unsafe.Pointer(pathp)), unsafe.Sizeof(*buf), uintptr(unsafe.Pointer(buf)))
142 if e != 0 {
143 err = e
144 }
145 return
146 }
147
148 func mmap(addr uintptr, length uintptr, prot int, flags int, fd int, offset int64) (xaddr uintptr, err error) {
149 page := uintptr(offset / 4096)
150 if offset != int64(page)*4096 {
151 return 0, EINVAL
152 }
153 return mmap2(addr, length, prot, flags, fd, page)
154 }
155
156 type rlimit32 struct {
157 Cur uint32
158 Max uint32
159 }
160
161
162
163 const rlimInf32 = ^uint32(0)
164 const rlimInf64 = ^uint64(0)
165
166 func Getrlimit(resource int, rlim *Rlimit) (err error) {
167 err = prlimit(0, resource, nil, rlim)
168 if err != ENOSYS {
169 return err
170 }
171
172 rl := rlimit32{}
173 err = getrlimit(resource, &rl)
174 if err != nil {
175 return
176 }
177
178 if rl.Cur == rlimInf32 {
179 rlim.Cur = rlimInf64
180 } else {
181 rlim.Cur = uint64(rl.Cur)
182 }
183
184 if rl.Max == rlimInf32 {
185 rlim.Max = rlimInf64
186 } else {
187 rlim.Max = uint64(rl.Max)
188 }
189 return
190 }
191
192
193
194 func Setrlimit(resource int, rlim *Rlimit) (err error) {
195 err = prlimit(0, resource, rlim, nil)
196 if err != ENOSYS {
197 return err
198 }
199
200 rl := rlimit32{}
201 if rlim.Cur == rlimInf64 {
202 rl.Cur = rlimInf32
203 } else if rlim.Cur < uint64(rlimInf32) {
204 rl.Cur = uint32(rlim.Cur)
205 } else {
206 return EINVAL
207 }
208 if rlim.Max == rlimInf64 {
209 rl.Max = rlimInf32
210 } else if rlim.Max < uint64(rlimInf32) {
211 rl.Max = uint32(rlim.Max)
212 } else {
213 return EINVAL
214 }
215
216 return setrlimit(resource, &rl)
217 }
218
219 func (r *PtraceRegs) PC() uint64 { return uint64(r.Uregs[15]) }
220
221 func (r *PtraceRegs) SetPC(pc uint64) { r.Uregs[15] = uint32(pc) }
222
223 func (iov *Iovec) SetLen(length int) {
224 iov.Len = uint32(length)
225 }
226
227 func (msghdr *Msghdr) SetControllen(length int) {
228 msghdr.Controllen = uint32(length)
229 }
230
231 func (cmsg *Cmsghdr) SetLen(length int) {
232 cmsg.Len = uint32(length)
233 }
234
235 func rawVforkSyscall(trap, a1 uintptr) (r1 uintptr, err Errno) {
236 panic("not implemented")
237 }
238
View as plain text